Eudokimus, a system administrator is in trouble again. As a result of an error in some script, a list of names of very important files has been damaged. Since they were files in the BerFS file system, it is known that each file name has a form "name.ext", where:   name is a string consisting of lowercase Latin letters, its length is from 1 to 8 characters;  ext is a string consisting of lowercase Latin letters, its length is from 1 to 3 characters. For example, "read.me", "example.txt" and "b.cpp" are valid file names and "version.info", "ntldr" and "contestdata.zip" are not.Damage to the list meant that all the file names were recorded one after another, without any separators. So now Eudokimus has a single string.Eudokimus needs to set everything right as soon as possible. He should divide the resulting string into parts so that each part would be a valid file name in BerFS. Since Eudokimus has already proved that he is not good at programming, help him. The resulting file list can contain the same file names.

The input data consists of a single string s, its length is from 1 to 4·105 characters. The string can contain only lowercase Latin letters ('a' - 'z') and periods ('.').

In the first line print "YES" (without the quotes), if it is possible to divide s into parts as required. In this case, the following lines should contain the parts of the required partition, one per line in the order in which they appear in s. The required partition can contain the same file names. If there are multiple solutions, print any of them. If the solution does not exist, then print in a single line "NO" (without the quotes).

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().Split('.');
            Boolean Can = true;
            int c = s.Count();
            if (c == 1)
                Can = false;
            if (s[0].Length < 1 || s[0].Length > 8)
                Can = false;
            for (int i = 1; i < c - 1; i++)
            {
                if (s[i].Length < 2 || s[i].Length > 11)
                    Can = false;
            }
            if (s[c - 1].Length > 3 || s[c - 1].Length < 1)
                Can = false;
            if (!Can)
                Console.WriteLine("NO");
            else
            {
                Console.WriteLine("YES");
                Console.Write(s[0] + ".");
                for (int i = 1; i < c - 1; i++)
                {
                    int k = Math.Max(1, s[i].Length - 8);
                    for (int j = 0; j < k; j++)
                    {
                        Console.Write(s[i][j]);
                    }
                    Console.WriteLine();
                    int l = s[i].Length;
                    for (int j = k; j < s[i].Length; j++)
                    {
                        Console.Write(s[i][j]);
                    }
                    Console.Write(".");
                }
                Console.WriteLine(s[c - 1]);
            }
        }
    }
}

[{'input': 'read.meexample.txtb.cpp\r\n', 'output': ['YES\r\nread.m\r\neexample.t\r\nxtb.cpp\r\n']}, {'input': 'version.infontldrcontestdata.zip\r\n', 'output': ['NO\r\n']}, {'input': 'thisis.text.txt\r\n', 'output': ['YES\r\nthisis.t\r\next.txt\r\n']}, {'input': 'oops.t\r\n', 'output': ['YES\r\noops.t\r\n']}, {'input': 'thisislongfilename\r\n', 'output': ['NO\r\n']}, {'input': 'double..dot\r\n', 'output': ['NO\r\n']}, {'input': 'one.one.one.one.one.one.one.one.one.one\r\n', 'output': ['YES\r\none.o\r\nne.o\r\nne.o\r\nne.o\r\nne.o\r\nne.o\r\nne.o\r\nne.o\r\nne.one\r\n']}, {'input': '.\r\n', 'output': ['NO\r\n']}, {'input': 'z\r\n', 'output': ['NO\r\n']}, {'input': 'a.\r\n', 'output': ['NO\r\n']}, {'input': '.a\r\n', 'output': ['NO\r\n']}, {'input': 'za\r\n', 'output': ['NO\r\n']}, {'input': '..\r\n', 'output': ['NO\r\n']}, {'input': 'xlq\r\n', 'output': ['NO\r\n']}, {'input': '.r.\r\n', 'output': ['NO\r\n']}, {'input': 'ulmc\r\n', 'output': ['NO\r\n']}, {'input': 'nja.\r\n', 'output': ['NO\r\n']}, {'input': 't..kz\r\n', 'output': ['NO\r\n']}, {'input': 'twaha\r\n', 'output': ['NO\r\n']}, {'input': 'm..dw.\r\n', 'output': ['NO\r\n']}, {'input': 'utsvfg.\r\n', 'output': ['NO\r\n']}, {'input': '.we.voae\r\n', 'output': ['NO\r\n']}, {'input': 'kw.gkcxk.\r\n', 'output': ['NO\r\n']}, {'input': '.c.v.hpehh\r\n', 'output': ['NO\r\n']}, {'input': 'akymwh\r\n', 'output': ['NO\r\n']}, {'input': 'jx.lqv.\r\n', 'output': ['NO\r\n']}, {'input': 'qkwtq.zw\r\n', 'output': ['YES\r\nqkwtq.zw\r\n']}, {'input': 'yxwvlk..b\r\n', 'output': ['NO\r\n']}, {'input': 'ph..qlr.pt\r\n', 'output': ['NO\r\n']}, {'input': 'cab.ab.bac\r\n', 'output': ['YES\r\ncab.a\r\nb.bac\r\n']}, {'input': 'badaba.ae\r\n', 'output': ['YES\r\nbadaba.ae\r\n']}, {'input': 'badabaca.mor\r\n', 'output': ['YES\r\nbadabaca.mor\r\n']}, {'input': 'bae.a\r\n', 'output': ['YES\r\nbae.a\r\n']}, {'input': 'b.baba.ebpbac.iabaeabac.abab.adabacaba.ahcggibij.adaacab.ebaba.aa.abacaba.dacabada.daqjcpc.jadab.dab\r\n', 'output': ['YES\r\nb.b\r\naba.e\r\nbpbac.i\r\nabaeabac.a\r\nbab.a\r\ndabacaba.a\r\nhcggibij.a\r\ndaacab.e\r\nbaba.a\r\na.a\r\nbacaba.d\r\nacabada.d\r\naqjcpc.j\r\nadab.dab\r\n']}, {'input': '.ab\r\n', 'output': ['NO\r\n']}, {'input': 'aa.aa.aaaabbbbccc.ddd.ee\r\n', 'output': ['YES\r\naa.a\r\na.aaa\r\nabbbbccc.d\r\ndd.ee\r\n']}, {'input': 'a.aaaa\r\n', 'output': ['NO\r\n']}, {'input': 'aaaaread.meexample.txtb.cpp\r\n', 'output': ['YES\r\naaaaread.m\r\neexample.t\r\nxtb.cpp\r\n']}, {'input': 'abcdabcd.a\r\n', 'output': ['YES\r\nabcdabcd.a\r\n']}, {'input': 'qwertyuio.qwe\r\n', 'output': ['NO\r\n']}, {'input': 'asd.\r\n', 'output': ['NO\r\n']}, {'input': 'aaaaaaaa.\r\n', 'output': ['NO\r\n']}, {'input': 'a.txtaaaaaaaaa.txt\r\n', 'output': ['NO\r\n']}, {'input': '.abcde.cpp\r\n', 'output': ['NO\r\n']}, {'input': '.abc.cpp\r\n', 'output': ['NO\r\n']}, {'input': 'abcdefgh.aaaabcdefgh.bbb\r\n', 'output': ['YES\r\nabcdefgh.aaa\r\nabcdefgh.bbb\r\n']}, {'input': 'filename.exe\r\n', 'output': ['YES\r\nfilename.exe\r\n']}, {'input': '.abcd.cpp\r\n', 'output': ['NO\r\n']}, {'input': 'abc.bcdabcdabcd.abc\r\n', 'output': ['YES\r\nabc.bcd\r\nabcdabcd.abc\r\n']}, {'input': 'abc.abcde\r\n', 'output': ['NO\r\n']}, {'input': 'a.cp\r\n', 'output': ['YES\r\na.cp\r\n']}, {'input': 'a.b.c\r\n', 'output': ['NO\r\n']}, {'input': '.ha\r\n', 'output': ['NO\r\n']}, {'input': 'a.a.a.a\r\n', 'output': ['NO\r\n']}, {'input': 'a.a.a\r\n', 'output': ['NO\r\n']}, {'input': 'qwertyui.cp\r\n', 'output': ['YES\r\nqwertyui.cp\r\n']}, {'input': 'ss.aaaaaaaaaaaa.aa\r\n', 'output': ['NO\r\n']}, {'input': 'name.extnamename.ext\r\n', 'output': ['YES\r\nname.ext\r\nnamename.ext\r\n']}, {'input': '.aaaa.aaa\r\n', 'output': ['NO\r\n']}, {'input': 'aaaaaaaaaaaaaaaaaaaa.a\r\n', 'output': ['NO\r\n']}, {'input': '.filena.exe\r\n', 'output': ['NO\r\n']}, {'input': 'a.aaaaaaaaaaa.a\r\n', 'output': ['YES\r\na.aaa\r\naaaaaaaa.a\r\n']}, {'input': '.aa.w\r\n', 'output': ['NO\r\n']}]


A group of n merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the n mugs must be the same.Polycarpus has already began the process and he partially emptied the Ber-Cola bottle. Now the first mug has a1 milliliters of the drink, the second one has a2 milliliters and so on. The bottle has b milliliters left and Polycarpus plans to pour them into the mugs so that the main equation was fulfilled.Write a program that would determine what volume of the drink Polycarpus needs to add into each mug to ensure that the following two conditions were fulfilled simultaneously:   there were b milliliters poured in total. That is, the bottle need to be emptied;  after the process is over, the volumes of the drink in the mugs should be equal.

The first line contains a pair of integers n, b (2 ≤ n ≤ 100, 1 ≤ b ≤ 100), where n is the total number of friends in the group and b is the current volume of drink in the bottle. The second line contains a sequence of integers a1, a2, ..., an (0 ≤ ai ≤ 100), where ai is the current volume of drink in the i-th mug.

Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print n float numbers c1, c2, ..., cn, where ci is the volume of the drink to add in the i-th mug. Print the numbers with no less than 6 digits after the decimal point, print each ci on a single line. Polycarpus proved that if a solution exists then it is unique. Russian locale is installed by default on the testing computer. Make sure that your solution use the point to separate the integer part of a real number from the decimal, not a comma.

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

namespace _2016_08_11_problem_about_equation
{
    class Program
    {
        static void Main(string[] args)
        {
            string nb, a;
            string [] nbArr;
            string[] aArr;
            int summeBottle;
            decimal toDivide;
            bool possible = true;

            nb = Console.ReadLine();
            nbArr = nb.Split(new char [] {' '});
            a = Console.ReadLine();
            aArr = a.Split(new char[] { ' ' });
            summeBottle = int.Parse(nbArr[1]);

            for (int i = 0; i < aArr.Length; i++)
            {
                summeBottle = summeBottle + int.Parse(aArr[i]);
            }

            toDivide = summeBottle / decimal.Parse(nbArr[0]);

            int j = 0;
            while (possible == true && j < aArr.Length)
            {
                if (decimal.Parse(aArr[j]) > toDivide)
                    possible = false;
                j++;
            }

            CultureInfo en = new CultureInfo("en-US", false);

            if (possible == false)
                Console.WriteLine("-1");
            else
                for (int i = 0; i < aArr.Length; i++ )
                {
                    aArr[i] = Convert.ToString(toDivide - decimal.Parse(aArr[i]));
                    Console.WriteLine((String.Format("{0:0.000000}", decimal.Parse(aArr[i]), 6)).Replace(",", "."));

                }

        }
    }
}


Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process.  Help the dwarfs find out how many triangle plants that point "upwards" will be in n years.

The first line contains a single integer n (0 ≤ n ≤ 1018) — the number of full years when the plant grew. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.

Print a single integer — the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7).

NoteThe first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one.

namespace Csharp_Contest
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Globalization;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System.Threading;
/*
 * #import_IntegerMatrix.cs
 */
    static class Program
    {
        private static int mod = (int)(1e9) + 7;

        static void Solve()
        {
            long n = NextLong();
            IntegerMatrix matrix = new IntegerMatrix(2, mod);
            matrix.Reset();
            matrix[0, 0] = 3;
            matrix[0, 1] = 1;
            matrix[1, 0] = 1;
            matrix[1, 1] = 3;
            var ans = matrix ^ n;
            Console.WriteLine(ans[0, 0]);
        }

        public static void Main(string[] args)
        {
#if CLown1331
            for (int testCase = 0; testCase < 3; testCase++)
            {
                Solve();
            }

            Utils.CreateFileForSubmission();
            if (Debugger.IsAttached) Thread.Sleep(Timeout.Infinite);
#else
            if (args.Length == 0)
            {
                Console.SetOut(new Printer(Console.OpenStandardOutput()));
            }

            Thread t = new Thread(Solve, 134217728);
            t.Start();
            t.Join();
            Console.Out.Flush();
#endif
        }

        static int NextInt() => int.Parse(Console_.NextString());
        static long NextLong() => long.Parse(Console_.NextString());
        static double NextDouble() => double.Parse(Console_.NextString());
        static string NextString() => Console_.NextString();
        static string NextLine() => Console.ReadLine();
        static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift);
        static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred);
        static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n);
        static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c);
        static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } }
        static IEnumerator<uint> _xsi = _xsc();
        static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } }

        static class Console_
        {
            static Queue<string> param = new Queue<string>();
            public static string NextString()
            {
                if (param.Count == 0)
                {
                    foreach (string item in NextLine().Split(' '))
                    {
                        param.Enqueue(item);
                    }
                }
                return param.Dequeue();
            }
        }
        class Printer : StreamWriter
        {
            public override IFormatProvider FormatProvider => CultureInfo.InvariantCulture;
            public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; }
            public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; }
        }
    }
}
namespace Csharp_Contest
{
/*
 * #import_Matrix.cs
 */
    public class IntegerMatrix: Matrix<int>
    {
        private readonly int mod;

        public IntegerMatrix(int size, int mod) : base(size)
        {
            this.mod = mod;
        }

        public override void Identity()
        {
            for (int i = 0; i < this.Size; i++)
            {
                for (int j = 0; j < this.Size; j++)
                {
                    this[i, j] = (i == j) ? 1 : 0;
                }
            }
        }

        protected override Matrix<int> Add(Matrix<int> right)
        {
            IntegerMatrix temp = new IntegerMatrix(this.Size, this.mod);
            temp.Reset();
            for (int i = 0; i < this.Size; i++)
            {
                for (int j = 0; j < this.Size; j++)
                {
                    temp[i, j] = (this[i, j] + right[i, j]) % this.mod;
                    while (temp[i, j] >= this.mod)
                    {
                        temp[i, j] -= this.mod;
                    }
                }
            }

            return temp;
        }

        protected override Matrix<int> Multiply(Matrix<int> right)
        {
            IntegerMatrix temp = new IntegerMatrix(this.Size, this.mod);
            temp.Reset();
            for (int i = 0; i < this.Size; i++)
            {
                for (int j = 0; j < this.Size; j++)
                {
                    for (int k = 0; k < this.Size; k++)
                    {
                        temp[i, k] += (int)((1L * this[i, j] * right[j, k]) % this.mod);
                        while (temp[i, k] >= this.mod)
                        {
                            temp[i, k] -= this.mod;
                        }
                    }
                }
            }

            return temp;
        }

        protected override Matrix<int> Power(long power)
        {
            IntegerMatrix ans = new IntegerMatrix(this.Size, this.mod);
            ans.Identity();
            IntegerMatrix num = this;
            for (; power > 0; power >>= 1)
            {
                if (power % 2 == 1)
                {
                    ans = (IntegerMatrix)(ans * num);
                }

                num = (IntegerMatrix)(num * num);
            }

            return ans;
        }
    }
}
namespace Csharp_Contest
{
    public abstract class Matrix<T>
    {
        private T[,] a;
        private readonly int size;

        protected Matrix(int size)
        {
            this.size = size;
            this.a = new T[this.size, this.size];
        }

        public void Reset()
        {
            for (int i = 0; i < this.size; i++)
            {
                for (int j = 0; j < this.size; j++)
                {
                    this[i, j] = default(T);
                }
            }
        }

        public abstract void Identity();

        public static Matrix<T> operator+ (Matrix<T> a, Matrix<T> b)
        {
            return a.Add(b);
        }

        protected abstract Matrix<T> Add(Matrix<T> right);

        public static Matrix<T> operator *(Matrix<T> a, Matrix<T> b)
        {
            return a.Multiply(b);
        }

        protected abstract Matrix<T> Multiply(Matrix<T> right);

        public static Matrix<T> operator ^(Matrix<T> a, long power)
        {
            return a.Power(power);
        }

        public static Matrix<T> operator ^(Matrix<T> a, int power)
        {
            return a.Power(power);
        }

        public T this[int i, int j]
        {
            get => this.a[i, j];
            set => this.a[i, j] = value;
        }

        protected abstract Matrix<T> Power(long power);

        public int Size => this.size;
    }
}


In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of n tiles that are lain in a row and are numbered from 1 to n from right to left. The opposition should start walking on the tile number 1 and the finish on the tile number n. During the walk it is allowed to move from right to left between adjacent tiles in a row, and jump over a tile. More formally, if you are standing on the tile number i (i < n - 1), you can reach the tiles number i + 1 or the tile number i + 2 from it (if you stand on the tile number n - 1, you can only reach tile number n). We can assume that all the opposition movements occur instantaneously.In order to thwart an opposition rally, the Berland bloody regime organized the rain. The tiles on the boulevard are of poor quality and they are rapidly destroyed in the rain. We know that the i-th tile is destroyed after ai days of rain (on day ai tile isn't destroyed yet, and on day ai + 1 it is already destroyed). Of course, no one is allowed to walk on the destroyed tiles! So the walk of the opposition is considered thwarted, if either the tile number 1 is broken, or the tile number n is broken, or it is impossible to reach the tile number n from the tile number 1 if we can walk on undestroyed tiles.The opposition wants to gather more supporters for their walk. Therefore, the more time they have to pack, the better. Help the opposition to calculate how much time they still have and tell us for how many days the walk from the tile number 1 to the tile number n will be possible.

The first line contains integer n (1 ≤ n ≤ 103) — the boulevard's length in tiles. The second line contains n space-separated integers ai — the number of days after which the i-th tile gets destroyed (1 ≤ ai ≤ 103).

Print a single number — the sought number of days.

NoteIn the first sample the second tile gets destroyed after day three, and the only path left is 1 → 3 → 4. After day five there is a two-tile gap between the first and the last tile, you can't jump over it.In the second sample path 1 → 3 → 5 is available up to day five, inclusive. On day six the last tile is destroyed and the walk is thwarted.

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

namespace Codeforces192B
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            int[] k = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            int countDay = 0;
            int countTile = 0;

            if (n == 1)
            {
                countDay = k[0];
            }
            else
            {
                while (countTile <= n)
                {
                    if (countTile == n - 1)
                    {
                        countDay++;
                        countTile = 0;
                    }

                    if (k[0] > countDay && countTile + 2 < n && k[countTile + 2] > countDay)
                        countTile += 2;
                    else if (k[0] > countDay && countTile + 1 < n && k[countTile + 1] > countDay)
                        countTile += 1;
                    else
                        break;
                }
            }
            Console.WriteLine(countDay);
        }
    }
}


The Little Elephant very much loves sums on intervals.This time he has a pair of integers l and r (l ≤ r). The Little Elephant has to find the number of such integers x (l ≤ x ≤ r), that the first digit of integer x equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be included in the answer and 47, 253 or 1020 will not.Help him and count the number of described numbers x for a given pair l and r.

The single line contains a pair of integers l and r (1 ≤ l ≤ r ≤ 1018) — the boundaries of the interval. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.

On a single line print a single integer — the answer to the problem.

NoteIn the first sample the answer includes integers 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44.

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

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

        private static void Solve()
        {
            var input = ReadLongArray();
            var l = input[0];
            var r = input[1];
            var dp = new long[20];
            dp[1] = 1;
            dp[2] = 1;
            long pow = 10;
            for (int i = 3; i <= 19; i++)
            {
                dp[i] = pow;
                pow *= 10;
            }
            long res = Get(r, dp) - Get(l - 1, dp);
            WriteLine(res);
        }

        private static long Get(long n, long[] dp)
        {
            if (n == 0)
                return 0;
            if (n < 10)
                return n;

            long res = 0;
            var count = 0;
            var initN = n;
            var first = 0L;
            while (n > 0)
            {
                count++;
                first = n;
                n /= 10;
            }
            for (int i = 1; i < count; i++)
            {
                res += 9 * dp[i];
            }
            res += (first - 1) * dp[count];
            n = initN;
            n -= first * (long)Math.Pow(10, count - 1);
            while (n % 10 != first && n > 0)
            {
                n--;
            }
            res += n / 10 + (n != 0 ? 1 : 0);

            return res;
        }

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

            Solve();

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

        #region Reader

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

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

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

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

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

        private static List<long> ReadLongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToList();
        }

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

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

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

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

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

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

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

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

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

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

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

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


Vasya, like many others, likes to participate in a variety of sweepstakes and lotteries. Now he collects wrappings from a famous chocolate bar "Jupiter". According to the sweepstake rules, each wrapping has an integer written on it — the number of points that the participant adds to his score as he buys the bar. After a participant earns a certain number of points, he can come to the prize distribution center and exchange the points for prizes. When somebody takes a prize, the prize's cost is simply subtracted from the number of his points.Vasya didn't only bought the bars, he also kept a record of how many points each wrapping cost. Also, he remembers that he always stucks to the greedy strategy — as soon as he could take at least one prize, he went to the prize distribution centre and exchanged the points for prizes. Moreover, if he could choose between multiple prizes, he chose the most expensive one. If after an exchange Vasya had enough points left to get at least one more prize, then he continued to exchange points.The sweepstake has the following prizes (the prizes are sorted by increasing of their cost):   a mug (costs a points),  a towel (costs b points),  a bag (costs c points),  a bicycle (costs d points),  a car (costs e points). Now Vasya wants to recollect what prizes he has received. You know sequence p1, p2, ..., pn, where pi is the number of points Vasya got for the i-th bar. The sequence of points is given in the chronological order. You also know numbers a, b, c, d, e. Your task is to find, how many prizes Vasya received, what prizes they are and how many points he's got left after all operations are completed.

The first line contains a single integer n (1 ≤ n ≤ 50) — the number of chocolate bar wrappings that brought points to Vasya. The second line contains space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ 109). The third line contains 5 integers a, b, c, d, e (1 ≤ a < b < c < d < e ≤ 109) — the prizes' costs.

Print on the first line 5 integers, separated by a space — the number of mugs, towels, bags, bicycles and cars that Vasya has got, respectively. On the second line print a single integer — the number of points Vasya will have left after all operations of exchange are completed. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

NoteIn the first sample Vasya gets 3 points after eating the first chocolate bar. Then he exchanges 2 points and gets a mug. Vasya wins a bag after eating the second chocolate bar. Then he wins a towel after eating the third chocolate bar. After all chocolate bars 3 - 2 + 10 - 10 + 4 - 4 = 1 points remains.

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

namespace ConsoleApplication10
{
    class Program
    {
       /*static long ch (long x)
        {
            if (x > 0)
                return ;
            else
                return ;
        }*/
        static void Main(string[] args)
        {
            long n = Convert.ToInt64(Console.ReadLine());
            string s = Console.ReadLine();
            string[] p = s.Split(' ');
            s = Console.ReadLine();
            string[] pr = s.Split(' ');
            long bal = 0;
            long a = Convert.ToInt64(pr[0]);
            long b = Convert.ToInt64(pr[1]);
            long c = Convert.ToInt64(pr[2]);
            long d = Convert.ToInt64(pr[3]);
            long e = Convert.ToInt64(pr[4]);
            long a1 = 0;
            long b1 = 0;
            long c1 = 0;
            long d1 = 0;
            long e1 = 0;
            for (int i = 1; i <= n; i++)
            {
                bal = bal + Convert.ToInt64(p[i - 1]);
                e1 = e1 + bal / e;
                bal = bal % e;
                d1 = d1 + bal / d;
                bal = bal % d;
                c1 = c1 + bal / c;
                bal = bal % c;
                b1 = b1 + bal / b;
                bal = bal % b;
                a1 = a1 + bal / a;
                bal = bal % a;

            }
            Console.WriteLine(a1+" "+b1+" "+c1+" "+d1+" "+e1);
            Console.WriteLine(bal);

        }
    }
}


Vasya's bicycle chain drive consists of two parts: n stars are attached to the pedal axle, m stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation.We know that the i-th star on the pedal axle has ai (0 < a1 < a2 < ... < an) teeth, and the j-th star on the rear wheel axle has bj (0 < b1 < b2 < ... < bm) teeth. Any pair (i, j) (1 ≤ i ≤ n; 1 ≤ j ≤ m) is called a gear and sets the indexes of stars to which the chain is currently attached. Gear (i, j) has a gear ratio, equal to the value .Since Vasya likes integers, he wants to find such gears (i, j), that their ratios are integers. On the other hand, Vasya likes fast driving, so among all "integer" gears (i, j) he wants to choose a gear with the maximum ratio. Help him to find the number of such gears.In the problem, fraction  denotes division in real numbers, that is, no rounding is performed.

The first input line contains integer n (1 ≤ n ≤ 50) — the number of stars on the bicycle's pedal axle. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 104) in the order of strict increasing. The third input line contains integer m (1 ≤ m ≤ 50) — the number of stars on the rear wheel axle. The fourth line contains m integers b1, b2, ..., bm (1 ≤ bi ≤ 104) in the order of strict increasing. It is guaranteed that there exists at least one gear (i, j), that its gear ratio is an integer. The numbers on the lines are separated by spaces.

Print the number of "integer" gears with the maximum ratio among all "integer" gears.

NoteIn the first sample the maximum "integer" gear ratio equals 3. There are two gears that have such gear ratio. For one of them a1 = 4, b1 = 12, and for the other a2 = 5, b3 = 15.

using System;
using System.Linq;
namespace codeforces
{
    class Program
    {
        static void Main(string[] args)
        {
            int n= int.Parse(Console.ReadLine());
            int[] a= Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            int m = int.Parse(Console.ReadLine());
            int[] b= Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            int count = 0;
            int max = 0;
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    if (b[j]%a[i]==0)
                    {
                        int rez = b[j] / a[i];
                        if (rez>max)
                        {
                            max = rez;
                            count=1;
                        }
                        else if (rez==max)
                        {
                            count++;
                        }
                    }
                }
            }
            Console.WriteLine(count) ;
        }
    }
}


Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created.We assume that Bajtek can only heap up snow drifts at integer coordinates.

The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift. Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсides with the direction of the Ox axis. All snow drift's locations are distinct.

Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one.

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

namespace _217A
{
    class Struct
    {
        public Struct(int x1, int y1, int set1)
        {

            x = x1;
            y = y1;
            set = set1;
        }
        public int x;
        public int y;
        public int set;

        public override string ToString()
        {
            return x + " " + y + " " + set;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var list = new List<Struct>();

            int id = 0;

            for (int i = 0; i < n; i++)
            {
                //Console.WriteLine("Точка №"+i);
                var strArr = Console.ReadLine().Split(' ');
                int x = int.Parse(strArr[0]);
                int y = int.Parse(strArr[1]);
                var setValue = list.Where(s => s.x == x ^ s.y == y).Select(s => s.set).ToArray();
                var setElems = list.Where(s => setValue.Contains(s.set)).ToArray();
                foreach (var item in setElems)
                {
                    item.set = id;
                }
                list.Add(new Struct(x, y, id));
                id++;
                //foreach (var item in list)
                //{
                //    Console.WriteLine(item.ToString());
                //}
            }
            Console.WriteLine(list.Select(s=>s.set).Distinct().Count()-1);
        }
    }
}


Peter likes to travel by train. He likes it so much that on the train he falls asleep. Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour.The boy started to memorize the order of the flags' colours that he had seen. But soon he fell asleep again. Unfortunately, he didn't sleep long, he woke up and went on memorizing the colours. Then he fell asleep again, and that time he slept till the end of the journey.At the station he told his parents about what he was doing, and wrote two sequences of the colours that he had seen before and after his sleep, respectively.Peter's parents know that their son likes to fantasize. They give you the list of the flags' colours at the stations that the train passes sequentially on the way from A to B, and ask you to find out if Peter could see those sequences on the way from A to B, or from B to A. Remember, please, that Peter had two periods of wakefulness.Peter's parents put lowercase Latin letters for colours. The same letter stands for the same colour, different letters — for different colours.

The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order.  The second line contains the sequence, written by Peter during the first period of wakefulness. The third line contains the sequence, written during the second period of wakefulness. Both sequences are non-empty, consist of lowercase Latin letters, and the length of each does not exceed 100 letters. Each of the sequences is written in chronological order.

Output one of the four words without inverted commas:    «forward» — if Peter could see such sequences only on the way from A to B;  «backward» — if Peter could see such sequences on the way from B to A;  «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A;  «fantasy» — if Peter could not see such sequences.

NoteIt is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B.

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

namespace ProgrammingContest.Codeforces.Round8
{
    class A
    {
        public static int Check(string s, int start, string c)
        {
            for (int i = start; i < s.Length; i++)
            {
                bool ok = true;
                for (int j = 0; j < c.Length; j++)
                {
                    int k = i + j;
                    if (k >= s.Length || c[j] != s[k])
                    {
                        ok = false;
                        break;
                    }
                }
                if (ok) return i;
            }
            return -1;
        }

        public static bool Check(string s, string c1, string c2)
        {
#if false
            for (int i = Check(s, 0, c1); i < s.Length; i = Check(s, i+1, c1))
            {
                if (Check(s, i+1, c2) != -1)
                    return true;
            }
#endif
            int i = Check(s, 0, c1);
            if (i == -1) return false;
            return Check(s, i+c1.Length, c2) != -1;
        }

        public static void Main()
        {
            string s = Console.ReadLine();
            string c1 = Console.ReadLine();
            string c2 = Console.ReadLine();

            bool forward = Check(s, c1, c2);
            bool backward = Check(new string(s.Reverse().ToArray()), c1, c2);

            if (forward && backward)
            {
                Console.Write("both");
            }
            else if (forward)
            {
                Console.Write("forward");
            }
            else if (backward)
            {
                Console.Write("backward");
            }
            else
            {
                Console.Write("fantasy");
            }
        }
    }
}

[{'input': 'atob\r\na\r\nb\r\n', 'output': ['forward\r\n']}, {'input': 'aaacaaa\r\naca\r\naa\r\n', 'output': ['both\r\n']}, {'input': 'aaa\r\naa\r\naa\r\n', 'output': ['fantasy\r\n']}, {'input': 'astalavista\r\nastla\r\nlavista\r\n', 'output': ['fantasy\r\n']}, {'input': 'abacabadabacaba\r\nabacaba\r\nabacaba\r\n', 'output': ['both\r\n']}, {'input': 'a\r\na\r\na\r\n', 'output': ['fantasy\r\n']}, {'input': 'ab\r\nb\r\na\r\n', 'output': ['backward\r\n']}, {'input': 'aaa\r\naaaa\r\naaaa\r\n', 'output': ['fantasy\r\n']}, {'input': 'bbabbbbababbaabaabaa\r\nabb\r\nbaab\r\n', 'output': ['forward\r\n']}, {'input': 'bbbbbbbbbbbbbbbbbbbbbbbbb\r\nbbbb\r\nbbbbb\r\n', 'output': ['both\r\n']}, {'input': 'babaabababaaaababaabababaabababababababbababbbabbaabababaababbaabbababaababaaabababaabbaababaaababaa\r\nabaabababaa\r\nabaabbaa\r\n', 'output': ['forward\r\n']}, {'input': 'bbbbbbbbbbbbbbbbbbbbbbbbb\r\nbbbb\r\nbbbbb\r\n', 'output': ['both\r\n']}, {'input': 'aababaaababaabbaabababaaababaabababbaabbabaabababaabbabbbababbababababababaabababaababaaaabababaabab\r\nabaabababaa\r\nabaabbaa\r\n', 'output': ['backward\r\n']}, {'input': 'aaaa\r\naaa\r\naa\r\n', 'output': ['fantasy\r\n']}, {'input': 'zzzz\r\nzz\r\nzzz\r\n', 'output': ['fantasy\r\n']}, {'input': 'zzzz\r\nzzzz\r\nzzzz\r\n', 'output': ['fantasy\r\n']}, {'input': 'zzzz\r\nzz\r\nzz\r\n', 'output': ['both\r\n']}, {'input': 'aabaa\r\naab\r\nbaa\r\n', 'output': ['fantasy\r\n']}, {'input': 'aabaab\r\naba\r\nab\r\n', 'output': ['forward\r\n']}, {'input': 'aab\r\nb\r\naa\r\n', 'output': ['backward\r\n']}, {'input': 'abacaba\r\naca\r\nba\r\n', 'output': ['both\r\n']}]


And again a misfortune fell on Poor Student. He is being late for an exam.Having rushed to a bus stop that is in point (0, 0), he got on a minibus and they drove along a straight line, parallel to axis OX, in the direction of increasing x.Poor Student knows the following:   during one run the minibus makes n stops, the i-th stop is in point (xi, 0)  coordinates of all the stops are different  the minibus drives at a constant speed, equal to vb  it can be assumed the passengers get on and off the minibus at a bus stop momentarily  Student can get off the minibus only at a bus stop  Student will have to get off the minibus at a terminal stop, if he does not get off earlier  the University, where the exam will be held, is in point (xu, yu)  Student can run from a bus stop to the University at a constant speed vs as long as needed  a distance between two points can be calculated according to the following formula:   Student is already on the minibus, so, he cannot get off at the first bus stop Poor Student wants to get to the University as soon as possible. Help him to choose the bus stop, where he should get off. If such bus stops are multiple, choose the bus stop closest to the University.

The first line contains three integer numbers: 2 ≤ n ≤ 100, 1 ≤ vb, vs ≤ 1000. The second line contains n non-negative integers in ascending order: coordinates xi of the bus stop with index i. It is guaranteed that x1 equals to zero, and xn ≤ 105. The third line contains the coordinates of the University, integers xu and yu, not exceeding 105 in absolute value.

In the only line output the answer to the problem — index of the optimum bus stop.

NoteAs you know, students are a special sort of people, and minibuses usually do not hurry. That's why you should not be surprised, if Student's speed is higher than the speed of the minibus.

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

namespace ProgrammingContest.Codeforces.Round9
{
    class C
    {
        public static void Main()
        {
            string[] s = Console.ReadLine().Split(' ');
            int n = int.Parse(s[0]);
            double vb = double.Parse(s[1]);
            double vs = double.Parse(s[2]);

            s = Console.ReadLine().Split(' ');
            double[] busStopX = new double[n];
            for (int i = 0; i < n; i++)
            {
                busStopX[i] = double.Parse(s[i]);
            }

            s = Console.ReadLine().Split(' ');
            double xu, yu;
            xu = double.Parse(s[0]);
            yu = double.Parse(s[1]);

            int optIndex = -1;
            double timeMin = double.MaxValue;
            double distMin = double.MaxValue;
            for (int i = 1; i < n; i++)
            {
                double dx = xu - busStopX[i];
                double dy = yu;
                double dist = Math.Sqrt(dx * dx + dy * dy);
                double time = busStopX[i] / vb + dist / vs;
                //Console.WriteLine("{0}, {1}", dist, time);
                if (timeMin > time || timeMin == time && distMin > dist)
                {
                    timeMin = time;
                    distMin = dist;
                    optIndex = i;
                }
            }
            Console.WriteLine(optIndex+1);
        }
    }
}


A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» n square houses with the centres on the Оx-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other.The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the Оx-axis, to be square in shape, have a side t, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the Ox-axis and it shouldn't overlap any of the houses in the village.Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house?

The first line of the input data contains numbers n and t (1 ≤ n, t ≤ 1000). Then there follow n lines, each of them contains two space-separated integer numbers: xi ai, where xi — x-coordinate of the centre of the i-th house, and ai — length of its side ( - 1000 ≤ xi ≤ 1000, 1 ≤ ai ≤ 1000).

Output the amount of possible positions of the new house.

NoteIt is possible for the x-coordinate of the new house to have non-integer value.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
static class P {
    static int[] ToIntArray(this string val) { return val.Split().Select(int.Parse).ToArray(); }
    static void Main() {
        var line = Console.ReadLine().ToIntArray();
        int n = line[0], t = line[1], i = 0, cnt = 0;
        var list = new SortedList<int, int>();
        for (; i < n; ++i) {
            var input = Console.ReadLine().ToIntArray();
            list.Add(input[0], input[1]);
        }

        IList<int> keys = list.Keys, values = list.Values;
        for (i = 0; i < n - 1; ++i) {
            var val = (keys[i + 1] - keys[i]) - ((values[i + 1] + values[i]) / 2.0);
            if (val > t) { cnt += 2; } else if (val == t) { cnt++; }
        }
        Console.Write(cnt + 2);
    }
}


Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits.

The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups.

Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any.

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

namespace CodeForce
{
    class _25b
    {
        public static void Main()
        {
            var line = Console.ReadLine();
            line = Console.ReadLine();
            var result = string.Empty;
            if (line.Length == 2)
            {
                Console.WriteLine(line);
                return;
            }
            var idx = 0;
            if (line.Length % 2 == 1)
            {
                result = line.Substring(0, 3);
                idx = 3;
            }
            else
            {
                result = line.Substring(0, 2);
                idx = 2;
            }
            for (var i = idx; i < line.Length; i += 2)
            {
                result += "-" + line.Substring(i, 2);
            }
            Console.WriteLine(result);
        }
    }
}


A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself.The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th year (these numbers can be negative — it means that there was a loss in the correspondent year). King wants to show financial stability. To do this, he needs to find common coefficient X — the coefficient of income growth during one year. This coefficient should satisfy the equation:A·Xn = B.Surely, the king is not going to do this job by himself, and demands you to find such number X.It is necessary to point out that the fractional numbers are not used in kingdom's economy. That's why all input numbers as well as coefficient X must be integers. The number X may be zero or negative.

The input contains three integers A, B, n (|A|, |B| ≤ 1000, 1 ≤ n ≤ 10).

Output the required integer coefficient X, or «No solution», if such a coefficient does not exist or it is fractional. If there are several possible solutions, output any of them.

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

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

        class Solver
        {
            public void Solve()
            {
                string[] ss = CF.ReadLine().Split(' ');
                int A = int.Parse(ss[0]);
                int B = int.Parse(ss[1]);
                int n = int.Parse(ss[2]);

                int? ans= _t(A,B,n);
                if( ans == null)
                    CF.WriteLine("No solution");
                else
                    CF.WriteLine(ans);
            }

            int? _t(int A,int B,int n)
            {
                if (A == 0)
                {
                    if (B == 0)
                        return 5;
                    return null;
                }

                if( B%A!= 0 )
                    return null;

                int C= B/A;

                if (C < 0 && n % 2 == 0)
                    return null;

                if (C == 0)
                    return 0;

                int s = Math.Sign(C);

                C=Math.Abs(C);
                n = Math.Abs(n);

                for (int x= 1; x <= 1000; x++)
                {
                    int xn = x;
                    for (int j = 1; j < n; j++)
                        xn *= x;
                    if (xn == C)
                    {
                        return s* x;
                    }
                    if (xn > C)
                        break;
                }

                return null;

            }
        }

        #region test

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

        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 Console.In.ReadLine();
#endif
            }

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

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

            public CodeforcesUtils(string test_input)
            {
                _test_input = test_input;
            }

            string _test_input;

            List<string> _lines;
        }

        #endregion
    }
}


In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly n soldiers. Within this task we can assume that the number of soldiers in the defense structure won't either increase or decrease.Every soldier has a rank — some natural number from 1 to k. 1 stands for a private and k stands for a general. The higher the rank of the soldier is, the better he fights. Therefore, the player profits from having the soldiers of the highest possible rank.To increase the ranks of soldiers they need to train. But the soldiers won't train for free, and each training session requires one golden coin. On each training session all the n soldiers are present.At the end of each training session the soldiers' ranks increase as follows. First all the soldiers are divided into groups with the same rank, so that the least possible number of groups is formed. Then, within each of the groups where the soldiers below the rank k are present, exactly one soldier increases his rank by one.You know the ranks of all n soldiers at the moment. Determine the number of golden coins that are needed to increase the ranks of all the soldiers to the rank k.

The first line contains two integers n and k (1 ≤ n, k ≤ 100). They represent the number of soldiers and the number of different ranks correspondingly. The second line contains n numbers in the non-decreasing order. The i-th of them, ai, represents the rank of the i-th soldier in the defense building (1 ≤ i ≤ n, 1 ≤ ai ≤ k).

Print a single integer — the number of golden coins needed to raise all the soldiers to the maximal rank.

NoteIn the first example the ranks will be raised in the following manner:1 2 2 3  →  2 2 3 4  →  2 3 4 4  →  3 4 4 4  →  4 4 4 4Thus totals to 4 training sessions that require 4 golden coins.

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

namespace ProgrammingContest.Codeforces.Round59
{
    class B
    {
        public static void Main()
        {
            int[] nk = Array.ConvertAll(Console.ReadLine().Split(' '), sss => int.Parse(sss));
            int n = nk[0], k = nk[1];
            int[] sol = Array.ConvertAll(Console.ReadLine().Split(' '), sss => int.Parse(sss));
            int res = 0;
            for (; ; res++)
            {
                bool updated = false;
                for (int i = 0; i < sol.Length && sol[i] < k; i++)
                {
                    if (i == sol.Length - 1 || sol[i] != sol[i + 1])
                    {
                        sol[i]++;
                        updated = true;
                    }
                }
                if (!updated)
                    break;
            }
            Console.WriteLine(res);
        }
    }
}


The blinds are known to consist of opaque horizontal stripes that can be rotated thus regulating the amount of light flowing in the room. There are n blind stripes with the width of 1 in the factory warehouse for blind production. The problem is that all of them are spare details from different orders, that is, they may not have the same length (it is even possible for them to have different lengths)Every stripe can be cut into two or more parts. The cuttings are made perpendicularly to the side along which the length is measured. Thus the cuttings do not change the width of a stripe but each of the resulting pieces has a lesser length (the sum of which is equal to the length of the initial stripe)After all the cuttings the blinds are constructed through consecutive joining of several parts, similar in length, along sides, along which length is measured. Also, apart from the resulting pieces an initial stripe can be used as a blind if it hasn't been cut. It is forbidden to construct blinds in any other way.Thus, if the blinds consist of k pieces each d in length, then they are of form of a rectangle of k × d bourlemeters. Your task is to find for what window possessing the largest possible area the blinds can be made from the given stripes if on technical grounds it is forbidden to use pieces shorter than l bourlemeter. The window is of form of a rectangle with side lengths as positive integers.

The first output line contains two space-separated integers n and l (1 ≤ n, l ≤ 100). They are the number of stripes in the warehouse and the minimal acceptable length of a blind stripe in bourlemeters. The second line contains space-separated n integers ai. They are the lengths of initial stripes in bourlemeters (1 ≤ ai ≤ 100).

Print the single number — the maximal area of the window in square bourlemeters that can be completely covered. If no window with a positive area that can be covered completely without breaking any of the given rules exist, then print the single number 0.

NoteIn the first sample test the required window is 2 × 4 in size and the blinds for it consist of 4 parts, each 2 bourlemeters long. One of the parts is the initial stripe with the length of 2, the other one is a part of a cut stripe with the length of 3 and the two remaining stripes are parts of a stripe with the length of 4 cut in halves.

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

namespace Task38C
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] container = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int n = container[0], L = container[1];
            container = Console.ReadLine().Split().Select(int.Parse).ToArray();

            List<int> areas = new List<int>();
            int max = container.Max();
            for (int i = L; i<=max;i++)
            { int count = 0;
                foreach (int item in container)
                        count += item / i;

                areas.Add(count * i);
            }

            Console.WriteLine(areas.Count!=0? areas.Max():0);
          //  Console.ReadKey();

        }
    }
}


Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, that’s why he decided to invent the function that will correct the words itself. Petya started from analyzing the case that happens to him most of the time, when all one needs is to delete one letter for the word to match a word from the dictionary. Thus, Petya faces one mini-task: he has a printed word and a word from the dictionary, and he should delete one letter from the first word to get the second one. And now the very non-trivial question that Petya faces is: which letter should he delete?

The input data contains two strings, consisting of lower-case Latin letters. The length of each string is from 1 to 106 symbols inclusive, the first string contains exactly 1 symbol more than the second one.

In the first line output the number of positions of the symbols in the first string, after the deleting of which the first string becomes identical to the second one. In the second line output space-separated positions of these symbols in increasing order. The positions are numbered starting from 1. If it is impossible to make the first string identical to the second string by deleting one symbol, output one number 0.

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

namespace Spelling_Check
{
    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 s1 = reader.ReadLine();
            string s2 = reader.ReadLine();

            var f = new bool[s1.Length];
            for (int i = s1.Length - 1; i > 0; i--)
            {
                if (s1[i] == s2[i - 1])
                    f[i] = true;
                else
                    break;
            }

            var ans = new List<int>();

            for (int i = 0; i < s1.Length; i++)
            {
                if (i + 1 >= f.Length || f[i + 1])
                    ans.Add(i);
                if (i >= s2.Length || s1[i] != s2[i])
                    break;
            }

            writer.WriteLine(ans.Count);
            foreach (int an in ans)
            {
                writer.Write(an + 1);
                writer.Write(' ');
            }

            writer.Flush();
        }
    }
}

[{'input': 'abdrakadabra\r\nabrakadabra\r\n', 'output': ['1\r\n3 ']}, {'input': 'aa\r\na\r\n', 'output': ['2\r\n1 2 ']}, {'input': 'competition\r\ncodeforces\r\n', 'output': ['0\r\n']}, {'input': 'ab\r\na\r\n', 'output': ['1\r\n2 ']}, {'input': 'bb\r\nb\r\n', 'output': ['2\r\n1 2 ']}, {'input': 'aab\r\nab\r\n', 'output': ['2\r\n1 2 ']}, {'input': 'aabb\r\nabb\r\n', 'output': ['2\r\n1 2 ']}, {'input': 'babaacaacaa\r\nbbaacaacaa\r\n', 'output': ['1\r\n2 ']}, {'input': 'bccaabbcccc\r\nbccaabcccc\r\n', 'output': ['2\r\n6 7 ']}, {'input': 'ababcaabaaa\r\nabacaabaaa\r\n', 'output': ['1\r\n4 ']}, {'input': 'cccacaccacb\r\ncccacaccac\r\n', 'output': ['1\r\n11 ']}, {'input': 'aaaaaaaaaaa\r\naaaaaaaaaa\r\n', 'output': ['11\r\n1 2 3 4 5 6 7 8 9 10 11 ']}, {'input': 'lcaaxcbcjca\r\nccaaacccca\r\n', 'output': ['0\r\n']}, {'input': 'babbbtaamba\r\nbabbbaabba\r\n', 'output': ['0\r\n']}, {'input': 'xdfxmcnzpch\r\nazvotghvtk\r\n', 'output': ['0\r\n']}, {'input': 'ki\r\nb\r\n', 'output': ['0\r\n']}, {'input': 'vct\r\nie\r\n', 'output': ['0\r\n']}, {'input': 'feee\r\nsnl\r\n', 'output': ['0\r\n']}, {'input': 'cbxxxxzvks\r\ncbxxxzvks\r\n', 'output': ['4\r\n3 4 5 6 ']}, {'input': 'qybldcgfhdhhhhhhhhhhopqkhuczzytzluiahwbqjltgafvvoecititchjwdoljiehubngmtjckqymldhoncgtqhxnqvoagnrmur\r\nqybldcgfhdhhhhhhhhhopqkhuczzytzluiahwbqjltgafvvoecititchjwdoljiehubngmtjckqymldhoncgtqhxnqvoagnrmur\r\n', 'output': ['10\r\n11 12 13 14 15 16 17 18 19 20 ']}]


A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count. The game goes as follows. Kids stand in circle. Let's agree to think of the children as numbered with numbers from 1 to n clockwise and the child number 1 is holding the ball. First the first child throws the ball to the next one clockwise, i.e. to the child number 2. Then the child number 2 throws the ball to the next but one child, i.e. to the child number 4, then the fourth child throws the ball to the child that stands two children away from him, i.e. to the child number 7, then the ball is thrown to the child who stands 3 children away from the child number 7, then the ball is thrown to the child who stands 4 children away from the last one, and so on. It should be mentioned that when a ball is thrown it may pass the beginning of the circle. For example, if n = 5, then after the third throw the child number 2 has the ball again. Overall, n - 1 throws are made, and the game ends.The problem is that not all the children get the ball during the game. If a child doesn't get the ball, he gets very upset and cries until Natalia Pavlovna gives him a candy. That's why Natalia Pavlovna asks you to help her to identify the numbers of the children who will get the ball after each throw.

The first line contains integer n (2 ≤ n ≤ 100) which indicates the number of kids in the circle.

In the single line print n - 1 numbers which are the numbers of children who will get the ball after each throw. Separate the numbers by spaces.

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

namespace ConsoleApplication3
{
    class Program
    {

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int current = 0;
            int q = 1;
            for (int i = 0; i < n-1; i++ )
            {
                current = (current + q) % n;
                q++;
                Console.Write((current + 1) + " ");
            }
        }
    }
}


Some time ago Leonid have known about idempotent functions. Idempotent function defined on a set {1, 2, ..., n} is such function , that for any  the formula g(g(x)) = g(x) holds.Let's denote as f(k)(x) the function f applied k times to the value x. More formally, f(1)(x) = f(x), f(k)(x) = f(f(k - 1)(x)) for each k > 1.You are given some function . Your task is to find minimum positive integer k such that function f(k)(x) is idempotent.

In the first line of the input there is a single integer n (1 ≤ n ≤ 200) — the size of function f domain. In the second line follow f(1), f(2), ..., f(n) (1 ≤ f(i) ≤ n for each 1 ≤ i ≤ n), the values of a function.

Output minimum k such that function f(k)(x) is idempotent.

NoteIn the first sample test function f(x) = f(1)(x) is already idempotent since f(f(1)) = f(1) = 1, f(f(2)) = f(2) = 2, f(f(3)) = f(3) = 2, f(f(4)) = f(4) = 4.In the second sample test:   function f(x) = f(1)(x) isn't idempotent because f(f(1)) = 3 but f(1) = 2;  function f(x) = f(2)(x) is idempotent since for any x it is true that f(2)(x) = 3, so it is also true that f(2)(f(2)(x)) = 3. In the third sample test:   function f(x) = f(1)(x) isn't idempotent because f(f(1)) = 3 but f(1) = 2;  function f(f(x)) = f(2)(x) isn't idempotent because f(2)(f(2)(1)) = 2 but f(2)(1) = 3;  function f(f(f(x))) = f(3)(x) is idempotent since it is identity function: f(3)(x) = x for any  meaning that the formula f(3)(f(3)(x)) = f(3)(x) also holds.

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

class ProblemC {
    static string inputFileName = "../../input.txt";
    static StreamReader fileReader;
    static string[] inputTokens;
    static int curInputTokenIndex;
    static string NextToken() {
        string ret = "";
        while (ret == "") {
            if (inputTokens == null || curInputTokenIndex >= inputTokens.Length) {
                string line;
                if (Type.GetType("HaitaoLocal") != null) {
                    if (fileReader == null) {
                        fileReader = new StreamReader(inputFileName);
                    }
                    line = fileReader.ReadLine();
                    if (line == null) {
                        throw new Exception("Error: out of input tokens!");
                    }
                } else {
                    line = Console.ReadLine();
                }
                inputTokens = line.Split();
                curInputTokenIndex = 0;
            }
            ret = inputTokens[curInputTokenIndex++];
        }
        return ret;
    }
    static int ReadInt() {
        return Int32.Parse(NextToken());
    }
    static string ReadString() {
        return NextToken();
    }
    static long ReadLong() {
        return Int64.Parse(NextToken());
    }
    static int[] ReadIntArray(int length) {
        int[] ret = new int[length];
        for (int i = 0; i < length; i++) {
            ret[i] = ReadInt();
        }
        return ret;
    }
    static string[] ReadStringArray(int length) {
        string[] ret = new string[length];
        for (int i = 0; i < length; i++) {
            ret[i] = ReadString();
        }
        return ret;
    }
    static long[] ReadLongArray(int length) {
        long[] ret = new long[length];
        for (int i = 0; i < length; i++) {
            ret[i] = ReadLong();
        }
        return ret;
    }
    static string DoubleToString(double d) {
        return d.ToString(new CultureInfo("en-US"));
    }

    public static void Main(string[] args) {

        int N = ReadInt();
        int[] ar = ReadIntArray(N);
        for (int i = 0; i < N; i++) ar[i]--;
        int[,] dp = new int[2 * N + 1, N];
        for (int k = 0; k <= 2 * N; k++) {
            for (int i = 0; i < N; i++) {
                if (k == 0) dp[k, i] = 1;
                else if (k == 1) dp[k, i] = ar[i];
                else dp[k, i] = ar[dp[k - 1, i]];
            }
        }
        int[] cycle = new int[N];

        for (int i = 0; i < N; i++) {
            cycle[i] = -1;
        }
        for (int i = 0; i < N; i++) {
            for (int k = 1; k <= N; k++) {
                if (dp[k, i] == i) { cycle[i] = k; break; }
            }
        }
        long lc = 1;
        for (int i = 0; i < N; i++) {
            //Console.WriteLine(i + " " + cycle[i]);
            if (cycle[i] != -1) lc = lcm(lc, cycle[i]);
        }
        long ans = -1;
        if (lc < N) {
            for (int k = 1; k <= N; k++) {
                bool flag = true;
                for (int i = 0; i < N; i++) {
                    if (dp[2 * k, i] != dp[k, i]) flag = false;
                }
                if (flag) { ans = k; break; }
            }
        }
        if (ans == -1) {
            ans = 0;
            while (ans < N) ans += lc;
        }

        Console.WriteLine(ans);

    }

    static long gcf(long a, long b) {
        while (b != 0) {
            long temp = b;
            b = a % b;
            a = temp;
        }
        return a;
    }

    static long lcm(long a, long b) {
        return (a / gcf(a, b)) * b;
    }
}


Alice has a string consisting of characters 'A', 'B' and 'C'. Bob can use the following transitions on any substring of our string in any order any number of times:   A  BC  B  AC  C  AB  AAA  empty string Note that a substring is one or more consecutive characters. For given queries, determine whether it is possible to obtain the target string from source.

The first line contains a string S (1 ≤ |S| ≤ 105). The second line contains a string T (1 ≤ |T| ≤ 105), each of these strings consists only of uppercase English letters 'A', 'B' and 'C'. The third line contains the number of queries Q (1 ≤ Q ≤ 105). The following Q lines describe queries. The i-th of these lines contains four space separated integers ai, bi, ci, di. These represent the i-th query: is it possible to create T[ci..di] from S[ai..bi] by applying the above transitions finite amount of times? Here, U[x..y] is a substring of U that begins at index x (indexed from 1) and ends at index y. In particular, U[1..|U|] is the whole string U. It is guaranteed that 1 ≤ a ≤ b ≤ |S| and 1 ≤ c ≤ d ≤ |T|.

Print a string of Q characters, where the i-th character is '1' if the answer to the i-th query is positive, and '0' otherwise.

NoteIn the first query we can achieve the result, for instance, by using transitions .The third query asks for changing AAB to A — but in this case we are not able to get rid of the character 'B'.

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

namespace Picking_Strings
{
    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)
        {
            Solve(args);
            writer.Flush();
        }

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

            var ss = new int[s.Length + 1];
            var sa = new int[s.Length + 1];
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == 'A')
                {
                    ss[i + 1] = ss[i];
                    sa[i + 1] = sa[i] + 1;
                }
                else
                {
                    ss[i + 1] = ss[i] + 1;
                }
            }
            var tt = new int[t.Length + 1];
            var ta = new int[t.Length + 1];
            for (int i = 0; i < t.Length; i++)
            {
                if (t[i] == 'A')
                {
                    tt[i + 1] = tt[i];
                    ta[i + 1] = ta[i] + 1;
                }
                else
                {
                    tt[i + 1] = tt[i] + 1;
                }
            }

            int Q = Next();

            while (Q-- > 0)
            {
                int a = Next(), b = Next(), c = Next(), d = Next();
                int cs = ss[b] - ss[a - 1];
                int ct = tt[d] - tt[c - 1];

                int esa = Math.Min(sa[b], b - a + 1);
                int eta = Math.Min(ta[d], d - c + 1);

                writer.Write(
                    cs > ct ||
                    cs < ct && (ct - cs)%2 != 0 ||
                    cs == ct && (eta > esa || eta < esa && (esa - eta)%3 != 0) ||
                    eta > 0 && (eta > esa || eta == esa && cs == 0 && ct > 0 || eta < esa && cs >= ct && (esa - eta)%3 != 0)
                        ? '0'
                        : '1');
            }
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == 'A')
                    return 0;
                if (c == 'B' || c == 'C')
                    return 1;
            } 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';
            }
        }
    }
}


Mike has a frog and a flower. His frog is named Xaniar and his flower is named Abol. Initially(at time 0), height of Xaniar is h1 and height of Abol is h2. Each second, Mike waters Abol and Xaniar.  So, if height of Xaniar is h1 and height of Abol is h2, after one second height of Xaniar will become  and height of Abol will become  where x1, y1, x2 and y2 are some integer numbers and  denotes the remainder of a modulo b.Mike is a competitive programmer fan. He wants to know the minimum time it takes until height of Xania is a1 and height of Abol is a2.Mike has asked you for your help. Calculate the minimum time or say it will never happen.

The first line of input contains integer m (2 ≤ m ≤ 106). The second line of input contains integers h1 and a1 (0 ≤ h1, a1 < m). The third line of input contains integers x1 and y1 (0 ≤ x1, y1 < m). The fourth line of input contains integers h2 and a2 (0 ≤ h2, a2 < m). The fifth line of input contains integers x2 and y2 (0 ≤ x2, y2 < m). It is guaranteed that h1 ≠ a1 and h2 ≠ a2.

Print the minimum number of seconds until Xaniar reaches height a1 and Abol reaches height a2 or print -1 otherwise.

NoteIn the first sample, heights sequences are following:Xaniar: Abol:

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

namespace Mike_and_Frog
{
    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 m = Next();
            int h1 = Next(), a1 = Next();
            int x1 = Next(), y1 = Next();
            int h2 = Next(), a2 = Next();
            int x2 = Next(), y2 = Next();

            long index1_1 = -1;
            int index1_2 = -1;

            for (int i = 1; i < 2*m; i++)
            {
                h1 = (int) (((long) x1*h1 + y1)%m);
                if (h1 == a1)
                {
                    if (index1_1 == -1)
                    {
                        index1_1 = i;
                    }
                    else
                    {
                        if (index1_2 == -1)
                        {
                            index1_2 = (int) (i - index1_1);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }

            long index2_1 = -1;
            int index2_2 = -1;

            for (int i = 1; i < 2*m; i++)
            {
                h2 = (int) (((long) x2*h2 + y2)%m);
                if (h2 == a2)
                {
                    if (index2_1 == -1)
                    {
                        index2_1 = i;
                    }
                    else
                    {
                        if (index2_2 == -1)
                        {
                            index2_2 = (int) (i - index2_1);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }

            if (index1_1 == index2_1)
            {
                writer.WriteLine(index1_1);
                writer.Flush();
                return;
            }

            if (index1_2 == -1 && index2_2 == -1)
            {
                writer.WriteLine(-1);
                writer.Flush();
                return;
            }

            for (int i = 0; i < m; i++)
            {
                while (index1_2 > 0 && index1_1 < index2_1)
                {
                    index1_1 += index1_2;
                }

                if (index1_1 == index2_1)
                {
                    writer.WriteLine(index1_1);
                    writer.Flush();
                    return;
                }

                while (index2_2 > 0 && index2_1 < index1_1)
                {
                    index2_1 += index2_2;
                }

                if (index1_1 == index2_1)
                {
                    writer.WriteLine(index1_1);
                    writer.Flush();
                    return;
                }
            }

            writer.WriteLine("-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';
            }
        }
    }
}


While creating high loaded systems one should pay a special attention to caching. This problem will be about one of the most popular caching algorithms called LRU (Least Recently Used).Suppose the cache may store no more than k objects. At the beginning of the workflow the cache is empty. When some object is queried we check if it is present in the cache and move it here if it's not. If there are more than k objects in the cache after this, the least recently used one should be removed. In other words, we remove the object that has the smallest time of the last query.Consider there are n videos being stored on the server, all of the same size. Cache can store no more than k videos and caching algorithm described above is applied. We know that any time a user enters the server he pick the video i with probability pi. The choice of the video is independent to any events before.The goal of this problem is to count for each of the videos the probability it will be present in the cache after 10100 queries.

The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 20) — the number of videos and the size of the cache respectively. Next line contains n real numbers pi (0 ≤ pi ≤ 1), each of them is given with no more than two digits after decimal point. It's guaranteed that the sum of all pi is equal to 1.

Print n real numbers, the i-th of them should be equal to the probability that the i-th video will be present in the cache after 10100 queries. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6.  Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if .

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 int BitCount(int x)
    {
        int ret = 0;
        while (x > 0)
        {
            ret++;
            x &= x - 1;
        }
        return ret;
    }

    public void Solve()
    {
        int n = ReadInt();
        int m = ReadInt();
        var p = ReadDoubleArray();

        int z = p.Count(pp => pp == 0);
        m = Math.Min(n - z, m);

        var dp = new double[1 << n];
        var ans = new double[n];
        dp[0] = 1;
        for (int mask = 0; mask < 1 << n; mask++)
            if (BitCount(mask) >= m)
            {
                if (BitCount(mask) == m)
                {
                    for (int i = 0; i < n; i++)
                        if ((mask >> i & 1) == 1)
                            ans[i] += dp[mask];
                }
                continue;
            }
            else
            {
                double s = 0;
                for (int i = 0; i < n; i++)
                    if ((mask >> i & 1) == 0)
                        s += p[i];
                if (s > 0)
                    for (int i = 0; i < n; i++)
                        if ((mask >> i & 1) == 0)
                            dp[mask | 1 << i] += dp[mask] * p[i] / s;
            }

        WriteArray(ans.Select(v => v.ToString(CultureInfo.InvariantCulture)));
    }

    #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)
        {
#if DEBUG
            Console.WriteLine(ex);
#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
}


International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year's competition.For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO'9, IAO'0 and IAO'1, while the competition in 2015 received an abbreviation IAO'15, as IAO'5 has been already used in 1995.You are given a list of abbreviations. For each of them determine the year it stands for.

The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of abbreviations to process.  Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits.

For each abbreviation given in the input, find the year of the corresponding Olympiad.

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

namespace chall_cs
{
    class Program
    {
        static int N, pos_1, pos_2;
        static long add, target, answer;
        static string phr, abbr;

        static void Main(string[] args)
        {
            N = Convert.ToInt32(Console.ReadLine());

            for (int i = 0; i < N; ++i)
            {
                phr = Console.ReadLine();
                abbr = "";

                for (int j = 4; j < phr.Length; ++j)
                    abbr += phr[j];

                answer = 1988;
                add = 1;
                pos_1 = 1;
                pos_2 = abbr.Length - 1;

                while (pos_2 >= 0)
                {
                    while (true)
                    {
                        answer += add;

                        if (take_dig(answer, pos_1) == abbr[pos_2] - '0')
                            break;
                    }

                    pos_2 -= 1;
                    pos_1 += 1;
                    add *= 10;
                }

                Console.WriteLine(answer);
            }

            //Console.ReadKey();
        }

        static long take_dig(long value, int pos)
        {
            while(value > 0)
            {
                if (pos == 1)
                    break;

                pos -= 1;
                value /= 10;
            }

            return value % 10;
        }
    }
}