A - Matches

17 May - Dünya Telekommunikasiya və İnformasiya Cəmiyyəti Gününə həsr olunan
“Ali məktəb tələbələri arasında informatika üzrə XII Ümumrespublika Olimpiadası” (I tur)
Bakı Mühəndislik Universiteti, 29 aprel 2017
Problems
A - Matches
B - Hie with the Pie
C - So you want to be a 2^n-aire?
D - Игра в дурака
E - Eustace-Alex
F - Minibuses
G - Road Removal
H - Frequent values
I - Its a Murder!
J - Degrees of two
1/11
17 May - Dünya Telekommunikasiya və İnformasiya Cəmiyyəti Gününə həsr olunan
“Ali məktəb tələbələri arasında informatika üzrə XII Ümumrespublika Olimpiadası” (I tur)
Bakı Mühəndislik Universiteti, 29 aprel 2017
A - Matches
What is the minimum number of matches necessary to pit on the plane n squares with a side in one match?
Matches can not be broken and put on each other. The vertices of the squares should be the points where the
ends of the matches meet, and the sides are matches themselves.
Write a program that by the number of squares n to be constructed, finds the minimum number of matches
required for this.
Input
One integer n (1 ≤ n ≤ 109).
Output
Print the minimum number of matches required to construct n squares.
Input example #1
4
Output example #1
12
2/11
17 May - Dünya Telekommunikasiya və İnformasiya Cəmiyyəti Gününə həsr olunan
“Ali məktəb tələbələri arasında informatika üzrə XII Ümumrespublika Olimpiadası” (I tur)
Bakı Mühəndislik Universiteti, 29 aprel 2017
B - Hie with the Pie
The Pizazz Pizzeria prides itself in delivering pizzas to its customers as fast as possible. Unfortunately,
due to cutbacks, they can afford to hire only one driver to do the deliveries. He will wait for 1 or more (up to
20) orders to be processed before he starts any deliveries. Needless to say, he would like to take the shortest
route in delivering these goodies and returning to the pizzeria, even if it means passing the same location(s) or
the pizzeria more than once on the way. He has commissioned you to write a program to help him.
Input
The first line will contain a single integer n (1 ≤ n ≤ 20) indicating the number of orders to deliver.
After this will be n + 1 lines each containing n + 1 integers indicating the times to travel between the pizzeria
(numbered 0) and the n locations (numbers 1 to n). The j-th value on the i-th line indicates the time to go
directly from location i to location j without visiting any other locations along the way. Note that there may be
quicker ways to go from i to j via other locations, due to different speed limits, traffic lights, etc. Also, the time
values may not be symmetric, i.e., the time to go directly from location i to j may not be the same as the time to
go directly from location j to i.
Output
Output a single number indicating the minimum time to deliver all of the pizzas and return to the
pizzeria.
Input example
3
0 1 10 10
1012
10 1 0 10
10 2 10 0
Output example
8
3/11
17 May - Dünya Telekommunikasiya və İnformasiya Cəmiyyəti Gününə həsr olunan
“Ali məktəb tələbələri arasında informatika üzrə XII Ümumrespublika Olimpiadası” (I tur)
Bakı Mühəndislik Universiteti, 29 aprel 2017
C - So you want to be a 2^n-aire?
The player starts with a prize of $1, and is asked a sequence of n questions. For each question, he may
 quit and keep his prize.
 answer the question. If wrong, he quits with nothing. If correct, the prize is doubled, and he continues
with the next question.
After the last question, he quits with his prize. The player wants to maximize his expected prize.
Once each question is asked, the player is able to assess the probability p that he will be able to answer
it. For each question, we assume that p is a random variable uniformly distributed over the range t .. 1.
Input
Input is a number of lines, each with two numbers: an integer n (1 ≤ n ≤ 30) and a real t (0 ≤ t ≤ 1).
Input is terminated by a line containing 0 0. This line should not be processed.
Output
For each input n and t, print the player's expected prize, if he plays the best strategy. Output should be
rounded to three fractional digits.
Example input
1 0.5
1 0.3
2 0.6
24 0.25
00
Example output
1.500
1.357
2.560
230.138
4/11
17 May - Dünya Telekommunikasiya və İnformasiya Cəmiyyəti Gününə həsr olunan
“Ali məktəb tələbələri arasında informatika üzrə XII Ümumrespublika Olimpiadası” (I tur)
Bakı Mühəndislik Universiteti, 29 aprel 2017
D - Durak game
A prankster monkey, a donkey, a goat and a clubfooted bear started to play cards in a fool. As you know, the
first starts in the game who has the trump card of the smallest dignity. Therefore, after the cards are dealt, all
four simultaneously name the value of the smallest trump that they have, namely, each says a number from 6 to
14 or 0 (numbers more than 10 correspond to pictures: jack, lady, king and ace, zero - no trumps).
You know what numbers were said. Determine the number of guaranteedly lied in this company.
The game use a deck of 36 cards - 9 cards of each of 4 suits. Each player is dealt 6 cards, the next card from the
deck is opened, and its suit becomes a trump for this game.
Input
Four integers that players called. Each of the numbers is either 0, or a number from 6 to 14.
Output
Print the minimum number of players who lied.
Input example #1
10 7 11 0
Output example #1
0
Input example #2
6 10 10 11
Output example #2
1
5/11
17 May - Dünya Telekommunikasiya və İnformasiya Cəmiyyəti Gününə həsr olunan
“Ali məktəb tələbələri arasında informatika üzrə XII Ümumrespublika Olimpiadası” (I tur)
Bakı Mühəndislik Universiteti, 29 aprel 2017
E - Eustace-Alex
After a brilliantly conducted operation Stirlitz able to determine the strength of the fascist army.
Naturally this information for four years as waiting in the headquarters of the Soviet army. To communicate
with the staff Stirlitz uses n wireless operators. Each of the radio operators must pass a message from Shtirlitsa
headquarters. Stirlitz as a cunning spy, encrypt the message this way: each of the radio operators, he gave the
same number - the size of the army, but their number system, so even in such a way that all the bases of number
systems from wireless operators are pairwise coprime. After the transfer of radiograms Mueller sleuths were
able to identify the last character of each message. You work full-time programmer and need to determine the
minimum number could send Stirlitz in your message. Mueller unlike you does not like binary code, so he
wants to the desired number you brought to the decimal system.
Input
The first line number n - the number of radio operators Shtirlits has. The next line contains n numbers ai
- the base number system, which gave the message Stirlitz radio operators (2 ≤ ai ≤ 36 ). In the third line of
space-separated n symbols ci - the last letter of each of the messages (0 ≤ ci < ai; ci - any number from 0 to 9 or
letter A through Z).
Output
Print the minimum number that could pass Stirlitz in the decimal system.
Example input
2
6 13
1B
Example output
37
6/11
17 May - Dünya Telekommunikasiya və İnformasiya Cəmiyyəti Gününə həsr olunan
“Ali məktəb tələbələri arasında informatika üzrə XII Ümumrespublika Olimpiadası” (I tur)
Bakı Mühəndislik Universiteti, 29 aprel 2017
F - Minibuses
At the rush hour, three minibuses arrived to the station at the same time, following the same route, into
which the passengers immediately got crowded. The drivers found that the number of people in different
minibuses is different, and they decided to reallocate a part of passengers so that in each minibus there was an
equal number of passengers. Determine the minimum number of passengers to reallocate.
Input
Three positive integers, not greater than 100 - the number of passengers in the first, second and third
minibus.
Output
Print the minimum number of passengers to reallocate. If this is not possible, print the word
"IMPOSSIBLE".
Input example #1
123
Output example #1
1
Input example #2
99 100 100
Output example #2
IMPOSSIBLE
7/11
17 May - Dünya Telekommunikasiya və İnformasiya Cəmiyyəti Gününə həsr olunan
“Ali məktəb tələbələri arasında informatika üzrə XII Ümumrespublika Olimpiadası” (I tur)
Bakı Mühəndislik Universiteti, 29 aprel 2017
G - Road Removal
You are given a network with n cities and m bidirectional roads connecting these cities. The first k
cities are important. You need to remove the minimum number of roads such that in the remaining network
there are no cycles that contain important cities. A cycle is a sequence of at least three different cities such that
each pair of neighboring cities are connected by a road and the first and the last city in the sequence are also
connected by a road.
Input
The first line contains the number of test cases t (1 ≤ t ≤ 20). Each case begins with a line containing
integers n, m and k (1 ≤ n ≤ 10000, 1 ≤ m ≤ 50000, 1 ≤ k ≤ n), which represent the number of cities, the
number of roads and the number of important cities, respectively. The cities are numbered from 0 to n-1, and
the important cities are numbered from 0 to k-1. The following m lines contain two integers ai and bi, 0 ≤ i <
m, that represent two different cities connected by a road.
It is guaranteed that 0 ≤ ai, bi < n and ai ≠ bi. There will be at most one road between two cities.
Output
For each of the test cases numbered in order from 1 to t, output "Case #i: " followed by a single integer,
the minimum number of roads that need to be removed such that there are no cycles that contain an important
city.
Example
In the first example, we have n = 5 cities that are connected by m = 7 roads and the cities 0 and 1 are
important. We can remove two roads connecting (0, 1) and (1, 2) and the remaining network will not contain
cycles with important cities. Note that in the remaining network there is a cycle that contains only nonimportant cities, and that there are also multiple ways to remove two roads and satisfy all conditions. One
cannot remove only one road and destroy all cycles that contain important cities.
Input example
2
572
01
12
14
02
24
23
34
8 12 2
02
04
05
23
27
31
34
46
56
57
61
71
Output example
Case #1: 2
Case #2: 4
8/11
17 May - Dünya Telekommunikasiya və İnformasiya Cəmiyyəti Gününə həsr olunan
“Ali məktəb tələbələri arasında informatika üzrə XII Ümumrespublika Olimpiadası” (I tur)
Bakı Mühəndislik Universiteti, 29 aprel 2017
H - Frequent values
You are given a sequence of n integers a1 , a2 , ... , an in non-decreasing order. In addition to that, you
are given several queries consisting of indices i and j (1 ≤ i ≤ j ≤ n). For each query, determine the most
frequent value among the integers ai , ... , aj.
Input
Consists of several test cases. Each test case starts with a line containing two integers n and q (1 ≤ n, q
≤ 100000). The next line contains n integers a1 , ... , an (-100000 ≤ ai ≤ 100000, for each i ∈ {1, ..., n})
separated by spaces. You can assume that for each i ∈ {1, ..., n - 1}: ai ≤ ai+1. The following q lines contain one
query each, consisting of two integers i and j (1 ≤ i ≤ j ≤ n), which indicate the boundary indices for the query.
The last test case is followed by a line containing a single 0.
Output
For each query, print one line with one integer: The number of occurrences of the most frequent value
within the given range.
Input example
10 3
-1 -1 1 1 1 1 3 10 10 10
23
1 10
5 10
0
Output example
1
4
3
9/11
17 May - Dünya Telekommunikasiya və İnformasiya Cəmiyyəti Gününə həsr olunan
“Ali məktəb tələbələri arasında informatika üzrə XII Ümumrespublika Olimpiadası” (I tur)
Bakı Mühəndislik Universiteti, 29 aprel 2017
I - Its a Murder!
Once detective Saikat was solving a murder case. While going to the crime scene he took the stairs and
saw that a number is written on every stair. He found it suspicious and decides to remember all the numbers
that he has seen till now. While remembering the numbers he found that he can find some pattern in those
numbers. So he decides that for each number on the stairs he will note down the sum of all the numbers
previously seen on the stairs which are smaller than the present number. Calculate the sum of all the numbers
written on his notes diary.
Input
First line gives the number of test cases t (t ≤ 10). 2t lines follow. First line gives the number of stairs n
(1 ≤ n≤105). Next line gives n numbers written on the stairs. All numbers will be between 0 and 106.
Output
For each test case print the final sum in a separate line.
Input example
1
5
15364
Output example
15
10/11
17 May - Dünya Telekommunikasiya və İnformasiya Cəmiyyəti Gününə həsr olunan
“Ali məktəb tələbələri arasında informatika üzrə XII Ümumrespublika Olimpiadası” (I tur)
Bakı Mühəndislik Universiteti, 29 aprel 2017
J - Degrees of two
It's not a secret that the number 2n for any nonnegative integer n in binary notation has a very simple
form - one in the high bit and then follow n zeros. In the decimal system these numbers are not so unvaried, but
even among them there are those that start with one.
Calculate how many such numbers in a given range.
Input
Two integers n1 and n2 (0 ≤ n1 < n2 ≤ 109), separated with a space.
Output
Print, how many numbers are power of two, belong to the range [2n1; 2n2] and in decimal notation their
first digit is one.
Input example
0 10
Output example
4
11/11