text stringlengths 0 801 |
|---|
In the first example, it is necessary to apply the operation to $i=2$, thus the array will become $[1, \textbf{2}, 1, \textbf{1}, 3]$, with the bold elements indicating those that have swapped places. The disturbance of this array is equal to $1$. |
In the fourth example, it is sufficient to apply the operation to $i=3$, thus the array will become $[2, 1, \textbf{2}, \textbf{1}, 2, 4]$. The disturbance of this array is equal to $0$. |
In the eighth example, it is sufficient to apply the operation to $i=3$, thus the array will become $[1, 4, \textbf{1}, 5, \textbf{3}, 1, 3]$. The disturbance of this array is equal to $0$. |
Kosuke is too lazy. He will not give you any legend, just the task: |
Fibonacci numbers are defined as follows: |
* $f(1)=f(2)=1$. * $f(n)=f(n-1)+f(n-2)$ $(3\le n)$ |
We denote $G(n,k)$ as an index of the $n$-th Fibonacci number that is divisible by $k$. For given $n$ and $k$, compute $G(n,k)$. |
As this number can be too big, output it by modulo $10^9+7$. |
For example: $G(3,2)=9$ because the $3$-rd Fibonacci number that is divisible by $2$ is $34$. $[1,1,\textbf{2},3,5,\textbf{8},13,21,\textbf{34}]$. |
The first line of the input data contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases. |
The first and only line contains two integers $n$ and $k$ ($1 \le n \le 10^{18}$, $1 \le k \le 10^5$). |
It is guaranteed that the sum of $k$ across all test cases does not exceed $10^6$. |
For each test case, output the only number: the value $G(n,k)$ taken by modulo $10^9+7$. |
Red was ejected. They were not the imposter. |
There are $n$ rows of $m$ people. Let the position in the $r$-th row and the $c$-th column be denoted by $(r, c)$. Number each person starting from $1$ in row-major order, i.e., the person numbered $(r-1)\cdot m+c$ is initially at $(r,c)$. |
The person at $(r, c)$ decides to leave. To fill the gap, let the person who left be numbered $i$. Each person numbered $j>i$ will move to the position where the person numbered $j-1$ is initially at. The following diagram illustrates the case where $n=2$, $m=3$, $r=1$, and $c=2$. |
 |
Calculate the sum of the Manhattan distances of each person's movement. If a person was initially at $(r_0, c_0)$ and then moved to $(r_1, c_1)$, the Manhattan distance is $|r_0-r_1|+|c_0-c_1|$. |
The first line contains a single integer $t$ ($1\le t\le 10^4$) — the number of test cases. |
The only line of each testcase contains $4$ integers $n$, $m$, $r$, and $c$ ($1\le r\le n\le 10^6$, $1 \le c \le m \le 10^6$), where $n$ is the number of rows, $m$ is the number of columns, and $(r,c)$ is the position where the person who left is initially at. |
For each test case, output a single integer denoting the sum of the Manhattan distances. |
For the first test case, the person numbered $2$ leaves, and the distances of the movements of the person numbered $3$, $4$, $5$, and $6$ are $1$, $3$, $1$, and $1$, respectively. So the answer is $1+3+1+1=6$. |
For the second test case, the person numbered $3$ leaves, and the person numbered $4$ moves. The answer is $1$. |
There are 3 heroes and 3 villains, so 6 people in total. |
Given a positive integer $n$. Find the smallest integer whose decimal representation has length $n$ and consists only of $3$s and $6$s such that it is divisible by both $33$ and $66$. If no such integer exists, print $-1$. |
The first line contains a single integer $t$ ($1\le t\le 500$) — the number of test cases. |
The only line of each test case contains a single integer $n$ ($1\le n\le 500$) — the length of the decimal representation. |
For each test case, output the smallest required integer if such an integer exists and $-1$ otherwise. |
For $n=1$, no such integer exists as neither $3$ nor $6$ is divisible by $33$. |
For $n=2$, $66$ consists only of $6$s and it is divisible by both $33$ and $66$. |
For $n=3$, no such integer exists. Only $363$ is divisible by $33$, but it is not divisible by $66$. |
For $n=4$, $3366$ and $6666$ are divisible by both $33$ and $66$, and $3366$ is the smallest. |
Man, this Genshin boss is so hard. Good thing they have a top-up of $6$ coins for only $ \$4.99$. I should be careful and spend no more than I need to, lest my mom catches me... |
You are fighting a monster with $z$ health using a weapon with $d$ damage. Initially, $d=0$. You can perform the following operations. |
* Increase $d$ — the damage of your weapon by $1$, costing $x$ coins. * Attack the monster, dealing $d$ damage and costing $y$ coins. |
You cannot perform the first operation for more than $k$ times in a row. |
Find the minimum number of coins needed to defeat the monster by dealing at least $z$ damage. |
The first line contains a single integer $t$ ($1\le t\le 100$) — the number of test cases. |
The only line of each test case contains 4 integers $x$, $y$, $z$, and $k$ ($1\leq x, y, z, k\leq 10^8$) — the first operation's cost, the second operation's cost, the monster's health, and the limitation on the first operation. |
For each test case, output the minimum number of coins needed to defeat the monster. |
In the first test case, $x = 2$, $y = 3$, $z = 5$, and $k = 5$. Here's a strategy that achieves the lowest possible cost of $12$ coins: |
* Increase damage by $1$, costing $2$ coins. * Increase damage by $1$, costing $2$ coins. * Increase damage by $1$, costing $2$ coins. * Attack the monster, dealing $3$ damage, costing $3$ coins. * Attack the monster, dealing $3$ damage, costing $3$ coins. |
You deal a total of $3 + 3 = 6$ damage, defeating the monster who has $5$ health. The total number of coins you use is $2 + 2 + 2 + 3 + 3 = 12$ coins. |
In the second test case, $x = 10$, $y = 20$, $z = 40$, and $k = 5$. Here's a strategy that achieves the lowest possible cost of $190$ coins: |
* Increase damage by $5$, costing $5\cdot x$ = $50$ coins. * Attack the monster once, dealing $5$ damage, costing $20$ coins. * Increase damage by $2$, costing $2\cdot x$ = $20$ coins. * Attack the monster $5$ times, dealing $5\cdot 7 = 35$ damage, costing $5\cdot y$ = $100$ coins. |
You deal |
Monocarp is opening his own IT company. He wants to hire $n$ programmers and $m$ testers. |
There are $n+m+1$ candidates, numbered from $1$ to $n+m+1$ in chronological order of their arriving time. The $i$-th candidate has programming skill $a_i$ and testing skill $b_i$ (a person's programming skill is different from their testing skill). The skill of the team is the sum of the programming skills of all candi... |
When a candidate arrives to interview, Monocarp tries to assign them to the most suitable position for them (if their programming skill is higher, then he hires them as a programmer, otherwise as a tester). If all slots for that position are filled, Monocarp assigns them to the other position. |
Your task is, for each candidate, calculate the skill of the team if everyone except them comes to interview. Note that it means that exactly $n+m$ candidates will arrive, so all $n+m$ positions in the company will be filled. |
The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases. |
Each test case consists of three lines: |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.