Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- import java.util.StringTokenizer;
- public class twosets {
- public static void main(String[] args) throws IOException {
- FastScanner in = new FastScanner();
- int n = in.nextInt();
- if( (n *(n+1))/2 % 2 != 0) {
- System.out.println("NO");
- }
- else {
- System.out.println("YES");
- List<Integer> set1 = new ArrayList<>();
- List<Integer> set2 = new ArrayList<>();
- long target = (n*(n+1))/4;
- long set1Sum = 0;
- for (int i = 1; i <= n; i++) {
- if (set1Sum + i< target) {
- set1Sum += i;
- set1.add(i);
- }
- else {
- // find the largest number u can add to this while removing a num
- // i is the current largest number we have
- // to replace the number, find the difference between target and n = i, then replace the i'th term with n;
- long dif = n - (target - set1Sum);
- int diff = (int)(dif);
- set1.remove(diff-1);
- set1.add(n);
- break;
- }
- }
- int c = 0;
- for (int i = 1; i <= n; i++) {
- if (c < set1.size()) {
- if (set1.get(c) != i) {
- set2.add(i);
- }
- else c++;
- }
- else set2.add(i);
- }
- System.out.println(set1.size());
- for (int x: set1) {
- System.out.print(x + " ");
- }
- System.out.println();
- System.out.println(set2.size());
- for (int x: set2) {
- System.out.print(x + " ");
- }
- System.out.println();
- }
- }
- public static class FastScanner {
- BufferedReader br;
- StringTokenizer st;
- public FastScanner(String s) {
- try {
- br = new BufferedReader(new FileReader(s));
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- public FastScanner() {
- br = new BufferedReader(new InputStreamReader(System.in));
- }
- String nextToken() {
- while (st == null || !st.hasMoreElements()) {
- try {
- st = new StringTokenizer(br.readLine());
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- return st.nextToken();
- }
- String nextLine() {
- st = null;
- try {
- return br.readLine();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return null;
- }
- int nextInt() {
- return Integer.parseInt(nextToken());
- }
- long nextLong() {
- return Long.parseLong(nextToken());
- }
- double nextDouble() {
- return Double.parseDouble(nextToken());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement