Problems > Two Equal Sets

Two Equal Sets

Difficulty: 1400 3000 ms 128 MB

math greedy

Split 1..N into two sets with equal sums, or print NO. To keep the answer unique: build the first set GREEDILY from N downward (take a number whenever it still fits), and print it ascending. Output YES, then |set1|, set1, |set2|, set2 on separate lines.

Input: one integer N.

Output: NO, or the five lines described above.

Constraints:

  • 1 ≤ N ≤ 105

Sample Tests

Input 1
7
Output 1
YES
3
1 6 7
4
2 3 4 5
Input 2
6
Output 2
NO

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.