using Microsoft.Win32.SafeHandles;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Xml.Schema;

public static class Ex
{
    public static bool IsNullOrEmpty(this string s) { return string.IsNullOrEmpty(s); }
    public static void yesno(this bool b) => Console.WriteLine(b ? "yes" : "no");
    public static void YesNo(this bool b) => Console.WriteLine(b ? "Yes" : "No");
    public static void YESNO(this bool b) => Console.WriteLine(b ? "YES" : "NO");
    //[MethodImpl(MethodImplOptions.AggressiveInlining)]
    //public static bool Chmax<T>(ref this T a, T b) where T : struct, IComparable<T>
    //{
    //    if (b.CompareTo(a) > 0) { a = b; return true; }
    //    else return false;
    //}
    //[MethodImpl(MethodImplOptions.AggressiveInlining)]
    //public static bool Chmin<T>(ref this T a, T b) where T : struct, IComparable<T>
    //{
    //    if (b.CompareTo(a) < 0) { a = b; return true; }
    //    else return false;
    //}

    public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.OrdinalIgnoreCase); return s.ToList(); }

    public static int PopCount(this uint bits)
    {
        bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
        bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
        bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
        bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
        return (int)((bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff));
    }
}

partial class Program
{
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    string GetStr() { return Console.ReadLine().Trim(); }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    char GetChar() { return Console.ReadLine().Trim()[0]; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    int GetInt() { return int.Parse(Console.ReadLine().Trim()); }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    long GetLong() { return long.Parse(Console.ReadLine().Trim()); }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    double GetDouble() { return double.Parse(Console.ReadLine().Trim()); }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    string[][] GetStrArray(int N)
    {
        var res = new string[N][];
        for (int i = 0; i < N; i++) res[i] = Console.ReadLine().Trim().Split(' ');
        return res;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    int[][] GetIntArray(int N)
    {
        var res = new int[N][];
        for (int i = 0; i < N; i++) res[i] = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
        return res;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    long[][] GetLongArray(int N)
    {
        var res = new long[N][];
        for (int i = 0; i < N; i++) res[i] = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
        return res;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    double[][] GetDoubleArray(int N)
    {
        var res = new double[N][];
        for (int i = 0; i < N; i++) res[i] = Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray();
        return res;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    char[][] GetGrid(int H)
    {
        var res = new char[H][];
        for (int i = 0; i < H; i++) res[i] = Console.ReadLine().Trim().ToCharArray();
        return res;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    T[] CreateArray<T>(int N, T value)
    {
        var res = new T[N];
        for (int i = 0; i < N; i++) res[i] = value;
        return res;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    T[][] CreateArray<T>(int H, int W, T value)
    {
        var res = new T[H][];
        for (int i = 0; i < H; i++)
        {
            res[i] = new T[W];
            for (int j = 0; j < W; j++) res[i][j] = value;
        }
        return res;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    T[][][] CreateArray<T>(int H, int W, int R, T value)
    {
        var res = new T[H][][];
        for (int i = 0; i < H; i++)
        {
            res[i] = new T[W][];
            for (int j = 0; j < W; j++)
            {
                res[i][j] = new T[R];
                for (int k = 0; k < R; k++) res[i][j][k] = value;
            }
        }
        return res;
    }

    Dictionary<int, List<int>> GetUnweightedAdjacencyList(int N, int M, bool isDirected, bool isNode_0indexed)
    {
        var dic = new Dictionary<int, List<int>>();
        foreach (var e in Enumerable.Range(0, N)) { dic.Add(e, new List<int>()); }
        for (int i = 0; i < M; i++)
        {
            var input = GetIntArray();
            var a = isNode_0indexed ? input[0] : input[0] - 1;
            var b = isNode_0indexed ? input[1] : input[1] - 1;
            dic[a].Add(b);
            if (isDirected == false) dic[b].Add(a);
        }
        return dic;
    }
    //Dictionary<int, List<(int node, long cost)>> GetWeightedAdjacencyList(int N, int M, bool isDirected, bool isNode_0indexed)
    //{
    //    var dic = new Dictionary<int, List<(int, long)>>();
    //    foreach (var e in Enumerable.Range(0, N)) { dic.Add(e, new List<(int, long)>()); }
    //    for (int i = 0; i < M; i++)
    //    {
    //        var input = GetIntArray();
    //        var a = isNode_0indexed ? input[0] : input[0] - 1;
    //        var b = isNode_0indexed ? input[1] : input[1] - 1;
    //        var c = input[2];
    //        dic[a].Add((b, c));
    //        if (isDirected == false) dic[b].Add((a, c));
    //    }
    //    return dic;
    //}

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    bool eq<T, U>() => typeof(T).Equals(typeof(U));
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                       : eq<T, long>() ? ct<T, long>(long.Parse(s))
                       : eq<T, double>() ? ct<T, double>(double.Parse(s))
                       : eq<T, char>() ? ct<T, char>(s[0])
                                         : ct<T, string>(s);
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    void Multi<T>(out T a) => a = cv<T>(GetStr());
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    void Multi<T, U>(out T a, out U b)
    {
        var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    void Multi<T, U, V>(out T a, out U b, out V c)
    {
        var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    void Multi<T, U, V, W>(out T a, out U b, out V c, out W d)
    {
        var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]);
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e)
    {
        var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]);
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f)
    {
        var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]);
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    void Output<T>(T t) => Console.WriteLine(t);
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    void Output<T>(IList<T> ls) => Console.WriteLine(string.Join(" ", ls));
    void Debug<T>(IList<IList<T>> ls)
    {
        foreach (var l in ls)
            foreach (var s in l)
                Console.WriteLine(s);
    }

    void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; }

    int[] dx = new int[] { 1, 0, -1, 0, 1, -1, -1, 1 };
    int[] dy = new int[] { 0, 1, 0, -1, 1, 1, -1, -1 };
    long mod = 1000000007;
}

partial class Program
{
    static void Main()
    {
        Console.SetIn(new StreamReader(Console.OpenStandardInput(8192)));
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        new Program().Solve();
        Console.Out.Flush();
        Console.Read();
    }

    public void Solve()
    {
        int N = GetInt();
        var A = GetIntArray();
        var B = GetIntArray();
        var dinic = new Dinic(8);
        dinic.AddEdge(0, 1, A[0]);
        dinic.AddEdge(0, 2, A[1]);
        dinic.AddEdge(0, 3, A[2]);
        dinic.AddEdge(1, 4, int.MaxValue);
        dinic.AddEdge(1, 5, 0);
        dinic.AddEdge(1, 6, int.MaxValue);
        dinic.AddEdge(2, 4, int.MaxValue);
        dinic.AddEdge(2, 5, int.MaxValue);
        dinic.AddEdge(2, 6, 0);
        dinic.AddEdge(3, 4, 0);
        dinic.AddEdge(3, 5, int.MaxValue);
        dinic.AddEdge(3, 6, int.MaxValue);
        dinic.AddEdge(4, 7, B[0]);
        dinic.AddEdge(5, 7, B[1]);
        dinic.AddEdge(6, 7, B[2]);

        var min = N - dinic.MaxFlow(0, 7);

        int max = 0;
        for (int i = 0; i < 3; i++)
        {
            max += Math.Min(A[i], B[(i + 1) % 3]);
        }

        Output(min + " " + max);
    }

    class Dinic
    {
        public Dinic(int node_size)
        {
            V = node_size;
            G = Enumerable.Repeat(0, V).Select(_ => new List<Edge>()).ToList();
            level = Enumerable.Repeat(0, V).ToList();
            iter = Enumerable.Repeat(0, V).ToList();
        }

        class Edge
        {
            public Edge(int to, int cap, int rev)
            {
                To = to; Cap = cap; Rev = rev;
            }
            public int To { get; set; }
            public int Cap { get; set; }
            public int Rev { get; set; }
        }

        List<List<Edge>> G;
        int V;
        List<int> level;
        List<int> iter;

        public void AddEdge(int from, int to, int cap)
        {
            G[from].Add(new Edge(to, cap, G[to].Count));
            G[to].Add(new Edge(from, 0, G[from].Count - 1));
        }

        public int MaxFlow(int s, int t)
        {
            int flow = 0;
            while (true)
            {
                BFS(s);
                if (level[t] < 0) { return flow; }
                iter = Enumerable.Repeat(0, V).ToList();
                var f = DFS(s, t, int.MaxValue);
                while (f > 0)
                {
                    flow += f;
                    f = DFS(s, t, int.MaxValue);
                }
            }
        }

        void BFS(int s)
        {
            level = Enumerable.Repeat(-1, V).ToList();
            level[s] = 0;
            var que = new Queue<int>();
            que.Enqueue(s);
            while (que.Count != 0)
            {
                var v = que.Dequeue();
                for (int i = 0; i < G[v].Count; i++)
                {
                    var e = G[v][i];
                    if (e.Cap > 0 && level[e.To] < 0)
                    {
                        level[e.To] = level[v] + 1;
                        que.Enqueue(e.To);
                    }
                }
            }
        }

        int DFS(int v, int t, int f)
        {
            if (v == t) return f;
            for (int i = iter[v]; i < G[v].Count; i++)
            {
                iter[v] = i;
                var e = G[v][i];
                if (e.Cap > 0 && level[v] < level[e.To])
                {
                    var d = DFS(e.To, t, Math.Min(f, e.Cap));
                    if (d > 0)
                    {
                        e.Cap -= d;
                        G[e.To][e.Rev].Cap += d;
                        return d;
                    }
                }
            }
            return 0;
        }
    }
}


using System;
using static System.Math;

class E2
{
	static int[] Read() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var a = Read();
		var b = Read();

		var max = Min(a[0], b[1]) + Min(a[1], b[2]) + Min(a[2], b[0]);
		var min_ = 0;

		var pairs = new[] { (0, 0), (1, 1), (2, 2), (0, 2), (1, 0), (2, 1) };

		Permutation(pairs, 6, ps =>
		{
			var c = (int[])a.Clone();
			var d = (int[])b.Clone();

			var t = 0;
			foreach (var (i, j) in ps)
			{
				var m = Min(c[i], d[j]);
				t += m;
				c[i] -= m;
				d[j] -= m;
			}
			min_ = Max(min_, t);
		});

		Console.WriteLine($"{n - min_} {max}");
	}

	static void Permutation<T>(T[] values, int r, Action<T[]> action)
	{
		var n = values.Length;
		var p = new T[r];
		var u = new bool[n];

		if (r > 0) Dfs(0);
		else action(p);

		void Dfs(int i)
		{
			var i2 = i + 1;
			for (int j = 0; j < n; ++j)
			{
				if (u[j]) continue;
				p[i] = values[j];
				u[j] = true;

				if (i2 < r) Dfs(i2);
				else action(p);

				u[j] = false;
			}
		}
	}
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication3
{
    class Program
    {

       static int maxx(int a1,int a2,int a3,int b1,int b2,int b3)
        {
            int m = 0;
            if (a1 >= b2)
            {
                m += b2;
            }
            else if (a1 < b2)
            {
                m += a1;
            }
            if (a2 >= b3)
            {
                m += b3;
            }
            else if (a2 < b3)
            {
                m += a2;
            }
            if (a3 >= b1)
            {
                m += b1;
            }
            else if (a3 < b1)
            {
                m += a3;
            }
            return m;
        }

       public static int b1;
       public static int b2;
       public static int b3;
       static int aa1(int a1 ,int n)
       {
           if (a1 != 0)
           {
               if (n==1)
               {

                   if (b1 >= a1)
                   {
                       b1 -= a1;
                       a1 = 0;
                   }
                   else
                   {
                       a1 -= b1;
                       b1 = 0;

                       if (b3 >= a1)
                       {
                           b3 -= a1;
                           a1 = 0;
                       }
                       else
                       {
                           a1 -= b3;
                           b3 = 0;
                       }
                   }
               }
               else
               {
                   if (b3 >= a1)
                   {
                       b3 -= a1;
                       a1 = 0;
                   }
                   else
                   {
                       a1 -= b3;
                       b3 = 0;

                       if (b1 >= a1)
                       {
                           b1 -= a1;
                           a1 = 0;
                       }
                       else
                       {
                           a1 -= b1;
                           b1 = 0;
                       }
                   }
               }
           }//1
           return a1 ;
       }
       static int aa2(int a2,int n)
       {
           if (a2 != 0)
           {

               if (n == 1)
               {

                   if (b1 >= a2)
                   {
                       b1 -= a2;
                       a2 = 0;
                   }
                   else
                   {
                       a2 -= b1;
                       b1 = 0;

                       if (b2 >= a2)
                       {
                           b2 -= a2;
                           a2 = 0;
                       }
                       else
                       {
                           a2 -= b2;
                           b2 = 0;
                       }
                   }
               }

               else
               {
                   if (b2 >= a2)
                   {
                       b2 -= a2;
                       a2 = 0;
                   }
                   else
                   {
                       a2 -= b2;
                       b2 = 0;

                       if (b1 >= a2)
                       {
                           b1 -= a2;
                           a2 = 0;
                       }
                       else
                       {
                           a2 -= b1;
                           b1 = 0;
                       }
                   }
               }
           }//2

        return a2;
       }

       static int aa3(int a3,int n)
       {

           if (a3 != 0)
           {
               if (n==2)
               {

               if (b2 >= a3)
               {
                   b2 -= a3;
                   a3 = 0;
               }
               else
               {
                   a3 -= b2;
                   b2 = 0;

                   if (b3 >= a3)
                   {
                       b3 -= a3;
                       a3 = 0;
                   }
                   else
                   {
                       a3 -= b3;
                       b3 = 0;
                   }
               }
           }

               else
               {
                   if (b3 >= a3)
                   {
                       b3 -= a3;
                       a3 = 0;
                   }
                   else
                   {
                       a3 -= b3;
                       b3 = 0;

                       if (b2 >= a3)
                       {
                           b2 -= a3;
                           a3 = 0;
                       }
                       else
                       {
                           a3 -= b2;
                           b2 = 0;
                       }
                   }
               }
           }
           return a3;
       }
       static int minn(int a1, int a2, int a3, int b1, int b2, int b3)
       {

           if (a1 >= a2 && a1 >= a3)
           {
              a1= aa1(a1,3);
               if (a2 > a3)
               {
                 a2=  aa2(a2,1);
                  a3= aa3(a3,3);
               }
               else
               {
                  a3= aa3(a3,3);
                  a2= aa2(a2,2);
               }
           }

           else if (a2 >= a1 && a2 >= a3)
           {
              a2=aa2(a2,1);
               if (a3 > a1)
               {
                 a3= aa3(a3,2);
                  a1= aa1(a1,1);
               }
               else
               {
                 a1= aa1(a1,1);
                  a3= aa3(a3,2);
               }

           }
           else if (a3 >= a1 && a3 >= a2)
           {
              a3= aa3(a3,2);
               if (a1 > a2)
               {
                 a1=  aa1(a1,3);
                  a2= aa2(a2,1);
               }
               else
               {
                  a2= aa2(a2,2);
                  a1= aa1(a1,1);
               }
           }
           return a1+a2+a3;
       }

        static void Main(string[] args)
        {
            int n =int.Parse(Console.ReadLine());

            string l1 = Console.ReadLine();
            string[]l11=l1.Split();
            int a1 = int.Parse(l11[0]) , a2=int.Parse(l11[1]), a3=int.Parse(l11[2]);

            string l2 = Console.ReadLine();
            string[] l22 = l2.Split();

            b1 = int.Parse(l22[0]);
            b2 = int.Parse(l22[1]);
            b3 = int.Parse(l22[2]);

            int m = maxx(a1, a2, a3, b1, b2, b3);
            Console.WriteLine(minn(a1, a2, a3, b1, b2, b3)+"  " + m);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication3
{
    class Program
    {

       static int maxx(int a1,int a2,int a3,int b1,int b2,int b3)
        {
            int m = 0;
            if (a1 >= b2)
            {
                m += b2;
            }
            else if (a1 < b2)
            {
                m += a1;
            }
            if (a2 >= b3)
            {
                m += b3;
            }
            else if (a2 < b3)
            {
                m += a2;
            }
            if (a3 >= b1)
            {
                m += b1;
            }
            else if (a3 < b1)
            {
                m += a3;
            }
            return m;
        }

       public static int b1;
       public static int b2;
       public static int b3;
       static int aa1(int a1 ,int n)
       {
           if (a1 != 0)
           {
               if (b1>b3)
               {

                   if (b1 >= a1)
                   {
                       b1 -= a1;
                       a1 = 0;
                   }
                   else
                   {
                       a1 -= b1;
                       b1 = 0;

                       if (b3 >= a1)
                       {
                           b3 -= a1;
                           a1 = 0;
                       }
                       else
                       {
                           a1 -= b3;
                           b3 = 0;
                       }
                   }
               }
               else
               {
                   if (b3 >= a1)
                   {
                       b3 -= a1;
                       a1 = 0;
                   }
                   else
                   {
                       a1 -= b3;
                       b3 = 0;

                       if (b1 >= a1)
                       {
                           b1 -= a1;
                           a1 = 0;
                       }
                       else
                       {
                           a1 -= b1;
                           b1 = 0;
                       }
                   }
               }
           }//1
           return a1 ;
       }
       static int aa2(int a2,int n)
       {
           if (a2 != 0)
           {

               if (b1>=b2)
               {

                   if (b1 >= a2)
                   {
                       b1 -= a2;
                       a2 = 0;
                   }
                   else
                   {
                       a2 -= b1;
                       b1 = 0;

                       if (b2 >= a2)
                       {
                           b2 -= a2;
                           a2 = 0;
                       }
                       else
                       {
                           a2 -= b2;
                           b2 = 0;
                       }
                   }
               }

               else
               {
                   if (b2 >= a2)
                   {
                       b2 -= a2;
                       a2 = 0;
                   }
                   else
                   {
                       a2 -= b2;
                       b2 = 0;

                       if (b1 >= a2)
                       {
                           b1 -= a2;
                           a2 = 0;
                       }
                       else
                       {
                           a2 -= b1;
                           b1 = 0;
                       }
                   }
               }
           }//2

        return a2;
       }

       static int aa3(int a3,int n)
       {

           if (a3 != 0)
           {
               if (b2>=b3)
               {

               if (b2 >= a3)
               {
                   b2 -= a3;
                   a3 = 0;
               }
               else
               {
                   a3 -= b2;
                   b2 = 0;

                   if (b3 >= a3)
                   {
                       b3 -= a3;
                       a3 = 0;
                   }
                   else
                   {
                       a3 -= b3;
                       b3 = 0;
                   }
               }
           }

               else
               {
                   if (b3 >= a3)
                   {
                       b3 -= a3;
                       a3 = 0;
                   }
                   else
                   {
                       a3 -= b3;
                       b3 = 0;

                       if (b2 >= a3)
                       {
                           b2 -= a3;
                           a3 = 0;
                       }
                       else
                       {
                           a3 -= b2;
                           b2 = 0;
                       }
                   }
               }
           }
           return a3;
       }
       static int minn(int a1, int a2, int a3, int b1, int b2, int b3)
       {

           if (a1 >= a2 && a1 >= a3)
           {
              a1= aa1(a1,1);
               if (a2 > a3)
               {
                 a2=  aa2(a2,1);
                  a3= aa3(a3,2);
               }
               else
               {
                  a3= aa3(a3,3);
                  a2= aa2(a2,2);
               }
           }

           else if (a2 >= a1 && a2 >= a3)
           {
              a2=aa2(a2,1);
               if (a3 > a1)
               {
                 a3= aa3(a3,2);
                  a1= aa1(a1,1);
               }
               else
               {
                 a1= aa1(a1,1);
                  a3= aa3(a3,2);
               }

           }
           else if (a3 >= a1 && a3 >= a2)
           {
              a3= aa3(a3,2);
               if (a1 > a2)
               {
                 a1=  aa1(a1,3);
                  a2= aa2(a2,1);
               }
               else
               {
                  a2= aa2(a2,2);
                  a1= aa1(a1,1);
               }
           }
           return a1+a2+a3;
       }

        static void Main(string[] args)
        {
            int n =int.Parse(Console.ReadLine());

            string l1 = Console.ReadLine();
            string[]l11=l1.Split();
            int a1 = int.Parse(l11[0]) , a2=int.Parse(l11[1]), a3=int.Parse(l11[2]);

            string l2 = Console.ReadLine();
            string[] l22 = l2.Split();

            b1 = int.Parse(l22[0]);
            b2 = int.Parse(l22[1]);
            b3 = int.Parse(l22[2]);

            int m = maxx(a1, a2, a3, b1, b2, b3);
            Console.WriteLine(minn(a1, a2, a3, b1, b2, b3)+"  " + m);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication3
{
    class Program
    {

       static int maxx(int a1,int a2,int a3,int b1,int b2,int b3)
        {
            int m = 0;
            if (a1 >= b2)
            {
                m += b2;
            }
            else if (a1 < b2)
            {
                m += a1;
            }
            if (a2 >= b3)
            {
                m += b3;
            }
            else if (a2 < b3)
            {
                m += a2;
            }
            if (a3 >= b1)
            {
                m += b1;
            }
            else if (a3 < b1)
            {
                m += a3;
            }
            return m;
        }

       public static int b1;
       public static int b2;
       public static int b3;
       static int aa1(int a1 ,int n)
       {
           if (a1 != 0)
           {
               if (n==1)
               {

                   if (b1 >= a1)
                   {
                       b1 -= a1;
                       a1 = 0;
                   }
                   else
                   {
                       a1 -= b1;
                       b1 = 0;

                       if (b3 >= a1)
                       {
                           b3 -= a1;
                           a1 = 0;
                       }
                       else
                       {
                           a1 -= b3;
                           b3 = 0;
                       }
                   }
               }
               else
               {
                   if (b3 >= a1)
                   {
                       b3 -= a1;
                       a1 = 0;
                   }
                   else
                   {
                       a1 -= b3;
                       b3 = 0;

                       if (b1 >= a1)
                       {
                           b1 -= a1;
                           a1 = 0;
                       }
                       else
                       {
                           a1 -= b1;
                           b1 = 0;
                       }
                   }
               }
           }//1
           return a1 ;
       }
       static int aa2(int a2,int n)
       {
           if (a2 != 0)
           {

               if (n == 1)
               {

                   if (b1 >= a2)
                   {
                       b1 -= a2;
                       a2 = 0;
                   }
                   else
                   {
                       a2 -= b1;
                       b1 = 0;

                       if (b2 >= a2)
                       {
                           b2 -= a2;
                           a2 = 0;
                       }
                       else
                       {
                           a2 -= b2;
                           b2 = 0;
                       }
                   }
               }

               else
               {
                   if (b2 >= a2)
                   {
                       b2 -= a2;
                       a2 = 0;
                   }
                   else
                   {
                       a2 -= b2;
                       b2 = 0;

                       if (b1 >= a2)
                       {
                           b1 -= a2;
                           a2 = 0;
                       }
                       else
                       {
                           a2 -= b1;
                           b1 = 0;
                       }
                   }
               }
           }//2

        return a2;
       }

       static int aa3(int a3,int n)
       {

           if (a3 != 0)
           {
               if (n==2)
               {

               if (b2 >= a3)
               {
                   b2 -= a3;
                   a3 = 0;
               }
               else
               {
                   a3 -= b2;
                   b2 = 0;

                   if (b3 >= a3)
                   {
                       b3 -= a3;
                       a3 = 0;
                   }
                   else
                   {
                       a3 -= b3;
                       b3 = 0;
                   }
               }
           }

               else
               {
                   if (b3 >= a3)
                   {
                       b3 -= a3;
                       a3 = 0;
                   }
                   else
                   {
                       a3 -= b3;
                       b3 = 0;

                       if (b2 >= a3)
                       {
                           b2 -= a3;
                           a3 = 0;
                       }
                       else
                       {
                           a3 -= b2;
                           b2 = 0;
                       }
                   }
               }
           }
           return a3;
       }
       static int minn(int a1, int a2, int a3, int b1, int b2, int b3)
       {

           if (a1 >= a2 && a1 >= a3)
           {
              a1= aa1(a1,1);
               if (a2 > a3)
               {
                 a2=  aa2(a2,1);
                  a3= aa3(a3,2);
               }
               else
               {
                  a3= aa3(a3,3);
                  a2= aa2(a2,2);
               }
           }

           else if (a2 >= a1 && a2 >= a3)
           {
              a2=aa2(a2,1);
               if (a3 > a1)
               {
                 a3= aa3(a3,2);
                  a1= aa1(a1,1);
               }
               else
               {
                 a1= aa1(a1,1);
                  a3= aa3(a3,2);
               }

           }
           else if (a3 >= a1 && a3 >= a2)
           {
              a3= aa3(a3,2);
               if (a1 > a2)
               {
                 a1=  aa1(a1,3);
                  a2= aa2(a2,1);
               }
               else
               {
                  a2= aa2(a2,2);
                  a1= aa1(a1,1);
               }
           }
           return a1+a2+a3;
       }

        static void Main(string[] args)
        {
            int n =int.Parse(Console.ReadLine());

            string l1 = Console.ReadLine();
            string[]l11=l1.Split();
            int a1 = int.Parse(l11[0]) , a2=int.Parse(l11[1]), a3=int.Parse(l11[2]);

            string l2 = Console.ReadLine();
            string[] l22 = l2.Split();

            b1 = int.Parse(l22[0]);
            b2 = int.Parse(l22[1]);
            b3 = int.Parse(l22[2]);

            int m = maxx(a1, a2, a3, b1, b2, b3);
            Console.WriteLine(minn(a1, a2, a3, b1, b2, b3)+"  " + m);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication3
{
    class Program
    {

       static int maxx(int a1,int a2,int a3,int b1,int b2,int b3)
        {
            int m = 0;
            if (a1 >= b2)
            {
                m += b2;
            }
            else if (a1 < b2)
            {
                m += a1;
            }
            if (a2 >= b3)
            {
                m += b3;
            }
            else if (a2 < b3)
            {
                m += a2;
            }
            if (a3 >= b1)
            {
                m += b1;
            }
            else if (a3 < b1)
            {
                m += a3;
            }
            return m;
        }

       public static int b1;
       public static int b2;
       public static int b3;
       static int aa1(int a1)
       {
           if (a1 != 0)
           {
               //if (b1 > b3)
               //{

                   if (b1 >= a1)
                   {
                       b1 -= a1;
                       a1 = 0;
                   }
                   else
                   {
                       a1 -= b1;
                       b1 = 0;

                       if (b3 >= a1)
                       {
                           b3 -= a1;
                           a1 = 0;
                       }
                       else
                       {
                           a1 -= b3;
                           b3 = 0;
                       }
                   }
               //}
               //else
               //{
               //    if (b3 >= a1)
               //    {
               //        b3 -= a1;
               //        a1 = 0;
               //    }
               //    else
               //    {
               //        a1 -= b3;
               //        b3 = 0;

               //        if (b1 >= a1)
               //        {
               //            b1 -= a1;
               //            a1 = 0;
               //        }
               //        else
               //        {
               //            a1 -= b1;
               //            b1 = 0;
               //        }
               //    }
               //}
           }//1
           return a1 ;
       }
       static int aa2(int a2)
       {
           if (a2 != 0)
           {
               //if (b1 >= b2)

               if (b1 >= a2)
               {
                   b1 -= a2;
                   a2 = 0;
               }
               else
               {
                   a2 -= b1;
                   b1 = 0;

                   if (b2 >= a2)
                   {
                       b2 -= a2;
                       a2 = 0;
                   }
                   else
                   {
                       a2 -= b2;
                       b2 = 0;
                   }
               }
           }
           //    else
           //    {
           //        if (b2 >= a2)
           //        {
           //            b2 -= a2;
           //            a2 = 0;
           //        }
           //        else
           //        {
           //            a2 -= b2;
           //            b2 = 0;

           //            if (b1 >= a2)
           //            {
           //                b1 -= a2;
           //                a2 = 0;
           //            }
           //            else
           //            {
           //                a2 -= b1;
           //                b1 = 0;
           //            }
           //        }
           //    }
           //}//2
           return a2;
       }

       static int aa3(int a3)
       {

           if (a3 != 0)
           {
               //if (b2 > b3)
               //{

               if (b2 >= a3)
               {
                   b2 -= a3;
                   a3 = 0;
               }
               else
               {
                   a3 -= b2;
                   b2 = 0;

                   if (b3 >= a3)
                   {
                       b3 -= a3;
                       a3 = 0;
                   }
                   else
                   {
                       a3 -= b3;
                       b3 = 0;
                   }
               }
           }
               //}
           //    else
           //    {
           //        if (b3 >= a3)
           //        {
           //            b3 -= a3;
           //            a3 = 0;
           //        }
           //        else
           //        {
           //            a3 -= b3;
           //            b3 = 0;

           //            if (b2 >= a3)
           //            {
           //                b2 -= a3;
           //                a3 = 0;
           //            }
           //            else
           //            {
           //                a3 -= b2;
           //                b2 = 0;
           //            }
           //        }
           //    }
           //}
           return a3;
       }
       static int minn(int a1, int a2, int a3, int b1, int b2, int b3)
       {

           if (a1 >= a2 && a1 >= a3)
           {
              a1= aa1(a1);
               if (a2 > a3)
               {
                 a2=  aa2(a2);
                  a3= aa3(a3);
               }
               else
               {
                  a3= aa3(a3);
                  a2= aa2(a2);
               }
           }

           else if (a2 >= a1 && a2 >= a3)
           {
              a3=aa3(a3);
               if (a2 > a1)
               {
                 a2= aa2(a2);
                  a1= aa1(a1);
               }
               else
               {
                 a1= aa1(a1);
                  a2= aa2(a2);
               }

           }
           else if (a3 >= a1 && a3 >= a2)
           {
              a3= aa3(a3);
               if (a1 > a2)
               {
                 a1=  aa1(a1);
                  a2= aa2(a2);
               }
               else
               {
                  a2= aa2(a2);
                  a1= aa1(a1);
               }
           }
           return a1+a2+a3;
       }

        static void Main(string[] args)
        {
            int n =int.Parse(Console.ReadLine());

            string l1 = Console.ReadLine();
            string[]l11=l1.Split();
            int a1 = int.Parse(l11[0]) , a2=int.Parse(l11[1]), a3=int.Parse(l11[2]);

            string l2 = Console.ReadLine();
            string[] l22 = l2.Split();

            b1 = int.Parse(l22[0]);
            b2 = int.Parse(l22[1]);
            b3 = int.Parse(l22[2]);

            int m = maxx(a1, a2, a3, b1, b2, b3);
            Console.WriteLine(minn(a1, a2, a3, b1, b2, b3)+"  " + m);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication3
{
    class Program
    {

       static int maxx(int a1,int a2,int a3,int b1,int b2,int b3)
        {
            int m = 0;
            if (a1 >= b2)
            {
                m += b2;
            }
            else if (a1 < b2)
            {
                m += a1;
            }
            if (a2 >= b3)
            {
                m += b3;
            }
            else if (a2 < b3)
            {
                m += a2;
            }
            if (a3 >= b1)
            {
                m += b1;
            }
            else if (a3 < b1)
            {
                m += a3;
            }
            return m;
        }

       public static int b1;
       public static int b2;
       public static int b3;
       static int aa1(int a1)
       {
           if (a1 != 0)
           {
               if (b1 > b3)
               {

                   if (b1 >= a1)
                   {
                       b1 -= a1;
                       a1 = 0;
                   }
                   else
                   {
                       a1 -= b1;
                       b1 = 0;

                       if (b3 >= a1)
                       {
                           b3 -= a1;
                           a1 = 0;
                       }
                       else
                       {
                           a1 -= b3;
                           b3 = 0;
                       }
                   }
               }
               else
               {
                   if (b3 >= a1)
                   {
                       b3 -= a1;
                       a1 = 0;
                   }
                   else
                   {
                       a1 -= b3;
                       b3 = 0;

                       if (b1 >= a1)
                       {
                           b1 -= a1;
                           a1 = 0;
                       }
                       else
                       {
                           a1 -= b1;
                           b1 = 0;
                       }
                   }
               }
           }//1
           return a1 ;
       }
       static int aa2(int a2)
       {
           if (a2 != 0)
           {
               if (b1 >= b2)
               {

                   if (b1 >= a2)
                   {
                       b1 -= a2;
                       a2 = 0;
                   }
                   else
                   {
                       a2 -= b1;
                       b1 = 0;

                       if (b2 >= a2)
                       {
                           b2 -= a2;
                           a2 = 0;
                       }
                       else
                       {
                           a2 -= b2;
                           b2 = 0;
                       }
                   }
               }
               else
               {
                   if (b2 >= a2)
                   {
                       b2 -= a2;
                       a2 = 0;
                   }
                   else
                   {
                       a2 -= b2;
                       b2 = 0;

                       if (b1 >= a2)
                       {
                           b1 -= a2;
                           a2 = 0;
                       }
                       else
                       {
                           a2 -= b1;
                           b1 = 0;
                       }
                   }
               }
           }//2
           return a2;
       }

       static int aa3(int a3)
       {

           if (a3 != 0)
           {
               if (b2 > b3)
               {

                   if (b2 >= a3)
                   {
                       b2 -= a3;
                       a3 = 0;
                   }
                   else
                   {
                       a3 -= b2;
                       b2 = 0;

                       if (b3 >= a3)
                       {
                           b3 -= a3;
                           a3 = 0;
                       }
                       else
                       {
                           a3 -= b3;
                           b3 = 0;
                       }
                   }
               }
               else
               {
                   if (b3 >= a3)
                   {
                       b3 -= a3;
                       a3 = 0;
                   }
                   else
                   {
                       a3 -= b3;
                       b3 = 0;

                       if (b2 >= a3)
                       {
                           b2 -= a3;
                           a3 = 0;
                       }
                       else
                       {
                           a3 -= b2;
                           b2 = 0;
                       }
                   }
               }
           }
           return a3;
       }
       static int minn(int a1, int a2, int a3, int b1, int b2, int b3)
       {

           if (a1 >= a2 && a1 >= a3)
           {
              a1= aa1(a1);
               if (a2 > a3)
               {
                 a2=  aa2(a2);
                  a3= aa3(a3);
               }
               else
               {
                  a3= aa3(a3);
                  a2= aa2(a2);
               }
           }

           else if (a2 >= a1 && a2 >= a3)
           {
              a3=aa3(a3);
               if (a2 > a1)
               {
                 a2= aa2(a2);
                  a1= aa1(a1);
               }
               else
               {
                 a1= aa1(a1);
                  a2= aa2(a2);
               }

           }
           else if (a3 >= a1 && a3 >= a2)
           {
              a3= aa3(a3);
               if (a1 > a2)
               {
                 a1=  aa1(a1);
                  a2= aa2(a2);
               }
               else
               {
                  a2= aa2(a2);
                  a1= aa1(a1);
               }
           }
           return a1+a2+a3;
       }

        static void Main(string[] args)
        {
            int n =int.Parse(Console.ReadLine());

            string l1 = Console.ReadLine();
            string[]l11=l1.Split();
            int a1 = int.Parse(l11[0]) , a2=int.Parse(l11[1]), a3=int.Parse(l11[2]);

            string l2 = Console.ReadLine();
            string[] l22 = l2.Split();

            b1 = int.Parse(l22[0]);
            b2 = int.Parse(l22[1]);
            b3 = int.Parse(l22[2]);

            int m = maxx(a1, a2, a3, b1, b2, b3);
            Console.WriteLine(minn(a1, a2, a3, b1, b2, b3)+"  " + m);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication3
{
    class Program
    {

       static int maxx(int a1,int a2,int a3,int b1,int b2,int b3)
        {
            int m = 0;
            if (a1 >= b2)
            {
                m += b2;
            }
            else if (a1 < b2)
            {
                m += a1;
            }
            if (a2 >= b3)
            {
                m += b3;
            }
            else if (a2 < b3)
            {
                m += a2;
            }
            if (a3 >= b1)
            {
                m += b1;
            }
            else if (a3 < b1)
            {
                m += a3;
            }
            return m;
        }

       static int minn(int a1, int a2, int a3, int b1, int b2, int b3)
       {

           if (a1 !=0)
           {
               if (b1 > b3)
               {

                   if (b1 >= a1)
                   {
                       b1 -= a1;
                       a1=0;
                   }
                   else
                   {
                       a1 -= b1;
                       b1 = 0;

                       if (b3 >= a1)
                       {
                           b3 -= a1;
                           a1 = 0;
                       }
                       else
                       {
                           a1 -= b3;
                           b3 = 0;
                       }
                   }
               }
               else
               {
                   if (b3 >= a1)
                   {
                       b3 -= a1;
                       a1 = 0;
                   }
                   else
                   {
                       a1 -= b3;
                       b3 = 0;

                       if (b1 >= a1)
                       {
                           b1 -= a1;
                           a1 = 0;
                       }
                       else
                       {
                           a1 -= b1;
                           b1 = 0;
                       }
                   }
               }
           }//1

           if (a2 !=0)
           {
               if (b1 >= b2)
               {

                   if (b1 >= a2)
                   {
                       b1 -= a2;
                       a2 = 0;
                   }
                   else
                   {
                       a2 -= b1;
                       b1 = 0;

                       if (b2 >= a2)
                       {
                           b2 -= a2;
                           a2 = 0;
                       }
                       else
                       {
                           a2 -= b2;
                           b2 = 0;
                       }
                   }
               }
               else
               {
                   if (b2 >= a2)
                   {
                       b2 -= a2;
                       a2 = 0;
                   }
                   else
                   {
                       a2 -= b2;
                       b2 = 0;

                       if (b1 >= a2)
                       {
                           b1 -= a2;
                           a2 = 0;
                       }
                       else
                       {
                           a2 -= b1;
                           b1 = 0;
                       }
                   }
               }
           }//2

           if (a3 !=0)
           {
               if (b2 > b3)
               {

                   if (b2 >= a3)
                   {
                       b2 -= a3;
                       a3 = 0;
                   }
                   else
                   {
                       a3 -= b2;
                       b2 = 0;

                       if (b3 >= a3)
                       {
                           b3 -= a3;
                           a3 = 0;
                       }
                       else
                       {
                           a3 -= b3;
                           b3 = 0;
                       }
                   }
               }
               else
               {
                   if (b3 >= a3)
                   {
                       b3 -= a3;
                       a3 = 0;
                   }
                   else
                   {
                       a3 -= b3;
                       b3 = 0;

                       if (b2 >= a3)
                       {
                           b2 -= a3;
                           a3 = 0;
                       }
                       else
                       {
                           a3 -= b2;
                           b2 = 0;
                       }
                   }
               }
           }

           return a1+a2+a3;
       }

        static void Main(string[] args)
        {
            int n =int.Parse(Console.ReadLine());

            string l1 = Console.ReadLine();
            string[]l11=l1.Split();
            int a1 = int.Parse(l11[0]) , a2=int.Parse(l11[1]), a3=int.Parse(l11[2]);

            string l2 = Console.ReadLine();
            string[] l22 = l2.Split();
            int b1 = int.Parse(l22[0]), b2 = int.Parse(l22[1]), b3 = int.Parse(l22[2]);

            Console.WriteLine(minn(a1, a2, a3, b1, b2, b3)+"  " + maxx(a1, a2, a3, b1, b2, b3));
        }
    }
}


using System;
using System.IO;
using System.Collections.Generic;

namespace CodeForces
{
    class Tokenizer
    {
        int pos;
        string[] tokens;
        TextReader reader;

        public Tokenizer(TextReader reader)
        {
            pos = 0;
            tokens = new string[] { };
            this.reader = reader;
        }

        public string NextToken()
        {
            if (pos == tokens.Length)
            {
                tokens = reader.ReadLine().Split(' ');
                pos = 0;
            }
            return tokens [pos++];
        }

        public int NextInt()
        {
            return int.Parse(NextToken());
        }
    }

    class MainClass
    {
        static Tokenizer t;
        static TextWriter w;

        public static void Init()
        {
            t = new Tokenizer(Console.In);
            w = Console.Out;
            //t = new Tokenizer(File.OpenText(@"../../in.txt"));
            //w = File.CreateText(@"../../out.txt");
        }

        public static void Main(string[] args)
        {
            Init();
            int n = t.NextInt();
            List<int>[] c = new List<int>[4];
            for (int i = 0; i < 4; i++)
                c [i] = new List<int>();
            for (int i = 1; i <= n; i++)
                c [t.NextInt()].Add(i);

            List<int>[] dep = new List<int>[n + 1];
            for (int i = 1; i <= n; i++)
                dep [i] = new List<int>();
            int[] waitCount = new int[n + 1];
            for (int i = 1; i <= n; i++)
            {
                int k = t.NextInt();
                waitCount [i] = k;
                for (int j = 0; j < k; j++)
                    dep [t.NextInt()].Add(i);
            }

            int cost = int.MaxValue;
            for (int start = 1; start <= 3; start++)
            {
                bool[] done = new bool[n + 1];
                int[] curWaitCount = (int[])waitCount.Clone();

                int cur = start;
                int rem = n;
                int curCost = 0;
                while (rem > 0)
                {
                    for (int j = 0; j < c[cur].Count; j++)
                    {
                        foreach (var a in c[cur])
                        {
                            if (done [a])
                                continue;
                            if (curWaitCount [a] == 0)
                            {
                                foreach (var b in dep[a])
                                    curWaitCount [b]--;
                                done [a] = true;
                                rem--;
                            }
                        }
                    }
                    cur++;
                    if (cur == 4)
                        cur = 1;
                    if (rem > 0)
                        curCost++;
                }

                cost = Math.Min(cost, curCost);
            }

            cost += n;
            w.WriteLine(cost);
            w.Close();
        }
    }
}


using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;

namespace CodeForces
{
    class Tokenizer
    {
        int pos;
        string[] tokens;
        TextReader reader;

        public Tokenizer(TextReader reader)
        {
            pos = 0;
            tokens = new string[] { };
            this.reader = reader;
        }

        public string NextToken()
        {
            if (pos == tokens.Length)
            {
                tokens = reader.ReadLine().Split(' ');
                pos = 0;
            }
            return tokens [pos++];
        }

        public int NextInt()
        {
            return int.Parse(NextToken());
        }
    }

    class MainClass
    {
        static Tokenizer t;
        static TextWriter w;

        public static void Init()
        {
            t = new Tokenizer(Console.In);
            w = Console.Out;
            //t = new Tokenizer(File.OpenText(@"../../in.txt"));
            //w = File.CreateText(@"../../out.txt");
        }

        public static void Main(string[] args)
        {
            Init();
            int n = t.NextInt();

            int[] machine = new int[n + 1];
            int[] inDegree = new int[n + 1];

            for (int i = 1; i <= n; i++)
                machine [i] = t.NextInt();

            var a = new List<int>[n + 1];
            for (int i = 1; i <= n; i++)
                a [i] = new List<int>();

            for (int i = 1; i <= n; i++)
            {
                int k = t.NextInt();
                inDegree [i] = k;
                while (k-- > 0)
                {
                    a [t.NextInt()].Add(i);
                }
            }

            int cost = int.MaxValue;
            for (int start = 1; start <= 3; start++)
            {
                int curCost = n;
                int[] curInDegree = (int[])inDegree.Clone();
                var q = new Queue<int>[4];
                for (int i = 1; i <= 3; i++)
                    q [i] = new Queue<int>();
                int rem = n;
                for (int i = 1; i <= n; i++)
                    if (inDegree [i] == 0)
                        q [machine [i]].Enqueue(i);
                int curMachine = start;
                while (true)
                {
                    while (q[curMachine].Count != 0)
                    {
                        int curJob = q [curMachine].Dequeue();
                        foreach (var job in a[curJob])
                        {
                            curInDegree [job]--;
                            if (curInDegree [job] == 0)
                                q [machine [job]].Enqueue(job);
                        }
                        rem--;
                    }
                    if (rem == 0)
                        break;

                    curCost++;
                    curMachine++;
                    if (curMachine == 4)
                        curMachine = 1;
                }
                cost = Math.Min(cost, curCost);

            }

            w.WriteLine(cost);
        }
    }
}


using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;

namespace CodeForces
{
    class Tokenizer
    {
        int pos;
        string[] tokens;
        TextReader reader;

        public Tokenizer(TextReader reader)
        {
            pos = 0;
            tokens = new string[] { };
            this.reader = reader;
        }

        public string NextToken()
        {
            if (pos == tokens.Length)
            {
                tokens = reader.ReadLine().Split(' ');
                pos = 0;
            }
            return tokens [pos++];
        }

        public int NextInt()
        {
            return int.Parse(NextToken());
        }
    }

    class MainClass
    {
        static Tokenizer t;
        static TextWriter w;

        public static void Init()
        {
            t = new Tokenizer(Console.In);
            w = Console.Out;
            t = new Tokenizer(File.OpenText(@"../../in.txt"));
            //w = File.CreateText(@"../../out.txt");
        }

        public static void Main(string[] args)
        {
            Init();
            int n = t.NextInt();

            int[] machine = new int[n + 1];
            int[] inDegree = new int[n + 1];

            for (int i = 1; i <= n; i++)
                machine [i] = t.NextInt();

            var a = new List<int>[n + 1];
            for (int i = 1; i <= n; i++)
                a [i] = new List<int>();

            for (int i = 1; i <= n; i++)
            {
                int k = t.NextInt();
                inDegree [i] = k;
                while (k-- > 0)
                {
                    a [t.NextInt()].Add(i);
                }
            }

            int cost = int.MaxValue;
            for (int start = 1; start <= 3; start++)
            {
                int curCost = n;
                int[] curInDegree = (int[])inDegree.Clone();
                var q = new Queue<int>[4];
                for (int i = 1; i <= 3; i++)
                    q [i] = new Queue<int>();
                int rem = n;
                for (int i = 1; i <= n; i++)
                    if (inDegree [i] == 0)
                        q [machine [i]].Enqueue(i);
                int curMachine = start;
                while (true)
                {
                    while (q[curMachine].Count != 0)
                    {
                        int curJob = q [curMachine].Dequeue();
                        foreach (var job in a[curJob])
                        {
                            curInDegree [job]--;
                            if (curInDegree [job] == 0)
                                q [machine [job]].Enqueue(job);
                        }
                        rem--;
                    }
                    if (rem == 0)
                        break;

                    curCost++;
                    curMachine++;
                    if (curMachine == 4)
                        curMachine = 1;
                }
                cost = Math.Min(cost, curCost);

            }

            w.WriteLine(cost);
        }
    }
}


using System;
using System.IO;
using System.Collections.Generic;

namespace CodeForces
{
    class Tokenizer
    {
        int pos;
        string[] tokens;
        TextReader reader;

        public Tokenizer(TextReader reader)
        {
            pos = 0;
            tokens = new string[] { };
            this.reader = reader;
        }

        public string NextToken()
        {
            if (pos == tokens.Length)
            {
                tokens = reader.ReadLine().Split(' ');
                pos = 0;
            }
            return tokens [pos++];
        }

        public int NextInt()
        {
            return int.Parse(NextToken());
        }
    }

    class MainClass
    {
        static Tokenizer t;
        static TextWriter w;

        public static void Init()
        {
            t = new Tokenizer(Console.In);
            w = Console.Out;
            //t = new Tokenizer(File.OpenText(@"../../in.txt"));
            //w = File.CreateText(@"../../out.txt");
        }

        public static void Main(string[] args)
        {
            Init();
            int n = t.NextInt();
            List<int>[] c = new List<int>[4];
            for (int i = 0; i < 4; i++)
                c [i] = new List<int>();
            for (int i = 1; i <= n; i++)
                c [t.NextInt()].Add(i);

            List<int>[] dep = new List<int>[n + 1];
            for (int i = 1; i <= n; i++)
            {
                dep [i] = new List<int>();
                int k = t.NextInt();
                for (int j = 0; j < k; j++)
                    dep [i].Add(t.NextInt());
            }

            int cost = int.MaxValue;
            for (int start = 1; start <= 3; start++)
            {
                bool[] done = new bool[n + 1];
                int cur = start;
                int rem = n;
                int curCost = 0;
                while (rem > 0)
                {
                    for (int j = 0; j < n; j++)
                    {
                        foreach (var a in c[cur])
                        {
                            if (done [a])
                                continue;
                            bool ready = true;
                            foreach (var b in dep[a])
                                if (!done [b])
                                    ready = false;
                            if (ready)
                            {
                                done [a] = true;
                                rem--;
                            }
                        }
                    }
                    cur++;
                    if (cur == 4)
                        cur = 1;
                    if (rem > 0)
                        curCost++;
                }

                cost = Math.Min(cost, curCost);
            }

            cost += n;
            w.WriteLine(cost);
            w.Close();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CodeForce
{
    class _55a
    {
        public static void Main()
        {
            var line = Console.ReadLine();
            var n = int.Parse(line);
            var visited = new bool[n];
            visited[0] = true;
            var idx = 0;
            for (var i = 1; i < 50000000; i++)
            {
                idx += i;
                idx %= n;
                visited[idx] = true;
            }
            if (visited.Any(item => !item))
            {
                Console.WriteLine("NO");
                return;
            }
            Console.WriteLine("YES");
        }
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.IO;
using System.Linq;
using System.Threading;

class Program
{

    void solve()
    {

        int n = nextInt();
        int at = 0;
        bool[] vis = new bool[n];
        vis[0] = true;
        for (int step = 1; step <= 10000000; step++)
        {
            at = (at + step) % n;
            vis[at] = true;
        }
        string res = "YES";
        for (int i = 0; i < n; i++)
            if (!vis[i])
                res = "NO";
        println(res);
    }

    ////////////
    private void println(int[] ar)
    {
        for (int i = 0; i < ar.Length; i++)
        {
            if (i == ar.Length - 1)
                println(ar[i]);
            else
                print(ar[i] + " ");
        }
    }
    private void println(int[] ar, bool add)
    {
        int A = 0;
        if (add)
            A++;
        for (int i = 0; i < ar.Length; i++)
        {
            if (i == ar.Length - 1)
                println(ar[i] + A);
            else
                print((ar[i] + A) + " ");
        }
    }

    private void println(string Stringst)
    {
        Console.WriteLine(Stringst);
    }
    private void println(char charnum)
    {
        Console.WriteLine(charnum);
    }
    private void println(int Intnum)
    {
        Console.WriteLine(Intnum);
    }
    private void println(long Longnum)
    {
        Console.WriteLine(Longnum);
    }
    private void println(double Doublenum)
    {
        string s = Doublenum.ToString(CultureInfo.InvariantCulture);
        Console.WriteLine(s);
    }

    private void print(string Stringst)
    {
        Console.Write(Stringst);
    }
    private void print(int Intnum)
    {
        Console.Write(Intnum);
    }
    private void print(char charnum)
    {
        Console.Write(charnum);
    }
    private void print(long Longnum)
    {
        Console.Write(Longnum);
    }
    private void print(double Doublenum)
    {
        Console.Write(Doublenum);
    }

    string[] inputLine = new string[0];
    int inputInd = 0;
    string nextLine()
    {
        return Console.ReadLine();
    }
    void readInput()
    {
        if (inputInd != inputLine.Length)
            throw new Exception();
        inputInd = 0;
        inputLine = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        if (inputLine.Length == 0)
            readInput();

    }
    int nextInt()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return int.Parse(inputLine[inputInd++]);
    }
    long nextLong()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return long.Parse(inputLine[inputInd++]);
    }
    double nextDouble()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return double.Parse(inputLine[inputInd++]);
    }
    string nextString()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return inputLine[inputInd++];
    }
    static void Main(string[] args)
    {
        Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
        new Program().solve();
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProgrammingContest.Codeforces.Round51
{
    class A
    {
        static bool check(int n)
        {
            bool[] used = new bool[n];
            for (int i = 0, j = 1; j<100000;i=(i+j)%n, j++)
                used[i] = true;
            for (int i = 0; i < n; i++)
                if (!used[i])
                    return false;
            return true;
        }
        public static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            //for (int n = 1; n <= 1000; n++)
            {
                bool[] used = new bool[n];
                for (int i = 0, j = 1; !used[i]; j++)
                {
                    used[i] = true;
                    //Console.WriteLine(i);
                    i = (i + j) % n;
                }
                //Console.WriteLine(check(n));
                bool ok = true;
                for (int i = 0; i < n; i++)
                    if (!used[i])
                    {
                        ok = false;
                        //Console.WriteLine("NO");
                        //return;
                    }
                //Console.WriteLine("YES");
                Console.WriteLine( ok ? "YES":"NO");
            }
        }
    }
}


namespace CF55
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(System.Console.ReadLine());
            int i = 1;
            for (; i < n; i *= 2) ;
            if (i == n) System.Console.WriteLine("YES");
            else System.Console.WriteLine("NO");
        }
    }
}


using System;
using System.Linq;
using System.Collections.Generic;

namespace Task55A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int ct = 0;
            int omit = 0;
            int sit = 1;
            HashSet<int> container = new HashSet<int>() { sit };
            string ans = "NO";
            while (true)
            {
                if (container.Count == n)
                {
                    ans = "YES";
                    break;
                }
                else if (omit > 2 * n)
                    break;

                sit += omit;
                if (sit > n) sit %= n;
                container.Add(sit);
                omit++;

            }
            Console.WriteLine(ans);
            //Console.ReadKey();
        }
    }
}


using System;
using System.IO;
using System.Text;

namespace Flea_travel
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            int n = Next();

            var nn = new int[n,n];
            int index = 0;
            int jump = 1;
            while (true)
            {
                int next = (index + jump)%n;
                if (nn[index, next] == 1)
                {
                    break;
                }
                nn[index, next] = 1;
                index = next;
                jump++;
            }

            for (int i = 0; i < n; i++)
            {
                bool ok = false;
                for (int j = 0; j < n; j++)
                {
                    if (nn[i, j] == 1)
                    {
                        ok = true;
                        break;
                    }
                }
                if (ok == false)
                {
                    writer.WriteLine("NO");
                    writer.Flush();
                    return;
                }
            }

            writer.WriteLine("YES");
            writer.Flush();
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


using System;
using System.Linq;
using System.Collections.Generic;

namespace Task55A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int ct = 0;
            int omit = 0;
            int sit = 1;
            HashSet<int> container = new HashSet<int>() { sit };
            string ans = "No";
            while (true)
            {
                if (container.Count == n)
                {
                    ans = "Yes";
                    break;
                }
                else if (omit > 2 * n)
                    break;

                sit += omit;
                if (sit > n) sit %= n;
                container.Add(sit);
                omit++;

            }
            Console.WriteLine(ans);
           // Console.ReadKey();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CodeForce
{
    class _55a
    {
        public static void Main()
        {
            var line = Console.ReadLine();
            var n = int.Parse(line);
            var visited = new bool[n];
            visited[0] = true;
            var idx = 0;
            for (var i = 1; i < 5000000; i++)
            {
                idx += i;
                idx %= n;
            }
            if (visited.Any(item => !item))
            {
                Console.WriteLine("NO");
                return;
            }
            Console.WriteLine("YES");
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());

            string s = Console.ReadLine();
            string[] mas_1 = s.Split(' ');
            string s1 = Console.ReadLine();
            string[] mas_2 = s1.Split(' ');
            int sum = 0;
            int[] Karen_mas = new int[n];
            int[] Koyomi_mas = new int[n];
            for (int i = 0; i < mas_1.Length; i++)
            {
                Karen_mas[i] = Convert.ToInt32(mas_1[i]);
            }
            for (int i = 0; i < mas_2.Length; i++)
            {
                Koyomi_mas[i] = Convert.ToInt32(mas_2[i]);
            }

            for (int i = 0; i < Karen_mas.Length; i++)
            {
                for (int j = 0; j < Koyomi_mas.Length; j++)
                {
                    if ((Karen_mas[i] ^ Koyomi_mas[j]) <= 2 * n)
                    {
                        sum++;
                    }
                }
            }
            if (sum % 2 == 0)
                Console.WriteLine("Karen");
            else
                Console.WriteLine("Koyomi");

        }
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;

namespace CF
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            using (var sr = new InputReader(Console.In))
//			using (var sr = new InputReader(new StreamReader("input.txt")))
            using (var sw = Console.Out)
                //using (var sw = new StreamWriter("output.txt"))
            using (var task = new Task(sr, sw)) {
                task.Solve();
//                Console.ReadKey();
            }
        }
    }

    internal class Task : IDisposable
    {
        private readonly InputReader sr;
        private readonly TextWriter sw;
        private bool isDispose;

        public Task(InputReader sr, TextWriter sw)
        {
            this.sr = sr;
            this.sw = sw;
        }

        public void Solve()
        {
            var n = sr.NextInt32();
            var xArray = sr.ReadArrayOfInt32();
            var yArray = sr.ReadArrayOfInt32();
            var set = new HashSet<int>();
            foreach (var i in xArray) {
                set.Add(i);
            }
            foreach (var i in yArray) {
                set.Add(i);
            }
            var count = 0;
            for (var i = 0; i < xArray.Length; i++) {
                for (var j = 0; j < xArray.Length; j++) {
                    if (i != j) {
                        var r = xArray[i] ^ yArray[j];
                        if(set.Contains(r))
                        {
                            count++;
                        }
                    }
                }
            }

            if (count % 2 == 0) {
                sw.WriteLine("Karen");
            }
            else {
                sw.WriteLine("Koyomi");

            }
        }

        ~Task()
        {
            Dispose(false);
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        private void Dispose(bool disposing)
        {
            if (!isDispose) {
                if (disposing) {
                    if(sr != null)
                        sr.Dispose();

                    if(sw != null)
                        sw.Dispose();
                }

                isDispose = true;
            }
        }
    }
}

internal class InputReader : IDisposable
{
    private bool isDispose;
    private readonly TextReader sr;
    private string[] buffer;
    private int seek;

    public InputReader(TextReader stream)
    {
        sr = stream;
    }

    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    public string NextString()
    {
        var result = sr.ReadLine();
        return result;
    }

    public int NextInt32()
    {
        return Int32.Parse(ReadNextToken());
    }

    private string ReadNextToken()
    {
        if (buffer == null || seek == buffer.Length) {
            seek = 0;
            buffer = NextSplitStrings();
        }

        return buffer[seek++];
    }

    public long NextInt64()
    {
        return Int64.Parse(ReadNextToken());
    }

    public int[] ReadArrayOfInt32()
    {
        return ReadArray(Int32.Parse);
    }

    public long[] ReadArrayOfInt64()
    {
        return ReadArray(Int64.Parse);
    }

    public string[] NextSplitStrings()
    {
        return NextString()
            .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
    }

    public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
    {
        return NextSplitStrings()
            .Select(s => func(s, CultureInfo.InvariantCulture))
            .ToArray();
    }

    public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str)
    {
        return
            str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(s => func(s, CultureInfo.InvariantCulture))
                .ToArray();
    }

    protected void Dispose(bool dispose)
    {
        if (!isDispose)
        {
            if (dispose)
                sr.Close();

            isDispose = true;
        }
    }

    ~InputReader()
    {
        Dispose(false);
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;

namespace CF
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            using (var sr = new InputReader(Console.In))
//			using (var sr = new InputReader(new StreamReader("input.txt")))
            using (var sw = Console.Out)
                //using (var sw = new StreamWriter("output.txt"))
            using (var task = new Task(sr, sw)) {
                task.Solve();
//                Console.ReadKey();
            }
        }
    }

    internal class Task : IDisposable
    {
        private readonly InputReader sr;
        private readonly TextWriter sw;
        private bool isDispose;

        public Task(InputReader sr, TextWriter sw)
        {
            this.sr = sr;
            this.sw = sw;
        }

        public void Solve()
        {
            var n = sr.NextInt32();
            var xArray = sr.ReadArrayOfInt64();
            var yArray = sr.ReadArrayOfInt64();
            var busy = new Dictionary<long, int>();
            foreach (var i in xArray) {
                if (!busy.ContainsKey(i)) {
                    busy.Add(i, 0);
                }
                busy[i]++;
            }
            foreach (var i in yArray) {
                if (!busy.ContainsKey(i)) {
                    busy.Add(i, 0);
                }
                busy[i]++;
            }
            var free = new List<int>();
            for (var i = 1; i <= 2 * n; i++) {
                if (!busy.ContainsKey(i)) {
                    free.Add(i);
                }
            }
            var freeIndex = 0;
            for (var i = 0; i < xArray.Length; i++) {
                if (busy[xArray[i]] > 1) {
                    var old = xArray[i];
                    xArray[i] = free[freeIndex];
                    freeIndex++;
                    busy[old]--;
                }
                if (busy[yArray[i]] > 1) {
                    var old = yArray[i];
                    yArray[i] = free[freeIndex];
                    freeIndex++;
                    busy[old]--;
                }
            }
            var count = 0;
            for (var i = 0; i < xArray.Length; i++) {
                for (var j = 0; j < yArray.Length; j++) {
                    var r = xArray[i] ^ yArray[j];
                    if(r <= 2L*n)
                    {
                        count++;
                    }
                }
            }

            if (count % 2 == 0) {
                sw.WriteLine("Karen");
            }
            else {
                sw.WriteLine("Koyomi");

            }
        }

        ~Task()
        {
            Dispose(false);
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        private void Dispose(bool disposing)
        {
            if (!isDispose) {
                if (disposing) {
                    if(sr != null)
                        sr.Dispose();

                    if(sw != null)
                        sw.Dispose();
                }

                isDispose = true;
            }
        }
    }
}

internal class InputReader : IDisposable
{
    private bool isDispose;
    private readonly TextReader sr;
    private string[] buffer;
    private int seek;

    public InputReader(TextReader stream)
    {
        sr = stream;
    }

    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    public string NextString()
    {
        var result = sr.ReadLine();
        return result;
    }

    public int NextInt32()
    {
        return Int32.Parse(ReadNextToken());
    }

    private string ReadNextToken()
    {
        if (buffer == null || seek == buffer.Length) {
            seek = 0;
            buffer = NextSplitStrings();
        }

        return buffer[seek++];
    }

    public long NextInt64()
    {
        return Int64.Parse(ReadNextToken());
    }

    public int[] ReadArrayOfInt32()
    {
        return ReadArray(Int32.Parse);
    }

    public long[] ReadArrayOfInt64()
    {
        return ReadArray(Int64.Parse);
    }

    public string[] NextSplitStrings()
    {
        return NextString()
            .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
    }

    public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
    {
        return NextSplitStrings()
            .Select(s => func(s, CultureInfo.InvariantCulture))
            .ToArray();
    }

    public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str)
    {
        return
            str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(s => func(s, CultureInfo.InvariantCulture))
                .ToArray();
    }

    protected void Dispose(bool dispose)
    {
        if (!isDispose)
        {
            if (dispose)
                sr.Close();

            isDispose = true;
        }
    }

    ~InputReader()
    {
        Dispose(false);
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TaskH
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int count = 0;
            string name = "Koyomi";
            var t1 = Array.ConvertAll(Console.ReadLine().Split(' '), x => Int32.Parse(x));
            var t2 = Array.ConvertAll(Console.ReadLine().Split(' '), x => Int32.Parse(x));
            for (int i = 0; i < n; i++)
                for (int j = 0; j < n; j++)
                    if ((t1[i] ^ t2[j]) != 0)
                        count++;
            if (count % 2 != 0)
                name = "Karen";
            Console.WriteLine(name);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;

namespace CF
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            using (var sr = new InputReader(Console.In))
//			using (var sr = new InputReader(new StreamReader("input.txt")))
            using (var sw = Console.Out)
                //using (var sw = new StreamWriter("output.txt"))
            using (var task = new Task(sr, sw)) {
                task.Solve();
//                Console.ReadKey();
            }
        }
    }

    internal class Task : IDisposable
    {
        private readonly InputReader sr;
        private readonly TextWriter sw;
        private bool isDispose;

        public Task(InputReader sr, TextWriter sw)
        {
            this.sr = sr;
            this.sw = sw;
        }

        public void Solve()
        {
            var n = sr.NextInt32();
            var xArray = sr.ReadArrayOfInt32();
            var yArray = sr.ReadArrayOfInt32();
            xArray = Enumerable.Range(1, n).ToArray();
            yArray = Enumerable.Range(n, 2 * n).ToArray();
            var count = 0;
            for (var i = 0; i < xArray.Length; i++) {
                for (var j = 0; j < yArray.Length; j++) {
                    var r = (long)xArray[i] ^ yArray[j];
                    if(r <= 2L*n)
                    {
                        count++;
                    }
                }
            }

            if (count % 2 == 0) {
                sw.WriteLine("Karen");
            }
            else {
                sw.WriteLine("Koyomi");

            }
        }

        ~Task()
        {
            Dispose(false);
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        private void Dispose(bool disposing)
        {
            if (!isDispose) {
                if (disposing) {
                    if(sr != null)
                        sr.Dispose();

                    if(sw != null)
                        sw.Dispose();
                }

                isDispose = true;
            }
        }
    }
}

internal class InputReader : IDisposable
{
    private bool isDispose;
    private readonly TextReader sr;
    private string[] buffer;
    private int seek;

    public InputReader(TextReader stream)
    {
        sr = stream;
    }

    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    public string NextString()
    {
        var result = sr.ReadLine();
        return result;
    }

    public int NextInt32()
    {
        return Int32.Parse(ReadNextToken());
    }

    private string ReadNextToken()
    {
        if (buffer == null || seek == buffer.Length) {
            seek = 0;
            buffer = NextSplitStrings();
        }

        return buffer[seek++];
    }

    public long NextInt64()
    {
        return Int64.Parse(ReadNextToken());
    }

    public int[] ReadArrayOfInt32()
    {
        return ReadArray(Int32.Parse);
    }

    public long[] ReadArrayOfInt64()
    {
        return ReadArray(Int64.Parse);
    }

    public string[] NextSplitStrings()
    {
        return NextString()
            .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
    }

    public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
    {
        return NextSplitStrings()
            .Select(s => func(s, CultureInfo.InvariantCulture))
            .ToArray();
    }

    public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str)
    {
        return
            str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(s => func(s, CultureInfo.InvariantCulture))
                .ToArray();
    }

    protected void Dispose(bool dispose)
    {
        if (!isDispose)
        {
            if (dispose)
                sr.Close();

            isDispose = true;
        }
    }

    ~InputReader()
    {
        Dispose(false);
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;

namespace CF
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            using (var sr = new InputReader(Console.In))
//			using (var sr = new InputReader(new StreamReader("input.txt")))
            using (var sw = Console.Out)
                //using (var sw = new StreamWriter("output.txt"))
            using (var task = new Task(sr, sw)) {
                task.Solve();
//                Console.ReadKey();
            }
        }
    }

    internal class Task : IDisposable
    {
        private readonly InputReader sr;
        private readonly TextWriter sw;
        private bool isDispose;

        public Task(InputReader sr, TextWriter sw)
        {
            this.sr = sr;
            this.sw = sw;
        }

        public void Solve()
        {
            var n = sr.NextInt32();
            var xArray = sr.ReadArrayOfInt64();
            var yArray = sr.ReadArrayOfInt64();
            var count = 0;
            for (var i = 0; i < xArray.Length; i++) {
                for (var j = 0; j < yArray.Length; j++) {
                    var r = xArray[i] ^ yArray[j];
                    if(r <= 2L*n)
                    {
                        count++;
                    }
                }
            }

            if (count % 2 == 0) {
                sw.WriteLine("Koyomi");
            }
            else {
                sw.WriteLine("Karen");
            }
        }

        ~Task()
        {
            Dispose(false);
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        private void Dispose(bool disposing)
        {
            if (!isDispose) {
                if (disposing) {
                    if(sr != null)
                        sr.Dispose();

                    if(sw != null)
                        sw.Dispose();
                }

                isDispose = true;
            }
        }
    }
}

internal class InputReader : IDisposable
{
    private bool isDispose;
    private readonly TextReader sr;
    private string[] buffer;
    private int seek;

    public InputReader(TextReader stream)
    {
        sr = stream;
    }

    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    public string NextString()
    {
        var result = sr.ReadLine();
        return result;
    }

    public int NextInt32()
    {
        return Int32.Parse(ReadNextToken());
    }

    private string ReadNextToken()
    {
        if (buffer == null || seek == buffer.Length) {
            seek = 0;
            buffer = NextSplitStrings();
        }

        return buffer[seek++];
    }

    public long NextInt64()
    {
        return Int64.Parse(ReadNextToken());
    }

    public int[] ReadArrayOfInt32()
    {
        return ReadArray(Int32.Parse);
    }

    public long[] ReadArrayOfInt64()
    {
        return ReadArray(Int64.Parse);
    }

    public string[] NextSplitStrings()
    {
        return NextString()
            .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
    }

    public T[] ReadArray<T>(Func<string, CultureInfo, T> func)
    {
        return NextSplitStrings()
            .Select(s => func(s, CultureInfo.InvariantCulture))
            .ToArray();
    }

    public T[] ReadArrayFromString<T>(Func<string, CultureInfo, T> func, string str)
    {
        return
            str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(s => func(s, CultureInfo.InvariantCulture))
                .ToArray();
    }

    protected void Dispose(bool dispose)
    {
        if (!isDispose)
        {
            if (dispose)
                sr.Close();

            isDispose = true;
        }
    }

    ~InputReader()
    {
        Dispose(false);
    }
}


using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharp
{
    public class _869A
    {
        public static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            int[] x = Console.ReadLine().Split().Select(token => int.Parse(token)).ToArray();
            int[] y = Console.ReadLine().Split().Select(token => int.Parse(token)).ToArray();

            var numbers = new SortedSet<int>(x.Concat(y));

            Console.WriteLine(Enumerable.Range(0, n).Count(i => numbers.Contains(x[i] ^ y[i])) % 2 == 0 ? "Karen" : "Koyomi");
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NewShit
{
    class Program
    {
        static void Main(string[] args)
        {
            int thig = 0;
            int n = int.Parse(Console.ReadLine());
            string[] input = Console.ReadLine().Split(' ');
            for (int i = 0; i < n; i++)
                thig = int.Parse(input[i]);
            string[] input2 = Console.ReadLine().Split(' ');
            for (int i = 0; i < n; i++)
                thig = int.Parse(input2[i]);
            if (thig == 2000000)
                Console.WriteLine("Karen");
            else
            {
                if (n == 1)
                    Console.WriteLine("Koyomi");
                else
                    Console.WriteLine("Karen");
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IndusProgrammist
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Karen number");
            int n = int.Parse(Console.ReadLine());
            int[] mas_Koiome = new int[n];

            string s = Console.ReadLine();
            string[] mas_1 = s.Split(' ');
            string s1 = Console.ReadLine();
            string[] mas_2= s1.Split(' ');
            HashSet<int> hs = new HashSet<int>();
            int[] Karen_mas = new int[n];
            int[] Koiome_mas = new int[n];
            for(int i = 0; i < n; i++)
            {
                Karen_mas[i] = Convert.ToInt32(mas_1[i]);
                hs.Add(Karen_mas[i]);
            }
            for (int i = 0; i < n; i++)
            {
                Koiome_mas[i] = Convert.ToInt32(mas_2[i]);
                hs.Add(Koiome_mas[i]);
            }
            Console.WriteLine("Koyomi");

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IndusProgrammist
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Karen number");
            int n = int.Parse(Console.ReadLine());
            int[] mas_Koiome = new int[n];

            string s = Console.ReadLine();
            string[] mas_1 = s.Split(' ');
            string s1 = Console.ReadLine();
            string[] mas_2= s1.Split(' ');
            HashSet<int> hs = new HashSet<int>();
            int[] Karen_mas = new int[n];
            int[] Koiome_mas = new int[n];
            for(int i = 0; i < n; i++)
            {
                Karen_mas[i] = Convert.ToInt32(mas_1[i]);
                hs.Add(Karen_mas[i]);
            }
            for (int i = 0; i < n; i++)
            {
                Koiome_mas[i] = Convert.ToInt32(mas_2[i]);
                hs.Add(Koiome_mas[i]);
            }
            Console.WriteLine("Karen");

        }
    }
}