Basic data structures
Previous
|< Mathematical algorithms |
Next
Sorting arrays>| |
Task 1-Palindrome
Examine if the palindrom number is entered.
Input
An entire number is entered.
Output
YES is written if the number is palindrome or NE if the number is not a palindrome.
Limitations
The number is five-digit.
Example
Input
50605
Output
YES
An entire number is entered.
Output
YES is written if the number is palindrome or NE if the number is not a palindrome.
Limitations
The number is five-digit.
Example
Input
50605
Output
YES
Task 2-Sequacious letters
A string is composed of the small letters of the English alphabet ('a' - 'z'). Find the longest part of the alphabet that is inside this string (ie find the longest substring whose each character, starting with the other, is the next in the alphabetical order in relation to the previous letter).
English alphabet (order): abcdefghijklmnopqrstuvwxyz
Input
In the single line of the input, there is a string S. Each string string is a letter between 'a' and 'z'.
Output
The output should contain one line, in which the longest part of the alphabet is the substring of the input string. If there are more such parts, the solution is whose first letter is the earliest in the alphabetical order.
Limitations
1 ≤ length (S) ≤ 10 000 000
Example
Input
bbcdrtughih
Output
bcd
Input
In the single line of the input, there is a string S. Each string string is a letter between 'a' and 'z'.
Output
The output should contain one line, in which the longest part of the alphabet is the substring of the input string. If there are more such parts, the solution is whose first letter is the earliest in the alphabetical order.
Limitations
1 ≤ length (S) ≤ 10 000 000
Example
Input
bbcdrtughih
Output
bcd
Task 2-Trace Matrix
The main diagonal of the square matrix is a diagonal starting from the first element of the first order and ending on the last element of the last row.
The matrix trace is defined as the sum of the elements on the main diagonal.
The data is a square matrix M, the dimension n × n. Calculate her trace.
The matrix trace is defined as the sum of the elements on the main diagonal.
The data is a square matrix M, the dimension n × n. Calculate her trace.
Input
In the first order of the input there is a number n, which represents the number of rows (and columns) of the matrix M.
The following n lines are located by n integers separated by spaces, so that the jth number in the second row is the element M [i] [j].
Output
The output should consist of only one number - the value of the trace of the matrix M.
Limitations
1 ≤ n ≤ 1000
-10000 ≤ M [i, j] ≤ 10000 for all 1 ≤ i, j ≤ n.
Example
Input
3
2 0 0
1 1 0
3 3 3
Output
6
Explanation of the case
2 0 0
1 1 0
3 3 3
The sum of the elements on the main diagonal is 2 + 3 + 1 = 6.
In the first order of the input there is a number n, which represents the number of rows (and columns) of the matrix M.
The following n lines are located by n integers separated by spaces, so that the jth number in the second row is the element M [i] [j].
Output
The output should consist of only one number - the value of the trace of the matrix M.
Limitations
1 ≤ n ≤ 1000
-10000 ≤ M [i, j] ≤ 10000 for all 1 ≤ i, j ≤ n.
Example
Input
3
2 0 0
1 1 0
3 3 3
Output
6
Explanation of the case
2 0 0
1 1 0
3 3 3
The sum of the elements on the main diagonal is 2 + 3 + 1 = 6.