-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwoSets.java
More file actions
45 lines (38 loc) · 1.28 KB
/
TwoSets.java
File metadata and controls
45 lines (38 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java.io.*;
import java.util.*;
public class TwoSets{
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
long n = Long.parseLong(br.readLine());
long sum = (n * (n + 1)) / 2;
if (sum % 2 != 0) {
pw.println("NO");
} else {
pw.println("YES");
long tsum = sum / 2;
long c = 0;
ArrayList<Long> a1 = new ArrayList<>();
ArrayList<Long> a2 = new ArrayList<>();
for (long i = n; i >= 1; i--) {
if (c + i <= tsum) {
a1.add(i);
c += i;
} else {
a2.add(i);
}
}
pw.println(a1.size());
for (int i = 0; i < a1.size(); i++) {
pw.print(a1.get(i) + " ");
}
pw.println();
pw.println(a2.size());
for (int i = 0; i < a2.size(); i++) {
pw.print(a2.get(i) + " ");
}
pw.println();
}
pw.flush();
}
}