using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var n = NN; var x = NList; var a = NList; var set = new HashSet(x); for (var i = 0; i < n; ++i) { set.Add(x[i] - a[i]); set.Add(x[i] + a[i]); } var list = new List(set); list.Sort(); var dic = new Dictionary(); for (var i = 0; i < list.Count; ++i) dic[list[i]] = i; var g = new SCCGraph(list.Count); for (var i = 0; i < n; ++i) { g.AddEdge(dic[x[i] - a[i]], dic[x[i]]); g.AddEdge(dic[x[i] + a[i]], dic[x[i]]); } var scc = g.SCC(); var gid = new int[list.Count]; for (var i = 0; i < scc.Length; ++i) foreach (var j in scc[i]) gid[j] = i; var tree = new List[scc.Length]; for (var i = 0; i < tree.Length; ++i) tree[i] = new List(); var refs = new int[scc.Length]; var max = new int[refs.Length]; for (var i = 0; i < n; ++i) { var f = dic[x[i] - a[i]]; var t = dic[x[i]]; max[gid[t]] = Math.Max(max[gid[t]], x[i]); max[gid[f]] = Math.Max(max[gid[f]], x[i] - a[i]); if (gid[f] != gid[t]) { tree[gid[f]].Add(gid[t]); ++refs[gid[t]]; } f = dic[x[i] + a[i]]; max[gid[f]] = Math.Max(max[gid[f]], x[i] + a[i]); if (gid[f] != gid[t]) { tree[gid[f]].Add(gid[t]); ++refs[gid[t]]; } } var q = new Queue(); for (var i = 0; i < refs.Length; ++i) if (refs[i] == 0) q.Enqueue(i); while (q.Count > 0) { var cur = q.Dequeue(); for (var i = tree[cur].Count - 1; i >= 0; --i) { max[tree[cur][i]] = Math.Max(max[tree[cur][i]], max[cur]); --refs[tree[cur][i]]; if (refs[tree[cur][i]] == 0) q.Enqueue(tree[cur][i]); tree[cur].RemoveAt(i); } } WriteLine(string.Join("\n" , x.Select(xi => max[gid[dic[xi]]] - xi))); } class SCCGraph { private int _n; private List<(int from, int to)> edges; public SCCGraph(int n) { _n = n; edges = new List<(int, int)>(); } public int NumVertices() { return _n; } public void AddEdge(int from, int to) { edges.Add((from, to )); } public (int, int[]) SCCIds() { var g = new CSR(_n, edges); var nowOrd = 0; var groupNum = 0; var visited = new List(_n); var low = new int[_n]; var ord = Enumerable.Repeat(-1, _n).ToArray(); var ids = new int[_n]; void DFS(int v) { low[v] = ord[v] = nowOrd++; visited.Add(v); for (var i = g.Start[v]; i < g.Start[v + 1]; ++i) { var to = g.EList[i]; if (ord[to] == -1) { DFS(to); low[v] = Math.Min(low[v], low[to]); } else low[v] = Math.Min(low[v], ord[to]); } if (low[v] == ord[v]) { while (true) { var u = visited.Last(); visited.RemoveAt(visited.Count - 1); ord[u] = _n; ids[u] = groupNum; if (u == v) break; } ++groupNum; } } for (var i = 0; i < _n; ++i) if (ord[i] == -1) DFS(i); for (var i = 0; i < ids.Length; ++i) ids[i] = groupNum - 1 - ids[i]; return (groupNum, ids); } public List[] SCC() { var (groupNum, list) = SCCIds(); var counts = new int[groupNum]; foreach (var x in list) ++counts[x]; var groups = new List[groupNum]; for (var i = 0; i < groups.Length; ++i) groups[i] = new List(counts[i]); for (var i = 0; i < _n; ++i) groups[list[i]].Add(i); return groups; } } // 有向辺のリスト class CSR { public int[] Start { get; private set; } public E[] EList { get; private set; } public CSR(int n, List<(int, E)> edges) { Start = new int[n + 1]; EList = new E[edges.Count]; foreach (var e in edges) ++Start[e.Item1 + 1]; for (var i = 1; i <= n; ++i) Start[i] += Start[i - 1]; var counter = (int[])Start.Clone(); foreach (var e in edges) { EList[counter[e.Item1]++] = e.Item2; } } } }