A COLLECTION OF TASKS · PRIMARY SCHOOL

Municipal computer science competitions

This collection contains tasks from municipal computer science competitions (2009, 2019 and 2023/2024), as well as two tasks from the qualifications. The tasks follow the order of the original collection, with separate statements, input, output, examples and extra explanations.

You can test tasks 12–18 on the site takprog.petlja.org (you need to log in). The tests there check the output exactly as in the original tasks, so for tasks 12–18 the output words are left in Serbian, with their meaning explained.

TASK 01 2019.

Angle

Municipal competition grade not stated

Source of the task: dms.rs

Task statement

An angle in degrees, minutes and seconds is read from standard input (the angle is less than 180 degrees, but it is given so that the number of minutes and the number of seconds can be greater than 59).

Write a program that prints the total number of seconds of the angle, and whether the angle is acute, right or obtuse.

Input

One line contains three whole numbers separated by a space: the number of degrees, minutes and seconds of the angle.

Output

Print the total number of seconds, and then, separated by a space, the word acute, right or obtuse.

Example 1

Input

23 18 370

Output

84250 acute
Explanation

The angle has 23 · 3600 + 18 · 60 + 370 = 84250 seconds. A right angle has 324000 seconds, so this angle is acute.

Example 2

Input

90 0 0

Output

324000 right

Example 3

Input

89 79 3

Output

325143 obtuse
Explanation

The angle has 89 · 3600 + 79 · 60 + 3 = 325143 seconds, which is more than 324000, so the angle is obtuse.

Hint and solution

TASK 02 2019.

Grandma

Municipal competition grade not stated

Source of the task: dms.rs

Task statement

Write a program that reads the ages of a grandmother, a father (her son) and a granddaughter (his daughter) and works out how many years older the grandmother is than her granddaughter. The numbers are entered in any order.

Input

Three ages are read from standard input, each on a separate line.

Output

Print the difference in years between the grandmother and the granddaughter.

Example 1

Input

73
42
17

Output

56
Explanation

The grandmother is the oldest (73) and the granddaughter the youngest (17), so the difference is 73 − 17 = 56.

Example 2

Input

26
3
49

Output

46
Explanation

The grandmother is 49 and the granddaughter 3, so the difference is 46.

Hint and solution

TASK 03 2019.

Type of triangle

Municipal competition 8th grade

Source of the task: dms.rs

Task statement

Write a program that, from the lengths of the three sides of a triangle, calculates and prints the perimeter of the triangle. Also print whether the triangle is isosceles, equilateral or scalene.

Input

The lengths of the three sides of the triangle are read from standard input, each on a separate line.

Output

Print the perimeter of the triangle, and then, separated by a space, the type of triangle: equilateral, isosceles or scalene.

Example 1

Input

17
17
17

Output

51 equilateral

Example 2

Input

12
19
12

Output

43 isosceles
TASK 04 2019.

Emails

Municipal competition 8th grade

Source of the task: dms.rs

Task statement

Pera works in a software company in Niš whose headquarters are in the USA, and he sent his boss n emails. For every email we know the time (hour and minute) it was sent (and also received), in local Niš time.

His boss works in New York from 9 to 17h, in local New York time, which is exactly 6 hours behind Niš time. Write a program that works out how many emails reached the boss outside his working hours (emails that arrived at 9:00 New York time are inside, and those at 17:00 are outside working hours).

Input

The first line contains the number of emails n. The next n lines contain the hour and minute when an email was sent (in Niš time), separated by a space.

Output

Print the number of emails that arrived outside working hours.

Example

Input

7
14 0
22 59
15 0
9 0
19 24
17 0
23 23

Output

3
Explanation

In New York time the emails arrived at 8:00, 16:59, 9:00, 3:00, 13:24, 11:00 and 17:23. The emails that arrived outside working hours are those at 8:00, 3:00 and 17:23, so there are three of them.

Hint and solution

TASK 05 2019.

Banana sweets

Municipal competition 5th grade

Source of the task: dms.rs

Task statement

Jovana has m 50-dinar notes and twice as many 20-dinar notes. Write a program that works out how much money she has left after she buys n chocolate banana sweets, each costing 15 dinars (you may assume that Jovana has enough money to buy all the sweets she wants).

Input

The whole numbers m and n are read from the input (each on a separate line, m < 100, n < 100).

Output

Print how many dinars Jovana has left.

Example 1

Input

3
10

Output

120
Explanation

Jovana has 3 · 50 + 6 · 20 = 270 dinars. The banana sweets cost 10 · 15 = 150 dinars, so she has 120 dinars left.

Example 2

Input

2
6

Output

90
Explanation

Jovana has 2 · 50 + 4 · 20 = 180 dinars. The banana sweets cost 90 dinars, so she has 90 dinars left.

TASK 06 2019.

Triangle

Municipal competition 8th grade

Source of the task: dms.rs

Task statement

A triangle has n rows. The first row contains only the element 0. Each following row has two more elements than the previous one; the first element of each row is d1 greater than the first element of the previous row, while in each row every next element is d2 greater than the previous one. For example, for d1 = 5, d2 = 2 and n = 4 we get the following triangle:

            0
         5  7  9
      10 12 14 16 18
15 17 19 21 23 25 27

Write a program that reads the natural numbers d1, d2 and n and prints the sum of all the elements on the edges of the triangle, that is, the elements of the left and right sides and the elements of the last row.

Input

The natural numbers d1, d2 and n are entered on separate lines, where 1 ≤ d1, d2 ≤ 10 and 2 ≤ n ≤ 1000.

Output

Print the sum of the elements on the edges of the triangle.

Example

Input

5
2
4

Output

189
Explanation

On the edges are the elements 0, 5, 9, 10, 18 and the whole last row (15 + 17 + 19 + 21 + 23 + 25 + 27 = 147). The sum is 0 + 14 + 28 + 147 = 189.

TASK 07 2022/2023.

Number of days of steady training

Qualifications, round 1 7th grade

Source of the task: dms.rs — computer science for primary schools

What you need to know first: Data in C++ Operators in C++ Branching in a program Loops Arrays

Task statement

While preparing for the coming competitions, an athlete measures the result achieved every day. Since he wants to improve his form steadily, he wants the result to be better every day (a larger number is a better result).

We will say that a day of training is good if the result achieved that day is strictly better than on the previous day and strictly worse than on the next day. To be good, it is enough for the first day to be strictly worse than the next one, and for the last day to be strictly better than the previous one.

Write a program that calculates the number of good days.

Input

The number of days n (3 ≤ n ≤ 100) during which the athlete trained is read from standard input, and on the second line the results the athlete achieved on each of those n days.

Output

Print the number of good days to standard output.

Example 1

Input

6
100 120 130 110 140 150

Output

4

Example 2

Input

6
10 20 30 40 50 60

Output

6
TASK 08 2022/2023.

The handyman

Qualifications, round 1 6th grade

Source of the task: dms.rs — computer science for primary schools

What you need to know first: Data in C++ Operators in C++ Branching in a program Loops Arrays

Task statement

After a job, n boxes of screws were returned to Pera the handyman. The boxes have been used and may contain different numbers of screws.

Pera wants to use the two boxes with the fewest screws. Help Pera work out how many screws there are altogether in the two boxes chosen this way.

Input

The first line of standard input contains the total number of boxes n (2 ≤ n ≤ 30). Then the next n lines contain the numbers of screws in the boxes ki (1 ≤ ki ≤ 100), in order.

Output

Print to standard output a whole number that is the total number of screws in the two boxes with the fewest screws.

Example 1

Input

5
45
32
9
15
67

Output

24

Example 2

Input

7
764
455
721
231
138
97
333

Output

235

Example 3

Input

5
28
14
30
15
14

Output

28
TASK 09 2019.

Days

Municipal competition grade not stated

Task statement

For every top mark (a 5) she got during one term, Lidija wrote down the name of the school day on which she got it. Write a program that works out which was her luckiest day during that term (you may assume that she got a different number of marks on each of the 5 school days).

Input

The number of top marks n < 100 she got is read, and then the day codes mon, tue, wed, thu, fri on which she got them, each on a separate line.

Output

Print the code of the day on which Lidija got the most top marks.

Example

Input

8
mon
wed
thu
mon
mon
fri
thu
wed

Output

mon
Explanation

On Mondays she got three top marks, on Wednesdays and Thursdays two each, and on Fridays one. The luckiest day is Monday.

TASK 10 2009.

Crossing the bridge

Municipal competition 5th, 6th, 7th and 8th grade

Source of the task: dms.rs — computer science for primary schools

What you need to know first: Operators in C++ Branching in a program

Task statement

In one of the tasks at a competition, young scouts have to cross a course with a movable bridge as fast as possible.

A competitor from one team needs T seconds to get from the starting point to the bridge. Exactly P seconds after he could set off from the starting point (i.e. from the start of timing), the bridge starts to rise. From the moment it rises until it is lowered, N seconds pass, and the bridge cannot be crossed during that time. After that the bridge stays down.

Competitors get negative points for waiting at the bridge, so this competitor decided to work out exactly when he should set off so that he can cross the bridge without stopping.

Write a program that reads the times T, P and N and works out after how many seconds from the start of timing the competitor should set off in order to cross the bridge as soon as possible without stopping.

Input

Three numbers are read: T, P and N.

Output

Print after how many seconds from the start of timing the competitor should set off.

Example 1

Input

T = 15 P = 20 N = 25

Output

0
Explanation

The competitor reaches the bridge after 15 seconds, and the bridge starts to rise only after 20 seconds, so he can set off straight away.

Example 2

Input

T = 15 P = 10 N = 12

Output

7
Explanation

The bridge is raised from the 10th to the 22nd second. The competitor must reach the bridge no earlier than the 22nd second, so he sets off at second 22 − 15 = 7.

TASK 11 2009.

Coloured blocks

Municipal competition 5th, 6th, 7th and 8th grade

Source of the task: dms.rs — computer science for primary schools

What you need to know first: Data in C++ Operators in C++ Branching in a program Loops

Task statement

One of the games is a guessing game. A team has to stand on coloured blocks and guess in advance the colour of the block on which the last competitor of the team will stand. The competitors stand on the blocks one after another, starting from the first, without leaving empty blocks between them.

The blocks are arranged so that at the beginning there are Z yellow blocks, then N orange blocks and then C red blocks. After that this pattern repeats.

When the competitors have lined up on the blocks and the team has guessed the colour of the block correctly, the team gets 10 points if the last competitor stood on an orange block, 7 points if he stood on a red block, and 2 points if he stood on a yellow block.

Write a program that reads the values Z, N, C and the number of competitors K in the team, and prints how many points the team earned if it guessed the colour.

Coloured blocks — a task from the 2009 municipal competition
Figure 1: Coloured blocks — a task from the 2009 municipal competition

Input

The numbers Z, N, C and K are entered.

Output

Print the number of points the team earned.

Example

Input

Z = 7
N = 4
C = 5
K = 25

Output

10
Explanation

The pattern repeats every 7 + 4 + 5 = 16 blocks. The last competitor stands on the 25th block, which is the 9th block of the second pattern. The first 7 blocks are yellow and the next 4 orange, so the 9th block is orange and the team gets 10 points.

TASK 12 2023/2024.

Perimeter of a parallelogram

Municipal competition 7th grade

Source of the task: takprog.petlja.org — the original collection of tasks

What you need to know first: Data in C++ Operators in C++

Task statement

If the perimeter of a parallelogram O is known, and that one side is d longer than the other, write a program that works out the lengths of the sides of this parallelogram.

Input

The whole number O (between 1 and 200) is entered from standard input, and then the whole number d (between 1 and 100). In every test the numbers O and d are such that the required side lengths are whole numbers.

Output

Print to standard output, on the same line, two whole numbers separated by one space. These numbers should be, in order, the whole-number lengths of the sides a and b, such that a ≤ b.

Example 1

Input

46
3

Output

10 13
Explanation

The side b = 13 is indeed 3 longer than the side a = 10, and the perimeter is 2(a + b) = 2(10 + 13) = 2 · 23 = 46.

Example 2

Input

102
1

Output

25 26
TASK 13 2023/2024.

Addresses and blocks

Municipal competition 7th grade

Source of the task: takprog.petlja.org — the original collection of tasks

What you need to know first: Data in C++ Operators in C++ Branching in a program Logical data Strings

Task statement

There are blocks of buildings on both sides of the Main Boulevard. Each block is on one side of the boulevard. Buildings with even numbers are on the right, and buildings with odd numbers on the left side of the boulevard. The numbers of buildings in the same block have the same parity and start with the same hundreds digit (their earlier digits are also equal, if there are any). The building numbers in consecutive blocks belong to consecutive hundreds (the exceptions are numbers divisible by 100, see the intervals in the picture).

          ||             ||             ||             ||
          ||             ||             ||             ||
   1-99   ||   101-199   ||   201-299   ||     ...     ||
          ||             ||             ||             ||
---> ===== Main Boulevard ============================== ...
          ||             ||             ||             ||
   2-98   ||   100-198   ||   200-298   ||     ...     ||
          ||             ||             ||             ||

If you need to get from one given address to another address in the Main Boulevard, work out whether the target address, compared with the starting one, is in the same building, in the same block, in the block across the street, in the previous block, in the next block, in the previous block across the street, in the next block across the street, or in some other block.

Input

Each of the two lines of standard input contains one natural number, not greater than 100000. The first number is the number of the building you start from, and the second is the number of the target building.

Output

Print to standard output one of the following texts (the original Serbian texts, which the tests on petlja.org check): ista zgrada (the same building), isti blok (the same block), sledeci blok (the next block), prethodni blok (the previous block), preko puta (across the street), sledeci blok preko puta (the next block across the street), prethodni blok preko puta (the previous block across the street) or daleko (far away).

Tip: to avoid typing mistakes, it is best to copy these texts into the program.

Example 1

Input

123
147

Output

isti blok
Explanation

Both numbers are odd, so the buildings are on the same side of the boulevard. Also, both numbers belong to the interval [100, 199], so the buildings are in the same block.

Example 2

Input

158
249

Output

sledeci blok preko puta
Explanation

The numbers have different parity, so the buildings are on different sides of the boulevard, i.e. the target building is in some block across the street. Since the number of the starting building belongs to the interval [100, 199], and the number of the target building to the interval [200, 299], the target building is in the next block across the street.

TASK 14 2023/2024.

Touch typing

Municipal competition 7th grade

Source of the task: takprog.petlja.org — the original collection of tasks

What you need to know first: Data in C++ Operators in C++ Branching in a program Logical data Strings Loops

Task statement

A computer science teacher is teaching children touch typing. So far they have covered only the letters in the home row (a, s, d, f, g, h, j, k, l). Write a program that helps the teacher choose from a list of words those words she can include in the practice, i.e. choose the words made only of letters from the home row.

Input

The number n (1 ≤ n ≤ 100) is read from standard input, and then n words, each containing at most 10 letters (each on a separate line).

Output

Print to standard output, on one line, the total number of words made of letters from the home row, and their total number of letters (that is the number of letters the pupils need to type in the whole practice). Separate the numbers with one space.

Example 1

Input

4
alfa
lisa
kajak
beta

Output

2 9
Explanation

The words made only of letters from the home row are alfa and kajak, and their total number of letters is 4 + 5 = 9.

Example 2

Input

3
grad
gama
delta

Output

0 0
Explanation

None of these words can be included in the practice, so both the number of words and the number of letters in them are 0.

TASK 15 2023/2024.

A volleyball match

Municipal competition 7th and 8th grade

Source of the task: takprog.petlja.org — the original collection of tasks

What you need to know first: Data in C++ Operators in C++ Branching in a program Logical data Strings The char type Loops

Task statement

Write a program that, from the list of points won since the start of a volleyball match, works out the current score.

A volleyball match is played until one team wins three sets. A set is won by the first team that wins 25 or more points, with a difference of at least 2. So a team can win a set 25:0, 25:1, ... or 25:23. The score 25:24 does not mean the end of the set, because the difference in points is not at least 2. In that case play continues until one of the teams makes a difference of at least 2 points (so 26:24, 27:25, 28:26 ...).

If it is 2:2 in sets, the last set is played not to 25 but to 15, with the other rules staying the same (there must be a difference of at least 2). When a team wins a set, from the next point a new set begins in which both teams have 0 points at the start.

How can the score 25:24 happen? This can happen if at some moment both teams have 24 points. Then the next point won will lead to 25:24 or 24:25, but that will not end the set.

Input

A string of the characters A or B is read from standard input; they show, in order, whether a point was won by team A or team B. The input data are guaranteed to be possible, i.e. if some letter marks the point that ends the match, there are no more letters after it in the input. The input string contains at least one and at most 500 characters.

Output

On the first line of standard output print the score in sets, and on the second the score in points in the current set (on each line first print the result of team A, then a colon and finally the result of team B). If the match is over, print only the score in sets, without the score in points.

Example 1

Input

AABABAABBBAAAABABBAABABAAAABBAAABABABABABABBABBA

Output

1:0
2:4
Explanation

Team A wins the first set 25:17 (the set ended when team A won its 25th point), and in the second set team B leads 2:4.

Example 2

Input

BABABABABABABABABBBABABABAAABABABABABABABABABABABABAABBABABBAAAAABBABBBAABBABABAAABABABABBBAABAAABBBBBBBAAABABBAA

Output

0:1
27:26
Explanation

Team B wins the first set 29:31. The set did not end earlier because neither team managed to make a difference of at least 2 points while also having at least 25 points. In the second set the score is currently 27:26 and the set is not over because nobody has yet made a difference of 2 points while having at least 25 points (although during the set the teams led by more than 2, they did not have at least 25 points then).

Example 3

Input

BABABABABABABABABBBABABABAAABABABABABABABABABABABABAABBABABBAAAAABBABBBAABBABABAAABABABABBBAABAAABBBBBBBAAABABBAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBABABABABABABABABABABBBBABB

Output

2:3
Explanation

Team B wins the first set 29:31. Team A wins the second set 28:26. Team A wins the third set 25:0, and team B the fourth 0:25. Team B wins the fifth set 11:15. Since the match is over, we do not print the points but only the sets.

TASK 16 2023/2024.

Baseball

Municipal competition 8th grade

Source of the task: takprog.petlja.org — the original collection of tasks

Task statement

Baseball is a very popular sport in the USA. Jack hit the ball three times and the distance it flew was measured, in the units used in the USA (yards, feet, inches). We want to know the longest hit of those three, but in units we understand (metres and centimetres). Write a program that helps us work this out.

Note: one inch is 2.54 centimetres. One foot has 12 inches, and one yard has 3 feet.

Input

The lengths of three hits are entered from standard input. For each hit a whole number of yards, feet and inches is given. The numbers are on the same line, separated by a space.

Output

Print to standard output two whole numbers separated by one space: the number of metres and centimetres of the longest hit, where the number of centimetres is rounded to the nearest whole number (which will be unambiguous in all the examples).

Example 1

Input

18 2 7
18 1 7
14 0 9

Output

17 25
Explanation

The longest hit is the one of 18 yards, 2 feet and 7 inches, which is 1724.66 centimetres. Rounding to the nearest whole number gives 1725 centimetres, which is 17 metres and 25 centimetres.

Example 2

Input

21 1 7
18 0 3
24 2 11

Output

22 83
Explanation

The longest hit is the one of 24 yards, 2 feet and 11 inches, which is 2283.46 centimetres. Rounding to the nearest whole number gives 2283 centimetres, which is 22 metres and 83 centimetres.

Solution

TASK 17 2023/2024.

Season

Municipal competition 8th grade

Source of the task: takprog.petlja.org — the original collection of tasks

Task statement

We will say that spring starts on 20 March (including that day) and lasts until 21 June (not including that day). Summer starts on 21 June (including that day) and lasts until 23 September (not including that day). Autumn starts on 23 September (including that day) and lasts until 21 December (not including that day). The other days are winter.

Write a program that works out the season from the date entered.

Input

The day is entered from standard input, and then the month (each number on a separate line). The number 1 means January, 2 February, 3 March and so on. Assume that the date entered is valid.

Output

Print to standard output the letter p (proleće – spring), l (leto – summer), j (jesen – autumn) or z (zima – winter); these are the original letters checked by the tests on petlja.org.

Example 1

Input

1
2

Output

z
Explanation

The date entered is the first of February, and it is in winter.

Example 2

Input

20
3

Output

p
Explanation

The date entered is 20 March, and we consider it to be the first day of spring.

Example 3

Input

19
3

Output

z

Example 4

Input

21
6

Output

l
TASK 18 2023/2024.

Odd even – in a circle

Municipal competition 8th grade

Source of the task: takprog.petlja.org — the original collection of tasks

Task statement

For a given natural number n, print all sequences of numbers of length 2n that meet the following three conditions:

  • they contain every number from 1 to 2n exactly once;
  • in the sequence the odd numbers come first, and then the even numbers;
  • the part with the odd numbers is obtained by rotating the sequence 1, 3, …, 2n−1, and the part with the even numbers is obtained by rotating the sequence 2, 4, …, 2n.

Rotating a sequence means moving the first element to the end of the sequence (and this can be repeated 0 or more times).

For example, for n = 3 one such sequence is 3, 5, 1, 2, 4, 6. Indeed, in it every number from 1 to 2n = 6 appears exactly once, first come the odd numbers 3, 5, 1, and then the even ones 2, 4, 6. The part 3, 5, 1 is obtained by rotating the sequence 1, 3, 5 by one position (the first element of 1, 3, 5 is moved to the end), and the part 2, 4, 6 by rotating the sequence 2, 4, 6 by zero positions.

Input

The number n (1 ≤ n ≤ 100) is read from standard input.

Output

Print to standard output all the required sequences. The sequences should be in lexicographic order (as shown in the examples): when any two printed sequences are compared, the value of the first element in which they differ must be smaller in the sequence that was printed earlier.

Example 1

Input

2

Output

1 3 2 4
1 3 4 2
3 1 2 4
3 1 4 2

Example 2

Input

3

Output

1 3 5 2 4 6
1 3 5 4 6 2
1 3 5 6 2 4
3 5 1 2 4 6
3 5 1 4 6 2
3 5 1 6 2 4
5 1 3 2 4 6
5 1 3 4 6 2
5 1 3 6 2 4