Codeforces Beta Round 98 (Div. 2)


A. Postcards and photos
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
CPCPCPC
Output
7
Input
CCCCCCPPPPPP
Output
4
Input
CCCCCCPPCPPPPPPPPPP
Output
6
Input
CCCCCCCCCC
Output
2
----------------------------------------------------------------------------------------------------
B. Permutation
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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

Examples
Input
5
1 10
2 9
3 8
4 7
5 6
Output
4
Input
5
1 100
2 50
51 99
52 98
10 60
Output
4
Input
1
1 1000000000
Output
0
----------------------------------------------------------------------------------------------------
D. Palindromes
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
abacaba
1
Output
0
abacaba
Input
abdcaba
2
Output
1
abdcdba
Input
abdcaba
5
Output
0
a+b+d+c+aba
Input
abacababababbcbabcd
3
Output
1
abacaba+babab+bcbabcb
----------------------------------------------------------------------------------------------------
E. Last Chance
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
Abo
Output
3 1
Input
OEIS
Output
3 1
Input
auBAAbeelii
Output
9 3
Input
AaaBRAaaCAaaDAaaBRAaa
Output
18 4
Input
EA
Output
No solution
----------------------------------------------------------------------------------------------------
