using System;

class P {
  static void Main() {
    var str = Console.ReadLine();
    var protocol = str.StartsWith("ht")?"http" : "ftp";
    str = str.Substring(protocol.Length);
    var i = str.IndexOf("ru", 1);
    var domain = str.Remove(i);
    var context = str.Substring(i+2);
    if (context != "") context = "/" + context;
    Console.WriteLine("{0}://{1}.ru{2}", protocol, domain, context);
  }
}


using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.I;
		var a=new int[n][];
		int ans=0;
		for(int i = 0;i<n;i++) {
			a[i]=sc.Ia;
			for(int j = i-1;j>=0;j--) {
				if(a[i][0]==a[j][1]){ans++;}
				if(a[j][0]==a[i][1]){ans++;}
			}
		}
		Console.WriteLine("{0}",ans);
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public int[] Ia3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public long[] La3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}


using System;

namespace Main
{
	class MainClass
	{
		public static void ProblemA() {
			string[] source = Console.ReadLine().Split(' ');
			int n = int.Parse(source[0]), k = int.Parse(source[1]);
			source = Console.ReadLine().Split(' ');
			int ans = k;
			for(int i = 0; i < n; i++) {
				int a = int.Parse(source[i]);
				if(k % a == 0) ans = Math.Min(ans, k / a);
			}
			Console.WriteLine(ans);
		}
		public static void Main(string[] args) {
			ProblemA();
		}
	}
}


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

namespace Artem_and_Array
{
    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 int[] nn;

        private static void Main(string[] args)
        {
            int n = Next();
            nn = new int[n + 2];
            nn[0] = -10000000;
            for (int i = 1; i <= n; i++)
            {
                nn[i] = Next();
            }
            nn[n + 1] = -10000000;

            long count = 0;

            var points = new point[n + 2];
            Queue<point> q = new Queue<point>();
            for (int i = 1; i <= n; i++)
            {
                var p = new point(i - 1, i + 1, nn[i]);
                points[i] = p;
                if (p.value>=p.current)
                {
                    q.Enqueue(p);
                    p.used = true;
                }
            }

            while (q.Count>0)
            {
                point p = q.Dequeue();
                count += p.value;

                point p1 = points[p.left];
                point p2 = points[p.right];
                p1.right = p.right;
                p2.left = p.left;
                p1.Recalc();
                p2.Recalc();

                if (p1.value >= p1.current && !p1.used)
                {
                    q.Enqueue(p1);
                    p1.used = true;
                }
                if (p2.value >= p2.current && !p2.used)
                {
                    q.Enqueue(p2);
                    p2.used = true;
                }
            }

            var heap = new MaxBinaryHeapObject(new point(0, 0, 0));
            for (int i = 1; i <= n; i++)
            {
                if (!points[i].used)
                    heap.Add(points[i]);
            }

            while (heap.HeapSize > 2)
            {
                point p = heap.GetMax();
                count += p.value;

                point p1 = points[p.left];
                point p2 = points[p.right];
                p1.right = p.right;
                p2.left = p.left;

                p1.Recalc();
                heap.Remove(p1);
                p2.Recalc();
                heap.Remove(p2);

                heap.Add(p1);
                heap.Add(p2);
            }

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

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

        #region Nested type: MaxBinaryHeapObject

        public class MaxBinaryHeapObject
        {
            private readonly IComparer<point> _comparer;
            private readonly List<point> _list;

            public MaxBinaryHeapObject(IComparer<point> comparer)
            {
                _comparer = comparer ?? Comparer<point>.Default;
                _list = new List<point>();
            }

            public int HeapSize
            {
                get { return _list.Count; }
            }

            public void Add(point value)
            {
                _list.Add(value);
                value.where = _list.Count - 1;
                int i = HeapSize - 1;
                int parent = (i - 1)/2;

                while (i > 0 && _comparer.Compare(_list[parent], _list[i]) == -1)
                {
                    point temp = _list[i];
                    _list[i] = _list[parent];
                    _list[parent] = temp;

                    _list[i].where = i;
                    _list[parent].where = parent;

                    i = parent;
                    parent = (i - 1)/2;
                }
            }

            public void Remove(point t)
            {
                _list[t.where] = _list[HeapSize - 1];
                _list[t.where].where = t.where;
                _list.RemoveAt(HeapSize - 1);
                Heapify(t.where);
            }

            public void Heapify(int i)
            {
                for (;;)
                {
                    int leftChild = 2*i + 1;
                    int rightChild = 2*i + 2;
                    int largestChild = i;

                    if (leftChild < HeapSize && _comparer.Compare(_list[leftChild], _list[largestChild]) == 1)
                    {
                        largestChild = leftChild;
                    }

                    if (rightChild < HeapSize && _comparer.Compare(_list[rightChild], _list[largestChild]) == 1)
                    {
                        largestChild = rightChild;
                    }

                    if (largestChild == i)
                    {
                        break;
                    }

                    point temp = _list[i];
                    _list[i] = _list[largestChild];
                    _list[largestChild] = temp;

                    _list[i].where = i;
                    _list[largestChild].where = largestChild;

                    i = largestChild;
                }
            }

            public point Max()
            {
                return _list[0];
            }

            public point GetMax()
            {
                point result = _list[0];
                _list[0] = _list[HeapSize - 1];
                _list[0].where = 0;
                _list.RemoveAt(HeapSize - 1);
                Heapify(0);
                return result;
            }
        }

        #endregion

        #region Nested type: point

        public class point : IComparer<point>
        {
            public readonly int current;
            public int left;
            public int right;
            public int value;
            public int where;
            public bool used;

            public point(int left, int right, int current)
            {
                this.left = left;
                this.right = right;
                this.current = current;
                value = Math.Min(nn[left], nn[right]);
            }

            #region IComparer<point> Members

            public int Compare(point x, point y)
            {
                int c = (x.value).CompareTo(y.value);
                //if (c == 0)
                //    c = y._current.CompareTo(x._current);
                return c;
            }

            #endregion

            public void Recalc()
            {
                value = Math.Min(nn[left], nn[right]);
            }
        }

        #endregion
    }
}


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

namespace Squares
{
    class Dictionary
    {
        static void Main(string[] args)
        {
            string line1 = Console.ReadLine().ToLower();
            string line2 = Console.ReadLine().ToLower();

            char[] array1 = new char[line1.Length];
            char[] array2 = new char[line2.Length];
            for (int i = 0; i < line1.Length; i++)
            {
                array1[i] = Convert.ToChar(line1.Substring(i, 1));
                array2[i] = Convert.ToChar(line2.Substring(i, 1));
            }
            for (int i = 0; i < array1.Length; i++)
            {
                if (array1[i] > array2[i])
                {
                    Console.WriteLine("1");
                    break;

                }
                else if (array1[i] < array2[i])
                {
                    Console.WriteLine("-1");
                    break;

                }
                else if (array1[i] == array2[i])
                {
                    if (i == array1.Length - 1)
                    {
                        Console.WriteLine("0");
                        break;
                    }

                }

            }

            Console.ReadLine();
        }
    }
}


using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
using Debug = System.Diagnostics.Debug;
using SB = System.Text.StringBuilder;
using Number = System.Int64;
using KV = System.Collections.Generic.KeyValuePair<int, long>;
namespace Program {
    public class Solver {
        public void Solve() {
            var k = ri;
            var pa = ri;
            var pb = ri;
            var p = pa * ModInt.Inverse(pa + pb);

            var q = pb * ModInt.Inverse(pa + pb);
            var invq = ModInt.Inverse(q);
            var dp = new ModInt[k + 5, k + 5];
            for (int i = 0; i < k + 5; i++)
                for (int j = 0; j < k + 5; j++)
                    dp[i, j].num = -1;
            Func<int, int, ModInt> dfs = null;
            dfs = (a, cnt) => {
                if (cnt >= k) return cnt;
                if (a + cnt >= k) {
                    return cnt + a + invq - 1;
                }
                if (dp[a, cnt].num != -1) return dp[a, cnt];
                ModInt ret = new ModInt(0);
                // a を出す
                ret += p * dfs(a + 1, cnt);
                // b を出す
                ret += q * dfs(a, cnt + a);

                return dp[a, cnt] = ret;
            };
            Console.WriteLine(dfs(1, 0));

        }
        const long INF = 1L << 60;
        int[] dx = { -1, 0, 1, 0 };
        int[] dy = { 0, 1, 0, -1 };

        int ri { get { return sc.Integer(); } }
        long rl { get { return sc.Long(); } }
        double rd { get { return sc.Double(); } }
        string rs { get { return sc.Scan(); } }
        public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());

        static T[] Enumerate<T>(int n, Func<int, T> f) {
            var a = new T[n];
            for (int i = 0; i < n; ++i) a[i] = f(i);
            return a;
        }

        static public void Swap<T>(ref T a, ref T b) {
            var tmp = a;
            a = b;
            b = tmp;
        }
    }
}

#region main

static class Ex {
    static public string AsString(this IEnumerable<char> ie) {
        return new string(ie.ToArray());
    }

    static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") {
        return string.Join(st, ie.Select(x => x.ToString()).ToArray());
        //return string.Join(st, ie);
    }

    static public void Main() {
        Console.SetOut(new Program.IO.Printer(Console.OpenStandardOutput()) { AutoFlush = false });
        var solver = new Program.Solver();
        solver.Solve();
        Console.Out.Flush();
    }
}

#endregion
#region Ex

namespace Program.IO {
    using System.IO;
    using System.Text;
    using System.Globalization;

    public class Printer: StreamWriter {
        public override IFormatProvider FormatProvider {
            get { return CultureInfo.InvariantCulture; }
        }
        public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
    }

    public class StreamScanner {
        public StreamScanner(Stream stream) {
            str = stream;
        }

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

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

        public char Char() {
            byte b = 0;
            do b = read(); while ((b < 33 || 126 < b) && !isEof);
            return (char)b;
        }

        public string Scan() {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b);
            return sb.ToString();
        }

        public string ScanLine() {
            var sb = new StringBuilder();
            for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b);
            return sb.ToString();
        }

        public long Long() {
            return isEof ? long.MinValue : long.Parse(Scan());
        }

        public int Integer() {
            return isEof ? int.MinValue : int.Parse(Scan());
        }

        public double Double() {
            return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture);
        }
    }
}

#endregion

#region ModInt
public struct ModInt {
    public const long Mod = (long)1e9 + 7;
    public long num;
    public ModInt(long n) { num = n; }
    public override string ToString() { return num.ToString(); }
    public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; }
    public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; }
    public static ModInt operator *(ModInt l, ModInt r) { return new ModInt((int)(l.num * r.num % Mod)); }
    public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); }
    public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); }
    public static ModInt Pow(long v, long k) {
        long ret = 1;
        for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)
            if ((k & 1) == 1) ret = ret * v % Mod;
        return new ModInt(ret);
    }
    public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }
}
#endregion


using System.IO;
using System;

class Program
{
    static void Main()
    {

        int n = 0;
        string S;
        int CheckPoint = 0;
        int[] a = null;
        int SUM = 0;

        n = Int32.Parse(Console.ReadLine());

        S = Console.ReadLine();

        a = new int[n];

        for(int i=0; i<n-1;i++)
        {
          if(S[i]==S[i+1])
          {
             a[CheckPoint] ++ ;
          }
          else
          {
             CheckPoint = i+1;
          }

        }

        for(int j=0;j<n;j++)
        {
            if(a[j]!=0)
            {
               SUM+=a[j];
            }
        }

        Console.WriteLine(SUM);
    }
}


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

namespace prA {

    class Program {
#if ONLINE_JUDGE
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024 * 10), System.Text.Encoding.ASCII, false, 1024 * 10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024 * 10), System.Text.Encoding.ASCII, 1024 * 10);
#else
        private static readonly StreamWriter writer = new StreamWriter(@"..\..\output");
        private static readonly StreamReader reader = new StreamReader(@"..\..\input");
#endif
        static void Main(string[] args) {
            char[] n = {'6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A'};
            string m = reader.ReadLine();
            string[] k = reader.ReadLine().Split(' ');
            if(k[0][1] == k[1][1]) {
                writer.Write(Array.IndexOf(n, k[0][0]) > Array.IndexOf(n, k[1][0]) ? "YES" : "NO");
            } else if(k[0][1] == m[0]) {
                writer.Write("YES");
            }
            else
                writer.Write("NO");

            writer.Flush();
#if !ONLINE_JUDGE
            writer.Close();
#endif
        }
        private static int Next() {
            int c;
            int res = 0;
            do {
                c = reader.Read();
                if(c == -1)
                    return res;
            } while(c != '-' && (c < '0' || c > '9'));
            int sign = 1;
            if(c == '-') {
                sign = -1;
                c = reader.Read();
            }
            res = c - '0';
            while(true) {
                c = reader.Read();
                if(c < '0' || c > '9')
                    return res * sign;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


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

namespace Codeforces
{
    class A
    {
        private static bool s_time = false;

        static long mod = 1000003;

        private static object Go()
        {
            string s = GetString();

            Dictionary<char, int> map = new Dictionary<char, int>();
            map['>'] = 8;
            map['<'] = 9;
            map['+'] = 10;
            map['-'] = 11;
            map['.'] = 12;
            map[','] = 13;
            map['['] = 14;
            map[']'] = 15;

            long ret = 0;
            for (int i = 0; i < s.Length; i++)
            {
                ret = (ret * 16 + map[s[i]]) % mod;
            }

            return ret;
        }

        #region Template

        public static void Main(string[] args)
        {
            DateTime start = DateTime.Now;
            object output = Go();
            TimeSpan duration = DateTime.Now.Subtract(start);
            if (output != null)
                Wl<string>(output.ToString());
            if (s_time)
                Wl(duration);
        }

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

            return ioEnum.Current;
        }

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

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

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

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

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

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

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

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

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

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

            public override string ToString()
            {
                return "(" + Item1 + " " + Item2 + ")";
            }

            #region IComparable<Tuple<T,K>> Members

            public int CompareTo(Tuple<T, K> other)
            {
                int ret = Item1.CompareTo(other.Item1);
                if (ret != 0) return ret;
                return Item2.CompareTo(other.Item2);
            }

            #endregion
        }

        #endregion
    }
}


using System;

namespace test
{
    static class Program
    {
        static void Main()
        {
            var str = Console.ReadLine();
            var names = new string[] { "Danil", "Olya", "Slava", "Ann", "Nikita" };
            var count = 0;
            var index = 0;
            for(var i = 0; i < 5; i++)
            {
                index = 0;
                for (int j = 0; j < 2 && index!=-1; j++)
                {
                    index = str.IndexOf(names[i], index);
                    if (index != -1) { count++; index++; }
                }
            }
            if (count == 1)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");
        }
    }
}


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

// (づ°ω°)づﾐ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    public object Solve()
    {
        int n = ReadInt();
        string s = ReadToken();
        if (s.Distinct().Count() < n)
            return "NO";

        Write("YES");
        if (n == 1)
        {
            Write(s);
            return null;
        }

        var f = new bool[200];
        f[s[0]] = true;
        int c = 0, p = 0;
        for (int i = 1; i < s.Length; i++)
            if (!f[s[i]])
            {
                Write(s.Substring(p, i - p));
                c++;
                p = i;
                f[s[i]] = true;
                if (c == n - 1)
                {
                    Write(s.Substring(p));
                    break;
                }
            }

        return null;
    }

    #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("hull.in");
        //writer = new StreamWriter("hull.out");
#endif
        try
        {
//            var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
//            thread.Start();
//            thread.Join();
            var ret = new Solver().Solve();
            if (ret != null)
                Write(ret);
        }
        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
}


#define Online

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

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

            D();

#if Online
            Console.ReadLine();
#endif

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

        static void A()
        {
            int n = ReadInt();
            int[] a = new int[n];
            int[] b = new int[n];
            for (int i = 0; i < n; i++)
            {
                string[] tokens = ReadArray(' ');
                a[i] = int.Parse(tokens[0]);
                b[i] = int.Parse(tokens[1]);
            }
            int ans = 0;
            for (int i = 0; i < n; i++)
            {
                bool isHere = false;
                for (int j = 0; j < n; j++)
                {
                    if (i == j) continue;
                    if (b[j] == a[i])
                        isHere = true;
                }
                if (!isHere)
                    ans++;
            }
            Console.WriteLine(ans);
        }

        static void B()
        {
            int n, m;
            string[] tokens = ReadArray(' ');
            n = int.Parse(tokens[0]);
            m = int.Parse(tokens[1]);
            int[] a = new int[n];
            tokens = ReadArray(' ');
            for (int i = 0; i < n; i++)
                a[i] = int.Parse(tokens[i]);

            int[] sum = new int[m + 1];
            int[] last = new int[n];
            StringBuilder ans = new StringBuilder();
            for (int i = 1; i <= m; i++)
            {
                sum[i] = sum[i - 1];
                tokens = ReadArray(' ');
                int t = int.Parse(tokens[0]);
                if (t == 1)
                {
                    int v = int.Parse(tokens[1]);
                    int x = int.Parse(tokens[2]);
                    a[v - 1] = x;
                    last[v - 1] = i;
                }
                if (t == 2)
                {
                    int y = int.Parse(tokens[1]);
                    sum[i] += y;
                }
                if (t == 3)
                {
                    int q = int.Parse(tokens[1]);
                    int val = a[q - 1] + (sum[i] - sum[last[q - 1]]);
                    ans.AppendLine(val.ToString());
                }
            }
            Console.Write(ans);
        }

        static void C()
        {
            long n, k;
            string[] tokens = ReadArray(' ');
            n = long.Parse(tokens[0]);
            k = long.Parse(tokens[1]);
            long[] a = new long[n + 1];
            tokens = ReadArray(' ');
            for (int i = 1; i <= n; i++)
            {
                a[i] = long.Parse(tokens[i - 1]);
            }
            StringBuilder ans = new StringBuilder();
            long cnt = 0;
            long cur = 0;
            long _d = 0;
            for (int i = 1; i <= n; i++)
            {
                _d = 0;
                _d -= (i - 1 - cnt) * ((n-cnt) - (i-cnt)) * a[i];
                _d += cur;
                if (_d < k)
                {
                    ans.AppendLine(i.ToString());
                    cnt++;
                }
                else
                {
                    cur += (i - cnt - 1) * a[i];
                }
            }
            Console.Write(ans);
        }

        static int FirstIndex(string a, string c, int i,int z, int j)
        {
            for (int k = 0; k < a.Length; k++, z++)
            {
                if (a[(i + z) % a.Length].Equals(c[j])) return (z + 1);
            }
            return -1;
        }

        static void D()
        {
            int b, d;
            string[] tokens = ReadArray(' ');
            b = int.Parse(tokens[0]);
            d = int.Parse(tokens[1]);
            string a = ReadLine();
            string c = ReadLine();

            int[] _cnt = new int[a.Length];
            for (int i = 0; i < a.Length; i++)
            {
                int z = 0;
                for (int j = 0; j < c.Length; j++)
                {
                    int m = FirstIndex(a, c, i, z, j);
                    if (m == -1)
                    {
                        Console.WriteLine(0);
                        return;
                    }
                    z = m;
                }
                _cnt[i] = z;
            }

            int[] r = new int[a.Length];
            int[] __cnt = new int[a.Length];
            for (int i = 0; i < a.Length; i++)
            {
                int j = 0;
                for (int k = 0; k < a.Length; k++)
                    r[k] = -1;
                for (int k = 0; k < d; j += _cnt[(i + j) % a.Length], k++)
                {
                    if (r[(i + j) % a.Length] > 0)
                    {
                        int dif = j - r[(i + j) % a.Length];
                        j += (d - k) * dif;
                        break;
                    }
                    r[(i + j) % a.Length] = j;
                }
                __cnt[i] = j;
            }
            r = new int[a.Length];
            int[] _r = new int[a.Length];
            int p = 0;
            for (int j = 0; j < a.Length * b; )
            {
                if (r[j % a.Length] > 0)
                {
                    int dif = j - r[j % a.Length];
                    int _dif = p - _r[j % a.Length];
                    p += ((a.Length * b - j) / dif) * (_dif);
                    j += ((a.Length * b - j) / dif) * dif;
                    while (j + __cnt[j % a.Length] <= a.Length * b)
                    {
                        p++;
                        j += __cnt[j % a.Length];
                    }
                    break;
                }
                r[j % a.Length] = j;
                _r[j % a.Length] = p;
                j += __cnt[j % a.Length];
                if (j <= a.Length * b) p++;
            }
            Console.WriteLine(p);

        }

        static void E()
        {

        }

        static void TestGen()
        {

        }

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

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

        static string ReadLine()
        {
            return 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);
        }
    }

    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<int>[] g;
        public int[] color; //0-white, 1-gray, 2-black
        public int[] o; //open
        public int[] c; //close
        public int[] p;
        public int[] d;
        public List<Edge> e;
        public Stack<int> ans = new Stack<int>();
        public Graph(int n)
        {
            g = new List<int>[n + 1];
            for (int i = 0; i <= n; i++)
                g[i] = new List<int>();
            color = new int[n + 1];
            o = new int[n + 1];
            c = new int[n + 1];
            p = new int[n + 1];
            d = new int[n + 1];
        }

        const int white = 0;
        const int gray = 1;
        const int black = 2;

        public bool DFS(int u, ref int time)
        {
            color[u] = gray;
            time++;
            o[u] = time;
            for (int i = 0; i < g[u].Count; i++)
            {
                int v = g[u][i];
                if (color[v] == gray)
                {
                    return true;
                }
                if (color[v] == white)
                {
                    p[v] = u;
                    if (DFS(v, ref time)) return true;
                }
            }
            color[u] = black;
            ans.Push(u);
            c[u] = time;
            time++;
            return false;
        }
    }

    static class GraphUtils
    {
        const int white = 0;
        const int gray = 1;
        const int black = 2;

        public static void BFS(int s, Graph g)
        {
            Queue<int> q = new Queue<int>();
            q.Enqueue(s);
            while (q.Count != 0)
            {
                int u = q.Dequeue();
                for (int i = 0; i < g.g[u].Count; i++)
                {
                    int v = g.g[u][i];
                    if (g.color[v] == white)
                    {
                        g.color[v] = gray;
                        g.d[v] = g.d[u] + 1;
                        g.p[v] = u;
                        q.Enqueue(v);
                    }
                }
                g.color[u] = black;
            }
        }

        public static bool DFS(int u, ref int time, Graph g, Stack<int> st)
        {
            g.color[u] = gray;
            time++;
            g.o[u] = time;
            for (int i = 0; i < g.g[u].Count; i++)
            {
                int v = g.g[u][i];
                if (g.color[v] == gray)
                {
                    return true;
                }
                if (g.color[v] == white)
                {
                    g.p[v] = u;
                    if (DFS(v, ref time, g, st)) return true;
                }
            }
            g.color[u] = black;
            st.Push(u);
            g.c[u] = time;
            time++;
            return false;
        }

        public static void FordBellman(int u, Graph g)
        {
            int n = g.g.Length;
            for (int i = 0; i <= n; i++)
            {
                g.d[i] = int.MaxValue;
                g.p[i] = 0;
            }

            g.d[u] = 0;

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

    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, Comparison<T> comp)
        {
            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 (comp(L[i], 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, Comparison<T> comp)
        {
            if (p >= r) return;
            int q = p + ((r - p) >> 1);
            Merge_Sort(A, p, q, L, R, comp);
            Merge_Sort(A, q + 1, r, L, R, comp);
            Merge(A, p, q, r, L, R, comp);
        }

        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;

namespace CF_357A
{
    class Program
    {
        static void Main()
        {
            int n = Int32.Parse(Console.ReadLine());
            string[] str = Console.ReadLine().Split(' ');
            long sumAll = 0;
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
            {
                int temp = Int32.Parse(str[i]);
                sumAll += temp;
                a[i] = temp;
            }
            str = Console.ReadLine().Split(' ');
            int x = Int32.Parse(str[0]);
            int y = Int32.Parse(str[1]);

            int mark = 1;
            long sumLooser = a[0];
            long sumWinner = sumAll - sumLooser;

            bool solve = false;

            for (int i = 1; i < n; i++)
            {
                if (sumLooser >= x && sumLooser <= y && sumWinner >= x && sumWinner <= y)
                {
                    solve = true;
                    break;
                }
                mark++;
                sumLooser += a[i];
                sumWinner -= a[i];
                if (sumLooser > y || sumWinner < x)
                {
                    break;
                }
            }

            if (solve)
            {
                Console.Write(++mark);
            }
            else
            {
                Console.Write(0);
            }
        }
    }
}


using System;
class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            long a = long.Parse(input[0]), b = long.Parse(input[1]), diff = b-a;
            if (diff == 1) Console.WriteLine(input[1][input[1].Length - 1]);
            else if (diff >= 5) Console.WriteLine("0");
            else
            {
                a = 1L;
                while(diff-->0)
                  a *= b-- % 10L;
                Console.WriteLine((a % 10L));
            }
        }
    }


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
			string textBox1 = Console.ReadLine();
 		    string textBox2="";//= Console.ReadLine();
           /* char[] arr;
            arr = num.ToCharArray(0, num.Length);
           */
           /* char[] arr2;
            arr2 = num.ToCharArray(0, num.Length);
*/
           int len = textBox1.Length;
            int beg ;
            beg =Convert.ToInt32( Math.Pow(2, len))-1;
            int end = beg*2;
            int ser =(end-beg+1)/2;
            char[] first = new char[len];
            int i = 0;

            while (i < len)
            {
                first[i] = textBox1[i];
                i++;
            }
            i = 0;
            while (i < len)
            {
                if(first[i]=='4')
                {
                    end = end - ser;
                    ser = ser / 2;
                }
                else
                {
                    beg = beg + ser;
                    ser = ser / 2;
                }

                i++;

            }
           // label1.Text = Convert.ToString(beg);

			Console.WriteLine(Convert.ToString(beg));

         }
    }
}


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

class Program
{
    private static long[,] GetCount(int n, int m, long k)
    {
        var rows = new List<int>();
        for (int i = 1; i <= n; i++) rows.Add(i);
        for (int i = n - 1; i > 1; i--) rows.Add(i);

        long[,] map = new long[n + 1, m + 1];
        long countPerIteration = 0;

        for (int i = 0; i < rows.Count; i++)
            for (int j = 1; j <= m; j++)
            {
                countPerIteration++;
                //map[rows[i], j]++;
            }

        long iterations = k / countPerIteration;

        for (int i = 0; i < rows.Count; i++)
            for (int j = 1; j <= m; j++)
            {
                map[rows[i], j] += iterations;
            }

        k %= countPerIteration;

        for (int i = 0; i < rows.Count; i++)
            for (int j = 1; j <= m; j++)
            {
                if (k > 0)
                {
                    map[rows[i], j]++;
                    k--;
                }
            }

        return map;
    }

    static void Main(string[] args)
    {
        int n = RI();
        int m = RI();
        long k = RL();
        int x = RI();
        int y = RI();

        var map = GetCount(n, m, k);

        var ser = map[x, y];
        long min = long.MaxValue;
        long max = 0;
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= m; j++)
            {
                max = Math.Max(max, map[i, j]);
                min = Math.Min(min, map[i, j]);
            }

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

    private const int Mod = 1000000000 + 7;

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

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

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

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

        return g;
    }

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

        return matrix;
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        return s.ToArray();
    }

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

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

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

        return s;
    }

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

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

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

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

        return s.ToArray();
    }

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

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

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

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

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

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

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

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

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

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


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

namespace ProgrammingContest.Codeforces.Round55
{
    class C
    {
        public static void Main()
        {
            int k = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();
            int n = s.Length;
            bool[] used = new bool[26];
            for (int i = 0; i < n; i++)
                if (s[i] != '?')
                    used[s[i] - 'a'] = true;
            char[] res = s.ToCharArray();

            for (int i = 0; i < n; i++)
                if (res[i] != '?' && res[n - 1 - i] == '?')
                    res[n - 1 - i] = res[i];

            for (int i = k - 1; i >= 0; i--)
                if (!used[i])
                    for (int j = n / 2; j >= 0; j--)
                        if (res[j] == '?' && res[n - j - 1] == '?')
                        {
                            res[j] = res[n - j - 1] = (char)(i + 'a');
                            used[i] = true;
                            break;
                        }

            for (int i = 0; i < n; i++)
                if (res[i] == '?' && res[n - 1 - i] == '?')
                    res[n - 1 - i] = res[i] = 'a';

            for(int i = 0; i < k; i++)
                if (!used[i])
                {
                    Console.WriteLine("IMPOSSIBLE");
                    return;
                }

            for (int i = 0; i < n; i++)
                if (res[i] != res[n - 1 - i])
                {
                    Console.WriteLine("IMPOSSIBLE");
                    return;
                }

            Console.WriteLine(new string(res));
        }
    }
}


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

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

            var n = Int32.Parse(Console.ReadLine());

            Console.WriteLine(GetVal(n));
        }

        const int MOD_VAL = 1000000007;
        private static int GetVal(int n)
        {
            var primes = GetAllPrimes(n);
            var res = 0;
            var primeCache = GetPrimeCache(primes, n);
            var dfsSolver = new DFSSolver(primeCache);
            for(var i = 1;i<=n-2;i++)
            {
                var primeFactors = GetPrimeFactors(i, primes);
                var primeMap = new Dictionary<int,int>();
                foreach(var (prime, primeCnt) in primeFactors)
                {
                    primeMap[prime] = primeCnt;
                }
                dfsSolver.SetPrimeMap(primeMap);
                dfsSolver.SetPrimeFactors(GetPrimeFactors(n-i, primes));
                res = (int)((res + (long)dfsSolver.GetRes()*i ) % MOD_VAL);
            }
            return res;
        }

        private class DFSSolver
        {
            private int _res;
            private Dictionary<int,int> _primeMap;
            private List<(int,int)> _primeFactors;

            private Dictionary<int, int[]> _primeCache;
            public DFSSolver(Dictionary<int, int[]> primeCache)
            {
                _primeCache = primeCache;
            }

            public void SetPrimeMap(Dictionary<int,int> primeMap)
            {
                _primeMap = primeMap;
            }

            public void SetPrimeFactors(List<(int,int)> primeFactors)
            {
                _primeFactors = primeFactors;
            }

            public int GetRes()
            {
                _res = 0;
                DFS(0,1);
                var tmp = 1;
                foreach(var (prime, cnt) in _primeFactors)
                {
                    if(_primeMap.ContainsKey(prime))
                    {
                        if(cnt > _primeMap[prime])
                        {
                            tmp*= _primeCache[prime][cnt-_primeMap[prime]];
                        }
                    }
                    else
                    {
                        tmp*= _primeCache[prime][cnt];
                    }
                }
                _res-=tmp;
                if (_res < MOD_VAL) _res+=MOD_VAL;
                return _res;
            }

            private void DFS(int index, int val)
            {
                if(index == _primeFactors.Count)
                {
                    _res = (_res + val) % MOD_VAL;
                    return;
                }
                var prime = _primeFactors[index].Item1;
                var cnt = _primeFactors[index].Item2;
                for(var i = 0;i<= cnt;i++)
                {
                    var append = 1;
                    if(_primeMap.ContainsKey(prime))
                    {
                        if(i > _primeMap[prime])
                        {
                            append = _primeCache[prime][i - _primeMap[prime]];
                        }
                    }
                    else
                    {
                        append = _primeCache[prime][i];
                    }

                    if (i < cnt)
                    {
                        append = append * (prime - 1) * _primeCache[prime][cnt-i-1];
                    }
                    DFS(index+1, (int)((long)val * append % MOD_VAL));
                }
            }
        }

        private static Dictionary<int, int[]> GetPrimeCache(List<int> primes, int n)
        {
            var primeCache = new Dictionary<int, int[]>();
            foreach(var prime in primes)
            {
                var list = new List<int>();
                list.Add(1);
                var tmp = prime;
                while(tmp <= n)
                {
                    list.Add(tmp);
                    tmp*=prime;
                }
                primeCache[prime] = list.ToArray();
            }
            return primeCache;
        }

        private static int GetLCM(int num0, int num1)
        {
            return (int)((long)num0 * num1 /GetGCD(num0, num1));
        }

        private static int GetGCD(int num0, int num1)
        {
            if (num0 < num1)
            {
                var tmp = num1;
                num1 = num0;
                num0 = tmp;
            }
            while (num1 > 0)
            {
                var tmp = num1;
                num1 = num0 % num1;
                num0 = tmp;
            }
            return num0;
        }

        static List<int> GetAllPrimes(int n)
        {
            var isNotPrimes = new bool[n+1];
            var primes = new List<int>();
            for(var i = 2;i<=n;i++)
            {
                if (!isNotPrimes[i])
                {
                    primes.Add(i);
                    var num = i * 2;
                    while(num <= n)
                    {
                        isNotPrimes[num]= true;
                        num+=i;
                    }
                }
            }
            return primes;
        }

        static List<(int,int)> GetPrimeFactors(int num, List<int> primes)
        {
            var primeFactors = new List<(int,int)>();
            foreach(var prime in primes)
            {
                if (num < prime * prime) break;
                var cnt = 0;
                while(num % prime == 0)
                {
                    cnt++;
                    num/=prime;
                }
                if (cnt > 0)
                {
                    primeFactors.Add((prime, cnt));
                }
            }
            if (num!=1)
            {
                primeFactors.Add((num, 1));
            }
            return primeFactors;
        }

        static int[] GetFactors(int num, List<int> primes)
        {
            return GetFactors(GetPrimeFactors(num, primes));
        }

        static int[] GetFactors(List<(int,int)> primeFactors)
        {
            var factorCnt = 1;
            foreach(var (_, cnt) in primeFactors)
            {
                factorCnt*=cnt+1;
            }
            var factors = new int[factorCnt];
            var preCnt = 1;
            var index = 1;
            factors[0] = 1;
            foreach(var (prime, cnt) in primeFactors)
            {
                var factor = prime;
                for(var i = 1;i<=cnt;i++)
                {
                    for(var j = 0;j<preCnt;j++)
                    {
                        factors[index++] = factors[j] * factor;
                    }
                    factor *= prime;
                }
                preCnt = index;
            }
            return factors;
        }

    }
}


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

namespace ContestProject
{
    class Program
    {
        static void Main(string[] args)
        {
            //var n = int.Parse("3");
            //var d = "001211".Select(s => int.Parse(s.ToString())).ToArray();
            var n = int.Parse(Console.ReadLine());
             var d = Console.ReadLine().Select(s => int.Parse(s.ToString())).ToArray();
            var p1 = d.Take(n).OrderBy(o => o).ToArray();
            var p2 = d.Skip(n).OrderBy(o => o).ToArray();
            bool sign = p1[0]>p2[0];
            bool fail = false;
            for (int i = 0; i < n; i++)
            {
                if (sign)
                {
                    if (p1[i] > p2[i]) continue;
                    else { fail = true; break; }
                }
                else
                {
                    if (p1[i] < p2[i]) continue;
                    else { fail = true; break; }
                }
            }
            Console.WriteLine(fail?"NO":"YES");
        }

    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using Pair = System.IComparable;
using Point = System.Tuple<int, int>;

public class Solution : Helper
{
    public Solution()
    {
        // http://codeforces.com/contest/899/problem/D
        var n = readInt32();
        long ans = 0;
        //
        if (n < 5)
        {
            ans = n * (n - 1) / 2;
        }
        else
        {
            var bs = bestSum(n);
            var str = bs.ToString();
            var f = str[0] - '0';
            if (f == 9)
            {
                ans = cp(bs, n);
            }
            else
            {
                range(0, f).each(h =>
                {
                    ans += cp(int.Parse(str.Replace(
                        f.ToString(),
                        h.ToString()
                        )), n);
                });
            }
        }
        //
        Console.WriteLine(ans);
    }
    //
    int cp(int sum, int n)
    {
        var a = sum / 2 + 1;
        var b = sum - 1;
        return count(a, Math.Min(b, n));
    }
    int count(int left, int right)
    {
        if (left > right) return 0;
        return (int)(right - left + 1);
    }
    int bestSum(int n)
    {
        var a = n + n - 1;
        var b = a.ToString();
        var c = b[0] - '0';
        var l = b.Length;
        var nines = b.Reverse().TakeWhile(x => x == '9').Count();
        if (nines >= l - 1)
            return a;
        return int.Parse((c - 1) + new string('9', l - 1));
    }
}

#region Core helper library
[DebuggerNonUserCode]
static partial class Extension
{
    internal static IEnumerable<T> each<T>(this IEnumerable<T> stream, Action<T> act) { foreach (var elem in stream) act(elem); return stream; }
    internal static IEnumerable<KeyValuePair<int, T>> kvp<T>(this IEnumerable<T> stream) { return stream.Select((elem, idx) => new KeyValuePair<int, T>(idx, elem)); }
    internal static IEnumerable<T> each<T>(this IEnumerable<T> stream, Action<T, int> act) { stream.kvp().each(kvp => act(kvp.Value, kvp.Key)); return stream; }
    internal static IEnumerable<int> indexIndices<T>(this IList<T> list) { return Helper.range(0, list.Count - 1); }
    internal static TValue? getOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> dict, TKey key) where TValue : struct
    { TValue ans; if (dict.TryGetValue(key, out ans)) return ans; return null; }
    internal static T? FirstOrNullable<T>(this IEnumerable<T> stream) where T : struct { foreach (var val in stream) return val; return null; }
    internal static List<T> Collect<T>(this IEnumerable<T> stream, int capacity) { var ans = new List<T>(capacity); ans.AddRange(stream); return ans; }
    internal static LinkedList<T> Collect<T>(this IEnumerable<T> stream) { return new LinkedList<T>(stream); }
}
[DebuggerNonUserCode]
public partial class Helper
{
    internal const int DEFAULT_BUFFER_SIZE = 4194304;
    internal static void fail(string reason = "ASSERTION FAILED") { throw new ApplicationException(reason); }
    internal static void debug(string reason = "ASSERTION FAILED") { Debug.Fail(reason); }
    internal static IEnumerable<int> range(int left, int right) { for (var i = left; i <= right; i++) yield return i; }
    internal static int? explainSearchIndex(int rawIndex) { if (rawIndex < 0) return null; return rawIndex; }
    internal static Pair pair<T1, T2>(T1 value1, T2 value2) { return Tuple.Create(value1, value2); }
}
#endregion

// additional plugable library
public partial class Helper
{
    #region STDIO
#if !DEBUG
    static void Main() { new Solution(); }
#endif
    static void eof() { throw new System.IO.EndOfStreamException(); }
    internal static string readLine_TRIM()
    { while (true) { var ans = Console.ReadLine(); if (ans == null) eof(); ans = ans.Trim(); if (ans.Any()) return ans; } }
    static IEnumerable<char> stream() { while (true) { var iread = Console.Read(); if (iread < 0) break; yield return (char)iread; } }
    static bool isWhitespace(char c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t'; }
    internal static string readString_TRIM(int maxCapacity)
    {
        var sb = new System.Text.StringBuilder(maxCapacity, maxCapacity);
        var iter = stream().SkipWhile(isWhitespace).TakeWhile(c => !isWhitespace(c));
        foreach (var c in iter) sb.Append(c);
        if (sb.Length == 0) eof(); return sb.ToString();
    }
    internal static long readLong64() { return long.Parse(readString_TRIM(21)); }
    internal static int readInt32() { return Convert.ToInt32(readLong64()); }
    #endregion
}
static partial class Extension
{

}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] nM = Console.ReadLine().Split(' ');
            string[] str = Console.ReadLine().Split(' ');
            int n = int.Parse(nM[0]);
            int m = int.Parse(nM[1]);

            int k = 1;
            int Ob = 0;

            for (int i = 0; i < n; i++)
            {
                if (Ob + int.Parse(str[i]) <= m)
                    Ob += int.Parse(str[i]);
                else
                {
                    k++;
                    Ob = int.Parse(str[i]);
                }

            }
                Console.WriteLine(k);
        }
    }
}


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

namespace ConsoleApplication35
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();
            int u = 0, d = 0,l=0,r=0,co=0;
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i]=='U')
                {
                    u++;
                }
                else if (s[i] == 'D')
                {
                    d++;
                }
                else if (s[i] == 'R')
                {
                    r++;
                }
                else if (s[i] == 'L')
                {
                    l++;
                }
            }
            co += 2 * Math.Min(r, l) + 2 * Math.Min(u, d);
            Console.WriteLine(co);
        }
    }
}


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

namespace TaskA
{
    class Program
    {
        static void Main(string[] args)
        {
            String[] sa = Console.ReadLine().Split('/');
            sa = (from x in sa where x != "" select x).ToArray();
            if (sa.Length == 0) Console.WriteLine('/');
            else foreach (String s in sa) Console.Write("/" + s);
        }
    }
}


using System;
using System.Linq;

namespace Contest
{
    internal class Program
    {
        private static void Main()
        {
            Console.ReadLine();
            var h = Console.ReadLine().ToCharArray();
            int X = h.Count(f=> f == 'X');
            int x = h.Count(z => z == 'x');
            if (X > x)
            {
                int r = (X - x)/2;
                Console.WriteLine(r);
                for (int i = 0; i < h.Length; i++)
                {
                    if (h[i] == 'X')
                    {
                        h[i] = 'x';
                        r--;
                    }
                    if(r==0) break;
                }
            }
            else if (x > X)
            {
                int r = (x - X)/2;
                Console.WriteLine(r);
                for (int i = 0; i < h.Length; i++)
                {
                    if (h[i] == 'x')
                    {
                        h[i] = 'X';
                        r--;
                    }
                    if (r == 0) break;
                }
            }
            else
            {
                Console.WriteLine(0);
            }

            Console.WriteLine(String.Join("",h));
        }
    }
}


using System;
using Math = System.Math;
using Dec = System.Decimal;
using System.Globalization;
using System.Linq;

namespace taskA
{
	class newDecimal {
	private
			Int64 Z, F, kol;
	public newDecimal(decimal t, Int64 Kol) {
			kol = Kol;
			Z = Dec.ToInt64 (t);
			Int64 p = 1;
			for (int i = 0; i < kol; i ++)
				p *= 10L;
			F = Dec.ToInt64 ((t - Z) * p);
		}
		public void print () {
			Console.Write ("{0}.", Z);
			int sz = F.ToString ().Length;
			for (int i = 0; i < kol - sz; i ++)
				Console.Write (0);
			Console.Write (F);
		}
	}

	class MainClass
	{
		public static long[,] C = new long[800, 10];

		public static void PreCalc() {
			C [1,1] = 1L;
			C [2,1] = 2L;
			C [2,2] = 1L;
			for (int i = 3; i <= 777; i ++) C[i,1] = 1L*i;
			for (int i = 3; i <= 777; i ++)
				for (int j = 2; j <= 7; j ++)
					C [i,j] = C [i - 1,j] + C [i - 1,j - 1];
		}

		public static void Main(string[] args) {
			PreCalc ();
			int n = int.Parse (Console.ReadLine ());
			long ans = 0l;

			ans += 4l * 3l * 2l * (1l << ((n - 3) << 1));
			if (n >= 4)
				ans += 3L * 3L * (n - 3L) * (1L << (2 * (n - 3)));
			Console.WriteLine (ans);
		}
	}
}


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

class Solver
{
    Scanner sc = new Scanner();
    //
    public void Solve()
    {
        int l, r, x, y;
        sc.Make(out l, out r, out x, out y);
        var fx = Factorize(x);
        var fy = Factorize(y);
        foreach (var p in fx)
        {
            if (!fy.ContainsKey(p.Key)||fy[p.Key]<p.Value)
                Fail(0);
        }
        var n = new List<P>();
        foreach (var p in fy)
        {
            if (!fx.ContainsKey(p.Key)) fx[p.Key] = 0;
            n.Add(new P(p.Key, p.Value, fx[p.Key]));
        }
        var res = 0;
        var ok = new Dictionary<long, Dictionary<long, bool>>();
        for(var i = 0; i < (1 << n.Count); i++)
        {
            long u = 1, v = 1;
            for(var j=0;j<n.Count;j++)
                if ((1 & i >> j) == 1)
                {
                    for (var k = 0; k < n[j].x; k++)
                        u *= n[j].v;
                    for (var k = 0; k < n[j].y; k++)
                        v *= n[j].v;
                }
                else
                {
                    for (var k = 0; k < n[j].x; k++)
                        v *= n[j].v;
                    for (var k = 0; k < n[j].y; k++)
                        u *= n[j].v;
                }
            if (r < u || u < l || r < v || v < l) continue;
            if (!ok.ContainsKey(u))
                ok[u] = new Dictionary<long, bool>();
            if (!ok[u].ContainsKey(v))
            {
                res++;
                ok[u][v] = true;
            }
        }
        WriteLine(res);
    }
    struct P
    {
        public long v, x, y;
        public P(long V,int X,int Y)
        {
            v = V;x = X;y = Y;
        }
    }

    public static Dictionary<long, int> Factorize(long num)
    {
        var dic = new Dictionary<long, int>();
        for (var i = 2L; i * i <= num; i++)
        {
            var ct = 0;
            while (num % i == 0)
            {
                ct++;
                num /= i;
            }
            if (ct != 0) dic[i] = ct;
        }
        if (num != 1) dic[num] = 1;
        return dic;
    }
}

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

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

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

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

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

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


using System;
using System.Linq;
using System.Collections.Generic;
using Debug = System.Diagnostics.Debug;
using StringBuilder = System.Text.StringBuilder;
using System.Numerics;
using Point = System.Numerics.Complex;
using Number = System.Int64;
namespace Program
{
    public class Solver
    {
        public void Solve()
        {
            var q = sc.Integer();
            var par = new int[500002];
            par[0] = -1;
            var dp = Enumerate(500002, x => new double[45]);
            for (int i = 1; i < 45; i++)
                dp[0][i] = 1.0;

            var ptr = 1;
            Action<int> recalc = null;
            recalc = v =>
              {
                  for (int h = 1; h < 40; h++)
                      dp[v][h] = 1.0;
                  var ps = new List<int>();
                  for (int h = 0; h <= 40; h++)
                  {
                      if (v == -1) break;
                      ps.Add(v);
                      v = par[v];
                  }
                  for (int i = ps.Count - 2; i > 0; i--)
                  {
                      var u = ps[i]; var h = i;
                      var p = ps[i + 1];
                      dp[p][h + 1] /= (dp[u][h] + 1) / 2;
                  }
                  for (int i = 0; i + 1 < ps.Count; i++)
                  {
                      var u = ps[i]; var h = i;
                      var p = ps[i + 1];
                      dp[p][h + 1] *= (dp[u][h] + 1) / 2;
                  }
              };
            for (int i = 0; i < q; i++)
            {
                if (sc.Integer() == 1)
                {
                    var p = sc.Integer() - 1;
                    par[ptr] = p;
                    recalc(ptr);
                    ptr++;

                }
                else
                {
                    var v = sc.Integer() - 1;
                    var ans = 0.0;
                    for (int h = 1; h < 40; h++)
                        ans += 1 - dp[v][h];
                    Debug.WriteLine(dp[v].AsJoinedString());
                    IO.Printer.Out.WriteLine(ans);

                }
            }
        }
        public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());
        static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; }
        static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
    }
}

#region main
static class Ex
{
    static public string AsString(this IEnumerable<char> ie) { return new string(System.Linq.Enumerable.ToArray(ie)); }
    static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); }
    static public void Main()
    {
        var solver = new Program.Solver();
        solver.Solve();
        Program.IO.Printer.Out.Flush();
    }
}
#endregion
#region Ex
namespace Program.IO
{
    using System.IO;
    using System.Text;
    using System.Globalization;
    public class Printer: StreamWriter
    {
        static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; }
        public static Printer Out { get; set; }
        public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
        public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
        public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) { }
        public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); }
        public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); }
    }
    public class StreamScanner
    {
        public StreamScanner(Stream stream) { str = stream; }
        public readonly Stream str;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream { get { return isEof; } }
        private byte read()
        {
            if (isEof) return 0;
            if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } }
            return buf[ptr++];
        }
        public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; }

        public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
        public string ScanLine()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b != '\n'; b = (char)read())
                if (b == 0) break;
                else if (b != '\r') sb.Append(b);
            return sb.ToString();
        }
        public long Long()
        {
            if (isEof) return long.MinValue;
            long ret = 0; byte b = 0; var ng = false;
            do b = read();
            while (b != 0 && b != '-' && (b < '0' || '9' < b));
            if (b == 0) return long.MinValue;
            if (b == '-') { ng = true; b = read(); }
            for (; true; b = read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = ret * 10 + b - '0';
            }
        }
        public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }
        public double Double() { var s = Scan(); return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; }
        private T[] enumerate<T>(int n, Func<T> f)
        {
            var a = new T[n];
            for (int i = 0; i < n; ++i) a[i] = f();
            return a;
        }

        public char[] Char(int n) { return enumerate(n, Char); }
        public string[] Scan(int n) { return enumerate(n, Scan); }
        public double[] Double(int n) { return enumerate(n, Double); }
        public int[] Integer(int n) { return enumerate(n, Integer); }
        public long[] Long(int n) { return enumerate(n, Long); }
    }
}
#endregion


using System;
using System.Linq;

namespace A_TrickyAlchemy
{
    class Program
    {
        static void Main(string[] args)
        {
            var having = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            var want = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            var neededYellow = 2 * want[0] + want[1];
            var neededBlue = want[1] + 3 * want[2];
            var result = Math.Max(0, neededYellow - having[0]) + Math.Max(0, neededBlue - having[1]);

            Console.WriteLine(result);
        }
    }
}


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

namespace Solution
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var a = Console.ReadLine();
            var SFtoS = Regex.Matches(a, "FS");
            var StoSF = Regex.Matches(a, "SF");
            Console.WriteLine(StoSF.Count > SFtoS.Count ? "YES" : "NO");
        }
    }
}


// Submitted by Silithus @ Macau
using System;
using System.Collections.Generic;
using System.Text;

namespace CF389_Round228d2
{
	class CF389A
	{
		public int GCD(int a, int b)
		{
			int t;
			if (a < b) { t = b; b = a; a = t; }
			while ((t = a % b) != 0) { a = b; b = t; }
			return b;
		}

		public void Solve()
		{
			int i, N,ans;
			int[] x = new int[100];

			N = XOI.r32();
			ans = XOI.r32();
			for(i=1; i<N; i++)
				ans = GCD(ans, XOI.r32());

			Console.WriteLine(N * ans);
		}

		static void Main(string[] args)
		{
			(new CF389A()).Solve();
		}
	}

	class XOI
	{
		public static int r32()
		{
			int n, c;
			do { c = Console.Read(); } while (c < '0');
			for (n = 0; c >= '0'; c = Console.Read())
				n = n * 10 + (c - '0');
			return n;
		}

		public static void r32x2(out int a, out int b)
		{
			a = XOI.r32();
			b = XOI.r32();
		}

		public static void r32x3(out int a, out int b, out int c)
		{
			XOI.r32x2(out a, out b);
			c = XOI.r32();
		}

		public static long r64()
		{
			long n, c;
			do { c = Console.Read(); } while (c < '0');
			for (n = 0; c >= '0'; c = Console.Read())
				n = n * 10 + (c - '0');
			return n;
		}
	}
}


using System;
using System.Linq;

namespace CSharp
{
    public class _9A
    {
        public static void Main(string[] args)
        {
            switch (Console.ReadLine().Split().Select(token => int.Parse(token)).Max())
            {
                case 1:
                    Console.WriteLine("1/1");
                    break;
                case 2:
                    Console.WriteLine("5/6");
                    break;
                case 3:
                    Console.WriteLine("2/3");
                    break;
                case 4:
                    Console.WriteLine("1/2");
                    break;
                case 5:
                    Console.WriteLine("1/3");
                    break;
                case 6:
                    Console.WriteLine("1/6");
                    break;
            }
        }
    }
}


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

namespace ConsoleApp5
{
    public class Program
    {
        //var t = int.Parse(Console.ReadLine());
        //var arr = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

        static void Main()
        {
            var a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var r = a[0];
            var c = a[1];
            var setR = new HashSet<int>();
            var setC = new HashSet<int>();
            for (int i = 0; i < r; i++)
            {
                var s = Console.ReadLine();
                for (int j = 0; j < c; j++)
                {
                    if (s[j] == 'S')
                    {
                        setR.Add(i);
                        setC.Add(j);
                    }
                }
            }

            var rCount = r - setR.Count();
            var cCount = c - setC.Count();
            var res = rCount * c + cCount * r - rCount * cCount;
            Console.WriteLine(res);
        }
    }
}


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

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

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

            int sum = 1;
            for (int i = 1; i < s.Length; i++)
            {
                if (s[i] > '1')
                    sum += s[i] - '0';
                else
                {
                    sum += 10;
                    i ++;
                }
            }

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


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

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

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

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

            reader = iReader;
            writer = oWriter;

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

        string[] curLine;
        int curTokenIdx;

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

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

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

            return curLine[curTokenIdx++];
        }

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

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

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

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

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

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

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

    class Program
    {
        protected IOHelper ioHelper;

        int n;
        int k;

        int[] types;
        int E, S;

        int Compute(int r)
        {
            int j;
            int e = 0;
            int s = 0;
            for(j=r;j<n;j+=k)
            {
                if (types[j] == 1)
                    e++;
                else
                    s++;
            }

            return Math.Abs(E-e - (S-s));
        }

        public void Solve()
        {
            n = ioHelper.ReadNextInt();
            k = ioHelper.ReadNextInt();
            types = new int[n + 2];

            int i;
            for (i = 0; i < n; i++)
            {
                types[i] = ioHelper.ReadNextInt();
                if (types[i] == 1)
                    E++;
                else
                    S++;
            }

            int rest;
            int best = 0;
            for(rest=0;rest<k;rest++)
            {
                var resHere = Compute(rest);
                if (resHere > best)
                    best = resHere;
            }

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

            //Console.ReadKey();
        }

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

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