using System;
using System.Globalization;
using System.IO;
using System.Linq;

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

	internal class Task
	{
		public void Solve(InputReader sr, TextWriter sw)
		{
			var n = sr.NextInt32();
			if (IsVis(n))
				sw.WriteLine(n + 28);
			else {
				var less = -1;
				for (var i = n - 1; i >= n - 10; i--) {
					if (IsVis(i)) {
						less = i;
						break;
					}
				}
				var greater = -1;
				for (var i = n + 1; i <= n + 10; i++) {
					if (IsVis(i)) {
						greater = i;
						break;
					}
				}
				if ((n - less) < (greater - n))
					sw.WriteLine(n + 11);
				else
					sw.WriteLine(n + 6);
			}
		}

		private bool IsVis(int n)
		{
			return (n % 400 == 0) || (n % 4 == 0 && n % 100 != 0);
		}
	}
}

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

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

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

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

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

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

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

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

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

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

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


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

namespace tes
{
	class contest
	{
		static void Main(string[] args)
		{

         int num = int.Parse(Console.ReadLine());

            var ord = new int[] { 6, 11, 6, 5 };

            if(num % 400 == 0)
            {
                num += 28;
            }
            else if(num %4 == 0)
            {
                if(num %100 == 0)
                {
                    int ind = 0;
                    while (true)
                    {
                        num += ord[ind % 4];
                        ind++;
                        if (num % 4 != 0) break;
                    }
                }
                else num += 28;
            }
            else
            {
                int ind = 0;
                while(true)
                {
                    num += ord[ind % 4];
                    ind++;
                    if (num % 4 != 0) break;
                }
            }

            Console.WriteLine(num);

		}

	}
}


using System;
using System.Globalization;
using System.IO;
using System.Linq;

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

	internal class Task
	{
		public void Solve(InputReader sr, TextWriter sw)
		{
			var n = sr.NextInt32();
			if (IsVis(n))
				sw.WriteLine(n + 28);
			else {
				var less = -1;
				for (var i = n - 1; i >= n - 4; i--) {
					if (IsVis(i)) {
						less = i;
					}
				}
				var greater = -1;
				for (var i = n + 1; i <= n + 4; i++) {
					if (IsVis(i))
						greater = i;
				}
				if ((n - less) < (greater - n))
					sw.WriteLine(n + 11);
				else
					sw.WriteLine(n + 6);
			}
		}

		private bool IsVis(int n)
		{
			return (n % 400 == 0) || (n % 4 == 0 && n % 100 != 0);
		}
	}
}

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

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

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

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

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

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

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

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

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

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

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


using System;
using System.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(sr, sw);
				//Console.ReadKey();
			}
		}
	}

	internal class Task
	{
		public void Solve(InputReader sr, TextWriter sw)
		{
			var n = sr.NextInt32();
			var curr = n + 1;
			var indx = 1;
			var isVis = IsVis(n);
			var visCount = 0;
			while (true) {
				indx++;
				if (IsVis(indx)) {
					visCount -= 2;
					if (visCount < 0) {
						visCount = 7 + visCount;
					}
					curr = visCount;
					if (isVis && curr == 0) {
						break;
					}
				}
				else
					curr += 1;
				curr = curr % 7;
				if (curr == 0 && !isVis)
					break;
			}

			sw.WriteLine(n + indx);
		}

		private bool IsVis(int n)
		{
			return (n % 400 == 0) || (n % 4 == 0 && n % 100 != 0);
		}
	}
}

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

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

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

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

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

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

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

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

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

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

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


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

namespace tes
{
	class contest
	{
		static void Main(string[] args)
		{

         int num = int.Parse(Console.ReadLine());

            var ord = new int[] { 6, 11, 6, 5 };

            if(num % 400 == 0)
            {
                num += 28;
            }
            else if(num %4 == 0)
            {
                if(num %100 == 0)
                {
                    num += 400;
                }
                num += 28;
            }
            else
            {
                int ind = 0;
                while(true)
                {
                    num += ord[ind % 4];

                    if (num % 4 != 0) break;
                }
            }

            Console.WriteLine(num);

		}

	}
}


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

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    public void Solve()
    {
        int x = ReadInt();
        int d = 0;
        while (x > 2000)
        {
            x -= 400;
            d++;
        }

        var d1 = new DateTime(x, 1, 1);
        for (int i = x + 1; ; i++)
        {
            var d2 = new DateTime(i, 1, 1);
            if (d1.DayOfWeek == d2.DayOfWeek && d1.AddDays(400).Day == d2.AddDays(400).Day)
            {
                Write(i + 400 * d);
                return;
            }
        }
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            new Solver().Solve();
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        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
}


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

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

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

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

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

        static bool isVi(int y)
        {
            var r1 = y % 400;
            var r2 = y % 4;
            var r3 = y % 100;

            return r1 == 0 || (r2 == 0 && r3 != 0);
        }
        static void solution()
        {
            #region SOLUTION
            var y = readInt();

            var svi = isVi(y);

            var need = 0;
            while (true)
            {
                if (isVi(y))
                {
                    need += 2;
                }
                else
                {
                    need++;
                }

                y++;

                var ci = isVi(y);
                if (need % 7 == 0 && (ci && svi || !ci && !svi))
                {
                    break;
                }
            }

            Console.WriteLine(y);

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

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

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

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

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

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

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

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


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

namespace ConsoleApplication2
{
    class Program
    {

        public long broj()
        {
            return Convert.ToInt64(Console.ReadLine());
        }
        public long[] niz()
        {
            string a = Console.ReadLine()+" ";
            int cnt = 0, curr = 0;
            for (int i = 0; i < a.Length; i++) if (a[i] == ' ') cnt++;
            long[] niz = new long[cnt];
            cnt = 0;
            for(int i=0;i<a.Length;i++)
            {
                if (a[i] == ' ')
                {
                    niz[cnt++] = curr;
                    curr = 0;
                }
                else curr = curr * 10 + a[i] - '0';
            }
            return niz;
        }

        bool prestupna(long a)
        {

            if (a % 400 == 0 || (a % 4 == 0 && a % 100 != 0)) return true;
            else return false;
        }

        static void Main(string[] args)
        {
            Program C = new ConsoleApplication2.Program();

            long[] a = C.niz();
            long N = a[0],curr=0;
            for(long i=N; ;i++)
            {
                if (C.prestupna(i)) curr += 366;
                else curr += 365;
                curr %= 7;
              if(curr==0&&C.prestupna(i+1)==C.prestupna(N))
                {
                    Console.WriteLine(i + 1);
                    break;
                }
            }

            //Console.ReadKey();
        }
    }
}


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

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

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

            int m = n/2000;
            n = n%2000;
            if (n==0)
            {
                n = 2000;
                m--;
            }

            var dn1 = new DateTime(n, 1, 1);
            var dn2 = new DateTime(n, 12, 31);

            for (n++;; n++)
            {
                var d1 = new DateTime(n, 1, 1);
                if (d1.DayOfWeek == dn1.DayOfWeek)
                {
                    var d2 = new DateTime(n, 12, 31);
                    if (d2.DayOfWeek == dn2.DayOfWeek)
                        break;
                }
            }

            writer.WriteLine(m*2000 + n);
            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)
    {
        var Y = sc.Int;
        var day = 0;
        for(int i=Y; ; i++)
        {
            if (i % 400 == 0 || (i % 100 != 0 && i % 4 == 0))
                day += 366;
            else day += 365;
            if (day % 7 == 0&&!(isuruu(i+1)^isuruu(Y))) Fail(i+1);
        }
    }
    bool isuruu(int i)
        => i % 400 == 0 || (i % 100 != 0 && i % 4 == 0);
}

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

namespace tes
{
	class contest
	{
		static void Main(string[] args)
		{

          int num = int.Parse(Console.ReadLine());

            bool uruu = false;
            if (num % 400 == 0 || (num % 4 == 0 && num % 100 != 0))
            {
               uruu = true;
            }
            int start = 0;

            for(int i=0; i<400; i++)
            {
                num++;

                if (num % 400 == 0 || (num % 4 == 0 && num % 100 != 0))
                {
                    start += 2;
                }
                else start++;

                if(start % 7 == 0)
                {
                    if (uruu)
                    {
                        if (num % 400 == 0 || (num % 4 == 0 && num % 100 != 0)) break;
                    }
                    else
                    {

                        if ((num % 400 != 0 && (num % 4 != 0 ))||( num % 100 == 0)) break;
                    }
                }

            }
            Console.WriteLine(num);

		}

	}
}


using System;
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(sr, sw);
				//Console.ReadKey();
			}
		}
	}

	internal class Task
	{
		public void Solve(InputReader sr, TextWriter sw)
		{
			var n = sr.NextInt32();
			int curr;
			var indx = n;
			var isVis = IsVis(n);
			var start = n % 7;
			curr = start;
			while (true) {
				indx++;
				if (IsVis(indx)) {
					curr += 2;
				}
				else
					curr += 1;
				curr = curr % 7;
				if (curr == start)
				{
					if (isVis) {
						if (IsVis(indx)) {
							break;
						}
					}
					else {
						if (!IsVis(indx)) {
							break;
						}
					}
				}
			}

			sw.WriteLine(indx);
		}

		private bool IsVis(int n)
		{
			return (n % 400 == 0) || (n % 4 == 0 && n % 100 != 0);
		}
	}
}

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;

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

            var diff = 0;
            var i = y;
            do
            {
                diff = (diff + NumDaysOfYear(i)) % 7;
                i++;
            } while (diff != 0 || NumDaysOfYear(y) != NumDaysOfYear(i));

            Console.WriteLine(i);
        }

        static int NumDaysOfYear(int y)
        {
            return (y % 4 == 0 && y % 100 != 0 || y % 400 == 0) ? 366 : 365;
        }
    }
}


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

namespace CodeForces
{
    class Program
    {

        static bool IsVis(int n)
        {
            if (n % 400 == 0 || (n % 4 == 0 && n % 100 != 0))
                return true;
            return false;
        }

        static void Main(string[] args)
        {
            //Ввод-------------------------------------------------------------------
            string[] input = Console.ReadLine().Split(' ');
            int n = Int32.Parse(input[0]);
            //int k = Int32.Parse(input[1]);

            int years = 0;
            for (int i = n + 1; i < 2*n; i++)
            {
                if (IsVis(i))
                    years += 2;
                else
                    years++;
                if (years % 7 == 0)
                {
                    if (IsVis(n) == IsVis(i))
                    {
                        Console.WriteLine(i);
                        return;
                    }
                }

            }
        }
    }
}


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

namespace Codeforces
{
    class Program : ProgramBase
    {
        private const long commonMod = 1000000007;

        static void Main(string[] args)
        {
            var p = new Program();
            var x = p.Get();
            p.Out(x);
        }

        object Get()
        {
            checked
            {
                var n = ReadInt();
                var current = (IsLeap(n) ? 366 : 365) % 7;
                var year = n + 1;
                var leap = IsLeap(n);
                while (current != 0 || IsLeap(year) != leap)
                {
                    current = (current + (IsLeap(year) ? 366 : 365)) % 7;
                    year++;
                }
                return year;
            }
        }

        bool IsLeap(int year)
        {
            if (year % 400 == 0)
                return true;
            if (year % 100 == 0)
                return false;
            if (year % 4 == 0)
                return true;
            return false;
        }

        int NextLeap(int year)
        {
            do
            {
                year += 4;
            } while (!IsLeap(year));
            return year;
        }
        //object Get()
        //{
        //    checked
        //    {
        //        var n = ReadIntToken();
        //        var k = ReadIntToken();
        //        var table = new bool[n, n];
        //        for (int i = 0; i < n; i++)
        //        {
        //            var input = Read();
        //            for (int j = 0; j < n; j++)
        //                table[i, j] = input[j] == '.';
        //        }
        //        var cells = BFS(table);
        //    }
        //}
        //Cell[,] BFS(bool[,] input)
        //{
        //    var n = input.GetLength(0);
        //    var cells = new Cell[n, n];
        //    var visited = new bool[n, n];
        //    var componentIndex = 0;
        //    for (int i = 0; i < n; i++)
        //    {
        //        for (int j = 0; j < n; j++)
        //        {
        //            if (!visited[i, j] && input[i, j])
        //                BFS(i, j, cells, input, visited, componentIndex);
        //        }
        //    }
        //}

        //void BFS(int i, int j, Cell[,] cells, bool[,] input, bool[,] visited, int ccIndex)
        //{
        //    var n = input.GetLength(0);
        //    for
        //}

        struct Cell
        {
            int CCNumber { get; set; }
        }

        class Automata
        {
            bool[] terminals;
            public int sigma;
            public int len;
            public int[,] jumps;

            public void Create()
            {
                var a = ReadInts();
                len = a[0];
                sigma = a[2];
                var ts = ReadInts();
                terminals = new bool[len];
                for (int i = 0; i < ts.Length; i++)
                    terminals[ts[i]] = true;
                jumps = new int[len, sigma];
                for (int i = 0; i < len * sigma; i++)
                {
                    var b = Console.ReadLine().Split(' ');
                    jumps[Convert.ToInt32(b[0]), b[1][0] - 'a'] = Convert.ToInt32(b[2]);
                }
            }
            protected int[] ReadInts()
            {
                return Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray();
            }

            public bool IsTerminal(int s)
            {
                return terminals[s];
            }
        }
    }

    abstract class ProgramBase
    {
        bool? prod = null;
        StreamReader f;
        Queue<string> tokens;
        protected string FileName { private get; set; }

        protected string Read()
        {
            if (f == null)
                f = string.IsNullOrEmpty(FileName)
                    ? new StreamReader(Console.OpenStandardInput())
                    : new StreamReader((GetProd() ? "" : "c:\\dev\\") + FileName);
            return f.ReadLine();
        }

        protected int ReadInt()
        {
            return int.Parse(Read());
        }

        protected int ReadIntToken()
        {
            if (tokens == null || tokens.Count == 0)
                tokens = new Queue<string>(Read().Split(' '));
            return int.Parse(tokens.Dequeue());
        }

        protected int[] ReadInts()
        {
            var tokens = Read().Split(' ');
            var result = new int[tokens.Length];
            for (int i = 0; i < tokens.Length; i++)
                result[i] = int.Parse(tokens[i]);
            return result;
        }

        protected long ReadLongToken()
        {
            if (tokens == null || tokens.Count == 0)
                tokens = new Queue<string>(Read().Split(' '));
            return long.Parse(tokens.Dequeue());
        }

        protected long ReadLong()
        {
            return Convert.ToInt64(Read());
        }

        protected long[] ReadLongs()
        {
            var tokens = Read().Split(' ');
            var result = new long[tokens.Length];
            for (int i = 0; i < tokens.Length; i++)
                result[i] = long.Parse(tokens[i]);
            return result;
        }

        public void Out(object r)
        {
            if (string.IsNullOrEmpty(FileName))
                Console.WriteLine(r);
            else if (GetProd())
                File.WriteAllText(FileName, r.ToString());
            else
                Console.WriteLine(r);
        }

        private bool GetProd()
        {

            if (!prod.HasValue)
                try
                {
                    prod = Environment.MachineName != "RENADEEN-W7";
                }
                catch (Exception)
                {
                    prod = true;
                }
            return prod.Value;
        }
    }

    public static class Huj
    {
        public static T MinBy<T>(this IEnumerable<T> source, Func<T, double> func) where T : class
        {
            T result = null;
            var min = double.MaxValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (min > current)
                {
                    min = current;
                    result = item;
                }
            }
            return result;
        }

        public static T MaxBy<T>(this IEnumerable<T> source, Func<T, double> func, T defaultValue = default(T))
        {
            T result = defaultValue;
            var max = double.MinValue;
            foreach (var item in source)
            {
                var current = func(item);
                if (max < current)
                {
                    max = current;
                    result = item;
                }
            }
            return result;
        }

        public static string JoinStrings(this IEnumerable<string> source, string delimeter)
        {
            return string.Join(delimeter, source.ToArray());
        }

        public static string JoinStrings(this IEnumerable<int> source, string delimeter)
        {
            return source.Select(x => x.ToString()).JoinStrings(delimeter);
        }
    }
}


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

namespace ConsoleApplication1
{
	class Program
	{
		static void Main(string[] args)
		{
			try
			{
				Main main = new Main();
				main.ReadData();
				main.Process();
				main.WriteAnswer();
			}
			catch (Exception e)
			{
				Console.WriteLine(e);
			}
		}
	}

	class Main
	{
		private int _y;
		private long _result;

		public void Process()
		{
			int day = 0;
			const int remCommon = 365 % 7;
			const int remHigh = 366 % 7;
			bool is_high = isHigh(_y);

			while (true)
			{
				_y++;
				if (isHigh(_y))
				{
					day = (day + remHigh) % 7;
				}
				else
				{
					day = (day + remCommon) % 7;
				}
				if (day == 0 && is_high == isHigh(_y))
				{
					break;
				}
			}
			_result = _y;
		}

		private bool isHigh(int year)
		{
			if (year%400 == 0 || (year%4 == 0 && year%100 != 0))
			{
				return true;
			}
			return false;
		}

		public void ReadData()
		{
			TextReader textReader = Console.In;
			//TextReader textReader = new StreamReader("input.txt");
			using (TextReader reader = textReader)
			{
				string readLine = reader.ReadLine();
				//string[] strings1 = readLine.Split(' ');

				_y = int.Parse(readLine);
			}
		}

		public void WriteAnswer()
		{
			using (TextWriter writer = Console.Out)
			{
				writer.WriteLine(_result);
			}
		}
	}
}


using System;

namespace _678B
{
    class Program
    {
        static void Main(string[] args)
        {
            int year = int.Parse(Console.ReadLine()), nextYear = year + 1;
            bool firstLeap = (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);
            int dayOfWeek = 0;
            for (;; nextYear++)
            {
                bool leap = (nextYear % 400 == 0) || (nextYear % 4 == 0 && nextYear % 100 != 0);
                dayOfWeek += leap ? 2 : 1;
                dayOfWeek %= 7;
                if (leap == firstLeap && dayOfWeek == 0)
                    break;
            }
            Console.WriteLine(nextYear);
        }
    }
}


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

class Program
{
    private static long Sqrt3(long x)
    {
        long l = 1;
        long r = Math.Min(1000000, x);
        while (r - l > 1)
        {
            long mid = (l + r) / 2;
            long m3 = mid * mid * mid;
            if (m3 <= x)
                l = mid;
            else
                r = mid;
        }

        return l;
    }

    private static long div(long a, long b, long mod)
    {
        return (a * pow(b, mod - 2, mod)) % mod;
    }
    private static long pow(long a, long p, long mod)
    {
        long res = 1;
        while (p > 0)
        {
            if ((p & 1) == 1) res = (res * a) % mod;
            a = (a * a) % mod;
            p >>= 1;
        }
        return res;
    }

    private static int Offset(int y)
    {
        if (y % 4 == 0)
        {
            if (y % 100 == 0 && y % 400 != 0)
            {
                return 365;
            }

            return 366;
        }

        return 365;
    }

    static void Main(string[] args)
    {
        int n = ReadInt();
        int offset = 0;
        int bOffset = Offset(n);
        while (true)
        {
            n++;
            offset += Offset(n);
            offset %= 7;

            if (offset == 0 && bOffset == Offset(n))
            {
                Console.WriteLine(n);
                return;
            }
        }
    }

    public class RSQ
    {
        private int[] m = new int[200001];
        public void Push(int pos, int v)
        {
            m[pos] += v;
        }

        public int Sum(int l, int r)
        {
            int ans = 0;
            while (l <= r) ans += m[l++];
            return ans;
        }
    }

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

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

        return g;
    }

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

        return matrix;
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        return s.ToArray();
    }

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

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

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

        return s;
    }

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

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

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

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

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

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

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

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


using System;
using System.Text.RegularExpressions;

namespace ConsoleApp2
{
    class Program
    {
       public static bool L(int y)
        {
            if(y%400==0||(y%100!=0 && y%4==0))
            {
                return true;
            }
            return false;
        }
        static void Main(string[] args)
        {
            int y, day = 0,q=0;
            y=Int32.Parse(Console.ReadLine());
            q = y;
            while (q++>0)
            {
                if (L(q) == true)
                {
                    day += 366;
                }
                else
                    day +=+365;
                day %= 7;
                if(L(q)==L(y))
                {
                    if(day==0)
                    {
                        Console.WriteLine(q);
                        break;
                    }
                }

            }
        }
    }
}


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

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

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

            int m = n/2000;
            n = n%2000;

            var dn1 = new DateTime(n, 1, 1);
            var dn2 = new DateTime(n, 12, 31);

            for (n++;; n++)
            {
                var d1 = new DateTime(n, 1, 1);
                if (d1.DayOfWeek == dn1.DayOfWeek)
                {
                    var d2 = new DateTime(n, 12, 31);
                    if (d2.DayOfWeek == dn2.DayOfWeek)
                        break;
                }
            }

            writer.WriteLine(m*2000 + n);
            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.Text;
using System.Linq;
using System.Collections;
using System.Globalization;
using System.Collections.Generic;

namespace ConsoleApplication1
{
    public static class Cin
    {
        public static string NextToken()
        {
            StringBuilder tokenChars = new StringBuilder();
            bool tokenFinished = false;
            bool skipWhiteSpaceMode = true;
            while (!tokenFinished)
            {
                int nextChar = Console.Read();
                if (nextChar == -1)
                {
                    tokenFinished = true;
                }
                else
                {
                    char ch = (char)nextChar;
                    if (char.IsWhiteSpace(ch))
                    {
                        if (!skipWhiteSpaceMode)
                        {
                            tokenFinished = true;
                            if (ch == '\r' && (Environment.NewLine == "\r\n"))
                            {
                                Console.Read();
                            }
                        }
                    }
                    else
                    {
                        skipWhiteSpaceMode = false;
                        tokenChars.Append(ch);
                    }
                }
            }

            string token = tokenChars.ToString();
            return token;
        }

        public static int NextInt()
        {
            string token = Cin.NextToken();
            return int.Parse(token);
        }
        public static long NextLong()
        {
            string token = Cin.NextToken();
            return long.Parse(token);
        }

        public static double NextDouble(bool acceptAnyDecimalSeparator = true)
        {
            string token = Cin.NextToken();
            if (acceptAnyDecimalSeparator)
            {
                token = token.Replace(',', '.');
                double result = double.Parse(token, CultureInfo.InvariantCulture);
                return result;
            }
            else
            {
                double result = double.Parse(token);
                return result;
            }
        }

        public static decimal NextDecimal(bool acceptAnyDecimalSeparator = true)
        {
            string token = Cin.NextToken();
            if (acceptAnyDecimalSeparator)
            {
                token = token.Replace(',', '.');
                decimal result = decimal.Parse(token, CultureInfo.InvariantCulture);
                return result;
            }
            else
            {
                decimal result = decimal.Parse(token);
                return result;
            }
        }
    }

    class Program
    {
        static bool isLeapYear(int x)
        {
            if (x%100 == 0)
            {
                return x%400 == 0;
            }
            else
            {
                return x%4 == 0;
            }
        }
        static void Main(string[] args)
        {
            int a = Cin.NextInt();
            for (int i = a + 1; /* pass */; i++)
            {
                var d1 = DateTime.Parse(string.Format("{0}-01-01", a));
                var d2 = DateTime.Parse(string.Format("{0}-01-01", i));

                var diff = d2 - d1;
                bool ly = !(isLeapYear(a) ^ isLeapYear(i));
                bool wd = diff.Days%7 == 0;

                if (ly && wd)
                {
                    Console.WriteLine(i);
                    break;
                }
            }
        }
    }
}


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

namespace ConsoleApplication1
{
    public static class Cin
    {
        public static string NextToken()
        {
            StringBuilder tokenChars = new StringBuilder();
            bool tokenFinished = false;
            bool skipWhiteSpaceMode = true;
            while (!tokenFinished)
            {
                int nextChar = Console.Read();
                if (nextChar == -1)
                {
                    tokenFinished = true;
                }
                else
                {
                    char ch = (char)nextChar;
                    if (char.IsWhiteSpace(ch))
                    {
                        if (!skipWhiteSpaceMode)
                        {
                            tokenFinished = true;
                            if (ch == '\r' && (Environment.NewLine == "\r\n"))
                            {
                                Console.Read();
                            }
                        }
                    }
                    else
                    {
                        skipWhiteSpaceMode = false;
                        tokenChars.Append(ch);
                    }
                }
            }

            string token = tokenChars.ToString();
            return token;
        }

        public static int NextInt()
        {
            string token = Cin.NextToken();
            return int.Parse(token);
        }
        public static long NextLong()
        {
            string token = Cin.NextToken();
            return long.Parse(token);
        }

        public static double NextDouble(bool acceptAnyDecimalSeparator = true)
        {
            string token = Cin.NextToken();
            if (acceptAnyDecimalSeparator)
            {
                token = token.Replace(',', '.');
                double result = double.Parse(token, CultureInfo.InvariantCulture);
                return result;
            }
            else
            {
                double result = double.Parse(token);
                return result;
            }
        }

        public static decimal NextDecimal(bool acceptAnyDecimalSeparator = true)
        {
            string token = Cin.NextToken();
            if (acceptAnyDecimalSeparator)
            {
                token = token.Replace(',', '.');
                decimal result = decimal.Parse(token, CultureInfo.InvariantCulture);
                return result;
            }
            else
            {
                decimal result = decimal.Parse(token);
                return result;
            }
        }
    }

    class Program
    {
        static bool isLeapYear(int x)
        {
            if (x%100 == 0)
            {
                return x%400 == 0;
            }
            else
            {
                return x%4 == 0;
            }
            return x%4 == 0 && x%400 != 0;
        }
        static void Main(string[] args)
        {
            int a = Cin.NextInt();
            for (int i = a + 1; /* pass */; i++)
            {
                var d1 = DateTime.Parse($"{a}-01-01");
                var d2 = DateTime.Parse($"{i}-01-01");

                var diff = d2 - d1;
                bool ly = !(isLeapYear(a) ^ isLeapYear(i));
                bool wd = diff.Days%7 == 0;

                if (ly && wd)
                {
                    Console.WriteLine(i);
                    break;
                }
            }
        }
    }
}


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

namespace ReadWriteTemplate
{
    public static class Solver
    {
        public static void Solve()
        {
            int max = (int)1e7;

            var p = new bool[max];
            var r = new bool[max];

            for (int i = 1; i < max; i++)
            {
                p[i] = true;
            }
            p[1] = false;
            p[2] = true;
            for (int i = 1; i < max; i++)
            {
                if (p[i])
                {
                    for (int j = i + i; j < max; j += i)
                    {
                        p[j] = false;
                    }
                }
            }

            for (int i = 1; i < 10000; i++)
            {
                int d = i;
                int pal1 = i;
                int pal2 = i * 10 + d % 10;
                d /= 10;
                while (d > 0)
                {
                    pal1 = pal1 * 10 + d % 10;
                    pal2 = pal2 * 10 + d % 10;
                    d /= 10;
                }
                r[pal1] = true;
                if (pal2 < max)
                {
                    r[pal2] = true;
                }
            }

            long pk = ReadLong();
            long qk = ReadLong();

            long pc = 0;
            long rc = 0;
            int ans = 0;
            for (int i = 1; i < max; i++)
            {
                if (p[i])
                {
                    pc++;
                }
                if (r[i])
                {
                    rc++;
                }

                if (pc * qk <= rc * pk)
                {
                    ans = i;
                }
            }
            Writer.Write(ans);
        }

        public static void Main()
        {
            Reader = Console.In; Writer = Console.Out;
            //Reader = File.OpenText("input.txt"); Writer = File.CreateText("output.txt");

            Solve();

            Reader.Close();
            Writer.Close();
        }

        public static IOrderedEnumerable<TSource> OrderByWithShuffle<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
        {
            return source.Shuffle().OrderBy(keySelector);
        }

        public static T[] Shuffle<T>(this IEnumerable<T> source)
        {
            T[] result = source.ToArray();
            Random rnd = new Random();
            for (int i = result.Length - 1; i >= 1; i--)
            {
                int k = rnd.Next(i + 1);
                T tmp = result[k];
                result[k] = result[i];
                result[i] = tmp;
            }
            return result;
        }

        #region Read/Write

        private static TextReader Reader;

        private static TextWriter Writer;

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

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

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

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

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

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

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

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

        public static double[] ReadDoubleArray()
        {
            return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();
        }

        public static int[][] ReadIntMatrix(int numberOfRows)
        {
            int[][] matrix = new int[numberOfRows][];
            for (int i = 0; i < numberOfRows; i++)
                matrix[i] = ReadIntArray();
            return matrix;
        }

        public static 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));
        }

        #endregion
    }
}


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

namespace RM_315_C
{
    class RM_C
    {
        static int[] Prime_count, Pal_count;
        static void Main(string[] args)
        {
            //StreamReader f = new StreamReader("input_C.txt");
            TextReader f = Console.In;
            string[] s = f.ReadLine().Split(' ');
            int p = int.Parse(s[0]), q = int.Parse(s[1]);
            int n = 1179858;
            Prime_count = new int[n + 1];
            Pal_count = new int[n + 1];
            int prime_c = GetCountofPrimes(n), pal_c = GetCountofPalindroms(n);

            for (int i = n; i > 0; i--)
            {
                if (Prime_count[i] <= (double)p / q * Pal_count[i])
                {
                    Console.WriteLine(i);
                    break;
                }
            }
            Console.ReadLine();
        }

        static int GetCountofPrimes(int n)
        {
            bool[] A = new bool[n + 1];
            for (int i = 0; i <= n; i++) A[i] = true;
            for (int i = 2; i * i <= n; i++)
            {
                if (A[i])
                {
                    for (int j = i * i; j <= n; j += i)
                    {
                        A[j] = false;
                    }
                }
            }
            int count = 0;
            for (int i = 2; i <= n; i++)
            {
                if (A[i]) count++;
                Prime_count[i] = count;
            }
            return count;
        }

        static int GetCountofPalindroms(int n)
        {
            int count = 0;
            for (int i = 1; i <= n; i++)
            {
                string s = i.ToString();
                bool b = true;
                for (int j = 0; j < s.Length / 2; j++)
                {
                    if (s[j] != s[s.Length - j - 1])
                    {
                        b = false;
                        break;
                    }
                }
                if (b) count++;
                Pal_count[i] = count;
            }
            return count;
        }
    }
}


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

namespace Cpri
{
    class Program
    {

        public static long lmt = 3000000;

        public static long check(long num)
        {
            long reverse = 0;
            long temp = num;
            while (num > 0)
            {
                long remainder = num % 10;
                reverse = reverse * 10 + remainder;
                num /= 10;
            }
            if (reverse == temp) return 1;
            else return 0;

        }
        static void Main(string[] args)
        {
            long[] pri = new long[lmt];
            for (long i = 2; i < lmt; i++)
            {
                pri[i] = 1;
            }
            for (long i = 2; i < lmt; i++)
            {
                if (pri[i] == 1)
                {
                    for (long j = 2 * i; j < lmt; j += i)
                    {
                        pri[j] = 0;
                    }
                }

            }
            for (long i = 1; i < lmt; i++)
            {
                pri[i] += pri[i - 1];
            }
            long[] pln = new long[lmt];
            for (long i = 1; i < lmt; i++)
            {
                pln[i] = check(i);
            }
            for (long i = 1; i < lmt; i++)
            {
                pln[i] += pln[i - 1];
            }

            long[] array = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
            long p = array[0];
            long q = array[1];
            long n = lmt - 1;
            for (n = lmt - 1; n > 0; n--)
            {
                if (pri[n] * q <= pln[n] * p) break;
            }
            Console.WriteLine(n);
        }
    }
}


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

namespace C.Primes_or_Palindromes
{
	class TextReaderHelper
	{
		protected TextReader baseReader;
		protected LinkedList<string> buffer;

		public TextReaderHelper(TextReader baseReader)
		{
			this.baseReader = baseReader;
			buffer = new LinkedList<string>();
		}

		protected void readIfEmpty()
		{
			if (buffer.Count > 0) return;
			string line;
			do
			{
				line = baseReader.ReadLine();
				if (line == null) return;
			}
			while (line.Trim() == string.Empty);
			foreach (var item in line.Split(' ', '\n', '\t'))
				if (item != string.Empty)
					buffer.AddLast(item);
		}

		private object readChar()
		{
			var node = buffer.First;
			var ret = node.Value[0];
			if (node.Value.Length > 1) node.Value = node.Value.Substring(1);
			else buffer.RemoveFirst();
			return ret;
		}

		public T NextElement<T>()
		{
			readIfEmpty();
			if (typeof(T) == typeof(char)) return (T)readChar();
			var ret = (T)Convert.ChangeType(buffer.First.Value, typeof(T));
			buffer.RemoveFirst();
			return ret;
		}

		public int NextInt() { return NextElement<int>(); }

		public string NextString() { return NextElement<string>(); }
	}

	class Program
	{
		[Conditional("DEBUG")]
		private static void Pause()
		{
			Console.ReadKey();
		}

		static void Main(string[] args)
		{
			var reader = new TextReaderHelper(new StreamReader(Console.OpenStandardInput(), Encoding.ASCII, false, 1048576));
			var writer = new StreamWriter(Console.OpenStandardOutput(), Encoding.ASCII, 1048576);
			int p = reader.NextInt(), q = reader.NextInt();
			const int N = 1179858;
			var vis = new bool[N + 1];
			vis[1] = true;
			for (int i = 2; i * i <= N; i++)
				if (!vis[i])
					for (int j = i + i; j <= N; j += i)
						vis[j] = true;
			int ans = 0, prime = 0, rub = 0;
			for (int i = 1; i <= N; i++)
			{
				if (!vis[i]) prime++;
				if (new string(i.ToString().Reverse().ToArray()) == i.ToString()) rub++;
				if (prime * q <= rub * p) ans = Math.Max(ans, i);
			}
			writer.WriteLine(ans);

			writer.Flush();
			Pause();
        }
	}
}


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 p = sc.Integer();
            var q = sc.Integer();
            var primes = MathEx.Sieve(2000050);
            var palindromes = new bool[2000050];
            for (int i = 1; i < 2000050; i++)
            {
                if (StringEx.IsPalindrome(i.ToString())) palindromes[i] = true;
            }
            var a = new int[2000050];
            var b = new int[2000050];
            for (int i = 1; i < 2000050; i++)
            {
                a[i] = a[i - 1] + (primes[i] ? 1 : 0);
                b[i] = b[i - 1] + (palindromes[i] ? 1 : 0);
            }
            for (int i = 2000050 - 1; i >= 0; i--)
            {
                if(q*a[i]<=p*b[i])
                {
                    IO.Printer.Out.WriteLine(i);
                    return;
                }
            }

        }
        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 Palindrome
static public partial class StringEx
{
    /// <summary>回文かどうか調べる．O(|S|)</summary>
    static public bool IsPalindrome(string s)
    {
        if (string.IsNullOrEmpty(s))
            throw new Exception("null or empty");
        var t = s.ToCharArray();
        Array.Reverse(t);
        return s == new string(t);
    }

}
#endregion

#region sieve
static public partial class MathEx
{
    static public bool[] Sieve(int p)
    {
        var isPrime = new bool[p + 1];
        for (int i = 2; i <= p; i++) isPrime[i] = true;
        for (int i = 2; i * i <= p; i++)
            if (!isPrime[i]) continue;
            else
                for (int j = i * i; j <= p; j += i)
                    isPrime[j] = false;
        return isPrime;
    }
}
#endregion


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

namespace codeforces_csharp {
	class Program {
		static bool isPalin(long n) {
			string a, b;
			a = n.ToString();
			b = new string(a.Reverse().ToArray());

			return a == b;
		}

		// 1,200,000

		static long n = 1200000;
		static bool[] not_prime = new bool[1200001];

		static void Main(string[] args) {
			for (long i = 2; i <= n; i++) {
				if (not_prime[i] == false) {
					for (long j = i * 2; j <= n; j += i) {
						not_prime[j] = true;
					}
				}
			}

			long c1 = 0;
			long c2 = 1;

			long max = 1;

			string[] split = Console.ReadLine().Split(' ');
			long p = Convert.ToInt64(split[0]);
			long q = Convert.ToInt64(split[1]);

			for (long i = 2; i <= n; i++) {
				bool t1 = !not_prime[i];
				bool t2 = isPalin(i);

				if (t1) { c1++; }
				if (t2) { c2++; }

				if (c1 * q <= c2 * p) {
					max = i;
				}
			}

			Console.WriteLine(max);
		}
	}
}


using System; namespace _569C { class Program { const int MAX = 1180000; static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int p = Int32.Parse(input[0]); int q = Int32.Parse(input[1]); int n1 = 0; int n2 = 0; int n = 1; int count = 0; for (int i = 1; i < MAX; i++) { if (isPrime(i) == true) n1++; if (IsPalindrome(i.ToString()) == true)                         n2++; if (n1 > n2 * p / q && count==0) {  n = i - 1;  count++; } if (count == 1 && n1 <= n2 * p / q) {  count = 0; } } Console.WriteLine(n == MAX ? "Palindromic tree is better than splay tree" : n.ToString()); } static bool isPrime(int n) { if (n == 1) return false; if (n == 2) return true; if (n == 3) return true; if (n % 2 == 0) return false; if (n % 3 == 0) return false; int i = 5; int w = 2; while (i * i <= n) { if (n % i == 0)                     return false; i += w; w = 6 - w; } return true; } static string Reverse(string value) { char[] chars = value.ToCharArray(); Array.Reverse(chars); return new string(chars); } static bool IsPalindrome(string value) { return value == Reverse(value); } } }


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

// (づ°ω°)づﾐ★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    private const int SIEVE_SIZE = 2000000;
    private readonly bool[] isComposite = new bool[SIEVE_SIZE + 1];
    private readonly IList<int> primes = new List<int>();
    void Sieve()
    {
        for (int i = 2; i * i <= SIEVE_SIZE; i++)
            if (!isComposite[i])
                for (int j = i * i; j <= SIEVE_SIZE; j += i)
                    isComposite[j] = true;
        for (int i = 2; i <= SIEVE_SIZE; i++)
            if (!isComposite[i])
                primes.Add(i);
    }

    void Solve()
    {
        Sieve();
        isComposite[1] = true;

        long p = ReadInt();
        long q = ReadInt();

        int c1 = 0;
        int c2 = 0;
        int ans = 1;
        for (int i = 1; i < SIEVE_SIZE; i++)
        {
            if (!isComposite[i])
                c1++;
            string s = i.ToString();
            bool f = true;
            for (int l = 0, r = s.Length - 1; f && l < r; l++, r--)
                if (s[l] != s[r])
                    f = false;
            if (f)
                c2++;
            if (c1 * q <= c2 * p)
            {
                ans = i;
            }
        }
        Write(ans);
    }

    #region Main

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

    #endregion

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


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

namespace ReadWriteTemplate
{
    public static class Solver
    {
        public static void Solve()
        {
            int max = (int)1e7;

            var p = new bool[max];
            var r = new bool[max];

            for (int i = 1; i < max; i++)
            {
                p[i] = true;
            }
            p[1] = false;
            p[2] = true;
            for (int i = 1; i < max; i++)
            {
                if (p[i])
                {
                    for (int j = i + i; j < max; j += i)
                    {
                        p[j] = false;
                    }
                }
            }

            for (int i = 1; i < 1000; i++)
            {
                int d = i;
                int pal1 = i;
                int pal2 = i * 10 + d % 10;
                d /= 10;
                while (d > 0)
                {
                    pal1 = pal1 * 10 + d % 10;
                    pal2 = pal2 * 10 + d % 10;
                    d /= 10;
                }
                r[pal1] = true;
                r[pal2] = true;
            }

            long pk = ReadLong();
            long qk = ReadLong();

            long pc = 0;
            long rc = 0;
            int ans = 0;
            for (int i = 1; i < max; i++)
            {
                if (p[i])
                {
                    pc++;
                }
                if (r[i])
                {
                    rc++;
                }

                if (pc * qk <= rc * pk)
                {
                    ans = i;
                }
            }
            Writer.Write(ans);
        }

        public static void Main()
        {
            Reader = Console.In; Writer = Console.Out;
            //Reader = File.OpenText("input.txt"); Writer = File.CreateText("output.txt");

            Solve();

            Reader.Close();
            Writer.Close();
        }

        public static IOrderedEnumerable<TSource> OrderByWithShuffle<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
        {
            return source.Shuffle().OrderBy(keySelector);
        }

        public static T[] Shuffle<T>(this IEnumerable<T> source)
        {
            T[] result = source.ToArray();
            Random rnd = new Random();
            for (int i = result.Length - 1; i >= 1; i--)
            {
                int k = rnd.Next(i + 1);
                T tmp = result[k];
                result[k] = result[i];
                result[i] = tmp;
            }
            return result;
        }

        #region Read/Write

        private static TextReader Reader;

        private static TextWriter Writer;

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

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

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

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

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

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

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

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

        public static double[] ReadDoubleArray()
        {
            return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray();
        }

        public static int[][] ReadIntMatrix(int numberOfRows)
        {
            int[][] matrix = new int[numberOfRows][];
            for (int i = 0; i < numberOfRows; i++)
                matrix[i] = ReadIntArray();
            return matrix;
        }

        public static 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));
        }

        #endregion
    }
}


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

namespace Cpri
{
    class Program
    {

        public static int lmt = 3000000;

        public static int check(int num)
        {
            int reverse = 0;
            int temp = num;
            while (num > 0)
            {
                int remainder = num % 10;
                reverse = reverse * 10 + remainder;
                num /= 10;
            }
            if (reverse == temp) return 1;
            else return 0;

        }
        static void Main(string[] args)
        {
            int[] pri = new int[lmt];
            for (int i = 2; i < lmt; i++)
            {
                pri[i] = 1;
            }
            for (int i = 2; i < lmt; i++)
            {
                if (pri[i] == 1)
                {
                    for (int j = 2 * i; j < lmt; j += i)
                    {
                        pri[j] = 0;
                    }
                }

            }
            for (int i = 1; i < lmt; i++)
            {
                pri[i] += pri[i - 1];
            }
            int[] pln = new int[lmt];
            for (int i = 1; i < lmt; i++)
            {
                pln[i] = check(i);
            }
            for (int i = 1; i < lmt; i++)
            {
                pln[i] += pln[i - 1];
            }

            int[] array = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int p = array[0];
            int q = array[1];
            int n = lmt-1;
            for (n = lmt - 1; n > 0; n--)
            {
                if (pri[n] * q <= pln[n] * p) break;
            }
            Console.WriteLine(n);
        }
    }
}


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


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

namespace You_re_a_Professional
{
    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 F = Next();
            int I = Next();
            int T = Next();

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

            writer.WriteLine(nn.Count(e => e >= T));
            writer.Flush();
        }

        private static int Next()
        {
            int c;
            int res;
            do
            {
                c = reader.Read();
                if (c == 'Y')
                    return 1;
                if (c == 'N')
                    return 0;
            } 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.IO;
using System.Linq;
using System.Text;

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

        private static void Main(string[] args)
        {
            string s = Convert.ToString(Next(), 8);
            writer.WriteLine(s.Count(e => e == '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.Diagnostics;
using System.IO;
using System.Linq;

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

        static void Main(string[] args)
        {
            string str = Convert.ToString(ToInt(ReadLine()), 8);
            int count = 0;
            for (int i = 0; i < str.Length; i++)
                if (str[i] == '1')
                    count++;
            Console.WriteLine(count);
            /*
            watch.Stop();
            var elapsedMs = watch.ElapsedMilliseconds;
            Console.WriteLine(elapsedMs);*/
        }
    }
}


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

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

        private static void Main(string[] args)
        {
            string s = Convert.ToString(Next(), 8);
            long t = long.Parse(s);
            writer.WriteLine(t%100);
            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.Text;
using System.Threading;

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    public void Solve()
    {
        int n = ReadInt();
        int ans = 0;
        if (n == 0)
            ans++;
        while (n > 0)
        {
            if (n % 8 == 0)
                ans++;
            n /= 8;
        }
        Write(ans);
    }

    #region Main

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

    #endregion

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


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

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

        static void Main(string[] args)
        {
            string str = ReadLine();
            int count = 0;
            for (int i = 0; i < str.Length; i++)
                if (str[i] == '1')
                    count++;
            Console.WriteLine(count);
            /*
            watch.Stop();
            var elapsedMs = watch.ElapsedMilliseconds;
            Console.WriteLine(elapsedMs);*/
        }
    }
}