using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.IO; using System.Reflection; using static System.Math; using System.Numerics; using System.Threading; using System.Runtime.CompilerServices; using System.Diagnostics; static class Program{ const int mod=(int)1e9+7; const long inf=long.MaxValue>>1; static List[] li; static void Main(){ Sc sc=new Sc(); var n=sc.I; int m=(n+1)<<1; li=new List[m]; for(int i=1;i();} var h=new int[n+2][]; h[0]=new int[]{-mod,-mod,-mod}; h[n+1]=new int[]{mod,mod,mod}; for(int i = 1;i<=n;i++) {h[i]=sc.Ia3(i);} var stg=new Stg(1,n,n+1,(v1,v2)=>{ li[v2].Add(v1); }); Array.Sort(h,(u,v)=>u[0]-v[0]); for(int i = 1;i<=n;i++) { int lb = -1, ub = n+1, mid = 0; while(lb+1!=ub) { mid=(ub+lb)/2; if(h[mid][0]>h[i][1]-h[i][2]) { ub=mid; } else { lb=mid; } } if(lb=1){ stg.Get(1,lb,v=>{li[v].Add(i);}); } else if(lb>=1){ if(1<=i-1){stg.Get(1,i-1,v=>{li[v].Add(i);});} if(i+1<=lb){stg.Get(i+1,lb,v=>{li[v].Add(i);});} } } var scc=new Scc(li); var dp=new long[scc.li.Length]; var ans=new long[n+1]; for(int i=1;i1){dp[i]=inf;} else if(scc.da[i][0]<=n){dp[i]+=h[scc.da[i][0]][1];} for(int j = 0;j=inf?"BAN":ans[i].ToString())+"\n");} Console.Write(sb); } } public class Scc{ private const int o=1; public List[] li; public int[][] da; public int[] h; public readonly int m; public Scc(List[] lim){ int n=lim.Length,p=1; var b=new bool[n]; var b2=new bool[n]; var b3=new bool[n]; var low=new int[n]; h=new int[n]; var sk=new Stack(); var lid=new List>(); for(int i = o;ilow[lim[a][i]]){ low[a]=low[lim[a][i]]; b3[a]=true; } } if(b3[a]){return;} int v=-1; lid.Add(new List()); while(v!=a){ v=sk.Pop(); lid[lid.Count-1].Add(v); b2[v]=true; h[v]=lid.Count-1; } } m=lid.Count+o; li=new List[m]; da=new int[m][]; for(int i = o;i();} for(int i = o;i=0;i--) { int e=m-i-1; da[e]=lid[i].ToArray(); for(int j = 0;j f){ lm=l; n=r-l+1; var cnt=n<<1; h=new int[cnt]; h[0]=a-1; for(int i = 1;i=cnt?l+i-n:(a+i-1);} for(int i = 1;i f){ l+=n-lm;r+=n-lm; while(l<=r){ if((l&1)==1){ f(h[l]); l++; } if((r&1)==0){ f(h[r]); r--; } l>>=1;r>>=1; } } } public class Sc{ [MethodImpl(MethodImplOptions.AggressiveInlining)] protected virtual string Rl(){return Console.ReadLine();} [MethodImpl(MethodImplOptions.AggressiveInlining)] protected virtual string[] Sp(string st){return st.Split();} [MethodImpl(MethodImplOptions.AggressiveInlining)] private T Ct(string s){return (T)Convert.ChangeType(s,typeof(T));} public virtual int I{get{return int.Parse(Rl());}} public virtual long L{get{return long.Parse(Rl());}} public virtual double D{get{return double.Parse(Rl());}} public virtual string S{get{return Rl();}} public int[] Ia{get{return Array.ConvertAll(Sp(Rl()),int.Parse);}} public long[] La{get{return Array.ConvertAll(Sp(Rl()),long.Parse);}} public double[] Da{get{return Array.ConvertAll(Sp(Rl()),double.Parse);}} public string[] Sa{get{return Sp(Rl());}} public object[] Oa{get{return Sp(Rl());}} public int[] Ia2{get{return Array.ConvertAll(Sp("0 "+Rl()+" 0"),int.Parse);}} public int[] Ia3(string a,string b){return Array.ConvertAll(Sp(a+Rl()+b),int.Parse);} public int[] Ia3(int a){return Array.ConvertAll(Sp(Rl()+" "+a.ToString()),int.Parse);} public long[] La2{get{return Array.ConvertAll(Sp("0 "+Rl()+" 0"),long.Parse);}} public long[] La3(string a,string b){return Array.ConvertAll(Sp(a+Rl()+b),long.Parse);} public long[] La3(int a){return Array.ConvertAll(Sp(Rl()+" "+a.ToString()),long.Parse);} public double[] Da2{get{return Array.ConvertAll(Sp("0 "+Rl()+" 0"),double.Parse);}} public double[] Da3(string a,string b){return Array.ConvertAll(Sp(a+Rl()+b),double.Parse);} public T[] Arr(int n,Func f){var a=new T[n];for(int i=0;i(int n,Func f){var a=new T[n];for(int i=0;i(int n,Func f){var a=new T[n];for(int i=0;i(int n,Func f){var a=new T[n];for(int i=0;i(){var s=Sp(Rl());return (Ct(s[0]),Ct(s[1]));} [MethodImpl(MethodImplOptions.AggressiveInlining)] public (T,T,T) Tp3(){var s=Sp(Rl());return (Ct(s[0]),Ct(s[1]),Ct(s[2]));} [MethodImpl(MethodImplOptions.AggressiveInlining)] public (T,T,T,T) Tp4(){var s=Sp(Rl());return (Ct(s[0]),Ct(s[1]),Ct(s[2]),Ct(s[3]));} [MethodImpl(MethodImplOptions.AggressiveInlining)] public (T,T,T,T,T) Tp5(){var s=Sp(Rl());return (Ct(s[0]),Ct(s[1]),Ct(s[2]),Ct(s[3]),Ct(s[4]));} [MethodImpl(MethodImplOptions.AggressiveInlining)] public (T,T,T,T,T,T) Tp6(){var s=Sp(Rl());return (Ct(s[0]),Ct(s[1]),Ct(s[2]),Ct(s[3]),Ct(s[4]),Ct(s[5]));} [MethodImpl(MethodImplOptions.AggressiveInlining)] public (T1,T2) Tp2(){var s=Sp(Rl());return (Ct(s[0]),Ct(s[1]));} [MethodImpl(MethodImplOptions.AggressiveInlining)] public (T1,T1,T2) Tp3(){var s=Sp(Rl());return (Ct(s[0]),Ct(s[1]),Ct(s[2]));} } public class Scs:Sc{ private StreamReader sr; public Scs(string t){sr=new StreamReader(t);} [MethodImpl(MethodImplOptions.AggressiveInlining)] protected override string Rl(){return sr.ReadLine();} } public class Sc2:Sc{ private string[] sps=new string[]{" "," ","\t"}; [MethodImpl(MethodImplOptions.AggressiveInlining)] protected override string[] Sp(string st){return st.Split(sps,StringSplitOptions.RemoveEmptyEntries);} public override int I{get{return int.Parse(Sp(Rl())[0]);}} public override long L{get{return long.Parse(Sp(Rl())[0]);}} public override double D{get{return double.Parse(Sp(Rl())[0]);}} public override string S{get{return Sp(Rl())[0];}} } public class Scs2:Sc2{ private StreamReader sr; public Scs2(string t){sr=new StreamReader(t);} [MethodImpl(MethodImplOptions.AggressiveInlining)] protected override string Rl(){return sr.ReadLine();} } public class Sct:Sc{ private List li=new List(); private int l=0; public void Add(int s){li.Add(s.ToString());} public void Add(long s){li.Add(s.ToString());} public void Add(double s){li.Add(s.ToString());} public void Add(string s){li.Add(s.ToString());} public void Add(object s){li.Add(s.ToString());} public void Add(int[] s){li.Add(string.Join(" ",s));} public void Add(long[] s){li.Add(string.Join(" ",s));} public void Add(double[] s){li.Add(string.Join(" ",s));} public void Add(string[] s){li.Add(string.Join(" ",s));} public void Add(object[] s){li.Add(string.Join(" ",s));} protected override string Rl(){return li[l++];} public void Clear(){li.Clear();l=0;} }