You are given an array $$$[p[1], p[2], ..., p[n]]$$$ where all the numbers in the array are distinct. In addition, the numbers are positive integers between $$$1$$$ and $$$n$$$. You can only perform the following operations on the array: Pick two indices $$$x$$$ and $$$y$$$ such that $$$|p[x] - p[y]| = 1$$$, and then swap the values of $$$p[x]$$$ and $$$p[y]$$$. We now want to sort this array in ascending order. That is, to make $$$p[i] = i$$$ for all $$$i\in\{1,2,\dots,n\}$$$. For example, we can sort the array $$$[p[1]=2,p[2]=3,p[3]=1]$$$ in two operations:
Please write a program to compute the minimum number of operations to sort a given array in ascending order.
The input contain two lines. The first line contains one integer $$$n$$$. The second lines contain $$$n$$$ space-saparated numbers $$$p[1],p[2],\dots,p[n]$$$ representing the array $$$[p[1], p[2],\dots, p[n]]$$$
Output only one number that denotes the minimum number of operations required to sort the given array.
3 1 3 2
1
5 5 3 2 1 4
7
On Animal Farm, the animals have rebelled against their human owner and have taken over the management of the farm. To ensure equality and fairness among all the animals, they have decided to create a new set of rules. However, as the new leaders, the pigs have started making changes to the rules to favor themselves.
The farm maintains a hierarchy of animals based on their species, with each animal assigned a specific influence level. This influence level, represented as a positive integer, determines the animal's priority in decision-making. Within a group, an animal can make decisions if it has the highest influence level among the members.
The pigs have a plan to maximize their collective influence in the leadership council by selecting a specific group of animals. Given a list of animals with their species and influence levels, you are tasked to form the most influential leadership council while adhering to the following rules:
Determine the maximum total influence levels of the council that can be formed under these rules.
The first line contains an integer $$$n$$$, representing the number of animals. The next $$$n$$$ lines each contain a string species and a positive integer influence:
Technical Specification
Output a single integer, the maximum total influence levels of the leadership council that can be formed following the rules.
5 pig 10 horse 15 pig 5 cow 20 sheep 25
10
5 pig 10 horse 15 pig 15 cow 15 sheep 10
25
Competitive frisbee has, for some reason, become a thing now, and everyone's trying to be the best. For this reason, Johannes and Asfora have begun practicing this sport, and their practice routine goes something like this: both of them start at the same point, and Johannes throws the frisbee in some direction while Asfora begins running after the frisbee. They're intelligent, so when the frisbee is thrown, Asfora is able to precisely pinpoint where it's going to land and begins running towards that direction.
Since they've been training a lot, Asfora has gotten lazy and will now only run if he's certain that he'll reach the frisbee. He doesn't have time to do this calculation, so he asks you for help in knowing whether he'll run or not. When Johannes throws a frisbee, Asfora is able to tell you the coordinates in which it'll land in relation to the starting point, how fast he's able to run at that moment, and how long it takes for the frisbee to reach the ground. Will you be able to help him?
The first line contains a single integer $$$T$$$, $$$(1 \leq T \leq 10^5)$$$ — the number of test cases.
Each test case is one line and contains four integers, $$$x$$$, $$$y$$$, $$$v$$$, $$$t$$$, $$$(1 \leq x, y \leq 10^4)$$$, $$$(1 \leq v, t \leq 10^2)$$$ — the $$$x$$$ and $$$y$$$ position where the frisbee lands in relation to the starting point, the speed in which Asfora runs, and the amount of time it took for the frisbee to reach the ground.
For each test case, output YES if he can get to the frisbee in the elapsed time, or NO otherwise.
24 2 3 106 8 1 9
YES NO
Diego knows that the sum of all integers between $$$1$$$ and $$$N$$$ is $$$\frac{N(N+1)}{2}$$$. However, he is wondering how to compute the exclusive or of all integers between $$$1$$$ and $$$N$$$.
Exclusive or is also known as xor. Most programming languages represent it with the character ^.
First, a single integer, $$$T$$$ $$$(1 \le T \le 10^5)$$$: the number of test cases.
Then $$$T$$$ lines, each of which contains a single integer, $$$N$$$ $$$(1 \le N \le 10^{18})$$$.
For each test case output a line containing a single integer: the exclusive or of every number between $$$1$$$ and $$$N$$$.
3 1 2 5
1 3 1
A divisor of a positive integer $$$n$$$ is an integer $$$d$$$ where $$$m=\frac{n}{d}$$$ is an integer. In this problem, we define the aliquot sum $$$s(n)$$$ of a positive integer $$$n$$$ as the sum of all divisors of $$$n$$$ other than $$$n$$$ itself. For examples, $$$s(12)=1+2+3+4+6=16$$$, $$$s(21)=1+3+7=11$$$, and $$$s(28)=1+2+4+7+14=28$$$.
With the aliquot sum, we can classify positive integers into three types: abundant numbers, deficient numbers, and perfect numbers. The rules are as follows.
You are given a list of positive integers. Please write a program to classify them.
The first line of the input contains one positive integer $$$T$$$ indicating the number of test cases. The second line of the input contains $$$T$$$ space-separated positive integers $$$n_1,\dots,n_T$$$.
Output $$$T$$$ lines. If $$$n_i$$$ is an abundant number, then print abundant on the $$$i$$$-th line. If $$$n_i$$$ is a deficient number, then print deficient on the $$$i$$$-th line. If $$$n_i$$$ is a perfect number, then print perfect on the $$$i$$$-th line.
3 12 21 28
abundant deficient perfect
The Silva family is a wheat producer in the interior of Brazil. They have a huge plantation managed by Mr. and Mrs. Silva. But the plantation has a peculiar shape: it has $$$N$$$ fields numbered from $$$1$$$ to $$$N$$$, connected by $$$M$$$ two-way roads. To facilitate the work at harvest time, the plantation was designed in such a way that there is a path between each pair of fields using the existing roads. In addition, the fields have different sizes, thus impacting the productivity of each one. The $$$i$$$-th field has a yield of $$$2^i$$$ kg of wheat per year.
As time went by, the Silva couple got tired of taking care of the plantation and decided to leave the task to their two kids: Ana and Bob. To not have any fights between the children, the couple wants to divide the $$$N$$$ fields according to the following rules:
When the couple tried to make this division, they realized that the task would be very complex, so they asked for your help. Given the fields and the roads, your job is to help the Silva family to divide the fields between the two siblings the way they wish.
The first line contains two integers $$$N$$$ ($$$2 \leq N \leq 3 \times 10^5$$$) and $$$M$$$ ($$$1 \leq M \leq 3\times 10^5$$$), indicating respectively the number of fields and the number of roads. Each of the next $$$M$$$ lines contains two integers $$$U$$$ and $$$V$$$ ($$$1 \leq U,V \leq N$$$ and $$$U \neq V$$$), denoting that there's a two-way road between fields $$$U$$$ and $$$V$$$. It is guaranteed that there is a path between each pair of fields using the given roads, and there is at most one road between each pair of fields.
Output a single line with a string of length $$$N$$$ such that its $$$i$$$-th character is either the uppercase letter "A" or the uppercase letter "B", indicating respectively that Ana or Bob should receive the $$$i$$$-th field. If there are multiple solutions, output any of them.
3 2 1 3 3 2
ABA
6 6 3 5 2 6 1 3 3 6 5 1 4 6
BABABA
Yazan created a new game for us hopefully it's easy
You are given a binary grid with n rows and m columns. (each cell is $$$0$$$ or $$$1$$$), you can select one cell with value equal to $$$1$$$ and turn all its neighbors' value to $$$1$$$, you can only do this operation once (two cells are considered to be neighboring if they have a common edge or corner).
If you can turn all values to 1 print WIN otherwise print LOSE
| 1 | 0 | 0 | 1 |
| 1 | 1 | 1 | 0 |
| 1 | 0 | 0 | 1 |
| 1 | 1 | 1 | 1 |
| 1 | 1 | 1 | 1 |
| 1 | 1 | 1 | 1 |
| 1 | 1 | 1 | 1 |
| 1 | 1 | 1 | 1 |
In the above example we can select $$$cell(2,3)$$$ and turn all it's neighbors to $$$1$$$ so all values will be equal to $$$1$$$ ($$$cell(i,j)$$$ represent the cell in the i-th row and j-th column).
The first line contains two positive integers n and m ($$$ 1 \le n,m \le 500$$$) the number of rows and the number of columns, respectively.
The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line $$$a_{i,j}$$$ is the number written in the $$$j$$$-th cell of the i-th row ($$$ 0 \le a_{i,j} \le 1 $$$).
If you can turn all values to 1 print "WIN" (without quotes). Otherwise print "LOSE".
4 4 1 0 0 1 1 1 1 0 1 0 0 1 1 1 1 1
WIN
2 5 1 0 0 0 1 1 0 0 0 1
LOSE