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(tv[0])); Arrays.sort(out, Comparator.comparing(v->v[0])); boolean[] on=new boolean[N]; int u=0,v=0; while(u!=Q || v!=Q) { if(out[u][0]<=in[v][0]) { // out[u]を実行 int id_=ans[out[u][1]]; on[id_]=false; if(disjoint(id_, on)) disjoint.add(dist[id_]); else adjacent.add(dist[id_]); ++u; }else{ // in[v]を実行 while(!disjoint.isEmpty() && (!disjoint(id[disjoint.peek()], on) || on[id[disjoint.peek()]])) { disjoint.poll(); } if(disjoint.isEmpty()&&adjacent.isEmpty()) { in[v][0]=out[u][0]; continue; } int dist_=!disjoint.isEmpty()?disjoint.poll():adjacent.poll(); int id_=id[dist_]; if(on[id_]) continue; ans[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]); } ++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());} }