Codeforces Round 249 (Div. 2)


A. Queue on Bus Stop
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 3
2 3 2 1
Output
3
Input
3 4
1 2 1
Output
1
----------------------------------------------------------------------------------------------------
B. Pasha Maximizes
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1990 1
Output
9190
Input
300 0
Output
300
Input
1034 2
Output
3104
Input
9090000078001234 6
Output
9907000008001234
----------------------------------------------------------------------------------------------------
C. Cardiogram
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
3 1 2 5 1
Output
     
 / 
\
     
  
 / 
\
 / 
  
\
    
 
 / 
      
\
   
 / 
        
\
  
          
\
 / 
Input
3
1 5 1
Output
 / 
\
     
  
\
    
   
\
   
    
\
  
     
\
 / 
----------------------------------------------------------------------------------------------------
D. Special Grid
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 5
10000
10010
00001
Output
20
Input
2 2
00
00
Output
4
Input
2 2
11
11
Output
0
----------------------------------------------------------------------------------------------------
E. Special Graph
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 5
10101
00020
01000
Output
13131
42424
31313
Input
2 2
00
00
Output
12
34
Input
2 2
11
00
Output
0
----------------------------------------------------------------------------------------------------
