Hiring process8 levels
  1. 1 IQ Test
  2. 2 Additional Online Test (If Required)
  3. 3 Office Interview with Hiring Manager
  4. 4 Unpaid Test Task (Motivation Check)
  5. 5 Paid Test Task and Follow-Up Interview
  6. 6 Iterative Paid Test Tasks
  7. 7 Office Verification
  8. 8 Final Interview with the Founder

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 Statistics

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.
Ctrl+Enter submit · Ctrl+Space autocomplete · F11 fullscreen