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

class PairVariable : IComparable<PairVariable>
{
    public int a, b;
    public PairVariable()
    {
        a = b = 0;
    }
    public PairVariable(string s)
    {
        string[] q = s.Split();
        a = int.Parse(q[0]);
        b = int.Parse(q[1]);
    }
    public PairVariable(int a, int b)
    {
        this.a = a;
        this.b = b;
    }

    public int CompareTo(PairVariable other)
    {
        return other.a.CompareTo(this.a);
    }
}

namespace ConsoleApplication254
{

    class Program
    {

        static bool foo(string s1, string s2)
        {
            for (int i = 0; i < s1.Length; i++)
            {
                for (int e = 0; e < s2.Length; e++)
                {
                    if (s1[i] == s2[e])
                    {
                        return true;
                    }
                }
            }
            return false;
        }
        static void Main(string[] args)
        {
            string[] ss = Console.ReadLine().Split();
            int n = int.Parse(ss[0]);
            List<int> d = new List<int>();
            int ans = 0;
            for (int i = 1; i <= Math.Sqrt(n); i++)
            {
                if (n % i == 0)
                {
                    d.Add(i);
                }
            }

            int x = d.Count;
            for (int i = 0; i < x; i++)
            {
                if (n / d[i] != d[i])
                {
                    d.Add(n / d[i]);
                }
            }

            string z = n.ToString();
            for (int i = 0; i < d.Count; i++)
            {
                string s = d[i].ToString();

                if (foo(s, z))
                {
                    ans++;
                }
            }
            Console.WriteLine(ans);
        }
    }
}


using System;
using System.Linq;

class Program
{
    static void Main()
    {
        string str = Console.ReadLine();
        int n = int.Parse(str);

        var squares = new int[n, 4];

        int minX = -1, maxX = -1, minY = -1, maxY = -1;

        for (int i = 0; i < n; i++)
        {
            str = Console.ReadLine();
            var q = str.Split(new char[] {' '});

            squares[i, 0] = int.Parse(q[0]);
            squares[i, 1] = int.Parse(q[1]);
            squares[i, 2] = int.Parse(q[2]);
            squares[i, 3] = int.Parse(q[3]);

            if (i == 0)
            {
                minX = squares[i, 0];
                minY = squares[i, 1];
                maxX = squares[i, 2];
                maxY = squares[i, 3];
            }

            if (minX > squares[i, 0]) minX = squares[i, 0];
            if (minY > squares[i, 1]) minY = squares[i, 1];
            if (maxX < squares[i, 2]) maxX = squares[i, 2];
            if (maxY < squares[i, 3]) maxY = squares[i, 3];
            // Console.WriteLine(str);
        }

        if (maxX - minX != maxY - minY)
        {
            Console.WriteLine("NO");
            return;
        }

        int square1 = (maxX - minX) * (maxY - minY);
        int square2 = 0;

        for (int i = 0; i < n; i++)
        {
            square2 += (squares[i, 2] - squares[i, 0]) * (squares[i, 3] - squares[i, 1]);
        }

        if (square1 != square2)
        {
            // Console.WriteLine("NO 2 1: {0} 2: {1}", square1, square2);
            Console.WriteLine("NO");
            return;
        }

        Console.WriteLine("YES");
    }
}


using System;
using System.Linq;
class Demo
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int S = 0;
        int minx = 31401, miny = 31401, maxx = 0, maxy = 0;
        while (n-- > 0)
        {
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            S += (a[2] - a[0]) * (a[3] - a[1]);
            if (a[0] < minx) minx = a[0];
            if (a[1] < miny) miny = a[1];
            if (a[2] > maxx) maxx = a[2];
            if (a[3] > maxy) maxy = a[3];
        }
        string ans = maxx - minx == maxy - miny && Math.Pow(maxx - minx, 2) == S ? "YES" : "NO";
        Console.WriteLine(ans);
    }
}


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

namespace A
{
    class Program
    {
        static int Dist(int x1, int y1, int x2, int y2)
        {
            return ((x1 - x2) * (x1 - x2) + (y2 - y1) * (y2 - y1));
        }
        static bool F(int x1, int y1, int x2, int y2, int x3, int y3)
        {
            if (x1 == x2 && y1 == y2) return false;
            if (x1 == x3 && y1 == y3) return false;
            if (x3 == x2 && y3 == y2) return false;
            int a = Dist(x1, y1, x2, y2);
            int b = Dist(x1, y1, x3, y3);
            int c = Dist(x3, y3, x2, y2);

            if (a + b == c)
                return true;
            if (a == b + c)
                return true;
            if (b == a + c)
                return true;
            return false;
        }

        static bool Ans(int x1, int y1, int x2, int y2, int x3, int y3)
        {
            if (F(x1 + 1, y1, x2, y2, x3, y3)) return true;
            if (F(x1 - 1, y1, x2, y2, x3, y3)) return true;
            if (F(x1, y1 + 1, x2, y2, x3, y3)) return true;
            if (F(x1, y1 - 1, x2, y2, x3, y3)) return true;
            return false;
        }
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            int x1 = int.Parse(s[0]);
            int y1 = int.Parse(s[1]);
            int x2 = int.Parse(s[2]);
            int y2 = int.Parse(s[3]);
            int x3 = int.Parse(s[4]);
            int y3 = int.Parse(s[5]);
            if (F(x1, y1, x2, y2, x3, y3))
            {
                Console.WriteLine("RIGHT");
            }
            else
            {
                if (Ans(x1, y1, x2, y2, x3, y3))
                {
                    Console.WriteLine("ALMOST");
                    return;
                }
                if (Ans(x2, y2, x1, y1, x3, y3))
                {
                    Console.WriteLine("ALMOST");
                    return;
                }
                if (Ans(x3, y3, x1, y1, x2, y2))
                {
                    Console.WriteLine("ALMOST");
                    return;
                }
                Console.WriteLine("NEITHER");
            }
        }
    }
}


using System;
using System.Linq;

namespace _18A
{
    class Program
    {
        static int[] dx = new[] { -1, 1, 0, 0 };
        static int[] dy = new[] { 0, 0, -1, 1 };

        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int[] x = new int[3], y = new int[3];
            for (int i = 0; i < 6; i++)
            {
                if (i % 2 == 0)
                    x[i / 2] = int.Parse(input[i]);
                else
                    y[i / 2] = int.Parse(input[i]);
            }

            bool right = Check(x, y), almost = false;
            if (!right)
            {
                for (int i = 0; i < 4 && !almost; i++) // direction
                {
                    for (int j = 0; j < 3 && !almost; j++) // point
                    {
                        x[j] += dx[i]; y[j] += dy[i];
                        almost = Check(x, y);
                        x[j] -= dx[i]; y[j] -= dy[i];
                    }
                }
            }

            if (right) Console.WriteLine("RIGHT");
            else if (almost) Console.WriteLine("ALMOST");
            else Console.WriteLine("NEITHER");
        }

        static bool Check(int[] x, int[] y)
        {
            if (x.All(a => a == x[0]) || y.All(a => a == y[0]))
                return false;

            for (int i = 0; i < 3; i++)
                for (int j = i + 1; j < 3; j++)
                    if (x[i] == x[j] && y[i] == y[j])
                        return false;

            double[] dist = new[]
            {
                Distance(x[0], y[0], x[1], y[1]),
                Distance(x[1], y[1], x[2], y[2]),
                Distance(x[2], y[2], x[0], y[0])
            };
            int maxIndex = -1; double max = 0;
            for (int i = 0; i < 3; i++)
                if (dist[i] > max)
                {
                    max = dist[i];
                    maxIndex = i;
                }

            double sum = 0;
            for (int i = 0; i < 3; i++)
                if (i != maxIndex)
                    sum += dist[i];

            return sum == max;
        }

        static double Distance(double x1, double y1, double x2, double y2)
        {
            return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
        }
    }
}


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

namespace ConsoleApp2
{
    class Program
    {
        const long MOD = 1000000007;
        static int before(int x, int ost)
        {
            if (x < ost)
                return 0;
            return (x - ost) / 3 + 1;
        }
        static void Main(string[] args)
        {
            int n, l, r;
            string[] input = Console.ReadLine().Split();
            n = int.Parse(input[0]);
            l = int.Parse(input[1]);
            r = int.Parse(input[2]);
            long[,] dp = new long[n, 3];
            dp[0, 0] = before(r, 0) - before(l - 1, 0);
            dp[0, 1] = before(r, 1) - before(l - 1, 1);
            dp[0, 2] = before(r, 2) - before(l - 1, 2);
            for (int i = 1; i < n; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    int pred0 = j;
                    int pred1 = j - 1;
                    int pred2 = j - 2;
                    if (pred1 < 0)
                        pred1 += 3;
                    if (pred2 < 0)
                        pred2 += 3;
                    dp[i, j] += dp[i - 1, pred0] * dp[0, 0];
                    dp[i, j] %= MOD;
                    dp[i, j] += dp[i - 1, pred1] * dp[0, 1];
                    dp[i, j] %= MOD;
                    dp[i, j] += dp[i - 1, pred2] * dp[0, 2];
                    dp[i, j] %= MOD;
                }
            }
            /*for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < 3; j++)
                    Console.Write($"{dp[i, j]} ");
                Console.WriteLine();
            }*/
            Console.WriteLine((dp[n - 1, 0])%MOD);
        }
    }
}


using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var I = G;
		int N = I[0], l = I[1], r = I[2];
		var mx = new int[3];
		mx[0] = (r + 3) / 3 - (l + 2) / 3;
		mx[1] = (r + 2) / 3 - (l + 1) / 3;
		mx[2] = (r + 1) / 3 - l / 3;
		var dp = new long[N + 1, 3];
		dp[0, 0] = 1;
		for (var n = 1; n <= N; n++)
			for (var m = 0; m < 3; m++)
				for (var x = 0; x < 3; x++)
					dp[n, m] = (dp[n, m] + mx[x] * dp[n - 1, (m - x + 3) % 3] % MOD) % MOD;
		WriteLine(dp[N, 0]);
	}
}


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

class Program
{

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

        HashSet<char> set = new HashSet<char>();
        for (int i = 0; i < n; i++)
        {
            if (char.IsUpper(str[i]))
            {
                arr[i] = 0;
                set = new HashSet<char>();
            }

            else
            {
                set.Add(str[i]);
                arr[i] = set.Count();
            }
        }

        Console.WriteLine(arr.Max());
    }
}


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

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Int32.Parse(Console.ReadLine());
            string str = Console.ReadLine();
            int currentMax = 0;
            for (int i = 0; i < n; ++i)
            {
                if(char.IsLower(str, i))
                {
                    int max = 1;
                    for(int j = i+1; j<n; ++j)
                    {
                        if (char.IsLower(str, j))
                        {
                            if (!str.Substring(i, j - i).Contains(str[j]))
                                max++;
                        }
                        else goto exit;
                     }
                exit:
                    if (max > currentMax)
                        currentMax = max;
                }
            }
            Console.WriteLine(currentMax);
        }
    }
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] a = new int[n+4];
            string[] s = Console.ReadLine().Split(' ');
            int ans = 0;
            for (int i = 0; i < n; i++)
            {
                a[i] = int.Parse(s[i]);
                if (a[i] == 1)
                    ans++;
            }
            for (int i = 0; i < n; i++)
                if (a[i] == 1 && a[i + 1] == 0 && a[i + 2] == 1)
                    ans++;

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


using System;

class Program
{

    static void Main()
    {
        string[] t = new string[1];
        t[0] = Console.ReadLine();

        int n = int.Parse(t[0]);
        int[] arr = new int[n];
        t[0] = Console.ReadLine();

        t = t[0].Split();

        for (int j = 0; j < n; ++j)
        {
            arr[j] = int.Parse(t[j]);
        }

        int i = 0, ans = 0;

        while (i < n && arr[i] == 0)
            ++i;

        for (; i < n;)
        {
            int q = 0;

            if (arr[i] != 0)
            {
                ++ans;
                ++i;
                continue;
            }

            while (i < n && arr[i] == 0)
            {
                ++i; ++q;
                if (i == n) q = 0;
            }

            if (q == 1)
                ++ans;

        }

        Console.WriteLine(ans);
    }
}


using System;
class Program
{
    static void Main()
    {
      int ans = 0;
        string[] tokens = Console.ReadLine().Split();
        long l = long.Parse(tokens[0]);
        long r = long.Parse(tokens[1]);
        for (int i = 0; i <= 32; ++i) {
          for (int j = 0; j <= 20; ++j)
          {
            long x = (long)Math.Pow(2, i) * (long)Math.Pow(3, j);
            if (x >= l && x <=r)
              ans++;
          }
        }
        Console.WriteLine(ans);

    }

}


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

namespace Codeforces
{
	class Program
	{
		static void Main(string[] args)
		{
			string input1 = Console.ReadLine();
			//string input2 = Console.ReadLine();

			//string input3 = Console.ReadLine();
			//string input4 = Console.ReadLine();

			var inputs1 = input1.Split(new[] {' ', '}', '{', ','}, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
			//var inputs2 = input2.Split(new[] { ' ', '}', '{', ',' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToList();
			//var inputs3 = input3.Split(new[] { ' ', '}', '{', ',' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
			//var inputs4 = input4.Split(new[] { ' ', '}', '{', ',' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();

			long l = inputs1[0];
			long r = inputs1[1];

			long end2 = (long)Math.Log(r, 2) + 1;

			var set = new HashSet<long>();
			for (long i = 0; i < end2 + 1; i++)
			{
				long start3 = (long)Math.Log(l / Math.Pow(2, i), 3);
				if (start3 < 0)
				{
					start3 = 0;
				}

				long end3 = (long)Math.Log(r / Math.Pow(2, i), 3) + 1;
				if (end3 < 0)
				{
					end3 = 0;
				}

				for (long j = start3; j < end3 + 1; j++)
				{
					long current = (long)(Math.Pow(2, i) * Math.Pow(3, j));
					if (current < l || current > r)
					{
						continue;
					}

					set.Add(current);
				}
			}

			Console.WriteLine(set.Count);
		}

		public class Team
		{
			public string Name { get; set; }

			public int Points { get; set; }

			public int GoalsFor { get; set; }

			public int GoalsAgainst { get; set; }
		}

		static long Factorial(long a)
		{
			return a > 1 ? a * Factorial(a - 1) : 1;
		}
	}
}


using System;
using System.Linq;

namespace CSharp
{
    public class _822A
    {
        public static void Main(string[] args)
        {
            Console.WriteLine(Enumerable.Range(1, Console.ReadLine().Split().Select(token => int.Parse(token)).Min()).Aggregate((a, b) => a * b));
        }
    }
}


using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
class Problem
{
    static void Main()
    {
        //--------------------------------input--------------------------------//

        var s = Array.ConvertAll( Console.ReadLine().Split(), Convert.ToInt32 );
        int a = s[0], b = s[1];

        //--------------------------------solve--------------------------------/

        Console.WriteLine( kq( Math.Min( a, b ) ) );

    }

    private static long kq(int p)
    {
        if(p == 1)
            return 1;
        else
            return p * kq( p - 1 );
    }
}


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

namespace ConsoleApplication6
{

    class Program
    {
        static void Main(string[] args)
        {
            int[,] tabl = new int[3, 3];
            int[,] tablrezult = new int[3, 3];
            string[] str1 = new string[3];
            for (int i = 0; i < 3; i++)
            {
                str1[i] = Console.ReadLine();
            }
            string[] strin1 = str1[0].Split(' ');
            string[] strin2 = str1[1].Split(' ');
            string[] strin3 = str1[2].Split(' ');
            for (int i = 0; i < 3; i++)
            {
                tabl[0, i] = int.Parse(strin1[i]);
                tabl[1, i] = int.Parse(strin2[i]);
                tabl[2, i] = int.Parse(strin3[i]);
            }

            tablrezult[2, 1] = tabl[2, 0] + tabl[2, 2] + tabl[1, 1] + tabl[2, 1];

            tablrezult[0, 1] = tabl[1, 1] + tabl[0, 0] + tabl[0, 2] + tabl[0, 1];
            tablrezult[1, 0] = tabl[0, 0] + tabl[2, 0] + tabl[1, 1] + tabl[1, 0];
            tablrezult[1, 2] = tabl[2, 2] + tabl[1, 1] + tabl[0, 2] + tabl[1, 2];

            tablrezult[0, 0] = tabl[1, 0] + tabl[0, 1] + tabl[0, 0];

            tablrezult[2, 2] = tabl[1, 2] + tabl[2, 1] + tabl[2, 2];

            tablrezult[0, 2] = tabl[1, 2] + tabl[0, 1] + tabl[0, 2];

            tablrezult[2, 0] = tabl[1, 0] + tabl[2, 1] + tabl[2, 0];

            tablrezult[1, 1] = tabl[2, 1] + tabl[1, 2] + tabl[0, 1] + tabl[1, 0] + tabl[1, 1];

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if ((tablrezult[i, j] % 2) == 0)
                    {
                        tablrezult[i, j] = 1;
                    }
                    else { tablrezult[i, j] = 0; }

                }
            }

                Console.WriteLine(tablrezult[0, 0].ToString() + tablrezult[0, 1].ToString() + tablrezult[0, 2].ToString());
                Console.WriteLine(tablrezult[1, 0].ToString() + tablrezult[1, 1].ToString() + tablrezult[1, 2].ToString());
                Console.WriteLine(tablrezult[2, 0].ToString() + tablrezult[2, 1].ToString() + tablrezult[2, 2].ToString());

            Console.ReadLine();
        }

    }
}


using System;

namespace ConvexShape
{
    class Program
    {
        public static void Main(string[] args)
        {
            int[,] lights = new int[3,3];
            int[,] lightsCumulative = new int[3, 3];
            for (int i = 0; i < 3; ++i)
            {
                string s = Console.ReadLine();
                string[] nums = s.Split(new[]{' '}, StringSplitOptions.RemoveEmptyEntries);
                for (int j = 0; j < 3; ++j )
                {
                    lights[i, j] = int.Parse(nums[j]);
                }
            }

            for (int i = 0; i < 3; ++i)
            {
                for (int j = 0; j < 3; ++j)
                {
                    int l=0, r=0, t=0, b=0;
                    l = (i - 1) >= 0 && (i - 1) < 3 ? lights[i - 1,j] : 0;
                    r = (i + 1) >= 0 && (i + 1) < 3 ? lights[i + 1,j] : 0;
                    b = (j + 1) >= 0 && (j + 1) < 3 ? lights[i ,j+1] : 0;
                    t = (j - 1) >= 0 && (j - 1) < 3 ? lights[i ,j-1] : 0;
                    lightsCumulative[i, j] = lights[i, j] + l + r + t + b;

                    Console.Write((lightsCumulative[i, j] + 1) % 2);
            }
                Console.WriteLine();
            }

        }

    }
}


using System;
using System.Collections.Generic;

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        s = Console.ReadLine().Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

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

class Myon
{
    Scanner cin;
    Myon() { }

    public static void Main()
    {
        new Myon().calc();
    }

    void calc()
    {
        cin = new Scanner();
        long ret = 0;
        int n, m, t;
        n = cin.nextInt();
        m = cin.nextInt();
        t = cin.nextInt();
        int i, j;
        const int MAX = 100;
        long[] choosen = new long[MAX];
        long[] choosem = new long[MAX];
        choosen[0] = choosem[0] = 1;
        for (i = 0; i < n; i++)
        {
            for (j = MAX - 1; j > 0; j--)
            {
                choosen[j] += choosen[j - 1];
            }
        }
        for (i = 0; i < m; i++)
        {
            for (j = MAX - 1; j > 0; j--)
            {
                choosem[j] += choosem[j - 1];
            }
        }
        for (i = 4; i < t; i++)
        {
            ret += choosen[i] * choosem[t - i];
        }
        Console.WriteLine(ret);

    }
}


using System;

namespace CSharp
{
    class _131C
    {
        public static void Main()
        {
            var tokens = Console.ReadLine().Split();

            int n = int.Parse(tokens[0]);
            int m = int.Parse(tokens[1]);
            int t = int.Parse(tokens[2]);

            long ways = 0;

            for (int b = 4; b <= n; b++)
            {
                int g = t - b;

                if (g >= 1 && g <= m)
                {
                    ways += Choose(n, b) * Choose(m, g);
                }
            }

            Console.WriteLine(ways);
        }

        private static long Choose(int n, int k)
        {
            long result = 1;

            for (int i = 0; i < k; i++)
            {
                result *= n - i;
                result /= i + 1;
            }

            return result;
        }
    }
}


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

namespace codeforces
{

    class Program
    {
        public static int ReadInt() => Int32.Parse(Console.ReadLine());

        public static int[] ReadInts() =>
            Console.ReadLine().Split(new[]{' '}, StringSplitOptions.RemoveEmptyEntries)
                .Select(Int32.Parse).ToArray();

        static void Main(string[] args)
        {
            int n = ReadInt();
            var grades = ReadInts();
            Array.Sort(grades);
            var todo = n*9 - grades.Sum() * 2;

            int i;
            for (i = 0; i < grades.Length && todo > 0; i++)
            {
                var grade = grades[i];
                var plus = (5 - grade)*2;
                todo -= plus;
            }
            Console.WriteLine(i);
        }
    }
}


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

namespace cs
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int twos = 0, threes = 0, fours = 0;
            int[] scores = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            for (int i = 0; i < scores.Length; i++)
            {
                if (scores[i] == 2)
                    twos++;
                else if (scores[i] == 3)
                    threes++;
                else if (scores[i] == 4)
                    fours++;
            }
            double EPSILON = 0E-12;
            int count = 0;
            int sum = scores.Sum();
            while ((double)sum / n - 4.5 < EPSILON && twos + threes + fours > 0)
            {
                if (twos > 0)
                {
                    twos--;
                    sum += 3;
                    count++;
                }
                else if (threes > 0)
                {
                    threes--;
                    sum += 2;
                    count++;
                }
                else if (fours > 0)
                {
                    fours--;
                    sum += 1;
                    count++;
                }
            }

            Console.WriteLine(count);
        }
    }
}


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

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

        private static void Main(string[] args)
        {
            int k = Next();
            int a = Next();
            int b = Next();

            if (k > a && k > b)
                writer.WriteLine("-1");
            else
            {
                int ma = a%k;
                int mb = b%k;

                if (ma > 0 && b/k == 0 || mb > 0 && a/k == 0)
                    writer.WriteLine("-1");
                else
                    writer.WriteLine(a/k + b/k);
            }

            writer.Flush();
        }

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


using System;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace Codeforces
{
	internal class Template
	{
		private void Solve()
		{
			var k = cin.NextInt();
			var a = cin.NextInt();
			var b = cin.NextInt();

			if (k > a && (b%k != 0 || b == 0))
			{
				Console.WriteLine(-1);
				return;
			}
			if (k > b && (a % k != 0 || a == 0))
			{
				Console.WriteLine(-1);
				return;
			}

			if (k > a && k > b)
			{
				Console.WriteLine(-1);
				return;
			}
			var count = a / k + b / k;
			Console.WriteLine(count);
		}

		private static readonly Scanner cin = new Scanner();

		private static void Main()
		{
#if DEBUG
			var inputText = File.ReadAllText(@"..\..\input.txt");
			var testCases = inputText.Split(new[] { "input" }, StringSplitOptions.RemoveEmptyEntries);
			var consoleOut = Console.Out;
			for (var i = 0; i < testCases.Length; i++)
			{
				var parts = testCases[i].Split(new[] { "output" }, StringSplitOptions.RemoveEmptyEntries);
				Console.SetIn(new StringReader(parts[0].Trim()));
				var stringWriter = new StringWriter();
				Console.SetOut(stringWriter);
				var sw = Stopwatch.StartNew();
				new Template().Solve();
				sw.Stop();
				var output = stringWriter.ToString();

				Console.SetOut(consoleOut);
				var color = ConsoleColor.Green;
				var status = "Passed";
				if (parts[1].Trim() != output.Trim())
				{
					color = ConsoleColor.Red;
					status = "Failed";
				}
				Console.ForegroundColor = color;
				Console.WriteLine("Test {0} {1} in {2}ms", i + 1, status, sw.ElapsedMilliseconds);
			}
			Console.ReadLine();
			Console.ReadKey();
#else
			new Template().Solve();
			Console.ReadLine();
#endif
		}
	}

	internal class Scanner
	{
		private string[] s = new string[0];
		private int i;
		private readonly char[] cs = { ' ' };

		public string NextString()
		{
			if (i < s.Length) return s[i++];
			var line = Console.ReadLine() ?? string.Empty;
			s = line.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			i = 1;
			return s.First();
		}

		public double NextDouble()
		{
			return double.Parse(NextString());
		}

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

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


using System;
using System.Collections.Generic;

namespace CodeForces
{
    static class Program
    {
        static void Main()
        {
            const string filePath = @"Data/MR18R2C.txt";
            if (System.IO.File.Exists(filePath))
            {
                Console.SetIn(new System.IO.StreamReader(filePath));
            }

            IProblem counter = new MR18R2C();

            foreach (var result in counter.GetResults())
            {
                Console.WriteLine(result);
            }
        }
    }

    internal class MR18R2C : ProblemBase
    {
        public override IEnumerable<string> GetResults()
        {
            var ints = this.ReadLongArray();
            var la = ints[0];
            var ra = ints[1];
            var ta = ints[2];

            ints = this.ReadLongArray();
            var lb = ints[0];
            var rb = ints[1];
            var tb = ints[2];

            var l = Math.Min(la, lb);

            la -= l;
            ra -= l;
            lb -= l;
            rb -= l;

            long result = 0;

            if (ta == tb)
            {
                result = GetLength(la, ra, lb, rb);
            }
            else
            {
                var t = Math.Max(ta, tb);
                var delta = t - Math.Min(ta, tb);

                var d = (int)this.Gcd(delta, t);
                if (d == 1)
                {
                    result = Math.Min(ra - la + 1, rb - lb + 1);
                }
                else // cycles
                {
                    var aDiff = (la / d) * d;
                    la -= aDiff;
                    ra -= aDiff;

                    var bDiff = (lb / d) * d;
                    lb -= bDiff;
                    rb -= bDiff;

                    var deltas = new[] {-2, -1, 0, 1, 2};

                    for (int i = 0; i < deltas.Length; i++)
                    {
                        long current = GetLength(la, ra, lb + deltas[i] * d, rb + deltas[i] * d);
                        if (current >= result)
                        {
                            result = current;
                        }

                    }
                }
            }

            yield return result.ToString();
        }

        private static long GetLength(long la, long ra, long lb, long rb)
        {
            var left = Math.Max(la, lb);
            var right = Math.Min(ra, rb);
            if (right >= left)
            {
                return right - left + 1;
            }

            return 0;
        }

        private long Gcd(long a, long b)
        {
            var first = a;
            var second = b;

            while (second != 0)
            {
                var temp = first % second;
                first = second;
                second = temp;
            }
            return first;
        }

    }

    internal class MR18R2D : ProblemBase
    {
        public override IEnumerable<string> GetResults()
        {
            yield return "n/a";
        }
    }

    abstract class MultipleTestsBase : ProblemBase
    {
        public sealed override IEnumerable<string> GetResults()
        {
            var t = Convert.ToInt32(Console.ReadLine());
            for (int testCaseNumber = 0; testCaseNumber < t; testCaseNumber++)
            {
                foreach (var result in GetTestResult(testCaseNumber + 1))
                {
                    yield return result;
                }

            }

        }

        protected abstract IEnumerable<string> GetTestResult(int caseNumber);
    }

    public interface IProblem
    {
        IEnumerable<string> GetResults();
    }

    public abstract class ProblemBase : IProblem
    {
        public void PrintArray<T>(IEnumerable<T> items, string prefixMessage)
        {
            Console.WriteLine("{0}: {1}", prefixMessage, string.Join(",", items));
        }

        public void WriteDiagnostics(string message, params object[] objects)
        {
            Console.WriteLine(message, objects);
        }

        public virtual IEnumerable<string> GetResults()
        {
            yield return "No result";
        }

        protected int[] ReadIntArray()
        {
            return Array.ConvertAll(ReadTokens(), Convert.ToInt32);
        }

        protected long[] ReadLongArray()
        {
            return Array.ConvertAll(ReadTokens(), Convert.ToInt64);
        }

        protected string[] ReadTokens()
        {
            var readLine = Console.ReadLine();
            if (readLine == null)
            {
                throw new Exception("Value read from Console is null");
            }
            return readLine.Split(' ');
        }

        protected int ReadInt32()
        {
            return Convert.ToInt32(Console.ReadLine());
        }
    }
}


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

class Program
{
    class T
    {
        public int X;
        public int Y;

        public T(int x, int y)
        {
            X = x;
            Y = y;
        }
    }
    //////////////////////////////////////////////////

    long gcda(long a, long b,out long x,out long y)
    {
        if (a == 0)
        {
            x = 0; y = 1;
            return b;
        }
        long x1, y1;
        long d = gcda(b % a, a,out x1,out y1);
        x = y1 - (b / a) * x1;
        y = x1;
        return d;
    }

    bool find_any_solution(long a, long b, long c, out long x0, out long y0, out long g)
    {
        g = gcda(Math.Abs(a), Math.Abs(b), out x0, out y0);
        if (c % g != 0)
            return false;
        change(a,b, c, g, ref x0, ref y0);
        return true;
    }

    void change(long a, long b, long c, long g, ref long x0, ref long y0)
    {
        x0 *= c / g;
        y0 *= c / g;
        if (a < 0) x0 *= -1;
        if (b < 0) y0 *= -1;
    }

        //////////////////////////////////////////////////
        void Solution()
    {
        var la = rl;
        var ra = rl;
        var ta = rl;
        var lb = rl;
        var rb = rl;
        var tb = rl;

        //kb*tb=ka*ta+la-lb
        //tb*kb-ta*ka=la-lb
        var c = la - lb;
        //long x = 0;// kb;
        var a = -ta;
        //long y = 0;// ka;
        var b = tb;

        if (c < 0)
        {
            c *= -1;
            a *= -1;
            b *= -1;
        }

        if (c == 0)
        {
            wln(Math.Min(rb, ra) - la + 1);
            return;
        }

        var flag = find_any_solution(a, b, c, out long x, out long y, out long g);
        if (flag)
        {
            wln(Math.Min(rb + y * tb - x * ta, ra) - la + 1);
        }
        else
        {

            var c1 = (c / g) * g;
            var c2 = c1 + g;
            var c0 = c1 - g;
            find_any_solution(a, b, c1, out long x1, out long y1, out long g1);
            find_any_solution(a, b, c2, out long x2, out long y2, out long g2);
            if (c0 < 0)
            {
                c0 *= -1;
                a *= -1;
                b *= -1;
            }
            find_any_solution(a, b, c0, out long x0, out long y0, out long g0);

            var res1 = Math.Min((rb + y1 * tb - x1 * ta), ra) - Math.Max(la, (lb + y1 * tb - x1 * ta)) + 1;
            var res2 = Math.Min((rb + y2 * tb - x2 * ta), ra) - Math.Max(la, (lb + y2 * tb - x2 * ta)) + 1;
            var res0 = Math.Min((rb + y0 * tb - x0 * ta), ra) - Math.Max(la, (lb + y0 * tb - x0 * ta)) + 1;
            wln(Math.Max(0, Math.Max(res0, Math.Max(res1, res2))));
        }
    }

    //////////////////////////////////////////////////

    struct P : IComparable<P>
    {
        public long X;
        public long Y;

        public P(long x, long y)
        {
            X = x;
            Y = y;
        }

        public int CompareTo(P other) => X != other.X ? X.CompareTo(other.X) : Y.CompareTo(other.Y);
        public static int Comparison(P p1, P p2) => p1.CompareTo(p2);

        public static bool operator ==(P p1, P p2) => (p1.X == p2.X) && (p1.Y == p2.Y);
        public static bool operator !=(P p1, P p2) => (p1.X != p2.X) || (p1.Y != p2.Y);

        public static P operator +(P p1, P p2) => new P(p1.X + p2.X, p1.Y + p2.Y);
        public static P operator -(P p1, P p2) => new P(p1.X - p2.X, p1.Y - p2.Y);
    }

    void swap<T>(ref T o1, ref T o2) { var o = o1; o1 = o2; o2 = o; }
    long gcd(long a, long b) => (b != 0) ? gcd(b, a % b) : a;
    long lcm(long a, long b) => a / gcd(a, b) * b;

    long rast2(long x1, long y1, long x2, long y2) => (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
    long rast2(P p1, P p2) => (p1.X - p2.X) * (p1.X - p2.X) + (p1.Y - p2.Y) * (p1.Y - p2.Y);
    long ccw(P p1, P p2, P p3) => p1.X * p2.Y + p1.Y * p3.X + p2.X * p3.Y - p2.Y * p3.X - p3.Y * p1.X - p1.Y * p2.X;

    StringBuilder _sb = new StringBuilder();
    void wln() { _sb.AppendLine(); }
    void wln<T>(T o) { _sb.AppendLine(o.ToString()); }
    void wsp<T>(T o) { _sb.Append(o).Append(" "); }
    void wrt<T>(T o) { _sb.Append(o); }
    void wln(double o) { _sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "{0:F12}", o)); }
    void wsp(double o) { _sb.Append(string.Format(CultureInfo.InvariantCulture, "{0:F12} ", o)); }
    void wrt(double o) { _sb.Append(string.Format(CultureInfo.InvariantCulture, "{0:F12}", o)); }

    List<P> rpa(int n)
    {
        var res = new List<P>(n);
        for (int i = 0; i < n; i++)
            res.Add(new P(rl, rl));
        return res;
    }

    int ri
    {
        get
        {
            _read(); while (_str[_ind] == ' ') ++_ind;
            int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }
            int p = 0;
            while (_ind < _count && _str[_ind] != ' ') p = p * 10 + _str[_ind++] - '0';
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return p * sign;
        }
    }
    long rl
    {
        get
        {
            _read(); while (_str[_ind] == ' ') ++_ind;
            int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }
            long p = 0;
            while (_ind < _count && _str[_ind] != ' ') p = p * 10 + _str[_ind++] - '0';
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return p * sign;
        }
    }
    double rd
    {
        get
        {
            _read(); while (_str[_ind] == ' ') ++_ind; int sign = 1; if (_str[_ind] == '-') { sign = -1; ++_ind; }
            long p = 0, q = 1; while (_ind < _count && _str[_ind] != ' ' && _str[_ind] != '.') p = p * 10 + _str[_ind++] - '0';
            if (_ind < _count && _str[_ind] == '.') { ++_ind; while (_ind < _count && _str[_ind] != ' ') { p = p * 10 + _str[_ind++] - '0'; q *= 10; } }
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return (double)p / q * sign;
        }
    }
    string rs
    {
        get
        {
            _read(); while (_ind < _count && _str[_ind] == ' ') ++_ind;
            var tmp = _str.IndexOf(' ', _ind);
            if (tmp == -1) { var res = _str.Substring(_ind); _count = 0; _ind = 0; return res; }
            var s = _str.Substring(_ind, tmp - _ind); _ind = tmp + 1;
            while (_ind < _count && _str[_ind] == ' ') ++_ind; return s;
        }
    }

    List<int> ria(int n)
    {
        var res = new int[n];
        for (int k = 0; k < n;)
        {
            var s = Console.ReadLine(); var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }
                int p = 0; while (i < m && s[i] != ' ') p = p * 10 + s[i++] - '0'; res[k++] = p * sign;
            }
        }
        _count = 0; _ind = 0; return res.ToList();
    }
    List<long> rla(int n)
    {
        var res = new long[n];
        for (int k = 0; k < n;)
        {
            var s = Console.ReadLine(); var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }
                long p = 0; while (i < m && s[i] != ' ') p = p * 10 + s[i++] - '0'; res[k++] = p * sign;
            }
        }
        _count = 0; _ind = 0; return res.ToList();
    }
    List<double> rda(int n)
    {
        var res = new double[n];
        for (int k = 0; k < n;)
        {
            var s = Console.ReadLine(); var m = s.Length;
            for (int i = 0; i < m && k < n; ++i)
            {
                while (i < m && s[i] == ' ') ++i; if (i == m) break; int sign = 1; if (s[i] == '-') { sign = -1; ++i; }
                long p = 0, q = 1; while (i < m && s[i] != ' ' && s[i] != '.') p = p * 10 + s[i++] - '0';
                if (i < m && s[i] == '.') { ++i; while (i < m && s[i] != ' ') { p = p * 10 + s[i++] - '0'; q *= 10; } }
                res[k++] = (double)p / q * sign;
            }
        }
        _count = 0; _ind = 0; return res.ToList();
    }
    List<string> rsa(int n) { var res = new string[n]; for (int k = 0; k < n; ++k) res[k] = Console.ReadLine(); _count = 0; _ind = 0; return res.ToList(); }
    string _str = null; int _count = 0; int _ind = 0;
    void _read() { if (_ind == _count) { _str = Console.ReadLine(); _count = _str.Length; _ind = 0; } }
    static void Main(string[] args) { new Program().Main(); }
    void Main()
    {
        //Console.SetIn(new StreamReader("input.txt")); Console.SetOut(new StreamWriter("output.txt"));
        Solution();
        Console.Write(_sb);
        //Console.In.Close(); Console.Out.Close();
    }
}


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

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

class Sol{
	public void Solve(){

		int mod=(int)(1e9+7);
		int N=200001;

		int[][] dp=new int[2][];

		dp[0]=new int[N];
		dp[1]=new int[N];
		dp[0][0]=1;

		int[] d=new int[1010];
		d[0]=1;

		int h=0;
		int rmax=0;
		int next;
		int now;
		int rr;
		int gg;
		for(int i=1;i<894;i++){
			next=i%2;
			now=1-next;
			for(int j=0;j<=Math.Min(rmax+i,N-1);j++)dp[next][j]=0;
			for(int j=0;j<=rmax;j++){
				if(dp[now][j]==0)continue;
				rr=j;
				gg=((i-1+1)*(i-1))/2-rr;

				if(r-rr>=i){
					dp[next][rr+i]+=dp[now][j];
					dp[next][rr+i]%=mod;
					if(rmax<rr+i)rmax=rr+i;
					d[i]+=dp[now][j];
					d[i]%=mod;
					h=i;
				}
				if(g-gg>=i){
					dp[next][rr]+=dp[now][j];
					dp[next][rr]%=mod;
					d[i]+=dp[now][j];
					d[i]%=mod;
					h=i;
				}
			}
		}
		//Console.WriteLine(h);
		Console.WriteLine(d[h]);

	}

	int r;
	int g;
	public Sol(){
		var d=ria();
		r=d[0];
		g=d[1];
	}

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

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

class Sol{
	public void Solve(){

		int mod=(int)(1e9+7);
		int N=200001;

		int[][] dp=new int[2][];

		dp[0]=new int[N];
		dp[1]=new int[N];
		dp[0][0]=1;

		int[] d=new int[1010];
		d[0]=1;

		int h=0;
		int rmax=0;
		int next;
		int now;
		int rr;
		int gg;
		for(int i=1;i<894;i++){
			next=i%2;
			now=1-next;
			for(int j=0;j<=Math.Min(rmax+i,N-1);j++)dp[next][j]=0;
			for(int j=0;j<=rmax;j++){
				if(dp[now][j]==0)continue;
				rr=j;
				gg=((i-1+1)*(i-1))/2-rr;

				if(r-rr>=i){
					dp[next][rr+i]+=dp[now][j];
					if(dp[next][rr+i]>mod)dp[next][rr+i]-=mod;
					if(rmax<rr+i)rmax=rr+i;
					d[i]+=dp[now][j];
					if(d[i]>mod)d[i]-=mod;
					h=i;
				}
				if(g-gg>=i){
					dp[next][rr]+=dp[now][j];
					if(dp[next][rr]>mod)dp[next][rr]-=mod;
					d[i]+=dp[now][j];
					if(d[i]>mod)d[i]-=mod;
					h=i;
				}
			}
		}
		//Console.WriteLine(h);
		Console.WriteLine(d[h]%mod);

	}

	int r;
	int g;
	public Sol(){
		var d=ria();
		r=d[0];
		g=d[1];
	}

	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.Globalization;
using System.IO;
using System.Linq;
using System.Text;
public class Codeforces
{
    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
        reader = new StreamReader(Console.OpenStandardInput(1024 * 10), System.Text.Encoding.ASCII, false, 1024 * 10);
        writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), System.Text.Encoding.ASCII, 1024 * 10);
        var v1 = ReadInt();
        var v2 = ReadInt();
        var t = ReadInt();
        var d = ReadInt();
        var a = 0;
        for (int i = 0; i < t; i++)
        {
            a += Math.Min(v1 + i * d, v2 + (t - i - 1) * d);
        }
        Write(a);
        reader.Close();
        writer.Close();
    }
    #region Read / Write

    private static Queue<string> currentLineTokens = new Queue<string>();

    private static string[] ReadAndSplitLine()
    {
        return reader.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
    }

    public static string ReadToken()
    {
        while (currentLineTokens.Count == 0)
            currentLineTokens = new Queue<string>(ReadAndSplitLine());
        return currentLineTokens.Dequeue();
    }

    public static int ReadInt()
    {
        return int.Parse(ReadToken());
    }

    public static long ReadLong()
    {
        return long.Parse(ReadToken());
    }

    public static double ReadDouble()
    {
        return double.Parse(ReadToken(), CultureInfo.InvariantCulture);
    }

    public static int[] ReadIntArray()
    {
        return ReadAndSplitLine().Select(int.Parse).ToArray();
    }

    public static long[] ReadLongArray()
    {
        return ReadAndSplitLine().Select(long.Parse).ToArray();
    }

    public static double[] ReadDoubleArray()
    {
        return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();
    }
    public static int[][] ReadIntMatrix(int numberOfRows)
    {
        int[][] matrix = new int[numberOfRows][];
        for (int i = 0; i < numberOfRows; i++)
            matrix[i] = ReadIntArray();
        return matrix;
    }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows);
        int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++)
        {
            ret[i] = new int[numberOfRows];
            for (int j = 0; j < numberOfRows; j++)
                ret[i][j] = matrix[j][i];
        }
        return ret;
    }

    public static string[] ReadLines(int quantity)
    {
        string[] lines = new string[quantity];
        for (int i = 0; i < quantity; i++)
            lines[i] = reader.ReadLine().Trim();
        return lines;
    }
    public static void WriteArray<T>(IEnumerable<T> array)
    {
        writer.WriteLine(string.Join(" ", array));
    }

    public static void Write<T>(params T[] array)
    {
        WriteArray(array);
    }

    public static void WriteLines<T>(IEnumerable<T> array)
    {
        foreach (var a in array)
            writer.WriteLine(a);
    }
    #endregion
}


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

namespace Takmicenja.CodeForces.CF298
{
    class B
    {
        public static void Main(string[] varg)
        {
            string[] tok = Console.ReadLine().Split(new char[] { ' ' });
            int v1 = int.Parse(tok[0]);
            int v2 = int.Parse(tok[1]);

            tok = Console.ReadLine().Split(new char[] { ' ' });
            int t = int.Parse(tok[0]);
            int d = int.Parse(tok[1]);

            int[] vleft = new int[t];
            vleft[0] = v1;
            for (int i = 1; i < t; i++)
                vleft[i] = vleft[i - 1] + d;

            int[] vright = new int[t];
            vright[0] = v2;
            for (int i = 1; i < t; i++)
                vright[i] = vright[i - 1] + d;

            int maxSpeed = v1>v2?v1:v2;
            int[] vUpper = new int[t];
            for (int i=0;i<t;i++)
            {
                vUpper[i] = vleft[i];
            }
            for (int i=0;i<t;i++)
            {
                if (vUpper[i] > vright[t - i - 1])
                    vUpper[i] = vright[t - i - 1];
            }

            long s = 0;
            for (int i = 0; i < t; i++)
                s += vUpper[i];

            Console.WriteLine(s);

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
public class Codeforces
{
    static void Main()
    {
        var _ = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var a = _[0];
        var c = _[1];
        var a3 = new Stack<int>();
        var a3ctr = 0;
        var b3 = new Stack<int>();
        var c3 = new Stack<int>();
        var c3ctr = 0;
        while (a > 0)
        {
            var rem = a % 3;
            a /= 3;
            a3.Push(rem);
            a3ctr++;
        }
        while (c > 0)
        {
            var rem = c % 3;
            c /= 3;
            c3.Push(rem);
            c3ctr++;
        }
        if (a3ctr > c3ctr)
        {
            for (int i = 0; i < a3ctr - c3ctr; i++)
            {
                c3.Push(0);
            }
            c3ctr = a3ctr;
        }
        else if (c3ctr > a3ctr)
        {
            for (int i = 0; i < c3ctr - a3ctr; i++)
            {
                a3.Push(0);
            }
            a3ctr = c3ctr;
        }
        long res = 0L;
        for (int i = 0; i < a3ctr; i++)
        {
            var ter = new[] { 0, 1, 2 };
            var m = c3.Pop();
            var n = a3.Pop();
            while (n-- != 0)
            {
                m--;
                if (m < 0) m = 2;
            }
            b3.Push(m);
            res += m * (long)Math.Pow(3, (a3ctr - 1 - i));
        }
        Console.WriteLine(res);
    }
}


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

namespace ConsoleApplication2
{

    class Program
    {

        static void Main(string[] args)
        {

            string[] str = Console.ReadLine().Split(' ');
            long a = long.Parse(str[0]);
            long c = long.Parse(str[1]);

            if(a == 0 && c ==0)
            {
                Console.WriteLine(0);
                return;
            }

            int length = (int)Math.Max(Math.Ceiling(Math.Log(a, 3)), Math.Ceiling(Math.Log(c, 3)))+1;

            //Console.WriteLine(length);

            int[] astr = new int[length];
            for (int i = 0; i < length; i++ )
            {
                astr[i] = (int)((a / (int)Math.Pow(3, i)) % 3);
            }

            int[] cstr = new int[length];
            for (int i = 0; i < length; i++)
            {
                cstr[i] = (int)((c / (int)Math.Pow(3, i)) % 3);
            }

            int[] bstr = new int[length];
            for (int i = 0; i < length; i++)
            {
                if (astr[i] <= cstr[i])
                {
                    bstr[i] = cstr[i] - astr[i];
                }
                else
                {
                    bstr[i] = cstr[i] - astr[i] + 3;
                }
            }

            /*
            for (int i = 0; i < length; i++ )
            {
                Console.Write(astr[i]);
            }
            Console.WriteLine();

            for (int i = 0; i < length; i++)
            {
                Console.Write(bstr[i]);
            }
            Console.WriteLine();

            for (int i = 0; i < length; i++)
            {
                Console.Write(cstr[i]);
            }
            Console.WriteLine();
            */

            long res = 0;
            for (int i = 0; i < length; i++)
            {
                //Console.WriteLine(bstr[i] + "  " + (int)Math.Pow(3, i));
                res += bstr[i] * (long)Math.Pow(3, i);
            }
            Console.WriteLine(res);
        }

    }
}


// CodeForces Basic Question For Recursions
//https://codeforces.com/group/MWSDmqGsZm/contest/223339

using System;
using System.Collections;
using System.Diagnostics;

public static class Program
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        for (int i = 0; i < n; i++)
        {
            int[] x = Array.ConvertAll(Console.ReadLine().Split(' '), (item) => Convert.ToInt32(item));
            int[] y = Array.ConvertAll(Console.ReadLine().Split(' '), (item2) => Convert.ToInt32(item2));
            Console.WriteLine(Solve(x, y));
        }
    }
    public static int Solve(int[] x, int[] y)
    {
        int count = 0;
        for (int i = 0; i < 2; i++)
        {
            if (x[i] == 1) count++;
            if (y[i] == 1) count++;
        }
        if(count == 0) return 0;
        if (count == 4) return 2;
        else return 1;
    }
}


// See https://aka.ms/new-console-template for more informatio
//int t, n, m;
//t = Convert.ToInt32(Console.ReadLine());
//for (int t1 = 0; t1 < t; t1++)
//{
//    var s = Console.ReadLine();
//    var endId = 0;
//    for(int i = 0; i < s.Length; i++)
//    {
//        if(s[i] == ' ')
//        {
//            endId = i;
//            break;
//        }
//    }
//    n = Convert.ToInt32(s.Substring(0, endId));
//    m = Convert.ToInt32(s.Substring(endId + 1, s.Length - endId - 1));
//    long res = 0;
//    for (int i = 1; i <= m; i++)
//    {
//        res += i;
//    }
//    for (int i = 1; i < n; i++)
//    {
//        res += i * m + m;
//    }
//    Console.WriteLine(res);
//}
using System;

public class HelloWorld
{
    public static void Main(string[] args)
    {
        int testCase;
        testCase = Convert.ToInt32(Console.ReadLine());
        for (int x = 0; x < testCase; x++)
        {
            var s = Console.ReadLine();
            int sum = 0;
            var endId = 0;
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == ' ')
                {
                    endId = i;
                    break;
                }
            }
            sum += Convert.ToInt32(s.Substring(0, endId));
            sum += Convert.ToInt32(s.Substring(endId + 1, s.Length - endId - 1));
            s = Console.ReadLine();
            endId = 0;
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == ' ')
                {
                    endId = i;
                    break;
                }
            }
            sum += Convert.ToInt32(s.Substring(0, endId));
            sum += Convert.ToInt32(s.Substring(endId + 1, s.Length - endId - 1));
            int res = 0;
            if (sum == 4)
            {
                res = 2;
            }
            else if (sum > 0)
            {
                res = 1;
            }
            Console.WriteLine(res);
        }
    }
}


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

namespace tes
{
	class contest
	{

		static void Main(string[] args)
		{

   string s = Console.ReadLine();
            string r = "";
            string c = "";
            int len = s.Length;
            for(int i=0; i< len; i++)
            {
                if (i < len - 1) r += s[i];
                else c += s[i];
            }

            var col = new string[]{"f","e","d","a","b","c" };
            long row = long.Parse(r);

            long time = (Array.IndexOf(col,c))+1;

            long a = row/3;
            long b = row % 3;

            long turn = row / 4;
            if (row % 4 > 0) turn++;

            time += (turn+turn-2) * 7;
            time += (turn -1) * 2;

            if (row % 2 == 0)
            {
                time += 7;
            }

            Console.WriteLine(time);

        }

	}
}


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

namespace _725B
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            int L = S.Length; sbyte A2 = 0;
            char C = char.Parse(S.Substring(L-1));
            string SN = (S.Substring(0, L - 1));
            long N = long.Parse(SN);

            switch (C)
            {
                case 'f':
                    A2 = 1;
                    break;
                case 'e':
                    A2 = 2;
                    break;
                case 'd':
                    A2 = 3;
                    break;
                case 'a':
                    A2 = 4;
                    break;
                case 'b':
                    A2 = 5;
                    break;
                case 'c':
                    A2 = 6;
                    break;

            }

            long A1 = 16 * ((N - 1) / 4);
            sbyte A3 = 0;
            if ((N % 2) == 0) A3 = 7;
            long T = A1 + A2 + A3;

            Console.WriteLine(T);

        }
    }
}


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

namespace CF
{
    public static class FromConsole
    {
        public static T To<T>(this string input) where T : IConvertible
        {
            return (T)Convert.ChangeType(input, typeof(T));
        }

        public static T[] ToArrayOf<T>(this string input, char? delimiter = null) where T : IConvertible
        {
            IEnumerable<string> sequence = delimiter == null ? input.Select(x => x.ToString()) : input.Split(delimiter.Value);

            return sequence.Select(x => x.ToString().To<T>()).ToArray();
        }

        public static T[] ToArrayOf<T>(int count) where T : IConvertible
        {
            T[] output = new T[count];

            for (int i = 0; i < count; i++)
            {
                output[i] = Console.ReadLine().To<T>();
            }

            return output;
        }

        public static T[] ToArrayOf<T>(T value, int count)
        {
            return Enumerable.Repeat(value, count).ToArray();
        }

        public static T[][] ToMatrixOf<T>(int n, char? delimiter = null) where T : IConvertible
        {
            T[][] output = new T[n][];

            for (int i = 0; i < n; i++)
            {
                output[i] = Console.ReadLine().ToArrayOf<T>(delimiter);
            }

            return output;
        }

        public static T[][] ToMatrixOf<T>(T value, int n, int m)
        {
            T[][] output = new T[n][];

            for (int i = 0; i < n; i++)
            {
                output[i] = ToArrayOf(value, m);
            }

            return output;
        }

        public static Tuple<int, int> IndexOf<T>(this T[][] input, params T[] targets)
        {
            for (int i = 0; i < input.Length; i++)
            {
                for (int j = 0; j < input[0].Length; j++)
                {
                    if (targets.Any(x => x.Equals(input[i][j])))
                    {
                        return new Tuple<int, int>(i, j);
                    }
                }
            }

            return new Tuple<int, int>(-1, -1);
        }

        public static void AddToList<T, U>(this Dictionary<T, List<U>> input, T k, U v)
        {
            if (input.ContainsKey(k))
            {
                input[k].Add(v);
            }
            else
            {
                input.Add(k, new List<U>() { v });
            }
        }

        public static void AddAndIncrement<T>(this Dictionary<T, int> input, T k)
        {
            if (input.ContainsKey(k))
            {
                input[k]++;
            }
            else
            {
                input.Add(k, 1);
            }
        }

        public static string ToBinary(this long input)
        {
            return Convert.ToString(input, 2);
        }

        public static long ToDecimal(this string input)
        {
            return Convert.ToInt32(input, 2);
        }

        public static long Binomial(long n, long k)
        {
            long r = 1;
            long d;
            if (k > n) return 0;
            for (d = 1; d <= k; d++)
            {
                r *= n--;
                r /= d;
            }
            return r;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            int[] bounds = Console.ReadLine().ToArrayOf<int>(' ');
            int n = bounds[0];
            int x = Math.Min(bounds[1], bounds[2]);
            int y = Math.Max(bounds[1], bounds[2]);

            Node head = new Node(1);
            Node current = head;
            for (int i = 2; i <= n; i++)
            {
                Node next = new Node(i);
                next.Previous = current;
                current.Next = next;
                current = next;
            }

            int round = 1;
            bool stillPossible = true;
            int finalRound = (int)Math.Log(n, 2);
            while (round <= finalRound)
            {
                Node one = head;
                Node two = head.Next;
                while (one != null)
                {
                    int i = one.Value;
                    int j = two.Value;

                    if (i == x && j == y)
                    {
                        stillPossible = false;
                        break;
                    }
                    else
                    {
                        if (i == x || i == y)
                        {
                            one.Next = two.Next;

                            if (two.Next == null)
                            {
                                break;
                            }

                            two.Next.Previous = one;
                            two = one.Next;

                            one = one.Next;
                            two = two.Next;
                        }
                        else
                        {
                            if (one.Previous == null)
                            {
                                head = two;
                                two.Previous = null;
                                one = head;
                                two = one.Next;

                                one = one.Next;
                                two = two.Next;
                            }
                            else
                            {
                                one.Previous.Next = two;
                                two.Previous = one.Previous;
                                one = two;
                                two = one.Next;

                                if (two == null)
                                {
                                    break;
                                }

                                one = one.Next;
                                two = two.Next;
                            }
                        }
                    }
                }

                if (!stillPossible)
                {
                    break;
                }

                round++;
            }

            Console.WriteLine(round == finalRound ? "Final!" : round.ToString());
            //Console.ReadKey();
        }
    }

    class Node
    {
        public int Value { get; set; }
        public Node Previous { get; set; }
        public Node Next { get; set; }

        public Node(int value)
        {
            Value = value;
        }
    }
}


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

namespace Codeforces
{
      class Program
      {
            static void Main(string[] args)
            {
                  string[] s = Console.ReadLine().Split(' ');
                  int n = int.Parse(s[0]);
                  int a = int.Parse(s[1]);
                  int b = int.Parse(s[2]);

                  if (a > b)
                  {
                        int x = a;
                        a = b;
                        b = x;
                  }

                  if (a <= n / 2 && b > n / 2)
                        Console.WriteLine("Final!");
                  else
                  {
                        a--;
                        b--;
                        int res;
                        for (res = 0; a != b; res++)
                        {
                              a /= 2;
                              b /= 2;
                        }
                        Console.WriteLine(res);
                  }
            }
      }
}


using System;

namespace CodeForces
{
    internal class ThreeDoors
    {
        public static void Main(string[] args)
        {
            int testcases = int.Parse(Console.ReadLine());

            for (int i = 0; i < testcases; i++)
            {
                int key = int.Parse(Console.ReadLine());

                int[] doors = new int[3];
                string[] split = Console.ReadLine().Split();

                for (int j = 0; j < 3; j++)
                {
                    doors[j] = int.Parse(split[j]);
                }

                TestPossible(key, doors);
            }
        }

        static void TestPossible(int key, int[] doors)
        {
            for (int i = 0; i < 2; i++)
            {
                key = doors[key - 1];
                if (key == 0)
                {
                    Console.WriteLine("no");
                    return;
                }
            }
            Console.WriteLine("yes");
        }
    }
}


using System;
using System.Linq;
using System.Text;
using System.Numerics;
using static System.Console;
using System.Collections.Generic;

using static CompLib.Algorithm;
using static CompLib.EMath;

namespace ProblemSolving.cs
{
    class MainClass
    {
        const int Mod = (int) (1e9 + 7);
        const int Def = (int) 1e9;

        static long[] OneLongLine => ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
        static int[] OneIntLine => ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
        static int[] OneCharLine => ReadLine().Trim().ToCharArray().Select(v => v - '0').ToArray();
        static long OneLong => long.Parse(ReadLine().Trim());
        static int OneInt => int.Parse(ReadLine().Trim());
        static string OneString => ReadLine().Trim();

        static void Solve()
        {
            int key = OneInt;
            var list = OneIntLine.ToList();
            int idx = list.IndexOf(0) + 1;

            if (list[key - 1] == 0 || list[list[key - 1] - 1] == 0)
            {
                WriteLine("NO");
            }
            else WriteLine("YES");

        }

        static bool Check(int[] arr)
        {
            return true;
        }

        static void Main()
        {
            int cases = OneInt;
            while (--cases >= 0)
            {
                Solve();
            }

            // Solve();
        }
    }
}

namespace CompLib
{
     public static class Algorithm
     {
         public static long LowerBound(long[] arr, long low, long high, long val)
         {
             if (low > high)
             {
                 return low;
             }

             long mid = low + (high - low) / 2;

             if (val <= arr[mid])
             {
                 return LowerBound(arr, low, mid - 1, val);
             }

             return LowerBound(arr, mid + 1, high, val);
         }

         public static long UpperBound(long[] arr, long low, long high, long val)
         {
             if (low > high || low == arr.Length)
             {
                 return low;
             }

             long mid = low + (high - low) / 2;

             if (val >= arr[mid])
             {
                 return UpperBound(arr, mid + 1, high, val);
             }

             return UpperBound(arr, low, mid - 1, val);
         }
     }

    public static class EMath
    {
        public static int Mod(int a, int m)
        {
            return (a % m + m) % m;
        }

        public static long Gcd(long a, long b)
        {
            long r;
            while (b != 0)
            {
                r = a % b;
                a = b;
                b = r;
            }

            return a;
        }

        public static long Lcm(long a, long b)
        {
            if (a > b)
            {
                return (a / Gcd(a, b)) * b;
            }

            return (b / Gcd(a, b)) * a;
        }
    }
}


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

    namespace Codeforces
    {
        class TaskA
        {
            static void Main()
            {
                var input = Console.ReadLine().Trim().Split(' ');
                var a = Int32.Parse(input[0]);
                var b = Int32.Parse(input[1]);

                var max = Math.Max(a, b);
                var min = Math.Min(a, b);

                long lenMax = 0;
                long nok = (long)a*b;
                for (long i = 1; i <= min; i++)
                {
                    var q = (max * i) % min;
                    if (q == 0)
                    {
                        lenMax += min;
                        nok = i * max;
                    }
                    else
                        lenMax += q;
                }
                if(lenMax*2 == nok)
                    Console.WriteLine("Equal");
                else if (lenMax * 2 < nok)
                {
                    if (max == b)
                        Console.WriteLine("Dasha");
                    else
                        Console.WriteLine("Masha");
                }
                else
                {
                    if (max == a)
                        Console.WriteLine("Dasha");
                    else
                        Console.WriteLine("Masha");
                }

            }
        }
    }


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

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

	internal class Task
	{
		public void Solve(InputReader sr, TextWriter sw)
		{
			var input = sr.ReadArrayOfInt64();
			var a = input[0];
			var b = input[1];
			var gcd = Gcd((int)a, (int)b);
			var lcm = (a * b) / gcd;
			var dCount = lcm / a;
			var mCount = lcm / b;
			if (a > b)
				dCount++;
			else {
				mCount++;
			}
			if (dCount == mCount)
			{
				sw.WriteLine("Equal");
				return;
			}
			if (dCount > mCount)
			{
				sw.WriteLine("Dasha");
			}
			else {
				sw.WriteLine("Masha");
			}
		}

		private int Gcd(int a, int b)
		{
			if (b == 0)
				return a;

			return Gcd(b, a % b);
		}
	}
}

internal class InputReader : IDisposable
{
	private bool isDispose;
	private readonly TextReader sr;

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

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

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

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

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

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

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

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

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

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

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

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


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

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

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

            int count = 0;

            for (int i = 1; i < p; i++)
            {
                int k = 1;
                for (int j = 1; j < p; j++)
                {
                    k = (k*i)%p;
                    if (k == 1)
                    {
                        if (j == p - 1)
                        {
                            count++;
                        }
                        break;
                    }
                }
            }

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

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


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

namespace Codeforces174_A
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            int p = int.Parse(Console.ReadLine());
            Console.WriteLine(Eiler(Eiler(p)));
        }

        private static int Eiler(int n)
        {
            if (n == 1) return 1;
            int upperBound = (int) Math.Sqrt(n) + 1;
            Dictionary<int, int> canonical_rep = new Dictionary<int, int>();
            for (int i = 2; i <= n; i++)
                while (n%i == 0 && n != 1)
                {
                    if (canonical_rep.ContainsKey(i)) canonical_rep[i]++;
                    else
                        canonical_rep.Add(i, 1);
                    n /= i;
                }
            int result = 1;
            foreach (var divisor in canonical_rep)
            {
                result *= (int) Math.Pow(divisor.Key, divisor.Value) - (int) Math.Pow(divisor.Key, divisor.Value - 1);
            }
            return result;
        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution{
	 static void Main(string[] args) {
             var tmp = Console.ReadLine().Split(' ');
            long d = long.Parse(tmp[0]);
            long k = long.Parse(tmp[1]);
            long a = long.Parse(tmp[2]);
            long b = long.Parse(tmp[3]);
            long t = long.Parse(tmp[4]);

            if (d <= k) {
                Console.WriteLine(a * d);
                return;
            }

            long ans = k * a + (d - k) * b;
            long low = 0, high = 1000000000000;
            while (high - low > 1) {
                long mid = (high + low) / 2;

                long center = Calc(d, k, a, b, t, mid);
                long center1 = Calc(d, k, a, b, t, mid + 1);
                long center_1 = Calc(d, k, a, b, t, mid - 1);

                if (center != -1) ans = Math.Min(ans, center);
                if (center1 != -1) ans = Math.Min(ans, center1);
                if (center_1 != -1) ans = Math.Min(ans, center_1);

                if (center1 == -1) {
                    high = mid;
                } else {
                    if (center1 > center) high = mid; else low = mid;
                }
            }
            Console.WriteLine(ans);
	 }
     private static long Calc(long d, long k, long a, long b, long t, long mid) {
            long withCar = k * mid;

            long remaining = d - withCar;
            if (remaining < 0) {
                return -1;
            }

            long time = k * mid * a + Math.Max(0, (mid - 1)) * t;
             if (remaining <= k) return Math.Min(t+time + remaining * a, time + remaining * b);
            return time + remaining * b;
        }
}


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

namespace Road_to_Post_Office
{
    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)
        {
            long d = Next(), k = Next(), a = Next(), b = Next(), t = Next();

            long cycle = t + a*k;

            long ans;

            if (d <= k)
            {
                ans = a*d;
            }
            else
            {
                d -= k;
                ans = k*a;
                if (cycle < b*k)
                {
                    ans += cycle*(d/k);
                    d %= k;

                    ans += Math.Min(d*b, t + a*d);
                }
                else
                {
                    ans += b*d;
                }
            }

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

        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;
using System.Linq;
using System.Security.Cryptography;
using CompLib.Util;

public class Program
{
    int N, K;
    string S;
    string T;
    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        K = sc.NextInt();
        S = sc.Next();
        T = sc.Next();

        /*
         * sと2文字t
         *
         * sの任意の文字をえらんで別の文字に置き換える
         *
         * k回まで操作
         * tの出現回数最大
         */

        if (T[0] == T[1])
        {
            int cnt = 0;
            foreach (var c in S)
            {
                if (c == T[0]) cnt++;
            }

            int max = Math.Min(cnt + K, N);

            Console.WriteLine((long)max * (max - 1) / 2);
        }
        else
        {

            // iまで見る
            // T[0]の個数
            // 変更回数
            int[,,] dp = new int[N + 1, N + 1, K + 1];
            for (int i = 0; i <= N; i++)
            {
                for (int j = 0; j <= N; j++)
                {
                    for (int k = 0; k <= K; k++)
                    {
                        dp[i, j, k] = int.MinValue;
                    }
                }
            }

            dp[0, 0, 0] = 0;
            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j <= N; j++)
                {
                    for (int k = 0; k <= K; k++)
                    {
                        if (dp[i, j, k] == int.MinValue) continue;
                        if (S[i] == T[0])
                        {
                            dp[i + 1, j + 1, k] = Math.Max(dp[i + 1, j + 1, k], dp[i, j, k]);
                        }
                        else if (k + 1 <= K)
                        {
                            dp[i + 1, j + 1, k + 1] = Math.Max(dp[i + 1, j + 1, k + 1], dp[i, j, k]);
                        }

                        if (S[i] == T[1])
                        {
                            dp[i + 1, j, k] = Math.Max(dp[i + 1, j, k], dp[i, j, k] + j);
                        }
                        else if (k + 1 <= K)
                        {
                            dp[i + 1, j, k + 1] = Math.Max(dp[i + 1, j, k + 1], dp[i, j, k] + j);
                        }

                        dp[i + 1, j, k] = Math.Max(dp[i + 1, j, k], dp[i, j, k]);
                    }
                }
            }

            int ans = int.MinValue;
            for (int j = 0; j <= N; j++)
            {
                for (int k = 0; k <= K; k++)
                {
                    ans = Math.Max(ans, dp[N, j, k]);
                }
            }

            Console.WriteLine(ans);
        }
    }

    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()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

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

            return _line[_index++];
        }

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

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

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

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


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;
using Library;

namespace Program
{
    public static class ProblemF
    {
        static bool SAIKI = false;
        static public int numberOfRandomCases = 0;
        static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker)
        {
        }
        static public void Solve()
        {
            var n = NN;
            var k = NN;
            var s = NS;
            var t = NS;
            var dp = new long[n + 1, n + 2, k + 2];
            for (var i = 0; i <= n; i++)
            {
                for (var j = 0; j <= n; j++)
                {
                    for (var x = 0; x <= k; x++)
                    {
                        dp[i, j, x] = long.MinValue;
                    }
                }
            }
            dp[0, 0, 0] = 0;
            var ans = 0L;
            for (var i = 0; i < n; i++)
            {
                for (var j = 0; j <= n; j++)
                {
                    for (var x = 0; x <= k; x++)
                    {
                        if (s[i] == t[0])
                        {
                            dp[i + 1, j + 1, x] = Max(dp[i + 1, j + 1, x], dp[i, j, x]);
                        }
                        if (s[i] == t[1])
                        {
                            dp[i + 1, j, x] = Max(dp[i + 1, j, x], dp[i, j, x] + j);
                        }
                        if (s[i] == t[0] && s[i] == t[1])
                        {
                            dp[i + 1, j + 1, x] = Max(dp[i + 1, j + 1, x], dp[i, j, x] + j);
                        }
                        if (t[0] == t[1])
                        {
                            dp[i + 1, j + 1, x + 1] = Max(dp[i + 1, j + 1, x + 1], dp[i, j, x] + j);
                        }
                        dp[i + 1, j, x + 1] = Max(dp[i + 1, j, x + 1], dp[i, j, x] + j);
                        dp[i + 1, j + 1, x + 1] = Max(dp[i + 1, j + 1, x + 1], dp[i, j, x]);
                        dp[i + 1, j, x] = Max(dp[i + 1, j, x], dp[i, j, x]);
                    }
                }
            }
            for (var j = 0; j <= n + 1; j++)
            {
                for (var x = 0; x <= k; x++)
                {
                    ans = Max(ans, dp[n, j, x]);
                }
            }
            Console.WriteLine(ans);
        }
        class Printer : StreamWriter
        {
            public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
            public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; }
            public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; }
        }
        static LIB_FastIO fastio = new LIB_FastIODebug();
        static public void Main(string[] args) { if (args.Length == 0) { fastio = new LIB_FastIO(); Console.SetOut(new Printer(Console.OpenStandardOutput())); } if (SAIKI) { var t = new Thread(Solve, 134217728); t.Start(); t.Join(); } else Solve(); Console.Out.Flush(); }
        static long NN => fastio.Long();
        static double ND => fastio.Double();
        static string NS => fastio.Scan();
        static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
        static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
        static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
        static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred);
        static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n);
        static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c);
        static IOrderedEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x, _ => xorshift);
        static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x.OrderByRand(), e => e);
        static IOrderedEnumerable<T1> OrderBy<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderBy(x.OrderByRand(), selector);
        static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x) => Enumerable.OrderByDescending(x.OrderByRand(), e => e);
        static IOrderedEnumerable<T1> OrderByDescending<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderByDescending(x.OrderByRand(), selector);
        static IOrderedEnumerable<string> OrderBy(this IEnumerable<string> x) => x.OrderByRand().OrderBy(e => e, StringComparer.OrdinalIgnoreCase);
        static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderBy(selector, StringComparer.OrdinalIgnoreCase);
        static IOrderedEnumerable<string> OrderByDescending(this IEnumerable<string> x) => x.OrderByRand().OrderByDescending(e => e, StringComparer.OrdinalIgnoreCase);
        static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderByDescending(selector, StringComparer.OrdinalIgnoreCase);
        static string Join<T>(this IEnumerable<T> x, string separator = "") => string.Join(separator, x);
        static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } }
        static IEnumerator<uint> _xsi = _xsc();
        static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } }
    }
}
namespace Library {
    class LIB_FastIO
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_FastIO() { str = Console.OpenStandardInput(); }
        readonly Stream str;
        readonly byte[] buf = new byte[1024];
        int len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream
        {
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            get { return isEof; }
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        byte read()
        {
            if (isEof) throw new EndOfStreamException();
            if (ptr >= len)
            {
                ptr = 0;
                if ((len = str.Read(buf, 0, 1024)) <= 0)
                {
                    isEof = true;
                    return 0;
                }
            }
            return buf[ptr++];
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        char Char()
        {
            byte b = 0;
            do b = read();
            while (b < 33 || 126 < b);
            return (char)b;
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        virtual public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        virtual public long Long()
        {
            long ret = 0; byte b = 0; var ng = false;
            do b = read();
            while (b != '-' && (b < '0' || '9' < b));
            if (b == '-') { ng = true; b = read(); }
            for (; true; b = read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = ret * 10 + b - '0';
            }
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        virtual public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); }
    }
    class LIB_FastIODebug : LIB_FastIO
    {
        Queue<string> param = new Queue<string>();
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_FastIODebug() { }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public override string Scan() => NextString();
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public override long Long() => long.Parse(NextString());
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public override double Double() => double.Parse(NextString());
    }
}