Micromasters


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

Recently, the Computer Engineering Department has launched its professional education under the title of “Micromasters”, which has been well received by audiences from various universities. Undoubtedly, the quality of these classes played a significant role in this reception. One of the quality factors is to limit the number of registrations for a class. Although the registration for this semester has ended, the director of professional education has decided to limit the number of registrations for each class to 50 and make an urgent decision for the classes with more than 50 students registered. Help the director of professional education to identify which classes have more than 50 students registered.

ورودی🔗

The only line of the input consists of nn (1n100)(1 \leq n \leq 100), the number of registrations in a class.

خروجی🔗

In the only line of output, Print Yes if n>50n > 50, and No otherwise.

ورودی نمونه ۱🔗

45
Plain text

خروجی نمونه ۱🔗

No
Plain text

ورودی نمونه ۲🔗

50
Plain text

خروجی نمونه ۲🔗

No
Plain text

ورودی نمونه ۳🔗

78
Plain text

خروجی نمونه ۳🔗

Yes
Plain text

Sara and Horse


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

Sara, who is deeply concerned about air pollution, has sold her car and bought a horse. She happily leads the horse to the parking lot and takes a very long string of pasta from the kitchen, which she gives to the horse. The horse happily takes several bites of pasta. Sara’s father, who notices the disappearance of the pasta string, finds the remaining pieces of pasta in the parking lot. Being an intelligent person, he knows that the horse selects a piece of pasta longer than 3 inches for each bite. Then, by biting 3 inches from the middle of the selected piece, she divides it into two pieces.

Given the lengths of the remaining pasta pieces, help Sara’s father determine the length of the initial pasta string.

ورودی🔗

The first line of the input contains an integer nn (1n100)(1 \leq n \leq 100), which is the number of remaining pasta pieces. The next line contains a sequence l1,l2,,lnl_1, l_2, \dots, l_n of nn integers, where lil_i (1li1000)(1 \leq l_i \leq 1000) represents the length of the ii-th remaining pasta piece.

خروجی🔗

In the only line of output, print the length of the initial pasta string.

ورودی نمونه ۱🔗

2
2 5
Plain text

خروجی نمونه ۱🔗

10
Plain text

ورودی نمونه ۲🔗

2
2 5
Plain text

خروجی نمونه ۲🔗

10
Plain text

The Niece


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

Sara wants to entertain her niece with nn coins she has in her pocket. To do this, she arranges a game. In this game, several coins should initially be placed on the table. Then, in each turn, a player must remove either 11 or exactly 44 coins from the table and pass the turn to the other player. The winner is the person who takes the last coin or coins. Sara, due to her love for her niece, allows her niece to start the game. Help Sara determine whether she can definitely win the game by placing all her coins on the table or not.

ورودی🔗

The input consists of a single integer nn (1n1018)(1 \leq n \leq 10^{18}), which represents the number of coins Sara has.

خروجی🔗

In the only line of output, print Yes if Sara has a guaranteed winning strategy, and No otherwise.

ورودی نمونه 1🔗

1
Plain text

خروجی نمونه 1🔗

No
Plain text

ورودی نمونه 2🔗

2
Plain text

خروجی نمونه 2🔗

Yes
Plain text

Binary Majid


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

Majid has a binary string of length nn with only 1 values. One morning, his niece accidentally finds this string and starts destroying it. She destroys the string in tt steps. The niece first chooses a sequence of integers: 1a1a2atn1 \leq a_1 \leq a_2 \leq \dots \leq a_t \leq n. Then, in the ii-th step, she selects the first aia_i bits and destroys this part as follows:

  • First, she negates all the selected bits.
  • Then, she reverses the order of the selected part.

To be more precise, if the binary string before the ii-th step is as follows:

S=s1s2,,snS = s_1 s_2, \dots, s_n

The binary string after the ii-th step will be as follows, where sˉi\bar{s}_i represents the negation of bit sis_i:

S=sˉai,sˉai1,,sˉ1,sai+1,,snS = \bar{s}_{a_i}, \bar{s}_{a_i-1}, \dots, \bar{s}_1, s_{a_i+1}, \dots, s_n

Majid wants to restore the string to its initial state using his superpower. Each time Majid uses his superpower, he chooses two numbers 1lrn1 \leq l \leq r \leq n. Then, magically, all the bits in positions from ll to rr inclusive are negated. This interval includes the bits at positions ll and rr themselves. The positions of the bits are considered from left to right, and the leftmost bit has a position of 11.

Help Majid restore the string to its initial state with the fewest number of uses of his superpower.

ورودی🔗

The first line of the input consists of two integers nn (1n1018)(1 \leq n \leq 10^{18}) and tt (1t105)(1 \leq t \leq 10^5) separated by a space, which is the length of the string and the number of steps of string destruction, respectively.
The second line contains a sequence of integers a1,a2,,ata_1, a_2, \dots, a_t (1ain)(1 \leq a_i \leq n), chosen by the niece.

خروجی🔗

Print kk, the minimum number of times Majid needs to use his superpower in the first line.
Then, in the (i+1)(i+1)th line (1ik)(1 \leq i \leq k) of the output, print the interval that Majid chooses in his use of superpower as two numbers separated by a space, in ascending order.

ورودی نمونه 1🔗

5 2
2 5
Plain text

خروجی نمونه 1🔗

1
1 3
Plain text

ورودی نمونه 2🔗

5 2
3 3
Plain text

خروجی نمونه 2🔗

0
Plain text

Ants’ Movements


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

Anumber of ants are located on a two-dimensional plane, and each ant moves either upward or rightward. In each step, each ant moves one unit forward in its direction. More precisely, consider an ant located at coordinates (xi,yi)(x_i,y_i) before the ithi-th step. If the ant moves upward, its coordinates after the ithi-th step will be (xi,yi+1)(x_i,y_i + 1), and if it moves rightward, its coordinates after the ithi-th step will be (xi+1,yi)(x_i + 1,y_i). Initially, no two ants are located at the same coordinates. If two ants collide at the same coordinate in a step, before the next step begins, their movement direction changes from up to right and from right to up. Sara is curious to know the total number of collisions. Given the initial coordinates of the ants and their directions of movement, calculate the total number of collisions for Sara.

ورودی🔗

The first line of the input contains an integer nn (2n2105)(2 \leq n \leq 2*10^5), which is the the number of ants. Then, for each 1in1 \leq i \leq n, the (i+1)th(i+1)th line of the input contains two space-separated integers xix_i and yiy_i (1xi,yi109)(1 \leq x_i,y_i \leq 10^9), and one of the letters U or R. The integers denote the initial coordinates of the ithi-th ant, and the letter indicates the initial direction of movement. The letter U represents upward movement, and the letter R represents rightward movement.

خروجی🔗

In the only line of output, print the total number of collisions if it is finite, and the word inf otherwise.

ورودی نمونه 1🔗

3 
1 2 R
2 1 U
3 1 U
Plain text

خروجی نمونه 1🔗

1
Plain text

ورودی نمونه 2🔗

4 
1 4 U 
1 2 U 
1 3 U 
1 1 U
Plain text

خروجی نمونه 2🔗

0
Plain text

Birthday Party


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

Sara wants to hold a birthday party for her niece. In this ceremony, the guests form a circle around the niece and cheer her up. But the problem is that the heights of the guests present at the birthday party is very different. Therefore, if these guests are randomly placed in the circle, due to the difference in height, they may not be able to hold each other’s hands and form the ring. The desired arrangement is a circular arrangement of guests in which the maximum height difference between consecutive individuals is minimum (there may be more than one desired arrangement). For example, if the heights of guests are 3,2,2,4,3,13,2,2,4,3,1, one desired arrangement could be as follows, where the maximum height difference between consecutive individuals is 11.

توضیح تصویر

By receiving the heights of guests, calculate the maximum height difference between consecutive individuals in a desired arrangement.

ورودی🔗

The first line of the input contains an integer nn (2n105)(2 \leq n \leq 10^5), which is the the number of guests. The next line contains a sequence l1,l2,...,lnl_1,l_2,...,l_n of nn integers, where lil_i (1li109)(1 \leq l_i \leq 10^9) represents the height of the ithi-th guests.

خروجی🔗

In the only line of output, print the maximum difference in height between two consecutive individuals in a desired circular arrangement.

ورودی نمونه 1🔗

5
2 1 1 3 2
Plain text

خروجی نمونه 1🔗

1
Plain text

ورودی نمونه 2🔗

3 
30 10 20
Plain text

خروجی نمونه 2🔗

20
Plain text

Arranging Bricks


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

Majid has nn cubic bricks with a unit side length. He wants to arrange these bricks as adjacent columns, such that the height of each column is not less than the height of the previous column. For example, if Majid has two bricks, he can arrange them in two ways. In the first arrangement, he can form a column with a height of 22, and in the second arrangement, he can create two columns with heights of 11 each. Majid wants to know in how many ways he can do this. Given nn, calculate the number of possible desired arrangements.

ورودی🔗

The input consists of a single integer nn (1n2000)(1 \leq n \leq 2000), which represents the number of bricks Majid has.

خروجی🔗

Print a single line containing the number of desired arrangements of the bricks. Since this number can be very large, print its remainder modulo 109+710^9 + 7.

ورودی نمونه 1🔗

1
Plain text

خروجی نمونه 1🔗

1
Plain text

ورودی نمونه 2🔗

2
Plain text

خروجی نمونه 2🔗

2
Plain text

Exiting the Matrix


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

After facing numerous challenges, Majid succeeded in escaping from the matrix. Upon exiting the matrix, he finds himself in an elevator on the sths-th floor of a building with ff floors. Majid quickly realizes that this elevator is not an ordinary one. The elevator has only two buttons: Up and Down. By pressing these buttons, the elevator moves uu floors up or dd floors down. Specifically:

  • After pressing Up button, if c+ufc+u \leq f, the elevator goes to floor c+uc+u. Otherwise, the elevator remains stationary.
  • After pressing Down button, if c-d \leq 1, the elevator goes to floor cdc-d. Otherwise, the elevator remains stationary. The only way to exit the building is the gthg-th floor. Since exiting the elevator shouldn’t be easy, each time Majid presses either the Up or Down button, he has to pay a high cost. Shocked by the conditions, Majid asks you to calculate the minimum cost for him to exit the building.

ورودی🔗

In the only input line, you are given integers ff, ss, gg, uu, and dd separated by a space from left to right (1s,gf106,0u,d106)(1 \leq s,g \leq f \leq 10^6, 0 \leq u,d \leq10^6).

خروجی🔗

In the only line of output, print the minimum number of times Majid needs to press the elevator buttons to exit the building. If it is impossible to reach from floor ss to floor gg using the elevator, print use the stairs.

ورودی نمونه 1🔗

10 1 10 2 1
Plain text

خروجی نمونه 1🔗

6
Plain text

ورودی نمونه 2🔗

100 2 1 1 0
Plain text

خروجی نمونه 2🔗

use the stairs
Plain text

Planting Flowers


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

As spring arrives, Majid plans to beautify his backyard by planting flowers. To achieve this, he has divided his backyard into an m×nm×n grid and has decided to plant red or blue roses in each cell. Majid has a keen eye for colour combinations and wants to ensure that each cells has at most one neighboring cell of the same color. Two cells are considered adjacent if they share at least one side. Given m and nn, calculate the number of desired ways to arrange the flowers in the grid for Majid. For example, if the dimensions of the grid are 2×32\times3, there are 88 possible ways to arrange the flowers in the grid as shown below:

توضیح تصویر

ورودی🔗

The first line of the input consists of two integers mm (1m105)(1 \leq m \leq 10^5) and nn (1n105)(1 \leq n \leq 10^5) separated by a space, which is the number of rows and the number of columns, respectively.

خروجی🔗

Print a single line containing the number of desired ways to plant the flowers. Since this number can be very large, print its remainder modulo 109+710^9 + 7.

ورودی نمونه 1🔗

2 3
Plain text

خروجی نمونه 1🔗

8
Plain text

ورودی نمونه 2🔗

1 2
Plain text

خروجی نمونه 2🔗

4
Plain text

Travel


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

The subway system in Barareh consists of nn stations and mm subway lines. The stations are numbered from 11 to nn. Each line is managed by a company and each company has a unique identifier. The ithi-th subway line (1im)(1 \leq i \leq m) is managed by company cic_i and connects only two stations, pip_i and qiq_i, in both directions. When arriving at a station, if more than one subway line is connected to that station, passengers can easily switch between lines. The cost of using the subway in Barareh is a bit different.

When a passenger uses only subway lines operated by a single company, he only need to pay 11 Bararehian dollar. However, if a passenger changes their subway line at a station, and these two lines are managed by different companies, he have to pay an additional 11 Bararehian dollar. In other words, the passenger pays 11 Bararehian dollar at the first station, and then at each intermediate station, they only need to pay an additional 11 Bararehian dollar if the two lines used for arriving and departing the station belong to different companies.

Calculate the minimum cost required to travel from station 11 to station nn.

ورودی🔗

The first line of the input consists of two integers nn (2n105)(2 \leq n \leq 10^5) and mm (0m2105)(0 \leq m \leq 2*10^5) separated by a space, which is the number of stations and the number of subway lines, respectively. Then, for each 1im1 \leq i \leq m , the (i+1)th(i + 1)-th line of input contains three integers pip_i, qiq_i, and cic_i (1ci106)(1 \leq ci \leq 10^6), separated by a space (piqi,1pi,qin)(p_i \neq q_i, 1 \leq p_i,q_i \leq n).

خروجی🔗

In the only line of output, if it is impossible to travel from station 11 to station nn using the subway lines, print 11. Otherwise, print the minimum cost required to travel from station 11 to station nn.

ورودی نمونه 1🔗

3 3 
1 2 1 
2 3 1 
3 1 2
Plain text

خروجی نمونه 1🔗

1
Plain text

ورودی نمونه 2🔗

8 11 
1 3 1 
1 4 2 
2 3 1 
2 5 1 
3 4 3 
3 6 3 
3 7 3 
4 8 4 
5 6 1 
6 7 5 
7 8 5
Plain text

خروجی نمونه 2🔗

2
Plain text

In the example above, initially, one can traverse the following path by paying 11 Bararehian dollar: 1>3>2>5>61->3->2->5->6 Then, with another 11 Bararehian dollar payment, continue the path as follows: 6>7>86-> 7 ->8.