It's IPL time and you are the owner of Goa Guardians, and you want your team to qualify for playoffs; hence, you are fixing matches. There are $$$N$$$ teams in the tournament, and the first four qualify for playoffs. The tournament is organized in a round robin format, i.e., each team plays with every other team once, and every match results in a win or loss(no draws) and gets $$$1$$$ point for a win and $$$0$$$ point for a loss. If two teams have the same points, then the team with a higher run rate qualifies.
You can decide the outcome of every match and the run rate of every team. Since winning more matches can be suspicious, find the minimum number of wins with which Goa Guardians can qualify, given that you are deciding the outcome of every match of the tournament.
The first line contains a single integer $$$t(1 \le t \le 10^3)$$$ — the number of test cases.
Each test case contains a single integer $$$N (4 \lt N \lt 10^9)$$$ — the number of teams in IPL.
For each test case, print a single integer, the minimum number of wins.
256
1 1
For the first test case, when there are 5 teams, we can qualify when we win just one match. Consider the following points table:
A - 4 wins
B - 3 wins
C - 2 wins
D - 1 win (Our team of interest)
E - 0 wins
Also, we would not be in the top 4 if we do not win any match. Thus, the optimal answer is 1.
In the distant land of Bitland, where all things operate based on binary logic, there exists a powerful artifact known as the "Bitstone." For centuries, it has maintained balance and order throughout the kingdom. However, one fateful day, the Bitstone began to lose its power, and chaos spread across the land.
The royal scholars discovered that the artifact's energy, symbolized by a number $$$n$$$, represents the current instability of the Bitstone. The only way to restore balance is to find two magical numbers $$$x$$$ and $$$y$$$ that satisfy the ancient binary laws of Bitland:
1. $$$(x \oplus y) = n$$$
2. $$$(x \& y) = 2n$$$
As a skilled programmer, you have been called upon to find how many such valid pairs $$$(x,y)$$$ exist for a given $$$n$$$ and help restore balance to Bitland before the chaos becomes irreversible.
The first line contains a single integer $$$t(1 \le t \le 10^3)$$$ — the number of test cases.
Each test case contains a single integer $$$n (0 \le n \le 10^{15})$$$ — the imbalance of the Bitstone.
For each test case, output a single integer representing the number of distinct valid pairs $$$(x, y)$$$ that can stabilize the Bitstone and restore peace to the kingdom.
701810121721
1 2 2 4 0 4 8
For $$$n = 0$$$, we need to find pairs $$$(x, y)$$$ such that:
1. $$$(x \oplus y) = 0$$$ (which means $$$x = y$$$)
2. $$$(x \& y) = 0$$$
The only possible solution in this case is $$$(0, 0)$$$ and the answer is $$$1$$$.
For $$$n = 1$$$, we need to find pairs $$$(x, y)$$$ such that:
1. $$$(x \oplus y) = 1$$$ (which means $$$x$$$ and $$$y$$$ must have a bit difference only at the lowest bit.)
2. $$$(x \& y) = 2$$$ (both $$$x$$$ and $$$y$$$ must have a bit set at the second position.)
So, the valid pairs are $$$(2,3)$$$ and $$$(3,2)$$$, and the answer is $$$2$$$.
You are given a string $$$s$$$ of size $$$n$$$ consisting of lowercase English alphabets $$$(a \space to \space z)$$$. The cost of moving from a character $$$c_i$$$ at index $$$i$$$ to $$$c_j$$$ at index $$$j$$$ is as follows:
You are given $$$q$$$ queries. Each query is of the form : $$$u \space v$$$
where you need to find minimum cost to move from character $$$u$$$ (i.e any index i such that $$$c_i = u$$$) to character $$$v$$$ (i.e any index j such that $$$c_j = v$$$). Print $$$-1$$$ if it's not possible to reach from $$$u$$$ to $$$v$$$(If any of u or v does not exist in string, then print $$$-1$$$).
First line contains $$$n$$$ and $$$q$$$. $$$(1 \leq n \leq 10^5)$$$ $$$(1 \leq q \leq 26 \times 26)$$$
Next line contains string $$$s$$$.
Next $$$q$$$ lines contain: $$$u \space v$$$ $$$(a \leq u, v \leq z)$$$
For each query output minimum cost to move from character $$$u$$$ to character $$$v$$$.
9 2aabbcedbaa cb d
2 1
11 7dcdcccedcebe bd be eb ee aa bd d
1 2 0 1 -1 -1 0
In test case $$$1$$$, we can move from 'a' at index $$$1$$$ to 'b' at index $$$2$$$ in cost of $$$|2-1|=1$$$. Now we can move from 'b' at index $$$2$$$ to 'b' at index $$$3$$$ in cost of $$$0$$$. Now we can reach 'c' at index $$$4$$$ from 'b' at index $$$3$$$ in cost of $$$|3-2|=1$$$. Thus the minimum cost of moving from 'a' to 'c' comes out to be $$$2$$$.
You are given a string $$$s$$$ of size $$$n$$$ consisting of lowercase English alphabets $$$(a \space to \space z)$$$. The cost of moving from index $$$i$$$ $$$(c_i$$$ is character at index $$$i)$$$ to index $$$j$$$ $$$(c_j$$$ is character at index $$$j)$$$ is as follows:
You are given a starting index $$$V$$$. You need to find minimum cost to move from $$$V$$$ to all other indices.
First line contains $$$n$$$, $$$V$$$ and $$$K$$$. $$$(1 \leq n \leq 10^3)$$$ $$$(0 \leq V \leq n-1)$$$ $$$(1 \leq K \leq 10^3)$$$
Next line contains string $$$s$$$.
Output an array $$$D$$$ of size $$$n$$$ where $$$D_i$$$ denotes minimum cost of reaching index $$$i$$$ from $$$V$$$.
9 0 1aabbcedba
0 1 2 3 4 4 3 2 1
18 3 3ababcacaaabbecbadc
3 2 1 0 1 2 3 4 4 4 3 3 4 4 3 4 5 4
In test case $$$1$$$, the minimum cost to move to index $$$4$$$ from index $$$0$$$ is $$$|4-0| = 4$$$. The minimum cost to move to index $$$5$$$ from index $$$0$$$ is also $$$4$$$. We can move from index $$$0$$$ to index $$$8$$$ at cost of $$$1$$$(as $$$c_0 == c_8$$$, so cost is equal to K i.e $$$1$$$) and then from index $$$8$$$ to index $$$5$$$ at cost of $$$3$$$.
For an undirected tree with $$$N$$$ nodes and $$$N-1$$$ edges, we define restricted diameter for a node $$$i$$$ as maximum distance path between any $$$2$$$ nodes(among all possible combinations) such that path between them contains node $$$i$$$.
For each node $$$i$$$ $$$(1 \leq i \leq N)$$$ print the restricted diameter length.
The first line contains a single integer $$$t$$$ $$$( 1 \leq t \leq 1000)$$$ — the number of test cases.
First line of each test case contains an integers $$$N$$$ $$$(1 \leq N \leq 10^5)$$$ - number of vertices in tree.
Next $$$N-1$$$ line describe the edges of the tree. The $$$i^{th}$$$ of these $$$N-1$$$ lines contains two space separated integers $$$u_i$$$ and $$$v_i$$$ denoting an edge between $$$u_i$$$ and $$$v_i$$$ $$$(1 \leq u_i,v_i \leq N)$$$.
(The sum of $$$N$$$ over all testcases won't exceed $$$10^5$$$).
A line containing $$$n$$$ integers denoting restricted diameter length for node $$$i$$$ $$$(1 \leq i \leq N)$$$.
241 22 32 481 22 31 41 54 64 77 8
2 2 2 2 5 5 5 5 4 4 5 5
Centered unscaled image. Given above is a graph of test case $$$2$$$. Clearly the diameter of the graph is $$$5$$$. So every node of the diameter is having the restricted diameter equal to $$$5$$$. For nodes $$$5$$$ and $$$6$$$, the restricted diameter is $$$4$$$.
Given a permutation$$$^{\dagger}$$$ $$$a$$$ of size $$$n$$$, with elements from $$$1$$$ to $$$n$$$.
Let's define the strength of an array $$$a$$$ of size $$$k$$$ (given all elements are distinct) as follows:-
Find the sum of the strength of all the non-empty subarrays of $$$a$$$.
$$$^{\dagger}$$$Permutation of size $$$k$$$ is an array which contains all integers from $$$1$$$ to $$$k$$$.
Each test contains multiple test cases. The first line contains an integer $$$t$$$ ($$$1\leq t \leq 5\cdot 10^4$$$). The following line contains the description of each test case.
The first line contains two integers $$$n$$$ ($$$1\leq n \leq 10^6$$$) — the size of the array.
The second line contains $$$n$$$ positive integers $$$a_1$$$, $$$a_2$$$, $$$a_3$$$, $$$...$$$ ,$$$a_n$$$ ($$$1 \leq a_i \leq n$$$) — elements of the array $$$a$$$.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^6$$$.
Print a single integer representing the sum of the strength of all the non-empty subarrays of $$$a$$$.
31132 1 343 4 1 2
1 9 14
For the second test case,