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

namespace aWholeMuseum
{
    /*you are a museum full of art but I choose to shut and keep my eyes shut*/
    class Program
    {
        static void Main(string[] args)
        {
            int nomFirst = int.Parse(Console.ReadLine());
            int nomSecond = int.Parse(Console.ReadLine());
            int maxOfFirst = int.Parse(Console.ReadLine());
            int maxOfSecond = int.Parse(Console.ReadLine());
            int totalCards = int.Parse(Console.ReadLine());

            int maxAnswer = getMax(nomFirst, nomSecond, maxOfFirst, maxOfSecond, totalCards);
            int minAnswer = getMin(nomFirst, nomSecond, maxOfFirst, maxOfSecond, totalCards);
            Console.WriteLine(minAnswer.ToString() + " " + maxAnswer.ToString());
           // Console.ReadLine();
        }
        static int getMax(int nomFirst, int nomSecond, int maxOfFirst, int maxOfSecond, int totalCards)
        {
            int weightFirst = nomFirst / maxOfFirst;
            int weightSecond = nomSecond / maxOfSecond;
            int flag = 0;
            if (weightFirst > weightSecond) { flag = 1; }
            else if (weightFirst < weightSecond) { flag = 2; }

            int Answer = 0;
            int some = nomFirst + nomSecond;

            while (totalCards > 0)
            {
                if (flag == 1)
                {

                    while (nomFirst > 0 && totalCards > 0)
                    {
                        nomFirst--;
                        totalCards -= maxOfFirst;
                        Answer++;
                    }
                    if (nomFirst <= 0) flag = 2;
                    if (totalCards < maxOfFirst) break;
                }
                else if (flag == 2)
                {

                    while (nomSecond > 0 && totalCards > 0)
                    {
                        nomSecond--;
                        totalCards -= maxOfSecond;
                        Answer++;
                    }
                    if (nomSecond <= 0) flag = 1;
                    if (totalCards < maxOfSecond) break;
                }
                else
                {
                    while (some > 0 && totalCards > 0)
                    {
                        some--;
                        totalCards -= maxOfSecond;
                        Answer++;
                    }
                    if (totalCards < maxOfSecond) break;
                }
            }
            return Answer;
        }

        static int getMin(int nomFirst, int nomSecond, int maxOfFirst, int maxOfSecond, int totalCards)
        {
            //eliminate the cards
            double weightFirst = Double.Parse(nomFirst.ToString()) /Double.Parse( maxOfFirst.ToString());
            double weightSecond = Double.Parse(nomSecond.ToString()) / Double.Parse(maxOfSecond.ToString());
            int flag = 0;
            if (weightFirst < weightSecond) { flag = 1; }
            else if (weightFirst > weightSecond) { flag = 2; }

            int Answer = 0;
            int some = nomFirst + nomSecond;

            while (totalCards > 0 && (nomFirst + nomSecond) > 0)
            {

                if (flag == 1)
                {

                    while (nomFirst > 0 && totalCards > 0)
                    {
                        nomFirst--;

                        if (maxOfFirst - 1 >= 0) totalCards -= (maxOfFirst - 1);

                    }
                    if (nomFirst <= 0) flag = 2;
                }
                else if (flag == 2)
                {

                    while (nomSecond > 0 && totalCards > 0)
                    {
                        nomSecond--;

                        if (maxOfSecond - 1 >= 0) totalCards -= (maxOfSecond - 1);

                    }
                    if (nomSecond <= 0) flag = 1;
                }
                else
                {
                    while (some > 0 && totalCards > 0)
                    {
                        some--;
                        if (maxOfSecond - 1 >= 0) totalCards -= (maxOfSecond - 1);

                    }
                    if (some <= 0) break;
                }
            }
            Answer = totalCards;
            return Answer;
        }
    }
}


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

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

            Console.WriteLine("Enter The Number Of The Cube ");
            int x = Convert.ToInt32(Console.ReadLine());
            int sum = 0;
            int c = 0;
            while (x > 0)
            {
                c++;
                for (int i = 1; i <= c; i++)
                {
                    sum += i;
                }
                x -= sum;
            }
            Console.WriteLine(c);

        }
    }
}


using System;
using System.Linq;

class P {
  static void Main() {
    var r = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    var c = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    var d = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    var res = new [] { new int[2], new int[2] };
    res[0][1] = r[0] + c[1] - d[0];
    if (res[0,1] % 2 == 1) { Console.WriteLine(-1); return; }
    res[0][1] /= 2;
    res[0][0] = r[0] - res[0][1];
    res[1][0] = c[0] - res[0][0];
    res[1][1] = r[1] - res[1][1];
    if (res.SelectMany(aa => aa).Distinct().Count(x => x>=1 && x<=9)<4 || res[0][1]+res[1][1] != c[1] || res[0][0]+res[1][1] != d[0] || res[0][1]+res[1][0] != d[1]) { Console.Write(-1); return; }

    Console.WriteLine("{0} {1}", res[0][0], res[0][1]);
    Console.WriteLine("{0} {1}", res[1][0], res[1][1]);
  }
}


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

class Startup
{
    static void Main()
    {
        int[] intInput = ReadLineAndParseToArray();
        int n = intInput[0];
        int nTemp = n;
        int m = intInput[1];

        if(n == m) { Console.WriteLine($"0"); return; }
        if((m % 2*n != 0 || m < 2*n ) && ( m % 3*n != 0 || m < 3*n) && ( m % 6*n != 0 || m < 6*n))  { Console.WriteLine("-1"); return; }

        int counter2 = 0;
        int counter3 = 0;
        while(nTemp % 2 == 0) { nTemp /= 2; counter2++; }
        while(nTemp % 3 == 0) { nTemp /= 3; counter3++; }

        int counter22 = 0;
        int counter33 = 0;
        while(m % 2 == 0 ) { m /= 2; counter22++; }
        while(m % 3 == 0) { m /= 3; counter33++; }
        counter22 -= counter2;
        counter33 -= counter3;
        for(int i = 0; i < counter22; i++){
            n *= 2;
        }
        for(int i = 0 ; i < counter33; i++){
            n *= 3;
        }
        if(n != m) { Console.WriteLine("-1"); return; }
        counter = counter22 + counter33 - counter2 - counter3;
        Console.WriteLine($"{counter}");

    }

    static int[] ReadLineAndParseToArray()
    {
        return Console.ReadLine().Split().Select(int.Parse).ToArray();
    }

}


using System;

namespace CF_SoldierAndBanana {
    class Program {
        static void Main(string[] args) {
            string[] inputs = Console.ReadLine().Split(' ');
            short startprice = Int16.Parse(inputs[0]);
            short cash = Int16.Parse(inputs[1]);
            short bananacount = Int16.Parse(inputs[2]);
            if ((startprice * bananacount * (bananacount + 1) / 2) > cash) {
                Console.WriteLine((startprice * bananacount * (bananacount + 1) / 2) - cash);
                return;
            }
            Console.WriteLine(0);
        }
    }
}


using System;

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

            if (n == m)
            {
                System.Console.WriteLine(0);
                return;
            }

            int maxGroups = n / 2;
            int maxGroupsGap = n % 2 != 0 ? 1 : 0;

            if (m < maxGroups)
            {
                System.Console.WriteLine(m + 1);
                return;
            }

            if (m > maxGroups + maxGroupsGap)
            {
                System.Console.WriteLine(maxGroups - (m - maxGroups - maxGroupsGap));
                return;
            }

            System.Console.WriteLine(maxGroups);
        }
    }
}


using System;

namespace testrun
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] values = Console.ReadLine().Split(' ');
            int n = int.Parse(values[0]);
            int m = int.Parse(values[1]);

            if (n == m)
            {
                System.Console.WriteLine(0);
                return;
            }

            int maxGroups = n / 2;
            int maxGroupsGap = n % 2 != 0 ? 1 : 0;

            if (m < maxGroups)
            {
                System.Console.WriteLine(m);
                return;
            }

            if (m > maxGroups + maxGroupsGap)
            {
                System.Console.WriteLine(maxGroups - (m - maxGroups - maxGroupsGap));
                return;
            }

            System.Console.WriteLine(maxGroups);
        }
    }
}


<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{25B6AE56-020D-4B7D-824A-5834F25493CD}</ProjectGuid>
    <OutputType>Exe</OutputType>
    <RootNamespace>_825</RootNamespace>
    <AssemblyName>825</AssemblyName>
    <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Net.Http" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Program.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <ItemGroup>
    <None Include="App.config" />
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>


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

namespace TestConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            var data = GetInput();
            SolveProblem(data);
        }

        public static void SolveProblem(List<string> input)
        {
            var inputLine = input[0] + input[1] + input[2];
            if (IsIllegalState(inputLine))
            {
                Console.WriteLine("illegal");
                return;
            }
            else
            {
                var positionData = GetCountAndPositions(inputLine);
                int xWonStateCount = IsWonPosition(positionData['X'].Item1);
                int zeroWonStateCount = IsWonPosition(positionData['0'].Item1);
                if (xWonStateCount > 0 && zeroWonStateCount == 0)
                {
                    Console.WriteLine("the first player won");
                    return;
                }
                else if (xWonStateCount == 0 && zeroWonStateCount > 0)
                {
                    Console.WriteLine("the second player won");
                    return;
                }
                else
                {
                    if (xWonStateCount == 0 && zeroWonStateCount == 0 && positionData['.'].Item2 == 0)
                    {
                        Console.WriteLine("draw");
                        return;
                    }
                    else if (positionData['.'].Item2 > 0)
                    {
                        if (positionData['X'].Item2 > positionData['0'].Item2)
                        {
                            Console.WriteLine("second");
                            return;
                        }
                        else
                        {
                            Console.WriteLine("first");
                            return;
                        }
                    }
                }
            }
        }

        public static List<string> GetInput()
        {
            var list = new List<string>();
            list.Add(Console.ReadLine());
            list.Add(Console.ReadLine());
            list.Add(Console.ReadLine());
            return list;
        }

        private static List<string> GetWonStateIndices()
        {
            var wonStates = new List<string>();
            wonStates.Add("0,1,2");
            wonStates.Add("3,4,5");
            wonStates.Add("6,7,8");
            wonStates.Add("0,3,6");
            wonStates.Add("1,4,7");
            wonStates.Add("2,5,8");
            wonStates.Add("0,4,8");
            wonStates.Add("2,4,6");
            return wonStates;
        }

        private static int IsWonPosition(string input)
        {
            int wonStateCount = 0;
            var wonStates = GetWonStateIndices();
            foreach (var state in wonStates)
            {
                bool isStatePresent = true;
                var positions = state.Split(',');
                foreach (var position in positions)
                {
                    if (!input.Contains(position))
                    {
                        isStatePresent = false;
                        break;
                    }
                }
                if (isStatePresent)
                    wonStateCount++;
            }
            return wonStateCount;
        }

        public static bool IsIllegalState(string input)
        {
            int xWonStateCount = 0;
            int zeroWonStateCount = 0;
            var positionData = GetCountAndPositions(input);
            if (positionData['0'].Item2 > positionData['X'].Item2)
                return true;
            if (Math.Abs(positionData['X'].Item2 - positionData['0'].Item2) > 1)
                return true;
            if (positionData['X'].Item2 > 5 || positionData['0'].Item2 > 4)
                return true;
            if (positionData['X'].Item2 >= 3)
            {
                xWonStateCount = IsWonPosition(positionData['X'].Item1);
                if (xWonStateCount > 1)
                    return true;
            }

            if (positionData['0'].Item2 >= 3)
            {
                zeroWonStateCount = IsWonPosition(positionData['0'].Item1);
                if (zeroWonStateCount > 1)
                    return true;
            }
            if (xWonStateCount > 0 && zeroWonStateCount > 0)
                return true;
            return false;
        }

        private static Dictionary<char, Tuple<string, int>> GetCountAndPositions(string input)
        {
            var zeroBuilder = new StringBuilder();
            var xBuilder = new StringBuilder();
            var dotBuilder = new StringBuilder();
            int zeroCount = 0;
            int xCount = 0;
            int dotCount = 0;
            for (int i = 0; i < input.Length; i++)
            {
                if (input[i] == '0')
                {
                    zeroBuilder.Append(i.ToString() + ",");
                    zeroCount++;
                }
                else if (input[i] == 'X')
                {
                    xBuilder.Append(i.ToString() + ",");
                    xCount++;
                }
                else
                {
                    dotBuilder.Append(i.ToString() + ",");
                    dotCount++;
                }
            }
            zeroBuilder.Remove(zeroBuilder.Length - 1, 1);
            xBuilder.Remove(xBuilder.Length - 1, 1);
            dotBuilder.Remove(dotBuilder.Length - 1, 1);

            var data = new Dictionary<char, Tuple<string, int>>();
            data.Add('0', Tuple.Create(zeroBuilder.ToString(), zeroCount));
            data.Add('X', Tuple.Create(xBuilder.ToString(), xCount));
            data.Add('.', Tuple.Create(dotBuilder.ToString(), dotCount));
            return data;
        }
    }
}


using System;

namespace _3A_TicTacToe
{

    class Program
    {
        static bool IsValidCoord(int x, int y)
        {
            if (x < 0 || x >= 3) return false;
            if (y < 0 || y >= 3) return false;
            return true;
        }
        static bool CheckWin(string[] grid, char val)
        {
            int[] dx = new int[] { -1, 0, 1, -1, 1, -1, 0, 1 };
            int[] dy = new int[] { -1, -1, -1, 0, 0, 1, 1, 1 };

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

                    if (grid[i][j] == val)
                    {
                        int numCellInLine = 0;

                        //move next state
                        for (int k = 0; k < dx.Length; k++)
                        {
                            var x = i;
                            var y = j;
                            while (IsValidCoord(x, y) && grid[x][y] == val)
                            {
                                x += dx[k];
                                y += dy[k];
                                ++numCellInLine;
                            }
                            //check if win
                            if (numCellInLine == 3) return true;
                            else numCellInLine = 0;

                        }

                    }

                }
            }

            return false;
        }
        static void Print(string status)
        {
            System.Console.WriteLine(status);
        }
        static void Main(string[] args)
        {
            //input
            int k = -1;
            var grid = new string[3];
            for (int i = 0; i < 3; i++)
            {
                grid[i] = args[++k];
            }

            //counting
            int num0 = 0;
            int numX = 0;

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (grid[i][j] == 'X') ++numX;
                    if (grid[i][j] == '0') ++num0;
                }
            }

            //process
            bool isXWin = CheckWin(grid, 'X');
            bool is0Win = CheckWin(grid, '0');
            if (Math.Abs(num0 - numX) >= 2 || num0 > numX || (is0Win && isXWin)
                ||(isXWin && num0 == numX)   /*X win but O still play*/
                || (is0Win && numX > num0))  /*O win but X still play*/
                Print("illegal");
            else if(isXWin) Print("the first player won");
            else if(is0Win) Print("the second player won");
            else if(num0 + numX == 9) Print("draw");
            else
            {
                if (num0 >= numX) Print("first");
                else Print("second");
            }

        }
    }
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static long xwin(long[,] z)
        {
            int count = 0;
            for (long i = 0; i < 3; i++)
                if (z[i, 0] == 1 && z[i, 1] == 1 && z[i, 2] == 1)
                    count++;
            for (long j = 0; j < 3; j++)
                if (z[0, j] == 1 && z[1, j] == 1 && z[2, j] == 1)
                    count++;
            if (z[0, 0] == 1 && z[1, 1] == 1 && z[2, 2] == 1)
                count++;
            if (z[0, 2] == 1 && z[1, 1] == 1 && z[2, 0] == 1)
                count++;
            return count;
        }
        static long owin(long[,] z)
        {
            int count = 0;
            for (long i = 0; i < 3; i++)
                if (z[i, 0] == 2 && z[i, 1] == 2 && z[i, 2] == 2)
                    count++;
            for (long j = 0; j < 3; j++)
                if (z[0, j] == 2 && z[1, j] == 2 && z[2, j] == 2)
                    count++;
            if (z[0, 0] == 2 && z[1, 1] == 2 && z[2, 2] == 2)
                count++;
            if (z[0, 2] == 2 && z[1, 1] == 2 && z[2, 0] == 2)
                count++;
            return count;
        }
        static void delay(long i)
        {
            for (long j = 0; j < i; j++)
                delay(i - 1);
        }
        static bool check(long[,] z)
        {
            long countx = 0, counto = 0;
            for (long i = 0; i < 3; i++)
            {
                for (long j = 0; j < 3; j++)
                {
                    if (z[i, j] == 1)
                        countx++;
                    if (z[i, j] == 2)
                        counto++;
                }
            }
            if (counto > countx)
                return false;
            if (countx - counto > 1)
                return false;
            if (xwin(z) > 0 || owin(z) > 0)
                return false;
            return true;
        }
        static bool legal(long[,] z)
        {
            for (long i = 0; i < 3; i++)
            {
                for (long j = 0; j < 3; j++)
                {
                    if (z[i, j] == 0)
                        continue;
                    long temp = z[i, j];
                    z[i, j] = 0;
                    if(check(z))
                    {
                        z[i,j]=temp;
                        return true;
                    }
                    z[i, j] = temp;
                }
            }
            return false;
        }
        static void Main(string[] args)
        {
            long[,] z = new long[3, 3];
            for (long i = 0; i < 3; i++)
            {
                string s = Console.ReadLine();
                for (int j = 0; j < 3; j++)
                {
                    z[i, j] = 0;
                    if (s[j] == 'X')
                        z[i, j] = 1;
                    if (s[j] == '0')
                        z[i, j] = 2;
                }
            }
            long countx = 0, count0 = 0;
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (z[i, j] == 1)
                        countx++;
                    if (z[i, j] == 2)
                        count0++;
                }
            }
            if (!legal(z))
            {
                Console.WriteLine("illegal");
                return;
            }
            if (xwin(z) == 1)
            {
                delay(1000);
                Console.WriteLine("the first player won");
                return;
            }
            if (owin(z) == 1)
            {
                delay(1000);
                Console.WriteLine("the second player won");
                return;
            }
            if (countx + count0 == 9)
            {
                delay(1000);
                Console.WriteLine("draw");
                return;
            }
            if (countx - count0 == 0)
            {
                Console.WriteLine("first");
                return;
            }
            Console.WriteLine("second");
        }
    }
}


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

namespace CodeForceContest
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().Split(' ').Select(ss => int.Parse(ss)).ToArray();
            //var s = "401 4".Split(' ').Select(ss => int.Parse(ss)).ToArray();
            var a = s[0];
            var b = s[1];
            var res = a + 1;
            for (; ; )
            {
                if(TakeMask(res)==b)
                {
                    break;
                }
            }
            Console.WriteLine(res);
        }
        static int TakeMask(int a)
        {
            var e = a.ToString();
            var list = new List<char>();
            foreach (var i in e)
            {
                if(i=='4' ||i=='7')list.Add(i);
            }
            return int.Parse(String.Join("", list.Select(s => s.ToString()).ToArray()));
        }
    }

}


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

namespace problemB
{
    class Program
    {
        static bool Contain47(int a)
        {
            int am10;
            while (a > 0)
            {
                am10=a%10;
                if (am10 == 4 || am10 == 7)
                    return true;
                a /= 10;
            }
            return false;
        }

        static void Main(string[] args)
        {
            int[] data = Array.ConvertAll<string, int>(Console.ReadLine().Split(), int.Parse);
            int a = data[0], b = data[1];
            int coef = 1;
            if (b < 10) coef = 10;
            else if (b < 100) coef = 100;
            else if (b < 1000) coef = 1000;
            else coef = 10000;
            int first = 0;
            while (true)
            {
                if (Contain47(first)) continue;
                if (first * coef + b > a)
                {
                    Console.WriteLine("{0}", first*coef+b);
                    break;
                }
                first++;
            }
        }
    }
}


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

namespace starwars
{
    class Program
    {
        static void Main(string[] args)
        {
            int n;

            n = Convert.ToInt32 (Console.ReadLine());
            char[,] array1 = new char[n, n];
            for (int i = 0; i <= n - 1; i++)
            {
               char[] temp =   Console.ReadLine().ToCharArray();
                for (int j = 0; j <= n - 1; j++)
                {
                    array1[i, j] = temp[j];
                }
            }
            char[,] array2 = new char[n, n];
            for (int i = 0; i <= n - 1; i++)
            {
                char[] temp = Console.ReadLine().ToCharArray();
                for (int j = 0; j <= n - 1; j++)
                {
                    array2[i, j] = temp[j];
                }
            }

                char[,] t90 = new char[n, n];
            for(int i = 0; i<=n-1;i++)
            {
                for (int j = 0; j <= n - 1; j++)
                    t90[j, n - 1 - i] = array1[i, j];
            }

            char[,] t180 = new char[n, n];
            for (int i = 0; i <= n - 1; i++)
            {
                for (int j = 0; j <= n - 1; j++)
                    t180[j, n - 1 - i] = t90[i, j];
            }

            char[,] t270 = new char[n, n];
            for (int i = 0; i <= n - 1; i++)
            {
                for (int j = 0; j<=n-1; j++)
                t270[j, n - 1 - i] = t180[i, j];
            }

            char[,] flippGorarray1 = new char[n, n];
            for (int i = 0; i <= n - 1; i++)
            {
                for (int j = 0; j <= n - 1; j++)
                    flippGorarray1[n - 1 - i, j] = array1[i, j];
            }

            char[,] flippvertarray1 = new char[n, n];
            for (int i = 0; i <= n - 1; i++)
            {
                for (int j = 0; j <= n - 1; j++)
                    flippvertarray1[i, n-1-j] = array1[i, j];
            }

            char[,] flippGort90 = new char[n, n];
            for (int i = 0; i <= n - 1; i++)
            {
                for (int j = 0; j <= n - 1; j++)
                    flippGort90[n - 1 - i, j] = t90[i, j];
            }

            char[,] flippvert90 = new char[n, n];
            for (int i = 0; i <= n - 1; i++)
            {
                for (int j = 0; j <= n - 1; j++)
                    flippvert90[i, n - 1 - j] = t90[i, j];
            }

            char[,] flippGort180 = new char[n, n];
            for (int i = 0; i <= n - 1; i++)
            {
                for (int j = 0; j <= n - 1; j++)
                    flippGort180[n - 1 - i, j] = t180[i, j];
            }

            char[,] flippvert180 = new char[n, n];
            for (int i = 0; i <= n - 1; i++)
            {
                for (int j = 0; j <= n - 1; j++)
                    flippvert180[i, n - 1 - j] = t180[i, j];
            }

            char[,] flippGorart270 = new char[n, n];
            for (int i = 0; i <= n - 1; i++)
            {
                for (int j = 0; j <= n - 1; j++)
                    flippGorart270[n - 1 - i, j] = t270[i, j];
            }

            char[,] flippvert270 = new char[n, n];
            for (int i = 0; i <= n - 1; i++)
            {
                for (int j = 0; j <= n - 1; j++)
                    flippvert270[i, n - 1 - j] = t270[i, j];
            }

            if (array2.ToString()== array1.ToString() || array2.ToString()== t90.ToString() || array2.ToString()== t180.ToString() ||
                array2.ToString()== t270.ToString() ||
                array2.ToString()== flippGorarray1.ToString() || array2.ToString()== flippvertarray1.ToString() ||
                array2.ToString() == flippGort90.ToString()||
                array2.ToString() == flippvert90.ToString()|| array2.ToString() == flippGort180.ToString() ||
                array2.ToString() == flippvert180.ToString()||
                array2.ToString() == flippGorart270.ToString() || array2.ToString() == flippvert270.ToString())
            {
                Console.WriteLine("Yes");
            }
            else Console.WriteLine("No");

        }

    }
}


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

class Program
{
    public static int[] Read(string str)
    {
        string[] tokens = str.Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        int[] ret = new int[tokens.Length];
        for (int i = 0; i < ret.Length; i++)
        {
            ret[i] = int.Parse(tokens[i]);
        }

        return ret;
    }

    public static long[] ReadLong(string str)
    {
        string[] tokens = str.Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        long[] ret = new long[tokens.Length];
        for (int i = 0; i < ret.Length; i++)
        {
            ret[i] = long.Parse(tokens[i]);
        }

        return ret;
    }

    public static double[] ReadDouble(string str)
    {
        string[] tokens = str.Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        double[] ret = new double[tokens.Length];
        for (int i = 0; i < ret.Length; i++)
        {
            ret[i] = double.Parse(tokens[i], CultureInfo.InvariantCulture);
        }

        return ret;
    }

    static string Reverse(string s)
    {
        char[] a = s.ToCharArray();
        Array.Reverse(a);
        return new string(a);
    }

    static bool Check(string t)
    {
        for (int i = 0; i < t.Length; i++)
        {
            if (char.IsLetterOrDigit(t[i]) == false && t[i] != '_')
            {
                return false;
            }
        }

        return true;
    }

    static void Main(string[] args)
    {
        int[] abc = Read(Console.ReadLine());
        int[] def = Read(Console.ReadLine());

        if (abc[0] * def[1] == abc[1] * def[0])
        {
            if (abc[0] * def[2] == abc[2] * def[0] && abc[1] * def[2] == abc[2] * def[1])
            {
                Console.WriteLine("-1");
            }
            else
            {
                Console.WriteLine("0");
            }
        }
        else
        {
            Console.WriteLine("1");
        }
    }
}


using System;
using System.Linq;

namespace codeforces
{
    class Program
    {
        static bool IsGood(int ch)
        {
            while(ch>0)
            {
                if (ch % 10 != 4 && ch % 10 != 7)
                    return false;
                ch = ch / 10;
            }
            return true;
        }
        static void Main(string[] args)
        {
            int count = int.Parse(Console.ReadLine());
            string str = Console.ReadLine();
            int a = str.Substring(0, count / 2).Select(x => int.Parse(x.ToString())).Sum();
            int b = str.Substring(count / 2).Select(x => int.Parse(x.ToString())).Sum();

            Console.WriteLine(IsGood(int.Parse(str))&&(a==b)?"YES":"NO") ;
        }
    }
}


using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
//using DebugerVisualizer;

namespace _105
{

    class Program
    {
        //static StreamReader inStream = new StreamReader("input.txt");
        //static string ReadLine()
        //{
        //    return inStream.ReadLine();
        //}

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

        static int AbsoluteMax = int.MinValue;
        static string AbsoluteMaxStr = "";

        static void Main(string[] args)
        {
            Player[] players = new Player[3];
            for (int i = 0; i < 3; i++)
            {
                players[i] = new Player();
                string[] arg = ReadLine().Split();
                players[i].Start = int.Parse(arg[0]);
                players[i].Walk = int.Parse(arg[1]);
                players[i].Throws = int.Parse(arg[2]);
                players[i].StartNode = new ExpressionNode();
                players[i].StartNode.Comment = string.Format("S({0})", i);
            }

            var builder = new ExpressionBuilder(Array.ConvertAll(players, x => x.StartNode));
            Solve(builder, Array.ConvertAll(players, x => x.StartNode), players);
            Console.WriteLine(AbsoluteMax);
            //Console.WriteLine(AbsoluteMaxStr);
        }

        static void Solve(ExpressionBuilder builder, ExpressionNode[] pNodes, Player[] players)
        {
            builder.ClearCalcs();

            for (int i = 0; i < 3; i++)
                players[i].StartNode.Min = players[i].StartNode.Max = players[i].Start;

            for (int i = 0; i < 3; i++)
            {
                if (!TraceMin(players[i].StartNode))
                    return;
                if (!TraceMax(players[i].StartNode))
                    return;
            }

            if (!builder.Validate())
                return;

            int max = builder.Max;
            if (AbsoluteMax < max)
            {
                AbsoluteMax = max;
                AbsoluteMaxStr = builder.ToString();
            }

            for (int i = 0; i < 3; i++)
                for (int j = 0; j < 3; j++)
                    if (i != j)
                    {
                        DoUp(i, j, builder, pNodes, players);
                    }

            for (int i = 0; i < 3; i++)
            {
                DoMove(i, builder, pNodes, players);
            }

            for (int i = 0; i < 3; i++)
            {
                DoThrow(i, builder, pNodes, players);
            }
        }

        static private void DoMove(int i, ExpressionBuilder builder, ExpressionNode[] pNodes, Player[] players)
        {
            if (players[i].alreadyWalked || players[i].Up >= 0 || players[i].Upped)
                return;

            players[i].alreadyWalked = true;

            ExpressionNode a = pNodes[i];

            builder.Start();

            ExpressionNode moved = builder.AddNode();
            pNodes[i] = moved;
            moved.Comment = string.Format("M({0})", i);

            builder.AddMin(moved, a, players[i].Walk);
            builder.AddMin(a, moved, players[i].Walk);

            NotEqual(players, i, builder, pNodes);

            builder.Rollback();
            pNodes[i] = a;
            players[i].alreadyWalked = false;
        }

        private static void DoThrow(int i, ExpressionBuilder builder, ExpressionNode[] pNodes, Player[] players)
        {
            if (players[i].alreadyThrowed || players[i].Up < 0 || players[i].Upped)
                return;

            players[i].alreadyThrowed = true;

            int j = players[i].Up;
            players[i].Up = -1;
            players[j].Upped = false;

            ExpressionNode a = pNodes[i];
            ExpressionNode b = pNodes[j];

            builder.Start();

            ExpressionNode moved = builder.AddNode();
            pNodes[j] = moved;
            moved.Comment = string.Format("T({0}, {1})", i, j);

            builder.AddMin(moved, a, players[i].Throws);
            builder.AddMin(a, moved, players[i].Throws);

            NotEqual(players, j, builder, pNodes);

            builder.Rollback();
            pNodes[j] = b;
            players[j].Upped = true;
            players[i].Up = j;
            players[i].alreadyThrowed = false;
        }

        private static void DoUp(int i, int j, ExpressionBuilder builder, ExpressionNode[] pNodes, Player[] players)
        {
            if (players[i].alreadyUpped || players[i].Up >= 0 || players[i].Upped || players[j].Upped || i == j)
                return;

            players[i].alreadyUpped = true;
            players[i].Up = j;
            players[j].Upped = true;

            ExpressionNode a = pNodes[i];
            ExpressionNode b = pNodes[j];

            builder.Start();

            ExpressionNode moved = builder.AddNode();
            pNodes[j] = moved;
            moved.Comment = string.Format("U({0}, {1})", i, j);

            builder.AddMin(moved, a, 0);
            builder.AddMin(a, moved, 0);

            builder.Start();
            builder.AddMin(a, b, -1);
            builder.AddMin(b, a, 1);
            Solve(builder, pNodes, players);
            builder.Rollback();

            builder.Start();
            builder.AddMin(a, b, 1);
            builder.AddMin(b, a, -1);
            Solve(builder, pNodes, players);
            builder.Rollback();

            builder.Rollback();
            pNodes[j] = b;
            players[j].Upped = false;
            players[i].Up = -1;
            players[i].alreadyUpped = false;
        }

        static private void NotEqual(Player[] players, int i, ExpressionBuilder builder, ExpressionNode[] pNodes)
        {
            ExpressionNode a = pNodes[i]; //current
            ExpressionNode b = pNodes[(i + 1) % 3]; //not equal to
            ExpressionNode c = pNodes[(i + 2) % 3]; //and not equal to

            builder.Start();
            builder.AddMin(a, b, -1);
            builder.AddMin(a, c, -1);
            Solve(builder, pNodes, players);
            builder.Rollback();

            builder.Start();
            builder.AddMin(b, a, -1);
            builder.AddMin(a, c, -1);
            Solve(builder, pNodes, players);
            builder.Rollback();

            builder.Start();
            builder.AddMin(b, a, -1);
            builder.AddMin(c, a, -1);
            Solve(builder, pNodes, players);
            builder.Rollback();

            builder.Start();
            builder.AddMin(a, b, -1);
            builder.AddMin(c, a, -1);
            Solve(builder, pNodes, players);
            builder.Rollback();
        }

        static bool TraceMin(ExpressionNode x)
        {
            x.Traced = true;

            try
            {
                foreach (var path in x.Maximize)
                {
                    // x <= path.Max + path.Mark

                    if (path.Max.Traced)
                    {
                        if (path.Max.Min < x.Min - path.Mark)
                            return false;
                    }
                    else
                    {
                        if (path.Max.Min < x.Min - path.Mark)
                        {
                            path.Max.Min = x.Min - path.Mark;
                            if (!TraceMin(path.Max))
                                return false;
                        }
                    }
                }
                return true;
            }
            finally
            {
                x.Traced = false;
            }
        }

        static bool TraceMax(ExpressionNode x)
        {
            x.Traced = true;

            try
            {
                foreach (var path in x.Minimize)
                {
                    if (path.Min.Traced)
                    {
                        if (path.Min.Max > x.Max + path.Mark)
                            return false;
                    }
                    else
                    {
                        if (path.Min.Max > x.Max + path.Mark)
                        {
                            path.Min.Max = x.Max + path.Mark;
                            if (!TraceMax(path.Min))
                                return false;
                        }
                    }
                }
                return true;
            }
            finally
            {
                x.Traced = false;
            }
        }
    }

    //[DebuggerVisualizer(typeof(ExpressionBuilderVisualizer))]
    [Serializable]
    class ExpressionBuilder
    {
        Stack<Actions> actions = new Stack<Actions>();
        Actions current = null;
        List<ExpressionNode> nodes = new List<ExpressionNode>();
        List<ExpressionPath> paths = new List<ExpressionPath>();

        public List<ExpressionNode> Nodes
        {
            get { return nodes; }
        }

        public List<ExpressionPath> Paths
        {
            get { return paths; }
        }

        public ExpressionBuilder(IEnumerable<ExpressionNode> startNodes)
        {
            nodes.AddRange(startNodes);
        }

        public int Max
        {
            get
            {
                int max = Int32.MinValue;
                foreach (var node in nodes)
                {
                    if (max < node.Max)
                        max = node.Max;
                }

                return max;
            }
        }

        public ExpressionNode AddNode()
        {
            var node = new ExpressionNode();
            nodes.Add(node);
            current.Nodes.Add(node);
            return node;
        }

        //a <= b + c
        public void AddMin(ExpressionNode a, ExpressionNode b, int c)
        {
            var path = new ExpressionPath() { Min = a, Max = b, Mark = c };
            paths.Add(path);
            a.Maximize.Add(path);
            b.Minimize.Add(path);
            current.Paths.Add(path);
        }

        public void Start()
        {
            current = new Actions();
            actions.Push(current);
        }

        public void Rollback()
        {
            RollbackActions(current);
            actions.Pop();
            if (actions.Count > 0)
                current = actions.Peek();
            else
                current = null;
        }

        private void RollbackActions(Actions action)
        {
            //int nc = nodes.Count;
            //int pc = paths.Count;

            if (action.Paths.Count > 0)
                paths.RemoveRange(paths.Count - action.Paths.Count, action.Paths.Count);
            if (action.Nodes.Count > 0)
                nodes.RemoveRange(nodes.Count - action.Nodes.Count, action.Nodes.Count);

            //Debug.Assert(!paths.Exists(x => action.Paths.Contains(x)));
            //Debug.Assert(!nodes.Exists(x => action.Nodes.Contains(x)));

            //System.Diagnostics.Debug.Assert(paths.Count == pc - action.Paths.Count);
            //System.Diagnostics.Debug.Assert(nodes.Count == nc - action.Nodes.Count);

            foreach (var p in action.Paths)
            {
                p.Max.Minimize.Remove(p);
                p.Min.Maximize.Remove(p);
            }
        }

        public void ClearCalcs()
        {
            foreach (var node in nodes)
            {
                node.Min = Int32.MinValue;
                node.Max = Int32.MaxValue;
                node.Traced = false;
            }
        }

        public bool Validate()
        {
            foreach (var node in nodes)
            {
                if (node.Min > node.Max)
                    return false;

                if (node.Min == Int32.MinValue || node.Min == Int32.MaxValue)
                    throw new Exception();
                if (node.Max == Int32.MinValue || node.Max == Int32.MaxValue)
                    throw new Exception();
            }

            return true;
        }

        public override string ToString()
        {
            string result = "";

            foreach (var node in nodes)
            {
                result += node.ToString();
            }

            result += "{";
            foreach (var path in paths)
            {
                result += String.Format("{0} <= {1} + {2}; ", path.Min, path.Max, path.Mark);
            }
            result += "}";

            return result;
        }
    }

    [Serializable]
    class Actions
    {
        public List<ExpressionNode> Nodes = new List<ExpressionNode>(10);
        public List<ExpressionPath> Paths = new List<ExpressionPath>(10);
    }

    [Serializable]
    internal class Player
    {
        public int Start;
        public int Walk;
        public int Throws;

        public bool alreadyWalked = false;
        public bool alreadyUpped = false;
        public bool alreadyThrowed = false;
        public bool Upped = false;
        public int Up = -1;
        public ExpressionNode StartNode;
    }

    [Serializable]
    class ExpressionNode
    {
        public List<ExpressionPath> Minimize = new List<ExpressionPath>(10);
        public List<ExpressionPath> Maximize = new List<ExpressionPath>(10);

        public int Min = Int32.MinValue;
        public int Max = Int32.MaxValue;

        public bool Traced = false;

        public string Comment;

        public override string ToString()
        {
            return Comment + String.Format("[{0}:{1}]", Min, Max);
        }
    }

    [Serializable]
    internal class ExpressionPath
    {
        public ExpressionNode Max;
        public ExpressionNode Min;
        public int Mark;

        public override string ToString()
        {
            return  String.Format("{0} <= {1} + {2}", Min, Max, Mark);
        }
    }
}


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
//using DebugerVisualizer;

namespace _105
{

	class Program
	{
		//static StreamReader inStream = new StreamReader("input.txt");
		//static string ReadLine()
		//{
		//    return inStream.ReadLine();
		//}

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

		static int AbsoluteMax = int.MinValue;
		static string AbsoluteMaxStr = "";

		static void Main(string[] args)
		{
			Player[] players = new Player[3];
			for (int i = 0; i < 3; i++)
			{
				players[i] = new Player();
				string[] arg = ReadLine().Split();
				players[i].Start = int.Parse(arg[0]);
				players[i].Walk = int.Parse(arg[1]);
				players[i].Throws = int.Parse(arg[2]);
			}

			var state = new GameState(players);

			Solve(state, players);
			Console.WriteLine(AbsoluteMax);
			//Console.WriteLine(AbsoluteMaxStr);
		}

		static void Solve(GameState state, Player[] players)
		{
			state.ClearTrace();
			for (int i = 0; i < 3; i++)
			{
				if (!TraceMin(state, state.GetPlayerStartNode(i)))
					return;
				if (!TraceMax(state, state.GetPlayerStartNode(i)))
					return;
			}

			if (!state.Validate())
				return;

			if (EuristicGetMax(state, players) <= AbsoluteMax)
				return;

			int max = state.Max;
			if (AbsoluteMax < max)
			{
				AbsoluteMax = max;
				AbsoluteMaxStr = state.ToString();
			}

			for (int i = 0; i < 3; i++)
			{
				DoMove(i, state.Clone(), players);
			}

			for (int i = 0; i < 3; i++)
				for (int j = 0; j < 3; j++)
					if (i != j)
					{
						DoUp(i, j, state.Clone(), players);
					}

			for (int i = 0; i < 3; i++)
			{
				DoThrow(i, state.Clone(), players);
			}
		}

		static private void DoMove(int i, GameState state, Player[] players)
		{
			if (players[i].alreadyWalked || players[i].Up >= 0 || players[i].Upped)
				return;

			players[i].alreadyWalked = true;

			ExpressionNode a = state.GetPlayerNode(i);
			ExpressionNode moved = state.AddPlayerNode(i);

			moved.Comment = string.Format("M({0})", i);

			state.AddMin(moved, a, players[i].Walk);
			state.AddMin(a, moved, players[i].Walk);

			NotEqual(players, i, state.Clone());

			players[i].alreadyWalked = false;
		}

		private static void DoThrow(int i, GameState state, Player[] players)
		{
			if (players[i].alreadyThrowed || players[i].Up < 0 || players[i].Upped)
				return;

			players[i].alreadyThrowed = true;

			int j = players[i].Up;
			players[i].Up = -1;
			players[j].Upped = false;

			ExpressionNode a = state.GetPlayerNode(i);

			ExpressionNode moved = state.AddPlayerNode(j);
			moved.Comment = string.Format("T({0}, {1})", i, j);

			state.AddMin(moved, a, players[i].Throws);
			state.AddMin(a, moved, players[i].Throws);

			NotEqual(players, j, state.Clone());

			players[j].Upped = true;
			players[i].Up = j;
			players[i].alreadyThrowed = false;
		}

		private static void DoUp(int i, int j, GameState state, Player[] players)
		{
			if (players[i].alreadyUpped || players[i].Up >= 0 || players[i].Upped || players[j].Upped || i == j)
				return;

			players[i].alreadyUpped = true;
			players[i].Up = j;
			players[j].Upped = true;

			ExpressionNode a = state.GetPlayerNode(i);
			ExpressionNode b = state.GetPlayerNode(j);

			ExpressionNode moved = state.AddPlayerNode(j);
			moved.Comment = string.Format("U({0}, {1})", i, j);

			state.AddMin(moved, a, 0);
			state.AddMin(a, moved, 0);

			var v1 = state.Clone();
			v1.AddMin(a, b, -1);
			v1.AddMin(b, a, 1);
			Solve(v1, players);

			var v2 = state;
			v2.AddMin(a, b, 1);
			v2.AddMin(b, a, -1);
			Solve(v2.Clone(), players);

			players[j].Upped = false;
			players[i].Up = -1;
			players[i].alreadyUpped = false;
		}

		static private void NotEqual(Player[] players, int i, GameState state)
		{
			ExpressionNode a = state.GetPlayerNode(i); //current
			ExpressionNode b = state.GetPlayerNode((i + 1) % 3); //not equal to
			ExpressionNode c = state.GetPlayerNode((i + 2) % 3); //and not equal to

			var v1 = state.Clone();
			v1.AddMin(a, b, -1);
			v1.AddMin(a, c, -1);
			Solve(v1, players);

			var v2 = state.Clone();
			v2.AddMin(b, a, -1);
			v2.AddMin(a, c, -1);
			Solve(v2, players);

			var v3 = state.Clone();
			v3.AddMin(b, a, -1);
			v3.AddMin(c, a, -1);
			Solve(v3, players);

			var v4 = state;
			v4.AddMin(a, b, -1);
			v4.AddMin(c, a, -1);
			Solve(v4, players);
		}

		static bool TraceMin(GameState state, ExpressionNode x)
		{
			x.Traced = true;

			try
			{
				foreach (var vector in state.Maximize(x))
				{
					// x <= path.Max + path.Mark

					if (vector.Target.Traced)
					{
						if (vector.Target.Min < x.Min - vector.Mark)
							return false;
					}
					else
					{
						if (vector.Target.Min < x.Min - vector.Mark)
						{
							vector.Target.Min = x.Min - vector.Mark;
							if (!TraceMin(state, vector.Target))
								return false;
						}
					}
				}
				return true;
			}
			finally
			{
				x.Traced = false;
			}
		}

		static bool TraceMax(GameState state, ExpressionNode x)
		{
			x.Traced = true;

			try
			{
				foreach (var vector in state.Minimize(x))
				{
					if (vector.Target.Traced)
					{
						if (vector.Target.Max > x.Max + vector.Mark)
							return false;
					}
					else
					{
						if (vector.Target.Max > x.Max + vector.Mark)
						{
							vector.Target.Max = x.Max + vector.Mark;
							if (!TraceMax(state, vector.Target))
								return false;
						}
					}
				}
				return true;
			}
			finally
			{
				x.Traced = false;
			}
		}

		static int EuristicGetMax(GameState state, Player[] players)
		{
			int radius = 0;

			for (int i = 0; i < 3; i++)
			{
				if (!players[i].alreadyThrowed)
					radius += players[i].Throws;
				if (!players[i].alreadyWalked)
					radius += players[i].Walk;
				if (!players[i].alreadyUpped)
					radius += 1;
			}

			var result = Enumerable.Range(0,2).Max(i => state.GetPlayerNode(i).Max + radius);
			return result;
		}
	}

	[Serializable]
	struct Vector
	{
		public int Mark;
		public ExpressionNode Target;

		public Vector(int mark, ExpressionNode target)
		{
			Mark = mark;
			Target = target;
		}
	}

	//[DebuggerVisualizer(typeof(ExpressionBuilderVisualizer))]
	[Serializable]
	class GameState
	{
		const int MaxVariables = 20;
		const int MaxDepth = 20;

		List<ExpressionNode> nodes = new List<ExpressionNode>();
		int[] playerNodes = new int[3];

		public List<ExpressionNode> Nodes
		{
			get { return nodes; }
		}

		private GameState()
		{
		}

		public void ClearTrace()
		{
			for (int i = 3; i < nodes.Count; i++)
			{
				nodes[i].Min = int.MinValue;
				nodes[i].Max = int.MaxValue;
			}
		}

		public GameState(Player[] players)
		{
			for (int i = 0; i < 3; i++)
			{
				nodes.Add(
					new ExpressionNode()
					{
						Id = i,
						Min = players[i].Start,
						Max = players[i].Start
					});
				playerNodes[i] = i;
			}
		}

		public GameState Clone()
		{
			var result = new GameState();
			result.nodes  = nodes.ConvertAll(x => x.Clone());
			result.playerNodes = (int[])playerNodes.Clone();
			return result;
		}

		public int Max
		{
			get
			{
				int max = Int32.MinValue;
				foreach (var node in nodes)
				{
					if (max < node.Max)
						max = node.Max;
				}

				return max;
			}
		}

		public ExpressionNode AddPlayerNode(int i)
		{
			var node = new ExpressionNode() { Id = nodes.Count };
			nodes.Add(node);
			playerNodes[i] = node.Id;
			return node;
		}

		public ExpressionNode GetPlayerNode(int i)
		{
			return nodes[playerNodes[i]];
		}

		public ExpressionNode GetPlayerStartNode(int i)
		{
			return nodes[i];
		}

		//a <= b + c
		public void AddMin(ExpressionNode a, ExpressionNode b, int c)
		{
			var path = new ExpressionPath() { MinId = a.Id, MaxId = b.Id, Mark = c };
			nodes[a.Id].Maximize.Add(path);
			nodes[b.Id].Minimize.Add(path);
		}

		public IEnumerable<Vector> Maximize(ExpressionNode a)
		{
			return nodes[a.Id].Maximize.Select(path => new Vector(path.Mark, nodes[path.MaxId]));
		}

		public IEnumerable<Vector> Minimize(ExpressionNode a)
		{
			return nodes[a.Id].Minimize.Select(path => new Vector(path.Mark, nodes[path.MinId]));
		}

		public bool Validate()
		{
			foreach (var node in nodes)
			{
				if (node.Min > node.Max)
					return false;

				if (node.Min == Int32.MinValue || node.Min == Int32.MaxValue)
					throw new Exception();
				if (node.Max == Int32.MinValue || node.Max == Int32.MaxValue)
					throw new Exception();
			}

			return true;
		}

		public override string ToString()
		{
			string result = "";

			foreach (var node in nodes)
			{
				result += node.ToString();
			}

			return result;
		}
	}

	[Serializable]
	internal class Player
	{
		public int Start;
		public int Walk;
		public int Throws;

		public bool alreadyWalked = false;
		public bool alreadyUpped = false;
		public bool alreadyThrowed = false;
		public bool Upped = false;
		public int Up = -1;

		public Player Clone()
		{
			var result = (Player)this.MemberwiseClone();
			return result;
		}
	}

	[Serializable]
	class ExpressionNode
	{
		public int Id;
		public List<ExpressionPath> Minimize = new List<ExpressionPath>();
		public List<ExpressionPath> Maximize = new List<ExpressionPath>();

		public int Min = Int32.MinValue;
		public int Max = Int32.MaxValue;

		public bool Traced = false;

		public string Comment;

		public ExpressionNode Clone()
		{
			var result = (ExpressionNode)this.MemberwiseClone();
			result.Minimize = new List<ExpressionPath>(Minimize);
			result.Maximize = new List<ExpressionPath>(Maximize);
			result.Minimize = Minimize.ConvertAll(x => x);
			result.Maximize = Maximize.ConvertAll(x => x);

			return result;
		}

		public override string ToString()
		{
			return Comment + String.Format("[{0}:{1}]", Min, Max);
		}

	}

	[Serializable]
	[ReadOnly(true)]
	struct ExpressionPath
	{
		public int MaxId;
		public int MinId;
		public int Mark;

		public override string ToString()
		{
			var result = String.Format("X{0} <= X{1}", MinId, MaxId);

			if (Mark > 0)
				result += string.Format(" + {0}", Mark);
			else if (Mark < 0)
				result += string.Format(" - {0}", -Mark);

			return result;
		}
	}
}


#include <stdio.h>
void main()
{
    int n, m, moves;
    scanf("%d %d", &n , &m);

    if(m <=n)
    {
    moves = (n % 2) + (n / 2);
        while(moves % m != 0)
            moves++;

    printf("%d", moves);
    }
    else
        printf("-1");
}


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

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

            int[] presents = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            Array.Sort(presents);

            int answer = int.MaxValue;
            for (int i = 0; i < m - n; i++)
            {
                answer = Math.Min(answer, presents[i + n - 1] - presents[i]);
            }

            Console.WriteLine(answer);
        }
    }
}


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

namespace DimaAndHorses
{
    class Program
    {
        private static bool[] p;

        private static bool Check(List<int>[] war, int i)
        {
            return war[i].Count(e => p[e] == p[i]) <= 1;
        }

        private static bool Dfs(List<int>[] war, int i)
        {
            if (i == p.Length)
            {
                for (int j = 0; j < i; j++)
                {
                    if (!Check(war, j))
                        return false;
                }

                return true;
            }

            if (!Check(war, i))
            {
                p[i] = !p[i];
                if (Check(war, i))
                {
                    if (Dfs(war, i + 1))
                        return true;
                }

                p[i] = !p[i];
            }

            return Dfs(war, i + 1);
        }

        static void Main(string[] args)
        {
            // var fin = File.OpenText("test.txt");
            // Console.SetIn(fin);

            string[] nm = Console.ReadLine().Split(' ');
            int n = int.Parse(nm[0]);
            int m = int.Parse(nm[1]);

            var war = new List<int>[n];
            for (int i = 0; i < n; i++)
            {
                war[i] = new List<int>();
            }

            for (int i = 0; i < m; i++)
            {
                string[] ab = Console.ReadLine().Split(' ');
                int a = int.Parse(ab[0]) - 1;
                int b = int.Parse(ab[1]) - 1;

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

            p = new bool[n];
            Dfs(war, 0);
            Console.WriteLine(string.Concat(p.Select(x => x ? 1 : 0)));

            // fin.Close();
        }
    }
}


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

namespace DimaAndHorses
{
    class Program
    {
        private static List<int>[] war;
        private static bool[] p;

        private static bool Check(int i)
        {
            return war[i].Count(e => p[e] == p[i]) <= 1;
        }

        private static void Fix(int i)
        {
            p[i] = !p[i];

            foreach (var e in war[i])
            {
                if (p[e] == p[i] && !Check(e))
                {
                    Fix(e);
                }
            }
        }

        private static void FixAll()
        {
            for (int i = 0; i < p.Length; i++)
            {
                if (!p[i] && !Check(i))
                {
                    Fix(i);
                }
            }
        }

        static void Main(string[] args)
        {
            var fin = File.OpenText("test.txt");
            Console.SetIn(fin);

            string[] nm = Console.ReadLine().Split(' ');
            int n = int.Parse(nm[0]);
            int m = int.Parse(nm[1]);

            war = new List<int>[n];
            p = new bool[n];
            for (int i = 0; i < n; i++)
            {
                war[i] = new List<int>();
                p[i] = false;
            }

            for (int i = 0; i < m; i++)
            {
                string[] ab = Console.ReadLine().Split(' ');
                int a = int.Parse(ab[0]) - 1;
                int b = int.Parse(ab[1]) - 1;

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

            FixAll();
            Console.WriteLine(string.Concat(p.Select(x => x ? 1 : 0)));

            fin.Close();
        }
    }
}


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

namespace Constest3
{
    class Program
    {
        static void Main(string[] args)
        {
            String path = Console.ReadLine();
            for (int i = 0; i < path.Length; i++)
            {
                if (path[i] == '/')
                {
                    int j;
                    for (j = i; path[j] == '/' && j < path.Length; j++)
                    {
                        if (j == i)
                            Console.Write(path[i]);
                    }
                    i = j - 1;
                    continue;
                }
                else
                {
                    Console.Write(path[i]);
                }
            }
        }
    }
}


using System;

namespace Task1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());

            if (n == 0)
            {
                Console.WriteLine(0);
                return;
            }

            if (n <= 9)
            {
                Console.WriteLine(n);
                return;
            }

            int s = 0;
            for (int i = 1; i <= n; i++)
            {
                s += i.ToString().Length;
            }

            Console.WriteLine(s);
        }
    }
}


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

class Program
{
    static char[] SPACE = new[] { ' ' };

    static void Main(string[] args)
    {
#if DEBUG
        using (var input = new StreamReader("input.txt"))
        using (var output = new StreamWriter("output.txt"))
        {
            Console.SetIn(input);
            Console.SetOut(output);

            int n = 0;
            do
            {
                Console.WriteLine();
                Console.WriteLine("Sample {0}", ++n);
                Prog();
            } while (Console.ReadLine() == string.Empty);
        }
#else
            Prog();
#endif
    }

    static int __ptr = 0;
    static string[] __input;
    static int NextInt()
    {
        return int.Parse(__input[__ptr++]);
    }
    static long NextLong()
    {
        return long.Parse(__input[__ptr++]);
    }
    static void ReadTokens(int n)
    {
        __ptr = 0;
        __input = Console.ReadLine().Split(SPACE, n);
    }

    //

    static void Prog()
    {
        ReadTokens(1);
        int n = NextInt();

        Console.WriteLine(Enumerable.Range(1, n).Aggregate("", (a, b) => a + "" + b).Length);
    }
}


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

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            int a =Convert.ToInt32( Console.ReadLine());
            string s=string.Empty;
            for (int i = 1; i <= a; i++)
            {
                s += i;
            }
            Console.WriteLine(s.Length);
        }
    }
}


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

namespace Contest308
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            int ans = 0;

            int k = 1;
            if (n <= 9) ans = n;
            else
            {
                while (k<=n)
                {
                    ans += k.ToString().Length;
                    k++;
                }

            }

            Console.WriteLine(ans);
        }
    }
}


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

namespace VanyaAndBooks
{
    class Program
    {
        static void Main(string[] args)
        {
            Int64 number = Convert.ToInt64(Console.ReadLine());
            int sum = 0;
            for (int i = 1; i <= number; i++)
            {
                if (i >= 10)
                {
                    sum += numberOfDigits(i);
                }
                else
                {
                    sum += 1;
                }
            }
            Console.WriteLine("{0}", sum);
        }

        static int numberOfDigits(Int64 num)
        {
            int digCount = 0;
            while (num != 0)
            {
                num = num / 10;
                digCount += 1;
            }
            return digCount;
        }
    }
}


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

namespace Codeforces_335
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split();
            int[] input1 = new int[3];
            for (int i = 0; i < input.Length; i++)
            {
                input1[i] = int.Parse(input[i]);
            }

            string[] rez = Console.ReadLine().Split();
            int[] rez1 = new int[3];
            for (int i = 0; i < rez.Length; i++)
            {
                rez1[i] = int.Parse(rez[i]);
            }

            bool f = false;
            int a = input1.Sum();
            int b = rez1.Sum();
            int c = 0;

            for (int i = 0; true; i++)
            {
                if (a - 2 == b)
                {
                    f = true;
                    break;
                }
                else
                    a = a - 2;

                if(a + 1 == b)
                {
                    f = false;
                    break;
                }
                else
                {
                    a = a + 1;
                }
            }

            if (f)
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }
    }
}


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

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split();
            string[] rez = Console.ReadLine().Split();
            int[] lol = new int[3];

            for (int l = 0; l < input.Length; l++)
            {
                if (int.Parse(input[l]) - int.Parse(rez[l]) >= 0)
                    lol[l] = 1;
                else
                    lol[l] = 0;
            }

            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            int c = int.Parse(input[2]);
            int x = int.Parse(rez[0]);
            int y = int.Parse(rez[1]);
            int z = int.Parse(rez[2]);
            int i = lol[0];
            int j = lol[1];
            int k = lol[2];

            Console.WriteLine(rer);
            Console.WriteLine(pop);
            Console.WriteLine(3 / 2);
            if ((i * (a - x) + j * (b - y) + k * (c - z)) / 2 >= (1 - i) * -1 * (a - x) - (1 - j) * (b - y) - (1 - k) * (c - z))
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }
    }
}


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


using System;
using System.Collections.Generic;
using System.Linq;
using Solver.Ex;
using Debug = System.Diagnostics.Debug;
using Watch = System.Diagnostics.Stopwatch;
using StringBuilder = System.Text.StringBuilder;
using System.Numerics;
namespace Solver
{
    public class Solver
    {
        public void Solve()
        {
            var n = sc.Integer();
            var d = sc.Integer();
            x = sc.Long();
            var a = new int[n];
            var b = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = i + 1;
            for (int i = 0; i < n; i++)
            {
                nextX();
                var tmp = a[i];
                a[i] = a[x % (i + 1)];
                a[x % (i + 1)] = tmp;
            }
            for (int i = 0; i < n; i++)
            {
                if (i < d) b[i] = 1;
                else b[i] = 0;
            }
            for (int i = 0; i < n; i++)
            {
                nextX();
                var tmp = b[i];
                b[i] = b[x % (i + 1)];
                b[x % (i + 1)] = tmp;
            }

            if (d <= 1000)
            {
                var position = new List<int>();
                for (int i = 0; i < n; i++)
                    if (b[i] == 1) position.Add(i);
                for (int i = 0; i < n; i++)
                {
                    var max = 0;
                    foreach (var p in position)
                    {
                        if (p <= i)
                            max = Math.Max(max, a[i - p]);
                    }
                    IO.Printer.Out.WriteLine(max);
                }

            }

            else
            {
                var position = new int[n];
                for (int i = 0; i < n; i++)
                    position[a[i] - 1] = i;
                for (int i = 0; i < n; i++)
                {
                    var f = false;
                    for (int j = n - 1; j >= n - 1000; j--)
                    {
                        if (position[j] > i) continue;
                        if (b[i - position[j]] > 0)
                        {
                            IO.Printer.Out.WriteLine(j + 1);
                            f = true;
                            break;
                        }
                    }
                    if (f) continue;
                    var max = 0;
                    foreach (var p in position)
                    {
                        if (p > i) break;
                        max = Math.Max(max, a[i - p]);
                    }
                    IO.Printer.Out.WriteLine(max);
                }

            }
        }
        long x;
        long nextX()
        {
            return x = (x * 37 + 10007) % 1000000007;
        }

        internal IO.StreamScanner sc;
        static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; i++) a[i] = f(i); return a; }
    }

    #region Main and Settings
    static class Program
    {
        static void Main(string[] arg)
        {
#if DEBUG
            var errStream = new System.IO.FileStream(@"..\..\dbg.out", System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite);
            Debug.Listeners.Add(new System.Diagnostics.TextWriterTraceListener(errStream, "debugStream"));
            Debug.AutoFlush = false;
            var sw = new Watch(); sw.Start();
            IO.Printer.Out.AutoFlush = true;
            try
            {
#endif

                var solver = new Solver();
                solver.sc = new IO.StreamScanner(Console.OpenStandardInput());
                solver.Solve();
                IO.Printer.Out.Flush();
#if DEBUG
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
                Console.Error.WriteLine(ex.StackTrace);
            }
            finally
            {
                sw.Stop();
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Error.WriteLine("Time:{0}ms", sw.ElapsedMilliseconds);
                Debug.Close();
                System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
            }
#endif
        }

    }
    #endregion
}

#region IO Helper
namespace Solver.IO
{
    public class Printer : System.IO.StreamWriter
    {
        static Printer()
        {
            Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false };
#if DEBUG
            Error = new Printer(Console.OpenStandardError()) { AutoFlush = true };
#else
            Error = new Printer(System.IO.Stream.Null) { AutoFlush = false };
#endif
        }
        public static Printer Out { get; set; }
        public static Printer Error { get; set; }
        public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } }
        public Printer(System.IO.Stream stream) : base(stream, new System.Text.UTF8Encoding(false, true)) { }
        public Printer(System.IO.Stream stream, System.Text.Encoding encoding) : base(stream, encoding) { }
        public void Write<T>(string format, IEnumerable<T> source) { base.Write(format, source.OfType<object>().ToArray()); }
        public void WriteLine<T>(string format, IEnumerable<T> source) { base.WriteLine(format, source.OfType<object>().ToArray()); }
    }
    public class StreamScanner
    {
        public StreamScanner(System.IO.Stream stream) { iStream = stream; }
        private readonly System.IO.Stream iStream;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        private bool eof = false;
        public bool IsEndOfStream { get { return eof; } }
        const byte lb = 33, ub = 126, el = 10, cr = 13;
        public byte read()
        {
            if (eof) throw new System.IO.EndOfStreamException();
            if (ptr >= len) { ptr = 0; if ((len = iStream.Read(buf, 0, 1024)) <= 0) { eof = true; return 0; } }
            return buf[ptr++];
        }
        public char Char() { byte b = 0; do b = read(); while (b < lb || ub < b); return (char)b; }
        public char[] Char(int n) { var a = new char[n]; for (int i = 0; i < n; i++) a[i] = Char(); return a; }
        public char[][] Char(int n, int m) { var a = new char[n][]; for (int i = 0; i < n; i++) a[i] = Char(m); return a; }
        public string Scan()
        {
            if (eof) throw new System.IO.EndOfStreamException();
            StringBuilder sb = null;
            var enc = System.Text.UTF8Encoding.Default;
            do
            {
                for (; ptr < len && (buf[ptr] < lb || ub < buf[ptr]); ptr++) ;
                if (ptr < len) break;
                ptr = 0;
                if ((len = iStream.Read(buf, 0, 1024)) <= 0) { eof = true; return ""; }
            } while (true);
            do
            {
                var f = ptr;
                for (; ptr < len; ptr++)
                    if (buf[ptr] < lb || ub < buf[ptr])
                    //if (buf[ptr] == cr || buf[ptr] == el)
                    {
                        string s;
                        if (sb == null) s = enc.GetString(buf, f, ptr - f);
                        else { sb.Append(enc.GetChars(buf, f, ptr - f)); s = sb.ToString(); }
                        ptr++; return s;
                    }
                if (sb == null) sb = new StringBuilder(enc.GetString(buf, f, len - f));
                else sb.Append(enc.GetChars(buf, f, len - f));
                ptr = 0;

            }
            while (!eof && (len = iStream.Read(buf, 0, 1024)) > 0);
            eof = true; return (sb != null) ? sb.ToString() : "";
        }
        public long Long()
        {
            long ret = 0; byte b = 0; bool isMynus = false;
            const byte zr = 48, nn = 57, my = 45;
            do b = read();
            while (b != my && (b < zr || nn < b));
            if (b == my) { isMynus = true; b = read(); }
            for (; true; b = read())
                if (b < zr || nn < b)
                    return isMynus ? -ret : ret;
                else ret = ret * 10 + b - zr;
        }
        public int Integer()
        {
            int ret = 0; byte b = 0; bool isMynus = false;
            const byte zr = 48, nn = 57, my = 45;
            do b = read();
            while (b != my && (b < zr || nn < b));
            if (b == my) { isMynus = true; b = read(); }
            for (; true; b = read())
                if (b < zr || nn < b)
                    return isMynus ? -ret : ret;
                else ret = ret * 10 + b - zr;
        }
        public double Double() { return double.Parse(Scan(), System.Globalization.CultureInfo.InvariantCulture); }
        public string[] Scan(int n) { var a = new string[n]; for (int i = 0; i < n; i++) a[i] = Scan(); return a; }
        public double[] Double(int n) { var a = new double[n]; for (int i = 0; i < n; i++) a[i] = Double(); return a; }
        public int[] Integer(int n) { var a = new int[n]; for (int i = 0; i < n; i++) a[i] = Integer(); return a; }
        public long[] Long(int n) { var a = new long[n]; for (int i = 0; i < n; i++)a[i] = Long(); return a; }
        public void Flush() { iStream.Flush(); }
    }
}
#endregion
#region Extension
namespace Solver.Ex
{
    static public partial class EnumerableEx
    {
        static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); }
        static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); }

    }
}
#endregion


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http.Headers;

namespace ConsoleApp1
{
    public static class PositionHelper
    {
        private static Dictionary<Program.Position, HashSet<Program.Position>> cache = new Dictionary<Program.Position, HashSet<Program.Position>>();

        public static HashSet<Program.Position> GetSurrondings(this Program.Position position)
        {
            if (!cache.ContainsKey(position))
            {
                cache.Add(position, new HashSet<Program.Position>
                {
                    position,
                    new Program.Position(position.X - 1, position.Y),
                    new Program.Position(position.X - 1, position.Y - 1),
                    new Program.Position(position.X - 1, position.Y + 1),
                    new Program.Position(position.X, position.Y - 1),
                    new Program.Position(position.X, position.Y + 1),
                    new Program.Position(position.X + 1, position.Y),
                    new Program.Position(position.X + 1, position.Y - 1),
                    new Program.Position(position.X + 1, position.Y + 1)
                });
            }
            return cache[position];
        }

    }

    public static class Program
    {
        public static void Main()
        {
            Console.WriteLine(HasAvailablePosition(ReadData()) ? "OTHER" : "CHECKMATE");
        }

        public static bool HasAvailablePosition(string positions)
        {
            var lines = positions.Split(' ');
            var l1Position = new Position(lines[0]);
            var l2Position = new Position(lines[1]);
            var kingPosition = new Position(lines[2]);
            var aimPosition = new Position(lines[3]);

            var positionsForCheck = aimPosition.GetSurrondings();

            foreach (var position in positionsForCheck)
            {
                if (IsAvailablePosition(position, aimPosition, l1Position, l2Position, kingPosition))
                {
                    return true;
                }
            }
            return false;
        }

        private static bool IsAvailablePosition(Position position, Position aimPosition, Position l1, Position l2, Position kingPosition)
        {
            if (position.X <= 0 || position.X > 8 || position.Y <= 0 || position.Y > 8)
                return false;

            if (kingPosition.GetSurrondings().Contains(position))
                return false;

            if (HasProblemsWithL(position, aimPosition, l1, l2, kingPosition))
                return false;

            if (HasProblemsWithL(position, aimPosition, l2, l1, kingPosition))
                return false;
            return true;
        }

        private static bool HasProblemsWithL(Position position, Position aimPosition, Position l1, Position l2, Position kingPosition)
        {
            if (position.X == l1.X || position.Y == l1.Y)
            {
                if (l1.X == l2.X || l1.Y == l2.Y)
                    return true;
                if (kingPosition.GetSurrondings().Contains(l1))
                    return true;
                if (!position.GetSurrondings().Contains(l1))
                    return true;
                if (!position.Equals(aimPosition) && !position.Equals(l1))
                    return true;
            }
            return false;
        }

        public class Position
        {

            private static readonly Dictionary<char, int> Positions = new Dictionary<char, int>
            {
                {'a', 1},
                {'b', 2},
                {'c', 3},
                {'d', 4},
                {'e', 5},
                {'f', 6},
                {'g', 7},
                {'h', 8}
            };

            public int X { get; }
            public int Y { get; }
            private char q;

            public Position(string position)
            {
                var splits = position.ToCharArray();
                X = Positions[splits[0]];
                Y = int.Parse(splits[1].ToString());
                q = splits[0];
            }

            public Position(int x, int y)
            {
                X = x;
                Y = y;
                q = Positions.FirstOrDefault(z => z.Value == x).Key;
            }

            protected bool Equals(Position other)
            {
                return X == other.X && Y == other.Y;
            }

            public override string ToString()
            {
                return $"{q}{Y}";
            }

            public override bool Equals(object obj)
            {
                if (ReferenceEquals(null, obj)) return false;
                if (ReferenceEquals(this, obj)) return true;
                if (obj.GetType() != this.GetType()) return false;
                return Equals((Position) obj);
            }

            public override int GetHashCode()
            {
                unchecked
                {
                    return (X * 397) ^ Y;
                }
            }
        }

        private static string ReadData()
        {
            //return File.ReadAllLines("1.txt").Single();
            return Console.ReadLine();
            //yield return Console.ReadLine();
        }

        //private static IEnumerable<string> ReadData()
        //{
        //    //return File.ReadAllLines("1.txt");
        //    while (true)
        //    {
        //        var line = Console.ReadLine();
        //        if (string.IsNullOrEmpty(line))
        //            yield break;
        //        yield return line;

        //    }
        //}
    }
}


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

namespace ConsoleApp1
{
    public static class PositionHelper
    {
        private static Dictionary<Program.Position, HashSet<Program.Position>> cache = new Dictionary<Program.Position, HashSet<Program.Position>>();

        public static HashSet<Program.Position> GetSurrondings(this Program.Position position)
        {
            if (!cache.ContainsKey(position))
            {
                cache.Add(position, new HashSet<Program.Position>
                {
                    position,
                    new Program.Position(position.X - 1, position.Y),
                    new Program.Position(position.X - 1, position.Y - 1),
                    new Program.Position(position.X - 1, position.Y + 1),
                    new Program.Position(position.X, position.Y - 1),
                    new Program.Position(position.X, position.Y + 1),
                    new Program.Position(position.X + 1, position.Y),
                    new Program.Position(position.X + 1, position.Y - 1),
                    new Program.Position(position.X + 1, position.Y + 1)
                });
            }
            return cache[position];
        }

    }

    public static class Program
    {
        public static void Main()
        {
            Console.WriteLine(HasAvailablePosition(ReadData()) ? "OTHER" : "CHECKMATE");
        }

        public static bool HasAvailablePosition(string positions)
        {
            var lines = positions.Split(' ');
            var l1Position = new Position(lines[0]);
            var l2Position = new Position(lines[1]);
            var kingPosition = new Position(lines[2]);
            var aimPosition = new Position(lines[3]);

            var positionsForCheck = aimPosition.GetSurrondings();

            foreach (var position in positionsForCheck)
            {
                if (IsAvailablePosition(position, aimPosition, l1Position, l2Position, kingPosition))
                {
                    return true;
                }
            }
            return false;
        }

        private static bool IsAvailablePosition(Position position, Position aimPosition, Position l1, Position l2, Position kingPosition)
        {
            if (position.X <= 0 || position.X > 8 || position.Y <= 0 || position.Y > 8)
                return false;

            if (kingPosition.GetSurrondings().Contains(position))
                return false;

            if (HasProblemsWithL(position, aimPosition, l1, l2, kingPosition))
                return false;

            if (HasProblemsWithL(position, aimPosition, l2, l1, kingPosition))
                return false;
            return true;
        }

        private static bool HasProblemsWithL(Position position, Position aimPosition, Position l1, Position l2, Position kingPosition)
        {
            if (position.X == l1.X || position.Y == l1.Y)
            {
                if (KingBetween(position, l1, kingPosition))
                    return false;
                if (l1.X == l2.X || l1.Y == l2.Y)
                    return true;
                if (kingPosition.GetSurrondings().Contains(l1))
                    return true;
                if (!position.GetSurrondings().Contains(l1))
                    return true;
                if (!position.Equals(aimPosition) && !position.Equals(l1))
                    return true;
            }
            return false;
        }

        private static bool KingBetween(Position position, Position l1, Position kingPosition)
        {
            if (position.X == l1.X && kingPosition.X == l1.X)
            {
                if (kingPosition.Y > l1.Y && kingPosition.Y < position.Y)
                    return true;
            }

            if (position.Y == l1.Y && kingPosition.Y == l1.Y)
            {
                if (kingPosition.X > l1.X && kingPosition.X < position.X)
                    return true;
            }
            return false;
        }

        public class Position
        {

            private static readonly Dictionary<char, int> Positions = new Dictionary<char, int>
            {
                {'a', 1},
                {'b', 2},
                {'c', 3},
                {'d', 4},
                {'e', 5},
                {'f', 6},
                {'g', 7},
                {'h', 8}
            };

            public int X { get; }
            public int Y { get; }
            private char q;

            public Position(string position)
            {
                var splits = position.ToCharArray();
                X = Positions[splits[0]];
                Y = int.Parse(splits[1].ToString());
                q = splits[0];
            }

            public Position(int x, int y)
            {
                X = x;
                Y = y;
                q = Positions.FirstOrDefault(z => z.Value == x).Key;
            }

            protected bool Equals(Position other)
            {
                return X == other.X && Y == other.Y;
            }

            public override string ToString()
            {
                return $"{q}{Y}";
            }

            public override bool Equals(object obj)
            {
                if (ReferenceEquals(null, obj)) return false;
                if (ReferenceEquals(this, obj)) return true;
                if (obj.GetType() != this.GetType()) return false;
                return Equals((Position) obj);
            }

            public override int GetHashCode()
            {
                unchecked
                {
                    return (X * 397) ^ Y;
                }
            }
        }

        private static string ReadData()
        {
            //return File.ReadAllLines("1.txt").Single();
            return Console.ReadLine();
            //yield return Console.ReadLine();
        }

        //private static IEnumerable<string> ReadData()
        //{
        //    //return File.ReadAllLines("1.txt");
        //    while (true)
        //    {
        //        var line = Console.ReadLine();
        //        if (string.IsNullOrEmpty(line))
        //            yield break;
        //        yield return line;

        //    }
        //}
    }
}


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

namespace Lib
{
    public class DivideCandies
    {
        public static void Main()
        {
            Solve(Console.In, Console.Out);
        }

        public static void Solve(TextReader tr, TextWriter tw)
        {
            var tokens = tr.ReadLine().Split();
            var n = long.Parse(tokens[0]);
            var m = long.Parse(tokens[1]);

            var t = new long[m, m];

            var res = 0L;
            for (long i = 0; i < m; i++)
            {
                for (long j = 0; j < m; j++)
                {
                    t[i, j] = ((i+1) * (i+1) + (j+1) * (j+1)) % m;
                    if (t[i, j] == 0)
                        res++;
                }
            }

            var p = n / m;
            res *= p * p;

            var r = n % m;

            var res2 = 0L;
            for (int i = 0; i < r; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    if (t[i, j] == 0)
                        res2++;
                }
            }

            res += res2 * 2;

            for (int i = 0; i < r; i++)
            {
                for (int j = 0; j < r; j++)
                {
                    if (t[i, j] == 0)
                        res++;
                }
            }

            tw.WriteLine(res);
        }
    }
}


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

namespace ConsoleApplication12_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string z1 = "", z2 = "", z3="";
            string k1 = "", k2 = "", k3 = "";
            z1 = Console.ReadLine();
            z2 = Console.ReadLine();
            z3 = Console.ReadLine();
            k1 = Convert.ToString(Convert.ToInt32(
                (z2.Substring(3,1))+Convert.ToInt32(z3.Substring(2,1)))/2
                );
            z1.Replace("0", k1);

            k2 = Convert.ToString(Convert.ToInt32(
                (z1.Substring(3, 1)) + Convert.ToInt32(z3.Substring(1, 1))) / 2
                );
            z2.Replace("0", k2);

            k3= Convert.ToString(Convert.ToInt32(
                    (z2.Substring(1, 1)) + Convert.ToInt32(z1.Substring(2, 1))) / 2
                      );

            z3.Replace("0", k3);

            Console.WriteLine(z1);
            Console.WriteLine(z2);
            Console.WriteLine(z3);

        }
    }
}


//#define LOCAL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace _258_E
{
    class Program
    {
        class Files
        {
            StreamReader fin = new StreamReader("d:\\date.in");
            StreamWriter fout = new StreamWriter("d:\\date.out");
            public string ReadLine()
            {
                return fin.ReadLine();
            }
            public void Write(string s)
            {
                fout.Write(s);
            }
            public void WriteLine(string s)
            {
                fout.WriteLine(s);
            }
            public void Close()
            {
                fout.Close();
            }
        }
        #if LOCAL
            static Files Console = new Files();
        #endif
        const Int64 Mod = (Int64)1e9+7;
        static string[] s;
        static string Line;
        static int step = 0, Length = 0;
        static Int64 GetNext()
        {
            if (step == Length)
            {
                Line = Console.ReadLine();
                s = Line.Split(' ');
                Length = s.Length;
                step = 0;
            }
            ++step;
            return Int64.Parse(s[step - 1]);
        }
        static Int64[] a = new Int64[30];
        static Int64 Inv = 1;
        static Int64 Comb(Int64 n, Int64 k)
        {
            if (n < k)
                return 0;
            Int64 result = 1;
            for (Int64 i = n - k + 1; i <= n; ++i)
                result = (Int64)result*i%Mod;
            result = (Int64)result*Inv%Mod;
            return result;
        }
        static Int64 Fix(Int64 x)
        {
            Int64 ret = x;
            while(ret >= Mod)
                ret -= Mod;
            while(ret < 0)
                ret += Mod;
            return ret;
        }

        static Int64 Pow_Log(Int64 x,Int64 p)
        {
            if (p == 0)
                return 1;
            Int64 y;
            if(p%2==1)
               y = (Int64)Pow_Log(x,p-1)*x%Mod;
            else
            {
                y = Pow_Log(x,p/2);
                y = (Int64)y*y%Mod;
            }
            return y;
        }
        static void Main(string[] args)
        {
            Int64 n = GetNext(), S = GetNext(), sum = 0, Max = 1;
            Inv = 1;
            for (int i = 0; i < n; ++i)
            {
                Max *= 2;
                if (i > 0)
                    Inv *= i;
                a[i] = GetNext();
                sum += a[i];
            }
            if (sum < S)
            {
                Console.WriteLine("0");
                return;
            }
            Inv = Pow_Log(Inv, Mod - 2);
            Int64 Solution = Comb(S + n - 1, n - 1),cnt = 0;
            for (int i = 1; i < Max; ++i)
            {
                Int64 k = 0;
                int nr = 0;
                for (int j = 0; j < n; ++j)
                    if (((1 << j) & i) != 0)
                    {
                        ++nr;
                        k += a[j]+1;
                    }
                k = S - k;
                if (nr % 2 == 1)
                    cnt += Comb(k + n - 1, n - 1);
                else
                    cnt -= Comb(k + n - 1, n - 1);
                cnt = Fix(cnt);
            }
            Solution -= cnt;
            Solution = Fix(Solution);
            Console.WriteLine(Solution.ToString());
            #if LOCAL
                Console.Close();
            #endif
        }
    }
}