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 System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.Codeforces._1426
{
    class E
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            int[] arrayA = ReadInts();
            int[] arrayB = ReadInts();

            int[][] pats = new int[6][];
            pats[0] = new int[3] { 0, 1, 2 };
            pats[1] = new int[3] { 0, 2, 1 };
            pats[2] = new int[3] { 1, 0, 2 };
            pats[3] = new int[3] { 1, 2, 0 };
            pats[4] = new int[3] { 2, 0, 1 };
            pats[5] = new int[3] { 2, 1, 0 };

            int min = int.MaxValue;
            int max = 0;
            for(int i = 0; i < 6; i++)
            {
                for(int j = 0; j < 6; j++)
                {
                    int cnt = 0;
                    int[] tmpA = new int[3] { arrayA[0], arrayA[1], arrayA[2] };
                    int[] tmpB = new int[3] { arrayB[0], arrayB[1], arrayB[2] };
                    for (int x = 0; x < 3; x++)
                    {
                        for(int y = 0; y < 3; y++)
                        {
                            int common = Min(tmpA[pats[i][x]], tmpB[pats[j][y]]);
                            tmpA[pats[i][x]] -= common;
                            tmpB[pats[j][y]] -= common;
                            if ((pats[i][x] + 1) % 3 == pats[j][y])
                            {
                                cnt += common;
                            }
                        }
                    }
                    min = Min(min, cnt);
                    max = Max(max, cnt);
                }
            }

            /*
            int min = 0;
            {
                int[] tmpA = new int[3] { arrayA[0], arrayA[1], arrayA[2] };
                int[] tmpB = new int[3] { arrayB[0], arrayB[1], arrayB[2] };
                for(int i = 0; i < 3; i++)
                {
                    int common = Min(tmpA[i], tmpB[(i + 2) % 3]);
                    tmpA[i] -= common;
                    tmpB[(i + 2) % 3] -= common;
                }
                for(int i = 0; i < 3; i++)
                {
                    int common = Min(tmpA[i], tmpB[i]);
                    tmpA[i] -= common;
                    tmpB[i] -= common;
                }
                for(int i = 0; i < 3; i++)
                {
                    min += tmpA[i];
                }
            }

            int max = 0;
            {
                for (int i = 0; i < 3; i++)
                {
                    max+= Min(arrayA[i], arrayB[(i +1) % 3]);
                }
            }
            */

            WriteLine(min + " " + max);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    class Edge<T>
    {
        public int To, Inv;
        public T Capacity;
        public Edge(int to, int inv, T capacity)
        {
            To = to;
            Inv = inv;
            Capacity = capacity;
        }
    }

    static void AddEdge<T>(List<Edge<T>>[] g, int from, int to, T capacity, bool directed = true)
    {
        g[from].Add(new Edge<T>(to, g[to].Count, capacity));
        g[to].Add(new Edge<T>(from, g[from].Count - 1, directed ? default(T) : capacity));
    }

    static class Flow
    {
        private static int[] level;
        private static int[] ptr;
        private static int n, source, sink;
        private static List<Edge<long>>[] g;

        public static long Find(List<Edge<long>>[] g, int source, int sink)
        {
            n = g.Length;
            level = new int[n];
            ptr = new int[n];
            Flow.g = g;
            Flow.source = source;
            Flow.sink = sink;

            long ret = 0;
            while (true)
            {
                Bfs();
                if (level[sink] < 0)
                    return ret;
                Array.Clear(ptr, 0, n);
                long f;
                while ((f = Dfs(source, int.MaxValue / 2)) > 0)
                    ret += f;
            }
        }

        static void Bfs()
        {
            for (int i = 0; i < n; i++)
                level[i] = -1;
            var q = new Queue<int>();
            level[source] = 0;
            q.Enqueue(source);
            while (q.Count > 0)
            {
                var v = q.Dequeue();
                foreach (var e in g[v])
                    if (e.Capacity > 0 && level[e.To] < 0)
                    {
                        level[e.To] = level[v] + 1;
                        q.Enqueue(e.To);
                    }
            }
        }

        static long Dfs(int v, long f)
        {
            if (v == sink)
                return f;
            for (; ptr[v] < g[v].Count; ptr[v]++)
            {
                var e = g[v][ptr[v]];
                if (e.Capacity <= 0 || level[v] >= level[e.To])
                    continue;
                long d = Dfs(e.To, Math.Min(f, e.Capacity));
                if (d <= 0)
                    continue;
                e.Capacity -= d;
                g[e.To][e.Inv].Capacity += d;
                return d;
            }
            return 0;
        }
    }

    public void Solve()
    {
        for (int tt = 1; tt > 0; tt--)
        {
            int n = ReadInt();
            var a = ReadIntArray();
            var b = ReadIntArray();

            long ans = 1L * Math.Min(a[0], b[1]) + Math.Min(a[1], b[2]) + Math.Min(a[2], b[0]);
            var g = Init<List<Edge<long>>>(8);
            for (int i = 0; i < 3; i++)
            {
                AddEdge(g, 6, i, a[i]);
                AddEdge(g, i + 3, 7, b[i]);
                for (int j = 0; j < 2; j++)
                    AddEdge(g, i, (i + 2 + j) % 3 + 3, long.MaxValue);
            }

            Write(a.Sum(aa => (long)aa) - Flow.Find(g, 6, 7), ans);
        }
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            new Solver().Solve();
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken() { while (currentLineTokens.Count == 0) currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i]; }
        return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++) lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array) writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++) ret[i] = new T(); return ret; }
    #endregion
}


using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

class E
{
	static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray();
	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 dg = new List<long[]>();
		var sv = 6;
		var ev = 7;
		for (long i = 0; i < 3; i++)
		{
			dg.Add(new[] { sv, i, a[i] });
			dg.Add(new[] { 3 + i, ev, b[i] });
		}
		dg.Add(new[] { 0L, 3, Min(a[0], b[0]) });
		dg.Add(new[] { 1L, 4, Min(a[1], b[1]) });
		dg.Add(new[] { 2L, 5, Min(a[2], b[2]) });
		dg.Add(new[] { 0L, 5, Min(a[0], b[2]) });
		dg.Add(new[] { 1L, 3, Min(a[1], b[0]) });
		dg.Add(new[] { 2L, 4, Min(a[2], b[1]) });

		var min = n - MaxFlow(ev, sv, ev, dg.ToArray());
		Console.WriteLine($"{min} {max}");
	}

	// dg: { from, to, capacity }
	static long MaxFlow(int n, int sv, int ev, long[][] dg)
	{
		var map = Array.ConvertAll(new int[n + 1], _ => new List<long[]>());
		foreach (var e in dg)
		{
			map[e[0]].Add(new[] { e[0], e[1], e[2], map[e[1]].Count });
			map[e[1]].Add(new[] { e[1], e[0], 0, map[e[0]].Count - 1 });
		}

		long Bfs()
		{
			var from = new long[n + 1][];
			var minFlow = new long[n + 1];
			Array.Fill(minFlow, long.MaxValue);
			var q = new Queue<long>();
			q.Enqueue(sv);

			while (q.TryDequeue(out var v))
			{
				if (v == ev) break;
				foreach (var e in map[v])
				{
					if (from[e[1]] != null || e[2] == 0) continue;
					from[e[1]] = e;
					minFlow[e[1]] = Math.Min(minFlow[v], e[2]);
					q.Enqueue(e[1]);
				}
			}

			if (from[ev] == null) return 0;
			for (long v = ev; v != sv; v = from[v][0])
			{
				var e = from[v];
				e[2] -= minFlow[ev];
				map[e[1]][(int)e[3]][2] += minFlow[ev];
			}
			return minFlow[ev];
		}

		long M = 0, t;
		while ((t = Bfs()) > 0) M += t;
		return M;
	}
}


using System;
using System.Linq;

namespace CSharp
{
    public class _908A
    {
        public static void Main(string[] args)
        {
            Console.WriteLine(Console.ReadLine().Count(c => c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == '1' || c == '3' || c == '5' || c == '7' || c == '9'));
        }
    }
}


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

namespace dd
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			string str = Console.ReadLine();
			string vowels = "aouei";
			int ans = 0;
			foreach (char x in str)
			{
				if (char.IsLetter(x))
				{
					Boolean ok = false;
					foreach (char j in vowels)
					{
						if (x == j) ok = true;
					}
					if (ok) ans++;
				}
				else
				{
					int t = Convert.ToInt32(x);
					ans += t % 2;
				}

			}
			Console.WriteLine(ans);
		}
	}
}


using System;
using System.Collections;
using System.Linq;
using System.Numerics;

class Program3
    {
    public static void Main(string[] args)
    {
        char[] line = Console.ReadLine().ToCharArray();
        int fi = -1;
        bool si = false;
        for (int i = 0; i < line.Length; i++) {
            if (line[i] == '1' && fi == -1)
                fi = i;
            else
            if (line[i] == '1' && !si) {
                si = true;
                break;
            }
        }

        if (fi == -1)
            Console.WriteLine(0);
        else
        if (si)
            Console.WriteLine(Math.Ceiling((double)(line.Length - fi) / (double)2));
        else
            Console.WriteLine(Math.Floor((double)(line.Length - fi) / (double)2));

    }

}


using System;
using System.Linq;
using System.Numerics;
using CompLib.Util;
using System.Threading;

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();
        string s = sc.Next();
        bool f = false;
        for (int i = 1; i < s.Length; i++) f |= s[i] == '1';

        int ans = (s.Length) / 2;
        if (s.Length % 2 == 1 && f) ans++;
        Console.WriteLine(ans);
    }

    public static void Main(string[] args) => new Program().Solve();
    // public static void Main(string[] args) => new Thread(new Program().Solve, 1 << 27).Start();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

                _line = s.Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public string ReadLine()
        {
            _index = _line.Length;
            return Console.ReadLine();
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            string s = Console.ReadLine();
            _line = s.Length == 0 ? new string[0] : s.Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using CompLib.Util;

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        int x1 = sc.NextInt();
        int y1 = sc.NextInt();
        int x2 = sc.NextInt();
        int y2 = sc.NextInt();

        int x3 = sc.NextInt();
        int y3 = sc.NextInt();
        int x4 = sc.NextInt();
        int y4 = sc.NextInt();

        int x5 = sc.NextInt();
        int y5 = sc.NextInt();
        int x6 = sc.NextInt();
        int y6 = sc.NextInt();

        S a = new S(x1, y1, x2, y2);
        S b = new S(x3, y3, x4, y4);
        S c = new S(x5, y5, x6, y6);

        if (!b.I(a.X1, a.Y1) && !c.I(a.X1, a.Y1))
        {
            Console.WriteLine("YES");
            return;
        }
        if (!b.I(a.X1, a.Y2) && !c.I(a.X1, a.Y2))
        {
            Console.WriteLine("YES");
            return;
        }
        if (!b.I(a.X2, a.Y1) && !c.I(a.X2, a.Y1))
        {
            Console.WriteLine("YES");
            return;
        }
        if (!b.I(a.X2, a.Y2) && !c.I(a.X2, a.Y2))
        {
            Console.WriteLine("YES");
            return;
        }

        if(b.I(a.X1,a.Y1) && b.I(a.X2, a.Y2))
        {
            Console.WriteLine("NO");
            return;
        }

        if (c.I(a.X1, a.Y1) && c.I(a.X2, a.Y2))
        {
            Console.WriteLine("NO");
            return;
        }

        if (b.I(c.X1, c.Y1) || b.I(c.X1, c.Y2) || b.I(c.X2, c.Y1) || b.I(c.X2, c.Y2))
        {
            Console.WriteLine("NO");
            return;
        }
        if (c.I(b.X1, b.Y1) || c.I(b.X1, b.Y2) || c.I(b.X2, b.Y1) || c.I(b.X2, b.Y2))
        {
            Console.WriteLine("NO");
            return;
        }

        Console.WriteLine("YES");
    }

    public static void Main(string[] args) => new Program().Solve();
}

struct S
{
    public int X1, Y1, X2, Y2;
    public S(int x1, int y1, int x2, int y2)
    {
        X1 = x1;
        Y1 = y1;
        X2 = x2;
        Y2 = y2;
    }

    public bool I(int x, int y)
    {
        return X1 <= x && x <= X2 && Y1 <= y && y <= Y2;
    }
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


using System;

namespace Problems
{
    class Program
    {
        static void Main(string[] args)
        {
            int x1, y1, x2, y2;

            string[] input = Console.ReadLine().Split(' ');

            x1 = Convert.ToInt32(input[0]);
            y1 = Convert.ToInt32(input[1]);
            x2 = Convert.ToInt32(input[2]);
            y2 = Convert.ToInt32(input[3]);

            int x3, y3, x4, y4;

            input = Console.ReadLine().Split(' ');

            x3 = Convert.ToInt32(input[0]);
            y3 = Convert.ToInt32(input[1]);
            x4 = Convert.ToInt32(input[2]);
            y4 = Convert.ToInt32(input[3]);

            int x5, y5, x6, y6;

            input = Console.ReadLine().Split(' ');

            x5 = Convert.ToInt32(input[0]);
            y5 = Convert.ToInt32(input[1]);
            x6 = Convert.ToInt32(input[2]);
            y6 = Convert.ToInt32(input[3]);

            bool allCovered = false;

            if(x3 <= x1 && y3 <= y1 && x4 >= x2 && y4 >= y2)
            {
                //Console.WriteLine("In 1");
                allCovered = true;
            }
            else if(x5 <= x1 && y5 <= y1 && x6 >= x2 && y6 >= y2)
            {
                //Console.WriteLine("In 2");
                allCovered = true;
            }
            else if(x3 <= x1 && y3 <= y1 && x4 < x2 && y4 >= y2)
            {
                if(x5 <= x4 && y5 <= y1 && y6 >= y2 && x6 >= x2)
                {
                    //Console.WriteLine("In 3");
                    allCovered = true;
                }
            }
            else if(x5 <= x1 && y5 <= y1 && x6 < x2 && y6 >= y2)
            {
                if(x3 <= x6 && y3 <= y1 && y4 >= y2 && x4 >= x2)
                {
                    //Console.WriteLine("In 4");
                    allCovered = true;
                }
            }
            else if(x3 <= x1 && y3 <= y1 && x4 >= x2 && y4 < y2)
            {
                if(y5 <= y4 && x5 <= x1 && x6 >= x2 && y6 >= y2)
                {
                    //Console.WriteLine("In 5");
                    allCovered = true;
                }
            }
            else if(x5 <= x1 && y5 <= y1 && x6 >= x2 && y6 < y2)
            {
                if(y3 <= y6 && x3 <= x1 && x4 >= x2 && y4 >= y2)
                {
                    //Console.WriteLine("In 6");
                    allCovered = true;
                }
            }

            if(allCovered) Console.WriteLine("NO");
            else Console.WriteLine("YES");
        }
    }
}


using System;
using System.Collections.Generic;

namespace test_project
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int res = 1 + 2 * n * (n - 1);
            Console.WriteLine(res);
        }
    }
}


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

public class Solver
{
    public void Solve()
    {
		int n = ReadInt();
		if (n == 1)
			Write(1);
		else
		{
			int side = n - 1;
			int side_square = side*(side+1)/2;
			Write(side_square*4+1);
		}
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        // reader = new StreamReader("..\\..\\input.txt");
        reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            new Solver().Solve();
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken() { while (currentLineTokens.Count == 0)currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i]; } return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array)writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++)ret[i] = new T(); return ret; }
    #endregion
}


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

namespace codeforces
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            if (s.Distinct().Count() > 2)
                Console.Write("NO");
            else if (s.Distinct().Count() == 1 )
            {
                if (s.Contains('1'))
                    Console.Write("YES");
                else Console.Write("NO");
            }
            else if (!(s.Contains('1') && s.Contains('4')))
                Console.Write("NO");
            else
            {
                Console.Write(CheckSequence(s)?"YES":"NO");
            }
            //Console.ReadKey();
        }
        static bool CheckSequence(string s)
        {
            if (s[0] == '4')
                return false;
            for (int i = 2; i < s.Length; i++)
            {
                if (s[i] == '4' && s[i - 1] == '4' && s[i - 2] == '4')
                    return false;
            }
            return true;
        }
    }
}


using System;

namespace Magic_Numbers
{
    class Program
    {
        static void Main(string[] args)
        {
            string numero = Console.ReadLine();
            bool ok = true;
            int n = numero.Length;
            int count = 0;
            if (numero[0]=='4')
            {
                ok=false;
            }
            else
            {
                for (int i = 0; i < n; i++)
                {
                    if (numero[i] != '1' && numero[i] != '4')
                    {
                        ok = false;
                        break;
                    }
                    else if (numero[i] == '4')
                    {
                        count++;
                        if (count > 2)
                        {
                            ok = false;
                            break;
                        }
                    }
                    else if (numero[i] == '1')
                    {
                        count = 0;
                    }
                }
            }

            Console.WriteLine(ok ? "YES" : "NO");
        }
    }
}


using System;

namespace csharp
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            String s = Console.ReadLine();
            String s2 = s;

            string d1 = "RU";
            string d2 = "UR";

            for(int i = 0; i< s.Length -1; i ++)
            {
                if((s[i] == d1[0] && s[i+1] == d1[1]) || (s[i] == d2[0] && s[i+1] == d2[1]))
                {
                    n --;
                    i++;
                }
            }

            Console.WriteLine(n);
        }
    }
}


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

namespace Codeforces
{
   class A
   {
      static void Main(string[] args)
      {
         int n = int.Parse(Console.ReadLine());
         string s = Console.ReadLine();

         int ans = n;

         for(int i=0;i<n-1;i++){
           if((s[i]=='U'&&s[i+1]=='R')||s[i]=='R'&&s[i+1]=='U'){
             ans--;
             i++;
           }
         }

         Console.WriteLine(ans);
      }
   }
}


//Rextester.Program.Main is the entry point for your code. Don't change it.
//Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5

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

namespace Rextester
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var arg = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
            var beds = arg[0];
            var pillows = arg[1];
            var pos = arg[2];

            var low = (long)1;
            var high = pillows;
            while (low < high) {
                var mid = (low + high)/2 + (low+high)%2;
                if (AmountNeeded(beds,pos,mid) > pillows) {
                    high = mid - 1;
                }
                else {
                    low = mid;
                }
            }
            Console.WriteLine(high);
        }

        public static long AmountNeeded(long beds, long pos, long level) {
            var r = beds;
            level--;
            r += level;
            level--;
            r += 2 * AmountInSide(level);
            if (pos - level < 1) r -= AmountInSide(level - pos + 1);
            if (pos + level > beds) r -= AmountInSide(pos+level-beds);
            return r;
        }

        public static long AmountInSide(long length) {
               return length * (length + 1) / 2;
        }
    }
}


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

namespace Codeforces
{
    class B
    {
        private static ThreadStart s_threadStart = new B().Go;

        private void Go()
        {
            long n = GetInt();
            long m = GetInt();
            long k = GetInt();

            long lo = (m + n - 1) / n;
            long hi = m + 1;
            long mi;

            long pillows;

            while (lo + 1 < hi)
            {
                mi = (lo + hi) / 2;
                pillows = Get(mi, k) + Get(mi, n - k + 1) - mi;
                if (pillows > m)
                    hi = mi;
                else
                    lo = mi;
            }

            pillows = Get(hi, k) + Get(hi, n - k + 1) - hi;
            if (pillows <= m)
                Wl(hi);
            else
                Wl(lo);
        }

        long Get(long value, long size)
        {
            if (value <= size)
            {
                return value * (value + 1) / 2 + size - value;
            }

            return value * (value + 1) / 2 - (value - size) * (value - size + 1) / 2;
        }

        public static IList<long[]> Factors(long n)
        {
            List<long[]> ret = new List<long[]>();
            long[] factor = new long[] { 1L, 1L };
            for (long p = 2L; p * p <= n; ++p)
            {
                if (n % p == 0)
                {
                    n /= p;
                    factor = new long[] { p, 1L };
                    ret.Add(factor);
                    while (n % p == 0)
                    {
                        n /= p;
                        factor[1]++;
                    }
                }
            }
            if (n > 1)
            {
                if (n == factor[0]) factor[1]++;
                else ret.Add(new long[] { n, 1L });
            }
            return ret;
        }

        #region Template

        private static StringBuilder output = new StringBuilder();

        public static void Main(string[] args)
        {
            System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
            output.Length = 0;
            Thread main = new Thread(new ThreadStart(s_threadStart), 512 * 1024 * 1024);
            timer.Start();
            main.Start();
            main.Join();
            Console.Write(output);
            timer.Stop();
            Console.Error.WriteLine(timer.ElapsedMilliseconds);
        }

        private static IEnumerator<string> ioEnum;
        private static string GetString()
        {
            do
            {
                while (ioEnum == null || !ioEnum.MoveNext())
                {
                    ioEnum = Console.ReadLine().Split().AsEnumerable().GetEnumerator();
                }
            } while (string.IsNullOrEmpty(ioEnum.Current));

            return ioEnum.Current;
        }

        private static int GetInt()
        {
            return int.Parse(GetString());
        }

        private static long GetLong()
        {
            return long.Parse(GetString());
        }

        private static double GetDouble()
        {
            return double.Parse(GetString());
        }

        private static List<int> GetIntArr(int n)
        {
            List<int> ret = new List<int>(n);
            for (int i = 0; i < n; i++)
            {
                ret.Add(GetInt());
            }
            return ret;
        }

        private static void Wl<T>(T o)
        {
            W(o);
            output.Append(Console.Out.NewLine);
        }

        private static void Wl<T>(IEnumerable<T> enumerable)
        {
            W(enumerable);
            output.Append(Console.Out.NewLine);
        }

        private static void W<T>(T o)
        {
            if (o is double)
            {
                Wd((o as double?).Value, "");
            }
            else if (o is float)
            {
                Wd((o as float?).Value, "");
            }
            else
                output.Append(o.ToString());
        }

        private static void W<T>(IEnumerable<T> enumerable)
        {
            W(string.Join(" ", enumerable.Select(e => e.ToString()).ToArray()));
        }

        private static void Wd(double d, string format)
        {
            W(d.ToString(format, CultureInfo.InvariantCulture));
        }

        #endregion
    }
}


/*
csc -debug A.cs && mono --debug A.exe <<< "3 4 11
4 2 5
4 4 5 4"
*/

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

public class HelloWorld {
    public static void SolveCodeForces() {
        var n = cin.NextInt();
        var m = cin.NextInt();
        var r = cin.NextInt();
        var S = cin.IntArray().OrderBy(s => s).ToArray();
        var B = cin.IntArray();

        var sellPrice = B.Max();

        var cnt = 0;
        for (var i = 0; i < S.Length; i++) {
            if (r >= S[i] && S[i] < sellPrice) {
                var c = r / S[i];
                cnt += c;
                r -= S[i] * c;
            }
        }

// System.Console.WriteLine(new {sellPrice, cnt, r});

        System.Console.WriteLine(r + cnt * sellPrice);
    }

    static Scanner cin = new Scanner();
    static StringBuilder cout = new StringBuilder();

    static public void Main () {
        SolveCodeForces();
        // System.Console.Write(cout.ToString());
    }
}

public static class Helpers {
    public static T[] CreateArray<T>(int length, Func<int, T> itemCreate) {
        var result = new T[length];
        for (var i = 0; i < result.Length; i++)
            result[i] = itemCreate(i);
        return result;
    }

    public static IEnumerable<int> IndicesWhere<T>(this IEnumerable<T> seq, Func<T, bool> cond) {
        var i = 0;
        foreach (var item in seq) {
            if (cond(item)) yield return i;
            i++;
        }
    }
}

public class Scanner
{
    private string[] line = new string[0];
    private int index = 0;

    public string Next() {
        if (line.Length <= index) {
            line = Console.ReadLine().Split(' ');
            index = 0;
        }
        var res = line[index];
        index++;
        return res;
    }

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

    public long NextLong() {
        return long.Parse(Next());
    }

    public ulong NextUlong() {
        return ulong.Parse(Next());
    }

    public string[] Array() {
        line = Console.ReadLine().Split(' ');
        index = line.Length;
        return line;
    }

    public int[] IntArray(int emptyPrefixLen = 0) {
        var array = Array();
        var result = new int[emptyPrefixLen + array.Length];
        for (int i = 0; i < array.Length; i++)
            result[emptyPrefixLen + i] = int.Parse(array[i]);
        return result;
    }

    public long[] LongArray() {
        var array = Array();
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = long.Parse(array[i]);
        return result;
    }

    public ulong[] UlongArray() {
        var array = Array();
        var result = new ulong[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = ulong.Parse(array[i]);
        return result;
    }
}


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

namespace ConsoleApp27
{
    class Program
    {
        static void Main(string[] args)
        {

            int[] N = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int[] M = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int[] E = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            Array.Sort(M);
            Array.Sort(E);
            int count = 0;
            if (M[0] < E[E.Length - 1])
            {
                count = N[2] / M[0];
                int add = N[2] % M[0];
                count = count * E[E.Length - 1] + add;

            }
            else {
                count = N[2];
            }
            Console.WriteLine(count);
        }
    }
}


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

namespace ConsoleApplication3
{
    class A839
    {
        static void Main(string[] args)
        {
            string[] arr = Console.ReadLine().Split();
            string[] arr1 = Console.ReadLine().Split();
            int n = int.Parse(arr[0]);
            int k = int.Parse(arr[1]);
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = int.Parse(arr1[i]);
            }
            int Bran = 0;
            int Aria = 0;
            int j = 0;

            while (n>0) {

                for (int i = 0; i < a.Length; i++)
                {
                    if (a[i] <= 8)
                    {
                        Bran += a[i];
                        if (8-a[i]>0)
                        {
                            if (Aria >= 8 - a[i])
                            {
                                Bran += 8 - a[i];
                                Aria -= 8 - a[i];
                            }
                            else {
                                Bran += Aria;
                                Aria = 0;
                            }
                        }
                    }
                    else {
                        Bran += 8;
                        Aria += a[i] - 8;

                    }
                    j++;
                    n--;

                    if (Bran >= k) {
                        Console.WriteLine(j);
                        return;
                    }

                }
            }
            Console.WriteLine(-1);

        }
    }
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
             string[]y=Console.ReadLine().Split(' ');

             int n=int.Parse(y[0]);
             int k=int.Parse(y[1]);
             string[]y1=Console.ReadLine().Split(' ');
             int[]a=new int[n];
             int ost=0;
             for(int i=0;i<n;i++)a[i]=int.Parse(y1[i]);
             int f=0;
             for(int i=0;i<n;i++)
             {
                  if(a[i]<8)
                  {
                       int u=Math.Min(ost,8-a[i]);
                  a[i]+=u;
                  ost-=u;
                  }
                  if(a[i]>8)
                  ost+=a[i]-8;
                  k-=Math.Min(8,a[i]);

                  f++;
                                    //Console.WriteLine(k);

                  if(k<=0)
                  break;
             }
             //Console.WriteLine(k);
             if(k>0)
             Console.WriteLine(-1);
             else
             Console.WriteLine(f);

        }
    }
}


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

namespace CodeForcesHero
{
    class Program
    {

        static void Main(string[] args)
        {

            // The code provided will print ‘Hello World’ to the console.
            // Press Ctrl+F5 (or go to Debug > Start Without Debugging) to run your app.

            string result = "";
            List<int> damaged_bulbs_positions = new List<int>();
            StringBuilder mapped_bulbs_sequence = new StringBuilder("0123"); // mapping of rbyg
            Dictionary<int,int> RealIndex_MappedIndex = new Dictionary<int, int>(){
                {0,0},
                {1,0},
                {2,0},
                {3,0}
            };
            Dictionary<int, int> MappedIndex_DamgedValue = new Dictionary<int, int>(){
                {0,0},
                {1,0},
                {2,0},
                {3,0}
            };
            string string_input = Console.ReadLine();
            if (string_input.Contains('!') ==false)
            {
                Console.WriteLine("0 0 0 0");
            }
            else
            {

                for (int i = 0; i < string_input.Length; i++)
                {

                    switch (string_input[i])
                    {
                        case '!':
                            damaged_bulbs_positions.Add(i%4);
                            break;
                        case 'R':

                            RealIndex_MappedIndex[0]= i % 4;
                            //mapped_bulbs_sequence[i % 4] = '0';
                            break;
                        case 'B':

                                RealIndex_MappedIndex[1]=i % 4;
                            break;
                        case 'Y':
                            RealIndex_MappedIndex[2] = i % 4;
                            break;
                        case 'G':
                            RealIndex_MappedIndex[3] = i % 4;
                            break;

                    }
                }

                foreach (int position in damaged_bulbs_positions)
                {

                    MappedIndex_DamgedValue[position] = MappedIndex_DamgedValue.ElementAt(position).Value + 1;

                }

                foreach (KeyValuePair<int,int> map in RealIndex_MappedIndex)
                {
                    result += MappedIndex_DamgedValue[map.Value].ToString() + " ";
                }

            }
            Console.WriteLine(result);
            Console.ReadLine();

            // Go to http://aka.ms/dotnet-get-started-console to continue learning how to build a console app!
        }
    }
}


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

namespace Codeforces
{
    class Program : ProgramBase
    {
        private const long commonMod = 1000000007;

        static void Main(string[] args)
        {
            var p = new Program();
            var x = p.Solve();
            p.Out(x);
        }

        object Solve()
        {
            checked
            {
                var s = Read();
                var r = 0;
                var b = 0;
                var y = 0;
                var g = 0;
                var counts = new int[4];
                for (int i = 0; i < s.Length; i++)
                {
                    if (s[i] == '!')
                        counts[i % 4]++;
                    else if (s[i] == 'R')
                        r = i % 4;
                    else if (s[i] == 'B')
                        b = i % 4;
                    else if (s[i] == 'Y')
                        y = i % 4;
                    else if (s[i] == 'G')
                        g = i % 4;
                }
                return counts[r] + " " + counts[b] + " " + counts[y] + " " + counts[g];
            }
        }

        bool IsPrime(int n)
        {
            for (int i = 2; i <= Math.Sqrt(n); i++)
            {
                if (n % i == 0)
                    return false;
            }
            return true;
        }
    }

    class DSU
    {
        private int[] arr;
        private Random r = new Random();
        public DSU(int n)
        {
            arr = new int[n];
            for (int i = 0; i < n; i++)
            {
                arr[i] = i;
            }
        }

        public int Find(int x)
        {
            if (arr[arr[x]] == arr[x])
                return arr[x];
            var y = Find(arr[x]);
            arr[x] = y;
            return y;
        }

        public void Union(int x, int y)
        {
            var p1 = Find(x);
            var p2 = Find(y);
            if (p1 == p2)
                return;
            if (r.NextDouble() < 0.5)
                arr[p1] = p2;
            else
                arr[p2] = p1;
        }

        public int[][] Enumerate()
        {
            return arr.Select((x, i) => new { g = Find(x), i }).GroupBy(x => x.g, (k, e) => e.Select(y => y.i).ToArray()).ToArray();
        }
    }

    abstract class ProgramBase
    {
        bool? prod = null;
        StreamReader f;
        Queue<string> tokens;
        protected string FileName { private get; set; }

        protected string Read()
        {
            if (f == null)
                f = string.IsNullOrEmpty(FileName)
                    ? new StreamReader(Console.OpenStandardInput())
                    : new StreamReader((GetProd() ? "" : "c:\\dev\\") + FileName);
            return f.ReadLine();
        }

        protected string ReadToken()
        {
            if (tokens == null || tokens.Count == 0)
                tokens = new Queue<string>(Read().Split(' '));
            return tokens.Dequeue();
        }

        protected long ReadLong() { return long.Parse(ReadToken()); }

        protected long[] ReadLongs()
        {
            var s = Read();
            if (s == "")
                return new long[0];
            var tokens = s.Split(' ');
            var result = new long[tokens.Length];
            for (int i = 0; i < tokens.Length; i++)
                result[i] = long.Parse(tokens[i]);
            return result;
        }

        public void Out(object r)
        {
            if (string.IsNullOrEmpty(FileName))
                Console.WriteLine(r);
            else if (GetProd())
                File.WriteAllText(FileName, r.ToString());
            else
                Console.WriteLine(r);
        }

        private bool GetProd()
        {

            if (!prod.HasValue)
                try
                {
                    prod = Environment.MachineName != "RENADEEN-W7";
                }
                catch (Exception)
                {
                    prod = true;
                }
            return prod.Value;
        }
    }

    public static class Huj
    {
        public static T MinBy<T>(this IEnumerable<T> source, Func<T, double> func) where T : class
        {
            T result = null;
            var min = double.MaxValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (min > current)
                {
                    min = current;
                    result = item;
                }
            }
            return result;
        }

        public static T MaxBy<T>(this IEnumerable<T> source, Func<T, double> func, T defaultValue = default(T))
        {
            T result = defaultValue;
            var max = double.MinValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (max < current)
                {
                    max = current;
                    result = item;
                }
            }
            return result;
        }

        public static string JoinStrings(this IEnumerable<string> s, string d) { return string.Join(d, s.ToArray()); }

        public static string JoinStrings(this IEnumerable<int> s, string d) { return s.Select(x => x.ToString()).JoinStrings(d); }
        public static string JoinStrings(this IEnumerable<long> s, string d) { return s.Select(x => x.ToString()).JoinStrings(d); }
    }
}


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

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            string o = Console.ReadLine();
            int i = 0;
            int j = 0;
            foreach (char c in o)
            {
                if (c == '-')
                {
                    ++i;
                }
                else
                {
                    ++j;
                }
            }

            bool yes = j <= 1 || i % j == 0;
            Console.WriteLine(yes ? "YES" : "NO");
        }
    }
}


using System;
using System.Linq;

namespace _980A_pearls_and_links
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int countLinks = s.Count(x => x == '-');
            int countPearls = s.Count(x => x == 'o');
            Console.WriteLine(countPearls != 0 && countLinks % countPearls != 0? "NO" : "YES");

        }

    }
}


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

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s1=Console.ReadLine().Split(':');
            DateTime d1=new DateTime(int.Parse(s1[0]),int.Parse(s1[1]),int.Parse(s1[2]));
            string[] s2 = Console.ReadLine().Split(':');
            DateTime d2 = new DateTime(int.Parse(s2[0]), int.Parse(s2[1]), int.Parse(s2[2]));
            Console.WriteLine(Math.Abs((d2 - d1).Days));
        }
    }
}


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

namespace codeforces____calendar
{
    class Program
    {
        static void Main(string[] args)
        {
            string input;
            input = Console.ReadLine();
            String[] s = input.Split(':');
            int year = int.Parse(s[0]);
            int month = int.Parse(s[1]);
            int day = int.Parse(s[2]);
            DateTime start = new DateTime(year, month, day);
            input = Console.ReadLine();
            s = new String[3];
            s = input.Split(':');
            year = int.Parse(s[0]);
            month = int.Parse(s[1]);
            day = int.Parse(s[2]);
            DateTime enddate = new DateTime(year, month, day);
            TimeSpan result = enddate.Subtract(start);
            Console.WriteLine(Math.Abs(result.Days));
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.IO;
using System.Numerics;
using System.Globalization;
using System.Threading;

namespace probleme {
    class Program {
        static void Main(string[] args) {
            //Console.SetIn(new StreamReader("file.txt"));
            char[][]table = new char[8][];
            for (int i=0;i<8;i++){
                table[i] = Console.ReadLine().ToCharArray();
            }
            int minW = 9;
            for (int j = 0; j < 8; j++) {
                int minR = 9;
                bool free = true;
                for (int i = 7; i >= 0; i--) {
                    if (table[i][j] == 'B') {
                        free = false;
                    }
                    if (table[i][j] == 'W') {
                        minR = i;
                        free = true;
                    }
                }
                if (free && minR < minW) {
                    minW = minR;
                }
            }
            int minB = 9;
            for (int j = 0; j < 8; j++) {
                int minR = 9;
                bool free = true;
                for (int i = 0; i < 8; i++) {
                    if (table[i][j] == 'W') {
                        free = false;
                    }
                    if (table[i][j] == 'B') {
                        minR = 7 - i;
                        free = true;
                    }
                }
                if (free && minR < minB) {
                    minB = minR;
                }
            }
           // Console.Write("{0} {1}\n", minW, minB);
            if (minW <= minB) {
                Console.Write("A");
            } else {
                Console.Write("B");
            }
            //Console.ReadKey();
        }
    }
}


using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Threading;
using System.Diagnostics;
using System.Linq;

#region testlib
public delegate bool ParserDelegate<T>(string word, out T item);

public class Input : IDisposable
{
private static EventArgs DefaultEventArgs = new EventArgs();

public TextReader TextReader { get; private set; }

public event EventHandler OnEndOfStream;
public event EventHandler OnParseError;
public event EventHandler OnReadError;

public bool CanRead { get; private set; }
public bool ThrowExceptions { get; set; }

string line = string.Empty;
int pos = 0;

static EventHandler emptyHandler;

public Input(string path)
: this(File.OpenRead(path))
{
}
public Input(Stream s)
: this(new StreamReader(s))
{

}
public Input(TextReader tr)
{
TextReader = tr;

if (emptyHandler == null)
emptyHandler = (a, b) => { };

OnEndOfStream = emptyHandler;
OnParseError = emptyHandler;
OnReadError = emptyHandler;

CanRead = true;
}

public static implicit operator Input(Stream s)
{
return new Input(s);
}
public static implicit operator Input(TextReader tr)
{
return new Input(tr);
}

private bool ReadStream()
{
if (!CanRead) return false;
if (pos < line.Length) return true;

Clear();

string s = TextReader.ReadLine();
if (s == null)
{
CanRead = false;
return false;
}

line = s;
return true;
}

public void SkipChar()
{
if (pos < line.Length) pos++;
else
{
ReadStream();
}
}
public void SkipChars(int length)
{
while (length > 0)
{
int dt = line.Length - pos;
if (dt <= 0)
{
length--;
if (!ReadStream()) return;
}
dt = Math.Min(length, dt);
pos += dt;
length -= dt;
}
}

public void SkipWhiteSpace()
{
while (true)
{
for (; pos < line.Length; pos++)
{
if (!char.IsWhiteSpace(line[pos])) return;
}
if (!ReadStream())
{
OnEndOfStream(this, DefaultEventArgs);
return;
}
}
}
public bool CanReadData()
{
SkipWhiteSpace();
return CanRead;
}

public T[] ReadArray<T>()
{
int length = ReadInt32();
return ReadArray<T>(length);
}
public T[] ReadArray<T>(int length)
{
ParserDelegate<T> parser = Parser.GetPrimitiveParser<T>();
return ReadArray<T>(length, parser);
}
public T[] ReadArray<T>(ParserDelegate<T> parser)
{
int length = ReadInt32();
return ReadArray<T>(length, parser);
}
public T[] ReadArray<T>(int length, ParserDelegate<T> parser)
{
T[] res = new T[length];
for (int i = 0; i < length; i++)
{
res[i] = ReadData<T>(parser);
}
return res;
}

public Decimal ReadDecimal()
{
return ReadData<Decimal>(Parser.DecimalParser);
}
public Double ReadDouble()
{
return ReadData<Double>(Parser.DoubleParser);
}
public Single ReadSingle()
{
return ReadData<Single>(Parser.SingleParser);
}
public UInt64 ReadUInt64()
{
return ReadData<UInt64>(UInt64.TryParse);
}
public UInt32 ReadUInt32()
{
return ReadData<UInt32>(UInt32.TryParse);
}
public UInt16 ReadUInt16()
{
return ReadData<UInt16>(UInt16.TryParse);
}
public Int64 ReadInt64()
{
return ReadData<Int64>(Int64.TryParse);
}
public Int32 ReadInt32()
{
return ReadData<Int32>(Int32.TryParse);
}
public Int16 ReadInt16()
{
return ReadData<Int16>(Int16.TryParse);
}
public Boolean ReadYesNo()
{
return ReadData<Boolean>(Parser.YesNoParser);
}
public Boolean ReadBoolean()
{
return ReadData<Boolean>(Boolean.TryParse);
}
public Byte ReadByte()
{
return ReadData<Byte>(Byte.TryParse);
}

private bool ReadCheck()
{
if (!CanRead)
{
OnReadError(this, DefaultEventArgs);
if (ThrowExceptions)
{
throw new Exception("!CanRead");
}
return false;
}
return true;
}
public T ReadData<T>()
{
return ReadData<T>(true);
}
public T ReadData<T>(bool skipWhiteSpace)
{
ParserDelegate<T> parser = Parser.GetPrimitiveParser<T>();
return ReadData<T>(parser, skipWhiteSpace);
}
public T ReadData<T>(ParserDelegate<T> parser)
{
return ReadData<T>(parser, true);
}
public T ReadData<T>(ParserDelegate<T> parser, bool skipWhiteSpace)
{
if (skipWhiteSpace)
SkipWhiteSpace();

if (!ReadCheck()) return default(T);

string s = ReadWord(false);

T res;
if (!parser.Invoke(s, out res))
{
OnParseError(this, DefaultEventArgs);
if (ThrowExceptions)
{
throw new Exception("!validate, word = " + Output.ToString(s, 256));
}
}
return res;
}

public string ReadWord()
{
return ReadWord(true);
}
public string ReadWord(bool skipWhiteSpace)
{
if (skipWhiteSpace)
SkipWhiteSpace();

if (!ReadCheck()) return string.Empty;

int from = pos;
int to = pos;
for (int i = pos; i < line.Length; i++)
{
if (char.IsWhiteSpace(line[i])) break;
to = i + 1;
}
pos = to;

return line.Substring(from, to - from);
}

public string ReadLine()
{
if (!ReadCheck()) return string.Empty;

ReadStream();
string res = line.Substring(pos);
pos = line.Length;

return res;
}

public void Close()
{
TextReader.Close();
}
public void Clear()
{
pos = 0;
line = string.Empty;
}

private bool disposed = false;
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
if (!this.disposed)
{
if (disposing)
{
line = string.Empty;
TextReader.Dispose();
}
disposed = true;
}
}
~Input()
{
Dispose(false);
}
}
public class Output : IDisposable
{
static char[] space = new char[] { ' ' };

public TextWriter TextWriter { get; private set; }
public bool AutoFlush { get; set; }

public static string ToString(object obj, int maxLength)
{
return ToString(FormatReal(obj), maxLength);
}
public static string ToString(string s, int maxLength)
{
if (s.Length <= maxLength) return s;
else return s.Substring(0, maxLength) + "...";
}
public static object FormatReal(object v, string format)
{
if (v is decimal) return ((decimal)v).ToString(format).Replace(',', '.');
if (v is double) return ((double)v).ToString(format).Replace(',', '.');
if (v is float) return ((float)v).ToString(format).Replace(',', '.');

return v;
}
public static object FormatReal(object v)
{
if (v is decimal || v is double || v is float)
{
return v.ToString().Replace(',', '.');
}
return v;
}

public Output()
: this(new MemoryStream())
{
}
public Output(string path)
: this(File.Create(path))
{

}
public Output(Stream s)
: this(new StreamWriter(s))
{
}
public Output(TextWriter tw)
{
TextWriter = tw;
}

public static implicit operator Output(Stream s)
{
return new Output(s);
}

public static implicit operator Output(TextWriter tw)
{
return new Output(tw);
}

public static Output operator +(Output output, object obj)
{
output.Write(obj);
return output;
}
public Output WriteArray<T>(params T[] array)
{
return WriteArray<T>(array, false);
}
public Output WriteArray<T>(T[] array, bool appendLength)
{
return WriteArray<T>(array, 0, array.Length, appendLength);
}
public Output WriteArray<T>(T[] array, int index, int count)
{
return WriteArray<T>(array, index, count, false);
}
public Output WriteArray<T>(T[] array, int index, int count, bool appendLength)
{
if (index + count > array.Length)
{
string message = string.Format(
"Index out of range: {0} + {1} >= {2}",
index,
count,
array.Length);
throw new Exception(message);
}
if (appendLength)
{
WriteLine(count);
}
for (int i = 0; i < count; i++)
{
Write(array[i]);
Write(space, 0, space.Length);
}
WriteLine();

return this;
}
public Output WriteLine(object obj)
{
obj = FormatReal(obj);
return WriteLine(obj.ToString());
}
public Output WriteLine(string format, params object[] args)
{
return WriteLine(string.Format(format, args));
}
public Output WriteLine(string s)
{
return WriteLine(s.ToCharArray());
}
public Output WriteLine(char[] buffer)
{
return WriteLine(buffer, 0, buffer.Length);
}
public Output WriteLine(char[] buffer, int index, int count)
{
TextWriter.WriteLine(buffer, index, count);
if (AutoFlush) TextWriter.Flush();
return this;
}
public Output WriteLine()
{
TextWriter.WriteLine();
if (AutoFlush) TextWriter.Flush();
return this;
}
public Output Write(object obj)
{
obj = FormatReal(obj);
return Write(obj.ToString());
}
public Output Write(string format, params object[] args)
{
return Write(string.Format(format, args));
}
public Output Write(string s)
{
return Write(s.ToCharArray());
}
public Output Write(char[] buffer)
{
return Write(buffer, 0, buffer.Length);
}
public Output Write(char[] buffer, int index, int count)
{
TextWriter.Write(buffer, index, count);
if (AutoFlush) TextWriter.Flush();
return this;
}

public void Close()
{
TextWriter.Close();
}
public void Flush()
{
TextWriter.Flush();
}

private bool disposed = false;
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
if (!this.disposed)
{
if (disposing)
{
TextWriter.Dispose();
}
disposed = true;
}
}
~Output()
{
Dispose(false);
}
}
public static class Parser
{
public static ParserDelegate<T> GetPrimitiveParser<T>()
{
if (!typeof(T).IsPrimitive) throw new Exception("Unknown type");
else if (default(T) is Byte) return new ParserDelegate<Byte>(Byte.TryParse) as ParserDelegate<T>;
else if (default(T) is Boolean) return new ParserDelegate<Boolean>(Boolean.TryParse) as ParserDelegate<T>;
else if (default(T) is Int16) return new ParserDelegate<Int16>(Int16.TryParse) as ParserDelegate<T>;
else if (default(T) is Int32) return new ParserDelegate<Int32>(Int32.TryParse) as ParserDelegate<T>;
else if (default(T) is Int64) return new ParserDelegate<Int64>(Int64.TryParse) as ParserDelegate<T>;
else if (default(T) is UInt16) return new ParserDelegate<UInt16>(UInt16.TryParse) as ParserDelegate<T>;
else if (default(T) is UInt32) return new ParserDelegate<UInt32>(UInt32.TryParse) as ParserDelegate<T>;
else if (default(T) is UInt64) return new ParserDelegate<UInt64>(UInt64.TryParse) as ParserDelegate<T>;
else if (default(T) is Single) return new ParserDelegate<Single>(Parser.SingleParser) as ParserDelegate<T>;
else if (default(T) is Double) return new ParserDelegate<Double>(Parser.DoubleParser) as ParserDelegate<T>;
else if (default(T) is Decimal) return new ParserDelegate<Decimal>(Parser.DecimalParser) as ParserDelegate<T>;
else if (default(T) is String) return new ParserDelegate<String>(Parser.StringParser) as ParserDelegate<T>;
else throw new Exception("Unknown type");
}
public static bool YesNoParser(string s, out Boolean result)
{
s = s.ToLower();
if (s == "yes") result = true;
else if (s == "no") result = false;
else
{
result = false;
return false;
}
return true;
}
public static bool StringParser(string s, out string result)
{
result = s;
return string.IsNullOrEmpty(s);
}
public static bool DecimalParser(string s, out Decimal result)
{
return Decimal.TryParse(s.Replace('.', ','), out result);
}
public static bool DoubleParser(string s, out Double result)
{
return Double.TryParse(s.Replace('.', ','), out result);
}
public static bool SingleParser(string s, out Single result)
{
return Single.TryParse(s.Replace('.', ','), out result);
}
}
#endregion

class V : IComparable<V>
{
    public int Index;
    public int StartT;
    public int EndT;
    public int Count;

    public int CompareTo(V a)
    {
        var r = EndT.CompareTo(a.EndT);
        if (r == 0) r = Count.CompareTo(a.Count);
        if (r == 0) r = Index.CompareTo(a.Index);
        return r;
    }
}
static class Program
{
    #region Streams
    static string endl = Environment.NewLine;
    static Input cin = new Input(Console.In);
    static Output cout = new Output(Console.Out);
    static Output cerr = new Output(Console.Error);

    static void InitIO()
    {
#if !DEBUG
        cin = new Input("input.txt");
        cout = new Output("output.txt");
#endif
    }
    #endregion
    #region Time
    static Stopwatch sw = new Stopwatch();
    static void Start()
    {
        sw.Reset();
        sw.Start();
    }
    static void Restart(string text = "")
    {
        Stop(text);
        Start();
    }
    static void Time(string text = "")
    {
        if (string.IsNullOrEmpty(text))
        {
            cerr.WriteLine(sw.Elapsed);
        }
        else
        {
            cerr.WriteLine(text + ": " + sw.Elapsed);
        }
    }
    static void Stop(string text = "")
    {
        sw.Stop();
        Time(text);
    }
    //*/
    #endregion
    #region Prewriten
    static void Swap<T>(ref T a, ref T b)
    {
        T c = a;
        a = b;
        b = c;
    }
    static long Gcd(long a, long b)
    {
        while (a > 0)
        {
            b %= a;
            Swap(ref a, ref b);
        }
        return b;
    }
    static int[] ZFunction(string s)
    {
        var z = new int[s.Length];
        for (int i = 1, l = 0, r = 0; i < s.Length; ++i)
        {
            if (i <= r)
            {
                z[i] = Math.Min(r - i + 1, z[i - l]);
            }
            while (i + z[i] < s.Length && s[z[i]] == s[i + z[i]])
            {
                z[i]++;
            }
            if (i + z[i] - 1 > r)
            {
                l = i;
                r = i + z[i] - 1;
            }
        }
        return z;
    }
    static long Pow(long a, long p)
    {
        var b = 1L;
        while (p > 0)
        {
            if ((p & 1) == 0)
            {
                a *= a;
                p >>= 1;
            }
            else
            {
                b *= a;
                p--;
            }
        }
        return b;
    }
    #endregion
    const string nyan = "^_^";
    const string name = "canalization";
    const long mod = 1000000007;

    static int Find(string[] a, char x)
    {
        var blocked = new bool[8];
        for (var i = 0; i < 8; i++)
        {
            for (var j = 0; j < 8; j++)
            {
                if (a[i][j] == x && !blocked[j]) return i;
                if (a[i][j] != '.') blocked[j] = true;
            }
        }
        return -1;
    }
    static void Solve()
    {
        var a = new string[8];
        for (var i = 0; i < 8; i++) a[i] = cin.ReadWord().ToLower();

        var w = Find(a, 'w');
        var b = Find(a.Reverse().ToArray(), 'b');

        if (w <= b) cout.WriteLine("A");
        else cout.WriteLine("B");
    }

    static string[] Tests =
    {
        @"........
........
.B....B.
....W...
........
..W.....
........
........",
        @"..B.....
..W.....
......B.
........
.....W..
......B.
........
........"
    };

    static string Generate(int k, int n)
    {
        var sb = new StringWriter();
        var output = new Output(sb);

        output.WriteLine("{0} {1}", k, n);

        return sb.ToString();
    }
    static void Main()
    {
#if DEBUG
        if (Tests.Length == 0)
        {
            Solve();
        }
        else
        {
            foreach(var test in Tests)
            {
                cin = new Input(new StringReader(test));
                Start();
                Solve();
                Stop();
            }
            /*
            for (var i = 0; i <= 10; i++)
            {
                var test = Generate(1, i);
                Start();
                cin = new Input(new StringReader(test));
                Solve();
                Stop();
            }
            //*/
        }
#else
        /*
        cin = new Input(name + ".in");
        cout = new Output(name + ".out");
        //*/
        //Solve();

                var th = new Thread(Solve, 1024 * 1024 * 64);
                th.Start();
                th.Join();
        cout.Flush();
        cout.Dispose();
#endif
    }
}


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());
            int min, max;
            max = 0;
            min = 2200;
            int[] years = new int[n];
            int i = 0;
            foreach (string s in Console.ReadLine().Split())
            {
                years[i] = Convert.ToInt32(s);
                max = max <= years[i] ? years[i] : max;
                min = min >= years[i] ? years[i] : min;
                i++;
            }
            Console.WriteLine("{0}", (max + min) / 2);
        }
    }
}


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

namespace ConsoleApplication4
{
    class Program
    {
        static int[] readArray()
        {
            string[] s = Console.ReadLine().Split(' ');
            int len = s.Length;
            int[] data = new int[len];
            for (int i = 0; i < len; i++)
            {
                data[i] = int.Parse(s[i]);
            }
            return data;
        }
        static int readInt()
        {
            string s = Console.ReadLine();
            return int.Parse(s);
        }
        static void Main(string[] args)
        {
            int n = readInt();
            int[] data = readArray();
            int min = data[0];
            int max = data[0];
            for(int i = 1; i < n; i++)
            {
                min = Math.Min(data[i], min);
                max = Math.Max(data[i], max);
            }

            Console.Write((min + max) / 2);
        }
    }
}

//int[] h = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
//Array.Sort(data, (int a,int b) => a>b?-1:a==b?0:1);


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

namespace contest1
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.SetIn(new StreamReader("input.txt"));
            solve_482A();
        }

        public static void solve_482A()
        {
            long n = Convert.ToInt64(Console.ReadLine());

            long pieces = 0;
            if (n > 0)
            {
                long pizza = n + 1;
                if (pizza % 2 == 0)
                {
                    pieces = pizza / 2;
                }
                else
                {
                    pieces = pizza;
                }
            }
            Console.WriteLine(pieces);
        }
    }
}


// Problem: 979A - Pizza, Pizza, Pizza!!!
// Author: Gusztav Szmolik

using System;

class PizzaPizzaPizza
    {
    static int Main ()
        {
        string[] words = ReadSplitLine (1);
        if (words == null)
            return -1;
        ulong n;
        if (!UInt64.TryParse (words[0], out n))
            return -1;
        if (n > 1000000000000000000)
            return -1;
        ulong ans = (n > 0 ? (n%2 == 0 ? n+1 : (n+1)/2) : 0);
        Console.WriteLine (ans);
        return 0;
        }

    static string[] ReadSplitLine (uint numWordNeed)
        {
        string line = Console.ReadLine ();
        if (line == null)
            return null;
        char[] delims = new char[2] {' ', '\t'};
        string[] words = line.Split (delims,StringSplitOptions.RemoveEmptyEntries);
        return (words.Length == numWordNeed ? words : null);
        }
    }


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

namespace ярморка
{
    class Program
    {
        static string Reverse(string s)
        {
            string res = "";
            for (int i = 0; i < s.Length; i++)
            {
                res = s[i] + res;
            }

            return res;
        }
        static void Main(string[] args)
        {

            string[] input = Console.ReadLine().Split();
            int k = Convert.ToInt32(input[0]);
            UInt64 p = Convert.ToUInt64(input[1]);

            UInt64 sum = 0;

            for (int i = k; i >= 1; i--)
            {
                string s = Convert.ToString(i) + Reverse(Convert.ToString(i));

                sum += Convert.ToUInt64(s);
            }

            Console.WriteLine(sum % p);

        }
    }
}


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

namespace Codeforces.NET
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            string[] parts = line.Split(' ').ToArray();
            long k = int.Parse(parts[0]);
            long p = int.Parse(parts[1]);
            long nr = 1;
            long sol = 0;
            for (int i = 1; i<=k; i++)
            {
                long nrAux = nr;
                long aux = nr;
                while (aux != 0)
                {
                    nrAux = nrAux * 10 + aux % 10;
                    aux = aux / 10;
                }

                sol = (sol + nrAux) % p;
                nr++;
            }

            Console.WriteLine(sol);
            Console.ReadLine();
        }
    }
}


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

namespace Codeforces
{
    class A
    {
        public static void Main(string[] args)
        {
            A program = new A();
            string output = program.Go();
            if (output != null)
                Wl<string>(output);
        }

        private string Go()
        {
            int r1 = GetInt();
            int r2 = GetInt();
            int c1 = GetInt();
            int c2 = GetInt();
            int d1 = GetInt();
            int d2 = GetInt();

            int x2 = r1 + c1 - d2;
            if (x2 % 2 != 0) return "-1";

            int x = x2 / 2;
            int y = r1 - x;
            int z = c1 - x;
            int t = d1 - x;

            HashSet<int> s = new HashSet<int>();
            s.Add(x); s.Add(y);
            s.Add(z); s.Add(t);

            if (x + y != r1 || z + t != r2 || x + z != c1 || y + t != c2 || x + t != d1 || y + z != d2
                || s.Count != 4 || x < 1 || x > 9 || y < 1 || y > 9 || z < 1 || z > 9 || t < 1 || t > 9) return "-1";

            Wl<int>(new int[] { x, y });
            Wl<int>(new int[] { z, t });

            return null;
        }

        #region Template

        private IEnumerator<string> ioEnum;
        private string GetString()
        {
            while (ioEnum == null || !ioEnum.MoveNext())
            {
                ioEnum = Console.ReadLine().Split().AsEnumerable().GetEnumerator();
            }

            return ioEnum.Current;
        }

        private int GetInt()
        {
            return int.Parse(GetString());
        }

        private double GetDouble()
        {
            return double.Parse(GetString());
        }

        private static void Wl<T>(T o)
        {
            Console.WriteLine(o.ToString());
        }

        private static void Wl<T>(IEnumerable<T> enumerable)
        {
            Wl(string.Join(" ", enumerable.Select(e => e.ToString()).ToArray()));
        }

        public struct Tuple<T, K>
        {
            public T Item1;
            public K Item2;

            public Tuple(T t, K k)
            {
                Item1 = t;
                Item2 = k;
            }

            public override bool Equals(object obj)
            {
                var o = (Tuple<T, K>)obj;
                return o.Item1.Equals(Item1) && o.Item2.Equals(Item2);
            }

            public override int GetHashCode()
            {
                return Item1.GetHashCode() ^ Item2.GetHashCode();
            }
        }

        #endregion
    }
}


using System;
using System.Linq;

class Program
{
    static void Main()
    {
        var r = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var c = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var d = Console.ReadLine().Split().Select(int.Parse).ToArray();
        for (int i = 1; i <= 9; i++)
        {
            for (int j = 1; j <= 9; j++)
            {
                if (j == i) continue;
                for (int k = 1; k <= 9; k++)
                {
                    if (k == j || k == i) continue;
                    for (int m = 1; m <= 9; m++)
                    {
                        if (m == k || m == j || m == i) continue;
                        if (r[0] == i + j && r[1] == k + m && c[0] == i + k && c[1] == j + m
                            && d[0] == i + m && d[1] == j + k)
                        {
                            Console.WriteLine("{0} {1}", i, j);
                            Console.WriteLine("{0} {1}", k, m);
                            return;
                        }
                    }
                }
            }
        }
        Console.WriteLine(-1);
    }
}