import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.Comparator; import java.util.NoSuchElementException; import java.util.PriorityQueue; public class Main { public static void main(String[] args) { new Main().run(); } boolean disjoint(int id, boolean[] on) { boolean ret=true; for(int i=Math.max(0, id-1);i<=Math.min(on.length-1, id+1);++i) { ret&=!on[i]; } return ret; } void run() { FastScanner sc=new FastScanner(); int N=sc.nextInt(); int fst=sc.nextInt()-1; int snd=sc.nextInt()-1; int[] dist=new int[N]; int[] id=new int[N]; int Q=sc.nextInt(); int[] ans=new int[Q]; Arrays.fill(ans, -1); PriorityQueue disjoint=new PriorityQueue<>(); PriorityQueue adjacent=new PriorityQueue<>(); { int p=1; int s=fst,t=fst+1; while (s>0||t0) dist[--s]=p++; } else { if(s>0) dist[--s]=p++; if(t out=new PriorityQueue<>(Comparator.comparing(v->v[0])); for(int i=0;iv[0])); boolean[] on=new boolean[N]; int v=0; long time=0; while(out.size()>1 || v!=Q) { in[v][0]=Math.max(in[v][0], time); if(out.peek()[0]<=in[v][0]) { // out[u]を実行 long[] o=out.poll(); int id_=ans[(int)o[1]]; on[id_]=false; for (int i=Math.max(id_-1, 0);i<=Math.min(id_+1, N-1);++i) { if(!on[i] && disjoint(i, on)) disjoint.add(dist[i]); else if(!on[i]) adjacent.add(dist[i]); } time=in[v][0]; }else{ // in[v]を実行 while(!disjoint.isEmpty() && (!disjoint(id[disjoint.peek()], on) || on[id[disjoint.peek()]])) { disjoint.poll(); } while(!adjacent.isEmpty() && (disjoint(id[adjacent.peek()], on) || on[id[adjacent.peek()]])) { adjacent.poll(); } if(disjoint.isEmpty()&&adjacent.isEmpty()) { in[v][0]=out.peek()[0]; continue; } int dist_=!disjoint.isEmpty()?disjoint.poll():adjacent.poll(); int id_=id[dist_]; if(on[id_]) continue; ans[(int)in[v][1]]=id_; on[id_]=true; for(int i=Math.max(0, id_-1);i<=Math.min(N-1, id_+1);++i) { if(!on[i] && !disjoint(i, on)) adjacent.add(dist[i]); } out.add(new long[] {in[v][0]+in[v][2],in[v][1]}); time=in[v][0]; ++v; } } PrintWriter pw=new PrintWriter(System.out); for(int i=0;i Integer.MAX_VALUE) throw new NumberFormatException(); return (int) nl; } public double nextDouble() { return Double.parseDouble(next());} }