import java.util.*;
import java.io.*;
import java.math.*;
public class loser
{
    static class InputReader {
        public BufferedReader br;
        public StringTokenizer token;
        public InputReader(InputStream stream)
        {
            br=new BufferedReader(new InputStreamReader(stream),32768);
            token=null;
        }

        public String next()
        {
            while(token==null || !token.hasMoreTokens())
            {
                try
                {
                    token=new StringTokenizer(br.readLine());
                }
                catch(IOException e)
                {
                    throw new RuntimeException(e);
                }
            }
            return token.nextToken();
        }

        public int nextInt()
        {
            return Integer.parseInt(next());
        }

        public long nextLong()
        {
            return Long.parseLong(next());
        }
    }
    static class card{
        int l;
        int r;
        public card(int ch,int i)
        {
            this.l=ch;
            this.r=i;
        }
    }
    static class sort implements Comparator<card>
    {
        public int compare(card o1,card o2)
        {
            if(o1.l!=o2.l)
                return (int)(o1.l-o2.l);
            else
                return (int)(o1.r-o2.r);
        }
    }
    static void shuffle(long a[])
    {
        List<Long> l=new ArrayList<>();
        for(int i=0;i<a.length;i++)
            l.add(a[i]);
        Collections.shuffle(l);
        for(int i=0;i<a.length;i++)
            a[i]=l.get(i);
    }

    /*static long gcd(long a,long b)
    {
    if(b==0)
    return a;
    else
    return gcd(b,a%b);
    }
    static int ans1=Integer.MAX_VALUE,ans2=Integer.MAX_VALUE,ans3=Integer.MAX_VALUE,ans4=Integer.MAX_VALUE;
    static boolean v[]=new boolean[101];
    static void dfs(Integer so,Set<Integer> s[]){
    if(!v[so.intValue()])
    {
    v[so]=true;
    for(Integer h:s[so.intValue()])
    {
    if(!v[h.intValue()])
    dfs(h,s);
    }
    }
    }
    static class Print{
    public PrintWriter out;
    Print(OutputStream o)
    {
    out=new PrintWriter(o);
    }
    }
    static int CeilIndex(int A[], int l, int r, int key)
    {
    while (r - l > 1) {
    int m = l + (r - l) / 2;
    if (A[m] >= key)
    r = m;
    else
    l = m;
    }

    return r;
    }

    static int LongestIncreasingSubsequenceLength(int A[], int size)
    {
    // Add boundary case, when array size is one
    int[] tailTable = new int[size];
    int len; // always points empty slot
    tailTable[0] = A[0];
    len = 1;
    for (int i = 1; i < size; i++) {
    if (A[i] < tailTable[0])
    // new smallest value
    tailTable[0] = A[i];

    else if (A[i] > tailTable[len - 1])
    // A[i] wants to extend largest subsequence
    tailTable[len++] = A[i];

    else
    // A[i] wants to be current end candidate of an existing
    // subsequence. It will replace ceil value in tailTable
    tailTable[CeilIndex(tailTable, -1, len - 1, A[i])] = A[i];
    }
    return len;
    }*/
    /*static int binary(int n)
    {
    int s=1;
    while(n>0)
    {
    s=s<<1;
    n--;
    }
    return s-1;
    }
    static StringBuilder bin(int i,int n)
    {
    StringBuilder s=new StringBuilder();
    while(i>0)
    {
    s.append(i%2);
    i=i/2;
    }
    while(s.length()!=n)
    {
    s.append(0);
    }
    return s.reverse();
    }*/
    public static void main(String[] args)
    {
        InputReader sc=new InputReader(System.in);
        long c=sc.nextLong();
        long vo=sc.nextLong();
        long v1=sc.nextLong();
        long a=sc.nextLong();
        long l=sc.nextLong();int c1=1;
        long t=vo,t1=vo;
        while(t<c)
        {
            c1++;
            t1=Math.min(t1+a,v1);
            t+=t1-l;
            //System.out.println(t1+" "+t);
        }
        System.out.println(c1);
    }
}


import	java.util.*;
public	class	Main{
	static	int	LsPr(int	n){
		boolean[]F=new	boolean[1+n];
		int	i=0,j=0;
		while(!F[n]&&n>i)	if(!F[++i]&&i+j++<n)	F[j+i]=true;
		return	n>i?0:j+i;
	}
	public	static	void	main(String[]args){
		Scanner	cin=new	Scanner(System.in);
		int	s=0,n=cin.nextInt(),i=0,Q[]=new	int[3];
		for(;n>i;s^=Q[i++]=cin.nextInt());
		if(2==n){
			if(Q[0]>Q[1]){i=Q[0];Q[0]=Q[1];Q[1]=i;}
			System.out.print(LsPr(Q[0])!=Q[1]?"BitLGM":"BitAryo");
		}else	System.out.print(0<s?"BitLGM":"BitAryo");
	}
}


import java.math.*;

import java.util.*;

public class BruteForce {

    public static Scanner in =new Scanner(System.in);
    public static BigInteger getN(String x){
        StringBuilder build=new StringBuilder(x);
        x=build.reverse().toString();
        BigInteger  sum=new BigInteger("0");
        for(int i=0;i<x.length();i++){
            int c=Integer.parseInt(x.charAt(i)+"");
            int s=(int)(Math.pow(2,i)*c);
            BigInteger  cur=new BigInteger(s+"");
            sum=sum.add(cur);
        }
        return sum;
    }
    public static String getB(int n){
        String x="";
        while(n > 0)
        {
            int a = n % 2;
            x = a + x;
            n = n / 2;
        }
        return x;
    }
    public static ArrayList<Integer> sieve(int n){
        long sqr=(long) Math.sqrt(n);
        boolean[] isPrime=new boolean[n+1];
        for(int i=0;i<=n;i++)
            isPrime[i]=true;
        for(int i=2;i<=sqr;i++){
            if(isPrime[i]){
                for(int p=i*i;p<=n;p+=i)
                    isPrime[p]=false;
            }
        }
        ArrayList<Integer> list=new ArrayList<Integer>();
        for(int i=0;i<=n;i++)
            if(isPrime[i])
                list.add(i);
        list.remove(0);
        list.remove(0);
        return list;
    }
    public static boolean isPrime(long n){
        boolean res=true;
        List l =sieve((int) Math.sqrt(n));
        for(int i=0;i<l.size();i++){
            int curPrime=(int) l.get(i);
            if(n%curPrime==0){
            res=false;
            break;
            }
        }
        return res;
    }
    public static void main(String[] args){
        int n=in.nextInt();
        int pos=in.nextInt();
        int l=in.nextInt();
        int r=in.nextInt();
         int left=l-1;
            int right=n-r;
        if(l==1&&r==n)
            System.out.println("0");
        else if(left==0){

            System.out.println(Math.abs(r-pos)+1);
        }
        else if(right==0){
            System.out.println(Math.abs(pos-l)+1);
        }
        else{

            int d1=Math.abs(pos-l);
            int d2=Math.abs(pos-r);
            int cost=0;
            cost+=Math.min(d1,d2)+1;
            cost+=(r-l+1);
            System.out.println(cost);
            //System.out.println(d1+" "+d2);
        }
    }

}


import java.util.*;

public class helloWorld
{
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		int d = in.nextInt();
		int L = in.nextInt();
		int v1 = in.nextInt();
		int v2 = in.nextInt();

		double ans = L-d;
		ans /= v1 + v2;

		System.out.println(ans);

		in.close();
	}
}


import java.util.*;
import java.io.*;
import java.math.*;
public class Tester {
	public static void main(String args[])
	{
		//Map<Integer, Integer> hm=new HashMap<>();
		Scanner sc=new Scanner(System.in);
			int i,j,k,l=1,r,m=1,n,o,p,a,b,c,d,x,t,h,count=0,max=Integer.MAX_VALUE,sum=0,index=0,temp;
			BigInteger bi1=BigInteger.ZERO, bi2=BigInteger.ONE;
			n=sc.nextInt();
			a=sc.nextInt();
			b=sc.nextInt();
			c=sc.nextInt();
			d=sc.nextInt();
			for(x=1;x<=n;x++)
			{
				int y=x+b-c;
				int z=x+a-d;
				int w=z+b-c;
				if((y>=1&&y<=n)&&(z>=1&&z<=n)&&(w>=1&&w<=n))
				{
					count++;
				}
			}
			bi2=bi2.multiply(BigInteger.valueOf(count));
			bi2=bi2.multiply(BigInteger.valueOf(n));
			System.out.println(bi2);
	}
}


import java.util.Scanner;

public class Main {
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);

    int N = scan.nextInt(), A = scan.nextInt(), B = scan.nextInt();
    int ans = 1;
    if(B >= 0){
      ans = (A + B) % N;
    }
    else{
      B = -B % N;
      ans = (A - B + N) % N;
    }
    if(ans == 0){
      ans = N;
    }

    System.out.println(ans);
  }
}


import java.util.Scanner;

public class A {
    public static int gcd(int x, int y) {
        return y == 0 ? x : gcd(y, x % y);
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] A = new int[n];
        for (int i = 0; i < n; i++)
            A[i] = in.nextInt();
        int min = A[0];
        for (int i = 1; i < n; i++)
            min = gcd(min, A[i]);
        System.out.println(n * min);
    }
}


//When I wrote this code, only God & I understood what it did. Now only God knows !!

import java.util.*;
import java.io.*;
import java.math.*;

public class Main {

    static class FastReader
    {
        private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public FastReader() { this(System.in); }public FastReader(InputStream is) { mIs = is;}
        public int read() {if (numChars == -1) throw new InputMismatchException();if (curChar >= numChars) {curChar = 0;try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}if (numChars <= 0) return -1; }return buf[curChar++];}
        public String nextLine(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isEndOfLine(c));return res.toString() ;}
        public String next(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();}
        public long l(){int c = read();while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }long res = 0; do{ if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read();}while(!isSpaceChar(c));return res * sgn;}
        public int i(){int c = read() ;while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }int res = 0;do{if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read() ;}while(!isSpaceChar(c));return res * sgn;}
        public double d() throws IOException {return Double.parseDouble(next()) ;}
        public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; }
        public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; }
        public void scanIntArr(int [] arr){ for(int li=0;li<arr.length;++li){ arr[li]=i();}}
        public void scanLongArr(long [] arr){for (int i=0;i<arr.length;++i){arr[i]=l();}}
        public void shuffle(int [] arr){ for(int i=arr.length;i>0;--i) { int r=(int)(Math.random()*i); int temp=arr[i-1]; arr[i-1]=arr[r]; arr[r]=temp; } }
    }

    public static void main(String[] args) throws IOException {

        FastReader fr = new FastReader();
        PrintWriter pw = new PrintWriter(System.out);
        /*
inputCopy
11 3
outputCopy
5
inputCopy
11 6
outputCopy
4
inputCopy
20 20
outputCopy
1
inputCopy
14 5
outputCopy
6
inputCopy
1000000 100
outputCopy
31248
  */
        long n=fr.l();
        long k=fr.l();
        long right=n;
        long left=1;
        while(left<right)
        {
            if(left/2 == right/2)
                break;
            long mid=(left+right)/2;
            long curK=0;
            long other=mid%2==0?mid-1:mid+1;
            long curK1=getK(mid,n);
            long curK2=getK(other,n);
            curK=Math.max(curK1,curK2);
            //System.err.println(mid+" "+curK);
            if(curK<k)
                right=mid-1;
            else
                left=mid+1;
        }
        //System.err.println("left="+left);
        left+=4;
        long k2=getK(left,n);
        while(k2<k || left>n) {
            --left;
            k2=getK(left,n);
        }
        pw.println(left);
        pw.flush();
        pw.close();
    }
    public static long getK(long num,long n)
    {
        long curK=0;
        long lowerBound=num;
        long upperBound=num%2==0?num+1:num;
        while(upperBound<n)
        {
            curK+=(upperBound-lowerBound)+1;
            lowerBound*=2;
            upperBound=2*upperBound+1;
        }
        curK+=Math.max((n-lowerBound)+1,0);
        return curK;
    }
}


import java.util.Scanner;

public class RobotSequence {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
	int n = in.nextInt();
	char[] commands = in.next().toCharArray();
	start(n, commands);
  }

  private static void start(int n, char[] commands) {
   	int toReturn = 0;
    int[] countsUDLR = new int[4];

    for (int i = 0; i < n - 1; i++) {
      countsUDLR = new int[4];
      countDir(commands[i], countsUDLR);

      for (int j = i + 1; j < n; j++) {
        countDir(commands[j], countsUDLR);
        if (atStart(countsUDLR)) {
          toReturn++;
        }
      }
    }

    System.out.println(toReturn);
  }

  private static void countDir(char dir, int[] counts) {
    if (dir == 'U') {
      counts[0]++;
    } else if (dir == 'D') {
      counts[1]++;
    } else if (dir == 'L') {
      counts[2]++;
    } else {
      counts[3]++;
    }
  }

  private static boolean atStart(int[] counts) {
    return counts[0] == counts[1] && counts[2] == counts[3];
  }
}


import java.util.*;
import java.io.*;
import java.text.*;

public class Main {
    //SOLUTION BEGIN
    //Into the Hardware Mode
    long MOD = 998244353;
    void pre() throws Exception{}
    void solve(int TC) throws Exception{
        int N = ni();
        long K = nl();
        int diff = 0;
        int[] h = new int[N];
        for(int i = 0; i< N; i++)h[i] = ni();
        for(int i = 0; i< N; i++)if(h[i] != h[(i+1)%N])diff++;
        long[] F = new long[1+diff], IF = new long[1+diff];
        F[0] = 1;IF[0] = 1;
        for(int i = 1; i<= diff; i++)F[i] = (F[i-1]*i)%MOD;
        IF[diff] = pow(F[diff], MOD-2);
        for(int i = diff-1; i >= 1; i--)IF[i] = (IF[i+1]*(i+1))%MOD;
        long ans = 0;
        for(int k = 0; 2*k <= diff; k++)
            ans += mul(pow(K-2, diff-2*k), F[diff], IF[k], IF[k], IF[diff-2*k]);
        ans = mul(ans, pow(K, N-diff));
        ans = (pow(K, N)+MOD-ans)%MOD;
        pn(mul(ans, pow(2, MOD-2)));
    }
    long mul(long... a){
        long o = 1;
        for(long x:a)o = (x*o)%MOD;
        return o;
    }
    long pow(long a, long p){
        long o = 1;
        for(;p>0;p>>=1){
            if((p&1)==1)o = (o*a)%MOD;
            a = (a*a)%MOD;
        }
        return o;
    }
    //SOLUTION END
    void hold(boolean b)throws Exception{if(!b)throw new Exception("Hold right there, Sparky!");}
    void exit(boolean b){if(!b)System.exit(0);}
    static void debug(Object... o){System.out.println(Arrays.deepToString(o));}
    final long IINF = (long)2e18;
    final int INF = (int)1e9+2;
    DecimalFormat df = new DecimalFormat("0.00000000000");
    double PI = 3.141592653589793238462643383279502884197169399, eps = 1e-8;
    static boolean multipleTC = false, memory = false, fileIO = false;
    FastReader in;PrintWriter out;
    void run() throws Exception{
        long ct = System.currentTimeMillis();
        if (fileIO) {
            in = new FastReader("");
            out = new PrintWriter("");
        } else {
            in = new FastReader();
            out = new PrintWriter(System.out);
        }
        //Solution Credits: Taranpreet Singh
        int T = multipleTC? ni():1;
        pre();
        for (int t = 1; t <= T; t++) solve(t);
        out.flush();
        out.close();
        System.err.println(System.currentTimeMillis() - ct);
    }
    public static void main(String[] args) throws Exception{
        if(memory)new Thread(null, new Runnable() {public void run(){try{new Main().run();}catch(Exception e){e.printStackTrace();}}}, "1", 1 << 28).start();
        else new Main().run();
    }
    int[][] make(int n, int[] from, int[] to, int e, boolean f){
        int[][] g = new int[n][];int[]cnt = new int[n];
        for(int i = 0; i< e; i++){
            cnt[from[i]]++;
            if(f)cnt[to[i]]++;
        }
        for(int i = 0; i< n; i++)g[i] = new int[cnt[i]];
        for(int i = 0; i< e; i++){
            g[from[i]][--cnt[from[i]]] = to[i];
            if(f)g[to[i]][--cnt[to[i]]] = from[i];
        }
        return g;
    }
    int[][][] makeS(int n, int[] from, int[] to, int e, boolean f){
        int[][][] g = new int[n][][];int[]cnt = new int[n];
        for(int i = 0; i< e; i++){
            cnt[from[i]]++;
            if(f)cnt[to[i]]++;
        }
        for(int i = 0; i< n; i++)g[i] = new int[cnt[i]][];
        for(int i = 0; i< e; i++){
            g[from[i]][--cnt[from[i]]] = new int[]{to[i], i, 0};
            if(f)g[to[i]][--cnt[to[i]]] = new int[]{from[i], i, 1};
        }
        return g;
    }
    int find(int[] set, int u){return set[u] = (set[u] == u?u:find(set, set[u]));}
    int digit(long s){int ans = 0;while(s>0){s/=10;ans++;}return ans;}
    long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
    int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
    int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}
    void p(Object o){out.print(o);}
    void pn(Object o){out.println(o);}
    void pni(Object o){out.println(o);out.flush();}
    String n()throws Exception{return in.next();}
    String nln()throws Exception{return in.nextLine();}
    int ni()throws Exception{return Integer.parseInt(in.next());}
    long nl()throws Exception{return Long.parseLong(in.next());}
    double nd()throws Exception{return Double.parseDouble(in.next());}

    class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

        String next() throws Exception{
            while (st == null || !st.hasMoreElements()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (IOException  e){
                    throw new Exception(e.toString());
                }
            }
            return st.nextToken();
        }

        String nextLine() throws Exception{
            String str;
            try{
                str = br.readLine();
            }catch (IOException e){
                throw new Exception(e.toString());
            }
            return str;
        }
    }
}


import java.lang.Math;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner newSc = new Scanner(System.in);
        int a = newSc.nextInt();
        int b = newSc.nextInt();
        if(a == b)
            System.out.println(0);
        int n = Math.max(a, b) - (Math.min(a, b) + Math.abs(a - b) / 2);
        if(a % 2 == b % 2)
            System.out.println(n * (n + 1));
        else
            System.out.println(n * n);

    }
    }


/**
 * 24/12/19
 */

import java.util.*;

public class A0908_Counting {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();

        System.out.println(s.length() - s.replaceAll("a|e|i|o|u|1|3|5|7|9", "").length());
    }
}


import java.util.Arrays;
import java.util.Scanner;

/**
 * Created by vinayr on 8/2/17.
 */
public class CorrectSolution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String val = sc.nextLine();
        String val1 = sc.nextLine();
        char[] arr = val.toCharArray();
        Arrays.sort(arr);
        int i;
        for (i = 0; i < arr.length && arr[i] == '0'; i++) ;
            if (i != 0 && i < arr.length) {
                arr[0] = arr[i];
                arr[i] = '0';
            }

        String ans = new String(arr);
       // System.out.println(ans);
        if (ans.equals(val1)) {
            System.out.println("OK");
        } else
            System.out.println("WRONG_ANSWER");
    }
}


import java.io.*;

public class A {

    BufferedReader read=new BufferedReader(new InputStreamReader(System.in));
    BufferedWriter write=new BufferedWriter(new OutputStreamWriter(System.out));

    void solve(String[] s,String[] s2) throws Exception{
        int x1=Integer.parseInt(s[0]);
        int y1=Integer.parseInt(s[1]);
        int x2=Integer.parseInt(s[2]);
        int y2=Integer.parseInt(s[3]);
        int x=Integer.parseInt(s2[0]);
        int y=Integer.parseInt(s2[1]);
        int dx = Math.abs(x1 - x2) / x, dy = Math.abs(y1 - y2) / y;
        int max = Math.max(dx, dy);
        int min = Math.min(dx, dy);
        write.write((x1 - x2) % x == 0 && (y1 - y2) % y == 0 && (max - min) % 2 == 0 ? "YES" : "NO");

        write.flush();
        write.close();

    }
    void run()  throws Exception{
        String[] si=read.readLine().split(" ");
        String[] se=read.readLine().split(" ");
        solve(si,se);
    }
    public static void main(String[] args) throws Exception {
        new A().run();
    }

}


import java.util.Scanner;

public class VusTheCossackAndContest_1186A {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int a = s.nextInt();
        int b = s.nextInt();
        if(a>=n && b>=n){
            System.out.println("YES");
        }
        else{
            System.out.println("NO");
        }
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.InputStream;

public class Main {

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AGennaAndACardGame solver = new AGennaAndACardGame();
        solver.solve(1, in, out);
        out.close();
    }

    static class AGennaAndACardGame {

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            char[] c = in.nextCharArray();
            for (int i = 0; i < 5; ++i) {
                char[] t = in.nextCharArray();
                if (c[0] == t[0] || c[1] == t[1]) {
                    out.println("YES");
                    return;
                }
            }
            out.println("NO");
        }

    }

    static class InputReader {

        private InputStream stream;
        private static final int DEFAULT_BUFFER_SIZE = 1 << 16;
        private static final int EOF = -1;
        private byte[] buf = new byte[DEFAULT_BUFFER_SIZE];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (this.numChars == EOF) {
                throw new UnknownError();
            } else {
                if (this.curChar >= this.numChars) {
                    this.curChar = 0;

                    try {
                        this.numChars = this.stream.read(this.buf);
                    } catch (IOException ex) {
                        throw new InputMismatchException();
                    }

                    if (this.numChars <= 0) {
                        return EOF;
                    }
                }

                return this.buf[this.curChar++];
            }
        }

        public String next() {
            int c;
            while (isSpaceChar(c = this.read())) {
            }

            StringBuilder result = new StringBuilder();
            result.appendCodePoint(c);

            while (!isSpaceChar(c = this.read())) {
                result.appendCodePoint(c);
            }

            return result.toString();
        }

        public static boolean isSpaceChar(int c) {
            return c == 32 || c == 10 || c == 13 || c == 9 || c == EOF;
        }

        public char[] nextCharArray() {
            return next().toCharArray();
        }

    }
}


import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

// Title
// 2012/10/31
public class P059C{
	Scanner sc=new Scanner(System.in);

	int k;
	String s;

	void run(){
		k=sc.nextInt();
		s=sc.next();
		solve();
	}

	void solve(){
		int n=s.length();
		int[] a=new int[n];
		for(int i=0; i<n; i++){
			if(Character.isLetter(s.charAt(i))){
				a[i]=s.charAt(i)-'a';
			}else{
				a[i]=-1;
			}
		}
		LinkedList<Integer> indices=new LinkedList<Integer>();
		LinkedList<Integer> unused=new LinkedList<Integer>();
		for(int i=0; i<k; i++){
			unused.addFirst(i);
		}
		boolean ok=true;
		for(int i=0;; i++){
			int j=n-1-i;
			if(i>j){
				break;
			}
			if(a[i]==-1&&a[j]==-1){
				indices.addFirst(i);
			}else if(a[i]==-1^a[j]==-1){
				a[i]=a[j]=a[i]==-1?a[j]:a[i];
				unused.remove((Integer)a[i]);
			}else{
				ok&=a[i]==a[j];
				unused.remove((Integer)a[i]);
			}
		}
		ok&=indices.size()>=unused.size();

		for(int i : indices){
			int j=n-1-i;
			int v;
			if(unused.size()==0){
				v=0;
			}else{
				v=unused.removeFirst();
			}
			a[i]=a[j]=v;
		}
		String ans="";;
		for(int i=0; i<n; i++){
			ans+=(char)(a[i]+'a');
		}
		if(!ok){
			ans="IMPOSSIBLE";
		}
		println(ans);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		Locale.setDefault(Locale.US);
		new P059C().run();
	}
}


import static java.lang.Math.*;
import static java.lang.System.currentTimeMillis;
import static java.lang.System.exit;
import static java.lang.System.arraycopy;
import static java.util.Arrays.sort;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.fill;
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException {
		try {
			if (new File("input.txt").exists())
				System.setIn(new FileInputStream("input.txt"));
		} catch (SecurityException e) {
		}
		new Thread(null, new Runnable() {
			public void run() {
				try {
					new Main().run();
				} catch (Throwable e) {
					e.printStackTrace();
					exit(999);
				}
			}
		}, "1", 1 << 23).start();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st = new StringTokenizer("");

	private void run() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		int k = nextInt();
		String s = nextLine();
		int L = s.length();
		int l,r;
		l = (L>>1) - ((L&1)^1);
		r = L>>1;
		boolean f = true;
		int pos = k-1;
		boolean used[] = new boolean[100];
		char cl,cr;
		char ms[] = s.toCharArray();
		for(int i = l; i >= 0; i--)
			if(ms[i] >= 'a')used[ms[i]-'a'] = true;
		for(int i = r; i < L; i++)
			if(ms[i] >= 'a')used[ms[i]-'a'] = true;
		while(used[pos] && pos>0)
			pos--;
		while(l>=0){
			cl = ms[l];
			cr = ms[r];
			if(cl == cr && cr!='?'){
				used[ms[l]-'a'] = true;
				l--;r++;
				continue;
			}
			if(cl!=cr && cl!='?' && cr!='?'){
				f = false;
				break;
			}
			if(cl =='?' && cr!='?'){
				ms[l] = ms[r];
				used[ms[l]-'a'] = true;
				l--;r++;
				continue;
			}
			if(cl !='?' && cr=='?'){
				ms[r] = ms[l];
				used[ms[l]-'a'] = true;
				l--;r++;
				continue;
			}
			while(used[pos] && pos>0)
				pos--;
			if(cl == '?' && cr == '?'){
				ms[l] = ms[r] = (char)('a'+pos);
				used[pos] = true;
				while(used[pos] && pos>0)
					pos--;
				l--;r++;
				continue;
			}
			out.println("trololo");
		}
		while(used[pos] && pos>0)
			pos--;
		if(f && pos==0 && used[0] == true)
			out.println(ms);
		else
			out.println("IMPOSSIBLE");

		in.close();
		out.close();
	}

	void chk(boolean b) {
		if (b)
			return;
		System.out.println(new Error().getStackTrace()[1]);
		exit(999);
	}
	void deb(String fmt, Object... args) {
		System.out.printf(Locale.US, fmt + "%n", args);
	}
	String nextToken() throws IOException {
		while (!st.hasMoreTokens())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}
	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}
	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}
	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
	String nextLine() throws IOException {
		st = new StringTokenizer("");
		return in.readLine();
	}
	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String s = in.readLine();
			if (s == null)
				return true;
			st = new StringTokenizer(s);
		}
		return false;
	}
}


import java.util.*;

public class C {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int k = s.nextInt();
		char cs[] = s.next().toCharArray();
		int r = 0, n = cs.length;
		BitSet used = new BitSet();
		for (int i = 0; i < n / 2; ++i) {
			char a = cs[i], b = cs[n - i - 1];
			if (a != '?' && b != '?' && a != b) {
				System.out.println("IMPOSSIBLE");
				return;
			}
			if (a == '?' && b != '?') {
				cs[i] = b;
				used.set(b - 'a');
			} else if (a != '?' && b == '?') {
				cs[n - i - 1] = a;
				used.set(a - 'a');
			} else if (a == '?' && b == '?') {
				++r;
			} else {
				used.set(a - 'a');
			}
		}
		if (n % 2 > 0) {
			if (cs[n / 2] == '?') {
				++r;
			} else {
				used.set(cs[n / 2] - 'a');
			}
		}
		int c = used.cardinality();
		if (k > r + c) {
			System.out.println("IMPOSSIBLE");
			return;
		}
		int p = 0;
		for (int i = 0; i < n / 2; ++i) {
			if (cs[i] == '?') {
				--r;
				if (r < k - c) {
					p = used.nextClearBit(p);
					cs[i] = cs[n-i-1] = (char)('a' + p);
					used.set(p);
				} else {
					cs[i] = cs[n - i - 1] = 'a';
				}
			}
		}
		if (n % 2 > 0) {
			if (cs[n / 2] == '?') {
				if(r < k - c){
				cs[n/2] = (char)('a' + used.nextClearBit(p));
				}else{
					cs[n/2] = 'a';
				}
			}
		}
		System.out.println(new String(cs));
	}
}


import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.Queue;
import java.util.Set;
import java.util.TreeSet;

public class Main
{
	public void foo()
	{
		MyScanner scan = new MyScanner();
		int k = scan.nextInt();
		char[] a = scan.next().toCharArray();
		boolean[] vis = new boolean[k];
		int cnt = 0;
		boolean isImpossible = false;
		int n = a.length;
		for(int i = 0;i <= (n - 1) / 2;++i)
		{
			if('?' == a[i] && '?' == a[n - 1 - i])
			{
				++cnt;
			}
			else if('?' == a[i] && a[n - 1 - i] != '?')
			{
				if(a[n - 1 - i] - 'a' >= k)
				{
					isImpossible = true;
					break;
				}
				vis[a[n - 1 - i] - 'a'] = true;
				a[i] = a[n - 1 - i];
			}
			else if(a[i] != '?' && '?' == a[n - 1 - i])
			{
				if(a[i] - 'a' >= k)
				{
					isImpossible = true;
					break;
				}
				vis[a[i] - 'a'] = true;
				a[n - 1 - i] = a[i];
			}
			else
			{
				if(a[i] != a[n - 1 - i] || a[i] - 'a' >= k)
				{
					isImpossible = true;
					break;
				}
				else
				{
					vis[a[i] - 'a'] = true;
				}
			}
		}
		if(isImpossible)
		{
			System.out.println("IMPOSSIBLE");
		}
		else
		{
			ArrayList<Character> arr = new ArrayList<Character>();
			for(int i = k - 1;i >= 0;--i)
			{
				if(!vis[i])
				{
					--cnt;
					arr.add((char)(i + 'a'));
				}
			}
			if(cnt < 0)
			{
				System.out.println("IMPOSSIBLE");
			}
			else
			{
				int j = 0;
				for(int i = (n - 1) / 2;i >= 0;--i)
				{
					if('?' == a[i])
					{
						if(j < arr.size())
						{
							a[i] = arr.get(j++);
							a[n - 1 - i] = a[i];
 						}
						else
						{
							a[i] = 'a';
							a[n - 1 - i] = 'a';
						}
					}
				}
				System.out.println(a);
			}
		}
	}

	public static void main(String[] args)
	{
		new Main().foo();
	}

	class MyScanner
	{
	    private byte[] buf = new byte[1024];
	    private int curChar;
	    private int numChars;
	    BufferedInputStream bis = new BufferedInputStream(System.in);

	    public int read()
	    {
	        if (-1 == numChars)
	        {
	        	throw new InputMismatchException();
	        }
	        if (curChar >= numChars)
	        {
	            curChar = 0;
	            try
	            {
	                numChars = bis.read(buf);
	            }
	            catch (IOException e)
	            {
	                throw new InputMismatchException();
	            }
	            if (numChars <= 0)
	            {
	            	return -1;
	            }
	        }
	        return buf[curChar++];
	    }

	    public int nextInt()
	    {
	        int c = read();
	        while (isSpaceChar(c))
	        {
	        	c = read();
	        }
	        int sgn = 1;
	        if (c == '-')
	        {
	            sgn = -1;
	            c = read();
	        }
	        int res = 0;
	        do
	        {
	            if (c < '0' || c > '9')
	            {
	            	throw new InputMismatchException();
	            }
	            res *= 10;
	            res += c - '0';
	            c = read();
	        } while (!isSpaceChar(c));
	        return res * sgn;
	    }

	    public long nextLong()
	    {
	    	int c = read();
	    	while (isSpaceChar(c))
	    	{
	    		c = read();
	    	}
	    	int sgn = 1;
	    	if (c == '-')
	    	{
	    		sgn = -1;
	    		c = read();
	    	}
	    	long res = 0;
	    	do
	    	{
	    		if (c < '0' || c > '9')
	    		{
	    			throw new InputMismatchException();
	    		}
	    		res *= 10;
	    		res += c - '0';
	    		c = read();
	    	} while (!isSpaceChar(c));
	    	return res * sgn;
	    }

	    public String next()
	    {
	        int c = read();
	        while (isSpaceChar(c))
	        {
	        	c = read();
	        }
	        StringBuilder res = new StringBuilder();
	        do
	        {
	            res.appendCodePoint(c);
	            c = read();
	        } while (!isSpaceChar(c));
	        return res.toString();
	    }

	    private boolean isSpaceChar(int c)
	    {
	        return ' ' == c || '\n' == c || '\r' == c || '\t' == c || -1 == c;
	    }
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Washoum
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        inputClass in = new inputClass(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CTitle solver = new CTitle();
        solver.solve(1, in, out);
        out.close();
    }

    static class CTitle {
        public void solve(int testNumber, inputClass sc, PrintWriter out) {
            int n = sc.nextInt();
            StringBuilder s = new StringBuilder(sc.nextLine());
            boolean[] used = new boolean[n];
            int len = s.length();
            int nb = 0;
            for (int i = 0; i < s.length() / 2 + (len % 2 == 0 ? 0 : 1); i++) {
                if (s.charAt(i) == '?' && s.charAt(len - 1 - i) == '?') {
                    nb++;
                    continue;
                }
                if (s.charAt(i) == '?' || s.charAt(len - 1 - i) == '?') {
                    if (s.charAt(i) == '?') {
                        s.setCharAt(i, s.charAt(len - 1 - i));
                    } else {
                        s.setCharAt(len - 1 - i, s.charAt(i));
                    }
                }
                if (s.charAt(i) != s.charAt(len - 1 - i)) {
                    out.println("IMPOSSIBLE");
                    return;
                }
                used[s.charAt(i) - 'a'] = true;
            }
            int toadd = 0;
            for (int i = 0; i < n; i++) {
                if (!used[i])
                    toadd++;
            }
            if (toadd > nb) {
                out.println("IMPOSSIBLE");
                return;
            }
            int nxt = 0;
            for (; nxt < n; nxt++) {
                if (!used[nxt])
                    break;
            }
            for (int i = 0; i < s.length() / 2 + (len % 2 == 0 ? 0 : 1); i++) {
                if (s.charAt(i) == '?') {
                    if (nb > toadd) {
                        s.setCharAt(i, 'a');
                        s.setCharAt(len - 1 - i, 'a');
                        nb--;
                    } else {
                        s.setCharAt(i, (char) (nxt + 'a'));
                        s.setCharAt(len - 1 - i, (char) (nxt + 'a'));
                        nxt++;
                        while (nxt < n && used[nxt]) nxt++;
                    }
                }
            }
            out.println(s);
        }

    }

    static class inputClass {
        BufferedReader br;
        StringTokenizer st;

        public inputClass(InputStream in) {

            br = new BufferedReader(new InputStreamReader(in));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
}


import java.io.*;
import java.util.*;
import java.math.*;

public class C implements Runnable {

	void solve() {
		int k = nextInt();
		char[] c = nextToken().toCharArray();
		for (int i = 0, j = c.length - 1; i < j; i++, j--) {
			if (c[i] != '?' && c[j] != '?' && c[i] != c[j]) {
				out.println("IMPOSSIBLE");
				return;
			}
		}
		int q = 0;
		TreeSet<Character> ts = new TreeSet<Character>();
		for (int i = 0; i < k; i++) {
			ts.add((char) ('a' + i));
		}
		for (int i = 0, j = c.length - 1; i <= j; i++, j--) {
			if (c[i] == '?' && c[j] == '?') {
				q++;
			}
			if (c[i] != '?') {
				ts.remove(c[i]);
			}
			if (c[j] != '?') {
				ts.remove(c[j]);
			}
		}
		for (int i = (c.length - 1) / 2, j = c.length - i - 1; i >= 0; i--, j++) {
			if (c[i] == '?' && c[j] == '?') {
				if (!ts.isEmpty()) {
					c[i] = c[j] = ts.pollLast();
				} else {
					c[i] = c[j] = 'a';
				}
			}
		}
		if (!ts.isEmpty()) {
			out.println("IMPOSSIBLE");
			return;
		}
		for (int i = 0, j = c.length - 1; i < j; i++, j--) {
			if (c[i] == '?') {
				c[i] = c[j];
			} else if (c[j] == '?') {
				c[j] = c[i];
			}
		}
		out.println(new String(c));
	}

	FastScanner sc;
	PrintWriter out;

	public void run() {
		Locale.setDefault(Locale.US);
		try {
			sc = new FastScanner(System.in);
			out = new PrintWriter(System.out);
			solve();
			sc.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	int nextInt() {
		return sc.nextInt();
	}

	String nextToken() {
		return sc.nextToken();
	}

	long nextLong() {
		return sc.nextLong();
	}

	double nextDouble() {
		return sc.nextDouble();
	}

	BigInteger nextBigInteger() {
		return sc.nextBigInteger();
	}

	class FastScanner extends BufferedReader {
		StringTokenizer st;
		boolean eof;
		String buf;
		String curLine;
		boolean createST;

		public FastScanner(String fileName) throws FileNotFoundException {
			this(fileName, true);
		}

		public FastScanner(String fileName, boolean createST)
				throws FileNotFoundException {
			super(new FileReader(fileName));
			this.createST = createST;
			nextToken();
		}

		public FastScanner(InputStream stream) {
			this(stream, true);
		}

		public FastScanner(InputStream stream, boolean createST) {
			super(new InputStreamReader(stream));
			this.createST = createST;
			nextToken();
		}

		String nextLine() {
			String ret = curLine;
			if (createST) {
				st = null;
			}
			nextToken();
			return ret;
		}

		String nextToken() {
			if (!createST) {
				try {
					curLine = readLine();
				} catch (Exception e) {
					eof = true;
				}
				return null;
			}
			while (st == null || !st.hasMoreTokens()) {
				try {
					curLine = readLine();
					st = new StringTokenizer(curLine);
				} catch (Exception e) {
					eof = true;
					break;
				}
			}
			String ret = buf;
			buf = eof ? "-1" : st.nextToken();
			return ret;
		}

		int nextInt() {
			return Integer.parseInt(nextToken());
		}

		long nextLong() {
			return Long.parseLong(nextToken());
		}

		double nextDouble() {
			return Double.parseDouble(nextToken());
		}

		BigInteger nextBigInteger() {
			return new BigInteger(nextToken());
		}

		public void close() {
			try {
				buf = null;
				st = null;
				curLine = null;
				super.close();
			} catch (Exception e) {

			}
		}

		boolean isEOF() {
			return eof;
		}
	}

	public static void main(String[] args) {
		new C().run();
	}
}


import java.util.Scanner;

public class B {
    static long n, k, total = 0;

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        n = in.nextLong();
        k = in.nextLong();

        total = (k - 1) * ((k - 1) + 1) / 2;
        if (n > total + 1) {
            System.out.println(-1);
        } else {
            if (n == 1) {
                System.out.println(0);
            } else if (n <= k) {
                System.out.println(1);
            } else {
                long high = k - 1, low = 1, mid = 0;
                for (int i = 0; i < 40; i++) {
                    mid = (high + low) / 2;
                    if (calculate(mid) >= n) {
                        high = mid;
                    } else {
                        low = mid;
                    }
                }

                System.out.println(high + 1);
            }
        }
    }

    private static long calculate(long x) {
        long m = (k - 1 - x);
        return (total - (m * (m + 1) / 2)) + k - x;
    }
}


import java.io.*;
import java.util.*;

public class Main {
    private static Scanner sc;
    private static Printer pr;
    static long aLong=(long )1e9+7;
    static long Mod=998244353;
    private static void solve() throws IOException {
        //in the name of god
        // you are anything and we are nothing
        //God,i am so tired . I have no one but you
        long x0=sc.nextLong(),y0=sc.nextLong();
        long ax=sc.nextLong(),ay=sc.nextLong();
        long bx=sc.nextLong(),by=sc.nextLong();
        long xs=sc.nextLong(),ys=sc.nextLong(),t=sc.nextLong();
        int maxT=60;
        ArrayList<Long>x=new ArrayList<>();
        ArrayList<Long>y=new ArrayList<>();
        ArrayList<Long>step=new ArrayList<>();
        ArrayList<Long>Pstep=new ArrayList<>();
        x.add(x0);
        y.add(y0);
        for (int i=1;i<maxT;++i){
            if (ax*x.get(i-1)+bx<0||ay*y.get(i-1)+by<0)
                break;
            x.add(ax*x.get(i-1)+bx);
            y.add(ay*y.get(i-1)+by);
        }
        step.add(0l);
        for (int i=1;i<x.size();++i){
            long sum=0;
            sum+=(x.get(i)-x.get(i-1));
            sum+=(y.get(i)-y.get(i-1));
            if (sum>0)
                step.add(sum);
            else
                break;
        }
        Pstep.add(0l);
        for (int i=1;i<step.size();++i) {
            long sum=0;
            sum+=Pstep.get(i-1)+step.get(i);
            if (sum>0)
                Pstep.add(sum);
            else
                break;
        }
        int ans=0;
        for (int i=0;i<Pstep.size();++i) {
            if (Math.abs(xs - x.get(i)) + Math.abs(ys - y.get(i)) <= t)
                ans = 1;
        }
        for (int i=0;i<Pstep.size();++i){
            for (int j=i+1;j<Pstep.size();++j){
                long diff=Pstep.get(j)-Pstep.get(i);
                long diff1=Math.abs(xs-x.get(i))+Math.abs(ys-y.get(i));
                long diff2=Math.abs(xs-x.get(j))+Math.abs(ys-y.get(j));
                long s1=diff+diff1;
                long s2=diff+diff2;
                if (diff>t)
                    break;
                if ((s1<=t&&s1>0)||(s2<=t&&s2>0)){
                    ans=Math.max(ans,j-i+1);
                }
            }
        }
        pr.println(ans);
    }
    static class point{
        int idx,val;
        public point(int idx, int val) {
            this.idx = idx;
            this.val = val;
        }
    }
    public static int[] radixSort(int[] f) {
        int[] to = new int[f.length];
        {
            int[] b = new int[65537];
            for (int i = 0; i < f.length; i++) b[1 + (f[i] & 0xffff)]++;
            for (int i = 1; i <= 65536; i++) b[i] += b[i - 1];
            for (int i = 0; i < f.length; i++) to[b[f[i] & 0xffff]++] = f[i];
            int[] d = f;
            f = to;
            to = d;
        }
        {
            int[] b = new int[65537];
            for (int i = 0; i < f.length; i++) b[1 + (f[i] >>> 16)]++;
            for (int i = 1; i <= 65536; i++) b[i] += b[i - 1];
            for (int i = 0; i < f.length; i++) to[b[f[i] >>> 16]++] = f[i];
            int[] d = f;
            f = to;
            to = d;
        }
        return f;
    }
    public static long []primeFactor(int n){
        long []prime=new long[n+1];
        prime[1]=1;
        for (int i=2;i<=n;i++)
            prime[i]=((i&1)==0)?2:i;
        for (int i=3;i*i<=n;i++){
            if (prime[i]==i){
                for (int j=i*i;j<=n;j+=i){
                    if (prime[j]==j)
                        prime[j]=i;
                }
            }
        }
        return prime;
    }
    public static long gcd(long a,long b) {
        if (a == 0) return b;
        return gcd(b % a, a);
    }
    public static void main(String[] args) throws IOException {
        sc = new Scanner(System.in);
        pr = new Printer(System.out);
        solve();

        pr.close();
        // sc.close();
    }
    private static class Scanner {
        BufferedReader br;

        Scanner (InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
        }

        private boolean isPrintable(int ch) {
            return ch >= '!' && ch <= '~';
        }

        private boolean isCRLF(int ch) {
            return ch == '\n' || ch == '\r' || ch == -1;
        }

        private int nextPrintable() {
            try {
                int ch;
                while (!isPrintable(ch = br.read())) {
                    if (ch == -1) {
                        throw new NoSuchElementException();
                    }
                }

                return ch;
            } catch (IOException e) {
                throw new NoSuchElementException();
            }
        }

        String next() {
            try {
                int ch = nextPrintable();
                StringBuilder sb = new StringBuilder();
                do {
                    sb.appendCodePoint(ch);
                } while (isPrintable(ch = br.read()));

                return sb.toString();
            } catch (IOException e) {
                throw new NoSuchElementException();
            }
        }

        int nextInt() {
            try {
                // parseInt from Integer.parseInt()
                boolean negative = false;
                int res = 0;
                int limit = -Integer.MAX_VALUE;
                int radix = 10;

                int fc = nextPrintable();
                if (fc < '0') {
                    if (fc == '-') {
                        negative = true;
                        limit = Integer.MIN_VALUE;
                    } else if (fc != '+') {
                        throw new NumberFormatException();
                    }
                    fc = br.read();
                }
                int multmin = limit / radix;

                int ch = fc;
                do {
                    int digit = ch - '0';
                    if (digit < 0 || digit >= radix) {
                        throw new NumberFormatException();
                    }
                    if (res < multmin) {
                        throw new NumberFormatException();
                    }
                    res *= radix;
                    if (res < limit + digit) {
                        throw new NumberFormatException();
                    }
                    res -= digit;

                } while (isPrintable(ch = br.read()));

                return negative ? res : -res;
            } catch (IOException e) {
                throw new NoSuchElementException();
            }
        }

        long nextLong() {
            try {
                // parseLong from Long.parseLong()
                boolean negative = false;
                long res = 0;
                long limit = -Long.MAX_VALUE;
                int radix = 10;

                int fc = nextPrintable();
                if (fc < '0') {
                    if (fc == '-') {
                        negative = true;
                        limit = Long.MIN_VALUE;
                    } else if (fc != '+') {
                        throw new NumberFormatException();
                    }
                    fc = br.read();
                }
                long multmin = limit / radix;

                int ch = fc;
                do {
                    int digit = ch - '0';
                    if (digit < 0 || digit >= radix) {
                        throw new NumberFormatException();
                    }
                    if (res < multmin) {
                        throw new NumberFormatException();
                    }
                    res *= radix;
                    if (res < limit + digit) {
                        throw new NumberFormatException();
                    }
                    res -= digit;

                } while (isPrintable(ch = br.read()));

                return negative ? res : -res;
            } catch (IOException e) {
                throw new NoSuchElementException();
            }
        }

        float nextFloat() {
            return Float.parseFloat(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            try {
                int ch;
                while (isCRLF(ch = br.read())) {
                    if (ch == -1) {
                        throw new NoSuchElementException();
                    }
                }
                StringBuilder sb = new StringBuilder();
                do {
                    sb.appendCodePoint(ch);
                } while (!isCRLF(ch = br.read()));

                return sb.toString();
            } catch (IOException e) {
                throw new NoSuchElementException();
            }
        }

        void close() {
            try {
                br.close();
            } catch (IOException e) {
//				throw new NoSuchElementException();
            }
        }
    }
    private static class Printer extends PrintWriter {
        Printer(PrintStream out) {
            super(out);
        }
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task1426e solver = new Task1426e();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task1426e {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int a1 = in.nextInt();
            int a2 = in.nextInt();
            int a3 = in.nextInt();
            int b1 = in.nextInt();
            int b2 = in.nextInt();
            int b3 = in.nextInt();
            int max = Math.min(a1, b2) + Math.min(a2, b3) + Math.min(a3, b1);
            int min = Math.min(a1, b1 + b3) + Math.min(a2, b1 + b2) + Math.min(a3, b2 + b3);
            min = n - min;
            out.println(min + " " + max);

        }

    }
}


import java.io.*;
import java.util.*;

public class Rock_Paper_Scissors {
    public static long mod = 1000000007;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        long a[] = sc.readArrayl(3);
        long b[] = sc.readArrayl(3);
        long max = 0;
        max = Math.min(a[0], b[1]) + Math.min(a[1], b[2]) + Math.min(a[2], b[0]);
        long min = 0;
        min += (a[0] > (b[0] + b[2]) ? -(b[0] + b[2]) + a[0] : 0);
        min += (a[1] > (b[0] + b[1]) ? -(b[0] + b[1]) + a[1] : 0);
        min += (a[2] > (b[1] + b[2]) ? -(b[1] + b[2]) + a[2] : 0);
        System.out.println(min + " " + max);

    }

    static final Random random = new Random();

    static void sort(int[] a) {
        int n = a.length;
        for (int i = 0; i < n; i++) {
            int val = random.nextInt(n);
            int cur = a[i];
            a[i] = a[val];
            a[val] = cur;
        }
        Arrays.sort(a);
    }

    static void sortl(long[] a) {
        int n = a.length;
        for (int i = 0; i < n; i++) {
            int val = random.nextInt(n);
            long cur = a[i];
            a[i] = a[val];
            a[val] = cur;
        }
        Arrays.sort(a);
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] readArrayl(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

}


import java.util.*;

public class e{
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int t = 1;
		while(t-->0){
			int n = s.nextInt();
			int a[] = new int[3];
			int b[] = new int[3];
			for(int i=0;i<3;i++){
				a[i] = s.nextInt();
			}
			for(int i=0;i<3;i++){
				b[i] = s.nextInt();
			}
			int sum = 0;
			for(int i=0;i<3;i++){
				sum += Math.min(a[i],b[i]+b[(i+2)%3]);
			}
			System.out.print((n-sum)+" ");
			sum = 0;
			for(int i=0;i<3;i++){
				sum += Math.min(a[i],b[(i+1)%3]);
			}
			System.out.println(sum);
		}
	}
}


import java.util.*;
import java.lang.*;
import java.io.*;

public class first {
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer tok;
    public int gcd(int a,int b)
    {
    	if(b==0) return a;
    	return gcd(b,a%b);
    }
	public void go() throws IOException
	{
			String test = in.readLine();
			if(test==null || test.trim().length()==0 )
				return ;

			tok = new StringTokenizer(test);
			int tt = Integer.parseInt(tok.nextToken());
			ntok();
			int n=tt;
			int a[]=iapar(3);
			ntok();
			int b[]=iapar(3);
			int alicemax=0,bobmax=0;
			if(a[0]!=0)
			{
				alicemax+=Math.min(a[0], b[1]);
			}
			if(a[1]!=0)
			{
				alicemax+=Math.min(a[1], b[2]);
			}
			if(a[2]!=0)
			{
				alicemax+=Math.min(a[2], b[0]);
			}
			if(b[0]!=0)
			{
				bobmax+=Math.min(b[0], a[1]);
				b[0]-=Math.min(b[0], a[1]);
				if(b[0]!=0)
				 bobmax+=Math.min(b[0], a[0]);
			}
			if(a[1]!=0)
			{
				bobmax+=Math.min(b[1], a[2]);
				b[1]-=Math.min(b[1], a[2]);
				if(b[1]!=0)
				 bobmax+=Math.min(b[1], a[1]);
			}
			if(a[2]!=0)
			{
				bobmax+=Math.min(b[2], a[0]);
				b[2]-=Math.min(b[2], a[0]);
				if(b[2]!=0)
				 bobmax+=Math.min(b[2], a[2]);
			}
			//System.out.println(bobmax);
			System.out.println((n-bobmax)+" "+alicemax);

//			for (int t = 0; t < tt; t++)
//			{
//
//
//			}
			out.flush();
			in.close();
	}

	public void ntok() throws IOException
		{ String test = in.readLine();
			if(test==null || test.trim().length()==0 )
				return ;
			tok = new StringTokenizer(test);
	}

	public int ipar()
	{
		String test=tok.nextToken();
		if(test==null || test.trim().length()==0)
			return 0;
		return Integer.parseInt(test);
	}

	public int[] iapar(int n)
	{
		int[] arr = new int[n];
		for (int i = 0; i < n; i++)
		{
			arr[i] = ipar();
		}
		return arr;
	}

	public long lpar()
	{
		String test=tok.nextToken();

		if(test==null || test.trim().length()==0)
			return 0;
		return Long.parseLong(test);
	}

	public long[] lapar(int n)
	{
		long[] arr = new long[n];

		for (int i = 0; i < n; i++)
		{
	        arr[i] = lpar();
		}
		return arr;
	}

	public double dpar()
	{
		return Double.parseDouble(tok.nextToken());
	}

	public String spar()
		{ 	String test=tok.nextToken();
			if(test==null || test.trim().length()==0)
				return "";

			return test;
		}

	public static void main(String[] args) throws IOException
	{
		new first().go();
	}
}


import java.io.*;
import java.lang.reflect.Array;
import java.util.*;

public class E {
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    static FastReader s = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);

    private static int[] rai(int n) {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = s.nextInt();
        }
        return arr;
    }

    private static int[][] rai(int n, int m) {
        int[][] arr = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j] = s.nextInt();
            }
        }
        return arr;
    }

    private static long[] ral(int n) {
        long[] arr = new long[n];
        for (int i = 0; i < n; i++) {
            arr[i] = s.nextLong();
        }
        return arr;
    }

    private static long[][] ral(int n, int m) {
        long[][] arr = new long[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j] = s.nextLong();
            }
        }
        return arr;
    }

    private static int ri() {
        return s.nextInt();
    }

    private static long rl() {
        return s.nextLong();
    }

    private static String rs() {
        return s.next();
    }

    static int gcd(int a, int b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    static int bsearch(List<Long> list,long val,int ind)
    {
        int l=ind,r=list.size()-1;
        int res=list.size();

        while(l<=r)
        {
            int mid=(l+r)/2;
            if(list.get(mid)>val)
            {
                if(mid==0)
                {
                    return mid;
                }
                if(list.get(mid-1)<=val)
                {
                    return mid;
                }
                r=mid-1;
            }
            else
            {
                l=mid+1;
            }
        }
        return res;

    }

    static long calc(List<Node> list,long[] b,int i)
    {
        if(i==3)
        {
            return 0;
        }

        //bInd
        Node first = list.get(i);
        int bInd = (first.ind - 1);
        if(bInd==-1)
        {
            bInd=2;
        }

        long min1 = Math.min(first.val, b[bInd]);
        first.val -= min1;
        b[bInd] -= min1;

        long min2 = Math.min(first.val, b[first.ind]);
        first.val -= min2;
        b[first.ind] -= min2;
        long sum = first.val;
        sum+=calc(list,b,i+1);
        first.val+=min1+min2;
        b[bInd]+=min1;
        b[first.ind]+=min2;

        //first.ind

        first = list.get(i);
        bInd = (first.ind - 1);
        if(bInd==-1)
        {
            bInd=2;
        }

        min1 = Math.min(first.val, b[first.ind]);
        first.val -= min1;
        b[first.ind] -= min1;

        min2 = Math.min(first.val, b[bInd]);
        first.val -= min2;
        b[bInd] -= min2;
        long sum2 = first.val;
        sum2+=calc(list,b,i+1);
        first.val+=min1+min2;
        b[bInd]+=min2;
        b[first.ind]+=min1;

        return Math.min(sum,sum2);
    }
    public static void main(String[] args) {
        StringBuilder ans = new StringBuilder();
//        int t = ri();
        int t = 1;
        while (t-- > 0) {
            int n=ri();
            long[] a=ral(3);
            long[] b=ral(3);

            long max=Math.min(a[0],b[1])+Math.min(a[1],b[2])+Math.min(a[2],b[0]);
            long min=Math.max(0,a[0]+b[1]-n)+Math.max(0,a[1]+b[2]-n)+Math.max(0,a[2]+b[0]-n);
            ans.append(min).append(" ").append(max).append("\n");

//            List<Node> list=new ArrayList<>();
//            for(int i=0;i<3;i++)
//            {
//                list.add(new Node(i,b[i]));
//
//            }
//            list.sort(new Comparator<Node>() {
//                @Override
//                public int compare(Node o1, Node o2) {
//                    return (int)(o2.val-o1.val);
//                }
//            });
//
////
//            ans.append(calc(list,b,0)).append(" ").append(max).append("\n");
//
//
//
//            //second
////            first=list.get(1);
////            bInd=(second.ind+1)%3;
////            min=Math.min(second.val,b[bInd]);
////            second.val
        }
        out.print(ans.toString());
        out.flush();

    }
    static class Node
    {
        int ind;
        long val;

        public Node(int ind, long val) {
            this.ind = ind;
            this.val = val;
        }
    }

}


import java.util.*;
import java.io.*;

public class _1426_E {
	public static void main(String[] args) throws Exception {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		int n = Integer.parseInt(in.readLine());
		int[] a = new int[3];
		int[] b = new int[3];
		StringTokenizer line = new StringTokenizer(in.readLine());
		for(int i = 0; i < 3; i++) {
			a[i] = Integer.parseInt(line.nextToken());
		}
		line = new StringTokenizer(in.readLine());
		for(int i = 0; i < 3; i++) {
			b[i] = Integer.parseInt(line.nextToken());
		}
		int max = Math.min(a[0], b[1]) + Math.min(a[1], b[2]) + Math.min(a[2], b[0]);
		int min = 0;
		int leftover = 0;
		if(a[0] >= b[0] + b[2]) {
			min += b[0] + b[2];
		}else {
			min += a[0];
			leftover = b[0] + b[2] - a[0];
		}
		int scissorsleft = 0;
		int provide = Math.min(b[0], leftover);
		if(provide >= a[1]) {
			min += a[1];
			leftover -= a[1];
			scissorsleft = b[1];
		}else {
			min += provide;
			leftover -= provide;
			int need = a[1] - provide;
			if(b[1] >= need) {
				scissorsleft = b[1] - need;
				min += need;
			}else {
				min += b[1];
			}
		}
		min += Math.min(a[2], scissorsleft + Math.min(leftover, b[2]));
		min = n - min;
		out.println(min + " " + max);
		in.close();
		out.close();
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ERockPaperScissors solver = new ERockPaperScissors();
        solver.solve(1, in, out);
        out.close();
    }

    static class ERockPaperScissors {
        int min;

        public void check(ArrayList<int[]> aa, int a[], int b[]) {
            for (int i = 0; i < aa.size(); i++) {
                int m = Math.min(a[aa.get(i)[0]], b[aa.get(i)[1]]);
                b[aa.get(i)[1]] -= m;
                a[aa.get(i)[0]] -= m;
            }
            int curr = 0;
            for (int i = 0; i < 3; i++) curr += a[i];
            min = Math.min(min, curr);
        }

        public void per(ArrayList<int[]> aa, int index, int a[], int b[]) {
            check(aa, a.clone(), b.clone());
            for (int i = index; i < aa.size(); i++) {
                Collections.swap(aa, i, index);
                per(aa, index + 1, a, b);
                Collections.swap(aa, i, index);
            }
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int a[] = new int[3];
            int b[] = new int[3];
            min = Integer.MAX_VALUE;
            int max = 0;
            for (int i = 0; i < 3; i++) {
                a[i] = in.nextInt();
            }
            for (int i = 0; i < 3; i++) {
                b[i] = in.nextInt();
            }
            max = Math.min(a[0], b[1]) + Math.min(a[1], b[2]) + Math.min(a[2], b[0]);
            ArrayList<int[]> aa = new ArrayList<>();
            aa.add(new int[]{0, 0});
            aa.add(new int[]{1, 1});
            aa.add(new int[]{2, 2});
            aa.add(new int[]{0, 2});
            aa.add(new int[]{1, 0});
            aa.add(new int[]{2, 1});
            per(aa, 0, a, b);
            out.println(min + " " + max);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.io.*;
import java.util.*;
public class codeforce
{
    public static void main(String[] args)
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[] arr=new int[3];
        int[] brr=new int[3];
        int i=0;
        for(i=0;i<3;i++)
        {
            arr[i]=sc.nextInt();
        }
        for(i=0;i<3;i++)
        {
            brr[i]=sc.nextInt();
        }
        int max=0,min=0;
        if(arr[0]>=brr[1])
        {
            max+=brr[1];
        }
        else
        {
            max+=arr[0];
        }

         if(arr[1]>=brr[2])
        {
            max+=brr[2];
        }
        else
        {
            max+=arr[1];
        }

         if(arr[2]>=brr[0])
        {
            max+=brr[0];
        }
        else
        {
            max+=arr[2];
        }

         if(arr[0]>brr[0]+brr[2])
         {
             min+=arr[0]-(brr[0]+brr[2]);
         }
         if(arr[1]>brr[1]+brr[0])
         {
             min+=arr[1]-(brr[0]+brr[1]);
         }
         if(arr[2]>brr[1]+brr[2])
         {
             min+=arr[2]-(brr[1]+brr[2]);
         }
         System.out.println(min+" "+max);
    }

}


/*
    Author: Anthony Ngene
    Created: 28/09/2020 - 10:42
*/

import java.io.*;
import java.util.*;

public class E {
// checks: 1. edge cases   2. overflow   3. possible errors (e.g 1/0, arr[out])   4. time/space complexity
    void solver() throws IOException {
        long n = in.intNext();
        long[] ar = in.nextLongArray(3);
        long[] br = in.nextLongArray(3);
        long mxWins = 0;
        long mxLosesOrDraw = 0;
        long draws = 0;
        for (int i = 0; i < 3; i++) {
            mxWins += min(ar[i], br[(i + 1) % 3]);
            long mxLose = min(br[i], ar[(i + 1) % 3]);
            long mxDraw = min(br[i], ar[i]);
            mxLosesOrDraw += min(br[i], mxLose + mxDraw);

        }
        out.pp(n - mxLosesOrDraw, mxWins);
    }

// Generated Code Below:
private static final FastWriter out = new FastWriter();
private static FastScanner in;
static ArrayList<Integer>[] adj;
private static long e97 = (long)1e9 + 7;
public static void main(String[] args) throws IOException {
    in = new FastScanner();
    new E().solver();
    out.close();
}

static class FastWriter {
    private static final int IO_BUFFERS = 128 * 1024;
    private final StringBuilder out;
    public FastWriter() { out = new StringBuilder(IO_BUFFERS); }
    public FastWriter p(Object object) { out.append(object); return this; }
    public FastWriter p(String format, Object... args) { out.append(String.format(format, args)); return this; }
    public FastWriter pp(Object... args) { for (Object ob : args) { out.append(ob).append(" ");  } out.append("\n"); return this; }
    public FastWriter pp(int[] args) { for (int ob : args) { out.append(ob).append(" ");  } out.append("\n"); return this; }
    public FastWriter pp(long[] args) { for (long ob : args) { out.append(ob).append(" ");  } out.append("\n"); return this; }
    public FastWriter pp(char[] args) { for (char ob : args) { out.append(ob).append(" ");  } out.append("\n"); return this; }
    public void println(long[] arr) { for(long e: arr) out.append(e).append(" "); out.append("\n"); }
    public void println(int[] arr) { for(int e: arr) out.append(e).append(" "); out.append("\n"); }
    public void println(char[] arr) { for(char e: arr) out.append(e).append(" "); out.append("\n"); }
    public void println(double[] arr) { for(double e: arr) out.append(e).append(" "); out.append("\n"); }
    public void println(boolean[] arr) { for(boolean e: arr) out.append(e).append(" "); out.append("\n"); }
    public <T>void println(T[] arr) { for(T e: arr) out.append(e).append(" "); out.append("\n"); }
    public void println(long[][] arr) {  for (long[] row: arr) out.append(Arrays.toString(row)).append("\n"); }
    public void println(int[][] arr) {  for (int[] row: arr) out.append(Arrays.toString(row)).append("\n"); }
    public void println(char[][] arr) {  for (char[] row: arr) out.append(Arrays.toString(row)).append("\n"); }
    public void println(double[][] arr) {  for (double[] row: arr) out.append(Arrays.toString(row)).append("\n"); }
    public <T>void println(T[][] arr) {  for (T[] row: arr) out.append(Arrays.toString(row)).append("\n"); }
    public FastWriter println(Object object) { out.append(object).append("\n"); return this; }
    public void toFile(String fileName) throws IOException {
        BufferedWriter writer = new BufferedWriter(new FileWriter(fileName));
        writer.write(out.toString());
        writer.close();
    }
    public void close() throws IOException { System.out.print(out); }
}
static class FastScanner {
    private InputStream sin = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    public FastScanner(){}
    public FastScanner(String filename) throws FileNotFoundException {
        File file = new File(filename);
        sin = new FileInputStream(file);
    }
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = sin.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long longNext() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b) || b == ':'){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int intNext() {
        long nl = longNext();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double doubleNext() { return Double.parseDouble(next());}
    public long[] nextLongArray(final int n){
        final long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = longNext();
        return a;
    }
    public int[] nextIntArray(final int n){
        final int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = intNext();
        return a;
    }
    public double[] nextDoubleArray(final int n){
        final double[] a = new double[n];
        for (int i = 0; i < n; i++)
            a[i] = doubleNext();
        return a;
    }
    public ArrayList<Integer>[] getAdj(int n) {
        ArrayList<Integer>[] adj = new ArrayList[n + 1];
        for (int i = 1; i <= n; i++) adj[i] = new ArrayList<>();
        return adj;
    }
    public ArrayList<Integer>[] adjacencyList(int nodes, int edges) throws IOException {
        return adjacencyList(nodes, edges, false);
    }
    public ArrayList<Integer>[] adjacencyList(int nodes, int edges, boolean isDirected) throws IOException {
        adj = getAdj(nodes);
        for (int i = 0; i < edges; i++) {
            int a = intNext(), b = intNext();
            adj[a].add(b);
            if (!isDirected) adj[b].add(a);
        }
        return adj;
    }
}
static class u {
    public static int upperBound(long[] array, long obj) {
        int l = 0, r = array.length - 1;
        while (r - l >= 0) {
            int c = (l + r) / 2;
            if (obj < array[c]) {
                r = c - 1;
            } else {
                l = c + 1;
            }
        }
        return l;
    }
    public static int upperBound(ArrayList<Long> array, long obj) {
        int l = 0, r = array.size() - 1;
        while (r - l >= 0) {
            int c = (l + r) / 2;
            if (obj < array.get(c)) {
                r = c - 1;
            } else {
                l = c + 1;
            }
        }
        return l;
    }
    public static int lowerBound(long[] array, long obj) {
        int l = 0, r = array.length - 1;
        while (r - l >= 0) {
            int c = (l + r) / 2;
            if (obj <= array[c]) {
                r = c - 1;
            } else {
                l = c + 1;
            }
        }
        return l;
    }
    public static int lowerBound(ArrayList<Long> array, long obj) {
        int l = 0, r = array.size() - 1;
        while (r - l >= 0) {
            int c = (l + r) / 2;
            if (obj <= array.get(c)) {
                r = c - 1;
            } else {
                l = c + 1;
            }
        }
        return l;
    }
    static <T> T[][] deepCopy(T[][] matrix) { return Arrays.stream(matrix).map(el -> el.clone()).toArray($ -> matrix.clone()); }
    static int[][] deepCopy(int[][] matrix) { return Arrays.stream(matrix).map(int[]::clone).toArray($ -> matrix.clone()); }
    static long[][] deepCopy(long[][] matrix) { return Arrays.stream(matrix).map(long[]::clone).toArray($ -> matrix.clone()); }
    private static void sort(int[][] arr){ Arrays.sort(arr, Comparator.comparingDouble(o -> o[0])); }
    private static void sort(long[][] arr){ Arrays.sort(arr, Comparator.comparingDouble(o -> o[0])); }
    private static <T>void rSort(T[] arr) { Arrays.sort(arr, Collections.reverseOrder()); }
    private static void customSort(int[][] arr) {
        Arrays.sort(arr, new Comparator<int[]>() {
            public int compare(int[] a, int[] b) {
                if (a[0] == b[0]) return Integer.compare(a[1], b[1]);
                return Integer.compare(a[0], b[0]);
            }
        });
    }
    public static int[] swap(int[] arr, int left, int right) {
        int temp = arr[left];
        arr[left] = arr[right];
        arr[right] = temp;
        return arr;
    }
    public static char[] swap(char[] arr, int left, int right) {
        char temp = arr[left];
        arr[left] = arr[right];
        arr[right] = temp;
        return arr;
    }
    public static int[] reverse(int[] arr, int left, int right) {
        while (left < right) {
            int temp = arr[left];
            arr[left++] = arr[right];
            arr[right--] = temp;
        }
        return arr;
    }
    public static boolean findNextPermutation(int[] data) {
        if (data.length <= 1) return false;
        int last = data.length - 2;
        while (last >= 0) {
            if (data[last] < data[last + 1]) break;
            last--;
        }
        if (last < 0) return false;
        int nextGreater = data.length - 1;
        for (int i = data.length - 1; i > last; i--) {
            if (data[i] > data[last]) {
                nextGreater = i;
                break;
            }
        }
        data = swap(data, nextGreater, last);
        data = reverse(data, last + 1, data.length - 1);
        return true;
    }
    public static int biSearch(int[] dt, int target){
        int left=0, right=dt.length-1;
        int mid=-1;
        while(left<=right){
            mid = (right+left)/2;
            if(dt[mid] == target) return mid;
            if(dt[mid] < target) left=mid+1;
            else right=mid-1;
        }
        return -1;
    }
    public static int biSearchMax(long[] dt, long target){
        int left=-1, right=dt.length;
        int mid=-1;

        while((right-left)>1){
            mid = left + (right-left)/2;
            if(dt[mid] <= target) left=mid;
            else right=mid;
        }
        return left;
    }
    public static int biSearchMaxAL(ArrayList<Integer> dt, long target){
        int left=-1, right=dt.size();
        int mid=-1;

        while((right-left)>1){
            mid = left + (right-left)/2;
            if(dt.get(mid) <= target) left=mid;
            else right=mid;
        }
        return left;
    }
    private static <T>void fill(T[][] ob, T res){for(int i=0;i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){  ob[i][j] = res; }}}
    private static void fill(boolean[][] ob,boolean res){for(int i=0;i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){  ob[i][j] = res; }}}
    private static void fill(int[][] ob, int res){      for(int i=0; i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){  ob[i][j] = res; }}}
    private static void fill(long[][] ob, long res){    for(int i=0; i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){  ob[i][j] = res; }}}
    private static void fill(char[][] ob, char res){    for(int i=0; i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){  ob[i][j] = res; }}}
    private static void fill(double[][] ob, double res){for(int i=0; i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){  ob[i][j] = res; }}}
    private static void fill(int[][][] ob,int res){for(int i=0;i<ob.length;i++){for(int j=0;j<ob[0].length;j++){for(int k=0;k<ob[0][0].length;k++){ob[i][j][k]=res;}}}}
    private static void fill(long[][][] ob,long res){for(int i=0;i<ob.length;i++){for(int j=0;j<ob[0].length;j++){for(int k=0;k<ob[0][0].length;k++){ob[i][j][k]=res;}}}}
    private static <T>void fill(T[][][] ob,T res){for(int i=0;i<ob.length;i++){for(int j=0;j<ob[0].length;j++){for(int k=0;k<ob[0][0].length;k++){ob[i][j][k]=res;}}}}
    private static void fill_parent(int[] ob){ for(int i=0; i<ob.length; i++) ob[i]=i; }
    private static boolean same3(long a, long b, long c){
        if(a!=b) return false;
        if(b!=c) return false;
        if(c!=a) return false;
        return true;
    }
    private static boolean dif3(long a, long b, long c){
        if(a==b) return false;
        if(b==c) return false;
        if(c==a) return false;
        return true;
    }
    private static double hypotenuse(double a, double b){
        return Math.sqrt(a*a+b*b);
    }
    private static long factorial(int n) {
        long ans=1;
        for(long i=n; i>0; i--){ ans*=i; }
        return ans;
    }
    private static long facMod(int n, long mod) {
        long ans=1;
        for(long i=n; i>0; i--) ans = (ans * i) % mod;
        return ans;
    }
    private static long lcm(long m, long n){
        long ans = m/gcd(m,n);
        ans *= n;
        return ans;
    }
    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
    private static boolean isPrime(long a){
        if(a==1) return false;
        for(int i=2; i<=Math.sqrt(a); i++){  if(a%i == 0) return false;  }
        return true;
    }
    static long modInverse(long a, long mod) {
    /* Fermat's little theorem: a^(MOD-1) => 1
    Therefore (divide both sides by a): a^(MOD-2) => a^(-1) */
        return binpowMod(a, mod - 2, mod);
    }
    static long binpowMod(long a, long b, long mod) {
        long res = 1;
        while (b > 0) {
            if (b % 2 == 1) res = (res * a) % mod;
            a = (a * a) % mod;
            b /= 2;
        }
        return res;
    }
    private static int getDigit2(long num){
        long cf = 1;    int d=0;
        while(num >= cf){   d++;    cf = 1<<d;  }
        return d;
    }
    private static int getDigit10(long num){
        long cf = 1;    int d=0;
        while(num >= cf){   d++;    cf*=10;     }
        return d;
    }
    private static boolean isInArea(int y, int x, int h, int w){
        if(y<0) return false;
        if(x<0) return false;
        if(y>=h) return false;
        if(x>=w) return false;
        return true;
    }
    private static ArrayList<Integer> generatePrimes(int n) {
        int[] lp = new int[n + 1];
        ArrayList<Integer> pr = new ArrayList<>();
        for (int i = 2; i <= n; ++i) {
            if (lp[i] == 0) {
                lp[i] = i;
                pr.add(i);
            }
            for (int j = 0; j < pr.size() && pr.get(j) <= lp[i] && i * pr.get(j) <= n; ++j) {
                lp[i * pr.get(j)] = pr.get(j);
            }
        }
        return pr;
    }
    static long nPrMod(int n, int r, long MOD) {
        long res = 1;
        for (int i = (n - r + 1); i <= n; i++) {
            res = (res * i) % MOD;
        }
        return res;
    }
    static long nCr(int n, int r) {
        if (r > (n - r))
            r = n - r;
        long ans = 1;
        for (int i = 1; i <= r; i++) {
            ans *= n;
            ans /= i;
            n--;
        }
        return ans;
    }
    static long nCrMod(int n, int r, long MOD) {
        long rFactorial = nPrMod(r, r, MOD);
        long first = nPrMod(n, r, MOD);
        long second = binpowMod(rFactorial, MOD-2, MOD);
        return  (first * second) % MOD;
    }
    static void printBitRepr(int n) {
        StringBuilder res = new StringBuilder();
        for (int i = 0; i < 32; i++) {
            int mask = (1 << i);
            res.append((mask & n) == 0 ? "0" : "1");
        }
        out.println(res);
    }
    static String bitString(int n) {return Integer.toBinaryString(n);}
    static int setKthBitToOne(int n, int k) { return (n | (1 << k)); } // zero indexed
    static int setKthBitToZero(int n, int k) { return (n & ~(1 << k)); }
    static int invertKthBit(int n, int k) { return (n ^ (1 << k)); }
    static boolean isPowerOfTwo(int n) { return (n & (n - 1)) == 0; }
    static HashMap<Character, Integer> counts(String word) {
        HashMap<Character, Integer> counts = new HashMap<>();
        for (int i = 0; i < word.length(); i++) counts.merge(word.charAt(i), 1, Integer::sum);
        return counts;
    }
    static HashMap<Integer, Integer> counts(int[] arr) {
        HashMap<Integer, Integer> counts = new HashMap<>();
        for (int value : arr) counts.merge(value, 1, Integer::sum);
        return counts;
    }
    static HashMap<Long, Integer> counts(long[] arr) {
        HashMap<Long, Integer> counts = new HashMap<>();
        for (long l : arr) counts.merge(l, 1, Integer::sum);
        return counts;
    }
    static HashMap<Character, Integer> counts(char[] arr) {
        HashMap<Character, Integer> counts = new HashMap<>();
        for (char c : arr) counts.merge(c, 1, Integer::sum);
        return counts;
    }
    static long hash(int x, int y) {
        return x* 1_000_000_000L +y;
    }
    static final Random random = new Random();
    static void sort(int[] a) {
        int n = a.length;// shuffle, then sort
        for (int i = 0; i < n; i++) {
            int oi = random.nextInt(n), temp = a[oi];
            a[oi] = a[i];
            a[i] = temp;
        }
        Arrays.sort(a);
    }
    static void sort(long[] arr) {
        shuffleArray(arr);
        Arrays.sort(arr);
    }
    static void shuffleArray(long[] arr) {
        int n = arr.length;
        for(int i=0; i<n; ++i){
            long tmp = arr[i];
            int randomPos = i + random.nextInt(n-i);
            arr[i] = arr[randomPos];
            arr[randomPos] = tmp;
        }
    }
}
static class Tuple implements Comparable<Tuple> {
    int a;
    int b;
    int c;
    public Tuple(int a, int b) {
        this.a = a;
        this.b = b;
        this.c = 0;
    }
    public Tuple(int a, int b, int c) {
        this.a = a;
        this.b = b;
        this.c = c;
    }
    public int getA() { return a; }
    public int getB() { return b; }
    public int getC() { return c; }
    public int compareTo(Tuple other) {
        if (this.a == other.a) {
            if (this.b == other.b) return Long.compare(this.c, other.c);
            return Long.compare(this.b, other.b);
        }
        return Long.compare(this.a, other.a);
    }
    @Override
    public int hashCode() { return Arrays.deepHashCode(new Integer[]{a, b, c}); }
    @Override
    public boolean equals(Object o) {
        if (!(o instanceof Tuple)) return false;
        Tuple pairo = (Tuple) o;
        return (this.a == pairo.a && this.b == pairo.b && this.c == pairo.c);
    }
    @Override
    public String toString() { return String.format("(%d %d %d)  ", this.a, this.b, this.c); }
}
private static int abs(int a){  return (a>=0) ? a: -a;  }
private static int min(int... ins){ int min = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] < min) min = ins[i]; } return min; }
private static int max(int... ins){ int max = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] > max) max = ins[i]; } return max; }
private static int sum(int... ins){ int total = 0; for (int v : ins) { total += v; } return total; }
private static long abs(long a){    return (a>=0) ? a: -a;  }
private static long min(long... ins){ long min = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] < min) min = ins[i]; } return min; }
private static long max(long... ins){ long max = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] > max) max = ins[i]; } return max; }
private static long sum(long... ins){ long total = 0; for (long v : ins) { total += v; } return total; }
private static double abs(double a){    return (a>=0) ? a: -a;  }
private static double min(double... ins){ double min = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] < min) min = ins[i]; } return min; }
private static double max(double... ins){ double max = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] > max) max = ins[i]; } return max; }
private static double sum(double... ins){ double total = 0; for (double v : ins) { total += v; } return total; }

}


import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        int[] a = sc.nextIntArray(3);
        int[] b = sc.nextIntArray(3);
        int min = Math.max(0,a[0]-b[0]-b[2]) + Math.max(0,a[1]-b[0]-b[1]) + Math.max(0,a[2]-b[1]-b[2]);
        int max = Math.min(a[0],b[1]) + Math.min(a[1],b[2]) + Math.min(a[2],b[0]);
        pw.println(min + " " + max);
        pw.flush();
    }

    static class GeekInteger {
        public static void save_sort(int[] array) {
            shuffle(array);
            Arrays.sort(array);
        }

        public static int[] shuffle(int[] array) {
            int n = array.length;
            Random random = new Random();
            for (int i = 0, j; i < n; i++) {
                j = i + random.nextInt(n - i);
                int randomElement = array[j];
                array[j] = array[i];
                array[i] = randomElement;
            }
            return array;
        }

    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}


import java.util.*;
import java.io.*;

public class E {

	public static void main(String[] args) throws IOException  {
		Reader sc=new Reader();
		Print pr=new Print();
		int t=1;
		while(t-->0) {
			int n=sc.nextInt();
            int a1=sc.nextInt();
            int a3=sc.nextInt();
            int a2=sc.nextInt();
            int b1=sc.nextInt();
            int b3=sc.nextInt();
            int b2=sc.nextInt();
            int min=0;
            int max=0;
            if(a1>b3)
                max+=b3;
            else
                max+=a1;
            if(a2>b1)
                max+=b1;
            else
                max+=a2;
            if(a3>b2)
                max+=b2;
            else
                max+=a3;
            if(a1>b2+b1)
                min+=(Math.max(a1-(b2+b1),0));
            if(a2>b3+b2)
                min+=(Math.max(a2-(b3+b2),0));
            if(a3>b1+b3)
                min+=(Math.max(a3-(b1+b3),0));
            pr.printLine(min+" "+max);
		}
        pr.close();
	}

	static class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din; private byte[] buffer;
        private int bufferPointer, bytesRead;
        public Reader() { din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];  bufferPointer = bytesRead = 0; }
        public Reader(String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; }
        public String readLine() throws IOException { int cnt = 0, c;
            byte[] buf = new byte[64]; while ((c = read()) != -1) { if (c == '\n')
            break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); }
        public int nextInt() throws IOException {
            int ret = 0; byte c = read(); while (c <= ' ') c = read();
            boolean neg = (c == '-'); if (neg) c = read(); do {
            ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9');
            if (neg) return -ret; return ret; }
        public long nextLong() throws IOException { long ret = 0; byte c = read();
            while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read();
            do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9');
            if (neg) return -ret; return ret; }
        public double nextDouble() throws IOException { double ret = 0,
            div = 1; byte c = read(); while (c <= ' ') c = read();
            boolean neg = (c == '-'); if (neg) c = read(); do {
            ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9');
            if (c == '.') { while ((c = read()) >= '0' && c <= '9') {
            ret += (c - '0') / (div *= 10); } } if (neg) return -ret;
            return ret; }
        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1) buffer[0] = -1; }
        private byte read() throws IOException { if (bufferPointer == bytesRead)
            fillBuffer(); return buffer[bufferPointer++]; }
        public void close() throws IOException { if (din == null) return;
            din.close(); }
    }

    static class Print {
        private final BufferedWriter bw;
        public Print() {
            bw=new BufferedWriter(new OutputStreamWriter(System.out)); }
        public void print(String str)throws IOException { bw.append(str); }
        public void printLine(String str)throws IOException { print(str);
            bw.append("\n"); }
        public void close()throws IOException { bw.close(); }
    }
}