Problem A. Second Best
Statement
Given the sequence of integers A1, A2, …, AN,
find a number As such that there exists exactly one
Am > As, and for all k ≠ m Ak ≤ As.
Input file format
Input contains
N followed by
A1 A2… AN.
Output file format
Output should contain a single integer —
As, or
−1 if no such number exists.
Constraints
1 ≤ N ≤ 1000000, 0 ≤ Ai ≤ 109,
Sample tests
No. |
Input file (input.txt ) |
Output file (output.txt ) |
1 |
3
1 2 3
|
2
|
2 |
4
3 3 2 3
|
-1
|
Problem B. Nearest number - 2
Statement
Input is the matrix A of N by N non-negative integers.
A distance between two elements Ai j and
Ap q is defined as |i − p| + |j − q|.
Your program must replace each zero element in the matrix with the nearest non-zero one.
If there are two or more nearest non-zeroes, the zero must be left in place.
Input file format
Input file contains the number
N followed by
N2 integers, representing the matrix
row-by-row.
Output file format
Output file must contain
N2 integers, representing the modified matrix
row-by-row.
Constraints
1 ≤
N ≤ 200, 0 ≤
Ai ≤ 1000000
Sample tests
No. |
Input file (input.txt ) |
Output file (output.txt ) |
1 |
3
0 0 0
1 0 2
0 3 0
|
1 0 2
1 0 2
0 3 0
|
Problem C. Count Squares
Statement
Given a set of points with integer coordinates xi, yi, i = 1… N,
your program must find all the squares having each of four vertices in one of these points.
Input file format
Input file contains integer
N followed by
N pairs of integers
xi yi.
Output file format
Output file must contain a single integer — number of squares found.
Constraints
−104 ≤ xi, yi ≤ 104,
1 ≤ N ≤ 2000.
All points in the input are different.
Sample tests
No. |
Input file (input.txt ) |
Output file (output.txt ) |
1 |
4 0 0 4 3 -3 4 1 7
|
1
|
2 |
9
1 1 1 2 1 3
2 1 2 2 2 3
3 1 3 2 3 3
|
6
|