ICPC Central Russia Regional Contest, 2021
A. Puzzle generator
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Many puzzles (Sudoku, towers, etc.) require filling the square field $$$ n \times n $$$ with numbers in such a way that in each row and each column the numbers $$$ 1...n $$$ occur exactly once. For the computer construction of such puzzles, it is necessary to be able to generate a square field with the specified property.

Write a program, that given the first row, fills in the remaining cells of the table so that each row and each column contain all the numbers from $$$ 1 $$$ to $$$ n $$$.

Input

The first line contains the size of the table $$$ n $$$ ($$$ 1 \leq n \leq 100 $$$). The second line contains $$$ n $$$ numbers separated by spaces – the contents of the first row of the table. The line consists of non-repeating numbers from $$$ 1 $$$ to $$$ n $$$.

Output

Output $$$ n $$$ lines of $$$ n $$$ numbers in each – the assumed input of the table. Adjacent numbers in the line must be separated by exactly one space.

Example
Input
4
1 2 3 4
Output
1 2 3 4
2 3 4 1
4 1 2 3
3 4 1 2

B. Shooting
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Igor and Ira decided to determine the head of the family, for this they will hold an archery tournament. The tournament is held according to simple rules: each of the participants shoots $$$n$$$ times (the first participant makes all his shots, then the second). Target — a circle consisting of $$$k$$$ rings, $$$1$$$ to $$$k$$$ points are given for hitting each of them. The head of the family is the one who scores more points.

Igor has already made his $$$n$$$ shots and scored $$$p$$$ points. Now it's Ira's turn. She has already adapted to archery, and now she always hits the target, unlike Igor. Ira hits each ring with the same probability.

Help Ira determine the number of winning combinations from $$$n$$$ shots.

Input

A single line contains three integers $$$n$$$, $$$k$$$, $$$p$$$ $$$(1\leq n, k\leq 300, 0 \le p\leq k\cdot n)$$$ — the number of shots, the number of rings on the target, and the number of points scored by Igor.

Output

In a single line print a number — the number of combinations of $$$n$$$ Ira's shots at the target, such that the sum of points scored will be greater than $$$p$$$.

Output the answer modulo 1000000007$$$(10^9+7)$$$.

Examples
Input
3 3 7
Output
4
Input
5 5 6
Output
3119
Note

In the first test, there are the following combinations of Ira hitting the target, in which Ira scores more points than Igor.

$$$[2,3,3]$$$ total points: 8

$$$[3,2,3]$$$ total points: 8

$$$[3,3,2]$$$ total points: 8

$$$[3,3,3]$$$ total points: 9

C. Pisano period
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Many recurrent sequences acquire new interesting properties if they are calculated modulo of some number. Due to the finiteness of the division residues, sequences turn into cycles or loops. The Fibonacci numbers are a good example of a looping sequence. The Fibonacci sequence is defined by the recurrence relation $$$ F_i = F_{i-1} + F_{i-2} $$$, where $$$ F_0 = 0, F_1 = 1 $$$.

When calculating such a sequence taken modulo $$$ n $$$, after a certain number of steps, there is a return to the initial values of $$$ 0 $$$ and $$$ 1 $$$. The minimum number of steps required to loop the sequence is denoted as $$$ \pi(n) $$$ and is called the Pisano period. The number $$$ \pi(n) $$$ exists for any $$$ n $$$. For each $$$ \pi(n) $$$ is valid $$$ F_{i} \equiv F_{i+\pi(n)} (mod~n) $$$ with any $$$ i $$$.

The relationship between the length of the Pisano period $$$ \pi(n) $$$ and the number $$$ n $$$ itself is quite complex and comes down to calculating Pisano periods for prime numbers. For a prime number $$$ p $$$, the value of $$$ \pi(p) $$$ is calculated according to the following rules:

  1. Two special cases are distinguished: $$$ \pi(2) = 3 $$$ – the only period with an odd length, and $$$ \pi(5) = 20 $$$.
  2. If $$$ p \equiv \pm 1 (mod~5) $$$, then $$$ \pi(p) $$$ will be the divisor of the number $$$ (p - 1)$$$.
  3. If $$$ p \equiv \pm 2 (mod~5) $$$, then $$$ \pi(p) $$$ will be a divisor of $$$ (2p + 2)$$$.
It should be noted that for all primes, except 2, $$$ \pi(p) $$$ is always even. For example, $$$ 47~mod~5 = 2 $$$, and $$$ \pi(47) = 32 $$$, and the number $$$ 32 $$$ is a divisor of the number $$$ 2 \cdot 47 + 2 = 96 $$$. Or $$$ 89~mod~5 = 4 (-1) $$$, and $$$ \pi(89) = 44 $$$, because $$$ 44 $$$ is the divisor of $$$ 89 - 1= 88 $$$. Write a program that, given a prime number $$$ p $$$ ($$$ 2 \leq p \leq 10^9 $$$), calculates $$$ \pi(p) $$$ for it.
Input

A single line contains a prime number $$$ p $$$ ($$$ 2 \leq p \leq 10^9 $$$).

Output

In a single line print a number – the length of the Pisano period $$$ \pi(p) $$$.

Examples
Input
11
Output
10
Input
5
Output
20

D. Bucket of sand
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

A thin stream of sand is poured into a conical fire bucket with a height of $$$ h $$$ and an upper diameter of $$$ d $$$. The sand is poured strictly into the center of the bucket, installed vertically, and forms a pile. As soon as the top of the pile reaches the upper edge of the bucket, the process stops. Find the volume of sand poured into a bucket if it is known that the angle at the base of a pile of sand poured onto a flat surface is 34 degrees.

Input

A single line contains two integers $$$ h $$$ ($$$ 1 \leq h \leq 1000 $$$) and $$$ d $$$ ($$$ 1 \leq d \leq h $$$), separated by a space.

Output

Print a singular number – the volume of sand poured into the bucket, specified with an accuracy of $$$ 10^{-6} $$$.

Examples
Input
10 10
Output
146.39985672107267
Input
5 1
Output
1.1487958374076184
Note

Picture:

E. Brass Birmingham: coins
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Today Igor and Ira together with friends  — Sasha and Lesha — are playing a new board game "Brass Birmingham".

In each round, the players take turns making moves. During the turn, the player can build one industry per city, a road connecting two cities, or perform an action. Players pay money for all their buildings in this game, as in the real world, everything costs money. At the end of his turn, the player builds a tower of spent coins and puts it next to his figure in the payment field, and at the end of the round, the spent coins are returned to the bank.

Igor wants to start the next round as soon as possible, so he decided to optimize the process of returning money to the bank. In one operation, he collects coins of the same nominal from all the tops of the towers. How often does Igor need to repeat this operation to start a new round as quickly as possible?

Input

The first string contains an integer $$$n$$$ $$$(1\leq n\leq 30)$$$ — the number of different coin nominals.

The second string contains four integers $$$m_i$$$ $$$(1\leq m_i\leq 30, 1\leq i\leq 4)$$$ — the number of coins in the tower of the $$$i$$$ player.

The next four strings contain a description of each player's towers. The $$$i$$$ th of them contains $$$m_i$$$ integers $$$k_{ij}$$$ $$$(1\leq k_{ij}\leq n,\; 1\leq i\leq 4,\; 1\leq j\leq m_i)$$$ — the nominal value of the coin with the number $$$j$$$. The coins are numbered from bottom to top.

Output

In a single string print the number — the minimum number of operations necessary for Igor to return all the coins to the bank.

Examples
Input
5
2 2 2 2
1 1
1 2
1 3
1 4
Output
4
Input
5
3 2 3 2
1 1 1
3 2
2 2 3
4 5
Output
6

F. Brass Birmingham: cities
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Today Igor and Ira with their friends Sasha and Lesha decided to play a new board game "Brass Birmingham".

In each round, the players take turns making moves. During the turn, the player can build one industry per city, a road connecting two cities, or perform an action.

To perform an action or build something, each player has $$$K$$$ cards in their hands. There are two types of cards: cards of cities with the name of a certain city, allowing to build any industry in a given city, and cards of industries that allow to build a given industry in any city, to which there is a player's road.

Igor keeps to his strategy and wants to put a steel plant in the city of Birmingham, which has the number 1. In his opinion, if one puts a steel plant in this city, then he wins the game for sure.

According to the rules of the game, all players take turns, this time Igor will go last. In this round, all players can build either one building or a road (they do not want to do actions).

According to the rules, the player can build a building in the city:

1) If a player has a card of the corresponding city, then he plays it and discards it from his hand.

2) If the player has a card with the corresponding industry and there is either a building in this city or the road of this player leading to this city. This card is also played and discarded.

Igor understands that the other players will definitely build a steel plant in Birmingham to stop him if they have the opportunity.

Igor writes down the entire course of the game in his notebook, so he knows which cards have already left the game, as well as he knows how many cards there were originally for each city and each industry.

With what probability will Igor be able to build a steel plant in the city of Birmingham?

Input

The first string contains three integers $$$N$$$, $$$K$$$ and $$$M$$$ $$$(2\leq N \leq 10^3,1\leq K, M \leq 10^3)$$$ — the number of cities in the game, the number of cards in each player's hand, and the number of cards left in the deck.

The second string contains four integers $$$C$$$, $$$R$$$, $$$G$$$, $$$H$$$ $$$(0\leq C + R\leq 4K+M,$$$ $$$ 0\leq G\leq C,$$$ $$$0\leq H\leq R)$$$ — the number of cards remaining in the game with the city of Birmingham, the number of cards remaining in the game with the steel plant, the number of cards with the city of Birmingham in Igor's hand, the number of cards with the steel plant in Igor's hand.

The third string contains 4 integers $$$a_i$$$ $$$(0\leq a_i\leq 1,1\leq i\leq 4)$$$, $$$a_i=0$$$ means that the player $$$i$$$ does not have a road to Birmingham and buildings in this city, otherwise $$$a_i = 1$$$. Igor considers himself the number 1 player.

Output

Print one real number with an accuracy of 4 decimal places — the probability that Igor will be able to build a steel plant in the city of Birmingham.

Examples
Input
5 4 12
3 3 2 2
1 0 0 0
Output
0.50000000
Input
5 4 12
2 2 2 1
0 1 1 1
Output
0.50000000
Input
9 1 20
4 2 0 1
1 1 0 0
Output
0.51835121
Input
3 1 6
1 1 1 0
0 0 1 1
Output
0.77777778

G. Brass Birmingham: beer
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Today Igor and Ira with friends  — Sasha and Lesha — decided to play a new board game "Brass Birmingham".

In each round, the players take turns making moves. During the turn, the player can build one industry per city, a road connecting two cities, or perform an action.

In his turn, Igor wants to open as many of his factories as possible. To open one factory, the player needs to transfer exactly one barrel of "beer" to the factory, because without a barrel of "beer" it will not be possible to have a formal opening. Thus, the more barrels of "beer" Igor transfers, the more factories he will be able to open.

Barrels of "beer" are in breweries previously built by players. Each brewery has exactly one barrel of "beer".

Igor wants to use his barrels of "beer", which he has prepared earlier, to open factories. If they are not enough, then Igor will have to use the barrels of other players.

The rules of the game state that one can use barrels of "beer" from his breweries without any restrictions. If the player wants to move a barrel of "beer" from someone else's brewery to build his factory, then this action can be done only if the factory and the brewery are in the same city, or there is a road path between the brewery and the factory.

How many of his own and other people's barrels of "beer" will Igor use?

Input

The first string contains an integer $$$N$$$ $$$(2\leq N\leq 10^5)$$$ — the number of cities in the game.

The second string contains an integer $$$M$$$ $$$(1\leq M\leq 10^5)$$$ — the number of factories Igor wants to open.

The third string contains $$$M$$$ integers $$$m_i$$$ $$$(1\leq m_i\leq N)$$$ — cities where Igor wants to open factories. There may be several factories in one city.

The fourth string contains an integer $$$K$$$ $$$(1\leq K\leq 10^5)$$$ — the number of Igor's breweries.

The fifth string contains $$$K$$$ integers $$$k_i$$$ $$$(1\leq k_i\leq N)$$$ — the cities where Igor's breweries are located. There may be several Igor's breweries in one city.

The sixth string contains an integer $$$L$$$ $$$(1\leq L\leq 10^5)$$$ — the number of breweries of other players.

The seventh string contains $$$L$$$ integers $$$l_i$$$ $$$(1\leq l_i\leq N)$$$ — cities where breweries of other players are located. There may be several breweries of other players in one city.

The eighth string contains an integer $$$G$$$ $$$(1\leq G\leq 10^5)$$$ — the number of already built roads.

The following $$$G$$$ strings contain pairs of integers $$$a_i, b_i$$$ $$$(1\leq a_i,b_i\leq N)$$$ — cities that are connected by a road number $$$i$$$.

Output

In a single string print two integers separated by a space: the number of his own and the number of other people's barrels of "beer" that Igor will need.

Examples
Input
8
4
1 4 3 2
2
2 8
4
8 7 6 5
4
1 2
2 3
4 3
4 5
Output
2 1
Input
6
5
2 3 5 2 5
2
1 2
8
2 2 1 6 4 1 2 3
9
4 3
5 2
4 6
1 2
5 6
6 5
1 2
3 4
6 1
Output
2 3

H. Brass Birmingham: roads
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Today Igor and Ira with friends — Sasha and Lesha — decided to play a new board game "Brass Birmingham".

In each round, the players take turns making moves. During the turn, the player can build one industry per city, a road connecting two cities, or perform an action.

The game ended late at night, and it was time to sum up the results. Igor was in charge of counting points for building roads. Each road built by the player earns him several points equal to the total number of industries opened in the cities connected by this road.

Unfortunately, Igor accidentally knocked over the playing field so that all the cards got mixed up. Igor was disappointed. He remembered that during the game, he wrote down the actions of each player in a notebook. Help Igor count the points for the roads received by each player.

Input

The first string contains an integer $$$N$$$ $$$(2\leq N\leq 10^5)$$$ — the number of cities in the game.

Next, for each of the four players, it is indicated:

The first string contains integers $$$M_k,G_k$$$ $$$(1\leq M_k,G_k\leq 10^4)$$$ — the number of industries and the number of roads built by the $$$k$$$ player.

In the next string $$$M_k$$$ of integers $$$m_{ki}$$$ $$$(1\leq m_{ki}\leq N)$$$ — the cities where the industries of the $$$k$$$ player are located.

Then $$$G_k$$$ strings, each of which contains two integers $$$a_{ki},b_{ki}$$$ $$$(1\leq a_{ki},b_{ki}\leq N)$$$ — cities that are connected by the road of the $$$k$$$ player.

Output

Print $$$4$$$ integers separated by a space – the number of points for the roads that each player received.

Example
Input
4
1 1
1
1 2
3 1
1 2 3
2 3
4 2
1 4 2 3
3 1
4 2
1 4
3
1 3
2 3
3 4
1 2
Output
5 5 9 20 

I. Problem 3n+1
time limit per test
2.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

In 1932, Lothar Collatz formulated a seemingly simple problem that has not been solved yet. Suppose we have some number $$$ n $$$, then if it is even, we divide it by $$$2$$$, and if it is odd - multiply it by $$$3$$$ and add one. Let's call this transformation a Collatz step. The hypothesis, which has not been proven, states that after a certain number of steps, any integer turns into one. For all numbers up to $$$ 10^{22} $$$, it is proved to be true.

Denote by $$$ t(n) $$$ the number of steps necessary for the number $$$ n $$$ to turn into one, and write down the consecutive values $$$ t(1), t(2), t(3), \dots $$$: $$$ 0, 1, 7, 2, 5, 8, 16, 3, 19, 6, 14, 9, 9, 17, 17, 4, 12, 20, 20, \dots $$$

Analyzing the given sequence, you can find that it very often contains pairs of identical values, so that $$$ t(i) = t(i + 1) $$$. According to some estimates, up to half of the sequence elements form such pairs. There are also longer segments of repeating values, for example, the first triple occurs already at $$$28$$$-th place $$$ t(28) = t(29) = t(30) = 18 $$$.

Write a program that, on an interval of length $$$ w $$$, starting with the element $$$ s $$$, finds the longest segment of the same values $$$ t() $$$. If there are several such segments, then you need to find the leftmost of them (with the minimum first element). Elements falling outside the range $$$ [s, s + w - 1] $$$ are not taken into account.

Input

A single line contains two integers $$$ s $$$ ($$$ 1 \leq s \leq 10^{10} $$$) and $$$ w $$$ ($$$ 1 \leq w \leq 10^6 $$$) separated by a space.

Output

In a single line print two integers separated by a space: $$$ l $$$ is the length of the segment, $$$ x $$$ is its beginning. The segment $$$ [x, x + l - 1] $$$ must belong entirely to the interval $$$ [s, s + w - 1] $$$.

Example
Input
1 50
Output
3 28
Note

On a segment of $$$50$$$ numbers starting with $$$1$$$, there are 6 pairs: $$$ t(12) = t(13) $$$, $$$ t(14) = t(15) $$$, $$$ t(18) = t(19) $$$, $$$ t(20) = t(21) $$$, $$$ t(22) = t(23) $$$, $$$ t(34) = t(35) $$$ and $$$3$$$ triples: $$$ t(28) = t(29) = t(30) $$$, $$$ t(36) = t(37) = t(38) $$$, $$$ t(44) = t(45) = t(46) $$$. From the triple $$$ t(49) = t(50) = t(51) $$$, only $$$2$$$ values fall into the interval, forming a "virtual" pair $$$ t(49) = t(50) $$$. The leftmost of the triples is the triple that starts at $$$ 28 $$$.

J. Interesting numbers
time limit per test
2 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output

Professor Sh. has recently become interested in number theory. In particular, he was very interested in the decomposition of a number into prime factors. Recall that a natural number is called a prime number if it has exactly two distinct natural divisors: 1 and the number itself. Professor Sh. calls a number N interesting if it can be presented as a product of exactly six pairwise distinct primes. Unfortunately, the professor does not know how to check too large numbers for interest.

Help Professor Sh. – write a program that based on a given number N will find if it is interesting.

Input

A single line contains an integer N (2 ≤ N ≤ 1018).

Output

In a single line print " - 1" if the number is not interesting, or 6 prime numbers in ascending order – the divisors of the number N.

Examples
Input
2
Output
-1
Input
3
Output
-1
Input
6
Output
-1

K. To-do list
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Igor wants to improve self-organization, so he decided to make a huge to-do list and a plan that he will stick to for $$$k$$$ days.

There were $$$n$$$ tasks in the list. Igor considered it necessary to repeat the task number $$$i$$$ from this list after $$$a_i$$$ days to develop a habit. Having decided on the list and the frequency of repetition of tasks, Igor immediately completed all tasks from the list, only to repeat them in the future. Therefore, he was very tired and completely forgot to make a plan for the next $$$k$$$ days.

Help Igor make a plan by specifying for each of the following days the number of tasks that Igor needs to complete.

Input

The first line contains two integers $$$n$$$, $$$k$$$ $$$(1\leq n,k\leq 10^5)$$$ — the number of tasks in Igor list and the number of days during which Igor wants to stick to the plan.

The second line contains $$$n$$$ integers $$$a_i$$$ $$$(0\leq a_i\leq 10^5,1\leq i\leq n)$$$ — the number of days after which it is necessary to repeat the $$$i$$$ th task.

Output

In a single line print $$$k$$$ numbers $$$m_j$$$ separated by a space. $$$m_j$$$ — the number of tasks planned by Igor for $$$j$$$ th $$$(1\leq j\leq k)$$$ day.

Examples
Input
2 10
1 2
Output
0 1 1 1 0 2 0 1 1 1 
Input
2 6
0 1
Output
1 2 1 2 1 2 
Input
3 15
1 2 3
Output
0 1 1 2 0 2 0 2 1 1 0 3 0 1 1 

L. Permutations and sums
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Working with permutations of numbers from $$$ 1 $$$ to $$$ n $$$, programmer Vasya noticed that some of them have interesting properties. For example, in the permutations "3 1 2" and "3 2 1", the first element is equal to the sum of all other elements. In the permutation "1 2 3 4 5" already the concatenation (attribution of one number to another) of the first two elements is equal to the sum of the remaining ($$$ 12 = 3 + 4 + 5 $$$). Vasya wondered: is it possible for any $$$ n $$$ to find such a permutation of the numbers $$$ 1..n $$$ that the first element, or the concatenation of the first two, will be equal to the sum of the remaining ones?

Write a program that, based on a given number $$$ n $$$, finds which elements need to be put at the beginning of the permutation so that either the first element or the concatenation of the first two will give the sum of all the remaining ones. If there are no such elements, then the program should report the absence of a solution.

Input

The single string contains the number $$$ n $$$ ($$$ 1 \leq n \leq 10^{9} $$$) – the number of elements in the permutation.

Output

In a single string print $$$ 0 $$$ if there is no solution. If there is one element that is equal to the sum of the remaining ones, then print two numbers separated by a space: "1" and the found element. If there are two elements, whose concatenation gives a number equal to the sum of the remaining elements, print "2", and then two numbers separated by a space – two elements in the order in which they need to be attributed to each other.

Examples
Input
3
Output
1 3
Input
5
Output
2 1 2
Input
2
Output
0

M. Three cushion carom
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There are two billiard balls on a carom table (billiard table without pockets) with length of $$$ l $$$ and width of $$$ w $$$. The balls are located at the points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$, where $$$ 1 \leq x_i \lt l, 1 \leq y_i \lt w $$$, and the coordinate axes go along the sides of the table (the abscissa axis is along the "long" side, the ordinate axis is along the "wide"). It is necessary to get the first ball into the second, contacting exactly three rail cushions. For simplicity, we will assume that the balls are points, the angle of reflection of the ball does not depend on the force of impact and is equal to the angle of hitting the cushion. When the ball hits exactly the corner, it is reflected strictly in the opposite direction, and it is considered that the ball hit both cushions forming the corner. A hit is considered to be an exact match of the coordinates of the points. Write a program that calculates the impact of the first ball, which, after reflecting off the rail cushions three times, hits the second one, and overcomes the minimum distance at the same time.

Input

The first string contains two integers $$$ l $$$ and $$$ w $$$ ($$$ 2 \leq l, w \leq 1000 $$$) separated by a space. The second string contains four integers: $$$ x_1, y_1, x_2, y_2 $$$, separated by spaces – the positions of the first and second balls, respectively ($$$ 1 \leq x_i \lt l, 1 \leq y_i \lt w $$$).

Output

Print a single number with an accuracy of $$$ 10^{-6} $$$ – the length of the trajectory of the optimal impact.

Example
Input
16 3
1 1 7 1
Output
10.00000000
Note

Optimal impact for the Example:

(1, 1) $$$\rightarrow$$$ (0, $$$\frac{1}{4}$$$) $$$\rightarrow$$$ ($$$\frac{1}{3}$$$, 0) $$$\rightarrow$$$ ($$$4\frac{1}{3}$$$, 3) $$$\rightarrow$$$ (7, 1)

Picture:

Statement is not available in English language
N. Очередная задача на массиве
ограничение по времени на тест
2 секунды
ограничение по памяти на тест
256 мегабайт
ввод
стандартный ввод
вывод
стандартный вывод

Помимо теории чисел и строковых алгоритмов Профессор Ш. любит заниматься массивами, но не простыми, а отсортированными по неубыванию элементов. Сегодня Профессор Ш. придумал отличную задачу и делится её формулировкой с вами.

Изначально имеется массив $$$a$$$, состоящий из $$$N$$$ чисел, элементы которого расположены в порядке неубывания. К данному массиву можно применять запросы $$$2$$$ типов:

  1. Сдвинуть массив циклически влево или вправо на $$$k$$$ позиций.
  2. Проверить, есть ли в массиве число $$$x$$$. Если такое число есть, вывести его номер в массиве (возможно, измененном). Если число входит в массив несколько раз, следует вывести номер его первого вхождения в массив.

Так как Профессор Ш. умеет работать только с отсортированными массивами, он не всегда умеет проверять, есть ли в массиве число $$$x$$$. Помогите Профессору – напишите программу, которая будет верно отвечать на запросы обоих типов.

Входные данные

В первой строке содержится число $$$N$$$ $$$(1 \le N \le 2 \cdot 10^5)$$$ – количество элементов массива.

Во второй строке содержатся $$$N$$$ чисел $$$a_i$$$ $$$(-10^{18} \le a_i \le 10^{18})$$$ – элементы массива $$$a$$$. Гарантируется, что изначально элементы массива отсортированы по неубыванию.

В третьей строке содержится число $$$Q$$$ $$$(1 \le Q \le 3 \cdot 10^5)$$$ – количество запросов.

В следующих $$$Q$$$ строках содержатся запросы. Запросы задаются следующим образом:

  1. $$$s~k$$$ $$$(1 \le |k| \lt N)$$$ – сдвинуть массив циклически на $$$k$$$ позиций. Если число $$$k$$$ отрицательное, то сдвиг осуществляется влево, в противном случае сдвиг должен быть осуществлён вправо.
  2. $$$?~x$$$ – проверить, есть ли в массиве число $$$x$$$.
Выходные данные

Для каждого запроса вида «$$$?~x$$$» выведите в отдельной строке число – номер числа $$$x$$$ в массиве. Если числа $$$x$$$ в масиве нет, в отдельной строке выведите «$$$-1$$$». Считается, что элементы массива нумеруются с $$$1$$$.

Примеры
Входные данные
7
1 2 3 4 5 6 7
7
? 9
s 2
? 4
s -2
? 3
s -5
? 6
Выходные данные
-1
6
3
1
Входные данные
7
1 1 2 2 3 3 4
7
? 9
s 2
? 4
s -1
? 2
s -5
? 1
Выходные данные
-1
2
4
4
Примечание

Рассмотрим первый пример.

Изначально массив $$$a = [1, 2, 3, 4, 5, 6, 7]$$$.

  1. Так как число $$$9$$$ больше любого элемента массива $$$a$$$, выведем $$$-1$$$.
  2. После запроса $$$s~2$$$ нужно сдвинуть массив вправо на $$$2$$$ позиции, он станет равен $$$[6, 7, 1, 2, 3, 4, 5]$$$.
  3. Число $$$4$$$ находится на позиции $$$6$$$, поэтому выводим $$$6$$$.
  4. После запроса $$$s~-2$$$ массив примет исходный вид $$$[1, 2, 3, 4, 5, 6, 7]$$$
  5. Число $$$3$$$ находится на позиции $$$3$$$, поэтому выводим $$$3$$$
  6. После запроса $$$s~-5$$$ массив сдвигается на $$$5$$$ позиций влево: $$$[6, 7, 1, 2, 3, 4, 5]$$$
  7. Число $$$6$$$ находится на позиции $$$1$$$, поэтому выводим $$$1$$$.

O. Sea Battle
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Professor Sh. is quite old, he has a grandson named Vlad, who studies at the Golovda State University. To prevent exhaustion from studying, sometimes one needs to take a break from it. Vlad does not waste time on stupid computer games, spending all his free time playing "Sea Battle" against his grandfather.

The idea of the game is the following: there is a grid of $$$10 \times 10$$$, on which $$$10$$$ ships are placed: $$$4$$$ single-deckers, $$$3$$$ double-deckers, $$$2$$$ three-deckers and $$$1$$$ four-decker, ships on the grid can only be placed horizontally or vertically. Vlad is a virtuoso of this game, so he never loses. We are only interested in the events that take place on the grid of Professor Sh. During the game, Vlad can query the following commands:

  1. command "SHOT $$$X~Y$$$" - shoot into a square with coordinates $$$(X, Y)$$$ $$$(1 \le X \le 10, 1 \le Y \le 10)$$$.
  2. command "SHOW" - output the number of undamaged, hit, and sunk ships on the grid of Professor Sh.
Your task is the following: according to the command log conducted by Vlad, restore the picture of the battle.
Input

The first $$$10$$$ input lines contain $$$10$$$ elements describing the opponent's grid before the start of the game: if the $$$j$$$ -th element of the $$$i$$$ -th line is equal to "#", this means that the square with coordinates $$$(i, j)$$$ contains a fragment of a ship, the symbol "*" means that there is "sea" in this square.

The $$$11$$$ input line contains the number $$$q$$$ ($$$1 \le q \le 100$$$) – the number of commands that Vlad requested. It is guaranteed that the ships are placed correctly on the grid, they do not intersect each other.

The following $$$q$$$ strings contain commands of the $$$2$$$ types that Vlad requested.

Output

For each query "SHOW" print $$$3$$$ numbers in a separate line in the following order: the number of undamaged, hit, and sunk ships on Professor Sh's grid.

Example
Input
*******#**
*####****#
*********#
****#*#***
******#***
*##*******
********#*
*#******#*
*****#**#*
###*******
5
SHOW
SHOT 1 8
SHOW
SHOT 9 9
SHOW
Output
10 0 0
9 0 1
8 1 1