-
Notifications
You must be signed in to change notification settings - Fork 0
/
Q7_1092.java
68 lines (63 loc) · 1.47 KB
/
Q7_1092.java
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* Name: Debopriyo Roy
* Reg No: 2241018184
* PS LINK: https://cses.fi/problemset/task/1092
*/
import java.util.*;
public class Q7_1092 {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
if(n%4==1||n%4==2) {
System.out.println("NO");
}
else {
System.out.println("YES");
ArrayList<Integer> set1=new ArrayList<>();
ArrayList<Integer> set2=new ArrayList<>();
if(n%2==0) {
int count=n/4;
int i=0;
for(;i<count;i++) {
set1.add(i+1);
set1.add(n-i);
}
for(i=i+1;i<=n-count;i++) {
set2.add(i);
}
}
else {
if(n==3) {
set1.add(3);
set2.add(1);
set2.add(2);
}
else {
int count=(n+1)/4;
int i=0;
for(;i<count-1;i++) {
set1.add(i+1);
set1.add(n-i);
}
if(!set1.isEmpty())
set1.add(set1.get(set1.size()-1)-1);
for(i=i+1;i<=n-count;i++) {
set2.add(i);
}
}
}
System.out.println(set1.size());
StringBuilder str1 = new StringBuilder();
StringBuilder str2 = new StringBuilder();
for (int i=0;i<set1.size();i++) {
str1.append(set1.get(i)).append(" ");
}
System.out.println(str1.toString());
System.out.println(set2.size());
for (int i=0;i<set2.size();i++) {
str2.append(set2.get(i)).append(" ");
}
System.out.println(str2.toString());
}
}
}