John discovered a new game. To play this game you need a circle on which $$$k$$$ ($$$k$$$ can be any positive integer) numbers are placed. The player decides at which number he begins his game and is then forced to visit every number on the circle in clockwise order starting from his chosen position. At the beginning of the game, the player's health is $$$0$$$. When he visits a number, that number is added to his health. If at any point the player's health becomes negative, the game is lost.
To test John's understanding of the game, Ana gives him an array of $$$n$$$ integers and a series of $$$q$$$ queries. Each query consists of $$$2$$$ numbers $$$l$$$ and $$$r$$$ and corresponds to the following question: If the circle was filled with the numbers in the subsequence [$$$l$$$, $$$r$$$], would the game be winnable?
Help John answer the queries.
The first line contains two integers $$$n$$$ $$$(1 \le n \le 10^6)$$$ and $$$q$$$ $$$(1 \le q \le 10^6)$$$, the size of the array, and the number of queries.
The second line contains $$$n$$$ integers $$$a_i$$$ $$$( -10^9 \leq a_i \leq 10^9 )$$$, the given array.
Each of the next $$$q$$$ lines contains two integers $$$l$$$ and $$$r$$$ $$$(1 \le l \le r \le n)$$$, representing the given queries.
For each query, print "YES" if the game described by the query is winnable, or "NO" otherwise.
You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
5 2 -4 3 5 -2 -10 2 4 4 5
YES NO
For the first query, we can pick $$$3$$$ as the starting point so we will visit the numbers in the following order: $$$3 \rightarrow 5 \rightarrow -2$$$. So our scores will be $$$3 \rightarrow 8 \rightarrow 6$$$.
For the second query, no matter the starting position the first number we will visit will be negative, thus instantly killing us.
John has a directed acyclic graph $$$G$$$ with $$$n$$$ vertices and $$$m$$$ edges. Each vertex $$$u$$$, $$$1\leq u\leq n$$$, has a value $$$a_{u}$$$ associated to it.
Let's define the beauty of a simple path $$$P=u_{1}u_{2}...u_{l-1}u_{l}$$$ over the graph $$$G$$$ as: $$$$$$ a_{u_{1}}\& a_{u_{2}}\&...\& a_{u_{l-1}}\& a_{u_{l}}$$$$$$ where $$$\&$$$ denotes the bitwise and operator.
Find the maximal possible beauty of a path $$$P$$$ consisting of exactly $$$k$$$ vertices over the graph $$$G$$$.
The first line contains three integers: $$$n$$$, $$$m$$$, $$$k$$$ $$$(2\leq n\leq 2 \cdot 10^5, n-1\leq m\leq 2 \cdot 10^5, 1\leq k \leq n)$$$ — the number of vertices of the graph $$$G$$$, the number of edges of the graph and the required length of the path, respectively.
The second line contains $$$n$$$ integers $$$a_{1}, a_{2},...,a_{n-1}, a_{n}$$$ $$$(0\leq a_{i} \lt 2^{20})$$$.
Each line $$$i$$$ of the next $$$m$$$ lines contains two integers: $$$u_{i}, v_{i}$$$, meaning that there is a directed edge from vertex $$$u_{i}$$$ to vertex $$$v_{i}$$$.
The output must contain a single integer, $$$x$$$ — the maximal possible value of the beauty of a path of length exactly $$$k$$$ over the graph $$$G$$$.
5 8 4 11 26 15 3 26 1 5 2 3 2 5 3 1 3 5 4 1 4 3 4 5
10
7 12 4 36 47 47 31 33 15 34 1 6 1 7 2 4 2 5 3 2 3 7 4 1 4 5 4 6 5 7 6 5 6 7
32
John the tractorist is driving his tractor around the fields of his native village.
The field he is currently located on can be described by an $$$n \cdot m$$$ matrix, each cell of which is assigned one of the following characters: '$$$p$$$'-simple dirt, '$$$s$$$'-highway and '$$$a$$$'-arable land.
John must move his tractor from the cell located at the intersection of row $$$y_1, 1\leq y_1 \leq n$$$ and column $$$x_1, 1\leq x_1 \leq m$$$, to the cell $$$y_2, x_2$$$.
It takes John 1 unit of time to pass through a cell with the character '$$$s$$$' assigned to it, 2 units of time to pass through a cell '$$$p$$$' and 3 units of time to pass through a cell '$$$a$$$'.
Driving this far can take a lot of time, so the mayor of the village promised to help John. The mayor can transform at most $$$k$$$ cells of type '$$$p$$$' to cells of type '$$$s$$$'.
Now, John has given you a very important task. You must find the minimal possible time needed for John to drive from cell $$$y_1, x_1$$$ to cell $$$y_2, x_2$$$, considering that the mayor changes the cells in an optimal way.
***Notice that passing the starting cell consumes John's time, and arriving at the destination cell also consumes some of John's time, according to the type of the destination cell.
***Notice that the mayor can change the values of the beginning and destination cells if any of these cells have the value '$$$p$$$' associated with them.
The first line consists of three integers $$$n, m, k ( 1\leq n\cdot m\cdot k \leq 10^{6}) $$$ — the number of rows of the matrix, the number of columns of the matrix and the maximal number of cells of type '$$$p$$$' that can be transformed to cells of type '$$$s$$$'.
The next line of input contains the numbers $$$y_1, x_1, y_2, x_2 (1\leq y_1 \leq n, 1\leq x_1 \leq m , 1\leq y_2 \leq n, 1\leq x_2 \leq m)$$$, describing the starting cell and the destination cell of the tractor's walk.
Each line $$$i$$$ of the next $$$n$$$ lines, contains $$$m$$$ characters $$$a_{i,1}a_{i,2}...a_{i,m-1}a_{i,m}$$$ ($$$a_{i,j}$$$='$$$a$$$' or $$$a_{i,j}$$$='$$$p$$$' or $$$a_{i,j}$$$='$$$s$$$')
Print a single integer $$$x$$$ — the minimum possible amount of time needed for the tractor to achieve the destination cell from the starting cell, if the cells of type '$$$p$$$' are transformed into cells of type '$$$s$$$' in an optimal, admissible way.
4 4 2 4 1 1 4 sppa apap sssa apaa
12
4 4 2 4 1 1 4 aaap ssss papa sspa
7
John wants to become the president of Nicolina. We all know that the neighborhood of Nicolina can be viewed as a tree with $$$n$$$ vertices and in each vertice $$$i$$$ lives a person that has the political opinion $$$p_i$$$. To win the election one must be voted by more than $$$\frac{n}{2}$$$ inhabitants that form a continuous path in the tree. John really wants to win so he will choose a political plan $$$x$$$ such that there exists such a path of voters. John will receive a person's vote if and only if $$$x \vert p_i$$$ ($$$x$$$ divides $$$p_i$$$).
The elections are very soon and John needs to start his political campaign. Knowing the political opinions of the inhabitants and the tree that represent Nicolina, John wants to know if there exists a political plan $$$x$$$ such that there exists a continuous path of more than $$$\frac{n}{2}$$$ voters in Nicolina. Of course, John cannot choose $$$x = 1$$$ because the people in the neighborhood will think that he is dishonest.
The first line of the input contains one integer $$$n$$$ $$$( 2 \leq n \leq 2 \cdot 10^5 )$$$ - the number of vertices in Nicolina. The second line contains $$$n$$$ integers $$$p_i$$$ $$$( 2 \leq p_i \leq 10^7 ) $$$ - the political opinions of each of the inhabitants Each of the following $$$n-1$$$ lines contains two integers $$$u$$$ and $$$v$$$ $$$(1 \leq u, v \leq n, u \neq v)$$$ - the vertices connected by an edge. It is guaranteed that these edges form a tree.
Output "YES" (without quotes) if John can win the game, and "NO" (without quotes) otherwise.
You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
5 19 2 4 1 14 3 4 1 3 2 5 2 1
NO
7 18 2 20 14 18 13 10 7 6 3 1 5 4 4 2 5 3 3 7
YES
In the first example, John can't choose a political plan such that he wins the elections.
In the second example, John can choose $$$x = 2$$$ and there exists such path of voters. Such a path could be $$$3 - 5 - 4 - 2$$$
Since hiring Jonathans is expensive, the city council decided to turn off all the lights.
The city's lights are in the form of a tree of size $$$N$$$. A tree is an undirected graph with exactly one simple path between each pair of vertices.
The lights are to be turned off in order $$$a_1, a_2, ..., a_N$$$, where $$$a_i$$$ $$$(1 \leq i \leq N)$$$ represents the index of the light bulb to be turned off at time $$$i$$$. You have to find, for each $$$i$$$, the maximum length of a simple path consisting only of lit nodes.
* The length of a path is defined as the number of nodes it contains.
The first line contains an integer $$$N$$$ $$$(1 \leq N \leq 2 \cdot 10^5)$$$ - the number of nodes of the tree.
Each of the next $$$N - 1$$$ lines contains two integers $$$u$$$ and $$$v$$$ $$$(1 \leq u, v \leq N; u \neq v)$$$ denoting there is an undirected edge between node $$$u$$$ and node $$$v$$$. It is guaranteed that the given edges form a tree.
The following line will contain $$$N$$$ integers, the values $$$a_1, a_2, ..., a_N$$$.
The output should contain $$$N$$$ integers, representing the length of the longest path containing only lit nodes after turning off the lightbulbs $$$a_1, a_2, ... a_i$$$.
3 2 1 2 3 1 2 3
2 1 0
8 3 7 7 8 4 8 5 7 6 5 3 2 6 1 4 3 7 5 1 6 2 8
6 5 3 2 1 1 1 0
In the first example, after turning off node $$$1$$$, we have the longest path $$$[2, 3]$$$. After turning off $$$2$$$, the longest path consists only of node $$$3$$$. After turning off the last bulb, there is no path left, so the answer is $$$0$$$.
John is in the middle of his Operating Systems exam and he just realized that he forgot a command that he needs. To save his grade he decided to randomly type letters in the hopes that he will get some partial score for trying.
The teacher knows the command that John needs for his program to run, so he wonders what is expected number of key strokes after which the necessary comand will be a suffix of the written text.
The expected value can be written in the form $$$\frac{p}{q} $$$. Please output $$$p \cdot q^{-1} \pmod{1000000007} $$$, where $$$q^{-1}$$$ is the modular inverse of $$$q$$$.
The first line contains an integer $$$n$$$ $$$(1 \le n \le 1000)$$$, the size of the command.
The second line contains a string consisting of $$$n$$$ lower case characters, the searched for command. The command only consists of lower case letters from the standard english alphabet.
Output a single integer, the requested number modulo $$$10^9 + 7$$$.
1 a
26
2 aa
702
5 tbddu
11881376