Shengdebao had grown tired of the everyday life he had, so he decided to write down a set of letters around a circle. Mehrdad also had a string made up of lower case English letters. Shengdebao then decided to start from one letter on that circle and go around it in clockwise direction.
If at any point of time the string that Shengdebao makes by turning around the circle becomes equal to the one Mehrdad has, Mehrdad is obligated to give Shengdebao a prize! (or *"Shirini"* as they call it!)
Shengdebao wants to know whether he can or cannot receive a prize, and for that reason he has asked you to help him solve this problem.
In the first line of the input string is given that is actually the string written around the circle. In the second line string is given which is Mehrdad's string.
Both strings are made up of lower case English letters.
In the only line of output print "Yes" if Shengdebao can receive the prize and "No" if not.
Explanation: by starting from the 4th character the string can be made.
Mr. , , and have decided to organize a programming contest so Shengdebao can take part in it! To make the contest they have to arrange a meeting and talk today but they are quite tired and decided to start a video chat instead.
For the video chat to be beneficial they have to talk constantly for exactly 15 minutes and to do this their computer systems should be plugged and have electricity.
The thing is , and live in different locations of the city and due to the over usage of electricity the power department of the city cuts down the power of various locations in some time intervals.
For these three people we know exactly when their power will be cut! You should find out exactly the first time they can start their video chat meeting for 15 minutes. To clarify, you should say the starting time of the 15 minutes interval which all of the three have power and can start the video chat that also ends until 12:00 am!
The input contains 3 lines each denoting the intervals in which they don't have any electricity. The first, second and third line indicates the times for , and in the same order. In each line a number is given and afterwards strings are given in the format each string is a given time with being the hour being the minute and being the second. This means from the time between the first and second , rd and th , th and th , ... , and that particular person does not have power.
If there is not any power from second to second it means the interval is inclusive meaning there is no electricity from the beginning of second till the end of second in the interval .
The given , and all have 2 digits for example for representing 6 o'clock in the format it should be written as
Output the first time they can have that meeting in the format, meaning they can start talking for 15 minutes in hour minute and second . If they cannot talk for 15 at all you should output "".
Shengdebao has recently created a bank account, and being a cautious fellow, he wants to make sure of the bank's security policies.
Financial experts have come up with a new formula to calculate the amount of security in a bank account. They introduce the amount of security as a quantity represented by a number, this number is calculated as follows:
If a bank has doors and seats this value is equal to the number of ways to choose distinct numbers from to so that if we write the pairwise difference between any two (the difference between numbers and is expressed as ) values (which will be exactly values), the gcd (greatest common divisor) of every pair of these integers will be or in other words these values must be pairwise coprime!
Shengdebao was quite surprised by the formula and could not find the relevency between this and the security, but who is he to question the experts! So he started counting the number of doors and seats in his bank.
Given the number of doors and seats, help him calculate the amount of security in his bank account.
In the only line of input the values (number of doors) and (the number of seats) are given in the same order.
Output only one line the security of the bank. Since the number can be quite large output it modulo .
Explanation: In this test if we choose three distinct numbers in anyway the conditions will be satisfied.
For example by choosing 1 , 2 and 4 the differences will be equal to 1 , 2 and 3 which are pairwise coprime.
Explanation: Any pair of numbers chosen will only make exactly one difference which satisfies the criteria.
It is the well-known annual day *"Tavalbao"* , Shengdebao's birthday!
In his birthday he has received gifts from all his friends and relatives. One particular present appeared the most interesting, A digraph (Directed Graph) which has vertices and directed edges. On vertex number is written. After his birthday party Shengdebao got bored and started traversing the graph. He decided to start from an arbitrary vertex and start traversing some edges in their directions. While doing so, he wanted to keep track of a number . Initially number is equal to (the label written on the starting vertex) after passing an edge he will write after the last digit of .
For example if he starts from vertex with label and goes to vertex with label we will have .
He intends to traverse over a walk (this walk can contain repeated edges or vertices) and write down number so that has exactly digits, since is his favorite number, and between all the available ways, should be maximized.
You're Shengdebao's friend so give the guy a hand and help him!
In the first line numbers are given denoting the number of vertices , edges and Shengdebao's favorite number in order.
Next line contains integers one after another, th integer is equal to . (the number written on vertex )
Afterwards lines each consisting of two integers are given showing edge exists in the graph.
The graph can contain loops or multiple edges.
In the only line of output display the digit number that is maximized.
Display if no answer exists!
Shengdebao is quite a dreamer, thereby dreams a lot! In a dream he had last night people built a whole city named *"Shengdepolis"* in his favour! For the opening of this magnificent city people invited him on a tour expressing the city's impressive features. Shengdebao started describing it for you:
I entered the city and the first thing I noticed was towers, some of them were glowing with a beautiful purple light. There were some elevated railroads between some pairs of towers, each railroad was between two distinct towers. Some of the railroads were magical meaning they could disappear! The highlighted thing was the city's diverse architecture. The lighting of the towers were related to the visible railways. By paying close attention I found out that at any point of time a tower glows purple only when there are Odd number of visible railroads connected to them. Some of the railways aren't magical and so are always visible, these railroads are always counted in their adjacent towers.
Their tour program was also interesting! The tour contained a set of turns, in each turn I start by observing the city from a purple luminous tower. A helicopter then comes and takes me to another glowing tower. In both before and after the trip with the helicopter I take a glance at the landscape. Then after I've took a glance at the landscape on the second tower, the magic happens! some of the magical railroads appear and some disappear, leading to a change in the city's lighting (it is possible that the city doesn't change at all), but the change must be in a way that the tower I'm on top of stays luminous (meaning odd number of visible railways should stay connected to it). After the change, the turn ends starting a new turn afterwards or ending the tour. These turns start from one Tower and should end at the same tower.
I remember agreeing to this tour in two conditions:
For all possible ways of architectures (meaning the ways which magical railways are visible or not) and every glowing tower in that form I should have a view of the city from the top of that tower. meaning if we have magical railways, for all possible city formats and each glowing tower in every format I should have at least one glance of that landscape in either before or after my trip with the helicopter in a turn.
The number of *"turns"* should be minimized.
The story ends!
Shengdebao has an identical memory and remembers each detail about the magical city. But he didn't keep track of the number of turns in his tour so you should help him find out a valid tour with minimum size. Also if the number of turns in the dreamy tour is more than the fact that Shengdebao is lying about his dream is in prospect! so if there is no tour with less than turns, you should say he is lying!
In the input Shengdepolis is given. First line contains the number of towers and railways respectively. Then in the next lines the explanation of each railroad is given by three integers . is either or if it is it means that the railway between towers number and is not magical and if then it is magical.
It is possible for two railways to be exactly the same.
In the first line of output you should write the minimum number of turns in the imaginary tour represented as a number . Then if is greater than you should display *"lie"* and end the program. If the condition holds you should output lines each consisting of 3 integers . represents the tower on which Shengdebao starts that turn and shows the one which he ends at after riding the helicopter. is a code showing the architecture of the city. A code of a city format is described below:
is a number less than that when written in the binary notation the th bit is either equal to or if it is equal to it means that the th edge is invisible in this form and otherwise this bit is . The number of each edge is in the order appeared in the input. By this explanation there does not exist any in which its th bit is with also the first integer in the th line of input being at the same time.
To clarify, in each line and both have Odd number of visible railways connected to them in the format coded as . The th line's third number should be equal to the th line's first number and the first number of the first line should be equal to the last number of the th line.
If there are multiple tours satifsying the criteria, you can output an arbitrary one.
Explanation: No railroad is magical so always towers and have visible adjacent railroads and they are always visible and the code is always (both railways are visible). By considering that the tour should contain the only architecture from both scenes from tower and , and also the fact that we should return to the same tower, its best to go from to and return back to again.
Science grows faster nowadays more than ever and scientific achievements increase more and more! One of the greatest achievements in the field of nano technology is being made by a company founded by Shengdebao's brother. The company's name is *"BAOCompany"* and their new project revolves around tiny ants called nano-ants. Here's some details about them:
Nono-ants should be kept in a form of prism with a regular -sided polygon base with the height of meters it means if we look at the prism from above we will see a regular sided polygon and if we put it on the ground it will be meters high. The vertical edges of the prism are numbered from to in clockwise order. There exists a special nano-needle that can put delicate holes on the edges of the prism with nano-meter accuracy. After creating each hole exactly one nano-ant can occupy that hole. In fact each hole can be represented by two integer numbers such that and meaning the hole is on the th edge and in height nano-meters.
Baoium, the material used to make the prism, is quite fragile and can't have more than holes on it. Also at the beginning the prism has exactly one hole placed on each edge.
Nano-ant movements are impressive! Their movements are in the form of -patrols each -patrols takes days. At the morning of everyday the ant starts from one hole on an edge, the ants takes a peek from the hole to the next edge in clockwise order and chooses the closest to it. If multiple closest holes exists, he chooses one with the lowest height. Then he starts traversing the intended side through a straight line. Nano-ants are tiny so it takes them one day to pass that side and when they reach the next hole in the next edge they become tired and rest in that hole for the night starting tomorrow morning from that hole again. Now in a -patrol this continues for days, a -patrol's result is the hole in which the ant rests in the last night.
Scientist are testing some of nano-ants properties, their research contains stages in each stage they either create a new hole on the prism, or they want to know the result of a specific -patrol. can be a large number so they asked you, their programmer, to help them with this problem.
In the first line of input comes number , the number of sides on the prism. Then in the next line numbers are given in the row number is equal to indicating the initial hole on the th edge.
In the third line you should receive number , the number of researches that should be done. next lines are in two formats:
It is guaranteed that the first type researches do not repeat and every time a new hole is created. Also, the next type of research always refers to a preceding created hole and not a hole not yet made.
For any type two query in one line output the hole as a pair showing the result of the related patrol.
Explanation: Before the addition of the new hole each hole has a unique destination on the next edge and the answer is uniquely determined from . After adding the new hole in the last patrol, by passing over sides the ant then returns to its former place and in the next stage it goes to the next closest hole (the new hole) .
Explanation : The ant in this patrol goes to heights respectively