import java.util.Scanner; class SLLNode { protected E element; protected SLLNode succ; public SLLNode(E elem, SLLNode succ) { this.element = elem; this.succ = succ; } @Override public String toString() { return element.toString(); } } class SLL { private SLLNode first; public SLL() { // Construct an empty SLL this.first = null; } public void deleteList() { first = null; } public int size() { int listSize = 0; SLLNode tmp = first; while(tmp != null) { listSize++; tmp = tmp.succ; } return listSize; } @Override public String toString() { String ret = new String(); if (first != null) { SLLNode tmp = first; ret += tmp; while (tmp.succ != null) { tmp = tmp.succ; ret += " " + tmp; } } else ret = "Prazna lista!!!"; return ret; } public void insertFirst(E o) { SLLNode ins = new SLLNode(o, null); ins.succ = first; //SLLNode ins = new SLLNode(o, first); first = ins; } public void insertAfter(E o, SLLNode node) { if (node != null) { SLLNode ins = new SLLNode(o, node.succ); node.succ = ins; } else { System.out.println("Dadenot jazol e null"); } } public void insertBefore(E o, SLLNode before) { if (first != null) { SLLNode tmp = first; if(first==before){ this.insertFirst(o); return; } //ako first!=before while (tmp.succ != before && tmp.succ!=null) tmp = tmp.succ; if (tmp.succ == before) { tmp.succ = new SLLNode(o, before);; } else { System.out.println("Elementot ne postoi vo listata"); } } else { System.out.println("Listata e prazna"); } } public void insertLast(E o) { if (first != null) { SLLNode tmp = first; while (tmp.succ != null) tmp = tmp.succ; tmp.succ = new SLLNode(o, null); } else { insertFirst(o); } } public E deleteFirst() { if (first != null) { SLLNode tmp = first; first = first.succ; return tmp.element; } else { System.out.println("Listata e prazna"); return null; } } public E delete(SLLNode node) { if (first != null) { SLLNode tmp = first; if(first == node) { return this.deleteFirst(); } while (tmp.succ != node && tmp.succ.succ != null) tmp = tmp.succ; if (tmp.succ == node) { tmp.succ = tmp.succ.succ; return node.element; } else { System.out.println("Elementot ne postoi vo listata"); return null; } } else { System.out.println("Listata e prazna"); return null; } } public SLLNode getFirst() { return first; } public SLLNode find(E o) { if (first != null) { SLLNode tmp = first; while (!tmp.element.equals(o) && tmp.succ != null) tmp = tmp.succ; if (tmp.element.equals(o)) { return tmp; } else { System.out.println("Elementot ne postoi vo listata"); } } else { System.out.println("Listata e prazna"); } return null; } public void merge (SLL in){ if (first != null) { SLLNode tmp = first; while(tmp.succ != null) tmp = tmp.succ; tmp.succ = in.getFirst(); } else{ first = in.getFirst(); } } public void mirror() { if (first != null) { //m=nextsucc, p=tmp,q=next SLLNode tmp = first; SLLNode newsucc = null; SLLNode next; while(tmp != null){ next = tmp.succ; tmp.succ = newsucc; newsucc = tmp; tmp = next; } first = newsucc; } } } public class SpecialSLLDelete { //TODO: implement method public void specialDelete(SLL list, int m) { if (list.size() <= 1 || m <= 1) { // Nothing to delete or invalid value of m return; } SLLNode current = list.getFirst(); SLLNode previous = null; int count = 0; while (current != null) { count++; if (count % m == 0) { // Delete the current node SLLNode next = current.succ; list.delete(current); current = next; } else { // Move to the next node previous = current; current = current.succ; } } } public static void main(String[] args) { Scanner input = new Scanner(System.in); int n = input.nextInt(); SLL list = new SLL<>(); for(int i=0;i tmp = new SpecialSLLDelete<>(); tmp.specialDelete(list, m); System.out.println(list); } }