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])); PriorityQueue in=new PriorityQueue<>(Comparator.comparing(v->v[0])); for(int i=0;i1 || in.size()>1) { in.peek()[0]=Math.max(in.peek()[0], time); if(out.peek()[0]<=in.peek()[0]) { 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]) continue; if(disjoint(i, on)) disjoint.add(dist[i]); else adjacent.add(dist[i]); } time=in.peek()[0]; }else{ 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.peek()[0]=out.peek()[0]; continue; } int dist_=!disjoint.isEmpty()?disjoint.poll():adjacent.poll(); int id_=id[dist_]; if(on[id_]) continue; ans[(int)in.peek()[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.peek()[0]+in.peek()[2],in.peek()[1]}); time=in.peek()[0]; in.poll(); } } 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());} }