apaz/codeforces-genesys huggingface dataset:
You are an expert competitive programmer. You will be given a problem statement, test case constraints and example test inputs and outputs. Please reason step by step about the solution (that must respect memory and time limits), then provide a complete implementation in python3.

Your solution must read input from standard input (cin), write output to standard output (cout).
Do not include any debug prints or additional output.

Put your final solution within a single code block:
```python
<your code here>
```

Execution time limit: 1.0 seconds
Memory limit: 256.0 MB

# Problem
Doremy's new city is under construction! The city can be regarded as a simple undirected graph with $$$n$$$ vertices. The $$$i$$$-th vertex has altitude $$$a_i$$$. Now Doremy is deciding which pairs of vertices should be connected with edges.

Due to economic reasons, there should be no self-loops or multiple edges in the graph.

Due to safety reasons, there should not be pairwise distinct vertices $$$u$$$, $$$v$$$, and $$$w$$$ such that $$$a_u \leq a_v \leq a_w$$$ and the edges $$$(u,v)$$$ and $$$(v,w)$$$ exist.

Under these constraints, Doremy would like to know the maximum possible number of edges in the graph. Can you help her?

Note that the constructed graph is allowed to be disconnected.

## Input Format
The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 2\cdot 10^5$$$) — the number of vertices.

The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1\le a_i\le 10^6$$$) — the altitudes of each vertex.

It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

## Output Format
For each test case, output the maximum possible number of edges in the graph.

## Examples
```input
4
4
2 2 3 1
6
5 2 3 1 5 2
12
7 2 4 9 1 4 6 3 7 4 2 3
4
1000000 1000000 1000000 1000000
```
```output
3
9
35
2
```

## Note
In the first test case, there can only be at most $$$3$$$ edges in the graph. A possible construction is to connect $$$(1,3)$$$, $$$(2,3)$$$, $$$(3,4)$$$. In the picture below the red number above node $$$i$$$ is $$$a_i$$$.

The following list shows all such $$$u$$$, $$$v$$$, $$$w$$$ that the edges $$$(u,v)$$$ and $$$(v,w)$$$ exist.

- $$$u=1$$$, $$$v=3$$$, $$$w=2$$$;
- $$$u=1$$$, $$$v=3$$$, $$$w=4$$$;
- $$$u=2$$$, $$$v=3$$$, $$$w=1$$$;
- $$$u=2$$$, $$$v=3$$$, $$$w=4$$$;
- $$$u=4$$$, $$$v=3$$$, $$$w=1$$$;
- $$$u=4$$$, $$$v=3$$$, $$$w=2$$$.

Another possible construction is to connect $$$(1,4)$$$, $$$(2,4)$$$, $$$(3,4)$$$.

An unacceptable construction is to connect $$$(1,3)$$$, $$$(2,3)$$$, $$$(2,4)$$$, $$$(3,4)$$$. Because when $$$u=4$$$, $$$v=2$$$, $$$w=3$$$, $$$a_u\le a_v \le a_w$$$ holds, and the respective edges exist.

Now solve the problem and return the code.
You are an expert competitive programmer. You will be given a problem statement, test case constraints and example test inputs and outputs. Please reason step by step about the solution (that must respect memory and time limits), then provide a complete implementation in python3.

Your solution must read input from standard input (cin), write output to standard output (cout).
Do not include any debug prints or additional output.

Put your final solution within a single code block:
```python
<your code here>
```

Execution time limit: 1.5 seconds
Memory limit: 512.0 MB

# Problem
Doremy has $$$n+1$$$ pegs. There are $$$n$$$ red pegs arranged as vertices of a regular $$$n$$$-sided polygon, numbered from $$$1$$$ to $$$n$$$ in anti-clockwise order. There is also a blue peg of slightly smaller diameter in the middle of the polygon. A rubber band is stretched around the red pegs.

Doremy is very bored today and has decided to play a game. Initially, she has an empty array $$$a$$$. While the rubber band does not touch the blue peg, she will:

1. choose $$$i$$$ ($$$1 \leq i \leq n$$$) such that the red peg $$$i$$$ has not been removed;
2. remove the red peg $$$i$$$;
3. append $$$i$$$ to the back of $$$a$$$.

Doremy wonders how many possible different arrays $$$a$$$ can be produced by the following process. Since the answer can be big, you are only required to output it modulo $$$p$$$. $$$p$$$ is guaranteed to be a prime number.

game with $$$n=9$$$ and $$$a=[7,5,2,8,3,9,4]$$$ and another game with $$$n=8$$$ and $$$a=[3,4,7,1,8,5,2]$$$

## Input Format
The first line contains two integers $$$n$$$ and $$$p$$$ ($$$3 \leq n \leq 5000$$$, $$$10^8 \le p \le 10^9$$$) — the number of red pegs and the modulo respectively.

$$$p$$$ is guaranteed to be a prime number.

## Output Format
Output a single integer, the number of different arrays $$$a$$$ that can be produced by the process described above modulo $$$p$$$.

## Examples
```input
4 100000007
```
```output
16
```
-----
```input
1145 141919831
```
```output
105242108
```

## Note
In the first test case, $$$n=4$$$, some possible arrays $$$a$$$ that can be produced are $$$[4,2,3]$$$ and $$$[1,4]$$$. However, it is not possible for $$$a$$$ to be $$$[1]$$$ or $$$[1,4,3]$$$.

Now solve the problem and return the code.
You are an expert competitive programmer. You will be given a problem statement, test case constraints and example test inputs and outputs. Please reason step by step about the solution (that must respect memory and time limits), then provide a complete implementation in python3.

Your solution must read input from standard input (cin), write output to standard output (cout).
Do not include any debug prints or additional output.

Put your final solution within a single code block:
```python
<your code here>
```

Execution time limit: 4.0 seconds
Memory limit: 256.0 MB

# Problem
Doremy has $$$n$$$ buckets of paint which is represented by an array $$$a$$$ of length $$$n$$$. Bucket $$$i$$$ contains paint with color $$$a_i$$$. Initially, $$$a_i=i$$$.

Doremy has $$$m$$$ segments $$$[l_i,r_i]$$$ ($$$1 \le l_i \le r_i \le n$$$). Each segment describes an operation. Operation $$$i$$$ is performed as follows:

- For each $$$j$$$ such that $$$l_i < j \leq r_i$$$, set $$$a_j := a_{l_i}$$$.

Doremy also selects an integer $$$k$$$. She wants to know for each integer $$$x$$$ from $$$0$$$ to $$$m-1$$$, the number of distinct colors in the array after performing operations $$$x \bmod m +1, (x+1) \bmod m + 1, \ldots, (x+k-1) \bmod m +1$$$. Can you help her calculate these values? Note that for each $$$x$$$ individually we start from the initial array and perform only the given $$$k$$$ operations in the given order.

## Input Format
The first line of input contains three integers $$$n$$$, $$$m$$$, and $$$k$$$ ($$$1\le n,m\le 2\cdot 10^5$$$, $$$1 \le k \le m$$$) — the length of the array $$$a$$$, the total number of operations, and the integer that Doremy selects.

The $$$i$$$-th line of the following $$$m$$$ lines contains two integers $$$l_i$$$, $$$r_i$$$ ($$$1\le l_i\le r_i\le n$$$) — the bounds of the $$$i$$$-th segment.

## Output Format
Output $$$m$$$ integers. The $$$(x+1)$$$-th integer should be the number of distinct colors in the array if we start from the initial array and perform operations $$$x \bmod m +1, (x+1) \bmod m + 1, \ldots, (x+k-1) \bmod m +1$$$.

## Examples
```input
7 5 5
3 5
2 3
4 6
5 7
1 2
```
```output
3 3 3 3 2
```
-----
```input
10 9 4
1 1
2 3
3 4
7 9
6 8
5 7
2 4
9 10
1 3
```
```output
6 6 7 6 5 5 7 7 7
```

## Note
In the first test case, the picture below shows the resulting array for the values of $$$x=0,1,2$$$ respectively.

Now solve the problem and return the code.
You are an expert competitive programmer. You will be given a problem statement, test case constraints and example test inputs and outputs. Please reason step by step about the solution (that must respect memory and time limits), then provide a complete implementation in python3.

Your solution must read input from standard input (cin), write output to standard output (cout).
Do not include any debug prints or additional output.

Put your final solution within a single code block:
```python
<your code here>
```

Execution time limit: 2.0 seconds
Memory limit: 256.0 MB

# Problem
You are given an array $$$a$$$ of $$$n$$$ integers.

Find two permutations$$$^\dagger$$$ $$$p$$$ and $$$q$$$ of length $$$n$$$ such that $$$\max(p_i,q_i)=a_i$$$ for all $$$1 \leq i \leq n$$$ or report that such $$$p$$$ and $$$q$$$ do not exist.

$$$^\dagger$$$ A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array), and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).

## Input Format
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows.

The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$).

The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \leq a_i \leq n$$$) — the array $$$a$$$.

It is guaranteed that the total sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

## Output Format
For each test case, if there do not exist $$$p$$$ and $$$q$$$ that satisfy the conditions, output "NO" (without quotes).

Otherwise, output "YES" (without quotes) and then output $$$2$$$ lines. The first line should contain $$$n$$$ integers $$$p_1,p_2,\ldots,p_n$$$ and the second line should contain $$$n$$$ integers $$$q_1,q_2,\ldots,q_n$$$.

If there are multiple solutions, you may output any of them.

You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).

## Examples
```input
3
1
1
5
5 3 4 2 5
2
1 1
```
```output
YES
1 
1 
YES
1 3 4 2 5 
5 2 3 1 4 
NO
```

## Note
In the first test case, $$$p=q=[1]$$$. It is correct since $$$a_1 = max(p_1,q_1) = 1$$$.

In the second test case, $$$p=[1,3,4,2,5]$$$ and $$$q=[5,2,3,1,4]$$$. It is correct since:

- $$$a_1 = \max(p_1, q_1) = \max(1, 5) = 5$$$,
- $$$a_2 = \max(p_2, q_2) = \max(3, 2) = 3$$$,
- $$$a_3 = \max(p_3, q_3) = \max(4, 3) = 4$$$,
- $$$a_4 = \max(p_4, q_4) = \max(2, 1) = 2$$$,
- $$$a_5 = \max(p_5, q_5) = \max(5, 4) = 5$$$.

In the third test case, one can show that no such $$$p$$$ and $$$q$$$ exist.

Now solve the problem and return the code.
You are an expert competitive programmer. You will be given a problem statement, test case constraints and example test inputs and outputs. Please reason step by step about the solution (that must respect memory and time limits), then provide a complete implementation in python3.

Your solution must read input from standard input (cin), write output to standard output (cout).
Do not include any debug prints or additional output.

Put your final solution within a single code block:
```python
<your code here>
```

Execution time limit: 1.0 seconds
Memory limit: 256.0 MB

# Problem
You are given a permutation$$$^\dagger$$$ $$$p$$$ of length $$$n$$$.

In one operation, you can choose two indices $$$1 \le i < j \le n$$$ and swap $$$p_i$$$ with $$$p_j$$$.

Find the minimum number of operations needed to have exactly one inversion$$$^\ddagger$$$ in the permutation.

$$$^\dagger$$$ A permutation is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array), and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).

$$$^\ddagger$$$ The number of inversions of a permutation $$$p$$$ is the number of pairs of indices $$$(i, j)$$$ such that $$$1 \le i < j \le n$$$ and $$$p_i > p_j$$$.

## Input Format
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The description of test cases follows.

The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$).

The second line of each test case contains $$$n$$$ integers $$$p_1,p_2,\ldots, p_n$$$ ($$$1 \le p_i \le n$$$). It is guaranteed that $$$p$$$ is a permutation.

It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

## Output Format
For each test case output a single integer — the minimum number of operations needed to have exactly one inversion in the permutation. It can be proven that an answer always exists.

## Examples
```input
4
2
2 1
2
1 2
4
3 4 1 2
4
2 4 3 1
```
```output
0
1
3
1
```

## Note
In the first test case, the permutation already satisfies the condition.

In the second test case, you can perform the operation with $$$(i,j)=(1,2)$$$, after that the permutation will be $$$[2,1]$$$ which has exactly one inversion.

In the third test case, it is not possible to satisfy the condition with less than $$$3$$$ operations. However, if we perform $$$3$$$ operations with $$$(i,j)$$$ being $$$(1,3)$$$,$$$(2,4)$$$, and $$$(3,4)$$$ in that order, the final permutation will be $$$[1, 2, 4, 3]$$$ which has exactly one inversion.

In the fourth test case, you can perform the operation with $$$(i,j)=(2,4)$$$, after that the permutation will be $$$[2,1,3,4]$$$ which has exactly one inversion.

Now solve the problem and return the code.
You are an expert competitive programmer. You will be given a problem statement, test case constraints and example test inputs and outputs. Please reason step by step about the solution (that must respect memory and time limits), then provide a complete implementation in python3.

Your solution must read input from standard input (cin), write output to standard output (cout).
Do not include any debug prints or additional output.

Put your final solution within a single code block:
```python
<your code here>
```

Execution time limit: 1.5 seconds
Memory limit: 1024.0 MB

# Problem
Consider a permutation$$$^\dagger$$$ $$$p$$$ of length $$$3n$$$. Each time you can do one of the following operations:

- Sort the first $$$2n$$$ elements in increasing order.
- Sort the last $$$2n$$$ elements in increasing order.

We can show that every permutation can be made sorted in increasing order using only these operations. Let's call $$$f(p)$$$ the minimum number of these operations needed to make the permutation $$$p$$$ sorted in increasing order.

Given $$$n$$$, find the sum of $$$f(p)$$$ over all $$$(3n)!$$$ permutations $$$p$$$ of size $$$3n$$$.

Since the answer could be very large, output it modulo a prime $$$M$$$.

$$$^\dagger$$$ A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array), and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).

## Input Format
The only line of input contains two numbers $$$n$$$ and $$$M$$$ ($$$1 \leq n \leq 10^6$$$, $$$10^8 \leq M \leq 10^9$$$). It is guaranteed that $$$M$$$ is a prime number.

## Output Format
Output the answer modulo $$$M$$$.

## Examples
```input
1 100009067
```
```output
9
```
-----
```input
2 100000357
```
```output
1689
```
-----
```input
69 999900997
```
```output
193862705
```

## Note
In the first test case, all the permutations are:

- $$$[1, 2, 3]$$$, which requires $$$0$$$ operations;
- $$$[1, 3, 2]$$$, which requires $$$1$$$ operation;
- $$$[2, 1, 3]$$$, which requires $$$1$$$ operation;
- $$$[2, 3, 1]$$$, which requires $$$2$$$ operations;
- $$$[3, 1, 2]$$$, which requires $$$2$$$ operations;
- $$$[3, 2, 1]$$$, which requires $$$3$$$ operations.

Therefore, the answer is $$$0+1+1+2+2+3=9$$$.

Now solve the problem and return the code.
You are an expert competitive programmer. You will be given a problem statement, test case constraints and example test inputs and outputs. Please reason step by step about the solution (that must respect memory and time limits), then provide a complete implementation in python3.

Your solution must read input from standard input (cin), write output to standard output (cout).
Do not include any debug prints or additional output.

Put your final solution within a single code block:
```python
<your code here>
```

Execution time limit: 4.0 seconds
Memory limit: 128.0 MB

# Problem
You are given an array of positive integers $$$a_1,a_2,\ldots,a_n$$$ of length $$$n$$$.

In one operation you can jump from index $$$i$$$ to index $$$j$$$ ($$$1 \le i \le j \le n$$$) by paying $$$\min(a_i, a_{i + 1}, \ldots, a_j) \cdot (j - i)^2$$$ eris.

For all $$$k$$$ from $$$1$$$ to $$$n$$$, find the minimum number of eris needed to get from index $$$1$$$ to index $$$k$$$.

## Input Format
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 4 \cdot 10^5$$$).

The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots a_n$$$ ($$$1 \le a_i \le n$$$).

## Output Format
Output $$$n$$$ integers — the $$$k$$$-th integer is the minimum number of eris needed to reach index $$$k$$$ if you start from index $$$1$$$.

## Examples
```input
3
2 1 3
```
```output
0 1 2
```
-----
```input
6
1 4 1 6 3 2
```
```output
0 1 2 3 6 8
```
-----
```input
2
1 2
```
```output
0 1
```
-----
```input
4
1 4 4 4
```
```output
0 1 4 8
```

## Note
In the first example:

- From $$$1$$$ to $$$1$$$: the cost is $$$0$$$,
- From $$$1$$$ to $$$2$$$: $$$1 \rightarrow 2$$$ — the cost is $$$\min(2, 1) \cdot (2 - 1) ^ 2=1$$$,
- From $$$1$$$ to $$$3$$$: $$$1 \rightarrow 2 \rightarrow 3$$$ — the cost is $$$\min(2, 1) \cdot (2 - 1) ^ 2 + \min(1, 3) \cdot (3 - 2) ^ 2 = 1 + 1 = 2$$$.

In the fourth example from $$$1$$$ to $$$4$$$: $$$1 \rightarrow 3 \rightarrow 4$$$ — the cost is $$$\min(1, 4, 4) \cdot (3 - 1) ^ 2 + \min(4, 4) \cdot (4 - 3) ^ 2 = 4 + 4 = 8$$$.

Now solve the problem and return the code.
You are an expert competitive programmer. You will be given a problem statement, test case constraints and example test inputs and outputs. Please reason step by step about the solution (that must respect memory and time limits), then provide a complete implementation in python3.

Your solution must read input from standard input (cin), write output to standard output (cout).
Do not include any debug prints or additional output.

Put your final solution within a single code block:
```python
<your code here>
```

Execution time limit: 1.0 seconds
Memory limit: 256.0 MB

# Problem
Reve has two integers $$$n$$$ and $$$k$$$.

Let $$$p$$$ be a permutation$$$^\dagger$$$ of length $$$n$$$. Let $$$c$$$ be an array of length $$$n - k + 1$$$ such that $$$$$$c_i = \max(p_i, \dots, p_{i+k-1}) + \min(p_i, \dots, p_{i+k-1}).$$$$$$ Let the cost of the permutation $$$p$$$ be the maximum element of $$$c$$$.

Koxia wants you to construct a permutation with the minimum possible cost.

$$$^\dagger$$$ A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array), and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).

## Input Format
Each test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 2000$$$) — the number of test cases. The description of test cases follows.

The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq k \leq n \leq 2 \cdot 10^5$$$).

It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

## Output Format
For each test case, output $$$n$$$ integers $$$p_1,p_2,\dots,p_n$$$, which is a permutation with minimal cost. If there is more than one permutation with minimal cost, you may output any of them.

## Examples
```input
3
5 3
5 1
6 6
```
```output
5 1 2 3 4
1 2 3 4 5
3 2 4 1 6 5
```

## Note
In the first test case,

- $$$c_1 = \max(p_1,p_2,p_3) + \min(p_1,p_2,p_3) = 5 + 1 = 6$$$.
- $$$c_2 = \max(p_2,p_3,p_4) + \min(p_2,p_3,p_4) = 3 + 1 = 4$$$.
- $$$c_3 = \max(p_3,p_4,p_5) + \min(p_3,p_4,p_5) = 4 + 2 = 6$$$.

Therefore, the cost is $$$\max(6,4,6)=6$$$. It can be proven that this is the minimal cost.

Now solve the problem and return the code.
You are an expert competitive programmer. You will be given a problem statement, test case constraints and example test inputs and outputs. Please reason step by step about the solution (that must respect memory and time limits), then provide a complete implementation in python3.

Your solution must read input from standard input (cin), write output to standard output (cout).
Do not include any debug prints or additional output.

Put your final solution within a single code block:
```python
<your code here>
```

Execution time limit: 1.0 seconds
Memory limit: 256.0 MB

# Problem
Joi has an array $$$a$$$ of $$$n$$$ positive integers. Koxia wants you to determine whether there exists a positive integer $$$x > 0$$$ such that $$$\gcd(a_i+x,a_j+x)=1$$$ for all $$$1 \leq i < j \leq n$$$.

Here $$$\gcd(y, z)$$$ denotes the greatest common divisor (GCD) of integers $$$y$$$ and $$$z$$$.

## Input Format
Each test consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows.

The first line of each test case contains an integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the size of the array.

The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq {10}^{18}$$$).

It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$1000$$$.

## Output Format
For each test case, output "YES" (without quotes) if there exists a positive integer $$$x$$$ such that $$$\gcd(a_i+x,a_j+x)=1$$$ for all $$$1 \leq i < j \leq n$$$, and "NO" (without quotes) otherwise.

You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

## Examples
```input
2
3
5 7 10
3
3 3 4
```
```output
YES
NO
```

## Note
In the first test case, we can set $$$x = 4$$$. This is valid because:

- When $$$i=1$$$ and $$$j=2$$$, $$$\gcd(a_i+x,a_j+x)=\gcd(5+4,7+4)=\gcd(9,11)=1$$$.
- When $$$i=1$$$ and $$$j=3$$$, $$$\gcd(a_i+x,a_j+x)=\gcd(5+4,10+4)=\gcd(9,14)=1$$$.
- When $$$i=2$$$ and $$$j=3$$$, $$$\gcd(a_i+x,a_j+x)=\gcd(7+4,10+4)=\gcd(11,14)=1$$$.

In the second test case, any choice of $$$x$$$ makes $$$\gcd(a_1 + x, a_2 + x) = \gcd(3+x,3+x)=3+x$$$. Therefore, no such $$$x$$$ exists.

Now solve the problem and return the code.