0% found this document useful (0 votes)
2 views2 pages

Problem - A - Codeforces

The document describes a problem involving permutations of even length integers where the goal is to find a permutation such that a final counter value will not equal 1, regardless of the operations performed. It outlines the input format for multiple test cases and provides examples of valid permutations. The constraints specify that the length of the permutation must be an even integer between 2 and 50.

Uploaded by

Thuan Nguyen Hoa
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Problem - A - Codeforces

The document describes a problem involving permutations of even length integers where the goal is to find a permutation such that a final counter value will not equal 1, regardless of the operations performed. It outlines the input format for multiple test cases and provides examples of valid permutations. The constraints specify that the length of the permutation must be an even integer between 2 and 50.

Uploaded by

Thuan Nguyen Hoa
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Enter | Register

PROBLEMS SUBMIT CODE MY SUBMISSIONS STATUS HACKS ROOM STANDINGS CUSTOM INVOCATION

A. farmpiggie and Subset Sum


time limit per test: 1 second
memory limit per test: 256 megabytes

For a permutation∗ p of even length, you can do the following process:

Initialize a counter c = 0.

For each i from 1 to n, either add i ⋅ pi to c, subtract i ⋅ pi from c, or do nothing.

Let the final value of the counter be cf inal .


n
Formally, for each i ∈ {1, … , n}, consider the set Si = {−i ⋅ pi , 0, i ⋅ pi } and choose some x i ∈ Si . Set cf inal = ∑
i=1
xi .

You are given a single even integer n. Find any permutation of length n so that regardless of the operations chosen, the final value
c f inal will not be 1.


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
Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 25 ). The description of the test cases
follows.

The first and only line of each test case contains a single even integer n (2 ≤ n ≤ 50) — the length of the desired permutation.

Output
For each test case, output n integers p1 , … , pn (1 ≤ pi ≤ n) — a permutation satisfying the conditions.

If there are multiple solutions, print any of them.

Example
input Copy

3
2
4
6

output Copy

2 1
2 3 4 1
5 4 6 2 1 3

Note
In the first test case, the permutation given in the output is [2, 1]. The counter may be incremented in the following 9 ways:

+2⋅1 +0

1. 0 −−→ 2 −→ 2
+0 +1⋅2

2. 0 −→ 2 −−→ 2
−2⋅1 +0

3. 0 −−→ −2 −→ −2
+0 −1⋅2

4. 0 −→ 2 −−→ −2
−2⋅1 +1⋅2

5. 0 −−→ −2 −−→ 0
+2⋅1 −1⋅2

6. 0 −−→ 2 −−→ 0
−2⋅1 −1⋅2

7. 0 −−→ −2 −−→ −4
+2⋅1 +1⋅2

8. 0 −−→ 2 −−→ 4.
9.
+0 +0

0 −→ 0 −→ 0.

None of these are 1, so the permutation satisfies the given condition.


We can show that the permutation given in the second test case satisfies the condition. However, the permutation [1, 2, 3, 4] would not
satisfy the condition, since the sequence
+1⋅1 +0 +0 +0

0 −−→ 1 −→ 1 −→ 1 −→ 1

results in c = 1 at the end.

Codeforces (c) Copyright 2010-2026 Mike Mirzayanov


The only programming contests Web 2.0 platform
Server time: Jul/13/2026 16:43:49UTC+7 (l1).
Mobile version, switch to desktop version.
Privacy Policy | Terms and Conditions

Supported by

You might also like