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

namespace KROK_QR
{
    class TaskB
    {
        static void Main(string[] args)
        {

            int a, b, m, r_cur, r_next, index;
            string str;
            string[] s = new string[4];
            //int[] r = new int[110000];
            ArrayList r = new ArrayList();
            str = Console.ReadLine();
            s = str.Split();
            a = int.Parse(s[0]);
            b = int.Parse(s[1]);
            m = int.Parse(s[2]);
            r_cur = int.Parse(s[3]);

            while (1 == 1)
            {
                r_next = (a * r_cur + b) % m;
                index = r.IndexOf(r_next);
                if (index == -1)
                {
                    r.Add(r_next);
                    r_cur = r_next;
                }
                else
                    break;
            }

            Console.WriteLine(r.Count - index);

        }
    }
}


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

namespace krok02
{
    class Program
    {

        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string[] ss = s.Split();
            int a, b, m, r0;
            a = Convert.ToInt32(ss[0]);
            b = Convert.ToInt32(ss[1]);
            m = Convert.ToInt32(ss[2]);
            r0 = Convert.ToInt32(ss[3]);
            int t = 0;
            int x = 0;
            int[] mas = new int[100000];
            mas[0] = r0;
            for (int i = 1; i < mas.Length; i++)
            {
                mas[i] = (a * mas[i - 1] + b) % m;
                x = Array.IndexOf(mas, mas[i]);
                if (x < i)
                {
                    t = i - x;
                    break;
                }
            }
            Console.WriteLine(t);
            //Console.ReadLine();
        }
    }
}


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

namespace krokA
{
    class Program
    {
        class Scanner
        {
            string[] s;
            int i;

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

            public Scanner()
            {
                //s = @"3 6 81 9".Split(cs, StringSplitOptions.RemoveEmptyEntries);
                s = new string[0];
                i = 0;
            }

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

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

            public long nextLong()
            {
                return long.Parse(next());
            }
        }
        static void Main(string[] args)
        {
            RC rc = new RC();
            rc.Go();
        }

        class RC
        {
            public void Go()
            {
                Scanner sc = new Scanner();
                int a = sc.nextInt();
                int b = sc.nextInt();
                int m = sc.nextInt();
                int r0 = sc.nextInt();

                List<int> lst = new List<int>();
                //lst.Add(r0);
                while (true)
                {
                    r0 = (r0 * a + b) % m;
                    if(lst.Contains(r0))
                    {
                        int pos = lst.FindIndex(p => p == r0);
                        Console.WriteLine(lst.Count - pos);
                        return;
                    }
                    lst.Add(r0);
                }
            }
        }
    }
}


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

namespace Codeforces
{
    internal class Program
    {
        private const string Test = "A1";

        private static void Solve()
        {
            var input = ReadIntArray();
            var a = input[0];
            var b = input[1];
            var m = input[2];
            var r0 = input[3];
            var res = new List<int>();
            var r = r0;
            for (int i = 0; i < m; i++)
            {
                r = (a*r + b)%m;
                if(res.Contains(r))
                    break;
                res.Add(r);
            }
            int first = 0;
            for (; first < res.Count; first++)
            {
                if (res[first] == r)
                    break;
            }
            Console.WriteLine(res.Count - first);
        }

        private static void Main()
        {
            if (Debugger.IsAttached)
            {
                Console.SetIn(new StreamReader(String.Format(@"..\..\..\..\Tests\{0}.in", Test)));
            }

            Solve();

            if (Debugger.IsAttached)
            {
                Console.In.Close();
                Console.SetIn(new StreamReader(Console.OpenStandardInput()));
                Console.ReadLine();
            }
        }

        #region Reader

        private static string Read()
        {
            return Console.ReadLine();
        }

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

        private static List<int> ReadIntArray()
        {
            var input = Console.ReadLine().Split(' ').Select(Int32.Parse).ToList();
            return input;
        }

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

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

        private static int ReadNextInt(string[] input, int index)
        {
            return Int32.Parse(input[index]);
        }

        #endregion
    }
}


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

namespace CODE2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            int m = int.Parse(str[2]);
            int r0 = int.Parse(str[3]);
            int [] array = new int[m];
            int ri = (a * r0 + b) % m;
            array[ri] = 0;
            int count = 1;
            for (; ;count++ )
            {
                ri = (a * ri + b) % m;
                if (array[ri] == 0)
                {
                    array[ri] = count;
                }
                else
                {
                    Console.Write(count - array[ri]);
                    return;
                }
            }
        }
    }
}

[close]


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

namespace CODE2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            int m = int.Parse(str[2]);
            int r0 = int.Parse(str[3]);
            int [] array = new int[m];
            int ri = (a * r0 + b) % m;
            array[ri] = 0;
            int count = 1;
            for (; ;count++ )
            {
                ri = (a * ri + b) % m;
                if (array[ri] == 0)
                {
                    array[ri] = count;
                }
                else
                {
                    Console.Write(count - array[ri]);
                }
            }
        }
    }
}


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

namespace CODE2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            int m = int.Parse(str[2]);
            int r0 = int.Parse(str[3]);
            int [] array = new int[m];
            int ri = (a * r0 + b) % m;
            array[ri] = 0;
            int count = 1;
            for (; ;count++ )
            {
                ri = (a * ri + b) % m;
                if (array[ri] == 0)
                {
                    array[ri] = count;
                }
                else
                {
                    Console.Write(count - array[ri]);
                    return;
                }
            }a
        }
    }
}


using System;
using System.Collections.Generic;

namespace ConsoleApplication11
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int r = int.Parse(str[3]);
            int r1,i=0;
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            int m = int.Parse(str[2]);
            bool flag=false;
            List<int> lis = new List<int>();
            while (true)
            {
                r1 = (a * r + b) % m;
                lis.Add(r1);
                r = r1;
                if (lis.Count >10000)
                {
                    for (i = 0; i < lis.Count; i++)
                    {
                        for (int j = i + 1; j < lis.Count; j++)
                        {
                            if (lis[i] == lis[j])
                            {
                                i = j - i;
                                flag = true;
                                break;
                            }
                        }
                        if (flag)
                            break;
                    }
                    if (flag)
                        break;
                }
            }
            Console.WriteLine(i);
        }
    }
}


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

namespace krok2
{
    class Program
    {
        private static int a, b, m, r0;
        static List<int> nums = new List<int>();

        static void Main(string[] args)
        {
            string readLine = Console.ReadLine();
            string[] strings = readLine.Split(new[] {' '});
            // a b m r0
            a = int.Parse(strings[0]);
            b = int.Parse(strings[1]);
            m = int.Parse(strings[2]);
            r0 = int.Parse(strings[3]);
            nums.Add(r0);

            bool notFound = true;
            int count = 1;

            while (notFound)
            {
                int number = Generate(count);
                if (!nums.Contains(number))
                {
                    nums.Add(number);
                    count++;
                }
                else
                {
                    int i = count - nums.IndexOf(number);
                    Console.WriteLine(i);
                    break;
                }
            }
        }

        static int Generate(int i)
        {
            int result = (a * nums[i - 1] + b) % m;
            return result;
        }
    }
}


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

namespace codeforces
{
    class Program
    {
        static int a, b, m, r0;

        static void Main()
        {
            var input = Console.ReadLine().Split(' ');
            a = int.Parse(input[0]);
            b = int.Parse(input[1]);
            m = int.Parse(input[2]);
            r0 = int.Parse(input[3]);

            List<int> nums = new List<int>();

            int r = (a * r0 + b) % m;
            nums.Add(r);

            while (true)
            {
                r = (a * r + b) % m;
                if (!nums.Contains(r))
                {
                    nums.Add(r);
                }
                else
                {
                    Console.WriteLine(nums.Count - nums.IndexOf(r));
                    break;
                }
            }
        }

        static int Next(int r)
        {
            return (a * r + b) % m;
        }
    }
}


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

namespace CrocCupB
{
    class Program
    {
        static void Main(string[] args)
        {
            //получим исходные данные
            var nkList = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
            var a = nkList[0];
            var b = nkList[1];
            var m = nkList[2];
            var r0 = nkList[3];

            var randGenerator = new RandGenerator(a, b, m, r0);
            var randList = new List<int>();

            //поищем цикл...
            var curRandom = randGenerator.GetNext();
            var cycleIndex = -1;
            while ((cycleIndex = randList.IndexOf(curRandom)) < 0)
            {
                randList.Add(curRandom);
                curRandom = randGenerator.GetNext();
            }

            Console.WriteLine(randList.Count - cycleIndex);
        }
    }

    internal class RandGenerator
    {
        private readonly int _a;
        private readonly int _b;
        private readonly int _m;
        private int _ri;

        public RandGenerator(int a, int b, int m, int r0)
        {
            _a = a;
            _b = b;
            _m = m;
            _ri = r0;
        }

        public int GetNext()
        {
            return _ri = (((_a*_ri) + _b)%_m);
        }
    }
}


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

class Program
{
    static void p(object value)
    {
        Console.WriteLine(value.ToString());
    }

    static string gets()
    {
        return Console.ReadLine();
    }
        static void Main(string[] args)
        {
          string input = gets();

          int[] r = new int[100001];

          int a = int.Parse(input.Split(' ')[0]);
          int b = int.Parse(input.Split(' ')[1]);
          int m = int.Parse(input.Split(' ')[2]);

          r[0] = int.Parse(input.Split(' ')[3]);

          bool found = false;
          int end = 0;
          int start = 0;
          int t=0;

          for (int i=1; i<100001;i++)
          {
              r[i] = (a*r[i-1]+b) % m;

              if (found) {
              if (r[i] == r[start]) {
                 p(t);
                 break;
              }

              if (r[i] == r[start+t]) {
                t = t +1;
                continue;
              }

              if (r[i] != r[start+t]) {
                 found = false;
                 i = end + 1;
              }
              }

              for (int j = 1; j<i; j++)
              {
                  if (r[j]==r[i]) {
                     found = true;
                     end = i;
                     start = j;
                     t = 1;
                  }
              }
          }
        }
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string str = Console.ReadLine();
            int t = 1,
                ind = 0,
                k = 0,
                vr = 0;
            bool y = true;

            while (ind + (t * 3) < n && y)
            {
                for (int j = ind+vr; j < n; j++)
                {
                  if (str[j] == '*')
                  { ind = j; break; }
                }
                vr = 1;
                for (int i = ind + t; ind + (t * 3) < n;)
                {
                    if (str[i] == '*')
                    { k++; i += t; }
                    else
                    {
                        t++;
                        i = ind + t;
                        k = 0;
                    }
                    if (k == 3)
                    { Console.WriteLine("yes"); y = false; break; }
                }
            t = 1;
            k = 0;
            }
            if (y)
                Console.WriteLine("no");
        }
    }
}


using System;
using System.Linq;

namespace CSharp
{
    public class _877A
    {
        public static void Main()
        {
            string s = Console.ReadLine();
            Console.WriteLine(new string[] { "Danil", "Olya", "Slava", "Ann", "Nikita" }.Count(name => s.Contains(name) && s.IndexOf(name, s.IndexOf(name) + name.Length) < 0) == 1 ? "YES" : "NO");
        }
    }
}


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

//namespace Codeforces
//{
//	internal class Template
//	{
//		private void Solve()
//		{
//			var n = cin.NextInt();
//			var x = new List<int>();
//			var y = new List<int>();
//			for (var i = 0; i < n; i++)
//			{
//				x.Add(cin.NextInt());
//				y.Add(cin.NextInt());
//			}
//			x = x.Distinct().ToList();
//			y = y.Distinct().ToList();
//			if (x.Count == 2 && y.Count == 2)
//			{
//				var area = Math.Abs(x[0] - x[1]) * Math.Abs(y[0] - y[1]);
//				Console.WriteLine(area);
//			}
//			else
//			{
//				Console.WriteLine(-1);
//			}
//		}

//		private static readonly Scanner cin = new Scanner();

//		private static void Main()
//		{
//#if DEBUG
//			Console.SetIn(new StreamReader(@"..\..\input.txt"));
//#endif
//			new Template().Solve();
//			Console.ReadLine();
//#if DEBUG
//			Console.ReadKey();
//#endif
//		}
//	}

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

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

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

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

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


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

namespace Codeforces582
{
    internal class Program2
    {
        private static void Main()
        {
            var input = Console.ReadLine().Split(' ').Select(int.Parse);
            var n = input.First();
            var k = input.Skip(1).First();
            var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            var zeroCosts = new int[n];
            for (var i = 0; i < n; i++)
            {
                var tmpCost = 0;
                var tmpAi = a[i];
                while (tmpAi > 0)
                {
                    tmpCost++;
                    tmpAi /= 2;
                }

                zeroCosts[i] = tmpCost;
            }

            Array.Sort(zeroCosts);
            var zeroAns = 0;
            for (var i = 0; i < k; i++) zeroAns += zeroCosts[i];
            var ans = zeroAns;

            foreach (var item in a)
            {
                var costs = new int[n];
                for (var i = 0; i < n; i++)
                    if (a[i] < item)
                    {
                        costs[i] = -1;
                    }
                    else
                    {
                        var tmpCost = 0;
                        var tmpAi = a[i];
                        while (tmpAi > item)
                        {
                            tmpCost++;
                            tmpAi /= 2;
                        }

                        if (tmpAi != item) costs[i] = -1;
                        else costs[i] = tmpCost;
                    }

                Array.Sort(costs);
                var tmpAns = 0;
                var tmpNum = 0;
                for (var i = 0; i < n && tmpNum < k; i++)
                {
                    if (costs[i] == -1) continue;

                    tmpNum++;
                    tmpAns += costs[i];
                }

                if (tmpNum == k && tmpAns < ans) ans = tmpAns;
            }

            Console.WriteLine(ans);
        }
    }
}


using System;

public class Test
{
	public static void Main()
	{
		string input = Console.ReadLine();

		Console.WriteLine(GetHQ9p(input));
	}

	public static string GetHQ9p(string input)
	{
		char[] alphabet = new char[]{'H','Q','9','+'}

		foreach(char a in input){
			foreach(char a2 in alphabet){
				if(a==a2){
					return "YES";
				}
			}
		}
		return "NO";
	}
}


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

namespace HQ+9
{
    class Program
    {
        static void Main(string[] args)
        {
          here:  string p = Console.ReadLine();
            if(p.Length<1||p.Length>100)
            {
                goto here;
            }
            char[] arr = p.ToCharArray();
            bool check = false;
            for(int i=0;i<arr.Length;i++)
            {
                if(arr[i]=='H'||arr[i]=='Q'||arr[i]=='+'||arr[i]=='9')
                {
                    check=true;
                    break;
                }
            }
            if(check==true)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }
}


<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{BBEEF3C8-5164-42A6-A65A-D19AFC694892}</ProjectGuid>
    <OutputType>Exe</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>HelloWorld</RootNamespace>
    <AssemblyName>HelloWorld</AssemblyName>
    <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Net.Http" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Program.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <ItemGroup>
    <None Include="App.config" />
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
</Project>


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

namespace HQ9+
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            if (line.Contains('H')||line.Contains('Q')||line.Contains('9')) Console.WriteLine("YES");
            else Console.WriteLine("NO");
        }
    }
}


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

namespace Pr1
{
    class Program
    {
        static void Main()
        {
            string a= Console.ReadLine();
            int k=1,max=0;
            string s="AEIOUY";
            for(int i=0;i<a.Length;i++)
            {
                if(!s.Contains(a[i]))
                {
                    k++;
                    if(i==a.Length-1)
                        max=Math.Max(k,max)
                }
                else
                {
                    max=Math.Max(k,max);
                    k=1;
                }
            }
            Console.WriteLine(max);

        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution{
	 static void Main(string[] args) {
           cconst int MOD = 1000000007;
            int n = int.Parse(Console.ReadLine());
            int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), x => Convert.ToInt32(x));
            C = new long[200, 200];
            C[0, 0] = 1;
            for (int i = 1; i < 200; i++) {
                C[i, 0] = C[i, i] = 1;
                for (int j = 1; j <= i; j++)
                    C[i, j] = (C[i - 1, j] + C[i - 1, j - 1]) % MOD;
            }

            long ans = 0;
            for (int k = a.Sum(); k <= n; k++) {

                long[,] dp = new long[110, 30];
                dp[k, 0] = 1;

                for (int j = 0; j < 10; j++)
                    for (int i = a[j]; i <= k; i++)
                        for (int l = a[j]; l <= i; l++) {
                            if (j == 0) dp[i - l, j + 1] = (dp[i - l, j + 1] + dp[i, j] * CNK(i - 1, l) % MOD) % MOD;
                            else dp[i - l, j + 1] = (dp[i - l, j + 1] + dp[i, j] * CNK(i, l) % MOD) % MOD;
                        }

                ans += dp[0, 10];
                ans %= MOD;
            }

            Console.WriteLine(ans);
	 }
     static long[,] C;
        static long CNK(long n, long k) {
            if (k > n || k < 0) return 0;
            if (k == n || k == 0) return 1;
            return C[n, k];
        }
}


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

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

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

            var nn = new int[n];
            for (int i = 0; i < n; i++)
            {
                nn[i] = Next();
            }

            writer.WriteLine(nn.Max() - nn[n - 1]);
            writer.Flush();
        }

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


using System;

class Program
{
    static void Main()
    {
        string s = Console.ReadLine();
        int val = Convert.ToInt32(Console.ReadLine());
        string all = "";
        for (int i = 0; i < val; i++)
        {
            all += Console.ReadLine();
        }
        Console.WriteLine(all.Contains(s)?"YES":"NO");
    }
}


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

namespace DoubleCola
{
    class Program
    {
        static void Main(string[] args)
        {
            int number = int.Parse(Console.ReadLine());

            List<string> queu = new List<string>();

            int i = 0 ;
            int k = 1;
            while (i < number )

            {

                for (int j = 1; j <= k; j++)
                {
                    queu.Add("Sheldon");
                    i++;
                }
                for (int j = 1; j <= k; j++)
                {
                    queu.Add("Leonard");
                    i++;
                }
                for (int j = 1; j <= k; j++)
                {
                    queu.Add("Penny");
                    i++;
                }
                for (int j = 1; j <= k; j++)
                {
                    queu.Add("Rajesh");
                    i++;
                }
                for (int j = 1; j <= k; j++)
                {
                    queu.Add("Howard");
                    i++;
                }
                k *= 2;
            }

            Console.WriteLine(queu[number-1]);
            Console.ReadLine();
        }
    }
}


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

namespace Codeforces
{
    class C
    {
        private static ThreadStart s_threadStart = new C().Go;
        private static bool s_time = true;

        Dictionary<int, int> memo;
        int DP(int x)
        {
            if (!memo.ContainsKey(x))
            {
                string s = "" + x;
                int ret = int.MaxValue;
                if (s.Length == 1)
                    ret = 0;
                else
                {
                    foreach (char ch in s)
                    {
                        if (ch != '0')
                        {
                            int y = DP(x - (ch - '0'));
                            if (ret > y) ret = y;
                        }
                    }
                }

                memo[x] = ret + 1;
            }
            return memo[x];
        }

        private void Go()
        {
            int n = GetInt();
            int[] dp = new int[n + 1];

            if (n < 10)
            {
                Wl(1);
                return;
            }

            dp[n] = 0;
            for (int i = n; i >= 0; i--)
            {
                if (i == n || dp[i] != 0)
                {
                    string s = i.ToString();
                    foreach (char ch in s)
                    {
                        if (ch != '0')
                        {
                            int ind = i - (ch - '0');
                            if (dp[ind] == 0 || dp[ind] > dp[i] + 1)
                                dp[ind] = dp[i] + 1;
                        }
                    }
                }
            }

            Wl(dp[0]);
        }

        #region Template

        public static void Main(string[] args)
        {
            System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
            Thread main = new Thread(new ThreadStart(s_threadStart), 200 * 1024 * 1024);
            timer.Start();
            main.Start();
            main.Join();
            timer.Stop();
            if (s_time)
                Wl(timer.ElapsedMilliseconds);
        }

        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)
        {
            if (o is double)
            {
                Wld((o as double?).Value, "");
            }
            else if (o is float)
            {
                Wld((o as float?).Value, "");
            }
            else
                Console.WriteLine(o.ToString());
        }

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

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

        #endregion
    }
}


using System;
using System.Text;

namespace CP
{
    class Program
    {
        static void Main(string[] args)
        {
            char dir = Convert.ToChar(Console.ReadLine());
            string message = Console.ReadLine();
            string keyboard = "qwertyuiopasdfghjkl;zxcvbnm,./";
            StringBuilder sb = new StringBuilder();
            if(dir == 'L')
            {
                for(int i = 0 ; i<message.Length ; i++)
                {
                    for(int j = 0 ; j<keyboard.Length ; j++)
                    {
                        if(message[i]==keyboard[j])
                        sb.Append(keyboard[i-1]);
                    }
                }
            }
            else
            {
                for(int i = 0 ; i<message.Length ; i++)
                {
                    for(int j = 0 ; j<keyboard.Length ; j++)
                    {
                        if(message[i]==keyboard[j])
                        sb.Append(keyboard[i+1]);
                    }
                }
            }
            Console.WriteLine(sb);
            }

        }
    }
}


using System; using System.Linq;

class P {
  static void Main() {
    var s =  Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    var a = s[0]; var b = s[1];
    do {
      a++;
      var tmp = a; var m = 1; var mask = 0;
      while (tmp > 0) {
        if (tmp % 10 == 4 || tmp % 10 == 7) { mask += m * (tmp % 10); m*=10; }
        tmp /= 10;
      }
      if (mask == b) { Console.Write(a); return; }
    }
  }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
namespace ConsoleApplication1
{
    class Program
    {

        static int[] divN=new int[3];
        static int[] divK=new int[3];
        public static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int n, k;
            n = int.Parse(s[0]);
            k = int.Parse(s[1]);
            if (n == k)
            {
                Console.WriteLine(0);
                return;
            }
            if (calcolaDivN(n) && calcolaDivK(k))
            {
                int ris = 0;
                for (int i = 0; i < 3; i++)
                {
                    ris += Math.Abs(divN[i] - divK[i]);
                }
                Console.WriteLine(ris);

            }

            else
            {
                Console.WriteLine(-1);

            }

        }
        static bool calcolaDivN(int i)
        {
            while (i % 2 == 0)
            {
                i /= 2;
                divN[0]++;
            }
            while (i % 3 == 0)
            {
                divN[1]++;
                i /= 3;
            }
            while (i % 5 == 0)
            {
                divN[2]++;
                i /= 5;
            }
            return i == 1;
        }
        static bool calcolaDivK(int i)
        {
            while (i % 2 == 0)
            {
                i /= 2;
                divK[0]++;
            }
            while (i % 3 == 0)
            {
                divK[1]++;
                i /= 3;
            }
            while (i % 5 == 0)
            {
                divK[2]++;
                i /= 5;
            }
            return i == 1;
        }

    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
namespace ConsoleApplication1
{
    class Program
    {

        static int[] divN=new int[3];
        static int[] divK=new int[3];
        static int n, k;
        public static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int n, k;
            n = int.Parse(s[0]);
            k = int.Parse(s[1]);
            if(n==k)
            {
                Console.WriteLine(0);
                return;
            }
            int ris = 0;
            calcolaDivK();
            calcolaDivN();
            if (n == k)
            {
                for (int i = 0; i < 3; i++)
                {
                    ris += Math.Abs(divK[i] - divN[i]);
                }
                Console.WriteLine(ris);
            }
            else
            {
                Console.WriteLine(-1);
            }

        }
        static void calcolaDivN()
        {
            while (n % 2 == 0)
            {
                n /= 2;
                divN[0]++;
            }
            while (n % 3 == 0)
            {
                divN[1]++;
                n /= 3;
            }
            while (n % 5 == 0)
            {
                divN[2]++;
                n /= 5;
            }

        }
        static void calcolaDivK()
        {
            while (k % 2 == 0)
            {
                k /= 2;
                divK[0]++;
            }
            while (k % 3 == 0)
            {
                divK[1]++;
                k /= 3;
            }
            while (k % 5 == 0)
            {
                divK[2]++;
                k /= 5;
            }

        }

    }
}


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

namespace probleme {
    class Program {
        static void Main(string[] args) {
            //Console.SetIn(new StreamReader("file.txt"));
            int n = int.Parse(Console.ReadLine());
            Console.Write((n - 2) * (n - 2));
            //Console.ReadKey();
        }
    }
}


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

namespace Codeforces
{
    class Program
    {

        #region input

        static long readLong() {
            long num;
            long.TryParse(Console.ReadLine(),out num);
            return num;
        }

        static int readInt() {
            int num;
            int.TryParse(Console.ReadLine(),out num);
            return num;
        }

        static bool readBool() {
            int num;
            int.TryParse(Console.ReadLine(),out num);
            return num != 0;
        }

        static long[] readLongs() {
            string[] nums = Console.ReadLine().Split(new char[] { ' ' });
            long[] parsed = new long[nums.Length];
            for(int i = 0; i < nums.Length; i++) {
                long.TryParse(nums[i],out parsed[i]);
            }
            return parsed;
        }

        static int[] readInts() {
            string[] nums = Console.ReadLine().Split(new char[] { ' ' });
            int[] parsed = new int[nums.Length];
            for(int i = 0; i < nums.Length; i++) {
                int.TryParse(nums[i],out parsed[i]);
            }
            return parsed;
        }

        static BitArray readBools() {
            string[] nums = Console.ReadLine().Split(new char[] { ' ' });
            int parsed;
            BitArray bits = new BitArray(nums.Length);
            for(int i = 0; i < nums.Length; i++) {
                int.TryParse(nums[i],out parsed);
                if(parsed != 0) {
                    bits[i] = true;
                }
            }
            return bits;
        }

        #endregion

        #region utility

        static long largeModolu(long a, long b, long m) {
            long prev = a;
            long sum = (b & 1) > 0 ? a : 1;
            int digits = (int)(Math.Ceiling(Math.Log(b,2)));
            for(int i = 1; i < digits; i++) {
                pusing System;
using System.Collections;
using System.Collections.Generic;

namespace Codeforces
{
    class Program
    {

        #region input

        static long readLong() {
            long num;
            long.TryParse(Console.ReadLine(),out num);
            return num;
        }

        static int readInt() {
            int num;
            int.TryParse(Console.ReadLine(),out num);
            return num;
        }

        static bool readBool() {
            int num;
            int.TryParse(Console.ReadLine(),out num);
            return num != 0;
        }

        static long[] readLongs() {
            string[] nums = Console.ReadLine().Split(new char[] { ' ' });
            long[] parsed = new long[nums.Length];
            for(int i = 0; i < nums.Length; i++) {
                long.TryParse(nums[i],out parsed[i]);
            }
            return parsed;
        }

        static int[] readInts() {
            string[] nums = Console.ReadLine().Split(new char[] { ' ' });
            int[] parsed = new int[nums.Length];
            for(int i = 0; i < nums.Length; i++) {
                int.TryParse(nums[i],out parsed[i]);
            }
            return parsed;
        }

        static BitArray readBools() {
            string[] nums = Console.ReadLine().Split(new char[] { ' ' });
            int parsed;
            BitArray bits = new BitArray(nums.Length);
            for(int i = 0; i < nums.Length; i++) {
                int.TryParse(nums[i],out parsed);
                if(parsed != 0) {
                    bits[i] = true;
                }
            }
            return bits;
        }

        #endregion

        #region utility

        static long largeModolu(long a, long b, long m) {
            long prev = a;
            long sum = (b & 1) > 0 ? a : 1;
            int digits = (int)(Math.Ceiling(Math.Log(b,2)));
            for(int i = 1; i < digits; i++) {
                prev = (prev * prev) % (m);
                if((b & (1l << i)) > 0) {
                    sum = (sum * prev) % (m);
                }
            }
            return sum;
        }

        #endregion

        static void Main(string[] args) {
            Console.WriteLine((int)Math.Pow((readInt() - 2),2));
        }
    }
}
rev = (prev * prev) % (m);
                if((b & (1l << i)) > 0) {
                    sum = (sum * prev) % (m);
                }
            }
            return sum;
        }

        #endregion

        static void Main(string[] args) {
            Console.WriteLine((int)Math.Pow((readInt() - 2),2));
        }
    }
}


using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FINDBESTHOUSE
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] SplitedInfo = Console.ReadLine().Split(new char[] {' ', '\n'}).Select(Int32.Parse).ToArray();
            int AmoutofHouse = SplitedInfo[0];
            int GFLocation = SplitedInfo[1] - 1;
            int YourMoney = SplitedInfo[2];
            int[] Finding = new int[AmoutofHouse];
            for (var j = 0; j < AmoutofHouse; j++)
            {
                int test = SplitedInfo[3 + j];
                if (test == 0)
                {
                    Finding[j] = 0;
                }
                else if (YourMoney > test)
                {
                    Finding[j] = 1;
                }
                else
                {
                    Finding[j] = 0;
                }
            }
            int Checker = 1;
            int get1 = 1, get2 = 1;
            int i = 0;
            do
            {
                i++;
                try
                {
                    if (Finding[GFLocation - i] == 0)
                    {
                        continue;
                    }
                    else if (Finding[GFLocation - i] == 1)
                    {
                        get1 = i;
                        break;
                    }
                    else
                    {
                        get1 = 0;
                    }
                }
                catch
                {
                    get1 = 0;
                    break;
                }
            }
            while (Checker == 1);
            Checker = 1;
            i = 0;
            do
            {
                i++;
                try
                {
                    if (Finding[GFLocation + i] == 0)
                    {
                        continue;
                    }
                    else if (Finding[GFLocation + i] == 1)
                    {
                        get2 = i;
                        break;
                    }
                    else
                    {
                        get2 = 0;
                    }
                }
                catch
                {
                    get2 = 0;
                    break;
                }
            }
            while (Checker == 1);
            int result = 0;
            if (get1 == 0)
            {
                result = get2;
            }
            else if (get2 == 0)
            {
                result = get1;
            }
            else
            {
                result = get1 > get2 ? get2 : get1;
            }
            Console.WriteLine(result * 10);

        }
    }
}


using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FINDBESTHOUSE
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] SplitedInfo = Console.ReadLine().Split(' ').Select(Int32.Parse).ToArray();
            int AmoutofHouse = SplitedInfo[0];
            int GFLocation = SplitedInfo[1] - 1;
            int YourMoney = SplitedInfo[2];
            int[] Finding = new int[AmoutofHouse];
            for (var j = 0; j < AmoutofHouse; j++)
            {
                int test = SplitedInfo[3 + j];
                if (test == 0)
                {
                    Finding[j] = 0;
                }
                else if (YourMoney > test)
                {
                    Finding[j] = 1;
                }
                else
                {
                    Finding[j] = 0;
                }
            }
            int Checker = 1;
            int get1 = 1, get2 = 1;
            int i = 0;
            do
            {
                i++;
                try
                {
                    if (Finding[GFLocation - i] == 0)
                    {
                        continue;
                    }
                    else if (Finding[GFLocation - i] == 1)
                    {
                        get1 = i;
                        break;
                    }
                    else
                    {
                        get1 = 0;
                    }
                }
                catch
                {
                    get1 = 0;
                    break;
                }
            }
            while (Checker == 1);
            Checker = 1;
            i = 0;
            do
            {
                i++;
                try
                {
                    if (Finding[GFLocation + i] == 0)
                    {
                        continue;
                    }
                    else if (Finding[GFLocation + i] == 1)
                    {
                        get2 = i;
                        break;
                    }
                    else
                    {
                        get2 = 0;
                    }
                }
                catch
                {
                    get2 = 0;
                    break;
                }
            }
            int result = 0;
            while (Checker == 1);
            if (get1 == 0)
            {
                result = get2;
            }
            else if (get2 == 0)
            {
                result = get1;
            }
            else
            {
                result = get1 > get2 ? get2 : get1;
            }
            Console.WriteLine(result * 10);

        }
    }
}


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

namespace Contest
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            int a, b, c;
            a = Convert.ToInt32(line.Split(' ')[0]);
            b = Convert.ToInt32(line.Split(' ')[1]);
            c = Convert.ToInt32(line.Split(' ')[2]);
            List<int> burutfors = new List<int>();
            burutfors.Add(a * b * c);
            burutfors.Add(a * (b + c));
            burutfors.Add((a * b) + c);
            burutfors.Add((a + b) * c);
            burutfors.Add(a + (b * c));
            burutfors.Add(a + b + c);
            burutfors.Sort();

            Console.WriteLine(burutfors.ElementAt(5));

        }
    }
}


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

namespace Codeforces
{
	class Program
	{
		static void Main(string[] args)
		{
			int x2 = int.Parse(Console.ReadLine());
			int px2 = Factorize(x2);
			int min = x2;
			int start2 = ((x2 / px2) - 1) * px2 + 1;

			for (int x1 = start2; x1 <= x2; x1++)
			{
				int px1 = Factorize(x1);
				int start1 = ((x1 / px1) - 1) * px1 + 1;
				if (start1 > 2 && start1 < min)
				{
					min = start1;
				}
			}
			Console.WriteLine(min);
			Console.ReadLine();
		}

		/// <summary>
		/// Разложение числа на простые множители O(n).
		/// </summary>
		public static int Factorize(int n)
		{
			//var res = new List<int>();
			int cur = n;
			int m = 2;
			int res = 0;
			while(cur != 1)
			{
				if (cur % m == 0)
				{
					cur /= m;
					//res.Add(m);
					res = m;
				}
				else m++;
			}
			return res;
		}
	}
}


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

namespace Codeforces
{
	class Program
	{
		static void Main(string[] args)
		{
			int x2 = int.Parse(Console.ReadLine());
			int px2 = maxPrimeDivs(x2);
			int min = x2;
			int start2 = ((x2 / px2) - 1) * px2 + 1;

			for (int x1 = start2; x1 <= x2; x1++)
			{
				int px1 = maxPrimeDivs(x1);
				int start1 = ((x1 / px1) - 1) * px1 + 1;
				if (start1 > 2 && starta1 < min)
				{
					min = start1;
				}
			}
			Console.WriteLine(min);
			Console.ReadLine();
		}

		private static int maxPrimeDivs(int n)
		{
			int d = 2;
			int result = 0;

			while (d * d <= n)
			{
				if (n % d == 0)
				{
					n /= d;
					if (result < d)
						result = d;
				}
				else d++;
			}
			return Math.Max(result, n);
		}

	}
}


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

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            int n = int.Parse(s[0]);
            int d = int.Parse(s[1]);
            string st = Console.ReadLine();
            int pos = 0;
            int kol = 0;
            while (pos!=st.Length-1)
            {
                int len = Math.Min(d, st.Length - pos - 1);
                string ss = st.Substring(pos+1, len);
                int lastind = ss.LastIndexOf('1');
                if (lastind == 0)
                {
                    Console.WriteLine(-1);
                    return;
                }
                pos += lastind+1;
                kol++;
            }
            Console.WriteLine(kol);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO.Pipes;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;

class Test
{
    static long MOD = 1000000007;
    static long[] fact = new long[500001];
    static long[] factInv = new long[500001];
    static List<int> anss = new List<int>();
    // Driver code
    public static void Main()
    {
        //int t = int.Parse(Console.ReadLine());
        // while (t > 0)
        {
            //  t--;
            var input1 = Console.ReadLine().Split(' ').Select(xx => int.Parse(xx)).ToArray();
            var n = input1[0];
            var k = input1[1];

            var arr = Console.ReadLine();
            var ans = minJumps(arr, 0, n - 1, k);
            Console.WriteLine(ans==int.MaxValue?-1:ans);

        }
    }

    static int minJumps(string arr, int l, int h,int k)
    {
        if (h == l)
            return 0;
        if (arr[l] == '0')
            return int.MaxValue;

        int min = int.MaxValue;
        for (int i = l + 1; i <= h && i <= l + k; i++)
        {
            int jumps = minJumps(arr, i, h,k);
            if (jumps != int.MaxValue && jumps + 1 < min)
                min = jumps + 1;
        }
        return min;
    }

    public static long FastPower(long a, long b)
    {
        if (b == 0)
            return 1;

        var val = FastPower(a, b / 2);

        if (b % 2 == 0)
            return val * val % MOD;
        else
            return val * val % MOD * a % MOD;
    }

    public static void Fact()
    {
        fact[0] = 1;
        factInv[0] = FastPower(fact[0], MOD - 2);

        for (int i = 1; i <= 500000; i++)
        {
            fact[i] = i * fact[i - 1] % MOD;
            factInv[i] = FastPower(fact[i], MOD - 2);
        }

    }

    public static long NCR(long n, long r)
    {
        return fact[n] * factInv[r] % MOD * factInv[n - r] % MOD;
    }
}


#region Usings
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;

using static System.Math;
#endregion

// https://codeforces.com/problemset/problem/910/A
public class A___The_Way_to_Home
{
    static int n, d;
    static string s;
    private static void Solve()
    {
        n = ReadInt();
        d = ReadInt();
        s = Read();

        int result = Jump(0, 0, n);

        // If value still n, it never actually reached n.
        // You need n - 1 jumps to get there, so the value was not overriden.
        // If it was not overriden, it means minJumps was never assigned jumps.
        // So the (pos == n - 1) condition was never reached.
        Write(result == n ? -1 : result);
    }

    /// <param name="pos">Current position</param>
    /// <param name="jumps">Accumulated jumps so far</param>
    /// <param name="minJumps">Min jumps discovered to achieve n so far</param>
    static int Jump(int pos, int jumps, int minJumps)
    {
        if (pos == n - 1)
            return jumps;

        // i = Jumping destination
        for (int i = pos + 1; i < Min(pos + d + 1, n); i++)
        {
            if (s[i] == '1')
                minJumps = Min(minJumps, Jump(i, jumps + 1, minJumps));
        }

        return minJumps;
    }

    #region Main

    private static TextReader reader;
    private static TextWriter writer;

    public static void Main()
    {
#if DEBUG

        //reader = new StreamReader("C:\\Users\\Axel\\Desktop\\input.txt");
        reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;

        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());

        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            Solve();

            //var thread = new Thread(new String_Task().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
#if DEBUG
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion Main

    #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 Read()
    {
        while (currentLineTokens.Count == 0) currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue();
    }

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

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

    public static double ReadDouble()
    {
        return double.Parse(Read(), 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 Read / Write
}


/*
csc -debug C.cs && mono --debug C.exe <<< "6 10"
*/

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

public class HelloWorld {
    public static void SolveCodeForces() {
        var a = cin.NextUlong();
        var b = cin.NextUlong();

        var bestAns = (a * b) / GCD(a, b);
        var bestK = 0ul;

// System.Console.WriteLine(new {bestAns, bestK});

        var ans1 = (a + 1ul) * (b + 1ul) / GCD(a + 1ul, b + 1ul);
        if (ans1 < bestAns) {
            bestAns = ans1;
            bestK = 1ul;
        }

// System.Console.WriteLine(new {bestAns, bestK, ans1});

        if (a > b) {
            var tmp = b;
            b = a;
            a = tmp;
        }
        // here a <= b;

        var d = b - a;

        if (2ul * a <= b) {
            var k = d;
            var ans = (a + k) * (b + k) / GCD(a + k, b + k);
            if (ans < bestAns) {
                bestAns = ans;
                bestK = k;
            }
// System.Console.WriteLine(new {a, b, k, ans});
        }

        if (d != 0) {
            for (var z = 1ul; z <= d; z++)
                if (d % z == 0) {

                    var k = z - a % z;
                    var ans3 = (a + k) * (b + k) / GCD(a + k, b + k);
                    if (ans3 < bestAns) {
                        bestAns = ans3;
                        bestK = k;
                    }

                    k = z - b % z;
                    var ans4 = (a + k) * (b + k) / GCD(a + k, b + k);
                    if (ans4 < bestAns) {
                        bestAns = ans4;
                        bestK = k;
                    }

                }
        }

        System.Console.WriteLine(bestK);
    }

    private static ulong GCD(ulong a, ulong b) {
        while (a != 0 && b != 0)
        {
            if (a > b)
                a %= b;
            else
                b %= a;
        }

        return a == 0 ? b : a;
    }

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

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

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

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

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

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

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

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

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

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

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

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

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


/*
csc -debug C.cs && mono --debug C.exe <<< "6 10"
*/

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

public class HelloWorld {
    public static void SolveCodeForces() {
        var a = cin.NextUlong();
        var b = cin.NextUlong();

        var bestAns = (a * b) / GCD(a, b);
        var bestK = 0ul;

// System.Console.WriteLine(new {bestAns, bestK});

        var ans1 = (a + 1ul) * (b + 1ul) / GCD(a + 1ul, b + 1ul);
        if (ans1 < bestAns) {
            bestAns = ans1;
            bestK = 1ul;
        }

// System.Console.WriteLine(new {bestAns, bestK, ans1});

        if (a > b) {
            var tmp = b;
            b = a;
            a = tmp;
        }
        // here a <= b;

        var d = b - a;

        if (2ul * a <= b) {
            var k = d;
            var ans = (a + k) * (b + k) / GCD(a + k, b + k);
            if (ans < bestAns) {
                bestAns = ans;
                bestK = k;
            }
// System.Console.WriteLine(new {a, b, k, ans});
        }

        if (d != 0) {
            var done = new bool[d+1];
            done[0] = true;
            done[1] = true;
            for (var z = 1ul; z <= d; z++)
                if (d % z == 0) {

                    var k = z - a % z;
                    if (!done[k]) {
                        var ans = (a + k) * (b + k) / GCD(a + k, b + k);
                        if (ans < bestAns) {
                            bestAns = ans;
                            bestK = k;
                        }
                        done[k] = true;
                    }

                    k = z - b % z;
                    if (!done[k]) {
                        var ans = (a + k) * (b + k) / GCD(a + k, b + k);
                        if (ans < bestAns) {
                            bestAns = ans;
                            bestK = k;
                        }
                        done[k] = true;
                    }

                }
        }

        System.Console.WriteLine(bestK);
    }

    private static ulong GCD(ulong a, ulong b) {
        while (a != 0 && b != 0)
        {
            if (a > b)
                a %= b;
            else
                b %= a;
        }

        return a == 0 ? b : a;
    }

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

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

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

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

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

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

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

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

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

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

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

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

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


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
            string[] s = Console.ReadLine().Split(' ');
            int n = Convert.ToInt32(s[0]);
            int b = Convert.ToInt32(s[1]);
            int p = Convert.ToInt32(s[2]);

            int x = 0;
            int y = n*p;
            if (n % 2 == 1)
            {
                n--;
                x = b * 2 + 1;
            }
            while (n != 1)
            {
                x += n * b + (n/2);
                n /= 2;
            }
            Console.WriteLine(x.ToString() + " " + y.ToString());

        }
    }
}


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

namespace ConsoleApplication1
{
    class Program
    {

 static long Pow2(long m)
        {
            long temp = 0;
            while (System.Math.Pow(2, temp) < m)
            {
               temp++;
            }
            return (long) System.Math.Pow(2,temp-1) ;
        }
 static void Main()
 {
     long n, b, p;
     string test = Console.ReadLine();
     string[] splitString = test.Split(' ');
     long[] ints = new long[3];
     for (int i = 0; i < 3; i++)
     {
         long x;
         long.TryParse(splitString[i], out x);
         ints[i] = x;
     }

     n = ints[0];
     b = ints[1];
     p = ints[2];

     p = p * n;
     long but = 0;
     long temp;
     while (n > 1)
     {
         temp = Program.Pow2(n);
         but = but + n * b + temp / 2;
         n = temp / 2 + n - temp;
     }
     Console.WriteLine((but - n*b - 1) + " " + p);

 }
    }
}


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

namespace Contest_59
{
    class Program
    {
        static void A()
        {
            var s = Console.ReadLine();
            var a = new string[] { s.ToUpper(), s.ToLower() };
            int[] k = new int[2];

            for (int j = 0; j < 2; j++)
            {
                for (int i = 0; i < s.Length; i++)
                {
                    if (s[i] == a[j][i])
                        k[j]++;
                }
            }
            if (k[0] > k[1])
                Console.WriteLine(a[0]);
            else Console.WriteLine(a[1]);
        }

        static void B()
        {
            int n = int.Parse(Console.ReadLine());
            var t = Console.ReadLine().Split(' ');

            List<int> a = new List<int>();
            List<int> b = new List<int>();

            foreach (var s in t)
            {
                int k = int.Parse(s);
                if (k % 2 == 0)
                    b.Add(k);
                else a.Add(k);
            }
            int sum = 0;
            int min = 0;
            if (a.Count == 0)
            {
                Console.WriteLine(0);
                return;
            }
            if (a.Count % 2 == 0)
            {
                min = a.Min();
            }

            foreach (var s in a)
                sum += s;
            foreach (var s in b)
                sum += s;
            sum -= min;
            Console.WriteLine(sum);
        }

        static void C()
        {
            int n = int.Parse(Console.ReadLine());
            char[] s = Console.ReadLine().ToCharArray();
            Dictionary<char, int> d = new Dictionary<char, int>();
            for (int i = 0; i < n; i++)
                d.Add((char)('a' + i), 0);
            int l = s.Length;
            bool ok = true;
            int needChar = 0;
            for (int i = 0, j = l - 1; i < l / 2; i++, j--)
            {
                if ((s[i] == '?') && (s[j] != '?')) { s[i] = s[j]; d[s[i]]++; }
                else if ((s[i] != '?') && (s[j] == '?'))
                {
                    s[j] =
                        s[i]; d[s[i]]++;
                }
                else if (s[i] != s[j])
                {
                    ok = false;
                    break;
                }
                else if (s[i] == '?') needChar++;
                else d[s[i]]++;
            }
            if (l % 2 == 1)
            {
                if (s[l / 2] == '?')
                    needChar++;
                d[s[l / 2]]++;
            }
            int used = 0;
            List<char> unused = new List<char>();
            foreach (var e in d)
            {
                if ((e.Key < 'a' + n) && (e.Value > 0))
                    used++;
                else unused.Add(e.Key);
            }

            if (n - used > needChar)
                ok = false;
            if (ok)
            {
                for (int i = 0, j = l - 1; i <= l / 2; i++, j--)
                {
                    if (s[i] == '?')
                    {
                        if (needChar > unused.Count)
                        {
                            s[i] = 'a';
                            s[j] = 'a';
                        }
                        else
                        {
                            s[i] = unused[0];
                            s[j] = unused[0];
                            if (unused.Count > 1)
                                unused.RemoveAt(0);
                        }
                        needChar--;
                    }
                }

                for (int i = 0; i < s.Length; i++)
                    Console.Write(s[i]);
            }
            else
            {
                Console.Write("IMPOSSIBLE");
            }
            Console.WriteLine();
        }

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


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

namespace _937B
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();

            var parsedInput = input.Split(' ').Select(x => int.Parse(x)).ToList();
            int hoppers = parsedInput[0];
            int branches = parsedInput[1];

            List<bool> occupations = new List<bool>(branches);
            for (int i = 0; i <= branches; i++)
            {
                occupations.Add(false);
            }
            occupations[0] = true;
            occupations[1] = true;

            for (int i = 2; i <= hoppers; i++)
            {
                for (int j = i; j <= branches; j += i)
                {
                    occupations[j] = true;
                }
            }

            int result = -1;
            for (int i = 0; i <= branches; i++)
            {
                if (!occupations[i])
                    result = i;
            }

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


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

namespace _937B
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            var parsedInput = input.Split(' ').Select(x => int.Parse(x)).ToList();
            int hoppers = parsedInput[0];
            int branches = parsedInput[1];

            List<bool> occupations = new List<bool>(branches);
            for (int i = 0; i <= branches; i++)
            {
                occupations.Add(false);
            }
            occupations[0] = true;
            occupations[1] = true;

            for (int i = 2; i <= hoppers; i++)
            {
                for (int j = i; j <= branches; j += i)
                {
                    occupations[j] = true;
                }
            }

            int result = -1;
            for (int i = 0; i <= branches; i++)
            {
                if (!occupations[i])
                    result = i;
            }

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


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

namespace _937B
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            var timer = new Stopwatch();
            timer.Start();
            var parsedInput = input.Split(' ').Select(x => int.Parse(x)).ToList();
            int hoppers = parsedInput[0];
            int branches = parsedInput[1];

            BitArray occupations = new BitArray(branches + 1);
            occupations[0] = true;
            occupations[1] = true;

            int top = (int)Math.Sqrt(branches);
            for (int i = 2; i <= hoppers && i <= top; i++)
            {
                if (occupations[i])
                    continue;

                int start = i * (int)Math.Ceiling((double)(hoppers + 1) / i);
                for (int j = start; j <= branches; j += i)
                {
                    occupations[j] = true;
                }
            }

            int result = -1;
            for (int i = branches; i > hoppers; i--)
            {
                if (!occupations[i])
                {
                    result = i;
                    break;
                }
            }

            Console.WriteLine(result);
            timer.Stop();
            //Console.WriteLine(timer.ElapsedMilliseconds);
            Console.ReadLine();
        }
    }
}


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

namespace _937B
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            var timer = new Stopwatch();
            timer.Start();
            var parsedInput = input.Split(' ').Select(x => int.Parse(x)).ToList();
            int hoppers = parsedInput[0];
            int branches = parsedInput[1];

            TightBoolList occupations = new TightBoolList(branches);
            occupations[0] = true;
            occupations[1] = true;

            int top = (int)Math.Sqrt(branches);
            for (int i = 2; i <= hoppers && i <= top; i++)
            {
                if (occupations[i])
                    continue;

                int start = i * (int)Math.Ceiling((double)(hoppers + 1) / i);
                for (int j = start; j <= branches; j += i)
                {
                    occupations[j] = true;
                }
            }

            //int result = -1;
            //for (int i = hoppers + 1; i <= branches; i++)
            //{
            //    if (!occupations[i])
            //        result = i;
            //}

            //Console.WriteLine(result);
            timer.Stop();
            Console.WriteLine(timer.ElapsedMilliseconds);
            Console.ReadLine();
        }

        private unsafe class TightBoolList
        {
            private List<byte> UnderlyingList;

            public int Size { get; private set; }

            public TightBoolList(int size)
            {
                Size = size;
                int capacity = (int)Math.Ceiling(size / 8d) + 1;
                UnderlyingList = new List<byte>(capacity);
                for (int i = 0; i < capacity; i++)
                {
                    UnderlyingList.Add(0);
                }
            }

            public bool this[int i]
            {
                get
                {
                    int index = i / 8;
                    int innerIndex = i % 8;
                    byte containing = UnderlyingList[index];
                    return (containing & (1 << innerIndex)) > 0;
                }
                set
                {
                    int index = i / 8;
                    int innerIndex = i % 8;
                    byte containing = UnderlyingList[index];
                    UnderlyingList[index] = (byte)(containing | (1 << innerIndex));
                }
            }
        }
    }
}


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

namespace KlonirovanijeIgrushek
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            int x = int.Parse(s[0]);
            int y = int.Parse(s[1]);

            if (y==1 && x>0)
                Console.Write("no")
            else if ((x - y + 1) % 2 == 0 && (y-1<=x) && y>0)
                Console.Write("yes");
            else
                Console.Write("no");

        }
    }
}


using System; using System.Linq;

class P {
  static void Main () {
    var s = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    var a = s[0]; var b = s[1]; var c = s[1];
    var res = Enumerable.Range(0,1000000).Where(x => a*c <= b*(c+x)).First();
    Console.Write(res);
  }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Xml.Linq;
namespace ConsoleApplication1
{
    class Program
    {

        public static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int speed, rate, length;
            speed = int.Parse(s[1]);
            rate = int.Parse(s[0]);
            length = int.Parse(s[2]);
            int size = rate * length;
            size -= length * speed;
            Console.WriteLine(size / speed+(size%rate!=0?1:0));
        }

    }
}


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

namespace Rextester
{
    public class Program
    {
        public static void Main(string[] args)
        {
            string str = Console.ReadLine();
            int countQ = 0, countA = 0, count = 0;
            for (int i = 0; i < str.Length; i++)
            {

                if (str[i] == 'A') countA++;
                if (str[i] == 'Q') countQ++;
                if (countA > 0 && countQ > 1 && str[i] == 'Q') count = countA*(countQ-1);
            }
            Console.Write(count);
            //Console.ReadKey();

        }
    }
}


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

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

class Sol{
	public void Solve(){

		if(N == 1){
			Console.WriteLine(0);
		}
		int H = 2;
		int W = N;

		int M = 1<<4;
		int[] c = new int[]{
			0xF - 1,
			0xF - 2,
			0xF - 4,
			0xF - 8,
			0
		};
		int[] dp = new int[M];
		for(int i=0;i<M;i++) dp[i] = -1;
		int s = 0;
		for(int i=0;i<2;i++){
			for(int j=0;j<H;j++){
				s |= (S[j][i] == 'X' ? 1 : 0) << (i * 2 + j);
			}
		}
//Console.WriteLine(s);
		dp[s] = 0;

		for(int t=0;t<N-1;t++){
//Console.WriteLine("dp:{0}",String.Join(" ",dp));
			int[] ndp = new int[M];
			for(int i=0;i<M;i++) ndp[i] = -1;
			for(int i=0;i<M;i++){
				if(dp[i] == -1) continue;
				foreach(var b in c){
					if((i & b) != 0) continue;
					var st = (i | b) >> 2;
					for(int j=0;j<2;j++){
						st |= ((t + 2 < N && S[j][t + 2] == 'X') ? 1 : 0) << (2 + j);
					}
//Console.WriteLine("i:{0}, b:{1}, st:{2}",i, b, st);
					ndp[st] = Math.Max(ndp[st], dp[i] + (b == 0 ? 0 : 1));
				}
			}
			dp = ndp;
//Console.WriteLine("ndp:{0}",String.Join(" ",dp));
		}

		Console.WriteLine(dp.Max());

	}
	int N;
	String[] S;
	public Sol(){
		S = new String[2];
		for(int i=0;i<2;i++) S[i] = rs();
		N = S[0].Length;
	}

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


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

namespace Task
{
  class Program
  {
    #region Read / Write
    protected static TextReader reader;
    protected static TextWriter writer;
    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=

    public static bool NextPermutation(List<int> perm)
    {
      for (int i = perm.Count - 2; i >= 0; i--)
      {
        if (perm[i] < perm[i + 1])
        {
          int min = i + 1;
          for (int j = min; j < perm.Count; j++)
            if (perm[j] > perm[i] && perm[j] < perm[min])
              min = j;

          int tmp = perm[i];
          perm[i] = perm[min];
          perm[min] = tmp;
          perm.Reverse(i + 1, perm.Count - i - 1);
          return true;
        }
      }

      return false;
    }

    static void Main(string[] args)
    {
      long i = 0;
      long ans = 0;
      reader = new StreamReader(Console.OpenStandardInput());
      writer = new StreamWriter(Console.OpenStandardOutput());

      var s = ReadLines(2);
      var mas = s.Select(it => it.Select(ch => ch == 'X' ? 1 : 0).ToArray()).ToArray();

      int n = mas[0].Length;
      if (n < 2)
      {
        Write(0);
      }
      else
      {
        for (i = 0; i < n - 1; i++)
        {
          int ones = mas[0][i] + mas[0][i + 1] + mas[1][i] + mas[1][i + 1];
          if (ones == 1)
          {
            ans++;
            mas[0][i] = mas[0][i + 1] = mas[1][i] = mas[1][i + 1] = 1;
          }
          else if (ones == 0)
          {
            ans++;
            mas[0][i] = mas[0][i + 1] = mas[1][i] = 1;
          }
        }
      }
      Write(ans);

      reader.Close();
      writer.Close();
    }
  }
}


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

namespace NetExperiment
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder(Console.ReadLine());

            if (sb.Length == 1)
            {
                Console.WriteLine(sb.ToString());
                return;
            }

            int l = sb.Length / 2 - 1;
            int r = l;
            bool right = true;
            StringBuilder res = new StringBuilder();
            res.Append(sb[l]);
            while(l - 1 >= 0 || r + 1 < sb.Length)
            {
                if (right)
                {
                    res.Append(sb[++r]);
                }
                else
                {
                    res.Append(sb[--l]);
                }

                right = !right;
            }
            Console.WriteLine(res.ToString());
        }
    }
}


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.106
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tech1", "Tech1\Tech1.csproj", "{1EB1A4F0-0118-4CCD-BF17-D608A682C2B4}"
EndProject
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|Any CPU = Debug|Any CPU
		Release|Any CPU = Release|Any CPU
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{1EB1A4F0-0118-4CCD-BF17-D608A682C2B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{1EB1A4F0-0118-4CCD-BF17-D608A682C2B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{1EB1A4F0-0118-4CCD-BF17-D608A682C2B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{1EB1A4F0-0118-4CCD-BF17-D608A682C2B4}.Release|Any CPU.Build.0 = Release|Any CPU
	EndGlobalSection
	GlobalSection(SolutionProperties) = preSolution
		HideSolutionNode = FALSE
	EndGlobalSection
	GlobalSection(ExtensibilityGlobals) = postSolution
		SolutionGuid = {C3620269-6E19-4EA1-ABB1-CD478D85838E}
	EndGlobalSection
EndGlobal


using System;
static class P {
    static void Main() {
        string s = "", r = "YES"; int i = 0;
        for (; i < 3; ++i) { s += Console.ReadLine(); }
        i = 0; int j = s.Length - 1;
        while (i < j) { if (s[i++] != s[j++]) { r = "NO"; break; } }
        Console.WriteLine(r);
    }
}


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

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

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

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

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

        static void solution()
        {
            #region SOLUTION
            var a = new int[3, 3];
            for (int i = 0; i < 3; i++)
            {
                var d = Console.ReadLine();
                for (int j = 0; j < 3; j++)
                {
                    if (d[j] == 'X')
                    {
                        a[i, j] = 1;
                    }
                }
            }

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (i == j)
                    {
                        continue;
                    }

                    var y = -1;
                    var x = -1;
                    if (i == 0)
                    {
                        y = 2;
                    }
                    else if (i == 1)
                    {
                        y = 1;
                    }
                    else if (i == 2)
                    {
                        y = 0;
                    }

                    if (j == 0)
                    {
                        x = 2;
                    }
                    else if (j == 1)
                    {
                        x = 1;
                    }
                    else if (j == 2)
                    {
                        x = 0;
                    }

                    if (a[i, j] != a[y, x])
                    {
                        Console.WriteLine("NO");
                        return;
                    }
                }
            }

            Console.WriteLine("YES");

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

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

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

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

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

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

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

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


using System;

class Program
{
	static void Main(string[] args)
	{
		int count=0;
		int k=0;
		string []tmp1 = Console.ReadLine().Split(' ');
     	string []tmp2 = Console.ReadLine().Split(' ');

		if(int.Parse(tmp2[0])!=0)
		for (int i=0;i<int.Parse(tmp1[0]);i++)
		{

		    if(int.Parse(tmp2[i])>int.Parse(tmp1[1]))
		    {
		    count1++;
		    k++;
		    }
		    else
		    break;

		}

		while(count<int.Parse(tmp1[1])&& k<int.Parse(tmp1[0])&& 0<int.Parse(tmp2[k]))
		{
		    count++;
		    k++;

	    }

	    if(count>int.Parse(tmp1[1]) && k<int.Parse(tmp1[0])&& 0<int.Parse(tmp2[k]))
	    {
	        for (int i=k+1;i<int.Parse(tmp1[0]);i++)
		     {

		        if(int.Parse(tmp2[k])==int.Parse(tmp2[i]))
		       { count++;
		       k++;
		       }
		         else
		         {
		         break;
		         }
      }

		Console.WriteLine(count);
	}
}
}


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

class Program
{
    static long Max(long a, long b, long c)
    {
        return Math.Max(a, Math.Max(b, c));
    }

    static long Min(long a, long b, long c)
    {
        return Math.Min(a, Math.Min(b, c));
    }

    static int gcd(int a, int b)
    {
        if (b == 0)
            return a;

        return gcd(b, a % b);
    }

    static long bs(long[] a,  long l, long r, long k)
    {
        if (l >= r)
            return l;

        long mid = (l + r) / 2;

        if (a[mid] >= k)
            return bs(a, l, mid - 1, k);

        return bs(a, mid + 1, r, k);
    }

    static long getMin(long v, long x, long k)
    {
        return v + (x * (k - 1));
    }

    static long getMax(long v, long x, long k)
    {
        return v + (x * k + 1);
    }

    static void Main(string[] args)
    {
        var s = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

        var n = s[0];
        var d = s[1];

        var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

        a = a.OrderBy(x=>x).ToArray();

        int l = 0;
        int r = a.Count() - 1;

        var max = backtest(a, l, r, d);

        Console.WriteLine(a.Count() - max);
    }

    static int backtest(int[] arr, int l, int r, int d)
    {
        if (arr[r] - arr[l] <= d) { return r - l + 1; }
        else
        {
            return Math.Max(backtest(arr, l + 1, r, d), backtest(arr, l, r - 1, d));
        }
    }
}


string num = Console.ReadLine();
           string  txt = Console.ReadLine();
            int count = 0;
            for (int i = 0; i <int.Parse(num); i++)
            {

                if (txt[i] ==Char.ToUpper(txt[i])&&txt[i]!=' ')
                {
                    count++;
                }
            }
            Console.WriteLine(count);


 int a, b;
            string Result = "NO";
            //int[] posled ;
            List<int> posled = new List<int>();
            Console.WriteLine("Введите a");
            a =int.Parse(Console.ReadLine().ToString());
            Console.WriteLine("Введите b");
            b = int.Parse(Console.ReadLine().ToString());
            int tempVar = b;
            while (tempVar > a)
            {
                posled.Add(tempVar);
                if (tempVar % 2 > 0)
                {
                    tempVar = (tempVar - 1) / 10;
                }
                else
                {
                    tempVar = tempVar / 2;
                }

                if (tempVar < 1)
                {
                    Result = "NO";
                    break;
                }
            }
            if (tempVar == a)
            {
                Result = "YES";
            };
            posled.Add(a);

            Console.WriteLine(Result);
            if (Result == "YES")
            {
                Console.WriteLine(posled.Count());
                for (int i = posled.Count() - 1; i >= 0; i--)
                {
                    Console.Write(posled[i] + " ");
                }

            }