using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using static System.Math; using static Extensions; public static class Program { public static void Solve() { var n = I; var a = Repeat(n, () => L).ToArray(); var b = Repeat(n, () => L).ToArray(); var pq = new BinaryHeap(); var min = long.MaxValue; Repeat(n, i => { var max = 0L; a.ForEach(x => pq.Enqueue(x << 32)); Repeat(n, j => { j = (i + j >= n) ? (i + j - n) : (i + j); var t = pq.Dequeue(); var x = t >> 32; var y = t - (x << 32); max = Max(max, y + 1); pq.Enqueue((x + b[j] / 2 << 32) + y + 1); }); pq.Clear(); min = Min(min, max); }); Answer(min); } static TextScanner _ts; static int I => int.Parse(_ts.Next()); static long L => long.Parse(_ts.Next()); public static void Main() { var sw = new StreamWriter(Console.OpenStandardOutput()); sw.NewLine = "\n"; #if DEBUG sw.AutoFlush = true; #else sw.AutoFlush = false; #endif Console.SetOut(sw); _ts = new TextScanner(Console.In); Solve(); Console.Out.Flush(); } } #region Library #pragma warning disable public interface IPriorityQueue { int Count { get; } bool Any(); void Clear(); void Enqueue(T item); T Dequeue(); T Peek(); } public class BinaryHeap : IPriorityQueue { private readonly IComparer _comparer; private readonly List _t; public BinaryHeap() : this(Comparer.Default) { } public BinaryHeap(IComparer comparer) { _t = new List(); _comparer = comparer; } public BinaryHeap(int capacity) : this(capacity, Comparer.Default) { } public BinaryHeap(int capacity, IComparer comparer) { _t = new List(capacity); _comparer = comparer; } public int Count { get; private set; } public int Capacity => _t.Capacity; public bool Any() => this.Count > 0; public void Clear() { _t.Clear(); this.Count = 0; } public void TrimExcess() => _t.TrimExcess(); public void Enqueue(T item) { var i = this.Count++; while (i > 0) { var p = (i - 1) >> 1; if (_comparer.Compare(_t[p], item) <= 0) break; Set(i, _t[p]); i = p; } Set(i, item); } public T Dequeue() { if (this.Count == 0) throw new InvalidOperationException(); var ret = _t[0]; var x = _t[--this.Count]; var i = 0; while ((i << 1) + 1 < this.Count) { var a = (i << 1) + 1; var b = (i << 1) + 2; if (b < this.Count && _comparer.Compare(_t[b], _t[a]) < 0) a = b; if (_comparer.Compare(_t[a], x) >= 0) break; _t[i] = _t[a]; i = a; } _t[i] = x; return ret; } public T Peek() { if (this.Count == 0) throw new InvalidOperationException(); return _t[0]; } private void Set(int i, T value) { if (i < _t.Count) _t[i] = value; else if (i == _t.Count) _t.Add(value); else throw new InvalidOperationException(); } } public class TextScanner { private readonly TextReader _tr; public TextScanner(TextReader tr) { _tr = tr; } public string Next() { var sb = new StringBuilder(); int i; do { i = _tr.Read(); if (i == -1) throw new EndOfStreamException(); } while (char.IsWhiteSpace((char)i)); while (i != -1 && !char.IsWhiteSpace((char)i)) { sb.Append((char)i); i = _tr.Read(); } return sb.ToString(); } } public static class Constants { } [DebuggerStepThrough] public static partial class Extensions { public static void Answer(object value) { Console.WriteLine(value); Exit(0); } public static void Exit(int exitCode) { Console.Out.Flush(); Environment.Exit(exitCode); } public static void ForEach(this IEnumerable source, Action action) { foreach (var item in source) action(item); } public static void Repeat(int count, Action action) { for (var i = 0; i < count; i++) action(i); } public static IEnumerable Repeat(int count, Func func) { for (var i = 0; i < count; i++) yield return func(); } } [DebuggerStepThrough] public static class MathExtensions { } #pragma warning restore #endregion