using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Runtime.CompilerServices; class Program { static string ReadLine() => Console.ReadLine().Trim(); static int ReadInt() => int.Parse(ReadLine()); static long ReadLong() => long.Parse(ReadLine()); static int[] ReadIntArray() { string str = ReadLine(); return str != "" ? str.Split().Select(_ => int.Parse(_)).ToArray() : new int[0]; } static long[] ReadLongArray() { string str = ReadLine(); return str != "" ? str.Split().Select(_ => long.Parse(_)).ToArray() : new long[0]; } static (int, int) ReadInt2() { int[] vs = ReadIntArray(); return (vs[0], vs[1]); } static (int, int, int) ReadInt3() { int[] vs = ReadIntArray(); return (vs[0], vs[1], vs[2]); } static (int, int, int, int) ReadInt4() { int[] vs = ReadIntArray(); return (vs[0], vs[1], vs[2], vs[3]); } static (int, int, int, int, int) ReadInt5() { int[] vs = ReadIntArray(); return (vs[0], vs[1], vs[2], vs[3], vs[4]); } static (long, long) ReadLong2() { long[] vs = ReadLongArray(); return (vs[0], vs[1]); } static (long, long, long) ReadLong3() { long[] vs = ReadLongArray(); return (vs[0], vs[1], vs[2]); } static void Main() { SourceExpander.Expander.Expand(); (long R, long P, long Q) = ReadInt3(); (long A, long B, long C, long D) = ReadInt4(); long ng = (A + B + C + D) / 3 + 10; long ok = 0; long aa = AtCoder.StlFunction.BinarySearch(ok, ng, mid => F(mid)); Console.WriteLine(aa); bool F(long x) { long husoku = 0; if(x - A > 0) husoku += x - A; if (x - B > 0) husoku += x - B; if (x - C > 0) husoku += x - C; long jouyo = 0; if (A - x > 0) jouyo += A - x; if (B - x > 0) jouyo += B - x; if (C - x > 0) jouyo += C - x; jouyo += D; if (husoku > jouyo) return false; return husoku * Q + x * P <= R; } } void F11() { (int N, int K) = ReadInt2(); long[] A = ReadLongArray(); long[] dp = new long[K + 1]; for (int i = 0; i < N; i++) { long v = A[i]; long[] n_dp = (long[])dp.Clone(); for (int j = 0; j <= K; j++) { if (j + 1 <= K && n_dp[j + 1] < dp[j] + v) n_dp[j + 1] = dp[j] + v; if (n_dp[j] < dp[j]) n_dp[j] = dp[j]; } dp = n_dp; } //Console.WriteLine(dp.Max()); } } #region Expanded by https://github.com/kzrnm/SourceExpander namespace AtCoder{public static class StlFunction{public struct NextPermutationEnumerator:IEnumerator,IEnumerablewhere T:IComparable{internal readonly IEnumerable_orig;internal NextPermutationEnumerator(IEnumerableorig){_orig=orig;Current=null;}public T[]Current{get;private set;}[MethodImpl(256)]public bool MoveNext(){if(Current==null){Current=_orig.ToArray();return true;}return NextPermutation(Current);}public void Reset()=>Current=null;object IEnumerator.Current=>Current;void IDisposable.Dispose(){}[MethodImpl(256)]public NextPermutationEnumeratorGetEnumerator()=>this;IEnumeratorIEnumerable.GetEnumerator()=>this;IEnumerator IEnumerable.GetEnumerator()=>this;}[MethodImpl(256)]public static bool NextPermutation(T[]array)where T:IComparable =>NextPermutation(array.AsSpan());[MethodImpl(256)]public static bool NextPermutation(Spanspan)where T:IComparable{int i;for(i=span.Length-2;i>=0;i--)if(span[i].CompareTo(span[i+1])<0)break;if(i<0)return false;int j;for(j=span.Length-1;j>=0;j--)if(span[i].CompareTo(span[j])<0)break;(span[i],span[j])=(span[j],span[i]);span.Slice(i+1,span.Length-i-1).Reverse();return true;}[MethodImpl(256)]public static NextPermutationEnumeratorPermutations(IEnumerableorig)where T:IComparable =>new NextPermutationEnumerator(orig);private struct DefaultComparer:IComparerwhere T:IComparable{[MethodImpl(256)]public int Compare(T x,T y)=>x.CompareTo(y);}[MethodImpl(256)]public static int BinarySearch(int ok,int ng,PredicateOk){while(Math.Abs(ok-ng)>1){var m=(ok+ng)>>1;if(Ok(m))ok=m;else ng=m;}return ok;}[MethodImpl(256)]public static long BinarySearch(long ok,long ng,PredicateOk){while(Math.Abs(ok-ng)>1){var m=(ok+ng)>>1;if(Ok(m))ok=m;else ng=m;}return ok;}}} namespace SourceExpander{public class Expander{[Conditional("EXP")]public static void Expand(string inputFilePath=null,string outputFilePath=null,bool ignoreAnyError=true){}public static string ExpandString(string inputFilePath=null,bool ignoreAnyError=true){return "";}}} #endregion Expanded by https://github.com/kzrnm/SourceExpander