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

namespace cf_BooksExposition
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] line = Console.ReadLine().Split(' ');
            int n = Convert.ToInt32(line[0]);
            int k = Convert.ToInt32(line[1]);
            line = Console.ReadLine().Split(' ');
            int[] nums = line.Select(s => Convert.ToInt32(s)).ToArray();

            //int k = 5;
            //int[] nums = new int[] { 8, 19,14, 10, 13,8};
            int l;
            var list = BooksExposition(k, nums, out l);
            Console.WriteLine(l + " " + list.Count);
            foreach (int i in list)
            {
                Console.WriteLine((i + 1) + " " + (i + l));

            }

        }

        private static List<int> BooksExposition(int k, int[] nums, out int l)
        {
            LinkedList<int> maxlist = new LinkedList<int>();
            LinkedList<int> minlist = new LinkedList<int>();

            l = 1;

            maxlist.AddLast(0);
            minlist.AddLast(0);
            int i = 0;
            List<int> results = new List<int>();
            results.Add(0);
            for (int j = 1; j < nums.Length; j++)
            {
                while (maxlist.Count > 0 && nums[j] > nums[maxlist.Last.Value])
                {
                    maxlist.RemoveLast();
                }
                if (maxlist.Count == 0 || nums[j] != nums[maxlist.Last.Value])
                    maxlist.AddLast(j);

                while (minlist.Count > 0 && nums[j] < nums[minlist.Last.Value])
                {
                    minlist.RemoveLast();
                }
                if (minlist.Count == 0 || nums[j] != nums[minlist.Last.Value])
                    minlist.AddLast(j);

                while (nums[maxlist.First.Value] - nums[minlist.First.Value] > k)
                {
                    if (minlist.First.Value < maxlist.First.Value)
                    {
                        i = minlist.First.Value + 1;
                        minlist.RemoveFirst();
                    }
                    else
                    {
                        i = maxlist.First.Value + 1;
                        maxlist.RemoveFirst();
                        if (minlist.First.Value == maxlist.First.Value)
                            minlist.RemoveFirst();
                    }

                }

                if (j - i + 1 > l)
                {
                    l = j - i + 1;
                    results.Clear();
                    results.Add(i);
                }
                else if (j - i + 1 == l)
                {
                    results.Add(i);
                }
            }
            return results;
        }
    }
}

There are several days left before the fiftieth birthday of a famous Berland's writer Berlbury. In this connection the local library decided to make an exposition of the works of this famous science-fiction writer. It was decided as well that it is necessary to include into the exposition only those books that were published during a particular time period. It is obvious that if the books differ much in size, the visitors will not like it. That was why the organizers came to the opinion, that the difference between the highest and the lowest books in the exposition should be not more than k millimeters.The library has n volumes of books by Berlbury, arranged in chronological order of their appearance. The height of each book in millimeters is know, it is hi. As Berlbury is highly respected in the city, the organizers want to include into the exposition as many books as possible, and to find out what periods of his creative work they will manage to cover. You are asked to help the organizers cope with this hard task.

The first line of the input data contains two integer numbers separated by a space n (1 ≤ n ≤ 105) and k (0 ≤ k ≤ 106) — the amount of books by Berlbury in the library, and the maximum allowed height difference between the lowest and the highest books. The second line contains n integer numbers separated by a space. Each number hi (1 ≤ hi ≤ 106) is the height of the i-th book in millimeters.

In the first line of the output data print two numbers a and b (separate them by a space), where a is the maximum amount of books the organizers can include into the exposition, and b — the amount of the time periods, during which Berlbury published a books, and the height difference between the lowest and the highest among these books is not more than k milllimeters. In each of the following b lines print two integer numbers separated by a space — indexes of the first and the last volumes from each of the required time periods of Berlbury's creative work.

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

namespace cf_BooksExposition
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] line = Console.ReadLine().Split(' ');
            int n = Convert.ToInt32(line[0]);
            int k = Convert.ToInt32(line[1]);
            line = Console.ReadLine().Split(' ');
            int[] nums = line.Select(s => Convert.ToInt32(s)).ToArray();

            //int k =  793;

            //int[] nums = new int[] {98580,27440,3719,73977,34819,64092,89939,75329,72884,66502,17464,73662,6666,47984,45348};
            int l;
            var list = BooksExposition(k, nums, out l);
            Console.WriteLine(l + " " + list.Count);
            foreach (int i in list)
            {
                Console.WriteLine((i + 1) + " " + (i + l));
            }

        }

        private static List<int> BooksExposition(int k, int[] nums, out int l)
        {
            LinkedList<int> maxlist = new LinkedList<int>();
            LinkedList<int> minlist = new LinkedList<int>();

            l = 1;

            maxlist.AddLast(0);
            minlist.AddLast(0);
            int i = 0;
            List<int> results = new List<int>();
            results.Add(0);
            for (int j = 1; j < nums.Length; j++)
            {
                while (maxlist.Count > 0 && nums[j] > nums[maxlist.Last.Value])
                {
                    maxlist.RemoveLast();
                }

                maxlist.AddLast(j);

                while (minlist.Count > 0 && nums[j] < nums[minlist.Last.Value])
                {
                    minlist.RemoveLast();
                }

                minlist.AddLast(j);

                while (nums[maxlist.First.Value] - nums[minlist.First.Value] > k)
                {
                    if (minlist.First.Value < maxlist.First.Value)
                    {
                        i = minlist.First.Value + 1;
                        minlist.RemoveFirst();
                        while (maxlist.First.Value < i)
                            maxlist.RemoveFirst();
                    }
                    else
                    {
                        i = maxlist.First.Value + 1;
                        maxlist.RemoveFirst();
                        while (minlist.First.Value < i)
                            minlist.RemoveFirst();
                    }
                }

                if (j - i + 1 > l)
                {
                    l = j - i + 1;
                    results.Clear();
                    results.Add(i);
                }
                else if (j - i + 1 == l)
                {
                    results.Add(i);
                }
            }
            return results;
        }
    }
}


//#undef DEBUG

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

namespace codeforces
{
    class C
    {
        //  test
        static CodeforcesUtils CF = new CodeforcesUtils(
@"
3
1 2 4
");

        class Solver
        {
            public void Solve()
            {
                //
                int n = int.Parse(CF.ReadLine());
                string[] ss = CF.ReadLine().Split(' ');
                List<int> ns = new List<int>();
                foreach (string s in ss)
                {
                    ns.Add(int.Parse(s));
                }
                //
                int a = ns[ns.Count - 1] + 2;
                int b = ns.Count+1;

                for (int i = 0; i < ns.Count; i++)
                {
                    int a1 = ns[i] + 1;
                    int b1 = i + 1;

                    if (a1 * b == a * b1)
                    {
                        CF.WriteLine("unique");
                        CF.WriteLine(ns[ns.Count-1]+1);
                        return;
                    }
                }
                CF.WriteLine("not unique");
            }
        }

        #region test

        static void Main(string[] args)
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("ru-RU");

            new Solver().Solve();
            CF.Close();
        }

        static void TLE()
        {
            for (; ; ) ;
        }

        class CodeforcesUtils
        {
            public string ReadLine()
            {
#if DEBUG
                if (_lines == null)
                {
                    _lines = new List<string>();
                    string[] ss = _test_input.Replace("\n", "").Split('\r');
                    for (int i = 0; i < ss.Length; i++)
                    {
                        if (
                            (i == 0 || i == ss.Length - 1) &&
                            ss[i].Length == 0
                            )
                            continue;

                        _lines.Add(ss[i]);
                    }
                }

                string s = null;
                if (_lines.Count > 0)
                {
                    s = _lines[0];
                    _lines.RemoveAt(0);
                }
                return s;

#else
                //return _sr.ReadLine();
            return Console.In.ReadLine();
#endif
            }

            public void WriteLine(object o)
            {
#if DEBUG
                System.Diagnostics.Trace.WriteLine(o);
#else
                //_sw.WriteLine(o);
            Console.WriteLine(o);
#endif
            }

            public void Write(object o)
            {
#if DEBUG
                System.Diagnostics.Trace.Write(o);
#else
                 //_sw.Write(o);
           Console.Write(o);
#endif
            }

            string _test_input;

            List<string> _lines;

#if DEBUG
            public CodeforcesUtils(string test_input)
            {
                _test_input = test_input;
            }
#else

            public CodeforcesUtils(string dummy)
            {
                //_sr = new System.IO.StreamReader("input.txt");
                //_sw = new System.IO.StreamWriter("output.txt");
            }
#endif

            public void Close()
            {
                if( _sr!= null)
                    _sr.Close();
                if( _sw != null)
                    _sw.Close();
            }

            System.IO.StreamReader _sr=null;
            System.IO.StreamWriter _sw=null;

        }

        #endregion
    }
}

Every year a race takes place on the motorway between cities A and B. This year Vanya decided to take part in the race and drive his own car that has been around and bears its own noble name — The Huff-puffer.So, Vasya leaves city A on the Huff-puffer, besides, at the very beginning he fills the petrol tank with α liters of petrol (α ≥ 10 is Vanya's favorite number, it is not necessarily integer). Petrol stations are located on the motorway at an interval of 100 kilometers, i.e. the first station is located 100 kilometers away from the city A, the second one is 200 kilometers away from the city A, the third one is 300 kilometers away from the city A and so on. The Huff-puffer spends 10 liters of petrol every 100 kilometers. Vanya checks the petrol tank every time he passes by a petrol station. If the petrol left in the tank is not enough to get to the next station, Vanya fills the tank with α liters of petrol. Otherwise, he doesn't stop at the station and drives on. For example, if α = 43.21, then the car will be fuelled up for the first time at the station number 4, when there'll be 3.21 petrol liters left. After the fuelling up the car will have 46.42 liters. Then Vanya stops at the station number 8 and ends up with 6.42 + 43.21 = 49.63 liters. The next stop is at the station number 12, 9.63 + 43.21 = 52.84. The next stop is at the station number 17 and so on. You won't believe this but the Huff-puffer has been leading in the race! Perhaps it is due to unexpected snow. Perhaps it is due to video cameras that have been installed along the motorway which register speed limit breaking. Perhaps it is due to the fact that Vanya threatened to junk the Huff-puffer unless the car wins. Whatever the reason is, the Huff-puffer is leading, and jealous people together with other contestants wrack their brains trying to think of a way to stop that outrage.One way to do this is to mine the next petrol station where Vanya will stop. Your task is to calculate at which station this will happen and warn Vanya. You don't know the α number, however, you are given the succession of the numbers of the stations where Vanya has stopped. Find the number of the station where the next stop will be.

The first line contains an integer n (1 ≤ n ≤ 1000) which represents the number of petrol stations where Vanya has stopped. The next line has n space-separated integers which represent the numbers of the stations. The numbers are positive and do not exceed 106, they are given in the increasing order. No two numbers in the succession match. It is guaranteed that there exists at least one number α ≥ 10, to which such a succession of stops corresponds.

Print in the first line "unique" (without quotes) if the answer can be determined uniquely. In the second line print the number of the station where the next stop will take place. If the answer is not unique, print in the first line "not unique".

NoteIn the second example the answer is not unique. For example, if α = 10, we'll have such a sequence as 1, 2, 3, and if α = 14, the sequence will be 1, 2, 4.

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

namespace ProgrammingContest.Codeforces.Round45
{
    class C
    {
        public static void Main()
        {
            Scanner scanner = Scanner.FromConsole();
            int n = scanner.NextInt();
            int[] stop = new int[n+1];
            stop[0] = 0;
            for (int i = 0; i < n; i++) stop[i + 1] = scanner.NextInt();

            double min = 10, max = double.MaxValue;
            for (int i = 1; i <= n; i++)
            {
                min = Math.Max(min, stop[i] * 10 / (double)i);
                max = Math.Min(max, (stop[i] + 1) * 10 / (double)i);
            }
            double eps = 1e-9;
            if ((int)(min / 10 * (n + 1) + eps) != (int)(max / 10 * (n + 1) - eps))
            {
                Console.Write("not unique");
                return;
            }
            Console.WriteLine("unique");
            Console.WriteLine((int)(min / 10 * (n + 1) + eps));
        }

        #region Scanner
        public class Scanner : IDisposable
        {
            const int MAX_BUFFER_SIZE = 1024 * 1024 * 16;
            const string DELIMITER = " \r\n\t";

            System.IO.TextReader stream;
            int pos = 0, len = 0;
            bool endStream = false;
            int BufferSize = MAX_BUFFER_SIZE;
            char[] buffer = new char[MAX_BUFFER_SIZE];

            public enum Option { Buffering, NoBuffering }

            public Scanner(System.IO.TextReader stream, Option bufferingOption)
            {
                this.stream = stream;
                if (bufferingOption == Option.NoBuffering) BufferSize = 1;
            }

            void ReadBuffer()
            {
                pos = 0;
                len = stream.ReadBlock(buffer, 0, BufferSize);
                endStream = len == 0;
            }

            void SkipDelimiter()
            {
                while (!endStream && IsDelimiter(Peek())) NextChar();
            }

            static bool IsDelimiter(char c)
            {
                return DELIMITER.Contains(c);
            }

            bool Continue(char c)
            {
                return !endStream && !IsDelimiter(c);
            }

            char Peek()
            {
                if (pos >= len) ReadBuffer();
                return buffer[pos];
            }

            public char NextChar()
            {
                if (pos >= len) ReadBuffer();
                return buffer[pos++];
            }

            public string NextString()
            {
                SkipDelimiter();
                StringBuilder res = new StringBuilder();
                for (char c = NextChar(); Continue(c); c = NextChar()) res.Append(c);
                return res.ToString();
            }

            public int NextInt()
            {
                SkipDelimiter();
                int res = 0;
                char c = NextChar();
                int sign = 1;
                if (c == '-') { sign = -1; c = NextChar(); }
                for (; Continue(c); c = NextChar())
                    res = res * 10 + (c - '0');
                return sign * res;
            }

            public long NextLong()
            {
                SkipDelimiter();
                long res = 0;
                char c = NextChar();
                long sign = 1;
                if (c == '-') { sign = -1; c = NextChar(); }
                for (; Continue(c); c = NextChar())
                    res = res * 10 + (c - '0');
                return sign * res;
            }

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

            public int[] NextInts(int n)
            {
                int[] res = new int[n];
                for (int i = 0; i < n; i++) res[i] = NextInt();
                return res;
            }

            public long[] NextLongs(int n)
            {
                long[] res = new long[n];
                for (int i = 0; i < n; i++) res[i] = NextLong();
                return res;
            }

            public double[] NextDoubles(int n)
            {
                double[] res = new double[n];
                for (int i = 0; i < n; i++) res[i] = NextDouble();
                return res;
            }

            public string[] NextStrings(int n)
            {
                string[] res = new string[n];
                for (int i = 0; i < n; i++) res[i] = NextString();
                return res;
            }

            public static Scanner FromString(string s)
            {
                return new Scanner(new System.IO.StreamReader(new System.IO.MemoryStream(Encoding.ASCII.GetBytes(s))), Option.Buffering);
            }

            public static Scanner FromFile(string path)
            {
                return new Scanner(new System.IO.StreamReader(path), Option.Buffering);
            }

            public static Scanner FromConsole()
            {
                return new Scanner(Console.In, Option.Buffering);
            }

            public void Dispose()
            {
                stream.Close();
            }
        }
        #endregion
    }
}


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

namespace Codeforces.TaskD
{
    public class Task
    {
        public static void Main()
        {
            var task = new Task();
            task.Solve();
        }

        private void Solve()
        {
            string text;
            long k;
            Input.Next(out text);
            Input.Next(out k);
            long n = text.Length;

            var corrections = new long[n, n + 1];

            for (var i = 0; i < n; i++)
                for (var j = i + 1; j < n; j++)
                    for (var t = 0; t < (j - i + 1) / 2; t++)
                        corrections[i, j - i + 1] += text[i + t] == text[j - t] ? 0 : 1;

            var dp = new long[n + 1, k + 1];
            for (var i = 0; i <= n; i++)
            {
                for (var j = 0; j <= k; j++)
                    dp[i, j] = long.MaxValue / 2;
                dp[i, 0] = 0;
                dp[i, 1] = corrections[0, i];
            }
            for (var i = 0; i <= k; i++) dp[0, i] = 0;

            for (var count = 1; count < k; count++)
            {
                for (var l = 0; l <= n; l++)
                {
                    for (var len = 1; l + len <= n; len++)
                    {
                        dp[l + len, count + 1] = Math.Min(dp[l + len, count + 1], dp[l, count] + corrections[l, len]);
                    }
                }
            }

            var min = long.MaxValue;
            var minIndex = -1;
            for (var i = 1; i <= k; i++)
                if (dp[n, i] < min)
                {
                    min = dp[n, i];
                    minIndex = i;
                }
            Console.WriteLine(min);

            var prev = n;
            var answers = new List<string>();
            for (var j = 1; j <= minIndex; j++)
            {
                var m = 100000L;
                for (var i = prev - 1; i > 0; i--)
                {
                    if (dp[i, minIndex - j] + corrections[i, prev - i] > min) continue;
                    m = i;
                }
                answers.Add(text.Substring((int)m, (int)(prev - m)));
                prev = m;
                min = dp[m, minIndex - j];
            }
            if (prev > 0) answers.Add(text.Substring(0, (int)(prev)));

            answers.Reverse();
            for (var i = 0; i < answers.Count; i++)
                answers[i] = answers[i].Substring(0, (answers[i].Length + 1)/2) + new string(answers[i].Substring(0, (answers[i].Length)/2).Reverse().ToArray());

            Console.WriteLine(string.Join("+", answers));
        }
    }

    #region Input

    public class Input
    {
        private static string _line;

        public static bool Next()
        {
            _line = Console.ReadLine();
            return !string.IsNullOrEmpty(_line);
        }

        public static bool Next(out long a)
        {
            bool ok = Next();
            a = ok ? long.Parse(_line) : 0;
            return ok;
        }

        public static bool Next(out long a, out long b)
        {
            bool ok = Next();
            if (ok)
            {
                long[] array = _line.Split(' ').Select(long.Parse).ToArray();
                a = array[0];
                b = array[1];
            }
            else
            {
                a = b = 0;
            }

            return ok;
        }

        public static bool Next(out long a, out long b, out long c)
        {
            bool ok = Next();
            if (ok)
            {
                long[] array = _line.Split(' ').Select(long.Parse).ToArray();
                a = array[0];
                b = array[1];
                c = array[2];
            }
            else
            {
                a = b = c = 0;
            }
            return ok;
        }

        public static bool Next(out long a, out long b, out long c, out long d)
        {
            bool ok = Next();
            if (ok)
            {
                long[] array = _line.Split(' ').Select(long.Parse).ToArray();
                a = array[0];
                b = array[1];
                c = array[2];
                d = array[3];
            }
            else
            {
                a = b = c = d = 0;
            }
            return ok;
        }

        public static bool Next(out long a, out long b, out long c, out long d, out long e)
        {
            bool ok = Next();
            if (ok)
            {
                long[] array = _line.Split(' ').Select(long.Parse).ToArray();
                a = array[0];
                b = array[1];
                c = array[2];
                d = array[3];
                e = array[4];
            }
            else
            {
                a = b = c = d = e = 0;
            }
            return ok;
        }

        public static List<long> Numbers()
        {
            Next();
            if (string.IsNullOrEmpty(_line)) return new List<long>();
            return _line.Split(' ').Select(long.Parse).ToList();
        }

        public static bool Next(out string value)
        {
            value = string.Empty;
            if (!Next()) return false;
            value = _line;
            return true;
        }
    }

    #endregion
}

Friday is Polycarpus' favourite day of the week. Not because it is followed by the weekend, but because the lessons on Friday are 2 IT lessons, 2 math lessons and 2 literature lessons. Of course, Polycarpus has prepared to all of them, unlike his buddy Innocentius. Innocentius spent all evening playing his favourite game Fur2 and didn't have enough time to do the literature task. As Innocentius didn't want to get an F, he decided to do the task and read the book called "Storm and Calm" during the IT and Math lessons (he never used to have problems with these subjects). When the IT teacher Mr. Watkins saw this, he decided to give Innocentius another task so that the boy concentrated more on the lesson and less — on the staff that has nothing to do with IT. Mr. Watkins said that a palindrome is a string that can be read the same way in either direction, from the left to the right and from the right to the left. A concatenation of strings a, b is a string ab that results from consecutive adding of string b to string a. Of course, Innocentius knew it all but the task was much harder than he could have imagined. Mr. Watkins asked change in the "Storm and Calm" the minimum number of characters so that the text of the book would also be a concatenation of no more than k palindromes. Innocentius can't complete the task and therefore asks you to help him.

The first input line contains a non-empty string s which is the text of "Storm and Calm" (without spaces). The length of the string s does not exceed 500 characters. String s consists of uppercase and lowercase Latin letters. The second line contains a single number k (1 ≤ k ≤ |s|, where |s| represents the length of the string s).

Print on the first line the minimum number of changes that Innocentius will have to make. Print on the second line the string consisting of no more than k palindromes. Each palindrome should be non-empty and consist of uppercase and lowercase Latin letters. Use the character "+" (ASCII-code 43) to separate consecutive palindromes. If there exist several solutions, print any of them. The letters' case does matter, that is an uppercase letter is not considered equivalent to the corresponding lowercase letter.

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

namespace Codeforces.TaskD
{
    public class Task
    {
        public static void Main()
        {
            var task = new Task();
            task.Solve();
        }

        private void Solve()
        {
            string text;
            long k;
            Input.Next(out text);
            Input.Next(out k);
            long n = text.Length;

            var corrections = new long[n, n + 1];

            for (var i = 0; i < n; i++)
                for (var j = i + 1; j < n; j++)
                    for (var t = 0; t < (j - i + 1) / 2; t++)
                        corrections[i, j - i + 1] += text[i + t] == text[j - t] ? 0 : 1;

            var dp = new long[n + 1, k + 1];
            for (var i = 0; i <= n; i++)
            {
                for (var j = 0; j <= k; j++)
                    dp[i, j] = long.MaxValue / 2;
                dp[i, 0] = 0;
                dp[i, 1] = corrections[0, i];
            }
            for (var i = 0; i <= k; i++) dp[0, i] = 0;

            for (var count = 1; count < k; count++)
            {
                for (var l = 0; l <= n; l++)
                {
                    for (var len = 1; l + len <= n; len++)
                    {
                        dp[l + len, count + 1] = Math.Min(dp[l + len, count + 1], dp[l, count] + corrections[l, len]);
                    }
                }
            }

            var min = long.MaxValue;
            var minIndex = -1;
            for (var i = 1; i <= k; i++)
                if (dp[n, i] < min)
                {
                    min = dp[n, i];
                    minIndex = i;
                }
            Console.WriteLine(min);

            var prev = n;
            var answers = new List<string>();
            for (var j = 1; j < minIndex; j++)
            {
                var m = 100000L;
                for (var i = prev - 1; i > 0; i--)
                {
                    if (dp[i, minIndex - j] + corrections[i, prev - i] > min) continue;
                    m = i;
                }
                answers.Add(text.Substring((int)m, (int)(prev - m)));
                prev = m;
                min = dp[m, minIndex - j];
            }
            answers.Add(text.Substring(0, (int)(prev)));

            answers.Reverse();
            for (var i = 0; i < answers.Count; i++)
                answers[i] = answers[i].Substring(0, (answers[i].Length + 1)/2) + new string(answers[i].Substring(0, (answers[i].Length)/2).Reverse().ToArray());

            Console.WriteLine(string.Join("+", answers));
        }
    }

    #region Input

    public class Input
    {
        private static string _line;

        public static bool Next()
        {
            _line = Console.ReadLine();
            return !string.IsNullOrEmpty(_line);
        }

        public static bool Next(out long a)
        {
            bool ok = Next();
            a = ok ? long.Parse(_line) : 0;
            return ok;
        }

        public static bool Next(out long a, out long b)
        {
            bool ok = Next();
            if (ok)
            {
                long[] array = _line.Split(' ').Select(long.Parse).ToArray();
                a = array[0];
                b = array[1];
            }
            else
            {
                a = b = 0;
            }

            return ok;
        }

        public static bool Next(out long a, out long b, out long c)
        {
            bool ok = Next();
            if (ok)
            {
                long[] array = _line.Split(' ').Select(long.Parse).ToArray();
                a = array[0];
                b = array[1];
                c = array[2];
            }
            else
            {
                a = b = c = 0;
            }
            return ok;
        }

        public static bool Next(out long a, out long b, out long c, out long d)
        {
            bool ok = Next();
            if (ok)
            {
                long[] array = _line.Split(' ').Select(long.Parse).ToArray();
                a = array[0];
                b = array[1];
                c = array[2];
                d = array[3];
            }
            else
            {
                a = b = c = d = 0;
            }
            return ok;
        }

        public static bool Next(out long a, out long b, out long c, out long d, out long e)
        {
            bool ok = Next();
            if (ok)
            {
                long[] array = _line.Split(' ').Select(long.Parse).ToArray();
                a = array[0];
                b = array[1];
                c = array[2];
                d = array[3];
                e = array[4];
            }
            else
            {
                a = b = c = d = e = 0;
            }
            return ok;
        }

        public static List<long> Numbers()
        {
            Next();
            if (string.IsNullOrEmpty(_line)) return new List<long>();
            return _line.Split(' ').Select(long.Parse).ToList();
        }

        public static bool Next(out string value)
        {
            value = string.Empty;
            if (!Next()) return false;
            value = _line;
            return true;
        }
    }

    #endregion
}


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

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

#if DEBUG
			TextReader reader = new StreamReader("../../input5.txt");
#else
			TextReader reader = Console.In;
#endif
			var ints = reader.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
			byte[] peoples = new byte[ints[0]];
			int rightPeoplesCount = ints[1];
			int[] opinions = peoples.Select(i => int.Parse(reader.ReadLine())).ToArray();

			HashSet<int> impossibleMurders = new HashSet<int>();
			int lastPossibleSolution = -1;
			for (int i = 0; i < peoples.Length; i++) {
				int countTruth = 0;
				// is it unpossible
				foreach (var opinion in opinions) {
					if (opinion > 0) {
						if (opinion == i + 1)
							countTruth++;
					} else {
						if (-opinion != i + 1)
							countTruth++;
					}
					if (countTruth > rightPeoplesCount)
						break;
				}
				if (countTruth != rightPeoplesCount)
					impossibleMurders.Add(i + 1);
				else
					lastPossibleSolution = i + 1;

			}

			if (impossibleMurders.Count == peoples.Length - 1) {
				for (int i = 0; i < opinions.Length; i++) {
					if (opinions[i] == lastPossibleSolution)
						peoples[i] = 2;
					else
						peoples[i] = 1;
				}
			} else {
				for (int i = 0; i < opinions.Length; i++) {
					if (opinions[i] > 0 && impossibleMurders.Contains(opinions[i]))
						peoples[i] = 1;
					if (opinions[i] < 0 && impossibleMurders.Contains(-opinions[i]))
						peoples[i] = 2;
				}
			}

			var answrs = new string[]{"Not defined", "Lie", "Truth" };
			Array.ForEach(peoples, i => Console.WriteLine(answrs[i]));

#if DEBUG
			Console.ReadKey();
#endif

		}
	}
}

As Sherlock Holmes was investigating a crime, he identified n suspects. He knows for sure that exactly one of them committed the crime. To find out which one did it, the detective lines up the suspects and numbered them from 1 to n. After that, he asked each one: "Which one committed the crime?". Suspect number i answered either "The crime was committed by suspect number ai", or "Suspect number ai didn't commit the crime". Also, the suspect could say so about himself (ai = i).Sherlock Holmes understood for sure that exactly m answers were the truth and all other answers were a lie. Now help him understand this: which suspect lied and which one told the truth?

The first line contains two integers n and m (1 ≤ n ≤ 105, 0 ≤ m ≤ n) — the total number of suspects and the number of suspects who told the truth. Next n lines contain the suspects' answers. The i-th line contains either "+ai" (without the quotes), if the suspect number i says that the crime was committed by suspect number ai, or "-ai" (without the quotes), if the suspect number i says that the suspect number ai didn't commit the crime (ai is an integer, 1 ≤ ai ≤ n). It is guaranteed that at least one suspect exists, such that if he committed the crime, then exactly m people told the truth.

Print n lines. Line number i should contain "Truth" if suspect number i has told the truth for sure. Print "Lie" if the suspect number i lied for sure and print "Not defined" if he could lie and could tell the truth, too, depending on who committed the crime.

NoteThe first sample has the single person and he confesses to the crime, and Sherlock Holmes knows that one person is telling the truth. That means that this person is telling the truth.In the second sample there are three suspects and each one denies his guilt. Sherlock Holmes knows that only two of them are telling the truth. Any one of them can be the criminal, so we don't know for any of them, whether this person is telling the truth or not.In the third sample the second and the fourth suspect defend the first and the third one. But only one is telling the truth, thus, the first or the third one is the criminal. Both of them can be criminals, so the second and the fourth one can either be lying or telling the truth. The first and the third one are lying for sure as they are blaming the second and the fourth one.

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

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

#if DEBUG
			TextReader reader = new StreamReader("../../input11.txt");
#else
			TextReader reader = Console.In;
#endif
			var ints = reader.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
			byte[] peoples = new byte[ints[0]];
			int rightPeoplesCount = ints[1];
			int[] peoplesLoveMe = new int[peoples.Length];
			int[] peoplesHateMe = new int[peoples.Length];
			int[] opinions = peoples.Select(i => int.Parse(reader.ReadLine())).ToArray();
			bool[] impossibleMurders = new bool[peoples.Length];
			int impossibleMurdersCount = 0;
			int lastPossibleSolution = -1;
			int hates=0;

			for (int i = 0; i < opinions.Length; i++) {
				if (opinions[i] > 0) {
					peoplesLoveMe[opinions[i] - 1]++;
				} else {
					peoplesHateMe[-opinions[i] - 1]++;
					hates++;
				}
			}

			for (int i = 0; i < peoples.Length; i++) {
				int truthCount = peoplesLoveMe[i];
				truthCount += hates - peoplesHateMe[i];
				if (truthCount != rightPeoplesCount) {
					impossibleMurders[i] = true;
					impossibleMurdersCount++;
				} else {
					lastPossibleSolution = i + 1;
				}
			}

			if (impossibleMurdersCount == peoples.Length - 1) {
				for (int i = 0; i < opinions.Length; i++) {
					if (opinions[i] > 0) {
						if (opinions[i] == lastPossibleSolution)
							peoples[i] = 2;
						else
							peoples[i] = 1;
					} else {
						if (-opinions[i] == lastPossibleSolution)
							peoples[i] = 1;
						else
							peoples[i] = 2;
					}
				}
			} else {
				for (int i = 0; i < opinions.Length; i++) {
					if (opinions[i] > 0 && impossibleMurders[opinions[i] - 1])
						peoples[i] = 1;
					if (opinions[i] < 0 && impossibleMurders[-opinions[i] - 1])
						peoples[i] = 2;
				}
			}

			var answrs = new string[]{"Not defined", "Lie", "Truth" };
			Array.ForEach(peoples, i => Console.WriteLine(answrs[i]));

#if DEBUG
			Console.ReadKey();
#endif

		}
	}
}

[{'input': '1 1\r\n+1\r\n', 'output': ['Truth\r\n']}, {'input': '3 2\r\n-1\r\n-2\r\n-3\r\n', 'output': ['Not defined\r\nNot defined\r\nNot defined\r\n']}, {'input': '4 1\r\n+2\r\n-3\r\n+4\r\n-1\r\n', 'output': ['Lie\r\nNot defined\r\nLie\r\nNot defined\r\n']}, {'input': '1 0\r\n-1\r\n', 'output': ['Lie\r\n']}, {'input': '2 2\r\n+1\r\n+1\r\n', 'output': ['Truth\r\nTruth\r\n']}, {'input': '2 1\r\n+2\r\n+1\r\n', 'output': ['Not defined\r\nNot defined\r\n']}, {'input': '2 0\r\n-2\r\n-2\r\n', 'output': ['Lie\r\nLie\r\n']}, {'input': '3 1\r\n+2\r\n+3\r\n+3\r\n', 'output': ['Truth\r\nLie\r\nLie\r\n']}, {'input': '6 3\r\n+5\r\n+5\r\n+5\r\n+1\r\n+1\r\n+1\r\n', 'output': ['Not defined\r\nNot defined\r\nNot defined\r\nNot defined\r\nNot defined\r\nNot defined\r\n']}, {'input': '4 3\r\n-4\r\n-3\r\n-1\r\n-3\r\n', 'output': ['Not defined\r\nTruth\r\nNot defined\r\nTruth\r\n']}, {'input': '10 4\r\n-8\r\n+1\r\n-6\r\n-10\r\n+5\r\n-6\r\n-8\r\n-8\r\n-4\r\n-8\r\n', 'output': ['Lie\r\nLie\r\nTruth\r\nTruth\r\nLie\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nLie\r\n']}, {'input': '10 5\r\n-4\r\n+4\r\n+4\r\n-9\r\n-9\r\n-4\r\n-4\r\n+2\r\n-9\r\n-4\r\n', 'output': ['Lie\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nLie\r\nTruth\r\nLie\r\n']}, {'input': '7 2\r\n+5\r\n+5\r\n+5\r\n-2\r\n+1\r\n-5\r\n-6\r\n', 'output': ['Lie\r\nLie\r\nLie\r\nNot defined\r\nLie\r\nTruth\r\nNot defined\r\n']}, {'input': '7 4\r\n+7\r\n-3\r\n-3\r\n-4\r\n+3\r\n+3\r\n+3\r\n', 'output': ['Not defined\r\nNot defined\r\nNot defined\r\nTruth\r\nNot defined\r\nNot defined\r\nNot defined\r\n']}, {'input': '6 3\r\n-6\r\n-1\r\n+5\r\n+1\r\n+6\r\n+1\r\n', 'output': ['Truth\r\nNot defined\r\nNot defined\r\nNot defined\r\nLie\r\nNot defined\r\n']}, {'input': '5 3\r\n-2\r\n+2\r\n+2\r\n-3\r\n+5\r\n', 'output': ['Not defined\r\nNot defined\r\nNot defined\r\nTruth\r\nNot defined\r\n']}, {'input': '3 0\r\n-2\r\n-2\r\n-2\r\n', 'output': ['Lie\r\nLie\r\nLie\r\n']}, {'input': '5 3\r\n-1\r\n-1\r\n-4\r\n+1\r\n-4\r\n', 'output': ['Lie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\n']}, {'input': '9 6\r\n+2\r\n+7\r\n+7\r\n-1\r\n-4\r\n+7\r\n-7\r\n+7\r\n+5\r\n', 'output': ['Lie\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nTruth\r\nLie\r\n']}, {'input': '43 18\r\n-14\r\n-28\r\n+16\r\n+10\r\n+25\r\n-30\r\n+25\r\n+30\r\n+25\r\n+25\r\n+25\r\n+25\r\n-25\r\n+22\r\n+3\r\n-17\r\n+16\r\n-25\r\n+10\r\n+14\r\n+41\r\n+25\r\n-25\r\n+33\r\n+24\r\n-23\r\n-25\r\n+25\r\n-22\r\n+29\r\n+28\r\n-25\r\n-25\r\n-29\r\n+11\r\n+26\r\n-25\r\n+25\r\n+10\r\n+1\r\n-20\r\n-17\r\n+23\r\n', 'output': ['Truth\r\nTruth\r\nNot defined\r\nLie\r\nNot defined\r\nTruth\r\nNot defined\r\nLie\r\nNot defined\r\nNot defined\r\nNot defined\r\nNot defined\r\nNot defined\r\nLie\r\nLie\r\nTruth\r\nNot defined\r\nNot defined\r\nLie\r\nLie\r\nLie\r\nNot defined\r\nNot defined\r\nLie\r\nLie\r\nTruth\r\nNot defined\r\nNot defined\r\nTruth\r\nLie\r\nLie\r\nNot defined\r\nNot defined\r\nTruth\r\nLie\r\nLie\r\nNot defined\r\nNot defined\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nLie\r\n']}, {'input': '28 12\r\n+10\r\n-7\r\n+17\r\n-20\r\n+7\r\n-7\r\n+13\r\n-21\r\n-7\r\n-7\r\n-18\r\n+7\r\n+7\r\n+3\r\n+6\r\n+14\r\n+7\r\n-24\r\n-21\r\n-7\r\n-7\r\n+4\r\n+7\r\n-7\r\n+21\r\n-7\r\n-26\r\n+7\r\n', 'output': ['Lie\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nLie\r\nTruth\r\nLie\r\nLie\r\nLie\r\nTruth\r\nTruth\r\n']}, {'input': '17 9\r\n-6\r\n+16\r\n+5\r\n+16\r\n-17\r\n+17\r\n-11\r\n+5\r\n+14\r\n+5\r\n-8\r\n-5\r\n+6\r\n-2\r\n-11\r\n+4\r\n+17\r\n', 'output': ['Truth\r\nNot defined\r\nNot defined\r\nNot defined\r\nTruth\r\nLie\r\nTruth\r\nNot defined\r\nLie\r\nNot defined\r\nTruth\r\nNot defined\r\nLie\r\nTruth\r\nTruth\r\nLie\r\nLie\r\n']}, {'input': '14 3\r\n+14\r\n+12\r\n-9\r\n+9\r\n-9\r\n-9\r\n+8\r\n+9\r\n+2\r\n+1\r\n-13\r\n-9\r\n+13\r\n+3\r\n', 'output': ['Lie\r\nLie\r\nLie\r\nTruth\r\nLie\r\nLie\r\nLie\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nLie\r\nLie\r\nLie\r\n']}, {'input': '10 4\r\n-9\r\n-8\r\n-5\r\n-9\r\n-7\r\n-9\r\n-9\r\n-9\r\n-4\r\n-9\r\n', 'output': ['Lie\r\nTruth\r\nTruth\r\nLie\r\nTruth\r\nLie\r\nLie\r\nLie\r\nTruth\r\nLie\r\n']}, {'input': '10 5\r\n-10\r\n-10\r\n-10\r\n-5\r\n-1\r\n+10\r\n-3\r\n-10\r\n-9\r\n-10\r\n', 'output': ['Lie\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nTruth\r\nLie\r\n']}, {'input': '10 4\r\n-3\r\n-3\r\n-3\r\n-3\r\n-3\r\n-2\r\n-2\r\n-6\r\n-7\r\n-3\r\n', 'output': ['Lie\r\nLie\r\nLie\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\n']}, {'input': '10 6\r\n-9\r\n-7\r\n-5\r\n-5\r\n-4\r\n-2\r\n-8\r\n-5\r\n-5\r\n-9\r\n', 'output': ['Truth\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nTruth\r\n']}, {'input': '10 4\r\n-8\r\n-2\r\n-8\r\n+1\r\n-4\r\n-8\r\n-2\r\n-8\r\n-8\r\n-1\r\n', 'output': ['Lie\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nLie\r\nTruth\r\nLie\r\nLie\r\nTruth\r\n']}, {'input': '10 2\r\n-8\r\n+10\r\n+1\r\n+8\r\n+4\r\n+8\r\n+6\r\n-8\r\n+10\r\n+1\r\n', 'output': ['Not defined\r\nLie\r\nLie\r\nNot defined\r\nLie\r\nNot defined\r\nLie\r\nNot defined\r\nLie\r\nLie\r\n']}, {'input': '10 3\r\n+9\r\n+3\r\n+8\r\n+3\r\n+6\r\n-3\r\n+6\r\n+8\r\n+3\r\n+7\r\n', 'output': ['Lie\r\nNot defined\r\nNot defined\r\nNot defined\r\nNot defined\r\nNot defined\r\nNot defined\r\nNot defined\r\nNot defined\r\nLie\r\n']}, {'input': '10 8\r\n-2\r\n+9\r\n+9\r\n-4\r\n+9\r\n+9\r\n+4\r\n-9\r\n-3\r\n+9\r\n', 'output': ['Truth\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nTruth\r\n']}, {'input': '10 7\r\n-4\r\n+6\r\n+4\r\n+9\r\n+6\r\n+6\r\n+6\r\n+6\r\n+6\r\n+2\r\n', 'output': ['Truth\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\n']}, {'input': '10 4\r\n+3\r\n+5\r\n+6\r\n+10\r\n+5\r\n+5\r\n+6\r\n+8\r\n+5\r\n+6\r\n', 'output': ['Lie\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nLie\r\n']}, {'input': '10 7\r\n-6\r\n-10\r\n-3\r\n-1\r\n-3\r\n-7\r\n-2\r\n-7\r\n-7\r\n-3\r\n', 'output': ['Truth\r\nTruth\r\nNot defined\r\nTruth\r\nNot defined\r\nNot defined\r\nTruth\r\nNot defined\r\nNot defined\r\nNot defined\r\n']}, {'input': '10 5\r\n-4\r\n-4\r\n-1\r\n-5\r\n-7\r\n-4\r\n-4\r\n-4\r\n-1\r\n-7\r\n', 'output': ['Lie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nLie\r\nTruth\r\nTruth\r\n']}, {'input': '10 5\r\n-9\r\n-7\r\n-6\r\n-3\r\n-10\r\n-10\r\n-10\r\n-10\r\n-10\r\n-2\r\n', 'output': ['Truth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nLie\r\nLie\r\nLie\r\nTruth\r\n']}, {'input': '10 3\r\n-10\r\n-10\r\n-10\r\n-3\r\n-10\r\n-10\r\n-10\r\n-8\r\n-4\r\n-10\r\n', 'output': ['Lie\r\nLie\r\nLie\r\nTruth\r\nLie\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nLie\r\n']}, {'input': '10 5\r\n-8\r\n-8\r\n-4\r\n-9\r\n-10\r\n-2\r\n-9\r\n-8\r\n-8\r\n-8\r\n', 'output': ['Lie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nLie\r\n']}, {'input': '10 5\r\n+7\r\n+8\r\n+9\r\n+1\r\n+7\r\n+7\r\n+7\r\n+6\r\n+6\r\n+7\r\n', 'output': ['Truth\r\nLie\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nTruth\r\n']}, {'input': '10 5\r\n+2\r\n+2\r\n+2\r\n+2\r\n+9\r\n+10\r\n+8\r\n+7\r\n+4\r\n+2\r\n', 'output': ['Truth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nLie\r\nLie\r\nLie\r\nTruth\r\n']}, {'input': '10 9\r\n+7\r\n+7\r\n+7\r\n+7\r\n+7\r\n+7\r\n+5\r\n+7\r\n+7\r\n+7\r\n', 'output': ['Truth\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\n']}, {'input': '10 3\r\n+10\r\n+2\r\n+10\r\n+9\r\n+1\r\n+9\r\n+4\r\n+9\r\n+3\r\n+2\r\n', 'output': ['Lie\r\nLie\r\nLie\r\nTruth\r\nLie\r\nTruth\r\nLie\r\nTruth\r\nLie\r\nLie\r\n']}, {'input': '10 6\r\n+10\r\n+10\r\n+10\r\n+3\r\n+10\r\n+10\r\n+6\r\n+6\r\n+10\r\n+8\r\n', 'output': ['Truth\r\nTruth\r\nTruth\r\nLie\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nLie\r\n']}, {'input': '3 2\r\n-1\r\n+2\r\n+3\r\n', 'output': ['Truth\r\nNot defined\r\nNot defined\r\n']}]


using System;
using System.Text;

class Fffuuuu {

    Char[] last;

    Int32 Have(Int32 dig, Int32 delta, Int32[] stat) {
        Int32 have = 0;
        if (dig - delta >= 0) {
            have += stat[dig - delta];
        }
        if (dig + delta < 10) {
            have += stat[dig + delta];
        }
        return have;
    }

    Int32 Pick(String str, Int32 dig, Int32[] stat, Int32 toChange) {
        Int32[] accDist = new Int32[10];
        toChange -= stat[dig];
        for (Int32 pick, dist = 1; toChange != 0; ++dist) {
            if (dig - dist >= 0) {
                pick = Math.Min(toChange, stat[dig - dist]);
                accDist[dist] += pick;
                toChange -= pick;
            }
            if (dig + dist < 10) {
                pick = Math.Min(toChange, stat[dig + dist]);
                accDist[dist] += pick;
                toChange -= pick;
            }
        }

        Int32 score = 0;
        for (Int32 delta, cur, i = 0; i < str.Length; ++i) {
            cur = str[i] & 0xf;
            delta = Math.Abs(cur - dig);
            if (accDist[delta] != 0) {
                if (cur > dig || accDist[delta] == Have(dig, delta, stat)) {
                    score += delta;
                    --accDist[delta];
                    --stat[cur];
                    cur = dig;
                } else {
                    --stat[cur];
                }
            }
            last[i] = (Char) (cur | 0x30);
        }

        return score;
    }

    public Fffuuuu() {
        Int32 toChange = Int32.Parse(Console.ReadLine().Split(' ')[1]);
        String str = Console.ReadLine();
        Int32[] stat = new Int32[10];
        for (Int32 i = 0; i < str.Length; ++stat[str[i++] & 0xf]) { }

        Int32 best = -1;
        String bestString = String.Empty;
        last = new Char[str.Length];
        for (Int32 one, dig = 0; dig < 10; ++dig) {
            one = Pick(str, dig, (Int32[]) stat.Clone(), toChange);
            if (best < 0 || best > one || (best == one && (new String(last).CompareTo(bestString) < 0))) {
                best = one;
                bestString = new String(last);
            }
        }
        Console.WriteLine(best);
        Console.WriteLine(bestString);
    }

    static void Main() {
#if DEBUG
        Console.SetIn(new System.IO.StreamReader("in.txt"));
#endif
        new Fffuuuu();
    }

}

A car number in Berland consists of exactly n digits. A number is called beautiful if it has at least k equal digits. Vasya wants to change the digits in his car's number so that the number became beautiful. To replace one of n digits Vasya has to pay the sum of money, equal to the absolute difference between the old digit and the new one.Help Vasya: find the minimum sum of money he should pay to make the number of his car beautiful. You should also find the resulting beautiful number. If there are several such numbers, then print the lexicographically minimum one.

The first line contains two space-separated integers n and k (2 ≤ n ≤ 104, 2 ≤ k ≤ n) which represent how many digits the number has and how many equal digits a beautiful number should have. The second line consists of n digits. It describes the old number of Vasya's car. It is guaranteed that the number contains no spaces and only contains digits.

On the first line print the minimum sum of money Vasya needs to change the number. On the second line print the car's new number. If there are several solutions, print the lexicographically minimum one.

NoteIn the first sample replacing the second digit with an "8" costs |9 - 8| = 1. Replacing the fifth digit with an "8" costs the same. Replacing the sixth digit costs |6 - 8| = 2. As a result, Vasya will pay 1 + 1 + 2 = 4 for a beautiful number "888188".The lexicographical comparison of strings is performed by the < operator in modern programming languages. The string x is lexicographically smaller than the string y, if there exists such i (1 ≤ i ≤ n), that xi < yi, and for any j (1 ≤ j < i) xj = yj. The strings compared in this problem will always have the length n.

using System;
using System.Text;

class Fffuuuu {

    Char[] last;

    Int32 Have(Int32 dig, Int32 delta, Int32[] stat) {
        Int32 have = 0;
        if (dig - delta >= 0) {
            have += stat[dig - delta];
        }
        if (dig + delta < 10) {
            have += stat[dig + delta];
        }
        return have;
    }

    Int32 Pick(String str, Int32 dig, Int32[] stat, Int32 toChange) {
        Int32[] accDist = new Int32[10];
        toChange -= stat[dig];
        for (Int32 pick, dist = 1; toChange > 0; ++dist) {
            if (dig - dist >= 0) {
                pick = Math.Min(toChange, stat[dig - dist]);
                accDist[dist] += pick;
                toChange -= pick;
            }
            if (dig + dist < 10) {
                pick = Math.Min(toChange, stat[dig + dist]);
                accDist[dist] += pick;
                toChange -= pick;
            }
        }

        Int32 score = 0;
        for (Int32 delta, cur, i = 0; i < str.Length; ++i) {
            cur = str[i] & 0xf;
            delta = Math.Abs(cur - dig);
            if (accDist[delta] != 0) {
                if (cur > dig || accDist[delta] == Have(dig, delta, stat)) {
                    score += delta;
                    --accDist[delta];
                    --stat[cur];
                    cur = dig;
                } else {
                    --stat[cur];
                }
            }
            last[i] = (Char) (cur | 0x30);
        }

        return score;
    }

    public Fffuuuu() {
        Int32 toChange = Int32.Parse(Console.ReadLine().Split(' ')[1]);
        String str = Console.ReadLine();
        Int32[] stat = new Int32[10];
        for (Int32 i = 0; i < str.Length; ++stat[str[i++] & 0xf]) { }

        Int32 best = -1;
        String bestString = String.Empty;
        last = new Char[str.Length];
        for (Int32 one, dig = 0; dig < 10; ++dig) {
            one = Pick(str, dig, (Int32[]) stat.Clone(), toChange);
            if (best < 0 || best > one || (best == one && (new String(last).CompareTo(bestString) < 0))) {
                best = one;
                bestString = new String(last);
            }
        }
        Console.WriteLine(best);
        Console.WriteLine(bestString);
    }

    static void Main() {
#if DEBUG
        Console.SetIn(new System.IO.StreamReader("in.txt"));
#endif
        new Fffuuuu();
    }

}


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

namespace B
{
    class bus
    {
        public int s, t;
    }

    class Program
    {
        const int mod = 1000000007;
        static int n, m;
        static bus[] buses;
        static Dictionary<int, int> mem = new Dictionary<int,int>();
        static int [] dp;
        static int t;

        static int countfrom(int p, int b)
        {
            if (p == t)
                return 1;

            if (dp[p] != -1)
                return dp[p];

            int ways = 0;
            for (int i = b + 1; i < m; i++)
            {
                if (p >= buses[i].s && p < buses[i].t)
                {
                    ways += countfrom(buses[i].t, i);
                    ways %= mod;
                }
            }

            dp[p] = ways;
            return ways;
        }

        static void Main(string[] args)
        {
            string[] line = Console.ReadLine().Split();
            n = int.Parse(line[0]);
            m = int.Parse(line[1]);

            buses = new bus[m];
            for (int i = 0; i < m; i++)
            {
                buses[i] = new bus();
                line = Console.ReadLine().Split();
                buses[i].s = int.Parse(line[0]);
                buses[i].t = int.Parse(line[1]);
            }

            SortedDictionary<int, int> distinct = new SortedDictionary<int, int>();
            distinct[0] = 0;
            distinct[n] = 0;

            for (int i = 0; i < buses.Length; i++)
            {
                distinct[buses[i].s] = 0;
                distinct[buses[i].t] = 0;
            }

            List<int> keys = distinct.Keys.ToList();
            keys.Sort();

            int curr = 0;
            for (int i = 0; i < keys.Count; i++)
                distinct[keys[i]] = curr++;

            for (int i = 0; i < buses.Length; i++)
            {
                buses[i].s = distinct[buses[i].s];
                buses[i].t = distinct[buses[i].t];
            }

            t = distinct[n];

            dp = new int[t + 1];
            for (int i = 0; i < dp.Length; i++)
                dp[i] = -1;

            Array.Sort(buses, (x, y) => x.t.CompareTo(y.t));
            Console.WriteLine(countfrom(0, -1));
        }
    }
}

Little boy Gerald studies at school which is quite far from his house. That's why he has to go there by bus every day. The way from home to school is represented by a segment of a straight line; the segment contains exactly n + 1 bus stops. All of them are numbered with integers from 0 to n in the order in which they follow from Gerald's home. The bus stop by Gerald's home has number 0 and the bus stop by the school has number n.There are m buses running between the house and the school: the i-th bus goes from stop si to ti (si < ti), visiting all the intermediate stops in the order in which they follow on the segment. Besides, Gerald's no idiot and he wouldn't get off the bus until it is still possible to ride on it closer to the school (obviously, getting off would be completely pointless). In other words, Gerald can get on the i-th bus on any stop numbered from si to ti - 1 inclusive, but he can get off the i-th bus only on the bus stop ti.Gerald can't walk between the bus stops and he also can't move in the direction from the school to the house.Gerald wants to know how many ways he has to get from home to school. Tell him this number. Two ways are considered different if Gerald crosses some segment between the stops on different buses. As the number of ways can be too much, find the remainder of a division of this number by 1000000007 (109 + 7).

The first line contains two space-separated integers: n and m (1 ≤ n ≤ 109, 0 ≤ m ≤ 105). Then follow m lines each containing two integers si, ti. They are the numbers of starting stops and end stops of the buses (0 ≤ si < ti ≤ n).

Print the only number — the number of ways to get to the school modulo 1000000007 (109 + 7).

NoteThe first test has the only variant to get to school: first on bus number one to the bus stop number one; then on bus number two to the bus stop number two.In the second test no bus goes to the third bus stop, where the school is positioned. Thus, the correct answer is 0.In the third test Gerald can either get or not on any of the first four buses to get closer to the school. Thus, the correct answer is 24 = 16.

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

namespace Codeforces
{
#if _ONLINE_JUDGE_
	[OnlineJudge.Task("Codeforces 101B")]
#endif
	class Task101B
	{
		private InputTokenizer input = new InputTokenizer();
		private TextWriter output = Console.Out;

		class FenwickTree
		{
			private long[] _data;
			private int _size;

			public FenwickTree(int size)
			{
				_size = size;
				_data = new long[_size];
			}

			public FenwickTree(IEnumerable<long> values)
			{
				_size = values.Count();
				_data = new long[_size];

				int i = 0;
				foreach (long x in values) Increment(i++, x);
			}

			public long Sum(int high)
			{
				if (high < 0) return 0;
				long answer = 0;
				for (; high >= 0; high = (high & (high + 1)) - 1)
					answer += _data[high];
				return answer;
			}

			public long Sum(int low, int high)
			{
				return Sum(high) - Sum(low - 1);
			}

			public void Increment(int index, long increment)
			{
				for (; index < _size; index |= index + 1)
					_data[index] += increment;
			}
		}

		struct T
		{
			public int a, b;
		}

		private void Solve()
		{
			int n, m;

			input.Line().Read(out n).Read(out m);

			var f = new SortedDictionary<int, int>();

			var tmp = new T[m];
			for (int i = 0; i < m; ++i)
			{
				input.Line().Read(out tmp[i].a).Read(out tmp[i].b);
				f[tmp[i].a] = 0;
				f[tmp[i].b] = 0;
			}

			f[0] = 0;
			f[n] = 0;

			var keys = f.Keys.ToArray();
			int g = 0;
			for (int i = 0; i < keys.Length; ++g) {
				f[keys[i]] = g;
				++i;
				while (i < keys.Length && keys[i - 1] == keys[i]) ++i;
			}

			Array.Sort(tmp, (l, r) => l.b - r.b);

			var ft = new FenwickTree(g);

			ft.Increment(0, 1);
			for (int i = 0; i < m; ++i)
			{
				ft.Increment(f[tmp[i].b], ft.Sum(f[tmp[i].a], f[tmp[i].b] - 1) % 1000000007);
			}

			output.WriteLine(ft.Sum(f[n], f[n]) % 1000000007);
		}

		public static void Main()
		{
			var obj = new Task101B();
			obj.Solve();
		}

		#region
		private class InputTokenizer
		{
			private List<string> _tokens = new List<string>();
			private int _offset = 0;

			public InputTokenizer()
			{
			}

			public InputTokenizer String(String s)
			{
				_tokens.AddRange(s.Split(new char[] { ' ', '\n', '\t', '\r' }, StringSplitOptions.RemoveEmptyEntries));
				return this;
			}

			public InputTokenizer Line()
			{
				return String(Console.In.ReadLine());
			}

			public InputTokenizer Read(out int v)
			{
				v = int.Parse(_tokens[_offset++]);
				return this;
			}

			public InputTokenizer Read(int n, out int[] v)
			{
				v = new int[n];
				for (int i = 0; i < n; ++i) Read(out v[i]);
				return this;
			}

			public InputTokenizer Read(out long v)
			{
				v = long.Parse(_tokens[_offset++]);
				return this;
			}

			public InputTokenizer Read(int n, out long[] v)
			{
				v = new long[n];
				for (int i = 0; i < n; ++i) Read(out v[i]);
				return this;
			}

			public InputTokenizer Read(out ulong v)
			{
				v = ulong.Parse(_tokens[_offset++]);
				return this;
			}

			public InputTokenizer Read(int n, out ulong[] v)
			{
				v = new ulong[n];
				for (int i = 0; i < n; ++i) Read(out v[i]);
				return this;
			}

			public InputTokenizer Read(out double v)
			{
				v = double.Parse(_tokens[_offset++]);
				return this;
			}

			public InputTokenizer Read(int n, out double[] v)
			{
				v = new double[n];
				for (int i = 0; i < n; ++i) Read(out v[i]);
				return this;
			}

			public InputTokenizer Read(out string v)
			{
				v = _tokens[_offset++];
				return this;
			}

			public InputTokenizer Read(int n, out string[] v)
			{
				v = new string[n];
				for (int i = 0; i < n; ++i) Read(out v[i]);
				return this;
			}
		}
		#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 b11d
{
    class Program
    {
        static string _inputFilename = "input.txt";
        static string _outputFilename = "output.txt";
        static bool _useFileInput = false;

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

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

        static void solution()
        {
            #region SOLUTION
            var d = readIntArray();
            var n = d[0];
            var m = d[1];
            var g = new List<int>[n];
            for (int i = 0; i < n; i++)
            {
                g[i] = new List<int>();
            }

            for (int i = 0; i < m; i++)
            {
                d = readIntArray();
                var from = d[0] - 1;
                var to = d[1] - 1;
                g[from].Add(to);
                g[to].Add(from);
            }

            var max = 0;
            for (int i = 0; i < n; i++)
            {
                max |= 1 << i;
            }

            var dp = new int[max + 1, n + 1];
            for (int i = 0; i < max + 1; i++)
            {
                for (int j = 0; j < n + 1; j++)
                {
                    dp[i, j] = 0;
                }
            }

            for (int i = 0; i < n; i++)
            {
                var mask = 1 << i;
                dp[mask, i] = 1;
            }

            for (int i = 1; i < max + 1; i++)
            {
                var f = true;
                for (int j = n - 1; j >= 0; j--)
                {
                    var val = (i & (1 << j)) != 0;
                    if (!val)
                    {
                        continue;
                    }

                    if (f)
                    {
                        f = false;
                        continue;
                    }

                    var msk = 1 << j;
                    var wth = i ^ msk;
                    var ps = g[j];
                    foreach (var p in ps)
                    {
                        if ((wth & (1 << p)) != 0)
                        {
                            var val1 = dp[wth, p];
                            dp[i, j] += val1;
                            //if (val1 != -1)
                            //{
                            //    if (dp[i, j] == -1)
                            //    {
                            //        dp[i, j] = 0;
                            //    }

                            //}
                        }
                    }
                }
            }

            var tc = 0;
            for (int i = 1; i < max + 1; i++)
            {
                var count = 0;
                var first = -1;
                for (int j = n - 1; j >= 0; j--)
                {
                    if ((i & (1 << j)) != 0)
                    {
                        count++;
                        if (first == -1)
                        {
                            first = j;
                        }
                    }
                }

                if (count < 3)
                {
                    continue;
                }

                var gs = g[first];
                for (int j = n - 1; j >= 0; j--)
                {
                    if ((i & (1 << j)) == 0)
                    {
                        continue;
                    }

                    if (j == first)
                    {
                        continue;
                    }

                    foreach (var ps in gs)
                    {
                        if (ps == j)
                        {
                            //if (dp[i, j] == -1)
                            //{
                            //    throw new InvalidOperationException();
                            //}

                            tc += dp[i, j];
                        }
                    }
                }
            }

            Console.WriteLine(tc / 2);

            //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
    }
}

Given a simple graph, output the number of simple cycles in it. A simple cycle is a cycle with no repeated vertices or edges.

The first line of input contains two integers n and m (1 ≤ n ≤ 19, 0 ≤ m) – respectively the number of vertices and edges of the graph. Each of the subsequent m lines contains two integers a and b, (1 ≤ a, b ≤ n, a ≠ b) indicating that vertices a and b are connected by an undirected edge. There is no more than one edge connecting any pair of vertices.

Output the number of cycles in the given graph.

NoteThe example graph is a clique and contains four cycles of length 3 and three cycles of length 4.

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

class Program
{

    void solve()
    {
        int n = nextInt();
        bool[,] g = new bool[n, n];
        int m = nextInt();
        for (int i = 0; i < m; i++)
        {
            int a = nextInt();
            int b = nextInt();
            a--;
            b--;
            g[a, b] = g[b, a] = true;

        }
        long ret = 0;
        for (int f = 0; f < n; f++)
        {
            long[,] dp = new long[f, 1 <<f];
            for(int i=0;i<f;i++)
                if(g[f,i])
                    dp[i,1<<i]=1;
            for (int set = 1; set < (1 <<f); set++)
                for (int i = 0; i < f; i++)
                    if ((set & (1 << i)) > 0)
                        for (int j = 0; j < f; j++)
                            if ((set & (1 << j)) > 0 && g[i, j])
                                dp[i, set] += dp[j, set ^ (1 << i)];
            for(int i=0;i<f;i++)
                if(g[f,i])
                    for(int set=1;set<(1<<f);set++)
                        if ((set & (1 << i)) > 0 && (set!=1<<i))
                        {
                            long num = dp[i, set];
                            ret += num;
                        }

        }
        Console.WriteLine(ret / 2);

    }

    //

    string[] inputLine = new string[0];
    int inputInd = 0;
    string nextLine()
    {
        return Console.ReadLine();
    }
    void readInput()
    {
        if (inputInd != inputLine.Length)
            throw new Exception();
        inputInd = 0;
        inputLine = Console.ReadLine().Split();

    }
    int nextInt()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return int.Parse(inputLine[inputInd++]);
    }
    long nextLong()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return long.Parse(inputLine[inputInd++]);
    }
    double nextDouble()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return double.Parse(inputLine[inputInd++]);
    }
    string nextString()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return inputLine[inputInd++];
    }
    static void Main(string[] args)
    {
        new Program().solve();
    }
}


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

class Program
{
    long[] a;
    long[,] dp;
    int maxn = 100000;
    void solve()
    {
        //test();
        long n = nextLong();
        a = new long[nextInt()];
        for (int i = 0; i < a.Length; i++)
            a[i] = nextLong();
        long res = n - doIt(n);
        println(res);

    }
    long doIt(long n)
    {
        Array.Sort(a);
        Array.Reverse(a);
        bool ok = true;
        for (int i = 0; i < a.Length; i++)
        {
            if (a[i] == 1)
                ok = false;
        }
        if (!ok)
        {
            return 0;
        }
        dp = new long[100, maxn];
        for (int i = 0; i < 100; i++)
            for (int j = 0; j < maxn; j++)
                dp[i, j] = -1;
        return go(n, 0);
    }
    private void test()
    {
        long n = 10000000000000;
        int k = 100;
        a = new long[k];
        int cur = 2;
        for (int i = 0; i < k; i++)
        {
            while (!prime(cur))
                cur++;
            a[i] = cur++;
        }
        println(doIt(n));
    }

    private bool prime(int p)
    {
        for (int i = 2; i * i <= p; i++)
            if (p % i == 0)
                return false;
        return true;
    }

    private long go(long n, int at)
    {
        if (at == a.Length)
            return 0;
        if (n == 0)
            return 0;
        if (n < maxn)
        {
            if (dp[at, n] != -1)
                return dp[at, n];
        }
        long res = go(n, at + 1);
        res += n / a[at];
        res -= go(n / a[at], at + 1);
        if (n < maxn)
        {
            return dp[at, n] = res;
        }
        return res;
    }

    ////////////
    private void println(int[] ar)
    {
        for (int i = 0; i < ar.Length; i++)
        {
            if (i == ar.Length - 1)
                println(ar[i]);
            else
                print(ar[i] + " ");
        }
    }
    private void println(int[] ar, bool add)
    {
        int A = 0;
        if (add)
            A++;
        for (int i = 0; i < ar.Length; i++)
        {
            if (i == ar.Length - 1)
                println(ar[i] + A);
            else
                print((ar[i] + A) + " ");
        }
    }

    private void println(string Stringst)
    {
        Console.WriteLine(Stringst);
    }
    private void println(char charnum)
    {
        Console.WriteLine(charnum);
    }
    private void println(int Intnum)
    {
        Console.WriteLine(Intnum);
    }
    private void println(long Longnum)
    {
        Console.WriteLine(Longnum);
    }
    private void println(double Doublenum)
    {
        string s = Doublenum.ToString(CultureInfo.InvariantCulture);
        Console.WriteLine(s);
    }

    private void print(string Stringst)
    {
        Console.Write(Stringst);
    }
    private void print(int Intnum)
    {
        Console.Write(Intnum);
    }
    private void print(char charnum)
    {
        Console.Write(charnum);
    }
    private void print(long Longnum)
    {
        Console.Write(Longnum);
    }
    private void print(double Doublenum)
    {
        Console.Write(Doublenum);
    }

    string[] inputLine = new string[0];
    int inputInd = 0;
    string nextLine()
    {
        return Console.ReadLine();
    }
    void readInput()
    {
        if (inputInd != inputLine.Length)
            throw new Exception();
        inputInd = 0;
        inputLine = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        if (inputLine.Length == 0)
            readInput();

    }
    int nextInt()
    {
        return int.Parse(nextString());
    }
    long nextLong()
    {
        return long.Parse(nextString());
    }
    double nextDouble()
    {
        return double.Parse(nextString());
    }
    string nextString()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return inputLine[inputInd++];
    }
    static void Main(string[] args)
    {
        Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
        new Program().solve();
    }
}

Igor K. very much likes a multiplayer role playing game WineAge II. Who knows, perhaps, that might be the reason for his poor performance at the university. As any person who plays the game, he is interested in equipping his hero with as good weapon and outfit as possible. One day, as he was reading the game's forum yet again, he discovered a very interesting fact. As it turns out, each weapon in the game is characterised with k different numbers: a1, ..., ak. They are called hit indicators and according to the game developers' plan they are pairwise coprime. The damage that is inflicted during a hit depends not only on the weapon's characteristics, but also on the hero's strength parameter. Thus, if the hero's strength equals n, than the inflicted damage will be calculated as the number of numbers on the segment , that aren't divisible by any hit indicator ai.Recently, having fulfilled another quest, Igor K. found a new Lostborn sword. He wants to know how much damage he will inflict upon his enemies if he uses it.

The first line contains two integers: n and k (1 ≤ n ≤ 1013, 1 ≤ k ≤ 100). They are the indicator of Igor K's hero's strength and the number of hit indicators. The next line contains space-separated k integers ai (1 ≤ ai ≤ 1000). They are Lostborn sword's hit indicators. The given k numbers are pairwise coprime.

Print the single number — the damage that will be inflicted by Igor K.'s hero when he uses his new weapon.  Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator.

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

class Program
{
    long[] a;
    long[,] dp;
    int maxn = 100000;
    void solve()
    {
        //test();
        long n = nextLong();
        a = new long[nextInt()];
        for (int i = 0; i < a.Length; i++)
            a[i] = nextLong();
        long res = n - doIt(n);
        println(res);

    }
    long doIt(long n)
    {
        Array.Sort(a);
        Array.Reverse(a);
        dp = new long[100, maxn];
        for (int i = 0; i < 100; i++)
            for (int j = 0; j < maxn; j++)
                dp[i, j] = -1;
        return go(n, 0);
    }
    private void test()
    {
        long n = 10000000000000;
        int k = 100;
        a = new long[k];
        int cur = 2;
        for (int i = 0; i < k; i++)
        {
            while (!prime(cur))
                cur++;
            a[i] = cur++;
        }
        println(doIt(n));
    }

    private bool prime(int p)
    {
        for (int i = 2; i * i <= p; i++)
            if (p % i == 0)
                return false;
        return true;
    }

    private long go(long n, int at)
    {
        if (at == a.Length)
            return 0;
        if (n == 0)
            return 0;
        if (n < maxn)
        {
            if (dp[at, n] != -1)
                return dp[at, n];
        }
        long res = go(n, at + 1);
        res += n / a[at];
        res -= go(n / a[at], at + 1);
        if (n < maxn)
        {
            return dp[at, n] = res;
        }
        return res;
    }

    ////////////
    private void println(int[] ar)
    {
        for (int i = 0; i < ar.Length; i++)
        {
            if (i == ar.Length - 1)
                println(ar[i]);
            else
                print(ar[i] + " ");
        }
    }
    private void println(int[] ar, bool add)
    {
        int A = 0;
        if (add)
            A++;
        for (int i = 0; i < ar.Length; i++)
        {
            if (i == ar.Length - 1)
                println(ar[i] + A);
            else
                print((ar[i] + A) + " ");
        }
    }

    private void println(string Stringst)
    {
        Console.WriteLine(Stringst);
    }
    private void println(char charnum)
    {
        Console.WriteLine(charnum);
    }
    private void println(int Intnum)
    {
        Console.WriteLine(Intnum);
    }
    private void println(long Longnum)
    {
        Console.WriteLine(Longnum);
    }
    private void println(double Doublenum)
    {
        string s = Doublenum.ToString(CultureInfo.InvariantCulture);
        Console.WriteLine(s);
    }

    private void print(string Stringst)
    {
        Console.Write(Stringst);
    }
    private void print(int Intnum)
    {
        Console.Write(Intnum);
    }
    private void print(char charnum)
    {
        Console.Write(charnum);
    }
    private void print(long Longnum)
    {
        Console.Write(Longnum);
    }
    private void print(double Doublenum)
    {
        Console.Write(Doublenum);
    }

    string[] inputLine = new string[0];
    int inputInd = 0;
    string nextLine()
    {
        return Console.ReadLine();
    }
    void readInput()
    {
        if (inputInd != inputLine.Length)
            throw new Exception();
        inputInd = 0;
        inputLine = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        if (inputLine.Length == 0)
            readInput();

    }
    int nextInt()
    {
        return int.Parse(nextString());
    }
    long nextLong()
    {
        return long.Parse(nextString());
    }
    double nextDouble()
    {
        return double.Parse(nextString());
    }
    string nextString()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return inputLine[inputInd++];
    }
    static void Main(string[] args)
    {
        Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
        new Program().solve();
    }
}