#define Online
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;
using System.Threading;

namespace CF
{
    delegate double F(double x);
    delegate decimal Fdec(decimal x);

    class Program
    {

        static void Main(string[] args)
        {

#if FileIO
            StreamReader sr = new StreamReader("input.txt");
            StreamWriter sw = new StreamWriter("output.txt");
            Console.SetIn(sr);
            Console.SetOut(sw);
#endif

            long n, m, x, y, a, b;
            string[] input = ReadArray();
            n = long.Parse(input[0]);
            m = long.Parse(input[1]);
            x = long.Parse(input[2]);
            y = long.Parse(input[3]);
            a = long.Parse(input[4]);
            b = long.Parse(input[5]);

            long gcd = MyMath.GCD(a, b);
            a /= gcd;
            b /= gcd;

            long left = 1;
            long right = m;

            long mid;
            while (left < right)
            {
                mid = left + ((right - left) >> 1);
                if (mid * a >= m || mid * b >= n)
                {
                    right = mid;
                }
                else
                {
                    left = mid + 1;
                }
            }
            if (!(left * a <= m && left * b <= n))
                left--;

            long w, h;
            w = left * a;
            h = left * b;
            long x1, y1, x2, y2;

            if (x - (w % 2 == 0 ? w / 2 : w / 2 + 1) >= 0)
            {
                if (x + w / 2 > m)
                {
                    x1 = x - (w % 2 == 0 ? w / 2 : w / 2 + 1);
                    x1 -= (x1 + w - m);
                    x2 = x1 + w;
                }
                else
                {
                    x1 = x - (w % 2 == 0 ? w / 2 : w / 2 + 1);
                    x2 = x1 + w;
                }
            }
            else
            {
                x1 = 0;
                x2 = w;
            }
            if (y - (h % 2 == 0 ? h / 2 : h / 2 + 1) >= 0)
            {
                if (y + h / 2 > n)
                {
                    y1 = y - (h % 2 == 0 ? h / 2 : h / 2 + 1);
                    y1 -= (y1 + h - n);
                    y2 = y1 + h;
                }
                else
                {
                    y1 = y - (h % 2 == 0 ? h / 2 : h / 2 + 1);
                    y2 = y1 + h;
                }
            }
            else
            {
                y1 = 0;
                y2 = h;
            }
            Console.WriteLine(x1 + " " + y1 + " " + x2 + " " + y2);
#if Online
            Console.ReadLine();
#endif

#if FileIO
            sr.Close();
            sw.Close();
#endif
        }

        static string[] ReadArray()
        {
            return Console.ReadLine().Split(' ');
        }

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

    public static class MyMath
    {
        public static long BinPow(long a, long n, long mod)
        {
            long res = 1;
            while (n > 0)
            {
                if ((n & 1) == 1)
                {
                    res = (res * a) % mod;
                }
                a = (a * a) % mod;
                n >>= 1;
            }
            return res;
        }

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

        public static int GCD(int a, int b)
        {
            while (b != 0) b = a % (a = b);
            return a;
        }

        public static long LCM(long a, long b)
        {
            return (a * b) / GCD(a, b);
        }

        public static int LCM(int a, int b)
        {
            return (a * b) / GCD(a, b);
        }
    }

    public class SegmentTree
    {
        int[] v_min;
        int[] v_max;
        int[] mas;
        public void BuildTree(int[] a)
        {
            int n = a.Length - 1;
            int z = 0;
            while (n >= 2)
            {
                z++;
                n >>= 1;
            }
            n = 1 << (z + 1);
            v_min = new int[n << 1];
            v_max = new int[n << 1];
            mas = new int[n << 1];
            for (int i = n; i < n + a.Length; i++)
                v_min[i] = a[i - n];
            for (int i = n + a.Length; i < v_min.Length; i++)
                v_min[i] = int.MaxValue;
            for (int i = n - 1; i > 0; i--)
                v_min[i] = Math.Min(v_min[(i << 1)], v_min[(i << 1) + 1]);

            for (int i = n; i < n + a.Length; i++)
                v_max[i] = a[i - n];
            for (int i = n + a.Length; i < v_max.Length; i++)
                v_max[i] = int.MinValue;
            for (int i = n - 1; i > 0; i--)
                v_max[i] = Math.Max(v_max[(i << 1)], v_max[(i << 1) + 1]);

        }
        //nil
        public int RMQ_MIN(int l, int r)
        {
            int ans = int.MaxValue;
            l += v_min.Length >> 1;
            r += v_min.Length >> 1;
            const int o = 1;
            while (l <= r)
            {
                if ((l & 1) == o)
                    ans = Math.Min(ans, v_min[l]);
                if (!((r & 1) == 0))
                    ans = Math.Min(ans, v_min[r]);
                l = (l + 1) >> 1;
                r = (r - 1) >> 1;
            }
            return ans;
        }

        public int RMQ_MAX(int l, int r)
        {
            int ans = int.MinValue;
            l += v_max.Length >> 1;
            r += v_max.Length >> 1;
            const int o = 1;
            while (l <= r)
            {
                if ((l & 1) == o)
                    ans = Math.Max(ans, v_max[l]);
                if (!((r & 1) == 0))
                    ans = Math.Max(ans, v_max[r]);
                l = (l + 1) >> 1;
                r = (r - 1) >> 1;
            }
            return ans;
        }

        public void Put(int l, int r, int op)
        {
            l += mas.Length >> 1;
            r += mas.Length >> 1;
            while (l <= r)
            {
                if (l % 2 != 0)
                    mas[l] = op;
                if (r % 2 == 0)
                    mas[r] = op;
                l = (l + 1) >> 1;
                r = (r - 1) >> 1;
            }
        }

        public int Get(int x)
        {
            x += mas.Length >> 1;
            int ans = int.MinValue;
            while (x > 0)
            {
                ans = Math.Max(mas[x], ans);
                x >>= 1;
            }
            return ans;
        }

        public void Update(int i, int x)
        {
            i += v_min.Length >> 1;
            v_min[i] = x;
            v_max[i] = x;
            i >>= 1;
            while (i > 0)
            {
                v_min[i] = Math.Min(v_min[(i << 1)], v_min[(i << 1) + 1]);
                v_max[i] = Math.Max(v_max[(i << 1)], v_max[(i << 1) + 1]);
                i >>= 1;
            }
        }
    }
    class Edge
    {
        public int a;
        public int b;
        public int w;

        public Edge(int a, int b, int w)
        {
            this.a = a;
            this.b = b;
            this.w = w;
        }
    }
    class Graph
    {
        public List<List<int>> g = new List<List<int>>();
        public List<Edge> e = new List<Edge>();
        public Stack<int> s;
        public List<bool> u;
        public List<int> d; //длина
        public List<int> p; //путь
        public Queue<int> q;
        public int n;
        public int start;
        public int finish;
        public Graph(int n)
        {
            for (int i = 0; i <= n; i++)
                g.Add(new List<int>());
            p = new List<int>();
            d = new List<int>();
            for (int i = 0; i <= n; i++)
                p.Add(-1);
            for (int i = 0; i <= n; i++)
                d.Add(-1);
            u = new List<bool>();
            for (int i = 0; i <= n; i++)
                u.Add(true);
            this.n = n;
        }

        public bool dfs1(int v)
        {
            u[v] = false;
            for (int i = 0; i < g[v].Count; i++)
            {
                if (u[g[v][i]])
                {
                    p[g[v][i]] = v;
                    if (dfs1(g[v][i])) return true;
                }
                else
                {
                    if (p[v] != g[v][i])
                    {
                        start = v;
                        finish = g[v][i];
                        return true;
                    }
                }
            }
            return false;
        }

        public void dfs2(int v)
        {
            s = new Stack<int>();
            s.Push(v);
            int cur;
            bool all;
            while (s.Count != 0)
            {
                cur = s.Peek();
                all = true;
                for (int i = 0; i < g[cur].Count; i++)
                {
                    if (d[g[cur][i]] == -1)
                    {
                        s.Push(g[cur][i]);
                        d[g[cur][i]] = d[cur] + 1;
                        all = false;
                    }
                }
                if (all)
                    s.Pop();
            }
        }

        public void DFS(int v)
        {
            s = new Stack<int>();

            s.Push(v);
            int cur;
            bool all;
            while (s.Count != 0)
            {
                cur = s.Peek();
                u[cur] = false;
                all = true;
                for (int i = 0; i < g[cur].Count; i++)
                {
                    if (u[g[cur][i]])
                    {
                        all = false;
                        p[g[cur][i]] = cur;
                        s.Push(g[cur][i]);
                    }
                    else
                    {
                        if (p[cur] != g[cur][i])
                        {
                            start = cur;
                            finish = g[cur][i];
                            return;
                        }
                    }
                }
                if (all)
                    s.Pop();
            }
        }

        public void BFS(params int[] v)
        {
            q = new Queue<int>();
            u = new List<bool>();
            d = new List<int>();
            p = new List<int>();

            for (int i = 0; i <= n; i++)
            {
                u.Add(true);
                d.Add(0);
                p.Add(0);
            }

            q.Enqueue(v[0]);
            u[v[0]] = false;
            int cur;

            while (q.Count != 0)
            {
                cur = q.Dequeue();
                for (int i = 0; i < g[cur].Count; i++)
                    if (u[g[cur][i]])
                    {
                        q.Enqueue(g[cur][i]);
                        u[g[cur][i]] = false;
                        p[g[cur][i]] = cur;
                        d[g[cur][i]] = d[cur] + 1;
                    }
            }

            int from = v[1];
            string path = from + "";
            while (p[from] != 0)
            {
                path = p[from] + " " + path;
                from = p[from];
            }
            Console.WriteLine(d[v[1]] + " : " + path);
        }

        public void FordBellman(params int[] v)
        {
            d = new List<int>();
            p = new List<int>();
            for (int i = 0; i <= n; i++)
            {
                d.Add(int.MaxValue);
                p.Add(0);
            }
            d[v[0]] = 0;

            for (int i = 0; i < n - 1; i++)
            {
                for (int j = 0; j < e.Count; j++)
                {
                    if (d[e[j].a] != int.MaxValue)
                    {
                        if (d[e[j].a] + e[j].w < d[e[j].b])
                        {
                            d[e[j].b] = d[e[j].a] + e[j].w;
                            p[e[j].b] = e[j].a;
                        }
                    }
                }
            }

            int from = v[1];

            if (d[from] == int.MaxValue)
            {
                Console.WriteLine("Can't find the minimal path");
                return;
            }

            string ans = from + "";
            while (p[from] != 0)
            {
                ans = p[from] + " " + ans;
                from = p[from];
            }

            Console.WriteLine(d[v[1]] + " : " + ans);
        }
    }
    static class ArrayUtils
    {
        public static int BinarySearch(int[] a, int val)
        {
            int left = 0;
            int right = a.Length - 1;
            int mid;

            while (left < right)
            {
                mid = left + ((right - left) >> 1);
                if (val <= a[mid])
                {
                    right = mid;
                }
                else
                {
                    left = mid + 1;
                }
            }

            if (a[left] == val)
                return left;
            else
                return -1;
        }

        public static double Bisection(F f, double left, double right, double eps)
        {
            double mid;
            while (right - left > eps)
            {
                mid = left + ((right - left) / 2d);
                if (Math.Sign(f(mid)) != Math.Sign(f(left)))
                    right = mid;
                else
                    left = mid;
            }
            return (left + right) / 2d;
        }

        public static decimal TernarySearchDec(Fdec f, decimal eps, decimal l, decimal r, bool isMax)
        {
            decimal m1, m2;
            while (r - l > eps)
            {
                m1 = l + (r - l) / 3m;
                m2 = r - (r - l) / 3m;
                if (f(m1) < f(m2))
                    if (isMax)
                        l = m1;
                    else
                        r = m2;
                else
                    if (isMax)
                        r = m2;
                    else
                        l = m1;
            }
            return r;
        }

        public static double TernarySearch(F f, double eps, double l, double r, bool isMax)
        {
            double m1, m2;
            while (r - l > eps)
            {
                m1 = l + (r - l) / 3d;
                m2 = r - (r - l) / 3d;
                if (f(m1) < f(m2))
                    if (isMax)
                        l = m1;
                    else
                        r = m2;
                else
                    if (isMax)
                        r = m2;
                    else
                        l = m1;
            }
            return r;
        }

        public static void Merge<T>(T[] A, int p, int q, int r, T[] L, T[] R) where T : IComparable<T>
        {
            for (int i = p; i <= q; i++)
                L[i] = A[i];
            for (int i = q + 1; i <= r; i++)
                R[i] = A[i];

            for (int k = p, i = p, j = q + 1; k <= r; k++)
            {
                if (i > q)
                {
                    for (; k <= r; k++, j++)
                        A[k] = R[j];
                    return;
                }
                if (j > r)
                {
                    for (; k <= r; k++, i++)
                        A[k] = L[i];
                    return;
                }
                if (L[i].CompareTo(R[j]) <= 0)
                {
                    A[k] = L[i];
                    i++;
                }
                else
                {
                    A[k] = R[j];
                    j++;
                }
            }
        }

        public static void Merge_Sort<T>(T[] A, int p, int r, T[] L, T[] R) where T : IComparable<T>
        {
            if (p >= r) return;
            int q = p + ((r - p) >> 1);
            Merge_Sort(A, p, q, L, R);
            Merge_Sort(A, q + 1, r, L, R);
            Merge(A, p, q, r, L, R);
        }

        static void Shake<T>(T[] a)
        {
            Random rnd = new Random(Environment.TickCount);
            T temp;
            int b, c;
            for (int i = 0; i < a.Length; i++)
            {
                b = rnd.Next(0, a.Length);
                c = rnd.Next(0, a.Length);
                temp = a[b];
                a[b] = a[c];
                a[c] = temp;
            }
        }
    }
}


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

namespace CodeForces
{
    class Prob303B
    {
        //Your task is to find a maximum sub-rectangle on the grid (x1, y1, x2, y2) so that it contains the given point (x, y),
        //and its length-width ratio is exactly (a, b). In other words the following conditions must hold:
        //0 ≤ x1 ≤ x ≤ x2 ≤ n, 0 ≤ y1 ≤ y ≤ y2 ≤ m, (x2-x1)/(y2-y1)=a/b.

        //The sides of this sub-rectangle should be parallel to the axes. And values x1, y1, x2, y2 should be integers.

        //If there are multiple solutions, find the rectangle which is closest to (x, y). Here "closest" means the Euclid
        //distance between (x, y) and the center of the rectangle is as small as possible. If there are still multiple
        //solutions, find the lexicographically minimum one. Here "lexicographically minimum" means that we should consider
        //the sub-rectangle as sequence of integers (x1, y1, x2, y2), so we can choose the lexicographically minimum one.
        class Pair
        {
            int x;
            int y;

            public Pair()
            {
                x = 0;
                y = 0;
            }

            public Pair(int xx, int yy)
            {
                x = xx;
                y = yy;
            }

            public int X
            {
                get { return x; }
                set { x = value; }
            }

            public int Y
            {
                get { return y; }
                set { y = value; }
            }

            public Pair makeBigger(int n)
            {
                return new Pair(x * n, y * n);
            }

            public Pair shift(Pair shiftBy)
            {
                return new Pair(x + shiftBy.X, y + shiftBy.Y);
            }

            public Pair simplify()
            {
                int a = x;
                int b = y;
                int rem;

                while (b != 0)
                {
                    rem = a % b;
                    a = b;
                    b = rem;
                }
                return new Pair(x / a, y / a);
            }

            public override String ToString()
            {
                return x + " " + y;
            }
        }

        class Rectangle
        {
            Pair bottomLeft;
            Pair upperRight;
            int width;
            int height;

            public Rectangle()
            {
                bottomLeft = new Pair();
                upperRight = new Pair();
                width = 0;
                height = 0;
            }

            public Rectangle(Pair bl, Pair ur)
            {
                bottomLeft = bl;
                upperRight = ur;
                width = upperRight.X - bottomLeft.X;
                height = upperRight.Y - bottomLeft.Y;
            }

            public Pair getLargestFit(Pair ratio)
            {
                Pair p = new Pair(ratio.X, ratio.Y);
                int max = Math.Min(width / p.X, height / p.Y);
                return p.makeBigger(max);
            }

            public Rectangle getClosestRectangle(Pair point, Pair dims)
            {
                Pair bottomLeftCorner = new Pair();

                bottomLeftCorner.X = point.X - (dims.X / 2) - (dims.X & 1);
                if (bottomLeftCorner.X < 0)
                {
                    bottomLeftCorner.X = 0;
                }
                else if (bottomLeftCorner.X + dims.X > width)
                {
                    bottomLeftCorner.X = width - dims.X;
                }

                bottomLeftCorner.Y = point.Y - (dims.Y / 2) - (dims.Y & 1);
                if (bottomLeftCorner.Y < 0)
                {
                    bottomLeftCorner.Y = 0;
                }
                else if (bottomLeftCorner.Y + dims.Y > height)
                {
                    bottomLeftCorner.Y = width - dims.Y;
                }

                return new Rectangle(bottomLeftCorner, bottomLeftCorner.shift(dims));
            }

            public override String ToString()
            {
                return bottomLeft.ToString() + " " + upperRight.ToString();
            }
        }

        Rectangle housing;
        Pair point;
        Pair ratio;

        public Prob303B(int n, int m, int x, int y, int a, int b)
        {
            housing = new Rectangle(new Pair(0, 0), new Pair(n, m));
            point = new Pair(x, y);
            ratio = new Pair(a, b);
        }

        public String solve()
        {
            Pair rectDims = housing.getLargestFit(ratio.simplify());
            Rectangle result = housing.getClosestRectangle(point, rectDims);
            return result.ToString();
        }

        public override String ToString()
        {
            return housing.ToString() + " " + point.ToString() + " " + ratio.ToString();
        }

        static void Main(string[] args)
        {
            String line = Console.ReadLine();
            String[] temp = line.Split(' ');
            int[] vals = new int[temp.Length];
            for (int i = 0; i < vals.Length; ++i)
            {
                vals[i] = Convert.ToInt32(temp[i]);
            }
            Prob303B prob = new Prob303B(vals[0], vals[1], vals[2], vals[3], vals[4], vals[5]);
            Console.WriteLine(prob.solve());
        }
    }
}


#define FileIO
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;
using System.Threading;

namespace CF
{
    delegate double F(double x);
    delegate decimal Fdec(decimal x);

    class Program
    {

        static void Main(string[] args)
        {

#if FileIO
            StreamReader sr = new StreamReader("input.txt");
            StreamWriter sw = new StreamWriter("output.txt");
            Console.SetIn(sr);
            Console.SetOut(sw);
#endif

            long n, m, x, y, a, b;
            string[] input = ReadArray();
            n = long.Parse(input[0]);
            m = long.Parse(input[1]);
            x = long.Parse(input[2]);
            y = long.Parse(input[3]);
            a = long.Parse(input[4]);
            b = long.Parse(input[5]);

            long gcd = MyMath.GCD(a, b);
            a /= gcd;
            b /= gcd;

            long left = 1;
            long right = m;

            long mid;
            while (left < right)
            {
                mid = left + ((right - left) >> 1);
                if (mid * a >= n || mid * b >= m)
                {
                    right = mid;
                }
                else
                {
                    left = mid + 1;
                }
            }
            if (!(left * a <= n && left * b <= m))
                left--;

            long w, h;
            w = left * a;
            h = left * b;
            long x1, y1, x2, y2;
            x1 = x2 = y1 = y2 = 0;

            if (x + w / 2 > n)
            {
                x1 = x - (w % 2L == 0 ? w / 2L : w / 2L + 1L) - (x + w / 2L - n);
                x2 = x1 + w;
            }
            else
            {
                if (x - (w % 2 == 0 ? w / 2 : w / 2 + 1) < 0)
                {
                    x1 = 0;
                    x2 = w;
                }
                else
                {
                    x1 = x - (w % 2L == 0 ? w / 2L : w / 2L + 1L);
                    x2 = x1 + w;
                }
            }
            if (y + h / 2 > m)
            {
                y1 = y - (h % 2L == 0 ? h / 2L : h / 2L + 1L) - (y + h / 2L - m);
                y2 = y1 + h;
            }
            else
            {
                if (y - (h % 2 == 0 ? h / 2 : h / 2 + 1) < 0)
                {
                    y1 = 0;
                    y2 = h;
                }
                else
                {
                    y1 = y - (h % 2L == 0 ? h / 2L : h / 2L + 1L);
                    y2 = y1 + h;
                }
            }

            Console.WriteLine(x1 + " " + y1 + " " + x2 + " " + y2);
#if Online
            Console.ReadLine();
#endif

#if FileIO
            sr.Close();
            sw.Close();
#endif
        }

        static string[] ReadArray()
        {
            return Console.ReadLine().Split(' ');
        }

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

    public static class MyMath
    {
        public static long BinPow(long a, long n, long mod)
        {
            long res = 1;
            while (n > 0)
            {
                if ((n & 1) == 1)
                {
                    res = (res * a) % mod;
                }
                a = (a * a) % mod;
                n >>= 1;
            }
            return res;
        }

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

        public static int GCD(int a, int b)
        {
            while (b != 0) b = a % (a = b);
            return a;
        }

        public static long LCM(long a, long b)
        {
            return (a * b) / GCD(a, b);
        }

        public static int LCM(int a, int b)
        {
            return (a * b) / GCD(a, b);
        }
    }

    public class SegmentTree
    {
        int[] v_min;
        int[] v_max;
        int[] mas;
        public void BuildTree(int[] a)
        {
            int n = a.Length - 1;
            int z = 0;
            while (n >= 2)
            {
                z++;
                n >>= 1;
            }
            n = 1 << (z + 1);
            v_min = new int[n << 1];
            v_max = new int[n << 1];
            mas = new int[n << 1];
            for (int i = n; i < n + a.Length; i++)
                v_min[i] = a[i - n];
            for (int i = n + a.Length; i < v_min.Length; i++)
                v_min[i] = int.MaxValue;
            for (int i = n - 1; i > 0; i--)
                v_min[i] = Math.Min(v_min[(i << 1)], v_min[(i << 1) + 1]);

            for (int i = n; i < n + a.Length; i++)
                v_max[i] = a[i - n];
            for (int i = n + a.Length; i < v_max.Length; i++)
                v_max[i] = int.MinValue;
            for (int i = n - 1; i > 0; i--)
                v_max[i] = Math.Max(v_max[(i << 1)], v_max[(i << 1) + 1]);

        }
        //nil
        public int RMQ_MIN(int l, int r)
        {
            int ans = int.MaxValue;
            l += v_min.Length >> 1;
            r += v_min.Length >> 1;
            const int o = 1;
            while (l <= r)
            {
                if ((l & 1) == o)
                    ans = Math.Min(ans, v_min[l]);
                if (!((r & 1) == 0))
                    ans = Math.Min(ans, v_min[r]);
                l = (l + 1) >> 1;
                r = (r - 1) >> 1;
            }
            return ans;
        }

        public int RMQ_MAX(int l, int r)
        {
            int ans = int.MinValue;
            l += v_max.Length >> 1;
            r += v_max.Length >> 1;
            const int o = 1;
            while (l <= r)
            {
                if ((l & 1) == o)
                    ans = Math.Max(ans, v_max[l]);
                if (!((r & 1) == 0))
                    ans = Math.Max(ans, v_max[r]);
                l = (l + 1) >> 1;
                r = (r - 1) >> 1;
            }
            return ans;
        }

        public void Put(int l, int r, int op)
        {
            l += mas.Length >> 1;
            r += mas.Length >> 1;
            while (l <= r)
            {
                if (l % 2 != 0)
                    mas[l] = op;
                if (r % 2 == 0)
                    mas[r] = op;
                l = (l + 1) >> 1;
                r = (r - 1) >> 1;
            }
        }

        public int Get(int x)
        {
            x += mas.Length >> 1;
            int ans = int.MinValue;
            while (x > 0)
            {
                ans = Math.Max(mas[x], ans);
                x >>= 1;
            }
            return ans;
        }

        public void Update(int i, int x)
        {
            i += v_min.Length >> 1;
            v_min[i] = x;
            v_max[i] = x;
            i >>= 1;
            while (i > 0)
            {
                v_min[i] = Math.Min(v_min[(i << 1)], v_min[(i << 1) + 1]);
                v_max[i] = Math.Max(v_max[(i << 1)], v_max[(i << 1) + 1]);
                i >>= 1;
            }
        }
    }
    class Edge
    {
        public int a;
        public int b;
        public int w;

        public Edge(int a, int b, int w)
        {
            this.a = a;
            this.b = b;
            this.w = w;
        }
    }
    class Graph
    {
        public List<List<int>> g = new List<List<int>>();
        public List<Edge> e = new List<Edge>();
        public Stack<int> s;
        public List<bool> u;
        public List<int> d; //длина
        public List<int> p; //путь
        public Queue<int> q;
        public int n;
        public int start;
        public int finish;
        public Graph(int n)
        {
            for (int i = 0; i <= n; i++)
                g.Add(new List<int>());
            p = new List<int>();
            d = new List<int>();
            for (int i = 0; i <= n; i++)
                p.Add(-1);
            for (int i = 0; i <= n; i++)
                d.Add(-1);
            u = new List<bool>();
            for (int i = 0; i <= n; i++)
                u.Add(true);
            this.n = n;
        }

        public bool dfs1(int v)
        {
            u[v] = false;
            for (int i = 0; i < g[v].Count; i++)
            {
                if (u[g[v][i]])
                {
                    p[g[v][i]] = v;
                    if (dfs1(g[v][i])) return true;
                }
                else
                {
                    if (p[v] != g[v][i])
                    {
                        start = v;
                        finish = g[v][i];
                        return true;
                    }
                }
            }
            return false;
        }

        public void dfs2(int v)
        {
            s = new Stack<int>();
            s.Push(v);
            int cur;
            bool all;
            while (s.Count != 0)
            {
                cur = s.Peek();
                all = true;
                for (int i = 0; i < g[cur].Count; i++)
                {
                    if (d[g[cur][i]] == -1)
                    {
                        s.Push(g[cur][i]);
                        d[g[cur][i]] = d[cur] + 1;
                        all = false;
                    }
                }
                if (all)
                    s.Pop();
            }
        }

        public void DFS(int v)
        {
            s = new Stack<int>();

            s.Push(v);
            int cur;
            bool all;
            while (s.Count != 0)
            {
                cur = s.Peek();
                u[cur] = false;
                all = true;
                for (int i = 0; i < g[cur].Count; i++)
                {
                    if (u[g[cur][i]])
                    {
                        all = false;
                        p[g[cur][i]] = cur;
                        s.Push(g[cur][i]);
                    }
                    else
                    {
                        if (p[cur] != g[cur][i])
                        {
                            start = cur;
                            finish = g[cur][i];
                            return;
                        }
                    }
                }
                if (all)
                    s.Pop();
            }
        }

        public void BFS(params int[] v)
        {
            q = new Queue<int>();
            u = new List<bool>();
            d = new List<int>();
            p = new List<int>();

            for (int i = 0; i <= n; i++)
            {
                u.Add(true);
                d.Add(0);
                p.Add(0);
            }

            q.Enqueue(v[0]);
            u[v[0]] = false;
            int cur;

            while (q.Count != 0)
            {
                cur = q.Dequeue();
                for (int i = 0; i < g[cur].Count; i++)
                    if (u[g[cur][i]])
                    {
                        q.Enqueue(g[cur][i]);
                        u[g[cur][i]] = false;
                        p[g[cur][i]] = cur;
                        d[g[cur][i]] = d[cur] + 1;
                    }
            }

            int from = v[1];
            string path = from + "";
            while (p[from] != 0)
            {
                path = p[from] + " " + path;
                from = p[from];
            }
            Console.WriteLine(d[v[1]] + " : " + path);
        }

        public void FordBellman(params int[] v)
        {
            d = new List<int>();
            p = new List<int>();
            for (int i = 0; i <= n; i++)
            {
                d.Add(int.MaxValue);
                p.Add(0);
            }
            d[v[0]] = 0;

            for (int i = 0; i < n - 1; i++)
            {
                for (int j = 0; j < e.Count; j++)
                {
                    if (d[e[j].a] != int.MaxValue)
                    {
                        if (d[e[j].a] + e[j].w < d[e[j].b])
                        {
                            d[e[j].b] = d[e[j].a] + e[j].w;
                            p[e[j].b] = e[j].a;
                        }
                    }
                }
            }

            int from = v[1];

            if (d[from] == int.MaxValue)
            {
                Console.WriteLine("Can't find the minimal path");
                return;
            }

            string ans = from + "";
            while (p[from] != 0)
            {
                ans = p[from] + " " + ans;
                from = p[from];
            }

            Console.WriteLine(d[v[1]] + " : " + ans);
        }
    }
    static class ArrayUtils
    {
        public static int BinarySearch(int[] a, int val)
        {
            int left = 0;
            int right = a.Length - 1;
            int mid;

            while (left < right)
            {
                mid = left + ((right - left) >> 1);
                if (val <= a[mid])
                {
                    right = mid;
                }
                else
                {
                    left = mid + 1;
                }
            }

            if (a[left] == val)
                return left;
            else
                return -1;
        }

        public static double Bisection(F f, double left, double right, double eps)
        {
            double mid;
            while (right - left > eps)
            {
                mid = left + ((right - left) / 2d);
                if (Math.Sign(f(mid)) != Math.Sign(f(left)))
                    right = mid;
                else
                    left = mid;
            }
            return (left + right) / 2d;
        }

        public static decimal TernarySearchDec(Fdec f, decimal eps, decimal l, decimal r, bool isMax)
        {
            decimal m1, m2;
            while (r - l > eps)
            {
                m1 = l + (r - l) / 3m;
                m2 = r - (r - l) / 3m;
                if (f(m1) < f(m2))
                    if (isMax)
                        l = m1;
                    else
                        r = m2;
                else
                    if (isMax)
                        r = m2;
                    else
                        l = m1;
            }
            return r;
        }

        public static double TernarySearch(F f, double eps, double l, double r, bool isMax)
        {
            double m1, m2;
            while (r - l > eps)
            {
                m1 = l + (r - l) / 3d;
                m2 = r - (r - l) / 3d;
                if (f(m1) < f(m2))
                    if (isMax)
                        l = m1;
                    else
                        r = m2;
                else
                    if (isMax)
                        r = m2;
                    else
                        l = m1;
            }
            return r;
        }

        public static void Merge<T>(T[] A, int p, int q, int r, T[] L, T[] R) where T : IComparable<T>
        {
            for (int i = p; i <= q; i++)
                L[i] = A[i];
            for (int i = q + 1; i <= r; i++)
                R[i] = A[i];

            for (int k = p, i = p, j = q + 1; k <= r; k++)
            {
                if (i > q)
                {
                    for (; k <= r; k++, j++)
                        A[k] = R[j];
                    return;
                }
                if (j > r)
                {
                    for (; k <= r; k++, i++)
                        A[k] = L[i];
                    return;
                }
                if (L[i].CompareTo(R[j]) <= 0)
                {
                    A[k] = L[i];
                    i++;
                }
                else
                {
                    A[k] = R[j];
                    j++;
                }
            }
        }

        public static void Merge_Sort<T>(T[] A, int p, int r, T[] L, T[] R) where T : IComparable<T>
        {
            if (p >= r) return;
            int q = p + ((r - p) >> 1);
            Merge_Sort(A, p, q, L, R);
            Merge_Sort(A, q + 1, r, L, R);
            Merge(A, p, q, r, L, R);
        }

        static void Shake<T>(T[] a)
        {
            Random rnd = new Random(Environment.TickCount);
            T temp;
            int b, c;
            for (int i = 0; i < a.Length; i++)
            {
                b = rnd.Next(0, a.Length);
                c = rnd.Next(0, a.Length);
                temp = a[b];
                a[b] = a[c];
                a[c] = temp;
            }
        }
    }
}


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

namespace CodeForces
{
    class R183_Div2_D
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            int n = int.Parse(s[0]);
            int m = int.Parse(s[1]);
            int x = int.Parse(s[2]);
            int y = int.Parse(s[3]);
            int a = int.Parse(s[4]);
            int b = int.Parse(s[5]);
            int g = GCD(a, b);
            a = a / g;
            b = b / g;

            int xDif = Math.Min(n - x, x - 0);
            int yDif = Math.Min(m - y, y - 0);

            int t = Math.Min(n / a, m / b);
            a *= t;
            b *= t;

            int x1, y1, x2, y2;
            x1 = x - a + (a / 2);
            y1 = y - b + (b / 2);
            x1 = Math.Min(x1, n - a);
            y1 = Math.Min(y1, m - b);
            x1 = Math.Max(x1, 0);
            y1 = Math.Max(y1, 0);
            x2 = x1 + a;
            y2 = y1 + b;
            Console.WriteLine(x1 + " " + y1 + " " + x2 + " " + y2);
        }

        static int GCD(int a, int b)
        {
            for (int i = Math.Min(a, b); i >= 1; i--)
                if (a % i == 0 && b % i == 0)
                    return i;
            return 0;
        }
    }
}


using System;

class Program
{
    static void Main(string[] args)
    {
        var inp = Console.ReadLine().Split(' ');
        int k = int.Parse(inp[0]);
        int q = int.Parse(inp[1]);
        char[,] rep = new char[q, 2];
        for (int i = 0; i < q; i++)
        {
            var inp2 = Console.ReadLine().Split(' ');
            rep[i, 0] = inp2[1][0];
            rep[i, 1] = inp2[0][0];
        }
        char[,] m = new char[7, 270000];
        int r = 1, c = 1, cd = 0;
        m[1, 0] = 'a';
        while (true)
        {
            for (int i = 0; i < c; i++)
            {
                for (int j = 0; j < q; j++)
                {
                    if (rep[j, 0] == m[r, i])
                    {
                        m[r + 1, cd] = rep[j, 1];
                        cd++;
                    }
                }
            }
            c = cd;
            r++;
            if (r == k) break;
            cd = 0;
        }
        Console.WriteLine(cd);
        Console.ReadLine();
    }
}


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

class Program
{
    private static int Go(int s, int n)
    {
        if (n == 0) return 1;

        int ans = 0;

        for (int i = 0; i < 36; i++)
        {
            if ((map[s] & pow2[i]) > 0)
            {
                ans += Go(i / 6, n - 1);
            }
        }

        return ans;
    }

    private static long[] pow2 = new long[64];
    private static long[] map = new long[6];
    private static void Main(string[] args)
    {
        pow2[0] = 1;
        for (int i = 1; i < pow2.Length; i++) pow2[i] = pow2[i - 1] * 2;

        int n = ReadInt();
        int q = ReadInt();

        for (int i = 0; i < q; i++)
        {
            var a = ReadString();
            var b = ReadString();
            map[b[0] - 'a'] |= pow2[(6 * (a[0] - 'a') + (a[1] - 'a'))];
        }

        Console.Write(Go(0, n - 1));
    }

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

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

        return g;
    }

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

        return matrix;
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        return s.ToArray();
    }

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

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

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

        return s;
    }

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

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

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

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

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

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

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

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


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

namespace ConsoleApp
{
    class Program
    {
        // int n = Convert.ToInt32(Console.ReadLine());
        // int[] array = Array.ConvertAll(Console.ReadLine().Split(), Convert.ToInt32);
        // StringBuilder stringBuilder = new StringBuilder();
        // for (int t = Convert.ToInt32(Console.ReadLine()); t > 0; t--)
        // {
        // }
        private static StringBuilder resultBuilder = new StringBuilder();
        public static void Main(string[] args)
        {
            int[] nq = Array.ConvertAll(Console.ReadLine().Split(), Convert.ToInt32);
            string[] input = new string[nq[1]];
            for (int i = 0; i < nq[1]; i++)
            {
                input[i] = Console.ReadLine();
            }
            int[] counter = new int[6];
            for (int i = 0; i < nq[1]; i++)
            {
                counter[input[i][3] - 'a']++;
            }

            long result = 0;
            getResult('a', 2);
            void getResult(char target, int length)
            {
                if (length == nq[0])
                {
                    result += counter[target - 'a'];
                }
                else
                {
                    for (int i = 0; i < nq[1]; i++)
                    {
                        if (input[i][3] == target)
                        {
                            getResult(input[i][0], length + 1);
                        }
                    }
                }
            }
            Console.Write(result);
        }
    }
}


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

namespace ConsoleApplication1
{
    class IndiaHacks2
    {
        static void Main(string[] args)
        {
            //Console.SetIn(new StreamReader(@"D:\Sergey\Code\2.txt"));

            string[] strParams = Console.ReadLine().Split(new char[] { ' ' });
            int n = int.Parse(strParams[0]);
            int q = int.Parse(strParams[1]);

            var a = new List<string>();
            var d = new Dictionary<string, char>(q);
            var g = new Dictionary<char, List<string>>();

            //var ba = new List<string>();

            int k = n;
            long r = 0;

            for (int i = 0; i < q; i++)
            {
                strParams = Console.ReadLine().Split(new char[] { ' ' });
                d[strParams[0]] = strParams[1][0];

                List<string> f;
                if (!g.TryGetValue(strParams[1][0], out f))
                {
                    f = new List<string>();
                    g[strParams[1][0]] = f;
                }
                f.Add(strParams[0]);
            }

            //HashSet<string> h = new HashSet<string>();

            var s = new LinkedList<char[]>();
            var c = new char[n];
            c[n - 1] = 'a';
            s.AddLast(c);
            LinkedListNode<char[]> sp = s.First;
            for (int i = n - 1; i >= 1; i--)
            {
                for (int j = 0, count = s.Count; j < count && sp != null; j++)
                {
                    List<string> f;
                    if (g.TryGetValue(sp.Value[i], out f))
                    {
                        for (k = 1; k < f.Count; k++)
                        {
                            char[] cc = sp.Value.ToArray();
                            cc[i] = f[k][1];
                            cc[i - 1] = f[k][0];
                            s.AddLast(cc);
                        }
                        sp.Value[i] = f[0][1];
                        sp.Value[i - 1] = f[0][0];
                        s.AddLast(sp.Value);
                    }
                    sp = sp.Next;
                    s.RemoveFirst();
                }
            }

            Console.WriteLine(s.Count);
        }//main

    }
}


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

namespace CF317
{
    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(1, sr, sw);
                //Console.ReadKey();
            }
        }
    }

    internal class Task
    {
        public void Solve(int testNumber, InputReader sr, TextWriter sw)
        {
            var input = sr.ReadArray(Int32.Parse);
            var n = input[0];
            var q = input[1];
            var array = new Tuple<string, char>[q];
            for (var i = 0; i < q; i++)
            {
                var next = sr.NextSplitStrings();
                array[i] = new Tuple<string, char>(next[0], next[1][0]);
            }
            var count = 0L;
            var list = new List<char>();
            for (var i = 0; i < q; i++)
            {
                if (array[i].Item2 == 'a')
                {
                    list.Add(array[i].Item1[0]);
                    if (n == 2)
                    {
                        count++;
                    }
                }
            }
            List<char> newList = null;
            for (var i = 3; i <= n; i++)
            {
                newList = new List<char>();
                foreach (var item in list)
                {
                    for (var j = 0; j < q; j++)
                    {
                        if (array[j].Item2 == item)
                        {
                            newList.Add(array[j].Item1[0]);
                            if (i == n)
                            {
                                count++;
                            }
                        }
                    }
                }
                list = newList;
            }
            sw.WriteLine(count);
        }
    }

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

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

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


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

namespace _653B
{
    class Program
    {
        static void Main()
        {
            var s = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var n = s[0];
            var q = s[1];
            Dictionary<string, string> dic = new Dictionary<string, string>();
            for (int i = 0; i < q; i++)
            {
                var s2 = Console.ReadLine().Split();
                dic.Add(s2[0], s2[1]);
            }
            var generator = new string[(int)Math.Pow(6, n)];
            int[] letters = new int[6];
            for (int i = 0; i < generator.Length; i++)
            {
                var str = new StringBuilder();
                for (int j = 0; j < n; j++)
                {
                    str.Append((char)('a' + letters[j]));
                }

                generator[i] = str.ToString();
                for (int j = n-1; j >= 0; j--)
                {
                    letters[j]++;
                    if (letters[j] < 6) break;
                    else { letters[j] = 0; }
                }
            }

            for (int i = 0; i < n - 1; i++ )
            {
                for (int j = 0; j < generator.Length; j++)
                {
                    if (dic.ContainsKey(generator[j].Substring(0, 2)))
                        generator[j] = dic[generator[j].Substring(0, 2)] + generator[j].Substring(2);
                }
            }
            var count = 0;
            for (int j = 0; j < generator.Length; j++)
            {
                if (generator[j] == "a") count++;
            }

            Console.WriteLine(count);
        }
    }
}


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

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

        private static void Main(string[] args)
        {
            string[] ss = reader.ReadLine().Split(' ');
            int n = int.Parse(ss[0]);
            int q = int.Parse(ss[1]);

            int size = 'f' - 'a' + 1;
            var nn = new List<string>[size];
            for (int i = 0; i < nn.Length; i++)
            {
                nn[i] = new List<string>();
            }
            for (int i = 0; i < q; i++)
            {
                ss = reader.ReadLine().Split(' ');
                int index = ss[1][0] - 'a';
                nn[index].Add(ss[0]);
            }
            var set = new HashSet<string> {"a"};

            for (int i = 1; i < n; i++)
            {
                var next = new HashSet<string>();

                foreach (string sss in set)
                {
                    int index = sss[0]-'a';
                    string suff = sss.Substring(1);
                    foreach (string pr in nn[index])
                    {
                        string m = pr + suff;
                        next.Add(m);
                    }
                }

                set = next;
            }

            writer.WriteLine(set.Count);
            writer.Flush();
        }
    }
}


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

//using Algorithms.Set_38;

class Solution
{
    private class Tokenizer
    {
        private string currentString = null;

        private string[] tokens = null;

        private int tokenNumber = 0;

        private static readonly char[] Separators = { ' ' };

        public T NextToken<T>(Func<string, T> parser)
        {
            return parser(this.GetNextToken());
        }

        public string NextToken()
        {
            return this.GetNextToken();
        }

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

        public long NextLong()
        {
            return this.NextToken(long.Parse);
        }

        private string GetNextToken()
        {
            if (this.currentString == null || this.tokenNumber == this.tokens.Length)
            {
                this.currentString = this.GetNextString();

                while (this.currentString != null && this.currentString.Equals(string.Empty))
                {
                    this.currentString = this.GetNextString();
                }

                if (this.currentString == null)
                {
                    throw new Exception("End of input");
                }

                this.tokens = this.currentString.Split(Separators, StringSplitOptions.RemoveEmptyEntries);
                this.tokenNumber = 0;
            }

            return this.tokens[this.tokenNumber++];
        }

        private string GetNextString()
        {
            string content = Console.ReadLine();
            if (content == null)
            {
                return null;
            }

            return content.Trim();
        }
    }

    static void Main()
    {
        //Console.SetIn(new StreamReader(File.OpenRead("input.txt")));
        //StreamWriter writer = new StreamWriter(File.Create("output.txt"));
        //Console.SetOut(writer);

        Tokenizer tokenizer = new Tokenizer();

        int n = tokenizer.NextInt();
        int q = tokenizer.NextInt();

        string[] from = new string[q];
        char[] to = new char[q];

        for (int i=0;i<q;i++)
        {
            from[i] = tokenizer.NextToken();
            to[i] = tokenizer.NextToken()[0];
        }

        Console.WriteLine(Compressing.Solve(n, q, from, to));

        //writer.Close();
    }

    public class Compressing
    {
        private const int LETTERS = 26;

        public static long Solve(int n, int q, string[] from, char[] to)
        {
            long[] current = new long[LETTERS];
            long[] next = new long[LETTERS];
            current[0] = 1;

            for (int i = 0; i < n - 1; i++)
            {
                for (int j = 0; j < q; j++)
                {
                    next[from[j][0] - 'a'] += current[to[j] - 'a'];
                }

                for (int j = 0; j < LETTERS; j++)
                {
                    current[j] = next[j];
                    next[j] = 0;
                }
            }

            long result = 0;
            for (int i = 0; i < LETTERS; i++)
            {
                result += current[i];
            }

            return result;
        }
    }
}


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

namespace codeforces
{
    class Program
    {
        //16:23
        //reading
        static string ReadLine()
        {
            return Console.ReadLine();
        }
        static string[] ReadArray()
        {
            return ReadLine().Split(' ');
        }
        static List<string> ReadList()
        {
            return ReadArray().ToList();
        }
        static List<int> ReadIntList()
        {
            return ReadArray().Select(c => Convert.ToInt32(c)).ToList();
        }
        static List<ulong> ReadULongList()
        {
            return ReadArray().Select(c => Convert.ToUInt64(c)).ToList();
        }

        static Dictionary<string, List<string>> dict;
        static int length;
        static SortedSet<string> res = new SortedSet<string>();

        static void GetResult(string str)
        {
            string key = str[0].ToString();
            if (!dict.ContainsKey(key))
                return;
            List<string> lst = dict[key];
            for (int i = 0; i < lst.Count; i++)
            {
                string newStr = lst[i] + str.Substring(1);
                if (length == newStr.Length)
                    res.Add(newStr);
                else
                {
                    GetResult(newStr);
                }
            }
        }

        static void Main(string[] args)
        {
            string[] input = ReadArray();
            length = Convert.ToInt32(input[0]);
            int n = Convert.ToInt32(input[1]);
            dict = new Dictionary<string, List<string>>();

            for (int i = 0; i < n; i++)
            {
                input = ReadArray();
                if (!dict.ContainsKey(input[1]))
                    dict.Add(input[1], new List<string>());
                dict[input[1]].Add(input[0]);
            }
            GetResult("a");
            Console.WriteLine(res.Count);
        }
    }
}


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

namespace Codeforces
{
    internal class Template
    {
        private void Solve()
        {
            var n = cin.NextInt();
            var q = cin.NextInt();
            var ops = new Dictionary<char, List<char>>();
            for (var i = 0; i < q; i++)
            {
                var a = cin.NextString();
                var b = cin.NextString();
                if (!ops.ContainsKey(b[0]))
                {
                    ops[b[0]] = new List<char>();
                }
                ops[b[0]].Add(a[0]);
            }
            var frontier = new List<char>();
            frontier.Add('a');
            for (var i = 1; i < n; i++)
            {
                var newFrontier = new List<char>();
                foreach (var c in frontier)
                {
                    if (ops.ContainsKey(c))
                    {
                        var list = ops[c];
                        newFrontier.AddRange(list);
                    }
                }
                frontier = newFrontier;
            }
            Console.WriteLine(frontier.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;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
using System.Text.RegularExpressions;

namespace Coding
{
    class Solution
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string[] s1 = s.Split(' ');
            int n = int.Parse(s1[0]);
            int q = int.Parse(s1[1]);
            string[] str1 = new string[q];
            char[] cr = new char[q];

            for(int i=0;i< q;i++)
            {
                string str = Console.ReadLine();
                string[] split = str.Split(' ');

                str1[i] = split[0];
                cr[i] = Convert.ToChar(split[1]);
            }

            int[] countFirstChar = new int[6];
            countFirstChar[0] = 1;
            char[] ar = { 'a', 'b', 'c', 'd', 'e', 'f' };
            for (int j=1;j < n;j++)
            {
                int[] tmpArray = new int[6];
                for(int k=0; k<6;k++)
                {
                    if(countFirstChar[k]!=0)
                    {
                        for (int l = 0; l < q; l++)
                        {
                            if (ar[k] == cr[l])
                            {
                                tmpArray[str1[l].ToCharArray()[0] - 97]+= countFirstChar[k];
                            }
                        }
                    }

                }

                countFirstChar = tmpArray;
            }

            Console.WriteLine(countFirstChar.Sum());
        }
    }
}


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

namespace CF317
{
    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(1, sr, sw);
                //Console.ReadKey();
            }
        }
    }

    internal class Task
    {
        public void Solve(int testNumber, InputReader sr, TextWriter sw)
        {
            var input = sr.ReadArray(Int32.Parse);
            var n = input[0];
            var q = input[1];
            var array = new Tuple<string, char>[q];
            for (var i = 0; i < q; i++)
            {
                var next = sr.NextSplitStrings();
                array[i] = new Tuple<string, char>(next[0], next[1][0]);
            }
            var count = 0;
            var list = new HashSet<char>();
            for (var i = 0; i < q; i++)
            {
                if (array[i].Item2 == 'a')
                {
                    list.Add(array[i].Item1[0]);
                }
            }
            HashSet<char> newList = null;
            for (var i = 2; i <= n; i++)
            {
                newList = new HashSet<char>();
                foreach (var item in list)
                {
                    for (var j = 0; j < q; j++)
                    {
                        if (array[j].Item2 == item)
                        {
                            newList.Add(array[j].Item1[0]);
                            if (i == n)
                            {
                                count++;
                            }
                        }
                    }
                }
                list = newList;
            }
            sw.WriteLine(count);
        }
    }

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

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

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


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

namespace Coding
{
    class Solution
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string[] s1 = s.Split(' ');
            int n = int.Parse(s1[0]);
            int q = int.Parse(s1[1]);
            string[] str1 = new string[q];
            char[] cr = new char[q];

            for(int i=0;i< q;i++)
            {
                string str = Console.ReadLine();
                string[] split = str.Split(' ');

                str1[i] = split[0];
                cr[i] = Convert.ToChar(split[1]);
            }

            int[] countFirstChar = new int[6];
            countFirstChar[0] = 1;
            char[] ar = { 'a', 'b', 'c', 'd', 'e', 'f' };
            for (int j=1;j < n;j++)
            {
                int[] tmpArray = new int[6];
                for(int k=0; k<6;k++)
                {
                    if(countFirstChar[k]!=0)
                    {
                        for (int l = 0; l < q; l++)
                        {
                            if (ar[k] == cr[l])
                            {
                                tmpArray[str1[l].ToCharArray()[0] - 97]++;
                            }
                        }
                    }

                }

                countFirstChar = tmpArray;
            }

            Console.WriteLine(countFirstChar.Sum());
        }
    }
}


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

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    string[] a;
    char[] b;
    int m;

    Dictionary<string, bool> mem = new Dictionary<string,bool>();
    bool Fun(string s)
    {
        if (s.Length == 1)
            return s[0] == 'a';
        if (mem.ContainsKey(s))
            return mem[s];

        bool ret = false;
        for (int i = 0; !ret && i < m; i++)
            if (a[i][0] == s[0] && a[i][1] == s[1])
                ret |= Fun(b[i] + s.Substring(2));
        return mem[s] = ret;
    }

    public void Solve()
    {
        int n = ReadInt();
        m = ReadInt();

        a = new string[m];
        b = new char[m];
        for (int i = 0; i < m; i++)
        {
            a[i] = ReadToken();
            b[i] = ReadToken()[0];
        }

        int ans = 0;
        var v = Enumerable.Repeat('a', n).ToArray();
        while (true)
        {
            if (Fun(new string(v)))
                ans++;
            v[n - 1]++;
            for (int i = n - 1; i > 0; i--)
                if (v[i] == 'g')
                {
                    v[i - 1]++;
                    v[i] = 'a';
                }
            if (v.All(vv => vv == 'f'))
                break;
        }

        Write(ans);
    }

    #region Main

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

    #endregion

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


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

namespace CF317
{
    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(1, sr, sw);
                //Console.ReadKey();
            }
        }
    }

    internal class Task
    {
        public void Solve(int testNumber, InputReader sr, TextWriter sw)
        {
            var input = sr.ReadArray(Int32.Parse);
            var n = input[0];
            var q = input[1];
            var array = new Tuple<string, char>[q];
            for (var i = 0; i < q; i++)
            {
                var next = sr.NextSplitStrings();
                array[i] = new Tuple<string, char>(next[0], next[1][0]);
            }
            var count = 0;
            var list = new HashSet<char>();
            for (var i = 0; i < q; i++)
            {
                if (array[i].Item2 == 'a')
                {
                    list.Add(array[i].Item1[0]);
                    if (n == 2)
                    {
                        count++;
                    }
                }
            }
            HashSet<char> newList = null;
            for (var i = 3; i <= n; i++)
            {
                newList = new HashSet<char>();
                foreach (var item in list)
                {
                    for (var j = 0; j < q; j++)
                    {
                        if (array[j].Item2 == item)
                        {
                            newList.Add(array[j].Item1[0]);
                            if (i == n)
                            {
                                count++;
                            }
                        }
                    }
                }
                list = newList;
            }
            sw.WriteLine(count);
        }
    }

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

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

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


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

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    string[] a;
    char[] b;
    int m;

    Dictionary<string, bool> mem = new Dictionary<string,bool>();
    bool Fun(string s)
    {
        if (s.Length == 1)
            return s[0] == 'a';
        if (mem.ContainsKey(s))
            return mem[s];

        bool ret = false;
        for (int i = 0; !ret && i < m; i++)
            if (a[i][0] == s[0] && a[i][1] == s[1])
                ret |= Fun(b[i] + s.Substring(2));
        return mem[s] = ret;
    }

    public void Solve()
    {
        int n = ReadInt();
        m = ReadInt();

        a = new string[m];
        b = new char[m];
        for (int i = 0; i < m; i++)
        {
            a[i] = ReadToken();
            b[i] = ReadToken()[0];
        }

        int ans = 0;
        var v = Enumerable.Repeat('a', n).ToArray();
        while (v.Any(vv => vv != 'f'))
        {
            v[n - 1]++;
            for (int i = n - 1; i >= 0; i--)
                if (v[i] == 'g')
                {
                    v[i - 1]++;
                    v[i] = 'a';
                }
            if (Fun(new string(v)))
                ans++;
        }

        Write(ans);
    }

    #region Main

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

    #endregion

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


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

namespace TaskF
{
    class Program
    {
        static int n;
        static int[,] g;
        static bool[] um, uw;
        static List<int> all = new List<int>();

        static void Rec(int radost, int numberMan) {
            if (numberMan == n)
            {
                //Console.WriteLine(radost);
                all.Add(radost);
            }
            else
            {
                for (int j = 0; j < n; j++)
                {
                    if (g[numberMan, j] > 0 && !uw[j])
                    {
                        uw[j] = true;
                        Rec(radost + g[numberMan, j], numberMan + 1);
                        uw[j] = false;
                    }
                }
                Rec(radost, numberMan + 1);
            }

        }

        static void Main(string[] args)
        {
            int[] data = Array.ConvertAll<string, int>(Console.ReadLine().Split(), int.Parse);
            n = data[0];
            int k = data[1], t = data[2];
            g = new int[n, n];
            uw = new bool[n];
            um = new bool[n];

            for (int i = 0; i < k; i++)
            {
                data = Array.ConvertAll<string, int>(Console.ReadLine().Split(), int.Parse);
                g[data[0]-1, data[1]-1] = data[2];
            }

            Rec(0,0);
            all.Sort();
            Console.WriteLine(all[t - 1]);
        }
    }
}


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

namespace TaskF
{
    class Program
    {
        static int n;
        static int[,] g;
        static bool[] um, uw;
        static List<int> all = new List<int>();

        static void Rec(int radost, int numberMan) {
            if (numberMan == n)
            {
               //Console.WriteLine(radost);
                all.Add(radost);
            }
            else
            {
                for (int j = 0; j < n; j++)
                {
                    if (g[numberMan, j] > 0 && !uw[j])
                    {
                        uw[j] = true;
                        Rec(radost + g[numberMan, j], numberMan + 1);
                        Rec(radost, numberMan + 1);
                        uw[j] = false;
                    }
                }
            }

        }

        static void Main(string[] args)
        {
            int[] data = Array.ConvertAll<string, int>(Console.ReadLine().Split(), int.Parse);
            n = data[0];
            int k = data[1], t = data[2];
            g = new int[n, n];
            uw = new bool[n];
            um = new bool[n];

            for (int i = 0; i < k; i++)
            {
                data = Array.ConvertAll<string, int>(Console.ReadLine().Split(), int.Parse);
                g[data[0]-1, data[1]-1] = data[2];
            }

            Rec(0,0);
            all.Sort();
            Console.WriteLine(all[t]);
        }
    }
}


#define LOCAL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace _258_E
{
    class Program
    {
        class Files
        {
            StreamReader fin = new StreamReader("d:\\date.in");
            StreamWriter fout = new StreamWriter("d:\\date.out");
            public string ReadLine()
            {
                return fin.ReadLine();
            }
            public void Write(string s)
            {
                fout.Write(s);
            }
            public void WriteLine(string s)
            {
                fout.WriteLine(s);
            }
            public void Close()
            {
                fout.Close();
            }
        }
        #if LOCAL
            static Files Console = new Files();
        #endif
        const int Mod = (int)1e9+7;
        static string[] s;
        static string Line;
        static int step = 0, Length = 0;
        static Int64 GetNext()
        {
            if (step == Length)
            {
                Line = Console.ReadLine();
                s = Line.Split(' ');
                Length = s.Length;
                step = 0;
            }
            ++step;
            return Int64.Parse(s[step - 1]);
        }
        static Int64[] a = new Int64[30];
        static Int64 Inv = 1;
        static Int64 Comb(Int64 n, Int64 k)
        {
            if (n < k)
                return 0;
            Int64 result = 1;
            for (Int64 i = n - k + 1; i <= n; ++i)
                result = (Int64)result*i%Mod;
            result = (Int64)result*Inv%Mod;
            return result;
        }
        static Int64 Fix(Int64 x)
        {
            Int64 ret = x;
            if (ret >= Mod)
                ret -= Mod;
            if (ret < 0)
                ret += Mod;
            return ret;
        }

        static Int64 Pow_Log(Int64 x,Int64 p)
        {
            if (p == 0)
                return 1;
            Int64 y;
            if(p%2==1)
               y = (Int64)Pow_Log(x,p-1)*x%Mod;
            else
            {
                y = Pow_Log(x,p/2);
                y = (Int64)y*y%Mod;
            }
            return y;
        }
        static void Main(string[] args)
        {
            Int64 n = GetNext(), S = GetNext(), sum = 0, Max = 1;
            Inv = 1;
            for (int i = 0; i < n; ++i)
            {
                Max *= 2;
                if (i > 0)
                    Inv *= i;
                a[i] = GetNext();
                sum += a[i];
            }
            if (sum < S)
            {
                Console.WriteLine("0");
                return;
            }
            Inv = Pow_Log(Inv, Mod - 2);
            Int64 Solution = Comb(S + n - 1, n - 1),cnt = 0;
            for (int i = 1; i < Max; ++i)
            {
                Int64 k = 0;
                int nr = 0;
                for (int j = 0; j < n; ++j)
                    if (((1 << j) & i) != 0)
                    {
                        ++nr;
                        k += a[j]+1;
                    }
                k = S - k;
                if (nr % 2 == 1)
                    cnt += Comb(k + n - 1, n - 1);
                else
                    cnt -= Comb(k + n - 1, n - 1);
                cnt = Fix(cnt);
            }
            Solution -= cnt;
            Console.WriteLine(Solution.ToString());
            #if LOCAL
                Console.Close();
            #endif
        }
    }
}


using System;

namespace Problem51Nod
{
    class Program
    {
        public static void Main(String[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = Convert.ToInt32(input[0]);
            long sum = Convert.ToInt64(input[1]);
            input = Console.ReadLine().Split(' ');
            long[] nums = new long[n];
            for (int i = 0; i < n; i++)
                nums[i] = Convert.ToInt64(input[i]);

            Console.WriteLine(Cal(sum, nums));
        }

        static long Mod = 1000000007;
        static long[] Nums, InvFacts;

        static void Init(long[] nums)
        {
            long[] invs = new long[30];
            InvFacts = new long[30];
            invs[1] = InvFacts[1] = 1;

            for (int i = 2; i < invs.Length; i++)
            {
                invs[i] = (Mod - Mod / i * invs[Mod % i] % Mod) % Mod;
                InvFacts[i] = InvFacts[i - 1] * invs[i] % Mod;
            }

            Nums = new long[nums.Length];

            for (int i = 0; i < nums.Length; i++)
                Nums[i] = nums[i] + 1;

            Array.Sort(Nums, (a, b) => b.CompareTo(a));
        }

        static long Cal(long sum, long[] nums)
        {
            if (nums.Length == 1) return nums[0] < sum ? 0 : 1;
            Init(nums);
            return (Cal(Nums.Length - 1, sum) + Mod) % Mod;
        }

        static long Cal(int index, long sum)
        {
            int k = Nums.Length - 1;
            long result = Cmn(sum + k, k);

            for(int i = index; i >= 0 && Nums[i] <= sum; i--)
                result -= Cal(i - 1, sum - Nums[i]);

            return result % Mod;
        }

        static long Cmn(long m, long n)
        {
            long result = 1;

            for(long i = m - n + 1; i <= m; i++)
                result = i % Mod * result % Mod;

            result = result * InvFacts[n] % Mod;
            return result;
        }
    }
}


//#define LOCAL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace _258_E
{
    class Program
    {
        class Files
        {
            StreamReader fin = new StreamReader("d:\\date.in");
            StreamWriter fout = new StreamWriter("d:\\date.out");
            public string ReadLine()
            {
                return fin.ReadLine();
            }
            public void Write(string s)
            {
                fout.Write(s);
            }
            public void WriteLine(string s)
            {
                fout.WriteLine(s);
            }
            public void Close()
            {
                fout.Close();
            }
        }
        #if LOCAL
            static Files Console = new Files();
        #endif
        const Int64 Mod = (Int64)1e9+7;
        static string[] s;
        static string Line;
        static int step = 0, Length = 0;
        static Int64 GetNext()
        {
            if (step == Length)
            {
                Line = Console.ReadLine();
                s = Line.Split(' ');
                Length = s.Length;
                step = 0;
            }
            ++step;
            return Int64.Parse(s[step - 1]);
        }
        static Int64[] a = new Int64[30];
        static Int64 Inv = 1;
        static Int64 Comb(Int64 n, Int64 k)
        {
            if (n < k)
                return 0;
            Int64 result = 1;
            for (Int64 i = n - k + 1; i <= n; ++i)
                result = (Int64)result*(i%Mod)%Mod;
            result = (Int64)result*Inv%Mod;
            return result;
        }
        static Int64 Fix(Int64 x)
        {
            Int64 ret = x;
            while(ret >= Mod)
                ret -= Mod;
            while(ret < 0)
                ret += Mod;
            return ret;
        }

        static Int64 Pow_Log(Int64 x,Int64 p)
        {
            if (p == 0)
                return 1;
            Int64 y;
            if(p%2==1)
               y = (Int64)Pow_Log(x,p-1)*x%Mod;
            else
            {
                y = Pow_Log(x,p/2);
                y = (Int64)y*y%Mod;
            }
            return y;
        }
        static void Main(string[] args)
        {
            Int64 n = GetNext(), S = GetNext(), sum = 0, Max = 1;
            Inv = 1;
            for (int i = 0; i < n; ++i)
            {
                Max *= 2;
                if (i > 0)
                    Inv *= i;
                a[i] = GetNext();
                sum += a[i];
            }
            if (sum < S)
            {
                Console.WriteLine("0");
                return;
            }

            //Console.WriteLine(Inv.ToString());
            Inv = Pow_Log(Inv%Mod, Mod - 2);

            //Console.WriteLine(Inv.ToString());
            Int64 Solution = Comb(S + n - 1, n - 1),cnt = 0;
            for (int i = 1; i < Max; ++i)
            {
                Int64 k = 0;
                int nr = 0;
                for (int j = 0; j < n; ++j)
                    if (((1 << j) & i) != 0)
                    {
                        ++nr;
                        k += a[j]+1;
                    }
                k = S - k;
                if (nr % 2 == 1)
                    cnt += Comb(k + n - 1, n - 1);
                else
                    cnt -= Comb(k + n - 1, n - 1);
                cnt = Fix(cnt);
            }
            Solution -= cnt;
            Solution = Fix(Solution);
            Console.WriteLine(Solution.ToString());
            #if LOCAL
                Console.Close();
            #endif
        }
    }
}