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

// (づ°ω°)づﾐ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    int[] KMP(string s)
    {
        int n = s.Length;
        var pi = new int[n];
	    for (int i = 1; i < n; ++i)
        {
		    int j = pi[i - 1];
		    while (j > 0 && s[i] != s[j])
			    j = pi[j - 1];
		    if (s[i] == s[j])
                j++;
		    pi[i] = j;
	    }
	    return pi;
    }

    public object Solve()
    {
        string s1 = ReadToken();
        string s2 = ReadToken();
        string s3 = ReadToken();

        int n1 = s1.Length;
        int n2 = s2.Length;
        int n3 = s3.Length;

        var dp = new int[n1 + 1, n2 + 1, n3];
        var path = new Tuple<int, int, int, char>[n1 + 1, n2 + 1, n3];
        for (int i1 = 1; i1 <= n1; i1++)
            for (int i2 = 1; i2 <= n2; i2++)
                for (int i3 = 0; i3 < n3; i3++)
                {
                    if (s1[i1 - 1] == s2[i2 - 1])
                    {
                        if (s3[i3] == s1[i1 - 1])
                        {
                            if (i3 + 1 < n3)
                            {
                                dp[i1, i2, i3 + 1] = dp[i1 - 1, i2 - 1, i3] + 1;
                                path[i1, i2, i3 + 1] = Tuple.Create(i1 - 1, i2 - 1, i3, s1[i1 - 1]);
                            }
                        }
                        else
                        {
                            int jump = KMP(s3.Substring(0, i3) + s1[i1 - 1])[i3];
                            if (dp[i1 - 1, i2 - 1, i3] + 1 > dp[i1, i2, jump])
                            {
                                dp[i1, i2, jump] = dp[i1 - 1, i2 - 1, i3] + 1;
                                path[i1, i2, jump] = Tuple.Create(i1 - 1, i2 - 1, i3, s1[i1 - 1]);
                            }
                        }
                    }
                    if (dp[i1 - 1, i2, i3] >= dp[i1, i2, i3])
                    {
                        dp[i1, i2, i3] = dp[i1 - 1, i2, i3];
                        path[i1, i2, i3] = Tuple.Create(i1 - 1, i2, i3, (char)0);
                    }
                    if (dp[i1, i2 - 1, i3] >= dp[i1, i2, i3])
                    {
                        dp[i1, i2, i3] = dp[i1, i2 - 1, i3];
                        path[i1, i2, i3] = Tuple.Create(i1, i2 - 1, i3, (char)0);
                    }
                }

        int max = -1;
        int nmax = -1;
        for (int i = 0; i < n3; i++)
        {
            if (dp[n1, n2, i] > max)
            {
                max = dp[n1, n2, i];
                nmax = i;
            }
        }
        if (max == 0)
            return 0;

        var list = new List<char>();
        var c = Tuple.Create(n1, n2, nmax, (char)0);
        while (c.Item1 > 0 && c.Item2 > 0)
        {
            c = path[c.Item1, c.Item2, c.Item3];
            if (c.Item4 > 0)
                list.Add(c.Item4);
        }
        list.Reverse();

//        for (int i = 0; i < n3; i++)
//        {
//            for (int j = 0; j <= n1; j++)
//            {
//                for (int k = 0; k <= n2; k++)
//                {
//                    Console.Write(dp[j, k, i]);
//                }
//                Console.WriteLine();
//            }
//            Console.WriteLine("-----------");
//        }

        return new string(list.ToArray());
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;

    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
#endif
        try
        {
            var ts = DateTime.Now;
            object result = new Solver().Solve();
            if (result != null)
                writer.WriteLine(result);
        }
        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));
    }

    #endregion
}


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

namespace CodeForces.Solutions.c331_AbbyyCupFinal
{
	public class ProgramC
	{
		public static void Main()
		{
			checked
			{
			    var subs = new int[1000001];

			    for (int i = 1; i < subs.Length; i++)
			    {
			        subs[i] = int.MaxValue;
			        var tmp = i;
                    while (tmp > 0)
                    {
                        var d = tmp%10;
                        if (d != 0)
                            subs[i] = Math.Min(subs[i], subs[i - d] + 1);
                        tmp /= 10;
                    }
			    }

			    var n = long.Parse(Console.ReadLine());
			    Console.WriteLine(subs[n]);
			}
		}
	}
}


using System;
using System.Linq;
using System.Collections.Generic;
namespace Codeforces
{
    class Program
    {
        static void Main(string[] args)
        {
            UInt16 n = Convert.ToUInt16(Console.ReadLine());
            string a = new string(Console.ReadLine().Replace("4", "322").Replace("6", "53").Replace("8", "7222").Replace("9", "7332").OrderByDescending(c => c).ToArray()).TrimEnd('1', '0');
            Console.WriteLine(a);
            Console.ReadLine();
        }
    }
}


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

namespace Tlqkf_zheld_whdk
{
    class Program
    {
        static StringBuilder sb = new StringBuilder();
        static void Main(string[] args)
        {
            int num = int.Parse(Console.ReadLine());
            char[] str = Console.ReadLine().ToCharArray();

            char lst0 = 'a';
            char lst1 = 'a';

            for(int i =0; i<num; i++)
            {
                if(str[i] >= lst0)
                {
                    sb.Append(0);
                    lst0 = str[i];
                }else if(str[i] >= lst1)
                {
                    sb.Append(1);
                    lst1 = str[i];
                }
                else
                {
                    Console.WriteLine("NO");
                    return;
                }
            }

            Console.WriteLine("YES");
            Console.WriteLine(sb.ToString());
        }
    }
}


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            BigInteger a = BigInteger.Parse(s[0]);
            BigInteger b = BigInteger.Parse(s[1]);
            while (a != 0 && b!= 0) {
                if(a >= 2*b)
                {
                    a = a % (2 * b);
                }
                else if(b >= 2 * a)
                {
                    b = b % (2 * a);
                }
                else
                {
                    break;
                }
            }
            Console.WriteLine(a + " " + b);
            return;
        }
    }
}


using System;
using static System.Console;
using static System.Math;
using static System.Array;

//string[] a = ReadLine().Split(' ')
//int[] b = new int [a.Length]
/*for(int i=0;i<a.length;i++){
b[i] = Convert.ToInt32(a[i])
}*/
namespace ConsoleApp9
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = ReadLine().Split(' ');
            int n = Convert.ToInt32(s[0]);
            double k = Convert.ToInt64(s[1]);
            int[] b = new int[n];
            double summ = 0;
            int count = 0;
            s = ReadLine().Split(' ');
            for (int i = 0; i < n; i++)
            {
                b[i] = Convert.ToInt32(s[i]);
                summ += b[i];
            }
            double res = summ / n;
            while (res < k-0.5)
            {
                count++;
                summ += k;
                n++;
                res = summ / n;
            }
            WriteLine($"{count}");
        }

    }
}


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

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

        private static void Main(string[] args)
        {
            writer.WriteLine(Solve(args) ? "Yes" : "No");
            writer.Flush();
        }

        private static bool Solve(string[] args)
        {
            long n = Next();
            long k = Next();

            var h = new HashSet<long>();
            for (int i = 1; i <= k; i++)
            {
                if (!h.Add(n%i))
                    return false;
            }

            return true;
        }

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


using System;
public class Program
    {
        public static void Main(string[] args)
        {
            long l1, r1, l2, r2, k;
            {
                string[] input = Console.ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                l1 = long.Parse(input[0]);
                r1 = long.Parse(input[1]);
                l2 = long.Parse(input[2]);
                r2 = long.Parse(input[3]);
                k = long.Parse(input[4]);
            }
           if(r1<l2 || r2<l1) Console.WriteLine("0");
           else
           {
                l1 = Math.Max(l2, l1);
                r1 = Math.Min(r1, r2);
                l2 = r1 - l1+(k>=l1 && k<=r1?0:1);
                Console.WriteLine(l2);
           }
        }
    }


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

namespace ProgrammingContest.Codeforces.Round66
{
    class A
    {
        public static void Main()
        {
            var xs = Array.ConvertAll(Console.ReadLine().Split(' '), sss=>long.Parse(sss));
            long k = xs[3];
            Array.Sort(xs, 0, 3);
            long[] ys = new long[3];
            for (int i = 0; i < 3; i++)
            {
                ys[i] = 1 + Math.Min((k + 2-i) / (3-i), xs[i] - 1);
                k -= ys[i] - 1;
                //Console.WriteLine("{0} {1} {2}", k, i, ys[i]);
            }
            Console.WriteLine(ys[0]*ys[1]*ys[2]);
        }
    }
}


// Problem: 1085A - Right-Left Cipher
// Author: Gusztav Szmolik

using System;

class RightLeftCipher
	{
	static int Main ()
		{
		string line = Console.ReadLine ();
		if (line == null)
			return -1;
		char[] delims = {' ', '\t'};
		string[] words = line.Split (delims,StringSplitOptions.RemoveEmptyEntries);
		if (words.Length != 1)
			return -1;
		string t = words[0];
		byte tLength = Convert.ToByte (t.Length);
		if (tLength > 50)
			return -1;
		for (byte i = 0; i < tLength; i++)
			if (!Char.IsLower (t[i]))
				return -1;
		byte iBegin = Convert.ToByte (tLength%2 == 0 ? (tLength-2)/2 : (tLength-1)/2);
		sbyte offset = 0;
		for (byte i = 0; i < tLength; i++)
			{
			Console.Write (t[iBegin+offset]);
			offset = Convert.ToSByte (i%2 == 0 ? -offset+1 : -offset);
			}
		Console.WriteLine ();
		return 0;
		}
	}


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

namespace G4
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] Steps = new int[10];
            Steps[0] = 1;
            for (int i = 1; i < 10; i++)
            {
                Steps[i] = Steps[i - 1] * 10;
            }

            string sin = Console.ReadLine();
            char[] FO = new char[sin.Length];

            byte n = 97;
            for (int i = 0; i < sin.Length; i++)
            {
                if (((byte)sin[i] <= n) && (n < 123))
                {
                    FO[i] = (char)n;
                    n++;
                }
                else
                {
                    FO[i] = sin[i];
                }
            }

            if (n > 122)
            {
                Console.Write(buffer : FO);
            }
            else
            {
                Console.Write("-1");
            }
        }
    }
}


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

namespace ConsoleApp1
{

    class Program
    {

        static int mod(int a, int m)
        {
            return a < 0 ? a + m : a >= m ? a - m : a;
        }

        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
            int n = input[0], m = input[1];
            var g = new int[n + 1];
            var f = new int[n + 1];
            f[1] = 1;
            for(int i=2;i <= n; i++)
            {
                f[i] = i == 2 ? 2 : mod(mod(2*f[i - 1] + 1,m) + g[i],m);
                var mis = mod(f[i] - f[i - 1], m);
                for(int j = i+i; j <= n; j += i)
                {
                    g[j] = mod(g[j] + mis, m);
                }
            }
            Console.WriteLine(f[n]);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using System.Diagnostics;
using System.Numerics;
using static Template;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pi = Pair<int, int>;

class Solver
{
    public void Solve(Scanner sc)
    {
        int x, y, a, b;sc.Make(out x, out y, out a, out b);
        WriteLine(Max(Abs(x - a),Abs(y - b)));
    }
}

#region Template
public static class Template
{
    static void Main(string[] args)
    {
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        new Solver().Solve(new Scanner());
        Console.Out.Flush();
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) == 1) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) == -1) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static U Unify<T, U>(this T[] A, Func<U, T, U> f, U init = default(U)) { for (int i = 0; i < A.Length; i++) init = f(init, A[i]);return init; }
    public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); }
}

public class Scanner
{
    public string Str => Console.ReadLine().Trim();
    public int Int => int.Parse(Str);
    public long Long => long.Parse(Str);
    public double Double => double.Parse(Str);
    public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
    public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
    public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
    public int[] ArrInt1D(int n) => Create(n, () => Int);
    public long[] ArrLong1D(int n) => Create(n, () => Long);
    public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
    public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
    private Queue<string> q = new Queue<string>();
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); }
    public void Make<T1>(out T1 v1) => v1 = Next<T1>();
    public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); }
    public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); }
    public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); }
    public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); }
    public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); }
    //public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1, v2); }
    //public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2, out T3 v3); return (v1, v2, v3); }
    //public (T1, T2, T3, T4) Make<T1, T2, T3, T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, v3, v4); }
}
public class Pair<T1, T2> : IComparable<Pair<T1, T2>>
{
    public T1 v1;
    public T2 v2;
    public Pair() { }
    public Pair(T1 v1, T2 v2)
    { this.v1 = v1; this.v2 = v2; }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int CompareTo(Pair<T1, T2> p)
    {
        var c = Comparer<T1>.Default.Compare(v1, p.v1);
        if (c == 0)
            c = Comparer<T2>.Default.Compare(v2, p.v2);
        return c;
    }
    public override string ToString() => $"{v1.ToString()} {v2.ToString()}";
    public void Deconstruct(out T1 a, out T2 b) { a = v1; b = v2; }
}

public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>>
{
    public T3 v3;
    public Pair() : base() { }
    public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2)
    { this.v3 = v3; }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int CompareTo(Pair<T1, T2, T3> p)
    {
        var c = base.CompareTo(p);
        if (c == 0)
            c = Comparer<T3>.Default.Compare(v3, p.v3);
        return c;
    }
    public override string ToString() => $"{base.ToString()} {v3.ToString()}";
    public void Deconstruct(out T1 a, out T2 b, out T3 c) { Deconstruct(out a, out b); c = v3; }
}
#endregion


using System;
using System.Linq;
using CompLib.Util;

public class Program
{
    int N, M;
    int[] K;
    int[] D, T;
    int[] index;
    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        M = sc.NextInt();
        K = sc.IntArray();
        D = new int[M];
        T = new int[M];
        for (int i = 0; i < M; i++)
        {
            D[i] = sc.NextInt();
            T[i] = sc.NextInt() - 1;
        }
        index = new int[M];
        for (int i = 0; i < M; i++)
        {
            index[i] = i;
        }

        Array.Sort(index, (l, r) => D[l].CompareTo(D[r]));

        // n種類ある
        // 毎日1獲得
        // 通常2 セール中は1支払えば買える
        // 種類iを丁度k[i]個買う
        // 毎日0個以上注文できる
        // 種類t[j]はd[j]日にセール

        //
        int ng = -1;
        int ok = 400000;
        while (ok - ng > 1)
        {
            int mid = (ok + ng) / 2;
            if (C(mid)) ok = mid;
            else ng = mid;
        }

        Console.WriteLine(ok);
    }

    // day日に達成できるか?
    bool C(int day)
    {
        // 区間内セール
        // 種類ごと一番最後
        // 前から

        int[] s = new int[N];
        for (int i = 0; i < N; i++)
        {
            s[i] = int.MaxValue;
        }

        for (int i = 0; i < M; i++)
        {
            if (D[index[i]] <= day)
            {
                s[T[index[i]]] = D[index[i]];
            }
        }

        var tmp = new int[N];
        for (int i = 0; i < N; i++)
        {
            tmp[i] = i;
        }
        Array.Sort(tmp, (l, r) => s[l].CompareTo(s[r]));
        //if (day == 8)
        //{
        //    Console.WriteLine("-----");
        //    Console.WriteLine(day);
        //    Console.WriteLine(string.Join(" ", s));
        //    Console.WriteLine(string.Join(" ", tmp));
        //}
        int nokori = 0;
        int m = 0;
        int p = 0;
        for (int i = 0; i < N; i++)
        {
            if (s[tmp[i]] == int.MaxValue)
            {
                nokori += K[tmp[i]];
            }
            else
            {
                // 買える分
                // s[i] - m

                int tt = Math.Min(K[tmp[i]], s[tmp[i]] - m);
                p += tt;
                m += tt;
                nokori += K[tmp[i]] - tt;
                //if (day == 8)
                //{
                //    Console.WriteLine($"{tmp[i]} {tt} {m}");
                //}
            }
        }
        //if(day == 8)
        //{
        //    Console.WriteLine("aaaa" + m);
        //}
        return nokori * 2 <= day - m;
    }

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

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

namespace prob1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, d;
            string[] str1 = Console.ReadLine().Split(' ');
            n = Convert.ToInt32(str1[0]);
            d = Convert.ToInt32(str1[1]);

            int[] a = new int[n];
            string[] str3=Console.ReadLine().Split(' ');
            for (int i = 0; i < n; i++)
                a[i] = Convert.ToInt32(str3[i]);
            int m = Convert.ToInt32(Console.ReadLine());
            int sum=0;
            int res = 0;
            Array.Sort(a);
            if (m <= n)
            {
                for (int i = 0; i < m; i++)
                    sum += a[i];
                res = sum;
            }
            else
            {
                for (int i = 0; i < n; i++)
                    sum += a[i];

                res = sum + ((n - m) * d);
            }
            Console.WriteLine(res);
            Console.ReadLine();
        }
    }
}


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

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

            List<int> lst = new List<int>();
            int[] inp = new int[3];
            string[] inp1 = Console.ReadLine().Split();
            inp[0] = Int32.Parse(inp1[0]);
            inp[1] = Int32.Parse(inp1[1]);
            inp[2] = Int32.Parse(inp1[2]);

            lst.Add((inp[0] + inp[1]) * 2);
            lst.Add((inp[1] + inp[2]) * 2);
            lst.Add((inp[0] + inp[2]) * 2);
            lst.Add(inp[0] + inp[2] + inp[1]);

            lst.Sort();

            Console.WriteLine(lst[0]);
        }
    }
}


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

namespace Test
{
    class IOHelper : IDisposable
    {
        StreamReader reader;
        StreamWriter writer;

        public IOHelper(string inputFile, string outputFile, Encoding encoding)
        {
            StreamReader iReader;
            StreamWriter oWriter;
            if (inputFile == null)
                iReader = new StreamReader(Console.OpenStandardInput(), encoding);
            else
                iReader = new StreamReader(inputFile, encoding);

            if (outputFile == null)
                oWriter = new StreamWriter(Console.OpenStandardOutput(), encoding);
            else
                oWriter = new StreamWriter(outputFile, false, encoding);

            reader = iReader;
            writer = oWriter;

            curLine = new string[] { };
            curTokenIdx = 0;
        }

        string[] curLine;
        int curTokenIdx;

        char[] whiteSpaces = new char[] { ' ', '\t', '\r', '\n' };

        public string ReadNextToken()
        {
            if (curTokenIdx >= curLine.Length)
            {
                //Read next line
                string line = reader.ReadLine();
                if (line != null)
                    curLine = line.Split(whiteSpaces, StringSplitOptions.RemoveEmptyEntries);
                else
                    curLine = new string[] { };
                curTokenIdx = 0;
            }

            if (curTokenIdx >= curLine.Length)
                return null;

            return curLine[curTokenIdx++];
        }

        public int ReadNextInt()
        {
            return int.Parse(ReadNextToken());
        }

        public double ReadNextDouble()
        {
            var nextToken = ReadNextToken();
            var result = 0.0;
            nextToken = nextToken.Replace(".", System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator);
            result = double.Parse(nextToken);
            return result;
        }

        public void Write(string stringToWrite)
        {
            writer.Write(stringToWrite);
        }

        public void WriteLine(string stringToWrite)
        {
            writer.WriteLine(stringToWrite);
        }

        public void WriteLine(double valueToWrite)
        {
            long intPart = (long)valueToWrite;
            double fracPart = valueToWrite - intPart;
            var fracPartStr = fracPart.ToString("F8");
            if (fracPartStr.Length > 1)
                fracPartStr = fracPartStr.Substring(2);
            var strToWrite = string.Format("{0}.{1}", intPart, fracPartStr);
            writer.WriteLine(strToWrite);
        }

        public void Dispose()
        {
            try
            {
                if (reader != null)
                {
                    reader.Dispose();
                }
                if (writer != null)
                {
                    writer.Dispose();
                }
            }
            catch { };
        }

        public void Flush()
        {
            if (writer != null)
            {
                writer.Flush();
            }
        }
    }

    class Program
    {
        protected IOHelper ioHelper;

        int w, h;
        int u1, d1;
        int u2, d2;

        public void Solve()
        {
            w = ioHelper.ReadNextInt();
            h = ioHelper.ReadNextInt();
            u1 = ioHelper.ReadNextInt();
            d1 = ioHelper.ReadNextInt();
            u2 = ioHelper.ReadNextInt();
            d2 = ioHelper.ReadNextInt();

            int i=h;

            while (i > 0)
            {
                w += i;
                if (i == d1)
                    w -= u1;
                if (i == d2)
                    w -= u2;
                if (w < 0)
                    w = 0;
                i--;
            }

            ioHelper.WriteLine(w.ToString());
            ioHelper.Flush();

            //Console.ReadKey();
        }

        public Program(string inputFile, string outputFile)
        {
            ioHelper = new IOHelper(inputFile, outputFile, Encoding.Default);
            Solve();
            ioHelper.Dispose();
        }

        static void Main(string[] args)
        {
            Program myProgram = new Program(null, null);
        }
    }
}


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

class Modular
{
    private const int M = 998244353;
    private long value;
    public Modular(long value) { this.value = value; }
    public static implicit operator Modular(long a)
    {
        var m = a % M;
        return new Modular((m < 0) ? m + M : m);
    }
    public static Modular operator +(Modular a, Modular b)
    {
        return a.value + b.value;
    }
    public static Modular operator -(Modular a, Modular b)
    {
        return a.value - b.value;
    }
    public static Modular operator *(Modular a, Modular b)
    {
        return a.value * b.value;
    }
    public static Modular Pow(Modular a, int n)
    {
        switch (n)
        {
            case 0:
                return 1;
            case 1:
                return a;
            default:
                var p = Pow(a, n / 2);
                return p * p * Pow(a, n % 2);
        }
    }
    public static Modular operator /(Modular a, Modular b)
    {
        return a * Pow(b, M - 2);
    }
    private static readonly List<int> facs = new List<int> { 1 };
    public static Modular Fac(int n)
    {
        for (int i = facs.Count; i <= n; ++i)
        {
            facs.Add((int)(Math.BigMul(facs.Last(), i) % M));
        }
        return facs[n];
    }
    public static Modular Ncr(int n, int r)
    {
        return (n < r) ? 0
        : (n == r) ? 1
        : Fac(n) / (Fac(r) * Fac(n - r));
    }
    public static explicit operator int(Modular a)
    {
        return (int)a.value;
    }
}

class MyClass
{
    public static void Solve()
    {
        var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
        Modular n = input[0];
        Modular m = input[1];
        var k = input[2];
        if (input[0] == 1)
        {
            Console.WriteLine((int)Modular.Pow(n, k));
            return;
        }
        var dp = new Modular[k + 1];
        var poly = new Modular[k + 1];
        for (int i = 0; i < k + 1; i++)
        {
            poly[i] = 0;
        }
        poly[1] = 1;
        for (int i = 1; i < k + 1; i++)
        {
            var num = Modular.Pow(1 / m, i);
            for (int j = 0; j < i; j++)
            {
                num *= n - j;
            }
            for (int j = 1; j < i; j++)
            {
                num -= poly[j] * dp[j];
            }
            dp[i] = num;
            if (i == k)
            {
                break;
            }
            poly[i + 1] = 1;
            for (int j = i; j >= 1; j--)
            {
                poly[j] = -i * poly[j] + poly[j - 1];
            }
        }
        Console.WriteLine((int)dp[k]);
    }

    public static void Main()
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
    }
}


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

class Program
{
    static void Main(string[] args)
    {
        int n = RI();
        int m = RI();
        int k = RI() - 1;

        int row = 1 + (k / (2 * m));
        k %= (2 * m);
        int col = 1 + (k / 2);
        k %= 2;

        Console.WriteLine(row + " " + col + " " + ((k == 1) ? "R" : "L"));
    }

    private const int Mod = 1000000000 + 7;

    #region Data Read
    private static char ReadSign()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if (ans == '+' || ans == '-' || ans == '?')
                return (char)ans;
        }
    }

    private static long GCD(long a, long b)
    {
        if (a % b == 0) return b;
        return GCD(b, a % b);
    }

    private static List<int>[] ReadGraph(int n, int m)
    {
        List<int>[] g = new List<int>[n];
        for (int i = 0; i < g.Length; i++) g[i] = new List<int>();
        for (int i = 0; i < m; i++)
        {
            int a = RI() - 1;
            int b = RI() - 1;

            g[a].Add(b);
            g[b].Add(a);
        }

        return g;
    }

    private static int[,] ReadGraphAsMatrix(int n, int m)
    {
        int[,] matrix = new int[n + 1, n + 1];
        for (int i = 0; i < m; i++)
        {
            int a = RI();
            int b = RI();
            matrix[a, b] = matrix[b, a] = 1;
        }

        return matrix;
    }

    private static void Sort(ref int a, ref int b)
    {
        if (a > b) Swap(ref a, ref b);
    }

    private static void Swap(ref int a, ref int b)
    {
        int tmp = a;
        a = b;
        b = tmp;
    }

    private const int BufferSize = 1 << 16;
    private static StreamReader consoleReader;
    private static MemoryStream testData;

    private static int RI()
    {
        int ans = 0;
        int mul = 1;
        do
        {
            ans = consoleReader.Read();
            if (ans == -1)
                return 0;
            if (ans == '-') mul = -1;
        } while (ans < '0' || ans > '9');

        ans -= '0';
        while (true)
        {
            int chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans * mul;
            ans = ans * 10 + chr - '0';
        }
    }

    private static ulong RUL()
    {
        ulong ans = 0;
        int chr;
        do
        {
            chr = consoleReader.Read();
            if (chr == -1)
                return 0;
        } while (chr < '0' || chr > '9');

        ans = (uint)(chr - '0');
        while (true)
        {
            chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans;
            ans = ans * 10 + (uint)(chr - '0');
        }
    }

    private static long RL()
    {
        long ans = 0;
        int mul = 1;
        do
        {
            ans = consoleReader.Read();
            if (ans == -1)
                return 0;
            if (ans == '-') mul = -1;
        } while (ans < '0' || ans > '9');

        ans -= '0';
        while (true)
        {
            int chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans * mul;
            ans = ans * 10 + chr - '0';
        }
    }

    private static int[] RIA(int n)
    {
        int[] ans = new int[n];
        for (int i = 0; i < n; i++)
            ans[i] = RI();
        return ans;
    }

    private static long[] RLA(int n)
    {
        long[] ans = new long[n];
        for (int i = 0; i < n; i++)
            ans[i] = RL();
        return ans;
    }

    private static char[] ReadWord()
    {
        int ans;

        do
        {
            ans = consoleReader.Read();
        } while (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')));

        List<char> s = new List<char>();
        do
        {
            s.Add((char)ans);
            ans = consoleReader.Read();
        } while ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'));

        return s.ToArray();
    }

    private static char[] ReadString(int n)
    {
        int ans;

        do
        {
            ans = consoleReader.Read();
        } while (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')));

        char[] s = new char[n];
        int pos = 0;
        do
        {
            s[pos++] = (char)ans;
            if (pos == n) break;
            ans = consoleReader.Read();
        } while ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'));

        return s;
    }

    private static char[] ReadStringLine()
    {
        int ans;

        do
        {
            ans = consoleReader.Read();
        } while (ans == 10 || ans == 13);

        List<char> s = new List<char>();

        do
        {
            s.Add((char)ans);
            ans = consoleReader.Read();
        } while (ans != 10 && ans != 13 && ans != -1);

        return s.ToArray();
    }

    private static char ReadLetter()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'))
                return (char)ans;
        }
    }
    private static char ReadNonLetter()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')))
                return (char)ans;
        }
    }

    private static char ReadAnyOf(IEnumerable<char> allowed)
    {
        while (true)
        {
            char ans = (char)consoleReader.Read();
            if (allowed.Contains(ans))
                return ans;
        }
    }

    private static char ReadDigit()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if (ans >= '0' && ans <= '9')
                return (char)ans;
        }
    }

    private static int ReadDigitInt()
    {
        return ReadDigit() - (int)'0';
    }

    private static char ReadAnyChar()
    {
        return (char)consoleReader.Read();
    }

    private static string DoubleToString(double x)
    {
        return x.ToString(CultureInfo.InvariantCulture);
    }

    private static double DoubleFromString(string x)
    {
        return double.Parse(x, CultureInfo.InvariantCulture);
    }

    static Program()
    {
        //Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
        consoleReader = new StreamReader(Console.OpenStandardInput(BufferSize), Encoding.ASCII, false, BufferSize);
    }

    private static void PushTestData(StringBuilder sb)
    {
        PushTestData(sb.ToString());
    }
    private static void PushTestData(string data)
    {
#if TOLYAN_TEST
        if (testData == null)
        {
            testData = new MemoryStream();
            consoleReader = new StreamReader(testData);
        }

        var pos = testData.Position;
        var bytes = Encoding.UTF8.GetBytes(data);
        testData.Write(bytes, 0, bytes.Length);
        testData.Flush();
        testData.Position = pos;
#endif
    }
    #endregion
}


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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){

		int cnt=0;
		while(true){
			int idx=0;
			int max=A[0];
			for(int i=1;i<N;i++){
				if(max<=A[i]){
					max=A[i];
					idx=i;
				}
			}
			if(idx==0)break;
			A[0]++;
			A[idx]--;
			cnt++;
		}
		//Console.WriteLine(String.Join(" ",A));
		Console.WriteLine(cnt);
	}
	int N;
	int[] A;
	public Sol(){
		N=ri();
		A=ria();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(){return Console.ReadLine().Split(' ');}
	static int[] ria(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));}
	static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));}
	static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));}
}


using System;
using System.Collections.Generic;
using System.Linq;
using Solver.Ex;
using Watch = System.Diagnostics.Stopwatch;
using StringBuilder = System.Text.StringBuilder;
namespace Solver
{

    public class Solver
    {
        public void Solve()
        {
            var n = sc.Long();
            var m = sc.Long();
            var k = (n % m == 0) ? 0 : 1;
            var max = (n - m + 1) * (n - m) / 2;
            var min = (n % m) * ((n / m + k) * ((n / m) + k - 1) / 2)
                + ((m - (n % m)) * (n / m) * ((n / m) - 1) / 2);
            IO.Printer.Out.PrintLine(new long[] { min, max });
        }
        internal IO.StreamScanner sc;
    }

    #region Main and Settings
    static class Program
    {
        static void Main(string[] arg)
        {
#if DEBUG
            var errStream = new System.IO.FileStream(@"..\..\dbg.out", System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite);
            System.Diagnostics.Debug.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(errStream, "debugStream"));
            System.Diagnostics.Debug.AutoFlush = false;
            var sw = new Watch();
            sw.Start();
            try
            {
#endif
                var solver = new Solver();
                solver.sc = new IO.StreamScanner(Console.OpenStandardInput());
                IO.Printer.Out = new IO.Printer(new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
                solver.Solve();
                IO.Printer.Out.Flush();
#if DEBUG
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
                Console.Error.WriteLine(ex.StackTrace);
            }
            finally
            {
                sw.Stop();
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Error.WriteLine("Time:{0}ms", sw.ElapsedMilliseconds);
                System.Diagnostics.Debug.Close();
                System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
            }
#endif
        }

    }
    #endregion
}
#region IO Helper
namespace Solver.IO
{
    public class Printer
    {
        static Printer()
        {
            Out = new Printer(Console.Out);
        }
        public static Printer Out { get; set; }
        private readonly System.IO.TextWriter writer;
        private readonly System.Globalization.CultureInfo info;
        public string Separator { get; set; }
        public string NewLine { get { return writer.NewLine; } set { writer.NewLine = value ?? "\n"; } }
        public Printer(System.IO.TextWriter tw = null, System.Globalization.CultureInfo ci = null, string separator = null, string newLine = null)
        {
            writer = tw ?? System.IO.TextWriter.Null;
            info = ci ?? System.Globalization.CultureInfo.InvariantCulture;
            NewLine = newLine;
            Separator = separator ?? " ";
        }
        public void Print(int num) { writer.Write(num.ToString(info)); }
        public void Print(int num, string format) { writer.Write(num.ToString(format, info)); }
        public void Print(long num) { writer.Write(num.ToString(info)); }
        public void Print(long num, string format) { writer.Write(num.ToString(format, info)); }
        public void Print(double num) { writer.Write(num.ToString("F12", info)); }
        public void Print(double num, string format) { writer.Write(num.ToString(format, info)); }
        public void Print(string str) { writer.Write(str); }
        public void Print(string format, params object[] arg) { writer.Write(string.Format(info, format, arg)); }
        public void Print<T>(string format, IEnumerable<T> sources) { writer.Write(format, sources.OfType<object>().ToArray()); }
        public void Print(IEnumerable<char> sources) { writer.Write(sources.AsString()); }
        public void Print<T>(IEnumerable<T> sources)
        {
            var res = new System.Text.StringBuilder();
            foreach (var x in sources)
            {
                res.AppendFormat(info, "{0}", x);
                if (string.IsNullOrEmpty(Separator))
                    res.Append(Separator);
            }
            writer.Write(res.ToString(0, res.Length - Separator.Length));
        }
        public void PrintLine() { writer.WriteLine(); }
        public void PrintLine(int num) { writer.WriteLine(num.ToString(info)); }
        public void PrintLine(int num, string format) { writer.WriteLine(num.ToString(format, info)); }
        public void PrintLine(long num) { writer.WriteLine(num.ToString(info)); }
        public void PrintLine(long num, string format) { writer.WriteLine(num.ToString(format, info)); }
        public void PrintLine(double num) { writer.WriteLine(num.ToString("F12", info)); }
        public void PrintLine(double num, string format) { writer.WriteLine(num.ToString(format, info)); }
        public void PrintLine(string str) { writer.WriteLine(str); }
        public void PrintLine(string format, params object[] arg) { writer.WriteLine(string.Format(info, format, arg)); }
        public void PrintLine<T>(string format, IEnumerable<T> sources) { writer.WriteLine(format, sources.OfType<object>().ToArray()); }
        public void PrintLine<T>(IEnumerable<T> sources)
        {
            var res = new StringBuilder();
            foreach (var x in sources)
            {
                res.AppendFormat(info, "{0}", x);
                if (!string.IsNullOrEmpty(Separator))
                    res.Append(Separator);
            }
            writer.WriteLine(res.ToString(0, res.Length - Separator.Length));
        }
        public void Flush() { writer.Flush(); }
    }
    public class StreamScanner
    {
        public StreamScanner(System.IO.Stream stream)
        {
            iStream = stream;
        }
        private readonly System.IO.Stream iStream;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        private bool eof = false;
        public bool EndOfStream { get { return eof; } }
        private byte readByte()
        {
            if (eof) throw new System.IO.EndOfStreamException();
            if (ptr >= len)
            {
                ptr = 0;
                len = iStream.Read(buf, 0, 1024);
                if (len <= 0)
                {
                    eof = true;
                    return 0;
                }
            }
            return buf[ptr++];
        }
        private bool inSpan(byte c)
        {
            const byte lb = 33, ub = 126;
            return !(c >= lb && c <= ub);
        }
        private byte skip()
        {
            byte b = 0;
            do b = readByte();
            while (!eof && inSpan(b));
            return b;
        }
        public char Char()
        {
            return (char)skip();
        }
        public char[] Char(int n)
        {
            var a = new char[n];
            for (int i = 0; i < n; i++)
                a[i] = (char)skip();
            return a;
        }
        public char[][] Char(int n, int m)
        {
            var a = new char[n][];
            for (int i = 0; i < n; i++)
                a[i] = Char(m);
            return a;
        }
        public string Scan()
        {

            const byte lb = 33, ub = 126;
            if (eof) throw new System.IO.EndOfStreamException();

            do
            {
                while (ptr < len && (buf[ptr] < lb || ub < buf[ptr]))
                {
                    ptr++;
                }
                if (ptr < len)
                    break;
                ptr = 0;
                len = iStream.Read(buf, 0, 1024);
                if (len <= 0)
                {
                    eof = true;
                    return null;
                }
                continue;
            } while (true);

            StringBuilder sb = null;
            do
            {
                var i = ptr;
                while (i < len)
                {
                    if (buf[i] < lb || ub < buf[i])
                    {
                        string s;
                        if (sb != null)
                        {
                            sb.Append(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i - ptr));
                            s = sb.ToString();
                        }
                        else s = new string(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i - ptr));
                        ptr = i + 1;
                        return s;
                    }
                    i++;
                }
                i = len - ptr;
                if (sb == null) sb = new StringBuilder(i + 32);
                sb.Append(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i));
                ptr = 0;
            } while ((len = iStream.Read(buf, 0, 1024)) > 0);
            eof = true;
            return sb.ToString();
        }
        public string[] Scan(int n)
        {
            var a = new string[n];
            for (int i = 0; i < n; i++)
                a[i] = Scan();
            return a;
        }
        public string ScanLine()
        {
            const byte el = 10, cr = 13;
            if (eof) throw new System.IO.EndOfStreamException();
            StringBuilder sb = null;
            do
            {
                var i = ptr;
                while (i < len)
                {
                    if (buf[i] == cr || buf[i] == el)
                    {
                        string s;
                        if (sb != null)
                        {
                            sb.Append(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i - ptr));
                            s = sb.ToString();
                        }
                        else s = new string(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i - ptr));
                        if (buf[i] == cr) i++;
                        if (buf[i] == el) i++;
                        ptr = i;
                        return s;
                    }
                    i++;
                }
                i = len - ptr;
                if (sb == null) sb = new StringBuilder(i + 32);
                sb.Append(System.Text.UTF8Encoding.Default.GetChars(buf, ptr, i));
                ptr = 0;
            } while ((len = iStream.Read(buf, 0, 1024)) > 0);
            eof = true;
            return sb.ToString();
        }
        public double Double()
        {
            return double.Parse(Scan(), System.Globalization.CultureInfo.InvariantCulture);
        }
        public double[] Double(int n)
        {
            var a = new double[n];
            for (int i = 0; i < n; i++)
                a[i] = Double();
            return a;
        }
        public int Integer()
        {
            var ret = 0;
            byte b = 0;
            bool isMynus = false;
            const byte zero = 48, nine = 57, mynus = 45;
            do b = readByte();
            while (!eof && !((b >= zero && b <= nine) || b == mynus));

            if (b == mynus)
            {
                isMynus = true;
                b = readByte();
            }
            while (true)
            {
                if (b >= zero && b <= nine)
                {
                    ret = ret * 10 + b - zero;
                }
                else return isMynus ? -ret : ret;
                b = readByte();
            }

        }
        public int[] Integer(int n)
        {
            var a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = Integer();
            return a;
        }
        public long Long()
        {
            long ret = 0;
            byte b = 0;
            bool isMynus = false;
            const byte zero = 48, nine = 57, mynus = 45;
            do b = readByte();
            while (!eof && !((b >= zero && b <= nine) || b == mynus));
            if (b == '-')
            {
                isMynus = true;
                b = readByte();
            }
            while (true)
            {
                if (b >= zero && b <= nine)
                    ret = ret * 10 + (b - zero);
                else return isMynus ? -ret : ret;
                b = readByte();
            }

        }
        public long[] Long(int n)
        {
            var a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = Long();
            return a;
        }
        public void Flush()
        {
            iStream.Flush();
        }

    }

}
#endregion
#region Extension
namespace Solver.Ex
{
    static public partial class EnumerableEx
    {
        static public string AsString(this IEnumerable<char> source)
        {
            return new string(source.ToArray());
        }
        static public string AsJoinedString<T>(this IEnumerable<T> source, string separator = " ")
        {
            return string.Join(separator, source);
        }
        static public T[] Enumerate<T>(this int n, Func<int, T> selector)
        {
            var res = new T[n];
            for (int i = 0; i < n; i++)
                res[i] = selector(i);
            return res;
        }
    }
}
#endregion


using System;
 class Program
    {
        public static void Main(string[] args)
        {
            string input = Console.In.ReadToEnd().Split(new char[] { ' ', '\t', '\n', '\r'}, StringSplitOptions.RemoveEmptyEntries)[1];
            int res = 0, curr=0, lg=1;
            for(int i = input.Length-1; i>-1; --i)
            {
                if (input[i] == '1') curr++;
                else { res += curr * lg; lg *= 10; curr = 0; }
            }
            Console.WriteLine(res += curr * lg);
        }
    }


using System;

class Program
{
    static void Main(string[] args)
    {
        int n, m;
        string[] input = Console.ReadLine().Split(' ');
        n = int.Parse(input[0]);
        m = int.Parse(input[1]);
        int min = Math.Min(n, m);
        int max = n + m - min;
        int ans1 = max - 1;
        int ans2 = (min % 2 == 0 ? min : (min / 2) * 2 + 1);
        Console.WriteLine(ans1 + " " + ans2);
        Console.ReadLine();
    }
}


#if DEBUG
using System.Reflection;
using System.Threading.Tasks;
#endif

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

namespace _208a
{
    class Program
    {
        static string _inputFilename = "input.txt";
        static string _outputFilename = "output.txt";
        static bool _useFileInput = false;

        static void Main(string[] args)
        {
            StreamWriter file = null;
#if DEBUG
			Console.SetIn(getInput());
#else
            if (_useFileInput)
            {
                Console.SetIn(File.OpenText(_inputFilename));
                file = new StreamWriter(_outputFilename);
                Console.SetOut(file);
            }
#endif

            try
            {
                solution();
            }
            finally
            {
                if (_useFileInput)
                {
                    file.Close();
                }
            }
        }

        static void solution()
        {
            #region SOLUTION
            var n = readInt();
            var a = readIntArray();
            var can = true;
            for (int i = 0; i < n - 1; i++)
            {
                var next = a[i];
                var end = a[i + 1];
                if (end < next)
                {
                    var t = next;
                    next = end;
                    end = t;
                }

                for (int j = i - 1; j >= 1; j--)
                {
                    var prev = a[j];
                    var ps = a[j - 1];
                    if (ps > prev)
                    {
                        var t = prev;
                        prev = ps;
                        ps = t;
                    }

                    if (prev > next && prev < end && ps < next)
                    {
                        can = false;
                        break;
                    }

                    if (ps > next && ps < end && prev > end)
                    {
                        can = false;
                        break;
                    }
                }

                if (!can)
                {
                    break;
                }
            }

            if (can)
            {
                Console.WriteLine("no");
            }
            else
            {
                Console.WriteLine("yes");
            }

            //var n = readInt();
            //var m = readInt();

            //var a = readIntArray();
            //var b = readIntArray();
            #endregion
        }

        static int readInt()
        {
            return int.Parse(Console.ReadLine());
        }

        static long readLong()
        {
            return long.Parse(Console.ReadLine());
        }

        static int[] readIntArray()
        {
            return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => int.Parse(i)).ToArray();
        }

        static long[] readLongArray()
        {
            return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => long.Parse(i)).ToArray();
        }

#if DEBUG
		static StreamReader getInput()
		{
			var resName = Assembly.GetCallingAssembly().GetManifestResourceNames()[0];
			var resource = Assembly.GetCallingAssembly().GetManifestResourceStream(resName);

			return new StreamReader(resource);
		}
#endif
    }
}


using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] nm = Console.ReadLine().Split().Select(t => Convert.ToInt32(t)).ToArray();
            (int n, int m) = (nm[0], nm[1]);
            int res = 1;
            if (m > 0)
                res = n / m >= 2 ? m : n - m;
            Console.WriteLine(res);
        }
    }
}


using System;

namespace Sol_V
{
	class Program
	{
		public static void Main(string[] args)
		{
			bool[] ms=new bool[1000001];
			for(int i=2;i<1000001;i++)
			{
				if(!ms[i])
					for(int y=i*2;y<1000001;y+=i)
						ms[y]=true;
			}
			int k=int.Parse(Console.ReadLine());
			for(int i=1;k*i+1<100001;i++)
			{
				if(ms[k*i+1])
				{
					Console.WriteLine(i);
					break;
				}
			}
		}
	}
}


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

class Program
{
    private static int[] GetCounts(int[] l, int max)
    {
        int[] count = new int[max + 1];
        for (int i = 0; i < n; i++) count[l[i]]++;
        return count;
    }

    private static Dictionary<int, int[]> distsCache = new Dictionary<int, int[]>();
    private static int[] GetDists(int vv)
    {
        if (distsCache.ContainsKey(vv))
            return distsCache[vv];

        int[] l = new int[n];

        List<int> buf = new List<int>() { vv };
        l[vv] = 1;
        int p = 0;
        while (p < buf.Count)
        {
            int v = buf[p++];
            foreach (var child in g[v])
                if (l[child] == 0)
                {
                    l[child] = l[v] + 1;
                    buf.Add(child);
                    if (buf.Count == n)
                    {
                        for (int i = 0; i < n; i++) l[i]--;
                        distsCache.Add(vv, l);
                        return l;
                    }
                }
        }

        for (int i = 0; i < n; i++) l[i]--;
        distsCache.Add(vv, l);

        return l;
    }

    private static double Try(int v)
    {
        var l = GetDists(v);
        int max = l.Max();

        int[] countByL = new int[max + 1];
        for (int i = 0; i < n; i++) countByL[l[i]]++;

        double ans = 0;

        double[] qq = new double[n];
        int[] id = new int[n];
        int nextId = 1;
        List<int> vv = new List<int>();

        for (int i = 0; i <= max; i++)
        {
            double p1 = 1 / (1.0 * n);
            if (countByL[i] == 1)
            {
                ans += p1;
                continue;
            }

            double[] q = new double[n];
            bool[] used = new bool[n];
            vv.Clear();

            for (int j = 0; j < n; j++)
                if (l[j] == i)
                {
                    double delta = 1 / (1.0 * (n * g[j].Count));
                    foreach (var ch in g[j])
                    {
                        q[ch] += delta;
                        if (!used[ch])
                        {
                            used[ch] = true;
                            vv.Add(ch);
                        }
                    }
                }

            double p2 = q.Max();

            double p3 = 0;
            for (int j = 0; j < n; j++)
            {
                nextId++;
                var l2 = GetDists(j);

                double qSum = 0;
                for (int ii = 0; ii < vv.Count; ii++)
                {
                    int vertex = vv[ii];
                    if (id[l2[vertex]] != nextId || q[vertex] > qq[l2[vertex]])
                    {
                        if (id[l2[vertex]] == nextId)
                            qSum -= qq[l2[vertex]];
                        else
                            id[l2[vertex]] = nextId;

                        qSum += q[vertex];
                        qq[l2[vertex]] = q[vertex];
                    }
                }

                p3 = Math.Max(qSum, p3);
            }

            ans += Math.Max(Math.Max(p1, p2), p3);
        }

        return ans;
    }

    private static int n;
    private static List<int>[] g;
    static void Main(string[] args)
    {
        n = ReadInt();
        int m = ReadInt();
        g = ReadGraph(n, m);

        double best = 0;
        for (int i = 0; i < n; i++)
        {
            best = Math.Max(best, Try(i));
            if (best + 1e-7 > 1) break;
        }

        Console.Write(DoubleToString(best));
    }

    private static int Mod = 1000000007;
    private static List<int>[] ReadGraph(int n, int m)
    {
        List<int>[] g = new List<int>[n];
        for (int i = 0; i < n; i++) g[i] = new List<int>();
        for (int i = 0; i < m; i++)
        {
            int a = ReadInt() - 1;
            int b = ReadInt() - 1;

            g[a].Add(b);
            g[b].Add(a);
        }

        return g;
    }

    private static int[,] ReadGraphAsMatrix(int n, int m)
    {
        int[,] matrix = new int[n + 1, n + 1];
        for (int i = 0; i < m; i++)
        {
            int a = ReadInt();
            int b = ReadInt();
            matrix[a, b] = matrix[b, a] = 1;
        }

        return matrix;
    }

    private static void Sort(ref int a, ref int b)
    {
        if (a > b) Swap(ref a, ref b);
    }

    private static void Swap(ref int a, ref int b)
    {
        int tmp = a;
        a = b;
        b = tmp;
    }

    private const int BufferSize = 1 << 16;
    private static StreamReader consoleReader;
    private static MemoryStream testData;

    private static int ReadInt()
    {
        int ans = 0;
        int mul = 1;
        do
        {
            ans = consoleReader.Read();
            if (ans == -1)
                return 0;
            if (ans == '-') mul = -1;
        } while (ans < '0' || ans > '9');

        ans -= '0';
        while (true)
        {
            int chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans * mul;
            ans = ans * 10 + chr - '0';
        }
    }

    private static ulong ReadULong()
    {
        ulong ans = 0;
        int chr;
        do
        {
            chr = consoleReader.Read();
            if (chr == -1)
                return 0;
        } while (chr < '0' || chr > '9');

        ans = (uint)(chr - '0');
        while (true)
        {
            chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans;
            ans = ans * 10 + (uint)(chr - '0');
        }
    }

    private static long ReadLong()
    {
        long ans = 0;
        int mul = 1;
        do
        {
            ans = consoleReader.Read();
            if (ans == -1)
                return 0;
            if (ans == '-') mul = -1;
        } while (ans < '0' || ans > '9');

        ans -= '0';
        while (true)
        {
            int chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans * mul;
            ans = ans * 10 + chr - '0';
        }
    }

    private static int[] ReadIntArray(int n)
    {
        int[] ans = new int[n];
        for (int i = 0; i < n; i++)
            ans[i] = ReadInt();
        return ans;
    }

    private static long[] ReadLongArray(int n)
    {
        long[] ans = new long[n];
        for (int i = 0; i < n; i++)
            ans[i] = ReadLong();
        return ans;
    }

    private static char[] ReadString()
    {
        int ans;

        do
        {
            ans = consoleReader.Read();
        } while (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')));

        List<char> s = new List<char>();
        do
        {
            s.Add((char)ans);
            ans = consoleReader.Read();
        } while ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'));

        return s.ToArray();
    }

    private static char[] ReadString(int n)
    {
        int ans;

        do
        {
            ans = consoleReader.Read();
        } while (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')));

        char[] s = new char[n];
        int pos = 0;
        do
        {
            s[pos++] = (char)ans;
            if (pos == n) break;
            ans = consoleReader.Read();
        } while ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'));

        return s;
    }

    private static char ReadLetter()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'))
                return (char)ans;
        }
    }
    private static char ReadNonLetter()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')))
                return (char)ans;
        }
    }

    private static char ReadDigit()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if (ans >= '0' && ans <= '9')
                return (char)ans;
        }
    }

    private static int ReadDigitInt()
    {
        return ReadDigit() - (int)'0';
    }

    private static char ReadAnyChar()
    {
        return (char)consoleReader.Read();
    }

    private static string DoubleToString(double x)
    {
        return x.ToString(CultureInfo.InvariantCulture);
    }

    private static double DoubleFromString(string x)
    {
        return double.Parse(x, CultureInfo.InvariantCulture);
    }

    static Program()
    {
        //Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
        consoleReader = new StreamReader(Console.OpenStandardInput(BufferSize), Encoding.ASCII, false, BufferSize);
    }

    private static void PushTestData(string data)
    {
#if !ONLINE_JUDGE
        if (testData == null)
        {
            testData = new MemoryStream();
            consoleReader = new StreamReader(testData);
        }

        var pos = testData.Position;
        var bytes = Encoding.UTF8.GetBytes(data);
        testData.Write(bytes, 0, bytes.Length);
        testData.Flush();
        testData.Position = pos;
#endif
    }
}


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

class Program
{
    private static long Solve(int a, int b, int c)
    {
        if (a >= b + c) return int.MaxValue;
        if (b >= a + c) return int.MaxValue;
        if (c >= a + b) return int.MaxValue;
        if (a == b && b == c && a == y) return 0;

        long ans = int.MaxValue;

        if (a <y && a < b + c - 1)
            ans = Math.Min(ans, 1 + Solve(Math.Min(y, b + c - 1), b, c));

        if (b < y && b < a + c - 1)
            ans = Math.Min(ans, 1 + Solve(a, Math.Min(y, a + c - 1), c));

        if (c < y && c < a + b - 1)
            ans = Math.Min(ans, 1 + Solve(a, b, Math.Min(y, a + b - 1)));

        int aa = Math.Max(y, Math.Max(b, c) - Math.Min(b, c) + 1);
        if (a > y &&  a > aa)
            ans = Math.Min(ans, 1 + Solve(aa, b, c));

        int bb = Math.Max(y, Math.Max(a, c) - Math.Min(a, c) + 1);
        if (b > y && b > bb)
            ans = Math.Min(ans, 1+ Solve(a, bb, c));

        int cc = Math.Max(y, Math.Max(a, b) - Math.Min(a, b) + 1);
        if (c > y && c > cc)
            ans = Math.Min(ans, 1 + Solve(a, b, cc));

        return ans;
    }

    private static int x, y;
    static void Main(string[] args)
    {
        x = RI();
        y = RI();

        List<long> m = new List<long>() { y, y, y };
        int count = 0;
        while (m.Min() < x)
        {
            count++;
            m.Sort();
            m[0] = m[1] + m[2] - 1;
        }

        Console.WriteLine(count);
    }

    private const int Mod = 1000000000 + 7;

    #region Data Read
    private static char ReadSign()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if (ans == '+' || ans == '-')
                return (char)ans;
        }
    }

    private static long GCD(long a, long b)
    {
        if (a % b == 0) return b;
        return GCD(b, a % b);
    }

    private static List<int>[] ReadGraph(int n, int m)
    {
        List<int>[] g = new List<int>[n];
        for (int i = 0; i < n; i++) g[i] = new List<int>();
        for (int i = 0; i < m; i++)
        {
            int a = RI() - 1;
            int b = RI() - 1;

            g[a].Add(b);
            g[b].Add(a);
        }

        return g;
    }

    private static int[,] ReadGraphAsMatrix(int n, int m)
    {
        int[,] matrix = new int[n + 1, n + 1];
        for (int i = 0; i < m; i++)
        {
            int a = RI();
            int b = RI();
            matrix[a, b] = matrix[b, a] = 1;
        }

        return matrix;
    }

    private static void Sort(ref int a, ref int b)
    {
        if (a > b) Swap(ref a, ref b);
    }

    private static void Swap(ref int a, ref int b)
    {
        int tmp = a;
        a = b;
        b = tmp;
    }

    private const int BufferSize = 1 << 16;
    private static StreamReader consoleReader;
    private static MemoryStream testData;

    private static int RI()
    {
        int ans = 0;
        int mul = 1;
        do
        {
            ans = consoleReader.Read();
            if (ans == -1)
                return 0;
            if (ans == '-') mul = -1;
        } while (ans < '0' || ans > '9');

        ans -= '0';
        while (true)
        {
            int chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans * mul;
            ans = ans * 10 + chr - '0';
        }
    }

    private static ulong RUL()
    {
        ulong ans = 0;
        int chr;
        do
        {
            chr = consoleReader.Read();
            if (chr == -1)
                return 0;
        } while (chr < '0' || chr > '9');

        ans = (uint)(chr - '0');
        while (true)
        {
            chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans;
            ans = ans * 10 + (uint)(chr - '0');
        }
    }

    private static long RL()
    {
        long ans = 0;
        int mul = 1;
        do
        {
            ans = consoleReader.Read();
            if (ans == -1)
                return 0;
            if (ans == '-') mul = -1;
        } while (ans < '0' || ans > '9');

        ans -= '0';
        while (true)
        {
            int chr = consoleReader.Read();
            if (chr < '0' || chr > '9')
                return ans * mul;
            ans = ans * 10 + chr - '0';
        }
    }

    private static int[] RIA(int n)
    {
        int[] ans = new int[n];
        for (int i = 0; i < n; i++)
            ans[i] = RI();
        return ans;
    }

    private static long[] RLA(int n)
    {
        long[] ans = new long[n];
        for (int i = 0; i < n; i++)
            ans[i] = RL();
        return ans;
    }

    private static char[] ReadString()
    {
        int ans;

        do
        {
            ans = consoleReader.Read();
        } while (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')));

        List<char> s = new List<char>();
        do
        {
            s.Add((char)ans);
            ans = consoleReader.Read();
        } while ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'));

        return s.ToArray();
    }

    private static char[] ReadString(int n)
    {
        int ans;

        do
        {
            ans = consoleReader.Read();
        } while (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')));

        char[] s = new char[n];
        int pos = 0;
        do
        {
            s[pos++] = (char)ans;
            if (pos == n) break;
            ans = consoleReader.Read();
        } while ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'));

        return s;
    }

    private static char[] ReadStringLine()
    {
        int ans;

        do
        {
            ans = consoleReader.Read();
        } while (ans == 10 || ans == 13);

        List<char> s = new List<char>();

        do
        {
            s.Add((char)ans);
            ans = consoleReader.Read();
        } while (ans != 10 && ans != 13);

        return s.ToArray();
    }

    private static char ReadLetter()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if ((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z'))
                return (char)ans;
        }
    }
    private static char ReadNonLetter()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if (!((ans >= 'a' && ans <= 'z') || (ans >= 'A' && ans <= 'Z')))
                return (char)ans;
        }
    }

    private static char ReadDigit()
    {
        while (true)
        {
            int ans = consoleReader.Read();
            if (ans >= '0' && ans <= '9')
                return (char)ans;
        }
    }

    private static int ReadDigitInt()
    {
        return ReadDigit() - (int)'0';
    }

    private static char ReadAnyChar()
    {
        return (char)consoleReader.Read();
    }

    private static string DoubleToString(double x)
    {
        return x.ToString(CultureInfo.InvariantCulture);
    }

    private static double DoubleFromString(string x)
    {
        return double.Parse(x, CultureInfo.InvariantCulture);
    }

    static Program()
    {
        //Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
        consoleReader = new StreamReader(Console.OpenStandardInput(BufferSize), Encoding.ASCII, false, BufferSize);
    }

    private static void PushTestData(string data)
    {
#if TOLYAN_TEST
        if (testData == null)
        {
            testData = new MemoryStream();
            consoleReader = new StreamReader(testData);
        }

        var pos = testData.Position;
        var bytes = Encoding.UTF8.GetBytes(data);
        testData.Write(bytes, 0, bytes.Length);
        testData.Flush();
        testData.Position = pos;
#endif
    }
    #endregion
}


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

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

        private static void Main(string[] args)
        {
            string s = reader.ReadLine();

            long prev = 0;
            long count = 1;
            int mod = 1000000007;
            for (int i = s.Length - 1; i >= 0; i--)
            {
                long next;
                if (s[i] == '1')
                {
                    next = (count*count)%mod;
                    next += 2*prev;
                }
                else
                {
                    next = 2*prev;
                }

                count = (count*2)%mod;
                prev = next%mod;
            }

            writer.WriteLine(prev);
            writer.Flush();
        }
    }
}


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

namespace CF_9C
{
    class Program
    {
        static void Main(string[] args)
        {
            var strInp = Console.ReadLine();
            var digitCnt = strInp.Count();
            var totCases = Math.Pow(2, digitCnt) - 1; //Not considering 0
            var inp = UInt64.Parse(strInp);

            while(inp < (UInt64)ConvertToDecimalValue((int)totCases)){
                totCases--;
            }
            Console.WriteLine(totCases);
        }

        static int ConvertToDecimalValue(int totCases)
        {
            var strInpRev = ConvertToBinaryValue((UInt64)totCases).ToArray<char>();
            int no = 0;
            for (int i = 0; i < strInpRev.Length; i++)
            {
                no += (int)(strInpRev[i] - '0') * (int)Math.Pow(10, i);
            }
            return no;
        }
        static string ConvertToBinaryValue(UInt64 inp)
        {
            string str = "";
            while(inp > 0){
                str += inp%2;
                inp = inp/2;
            }
            return str;
        }
    }
}


using System;
using System.Text;

    class Program
    {
        static void Main(string[] args)
        {
            int[,] m;
            var n = Int32.Parse(Console.ReadLine());
            m = new int[n, n];
            for (int i = 0; i < n; i++)
            {
                var s = Console.ReadLine().Split(' ');
                for (int j = 0; j < n; j++)
                    m[i, j] = Int32.Parse(s[j]);
            }
            int sum = 0;
            for (int i = 0; i < n; i++)
                for (int j = 0; j < n; j++)
                    if (i == j || n - i == j + 1  || n - j == i + 1 || i == (n - 1) / 2 || j == (n - 1) / 2)
                        sum+=m[i,j];

            Console.WriteLine(sum);
        }

    }


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

namespace CodeForces {
	class Program {
		static void Main(string[] args) {
			string line;
			int n, m;

			line = Console.ReadLine();
			n = int.Parse(line.Split(' ')[0]); // dospeli
			m = int.Parse(line.Split(' ')[1]); // deti

			if (n == 0 && m > 0) {
				Console.WriteLine("Impossible");
			} else if (n > 0 && m == 0) {
				Console.WriteLine(n + " " + n);
			} else if(n == 0 && m == 0) {
				Console.WriteLine("0 0");
			} else if (n >= m) {
				int min = n;
				int max = n + m - 1;

				Console.WriteLine(min + " " + max);
			} else if (n < m) {
				int min = n + (m - n);
				int max = n + m - 1;

				Console.WriteLine(min + " " + max);
			}
		}
	}
}


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

namespace _577A
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();

            int n = Convert.ToInt32(str.Split(' ')[0]);
            int x = Convert.ToInt32(str.Split(' ')[1]);
            int count = 0;
            if (n >= x)
            {
                for (int i = 1; i <= n; i++)
                {
                    if (x % i == 0)
                    {
                        count++;
                    }
                }
            }
            else
            {
                int k = 0;
                if (x % n == 0)
                {
                    k = x / n;
                }
                else
                {
                    k = (x / n) + 1;
                }
                for (int i = k; i <= n; i++)
                {
                    if (x % i == 0)
                    {
                        count++;
                    }
                }
            }
            Console.Write(count);
            Console.ReadLine();
        }
    }
}


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

namespace CodeForces800
{
    internal static class Program
    {
        public static long prime = 1000000007;
        public static long[] bprime = new long[2];
        public static Dictionary<long, long> invar = new Dictionary<long, long>();
        public static long[] fact = new long[1];
        public static void Main()
        {
            var cur = prime - 2;
            var list = new List<long>();
            while (cur != 0)
            {
                list.Add(cur % 2);
                cur = cur / 2;
            }
            bprime = list.ToArray();
            var str = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToList();
            var n = str[0];
            var k = str[1];
            long res = 0;
            fact = new long[n + 1];
            fact[0] = 1;
            for (var i = 1; i < n + 1; i++)
            {
                fact[i] = (long)((long)fact[i - 1] * i) % prime;
            }
            for (var i = 0; i <= Math.Min(n,k); i++)
            {
                res += C(n, i);
                res = res % prime;
            }
            Console.WriteLine(res);
        }
        private static long C(long n, long k)
        {
            if (n >= k)
            {
                long res = fact[n];
                res = res * calcInv(fact[n - k]);
                res = res % prime;
                res = res * calcInv(fact[k]);
                res = res % prime;
                return (long)res;
            }
            else return 0;
        }

        public static long calcInv(long n)
        {
            if (invar.TryGetValue(n, out var invn))
                return invn;
            else
            {
                var ost = new long[bprime.Length];
                ost[0] = n;
                for (var i = 1; i < bprime.Length; i++)
                {
                    ost[i] = (ost[i - 1] * ost[i - 1]) % prime;
                }
                long inv = 1;
                for (var i = 0; i < bprime.Length; i++)
                {
                    inv *= (bprime[i] == 1) ? ost[i] : 1;
                    inv = inv % prime;
                }
                invar.Add(n, (long)inv);

                return (long)inv;
            }
        }
    }
}


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

namespace Codeforces415A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] inp = Console.ReadLine().Split();
            int n = Convert.ToInt32(inp[0]);
            int m = Convert.ToInt32(inp[1]);
            string[] inp2 = Console.ReadLine().Split();
            int[] b = new int[m];
            int[] outp = new int[n];

            for (int i = 0; i < m; i++)
            {
                b[i] = Convert.ToInt32(inp2[i]);
            }

            for (int i = 0; i < m; i++)
            {
                int max = i == 0 ? n : b[i - 1]-1;

                if (i>0 && b[i] > b[i - 1])
                    continue;

                for (int j = b[i]-1; j < max; j++)
                {
                    if (outp[j] != 0)
                        break;
                    outp[j] = b[i];
                }
            }

            string outp_str = "";
            for (int i = 0; i < n; i++)
            {
                outp_str += outp[i] + " ";
            }

            Console.WriteLine(outp_str.Trim());
            //inp = Console.ReadLine().Split();
        }
    }
}


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

namespace ConsoleApplication15
{
    class Hello2018_1
    {
        static void Main(string[] args)
        {
#if MY_DEBUG
            Console.SetIn(new StreamReader(@"D:\Sergey\Code\1.txt"));
            //var writer = new StreamWriter(@"D:\Sergey\Code\out.txt");
            //Console.SetOut(writer);
#endif
            int n = int.Parse(Console.ReadLine());
            int m = int.Parse(Console.ReadLine());

            if (n > 28)
            {
                Console.WriteLine(m);
                return;
            }

            int r = m % (int)Math.Pow(2, n);

            Console.WriteLine(r);
#if MY_DEBUG
            //writer.Close();
#endif
        } // main

    }
}


using System;
using System.Linq;
using System.Collections.Generic;
using Debug = System.Diagnostics.Trace;
using SB = System.Text.StringBuilder;
using static System.Math;
using static System.Numerics.BigInteger;
using static Program.IO.Scanner;

using Number = System.Int64;
#region IO
namespace Program.IO {
	using System.IO;
	using System.Text;
	using System.Globalization;

	public class Printer : StreamWriter {
		public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
		public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
	}
	static public class Scanner {
		public static StreamScanner sc = new StreamScanner(Console.OpenStandardInput());
		public static int ri => sc.Integer();
		public static long rl => sc.Long();
		public static string rs => sc.Scan();
		public static double rd => sc.Double();
	}
	public class StreamScanner {
		public StreamScanner(Stream stream) { str = stream; }

		public readonly Stream str;
		private readonly byte[] buf = new byte[1024];
		private int len, ptr;
		public bool isEof = false;
		public bool IsEndOfStream { get { return isEof; } }

		private byte read() {
			if (isEof) return 0;
			if (ptr >= len) {
				ptr = 0;
				if ((len = str.Read(buf, 0, 1024)) <= 0) {
					isEof = true;
					return 0;
				}
			}
			return buf[ptr++];
		}

		public char Char() {
			byte b = 0;
			do b = read(); while ((b < 33 || 126 < b) && !isEof);
			return (char)b;
		}
		public string Scan() {
			var sb = new StringBuilder();
			for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b);
			return sb.ToString();
		}
		public string ScanLine() {
			var sb = new StringBuilder();
			for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b);
			return sb.ToString();
		}
		public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); }
		public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); }
		public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); }
	}

}

#endregion

#region main
static class Ex {
	static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); }
	static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") {
		return string.Join(st, ie);
	}

	static public void Main() {
		Console.SetOut(new Program.IO.Printer(Console.OpenStandardOutput()) { AutoFlush = false });
		var solver = new Program.Solver();
		var t = new System.Threading.Thread(solver.Solve, 50000000);
		t.Start();
		t.Join();
		//*/
		//solver.Solve();
		Console.Out.Flush();
	}
}
#endregion

namespace Program {
	public class Solver {
		Random rnd = new Random(0);
		public void Solve() {

			var n = ri;
			var k = ri - 1;
			var dp = new ModInt[n + 1];
			dp[0] = 1;
			var binom = Enumerate(n + 5, x => new ModInt[n + 5]);
			binom[0][0] = 1;
			for (int i = 0; i < n; i++)
				for (int j = 0; j < n; j++) {
					binom[i + 1][j] += binom[i][j];
					binom[i + 1][j + 1] += binom[i][j];
				}
			var powK = Enumerate(n + 5, x => 1.m());
			for (int i = 1; i < powK.Length; i++)
				powK[i] = powK[i - 1] * k.m();
			var powK2 = Enumerate(n + 5, x => 1.m());
			for (int i = 1; i < powK2.Length; i++)
				powK2[i] = powK2[i - 1] * (k + 1).m();

			for (int _ = 0; _ < n; _++) {
				var next = new ModInt[n + 1];
				for (int j = 0; j < dp.Length; j++) if (dp[j].num != 0)
						for (int d = 0; j + d <= n; d++) {
							ModInt coef = binom[n - j][d];
							coef *= powK[n - j - d];
							if (d != 0) coef *= powK2[j];
							else coef *= powK2[j] - powK[j];
							//Debug.WriteLine($"{j} -> {j + d} {dp[j]} {binom[n - j, d]} {powK[n - j - d]} {coef}");
							next[j + d] += dp[j] * coef;
						}
				dp = next;
				// Debug.WriteLine(dp.AsJoinedString());
			}

			Console.WriteLine(dp[n]);
		}
		const long INF = 1L << 60;
		static int[] dx = { -1, 0, 1, 0 };
		static int[] dy = { 0, 1, 0, -1 };
		static T[] Enumerate<T>(int n, Func<int, T> f) {
			var a = new T[n]; for (int i = 0; i < a.Length; ++i) a[i] = f(i); return a;
		}
		static T[][] Enumerate<T>(int n, int m, Func<int, int, T> f) {
			return Enumerate(n, x => Enumerate(m, y => f(x, y)));
		}
		static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
	}
}
#region ModInt
/// <summary>
/// [0,<see cref="Mod"/>) までの値を取るような数
/// </summary>
public struct ModInt {
	public const long Mod = (int)1e9 + 7;
	public long num;
	public ModInt(long n) { num = n; }
	public override string ToString() { return num.ToString(); }
	public static ModInt operator +(ModInt l, ModInt r) { return new ModInt(l.num + r.num < Mod ? l.num + r.num : l.num + r.num - Mod); }
	public static ModInt operator -(ModInt l, ModInt r) { return new ModInt(l.num + Mod - r.num < Mod ? l.num + Mod - r.num : l.num - r.num); }
	public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); }
	public static ModInt operator /(ModInt l, ModInt r) { return l * Inverse(r); }
	public static implicit operator ModInt(long n) { return n.mod(); }
	public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); }
	public static ModInt Pow(long v, long k) {
		long ret = 1;
		for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)
			if ((k & 1) == 1) ret = ret * v % Mod;
		return new ModInt(ret);
	}
	public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }
}
public static partial class ModIntEx {
	public static ModInt mod(this long v) {
		v %= ModInt.Mod;
		if (v < 0) v += ModInt.Mod;
		return new ModInt(v);
	}
	public static ModInt mod(this int v) {
		var u = v % ModInt.Mod;
		if (u < 0) u += ModInt.Mod;
		return new ModInt(u);
	}
	public static ModInt m(this long v) { return new ModInt(v); }
	public static ModInt m(this int v) { return new ModInt(v); }
}
#endregion

#region Binomial Coefficient
public class BinomialCoefficient {
	public ModInt[] fact, ifact;
	public BinomialCoefficient(int n) {
		fact = new ModInt[n + 1];
		ifact = new ModInt[n + 1];
		fact[0] = 1.m();
		for (int i = 1; i <= n; i++)
			fact[i] = fact[i - 1] * i.m();
		ifact[n] = ModInt.Inverse(fact[n]);
		for (int i = n - 1; i >= 0; i--)
			ifact[i] = ifact[i + 1] * (i + 1).m();
		ifact[0] = ifact[1];
	}
	public ModInt this[int n, int r] {
		get {
			if (n < 0 || n >= fact.Length || r < 0 || r > n) return 0;
			return fact[n] * ifact[n - r] * ifact[r];
		}
	}
	public ModInt RepeatedCombination(int n, int k) {
		if (k == 0) return 1.m();
		return this[n + k - 1, k];
	}
}
#endregion


// problem here: http://codeforces.com/problemset/problem/895/A
using System;
using System.Collections.Generic;
using System.Linq;

public class MainClass{
    public static void Main(string[] args){
        int n = Int32.Parse(Console.ReadLine());
        List<int> list = Console.ReadLine().Split().Select(
                x => Int32.Parse(x)).ToList();
        List<int> minDiffs = new List<int>();

        for (int j = 0; j < n; j++) {
            list.Add(list[0]);
            list.RemoveAt(0);
            int diff = 360;
            int head = 0;
            int tail = 360;
            for (int i = 0; i < n; i++) {
                head += list[i];
                tail -= list[i];
                if (Math.Abs(head - tail) < diff) {
                    diff = Math.Abs(head - tail);
                } else {
                    minDiffs.Add(diff);
                    break;
                }
                //Console.Write(list[i] + " ");
            }
            //Console.WriteLine();
        }
        Console.WriteLine(minDiffs.Min());
    }
}