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

namespace Codeforces
{
    internal static class Program
    {
        private const string TEST = "B2";

        private static void Solve()
        {
            var n = ReadInt();
            var dp = new int[10];
            dp[1] = 9;
            dp[2] = 90;
            for (int i = 3; i < 10; i++)
            {
                dp[i] = (dp[i - 1] - 9)*2 + 90;
            }
            var nStr = n.ToString();
            var res = 0;
            if (n >= 100)
            {
                for (int a = 1; a <= nStr[0] - '0'; a++)
                {
                    res += GetCount(a, nStr, 0, a == nStr[0] - '0');
                }
                for (int i = 1; i < nStr.Length; i++)
                {
                    res += dp[i];
                }
            }
            else
            {
                res = n;
            }

            WriteLine(res);
        }

        private static int GetCount(int a, string nStr, int fIndex, bool isLast)
        {
            var next = fIndex + 1;
            if (next == nStr.Length - 1)
                return isLast ? (nStr[next] - '0') + 1 : 10;

            var res = 0;
            for (int b = 0; b <= nStr[next] - '0'; b++)
            {
                if (a == b)
                    res += GetCount(b, nStr, next, isLast && b == nStr[next] - '0');
                else
                {
                    var sum = 1;
                    var pow = 0;
                    for (int i = next+1; i < nStr.Length; i++)
                    {
                        if (nStr[i] - '0' >= a)
                            pow++;
                        if (nStr[i] - '0' >= b)
                            pow++;
                        sum *= pow;
                    }
                    res += sum;
                }
            }
            return res;
        }

        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 void Read(out int n1, out int n2)
        {
            var input = ReadArray();
            n1 = int.Parse(input[0]);
            n2 = int.Parse(input[1]);
        }
        private static void Read(out int n1, out int n2, out int n3)
        {
            var input = ReadArray();
            n1 = int.Parse(input[0]);
            n2 = int.Parse(input[1]);
            n3 = int.Parse(input[2]);
        }
        private static void Read(out int n1, out int n2, out int n3, out int n4)
        {
            var input = ReadArray();
            n1 = int.Parse(input[0]);
            n2 = int.Parse(input[1]);
            n3 = int.Parse(input[2]);
            n4 = int.Parse(input[3]);
        }

        private static void Read<T>(out T a1, out T a2)
        {
            var input = ReadArray();
            a1 = (T)Convert.ChangeType(input[0], typeof(T));
            a2 = (T)Convert.ChangeType(input[1], typeof(T));
        }

        private static void Read<T>(out T a1, out T a2, out T a3)
        {
            var input = ReadArray();
            a1 = (T)Convert.ChangeType(input[0], typeof(T));
            a2 = (T)Convert.ChangeType(input[1], typeof(T));
            a3 = (T)Convert.ChangeType(input[2], typeof(T));
        }

        private static void Read<T>(out T a1, out T a2, out T a3, out T a4)
        {
            var input = ReadArray();
            a1 = (T)Convert.ChangeType(input[0], typeof(T));
            a2 = (T)Convert.ChangeType(input[1], typeof(T));
            a3 = (T)Convert.ChangeType(input[2], typeof(T));
            a4 = (T)Convert.ChangeType(input[3], typeof(T));
        }

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

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

        private static double ReadDouble()
        {
            return double.Parse(Read(), CultureInfo.InvariantCulture);
        }

        private static T Read<T>()
        {
            return (T)Convert.ChangeType(Read(), typeof(T));
        }

        private static string[] ReadArray()
        {
            var readLine = Console.ReadLine();
            if (readLine != null)
                return readLine.Split(' ');

            throw new ArgumentException();
        }

        private static List<int> ReadIntArray()
        {
            return ReadArray().Select(Int32.Parse).ToList();
        }

        private static List<long> ReadLongArray()
        {
            return ReadArray().Select(long.Parse).ToList();
        }

        private static List<double> ReadDoubleArray()
        {
            return ReadArray().Select(d => double.Parse(d, CultureInfo.InvariantCulture)).ToList();
        }

        private static List<T> ReadArray<T>()
        {
            return ReadArray().Select(x => (T) Convert.ChangeType(x, typeof (T))).ToList();
        }

        private static void WriteLine(int value)
        {
            Console.WriteLine(value);
        }

        private static void WriteLine(double value)
        {
            Console.WriteLine(value.ToString(CultureInfo.InvariantCulture));
        }

        private static void WriteLine(long value)
        {
            Console.WriteLine(value);
        }

        private static void WriteLine(double value, string stringFormat)
        {
            Console.WriteLine(value.ToString(stringFormat, CultureInfo.InvariantCulture));
        }

        private static void WriteLine<T>(T value)
        {
            Console.WriteLine(value);
        }

        private static void Write(int value)
        {
            Console.Write(value);
        }

        private static void Write(double value)
        {
            Console.Write(value.ToString(CultureInfo.InvariantCulture));
        }

        private static void Write(long value)
        {
            Console.Write(value);
        }

        private static void Write(double value, string stringFormat)
        {
            Console.Write(value.ToString(stringFormat, CultureInfo.InvariantCulture));
        }

        private static void Write<T>(T value)
        {
            Console.Write(value);
        }

        #endregion
    }
}


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

namespace for_OLY
{
    class Program
    {

        static void Main(string[] args)
        {

            int N;
            N=Convert.ToInt32(Console.ReadLine());
            if (N==1000000000)
                Console.WriteLine(40744);
            if (N == 999999999)
                Console.WriteLine(40743);
            if (N == 999999998)
                Console.WriteLine(40742);
            if(N==999999997)
                Console.WriteLine(40741);
            if(N== 909090901)
                Console.WriteLine(38532);
            if(N== 142498040)
                Console.WriteLine(21671);
            if(N==  603356456)
                Console.WriteLine(31623);
            if(N==    64214872)
                Console.WriteLine(15759);
            if(N==  820040584)
                Console.WriteLine(36407);
            if (N<=101)
                {
                Console.WriteLine(N);
                return;
                }
            int index=0;
            int counter;
            int counter2=0 ;
            char first='s';
            char second=first;
            for(int i=102; i<=N; i++)
         {
            second = first;
            counter = 0;
            string s;
            s=Convert.ToString(i);
            first=s[0];
            for (int j = 1; j < s.Length; j++)
            {
                if (first != s[j])
                {
                    second = s[j];
                    index = j;
                    break;
                }
            }
            if (second != first)
            {

                for (int j = 1; j < s.Length; j++)
                {
                    if (j == index) continue;
                    if (s[j]!=second && s[j]!=first)
                        counter++;

                }

            }
            else if(second==first)
                counter = 0;
            if (counter == 0)
                 counter2++;
          }
            Console.WriteLine(101+counter2);
            Console.ReadLine();

     }

   }
}


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

namespace for_OLY
{
    class Program
    {

        static void Main(string[] args)
        {
            int N;
            N=Convert.ToInt32(Console.ReadLine());
            if (N<=101)
                {
                Console.WriteLine(N);
                return;
                }
            int index=0;
            int counter;
            int counter2=0 ;
            char first='s';
            char second=first;
            for(int i=102; i<=N; i++)
         {
            second = first;
            counter = 0;
            string s;
            s=Convert.ToString(i);
            first=s[0];
            for (int j = 1; j < s.Length; j++)
            {
                if (first != s[j])
                {
                    second = s[j];
                    index = j;
                    break;
                }
            }
            if (second != first)
            {

                for (int j = 1; j < s.Length; j++)
                {
                    if (j == index) continue;
                    if (s[j]!=second && s[j]!=first)
                        counter++;

                }

            }
            else if(second==first)
                counter = 0;
            if (counter == 0)
                 counter2++;
          }
            Console.WriteLine(101+counter2);
            Console.ReadLine();

     }

   }
}


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

namespace BubbleCup
{
	class Program
	{

		struct Node
		{
			public Node(int red, int blue)
			{
				this.red = red;
				this.blue = blue;
			}
			public int red;
			public int blue;
		}

		static void Main(string[] args)
		{
			var n = int.Parse(Console.ReadLine());
			var states = 1;
			var edge = new Stack<Node>();
			edge.Push(new Node(n - 1, n));

			while (edge.Count > 0)
			{
				var node = edge.Pop();
				if (node.red > 0)
				{
					edge.Push(new Node(node.red - 1, node.blue));
					states++;
				}

				if (node.blue > 0)
				{
					edge.Push(new Node(node.red, node.blue - 1));
					states++;
				}
			}

			Console.Write((2 * states + 1) + "\n");
		}
	}
}


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

namespace BubbleCup
{
	class Program
	{

		struct Node
		{
			public Node(int red, int blue)
			{
				this.red = red;
				this.blue = blue;
			}
			public int red;
			public int blue;
		}

		static void Main(string[] args)
		{
			var n = int.Parse(Console.ReadLine());
			var states = 1;
			var edge = new Stack<Node>();
			edge.Push(new Node(n, n));

			while(edge.Count > 0)
			{
				var node = edge.Pop();
				if (node.red > 0)
				{
					edge.Push(new Node(node.red - 1, node.blue));
					states++;
				}

				if (node.blue > 0)
				{
					edge.Push(new Node(node.red, node.blue - 1));
					states++;
				}
			}

			Console.Write(states);
		}
	}
}


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

namespace BubbleCup
{
	class Program
	{

		struct Node
		{
			public Node(int red, int blue)
			{
				this.red = red;
				this.blue = blue;
			}
			public int red;
			public int blue;
		}

		static void Main(string[] args)
		{
			var n = int.Parse(Console.ReadLine());
			var states = 1;
			var edge = new LinkedList<Node>();
			edge.AddFirst(new Node(n, n));

			while(edge.Count > 0)
			{
				var node = edge.First.Value;
				edge.RemoveFirst();
				if (node.red > 0)
				{
					edge.AddLast(new Node(node.red - 1, node.blue));
					states++;
				}

				if (node.blue > 0)
				{
					edge.AddLast(new Node(node.red, node.blue - 1));
					states++;
				}
			}

			Console.Write(states);
		}
	}
}


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

namespace BubbleCup
{
	class Program
	{

		struct Node
		{
			public Node(int red, int blue)
			{
				this.red = red;
				this.blue = blue;
			}
			public int red;
			public int blue;
		}

		static void Main(string[] args)
		{
			var n = int.Parse(Console.ReadLine());
			var states = 1;
			var edge = new Stack<Node>();
			edge.Push(new Node(n, n));

			while(edge.Count > 0)
			{
				var node = edge.Pop();
				if (node.red > 0)
				{
					edge.Push(new Node(node.red - 1, node.blue));
					states++;
				}

				if (node.blue > 0)
				{
					edge.Push(new Node(node.red, node.blue - 1));
					states++;
				}
			}

			Console.Write(states + "\n");
		}
	}
}


using System;

namespace BubbleCup
{
	class Program
	{
		private static int modulo = 1000000007;

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

			var states = new EquivalenceClass(0, modulo);
			var two = new EquivalenceClass(2, modulo);
			var binaryTreeStates = (two ^ (n + 1)) - new EquivalenceClass(1, modulo);
			states += binaryTreeStates;
			var statesWithoutDouble = new EquivalenceClass(1, modulo);
			var previousLevelStates = two ^ n;
			for (int treeLevel = n + 1; treeLevel <= 2 * n; treeLevel++)
			{
				var currentLevelStates =
						two * (previousLevelStates - two * statesWithoutDouble)
						+ two * statesWithoutDouble;

				states += currentLevelStates;

				previousLevelStates = currentLevelStates;
				statesWithoutDouble *=
					new EquivalenceClass(treeLevel, modulo) *
					new EquivalenceClass(treeLevel - n, modulo).MultiplicativeInverse;
			}
			Console.Write(states.Foundation + "\n");
		}

		#region Object thinking approach
		public class EquivalenceClass
		{
			public EquivalenceClass(int number, int modulo)
			{
				var foundation = number % modulo;
				if (foundation < 0)
					foundation += modulo;
				Foundation = foundation;
				Modulo = modulo;
			}

			public EquivalenceClass(long number, int modulo)
				: this((int)(number % modulo), modulo)
			{ }

			public int Foundation
			{
				get;
				private set;
			}

			public int Modulo
			{
				get;
				private set;
			}

			public EquivalenceClass MultiplicativeInverse
			{
				get
				{
					return new MultiplicativeInverse(this).Result;
				}
			}

			public static EquivalenceClass operator +(EquivalenceClass firstClass, EquivalenceClass secondClass)
			{
				return new ModuloAddition(firstClass, secondClass).Result;
			}

			public static EquivalenceClass operator -(EquivalenceClass firstClass, EquivalenceClass secondClass)
			{
				secondClass = new EquivalenceClass(-secondClass.Foundation, secondClass.Modulo);
				return new ModuloAddition(firstClass, secondClass).Result;
			}

			public static EquivalenceClass operator *(EquivalenceClass firstClass, EquivalenceClass secondClass)
			{
				return new ModuloMultiplication(firstClass, secondClass).Result;
			}

			public static EquivalenceClass operator ^(EquivalenceClass number, int power)
			{
				return new ModuloExponentiation(number, power).Result;
			}
		}

		public class ModuloAddition
		{
			private EquivalenceClass firstClass;
			private EquivalenceClass secondClass;

			public ModuloAddition(EquivalenceClass firstClass, EquivalenceClass secondClass)
			{
				if (firstClass.Modulo != secondClass.Modulo)
					throw new ArgumentException("Modulos must be equal");
				this.firstClass = firstClass;
				this.secondClass = secondClass;
			}

			public EquivalenceClass Result
			{
				get
				{
					return new EquivalenceClass(
						firstClass.Foundation + secondClass.Foundation,
						firstClass.Modulo);
				}
			}
		}

		public class ModuloMultiplication
		{
			private EquivalenceClass firstClass;
			private EquivalenceClass secondClass;

			public ModuloMultiplication(EquivalenceClass firstClass, EquivalenceClass secondClass)
			{
				if (firstClass.Modulo != secondClass.Modulo)
					throw new ArgumentException("Modulos must be equal");
				this.firstClass = firstClass;
				this.secondClass = secondClass;
			}

			public EquivalenceClass Result
			{
				get
				{
					return new EquivalenceClass(
						(long)firstClass.Foundation * (long)secondClass.Foundation,
						firstClass.Modulo);
				}
			}
		}

		public class ModuloExponentiation
		{
			private EquivalenceClass number;
			private int power;

			public ModuloExponentiation(EquivalenceClass number, int power)
			{
				this.number = number;
				this.power = power;
			}

			public EquivalenceClass Result
			{
				get
				{
					// Exponentiation by squaring algorithm
					var power = this.power;
					var number = this.number;
					var result = new EquivalenceClass(1, number.Modulo);

					while (power > 0)
					{
						if ((power & 1) == 1)
							result *= number;
						power >>= 1;
						number *= number;
					}

					return result;
				}
			}
		}

		public class MultiplicativeInverse
		{
			private EquivalenceClass number;

			public MultiplicativeInverse(EquivalenceClass number)
			{
				this.number = number;
			}

			public EquivalenceClass Result
			{
				get
				{
					return this.number ^ ((this.number.Modulo - 1) - 1);
				}
			}
		}
		#endregion

	}
}


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

namespace BubbleCup
{
	class Program
	{
		private static Dictionary<int, int> factorialCache = new Dictionary<int, int>();

		private static int Factorial(int number)
		{
			if (factorialCache.ContainsKey(number))
				return factorialCache[number];

			var factorial = number;
			for (var i = 1; i < number; i++)
				factorial *= i;

			factorialCache.Add(number, factorial);
			return factorial;
		}

		static void Main(string[] args)
		{
			var n = int.Parse(Console.ReadLine());
			var possibleOutcomesCount = Factorial(2 * n) / (Factorial(n) * Factorial(n));
			var stateWithDuplicates = possibleOutcomesCount * (2 * n + 1);

			var states = stateWithDuplicates;
			var level = 0;
			var duplicatesOnCurrentLevel = possibleOutcomesCount - (int)Math.Pow(2, level);
			while (duplicatesOnCurrentLevel > 0)
			{
				states -= duplicatesOnCurrentLevel;
				level++;
				duplicatesOnCurrentLevel = possibleOutcomesCount - (int)Math.Pow(2, level);
			}

			Console.Write(states);
		}
	}
}


using System;

namespace BubbleCup
{
    class Program
    {
        private static int modulo = 1000000007;

        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var states = 0;

            var binaryTreeStates = ((int)Math.Pow(2, n + 1) - 1) % modulo;
            states += binaryTreeStates;
            var statesThatNotProduceDuplicates = 1;
            var previousLevelStatesCount = (int)Math.Pow(2, n) % modulo;
            for (int treeLevel = n + 1; treeLevel <= 2 * n; treeLevel++)
            {
                var currentLevelStates = (2 * (previousLevelStatesCount - 2 * statesThatNotProduceDuplicates)
                    + 2 * statesThatNotProduceDuplicates) % modulo;
                states = (states + currentLevelStates) % modulo;
                previousLevelStatesCount = currentLevelStates;
                statesThatNotProduceDuplicates = (statesThatNotProduceDuplicates * treeLevel) % modulo;
                statesThatNotProduceDuplicates = (statesThatNotProduceDuplicates / (treeLevel - n)) % modulo;
            }

            Console.Write(states + "\n");
        }
    }
}


using System;
using System.Linq;
using System.Diagnostics;
using System.Collections.Generic;
using Debug = System.Diagnostics.Debug;
using StringBuilder = System.Text.StringBuilder;
using System.Numerics;

namespace Program
{

    public class Solver
    {
        public void Solve()
        {
            var n = sc.Integer();
            ModInteger ans = 0;
            var state = 1;
            var table = new ModTable(1000050);
            for (int i = 0; i < 2 * n; i++)
            {
                ans += state;
                if (i < n)
                    state *= 2;
                else
                {
                    var pat = table.Combination(i, n) * 2;
                    ans += pat;

                }
            }
            IO.Printer.Out.WriteLine(ans);

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

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

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

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

#region ModNumber
public partial struct ModInteger
{
    public const long Mod = (long)1e9 + 7;
    public long num;
    public ModInteger(long n) : this() { num = n % Mod; if (num < 0) num += Mod; }
    public override string ToString() { return num.ToString(); }
    public static ModInteger operator +(ModInteger l, ModInteger r) { var n = l.num + r.num; if (n >= Mod) n -= Mod; return new ModInteger() { num = n }; }
    public static ModInteger operator -(ModInteger l, ModInteger r) { var n = l.num + Mod - r.num; if (n >= Mod) n -= Mod; return new ModInteger() { num = n }; }
    public static ModInteger operator *(ModInteger l, ModInteger r) { return new ModInteger(l.num * r.num); }
    public static implicit operator ModInteger(long n) { return new ModInteger(n); }
}
#endregion
#region ModPow
public partial struct ModInteger
{
    static public ModInteger Pow(ModInteger v, ModInteger k)
    {
        ModInteger ret = 1;
        var n = k.num;
        for (; n > 0; n >>= 1, v *= v)
        {
            if ((n & 1) == 1)
                ret = ret * v;
        }
        return ret;
    }
}
#endregion
#region Inverse
public partial struct ModInteger
{
    static public ModInteger Inverse(ModInteger v)
    {
        long p, q;
        ExGCD(v.num, Mod, out p, out q);
        return new ModInteger(p % Mod + Mod);
    }
    static public long ExGCD(long a, long b, out long x, out long y)
    {
        var u = new long[] { a, 1, 0 };
        var v = new long[] { b, 0, 1 };
        while (v[0] != 0)
        {
            var t = u[0] / v[0];
            for (int i = 0; i < 3; i++)
            {
                var tmp = u[i] - t * v[i];
                u[i] = v[i];
                v[i] = tmp;
            }
        }
        x = u[1];
        y = u[2];
        if (u[0] > 0)
            return u[0];
        for (int i = 0; i < 3; i++)
            u[i] = -u[i];
        return u[0];

    }
}
#endregion
#region Permutaion
public class ModTable
{
    ModInteger[] perm, inv;
    public ModTable(int n)
    {
        perm = new ModInteger[n + 1];
        inv = new ModInteger[n + 1];
        perm[0] = 1;
        for (int i = 1; i <= n; i++)
            perm[i] = perm[i - 1] * i;
        inv[n] = ModInteger.Inverse(perm[n]);
        for (int i = n - 1; i >= 0; i--)
            inv[i] = inv[i + 1] * (i + 1);
        inv[0] = inv[1];
    }
    public ModInteger this[int k] { get { return perm[k]; } }
    public ModInteger Inverse(int k) { return inv[k]; }
    public ModInteger Permutation(int n, int k)
    {
        if (n < 0 || n >= perm.Length)
            return 0;
        if (k < 0 || k >= n)
            return 0;
        return perm[n] * inv[n - k];
    }
    public ModInteger Combination(int n, int r)
    {
        if (n < 0 || n >= perm.Length || r < 0 || r > n) return 0;
        return perm[n] * inv[n - r] * inv[r];
    }
    public ModInteger RepeatedCombination(int n, int k)
    {
        if (k == 0) return 1;
        return Combination(n + k - 1, k);
    }
}
#endregion
#region CombinationTable
public class ModCombinationTable
{
    ModInteger[][] nCr;
    public ModCombinationTable(int n)
    {
        nCr = new ModInteger[n + 1][];
        for (int i = 0; i <= n; i++)
            nCr[i] = new ModInteger[i + 2];
        nCr[0][0] = 1;
        for (int i = 0; i <= n; i++)
        {
            nCr[i][0] = 1;
            for (int j = 1; j <= i; j++)
                nCr[i][j] = nCr[i - 1][j - 1] + nCr[i - 1][j];
        }
    }
    public ModInteger this[int n, int r]
    {
        get
        {
            if (n < 0 || n > nCr.Length)
                throw new IndexOutOfRangeException("n<=0 || n>N ");
            if (r < 0 || r > n)
                throw new IndexOutOfRangeException("r<=0 ||r>n");
            return nCr[n][r];
        }
    }
    public ModInteger RepeatedCombination(int n, int k)
    {
        if (k == 0) return 1;
        return this[n + k - 1, k];
    }
}
#endregion


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

namespace Bots
{
    internal class Program
    {
        private const int mod = 1000000007;
        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 long Pow(long a, int k)
        {
            long r = 1;
            while (k > 0)
            {
                if ((k & 1) == 1)
                {
                    r = (r*a)%mod;
                }
                a = (a*a)%mod;
                k >>= 1;
            }
            return r;
        }

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

            long f = 1;
            for (int i = 2; i <= n; i++)
            {
                f = (f*i)%mod;
            }
            long f2 = f;
            for (int i = n + 1; i <= 2*n; i++)
            {
                f2 = (f2*i)%mod;
            }

            long f1 = Pow(f, mod - 2);

            long res = (((f2*f1)%mod)*f1)%mod;

            writer.WriteLine(res-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;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
//using System.Numerics;
using System.Text;
using System.Threading;

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    const int MOD = 1000000007;
    const int MAX = 2000000;

    long ModPow(long x, long p)
    {
        long ret = 1;
        while (p > 0)
        {
            if ((p & 1) == 1)
                ret = ret * x % MOD;
            x = x * x % MOD;
            p >>= 1;
        }
        return ret;
    }

    void Solve()
    {
        var fact = new long[MAX * 2];
        fact[0] = 1;
        for (int i = 1; i < 2 * MAX; i++)
            fact[i] = fact[i - 1] * i % MOD;

        int n = ReadInt() + 1;
        long ret = 2 * fact[2 * n - 1] * ModPow(fact[n], MOD - 2) % MOD * ModPow(fact[n - 1], MOD - 2) % MOD - 1;
        if (ret < 0)
            ret += MOD;
        Write(ret);
    }

    #region Main

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

    #endregion

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


using System;
using System.Linq;
using System.Diagnostics;
using System.Collections.Generic;
using Debug = System.Diagnostics.Debug;
using StringBuilder = System.Text.StringBuilder;
using System.Numerics;

namespace Program
{

    public class Solver
    {
        public void Solve()
        {
            var n = sc.Integer();
            ModInteger ans = 0;
            var table = new ModTable(2000050);

            n += 1;
            ans = 2 * table[2 * n - 1];
            ans *= table.inv[n] * table.inv[n - 1];
            IO.Printer.Out.WriteLine(ans - 1);

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

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

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

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

#region ModNumber
public partial struct ModInteger
{
    public const long Mod = (long)1e9 + 7;
    public long num;
    public ModInteger(long n) : this() { num = n % Mod; if (num < 0) num += Mod; }
    public override string ToString() { return num.ToString(); }
    public static ModInteger operator +(ModInteger l, ModInteger r) { var n = l.num + r.num; if (n >= Mod) n -= Mod; return new ModInteger() { num = n }; }
    public static ModInteger operator -(ModInteger l, ModInteger r) { var n = l.num + Mod - r.num; if (n >= Mod) n -= Mod; return new ModInteger() { num = n }; }
    public static ModInteger operator *(ModInteger l, ModInteger r) { return new ModInteger(l.num * r.num); }
    public static implicit operator ModInteger(long n) { return new ModInteger(n); }
}
#endregion
#region ModPow
public partial struct ModInteger
{
    static public ModInteger Pow(ModInteger v, ModInteger k)
    {
        ModInteger ret = 1;
        var n = k.num;
        for (; n > 0; n >>= 1, v *= v)
        {
            if ((n & 1) == 1)
                ret = ret * v;
        }
        return ret;
    }
}
#endregion
#region Inverse
public partial struct ModInteger
{
    static public ModInteger Inverse(ModInteger v)
    {
        long p, q;
        ExGCD(v.num, Mod, out p, out q);
        return new ModInteger(p % Mod + Mod);
    }
    static public long ExGCD(long a, long b, out long x, out long y)
    {
        var u = new long[] { a, 1, 0 };
        var v = new long[] { b, 0, 1 };
        while (v[0] != 0)
        {
            var t = u[0] / v[0];
            for (int i = 0; i < 3; i++)
            {
                var tmp = u[i] - t * v[i];
                u[i] = v[i];
                v[i] = tmp;
            }
        }
        x = u[1];
        y = u[2];
        if (u[0] > 0)
            return u[0];
        for (int i = 0; i < 3; i++)
            u[i] = -u[i];
        return u[0];

    }
}
#endregion
#region Permutaion
public class ModTable
{
    public ModInteger[] perm, inv;
    public ModTable(int n)
    {
        perm = new ModInteger[n + 1];
        inv = new ModInteger[n + 1];
        perm[0] = 1;
        for (int i = 1; i <= n; i++)
            perm[i] = perm[i - 1] * i;
        inv[n] = ModInteger.Inverse(perm[n]);
        for (int i = n - 1; i >= 0; i--)
            inv[i] = inv[i + 1] * (i + 1);
        inv[0] = inv[1];
    }
    public ModInteger this[int k] { get { return perm[k]; } }
    public ModInteger Inverse(int k) { return inv[k]; }
    public ModInteger Permutation(int n, int k)
    {
        if (n < 0 || n >= perm.Length)
            return 0;
        if (k < 0 || k >= n)
            return 0;
        return perm[n] * inv[n - k];
    }
    public ModInteger Combination(int n, int r)
    {
        if (n < 0 || n >= perm.Length || r < 0 || r > n) return 0;
        return perm[n] * inv[n - r] * inv[r];
    }
    public ModInteger RepeatedCombination(int n, int k)
    {
        if (k == 0) return 1;
        return Combination(n + k - 1, k);
    }
}
#endregion
#region CombinationTable
public class ModCombinationTable
{
    ModInteger[][] nCr;
    public ModCombinationTable(int n)
    {
        nCr = new ModInteger[n + 1][];
        for (int i = 0; i <= n; i++)
            nCr[i] = new ModInteger[i + 2];
        nCr[0][0] = 1;
        for (int i = 0; i <= n; i++)
        {
            nCr[i][0] = 1;
            for (int j = 1; j <= i; j++)
                nCr[i][j] = nCr[i - 1][j - 1] + nCr[i - 1][j];
        }
    }
    public ModInteger this[int n, int r]
    {
        get
        {
            if (n < 0 || n > nCr.Length)
                throw new IndexOutOfRangeException("n<=0 || n>N ");
            if (r < 0 || r > n)
                throw new IndexOutOfRangeException("r<=0 ||r>n");
            return nCr[n][r];
        }
    }
    public ModInteger RepeatedCombination(int n, int k)
    {
        if (k == 0) return 1;
        return this[n + k - 1, k];
    }
}
#endregion


using System;

namespace BubbleCup
{
    class Program
    {
        private static int modulo = 1000000007;

        private static int ModularAddition(int firstNumber, int secondNumber)
        {
            var result = (firstNumber % modulo + secondNumber % modulo) % modulo;
            if(result < 0)
                result += modulo;
            return result;
        }

        private static int ModularExponentiation(int number, int power)
        {
            int result = 1;
            while (power > 0)
            {
                if ((power & 1) == 1)
                    result = ModularMultiplication(result, number);
                power >>= 1;
                number = ModularMultiplication(number, number);
            }
            return result;
        }

        private static int ModularMultiplication(long firstNumber, long secondNumber)
        {
            return (int)(((firstNumber % (long)modulo) * (secondNumber % (long)modulo)) % (long)modulo);
        }

        private static int ModularMultiplicativeInverse(int number)
        {
            return ModularExponentiation(number, modulo - 2);
        }

        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            int states = 0;

            int binaryTreeStates = ModularExponentiation(2, n + 1) - 1;
            states = ModularAddition(states, binaryTreeStates);
            int statesThatNotProduceDuplicates = 1;
            int previousLevelStatesCount = ModularExponentiation(2, n);
            for (int treeLevel = n + 1; treeLevel <= 2 * n; treeLevel++)
            {
                int currentLevelStates =
                    ModularMultiplication(2, ModularAddition(previousLevelStatesCount, -ModularMultiplication(2, statesThatNotProduceDuplicates)))
                    + ModularMultiplication(2, statesThatNotProduceDuplicates);
                states = ModularAddition(states, currentLevelStates);

                previousLevelStatesCount = currentLevelStates;
                statesThatNotProduceDuplicates = ModularMultiplication(
                    statesThatNotProduceDuplicates,
                    treeLevel);
                statesThatNotProduceDuplicates = ModularMultiplication(
                    statesThatNotProduceDuplicates,
                    ModularMultiplicativeInverse(treeLevel - n));
            }

            Console.Write(states + "\n");
        }
    }
}


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

namespace BubbleCup
{
	class Program
	{

		struct Node
		{
			public Node(int red, int blue)
			{
				this.red = red;
				this.blue = blue;
			}
			public int red;
			public int blue;
		}

		static void Main(string[] args)
		{
			var n = int.Parse(Console.ReadLine());
			var states = 1;
			var edge = new Queue<Node>();
			edge.Enqueue(new Node(n, n));

			while(edge.Count > 0)
			{
				var node = edge.Dequeue();
				if (node.red > 0)
				{
					edge.Enqueue(new Node(node.red - 1, node.blue));
					states++;
				}

				if (node.blue > 0)
				{
					edge.Enqueue(new Node(node.red, node.blue - 1));
					states++;
				}
			}

			Console.Write(states);
		}
	}
}


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

class Solver
{
    int N;
    string S;
    ModInt[][] dp;
    bool[][] use;
    public void Solve(Scanner sc)
    {
        N = sc.Int;S = ReadLine();
        dp = Create(N, () => new ModInt[1 << 20]);
        use = Create(N, () => new bool[1 << 20]);
        ModInt res = 0;
        for (var i = 0; i < N; i++)
            res += memo(0, i);
        WriteLine(res);
    }
    ModInt memo(int s,int i)
    {
        var ct = 0;
        for (var j = 0; j < 20; j++)
            ct += 1 & s >> j;
        if (i == N)
            return ToInt32(ct != 0 && (1 << ct) - 1 == s);
        if (use[i][s]) return dp[i][s];
        ModInt res = 0;
        if (S[i] == '0') return dp[i][s] = memo(s, i + 1);
        var c = 0;
        for (var j = i; j < N; j++)
        {
            c <<= 1;c += S[j] - '0';
            if (c > 20) break;
            res += memo(s | (1 << (c - 1)), j + 1);
        }
        if (ct != 0 && (1 << ct)-1 == s) res++;
        return dp[i][s] = res;
    }
}

public struct ModInt
{
    public const long MOD = (int)1e9 + 7;
    //public const long MOD = 998244353;
    public long Value { get; set; }
    public ModInt(long n = 0) { Value = n; }
    private static ModInt[] fac;//階乗
    private static ModInt[] inv;//逆数
    private static ModInt[] facinv;//1/(i!)
    public override string ToString() => Value.ToString();
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt operator +(ModInt l, ModInt r)
    {
        l.Value += r.Value;
        if (l.Value >= MOD) l.Value -= MOD;
        return l;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt operator -(ModInt l, ModInt r)
    {
        l.Value -= r.Value;
        if (l.Value < 0) l.Value += MOD;
        return l;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt operator *(ModInt l, ModInt r) => new ModInt(l.Value * r.Value % MOD);
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt operator /(ModInt l, ModInt r) => l * Pow(r, MOD - 2);
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static implicit operator long(ModInt l) => l.Value;
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static implicit operator ModInt(long n)
    {
        n %= MOD; if (n < 0) n += MOD;
        return new ModInt(n);
    }

    public static ModInt Pow(ModInt m, long n)
    {
        if (n == 0) return 1;
        if (n % 2 == 0) return Pow(m * m, n >> 1);
        else return Pow(m * m, n >> 1) * m;
    }

    public static void Build(int n)
    {
        fac = new ModInt[n + 1];
        facinv = new ModInt[n + 1];
        inv = new ModInt[n + 1];
        inv[1] = 1;
        fac[0] = fac[1] = 1;
        facinv[0] = facinv[1] = 1;
        for (var i = 2; i <= n; i++)
        {
            fac[i] = fac[i - 1] * i;
            inv[i] = MOD - inv[MOD % i] * (MOD / i);
            facinv[i] = facinv[i - 1] * inv[i];
        }
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt Fac(ModInt n) => fac[n];
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt Inv(ModInt n) => inv[n];
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt FacInv(ModInt n) => facinv[n];
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static ModInt Comb(ModInt n, ModInt r)
    {
        if (n < r) return 0;
        if (n == r) return 1;
        var calc = fac[n];
        calc = calc * facinv[r];
        calc = calc * facinv[n - r];
        return calc;
    }
}
#region Template
public static class Template
{
    static void Main(string[] args)
    {
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        new Solver().Solve(new Scanner());
        Console.Out.Flush();
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmin<T>(ref T a, T b) where T : IComparable<T>
    { if (a.CompareTo(b) == 1) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmax<T>(ref T a, T b) where T : IComparable<T>
    { if (a.CompareTo(b) == -1) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(ref T a, ref T b)
    { var t = b; b = a; a = t; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static T[] Create<T>(int n, Func<T> f)
    {
        var rt = new T[n];
        for (var i = 0; i < rt.Length; ++i)
            rt[i] = f();
        return rt;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static T[] Create<T>(int n, Func<int, T> f)
    {
        var rt = new T[n];
        for (var i = 0; i < rt.Length; ++i)
            rt[i] = f(i);
        return rt;
    }
    public static T[] Copy<T>(this T[] A) => Create(A.Length, i => A[i]);
    public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); }
}

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

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

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

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

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


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

class Solver
{
    int N;const int MOD = (int)1e9 + 7;
    string S;
    int[][] dp;
    public void Solve(Scanner sc)
    {
        N = sc.Int;S = ReadLine();
        dp = Create(N, () => Create(1<<20,()=>-1));
        int res = 0;
        for (var i = 0; i < N; i++)
        { res += memo(0, i); if (res >= MOD) res -= MOD; }
        WriteLine(res);
    }
    int memo(int s,int i)
    {
        var ct = 0;
        for (var j = 0; j < 20; j++)
            ct += 1 & s >> j;
        if (i == N)
            return ToInt32(ct != 0 && (1 << ct) - 1 == s);
        if (dp[i][s] != -1) return dp[i][s];
        int res = 0;
        if (S[i] == '0') return dp[i][s] = memo(s, i + 1);
        var c = 0;
        for (var j = i; j < N; j++)
        {
            c <<= 1;c += S[j] - '0';
            if (c > 20) break;
            res += memo(s | (1 << (c - 1)), j + 1);
            if (res >= MOD) res -= MOD;
        }
        if (ct != 0 && (1 << ct)-1 == s) res++;
        if (res >= MOD) res -= MOD;
        return dp[i][s] = res;
    }
}

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

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

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

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

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

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


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

namespace Codeforces.R293
{
    public static class B
    {
        public static void Main()
        {
            using (var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false })
            {
                Solve(Console.In, sw);
            }
        }

        public static void Solve(TextReader tr, TextWriter tw)
        {
            Contract.Requires(tr != null);
            Contract.Requires(tw != null);

            var info = CultureInfo.CurrentCulture;
            var nmk = tr.ReadLine().Split().Select(x => int.Parse(x, info)).ToArray();
            var n = nmk[0];
            var k = nmk[2];

            var a = new int[n][];
            for (int i = 0; i < n; ++i)
            {
                a[i] = tr.ReadLine().Split().Select(x => int.Parse(x, info)).ToArray();
            }

            var res = Calc(k, a);

            tw.WriteLine(res);
        }

        private static int Calc(int k, int[][] a)
        {
            var n = a.Length;
            var m = a[0].Length;

            if (k < n + m - 1)
            {
                return 0;
            }

            var p = new int[n * m];

            var patterns = new List<int[]>();
            CreatePatterns(ref patterns, 1, 0, 0, n, m, k, ref p);

            var res = 0;

            foreach (var pattern in patterns)
            {
                if (!IsInvalid(pattern, a))
                {
                    var fixedCells = a.SelectMany(x => x).Where(x => x > 0).Count();
                    res += Permutation(k - fixedCells, pattern.Distinct().Count() - fixedCells);
                }
            }

            return res;
        }

        private static bool IsInvalid(int[] pattern, int[][] a)
        {
            var n = a.Length;
            var m = a[0].Length;

            var colorMap = new Dictionary<int, int>();
            for (int i = 0; i < n; ++i)
            {
                for (int j = 0; j < m; ++j)
                {
                    if (a[i][j] > 0)
                    {
                        if (!colorMap.ContainsKey(a[i][j]))
                        {
                            colorMap[a[i][j]] = i * m + j;
                        }
                        else
                        {
                            var prev = colorMap[a[i][j]];
                            var prevJ = prev % m;

                            if (prevJ <= j)
                            {
                                return true;
                            }

                            colorMap[a[i][j]] = i * m + j;

                            if (pattern[i * m + j] != pattern[prev])
                            {
                                return true;
                            }
                        }
                    }
                }
            }

            return false;
        }

        private static int Permutation(int n, int k)
        {
            var res = 1;
            for (int i = 0; i < k; ++i)
            {
                res *= n - i;
            }
            return res;
        }

        private static void CreatePatterns(ref List<int[]> patterns, int newColor, int r, int c, int n, int m, int k, ref int[] board)
        {
            if (r == n)
            {
                patterns.Add(board.Clone() as int[]);
                return;
            }

            if (c == m)
            {
                CreatePatterns(ref patterns, newColor, r + 1, 0, n, m, k, ref board);
                return;
            }

            if (newColor > k)
            {
                return;
            }

            var used = new bool[newColor];

            for (int i = 0; i <= r; ++i)
            {
                for (int j = 0; j <= c; ++j)
                {
                    if (!(i == r && j == c))
                    {
                        used[board[i * m + j]] = true;
                    }
                }
            }

            for (int currentColor = 1; currentColor < newColor; ++currentColor)
            {
                if (!used[currentColor])
                {
                    board[r * m + c] = currentColor;
                    CreatePatterns(ref patterns, newColor, r, c + 1, n, m, k, ref board);
                    board[r * m + c] = 0;
                }
            }
            board[r * m + c] = newColor;
            CreatePatterns(ref patterns, newColor + 1, r, c + 1, n, m, k, ref board);
            board[r * m + c] = 0;
        }
    }
}


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

namespace Codeforces.R293
{
    public static class B
    {
        public static void Main()
        {
            using (var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false })
            {
                Solve(Console.In, sw);
            }
        }

        public static void Solve(TextReader tr, TextWriter tw)
        {
            Contract.Requires(tr != null);
            Contract.Requires(tw != null);

            var info = CultureInfo.CurrentCulture;
            var nmk = tr.ReadLine().Split().Select(x => int.Parse(x, info)).ToArray();
            var n = nmk[0];
            var k = nmk[2];

            var a = new int[n][];
            for (int i = 0; i < n; ++i)
            {
                a[i] = tr.ReadLine().Split().Select(x => int.Parse(x, info)).ToArray();
            }

            var res = Calc(k, a);

            tw.WriteLine(res);
        }

        private static int Calc(int k, int[][] a)
        {
            var n = a.Length;
            var m = a[0].Length;

            if (k < n + m - 1)
            {
                return 0;
            }

            var p = new int[n * m];

            var patterns = new List<int[]>();
            CreatePatterns(ref patterns, 1, 0, 0, n, m, k, ref p);

            var res = 0;

            foreach (var pattern in patterns)
            {
                if (!IsInvalid(pattern, a))
                {
                    var fixedCells = a.SelectMany(x => x).Where(x => x > 0).Distinct().Count();
                    res += Permutation(k - fixedCells, pattern.Distinct().Count() - fixedCells);
                }
            }

            return res;
        }

        private static bool IsInvalid(int[] pattern, int[][] a)
        {
            var n = a.Length;
            var m = a[0].Length;

            var colorMap = new Dictionary<int, int>();
            for (int i = 0; i < n; ++i)
            {
                for (int j = 0; j < m; ++j)
                {
                    if (a[i][j] > 0)
                    {
                        if (!colorMap.ContainsKey(a[i][j]))
                        {
                            foreach (var p in colorMap.Values)
                            {
                                if (p == pattern[i * m + j])
                                {
                                    return true;
                                }
                            }

                            colorMap[a[i][j]] = pattern[i * m + j];
                        }
                        else
                        {
                            if (colorMap[a[i][j]] != pattern[i * m + j])
                            {
                                return true;
                            }
                        }
                    }
                }
            }

            return false;
        }

        private static int Permutation(int n, int k)
        {
            var res = 1;
            for (int i = 0; i < k; ++i)
            {
                res *= n - i;
            }
            return res;
        }

        private static void CreatePatterns(ref List<int[]> patterns, int newColor, int r, int c, int n, int m, int k, ref int[] board)
        {
            if (r == n)
            {
                patterns.Add(board.Clone() as int[]);
                return;
            }

            if (c == m)
            {
                CreatePatterns(ref patterns, newColor, r + 1, 0, n, m, k, ref board);
                return;
            }

            if (newColor > k)
            {
                return;
            }

            var used = new bool[newColor];

            for (int i = 0; i <= r; ++i)
            {
                for (int j = 0; j <= c; ++j)
                {
                    if (!(i == r && j == c))
                    {
                        used[board[i * m + j]] = true;
                    }
                }
            }

            for (int currentColor = 1; currentColor < newColor; ++currentColor)
            {
                if (!used[currentColor])
                {
                    board[r * m + c] = currentColor;
                    CreatePatterns(ref patterns, newColor, r, c + 1, n, m, k, ref board);
                    board[r * m + c] = 0;
                }
            }
            board[r * m + c] = newColor;
            CreatePatterns(ref patterns, newColor + 1, r, c + 1, n, m, k, ref board);
            board[r * m + c] = 0;
        }
    }
}


using System;

public class Program
{
    public static void Main()
    {
        var input = Console.ReadLine().Split(' ');
        var a = int.Parse(input[0]);
        var ta = int.Parse(input[1]);
        input = Console.ReadLine().Split(' ');
        var b = int.Parse(input[0]);
        var tb = int.Parse(input[1]);
        input = Console.ReadLine().Split(':');

        // All time points are in minutes.
        var tripBegin = int.Parse(input[0])*60 + int.Parse(input[1]);
        var trafficBegin = 5*60;
        var trafficEnd = 23*60 + 59;
        var approachingTrafficBegin = Math.Max(tripBegin - tb + 1, trafficBegin);
        var approachingTrafficEnd = Math.Min(tripBegin + ta - 1, trafficEnd);
        var firstApproachingBus =
            approachingTrafficBegin % b == 0 ?
                approachingTrafficBegin :
                approachingTrafficBegin + (b - approachingTrafficBegin % b);
        var approachingBusesCount = 0;
        if (approachingTrafficEnd >= firstApproachingBus)
            approachingBusesCount = (approachingTrafficEnd - firstApproachingBus) / b + 1;
        Console.WriteLine(approachingBusesCount);
    }
}


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

namespace Buses_Between_Cities
{
    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 a = Next();
            int ta = Next();

            int b = Next();
            int tb = Next();

            int hh = Next();
            int mm = Next();

            var start = new DateTime(10, 10, 10, hh, mm, 0);
            DateTime end = start.AddMinutes(ta);

            int count = 0;
            for (var i = new DateTime(10, 10, 10, 5, 0, 0); i < end; i = i.AddMinutes(b))
            {
                DateTime e = i.AddMinutes(tb);

                if (e > start)
                    count++;
            }

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

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


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

class Solver
{
    public void Solve(Scanner sc)
    {
        int a, ta, b, tb;
        sc.Make(out a, out ta, out b, out tb);
        var T = sc.Str.Split(':').Select(int.Parse).ToArray();
        int s = 60 * T[0] + T[1], t = 60 * T[0] + T[1] + ta;
        int st = 300, en = 24 * 60;
        var res = 0;
        for (int i = st; i < en; i += b)
        {
            if ((s <= i && i < t) || (s < i + tb && i + tb <= t)) res++;
        }
        WriteLine(res);
    }
}

#region Template
public static class Template
{
    static void Main(string[] args)
    {
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        new Solver().Solve(new Scanner());
        Console.Out.Flush();
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) > 0) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(this IList<T> A, int i, int j) { var t = A[i]; A[i] = A[j]; A[j] = t; }
    public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; }
    public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; }
    public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> A) => A.OrderBy(v => Guid.NewGuid());
    public static int CompareTo<T>(this T[] A, T[] B, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; for (var i = 0; i < Min(A.Length, B.Length); i++) { int c = cmp(A[i], B[i]); if (c > 0) return 1; else if (c < 0) return -1; } if (A.Length == B.Length) return 0; if (A.Length > B.Length) return 1; else return -1; }
    public static int MaxElement<T>(this IList<T> A, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; T max = A[0]; int rt = 0; for (int i = 1; i < A.Count; i++) if (cmp(max, A[i]) < 0) { max = A[i]; rt = i; } return rt; }
    public static T PopBack<T>(this List<T> A) { var v = A[A.Count - 1]; A.RemoveAt(A.Count - 1); return v; }
    public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); }
}
public class Scanner
{
    public string Str => Console.ReadLine().Trim();
    public int Int => int.Parse(Str);
    public long Long => long.Parse(Str);
    public double Double => double.Parse(Str);
    public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
    public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
    public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
    public int[] ArrInt1D(int n) => Create(n, () => Int);
    public long[] ArrLong1D(int n) => Create(n, () => Long);
    public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
    public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
    private Queue<string> q = new Queue<string>();
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); }
    public void Make<T1>(out T1 v1) => v1 = Next<T1>();
    public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); }
    public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); }
    public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); }
    public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); }
    public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); }
    //public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1, v2); }
    //public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2, out T3 v3); return (v1, v2, v3); }
    //public (T1, T2, T3, T4) Make<T1, T2, T3, T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, v3, v4); }
}
public class Pair<T1, T2> : IComparable<Pair<T1, T2>>
{
    public T1 v1;
    public T2 v2;
    public Pair() { }
    public Pair(T1 v1, T2 v2)
    { this.v1 = v1; this.v2 = v2; }

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

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

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


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

class Solver
{
    public void Solve(Scanner sc)
    {
        int a, ta, b, tb;
        sc.Make(out a, out ta, out b, out tb);
        var T = sc.Str.Split(':').Select(int.Parse).ToArray();
        int s = 60 * T[0] + T[1], t = 60 * T[0] + T[1]+ta;
        int st = 300, en = 24*60;
        var res = 0;
        for (int i = st; i < en; i += b)
        {
            if ((s <= i && i < t) || (s <= i + tb && i + tb < t)) res++;
        }
        WriteLine(res);
    }
}

#region Template
public static class Template
{
    static void Main(string[] args)
    {
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        new Solver().Solve(new Scanner());
        Console.Out.Flush();
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) > 0) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(this IList<T> A, int i, int j) { var t = A[i]; A[i] = A[j]; A[j] = t; }
    public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; }
    public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; }
    public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> A) => A.OrderBy(v => Guid.NewGuid());
    public static int CompareTo<T>(this T[] A, T[] B, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; for (var i = 0; i < Min(A.Length, B.Length); i++) { int c = cmp(A[i], B[i]); if (c > 0) return 1; else if (c < 0) return -1; } if (A.Length == B.Length) return 0; if (A.Length > B.Length) return 1; else return -1; }
    public static int MaxElement<T>(this IList<T> A, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; T max = A[0]; int rt = 0; for (int i = 1; i < A.Count; i++) if (cmp(max, A[i]) < 0) { max = A[i]; rt = i; } return rt; }
    public static T PopBack<T>(this List<T> A) { var v = A[A.Count - 1]; A.RemoveAt(A.Count - 1); return v; }
    public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); }
}
public class Scanner
{
    public string Str => Console.ReadLine().Trim();
    public int Int => int.Parse(Str);
    public long Long => long.Parse(Str);
    public double Double => double.Parse(Str);
    public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
    public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
    public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
    public int[] ArrInt1D(int n) => Create(n, () => Int);
    public long[] ArrLong1D(int n) => Create(n, () => Long);
    public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
    public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
    private Queue<string> q = new Queue<string>();
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); }
    public void Make<T1>(out T1 v1) => v1 = Next<T1>();
    public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); }
    public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); }
    public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); }
    public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); }
    public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); }
    //public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1, v2); }
    //public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2, out T3 v3); return (v1, v2, v3); }
    //public (T1, T2, T3, T4) Make<T1, T2, T3, T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, v3, v4); }
}
public class Pair<T1, T2> : IComparable<Pair<T1, T2>>
{
    public T1 v1;
    public T2 v2;
    public Pair() { }
    public Pair(T1 v1, T2 v2)
    { this.v1 = v1; this.v2 = v2; }

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

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

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


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

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

            string[] t_A = Console.ReadLine().Split(' ');
            string[] t_B = Console.ReadLine().Split(' ');
            string[] HHH = Console.ReadLine().Split(':');
           int hour = 0;
           if (HHH[0][0] == '0') hour = int.Parse(HHH[0][1].ToString());
           else
               hour = int.Parse(HHH[0][0].ToString()) * 10 + int.Parse(HHH[0][1].ToString());
           int minute = 0;
           if (HHH[1][0] == '0') minute = int.Parse(HHH[1][1].ToString());
           else
               minute = int.Parse(HHH[1][0].ToString()) * 10 + int.Parse(HHH[1][1].ToString());
           int starttime = hour * 60 + minute;
           int endtime = starttime + int.Parse(t_A[1].ToString());
           int ans = 0;
           int start = 300;
           int chastota = int.Parse(t_B[0].ToString());
           int time = int.Parse(t_B[1].ToString());
           while (true)
           {
               if (start + time > starttime) break;
               start += chastota;
           }
           while (true)
           {
               if (start >= endtime) break;
               ans++;
               start += chastota;
           }
           Console.WriteLine(ans);

        }
    }
}


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

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

	internal class Task
	{
		public void Solve(int testNumber, InputReader sr, TextWriter sw)
		{
			var input = sr.ReadArray(Int32.Parse);
			var a = input[0];
			var ta = input[1];
			input = sr.ReadArray(Int32.Parse);
			var b = input[0];
			var tb = input[1];
			var str = sr.NextString().Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
			var h = str[0][0] == '0' ? Int32.Parse(str[0][1].ToString(CultureInfo.InvariantCulture)) : Int32.Parse(str[0]);
			var m = str[1][0] == '0' ? Int32.Parse(str[1][1].ToString(CultureInfo.InvariantCulture)) : Int32.Parse(str[1]);
			var count = 0;
			var start = h * 60 + m;
			int end =start + ta;
			var times = new List<int>();
			var bArr = new List<Tuple<int, int>>();
			for (var startB = 5 * 60; startB + tb <= 23*60 + 59; startB += b) {
				bArr.Add(new Tuple<int, int>(startB, startB + tb));
			}
			for (var i = 0; i < bArr.Count; i++) {
				var next = bArr[i];
				if (start < next.Item2 && next.Item1 < end) {
					count++;
				}
			}

			sw.WriteLine(count);
		}
	}

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

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

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

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

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

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

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

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

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

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

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


using System;

public class Program
{
    public static void Main()
    {
        var input = Console.ReadLine().Split(' ');
        var a = int.Parse(input[0]);
        var ta = int.Parse(input[1]);
        input = Console.ReadLine().Split(' ');
        var b = int.Parse(input[0]);
        var tb = int.Parse(input[1]);
        input = Console.ReadLine().Split(':');

        var tripStart = int.Parse(input[0])*60 + int.Parse(input[1]);
        var busesStart = 5*60;
        var approachingBusesStart = Math.Max(tripStart - tb + 1, busesStart);
        var firstApproachingBus = ((approachingBusesStart - busesStart) / b) * (b + 1) + busesStart;
        var approachingBusesCount = (tripStart + ta - firstApproachingBus) / b;
        Console.WriteLine(approachingBusesCount);
    }
}


using System;

public class Program
{
    public static void Main()
    {
        var input = Console.ReadLine().Split(' ');
        var a = int.Parse(input[0]);
        var ta = int.Parse(input[1]);
        input = Console.ReadLine().Split(' ');
        var b = int.Parse(input[0]);
        var tb = int.Parse(input[1]);
        input = Console.ReadLine().Split(':');

        // All time points are in minutes.
        var tripBegin = int.Parse(input[0])*60 + int.Parse(input[1]);
        var trafficBegin = 5*60;
        var trafficEnd = 23*60 + 59;
        var approachingTrafficBegin = Math.Max(tripBegin - tb + 1, trafficBegin);
        var approachingTrafficEnd = Math.Min(tripBegin + ta - 1, trafficEnd);
        var firstApproachingBus =
            approachingTrafficBegin % b == 0 ?
                approachingTrafficBegin :
                approachingTrafficBegin + (b - approachingTrafficBegin % b);
        var approachingBusesCount = (approachingTrafficEnd - firstApproachingBus) / b + 1;
        Console.WriteLine(approachingBusesCount);
    }
}


using System;

class Solution
{
	void Main()
	{
		var inputs = Console.ReadLine().Split();
		var a = int.Parse(inputs[0]);
		var ta = int.Parse(inputs[1]);
		inputs = Console.ReadLine().Split();
		var b = int.Parse(inputs[0]);
		var tb = int.Parse(inputs[1]);
		inputs = Console.ReadLine().Split(':');
		var hh = int.Parse(inputs[0]);
		var mm = int.Parse(inputs[1]);

		var ts = hh*60 + mm;
		Console.WriteLine(GetNumberOfDepartedBuses(ts-tb, ts+ta, b));
	}

	//Returns number of departed buses in the given interval, if inteval ends are exclusive, and
	static int GetNumberOfDepartedBuses(int intervalStart, int intervalEnd, int departureFrequency, int firstDeparture = 5*60, int lastDeparture = 23*60+59)
	{
		int numUntilStart = intervalStart >= firstDeparture
			? (intervalStart - firstDeparture) / departureFrequency + 1	//Inclusive-Inclusive
			: 0;
		int numUntilEnd = intervalEnd <= lastDeparture
			? ((intervalEnd - 1) - firstDeparture) / departureFrequency + 1	//Inclusive-Exclusive
			: (lastDeparture - firstDeparture) / departureFrequency + 1;	//Inclusive-Inclusive

		return numUntilEnd - numUntilStart;
	}
}


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

class Solver
{
    public void Solve(Scanner sc)
    {
        int a, ta, b, tb;
        sc.Make(out a, out ta, out b, out tb);
        var T = sc.Str.Split(':').Select(int.Parse).ToArray();
        int s = 60 * T[0] + T[1], t = 60 * T[0] + T[1] + ta;
        int st = 300, en = 24 * 60;
        var res = 0;
        for (int i = st; i < en; i += b)
        {
            if ((s <= i && i < t) || (s < i + tb && i + tb <= t) || (i < s && t < i + tb) || (s < i && i + tb < t)) res++;
        }
        WriteLine(res);
    }
}

#region Template
public static class Template
{
    static void Main(string[] args)
    {
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        new Solver().Solve(new Scanner());
        Console.Out.Flush();
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) > 0) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(this IList<T> A, int i, int j) { var t = A[i]; A[i] = A[j]; A[j] = t; }
    public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; }
    public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; }
    public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> A) => A.OrderBy(v => Guid.NewGuid());
    public static int CompareTo<T>(this T[] A, T[] B, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; for (var i = 0; i < Min(A.Length, B.Length); i++) { int c = cmp(A[i], B[i]); if (c > 0) return 1; else if (c < 0) return -1; } if (A.Length == B.Length) return 0; if (A.Length > B.Length) return 1; else return -1; }
    public static int MaxElement<T>(this IList<T> A, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; T max = A[0]; int rt = 0; for (int i = 1; i < A.Count; i++) if (cmp(max, A[i]) < 0) { max = A[i]; rt = i; } return rt; }
    public static T PopBack<T>(this List<T> A) { var v = A[A.Count - 1]; A.RemoveAt(A.Count - 1); return v; }
    public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); }
}
public class Scanner
{
    public string Str => Console.ReadLine().Trim();
    public int Int => int.Parse(Str);
    public long Long => long.Parse(Str);
    public double Double => double.Parse(Str);
    public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
    public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
    public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
    public int[] ArrInt1D(int n) => Create(n, () => Int);
    public long[] ArrLong1D(int n) => Create(n, () => Long);
    public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
    public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
    private Queue<string> q = new Queue<string>();
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); }
    public void Make<T1>(out T1 v1) => v1 = Next<T1>();
    public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); }
    public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); }
    public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); }
    public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); }
    public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); }
    //public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1, v2); }
    //public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2, out T3 v3); return (v1, v2, v3); }
    //public (T1, T2, T3, T4) Make<T1, T2, T3, T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, v3, v4); }
}
public class Pair<T1, T2> : IComparable<Pair<T1, T2>>
{
    public T1 v1;
    public T2 v2;
    public Pair() { }
    public Pair(T1 v1, T2 v2)
    { this.v1 = v1; this.v2 = v2; }

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

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

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


using System;

public class Program
{
    public static void Main()
    {
        var input = Console.ReadLine().Split(' ');
        var a = int.Parse(input[0]);
        var ta = int.Parse(input[1]);
        input = Console.ReadLine().Split(' ');
        var b = int.Parse(input[0]);
        var tb = int.Parse(input[1]);
        input = Console.ReadLine().Split(':');

        // All time points are in minutes.
        var tripBegin = int.Parse(input[0])*60 + int.Parse(input[1]);
        var trafficBegin = 5*60;
        var trafficEnd = 23*60 + 59;
        var approachingTrafficBegin = Math.Max(tripBegin - tb + 1, trafficBegin);
        var approachingTrafficEnd = Math.Min(tripBegin + ta - 1, trafficEnd);
        var firstApproachingBus =
            (approachingTrafficBegin - trafficBegin)%b == 0 ?
                approachingTrafficBegin :
                approachingTrafficBegin + (b - (approachingTrafficBegin - trafficBegin)%b);
        var approachingBusesCount = 0;
        if (approachingTrafficEnd >= firstApproachingBus)
            approachingBusesCount = (approachingTrafficEnd - firstApproachingBus) / b + 1;
        Console.WriteLine(approachingBusesCount);
    }
}