public List <int> Go()
        {
            double d = 2.5 % (1000000000 + 7);

            /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */
            ReadingTestCases.ReadAllText();
            int n = Int32.Parse(ReadingTestCases.ReadLine());
            int m = Int32.Parse(ReadingTestCases.ReadLine());

            int[][] a   = new int[n][];
            int     row = 0;

            while (row < n)
            {
                a[row] = Array.ConvertAll(ReadingTestCases.ReadLine().Split(' '), Int32.Parse);
                row++;
            }
            int[,] map = new int[n, m];
            Dictionary <int, int> dict = new Dictionary <int, int>();
            int key = 0;

            check(a, map, 0, 0, n, m, dict, ref key);
            Console.WriteLine(dict.Values.Max());
            return(new List <int>());
        }
Example #2
0
        public List <int> Go()
        {
            ReadingTestCases.ReadAllText();
            int           q  = Int32.Parse(ReadingTestCases.ReadLine());
            StringBuilder sb = new StringBuilder();

            while (q-- > 0)
            {
                long[] arr = Array.ConvertAll(ReadingTestCases.ReadLine().Split(' '), long.Parse);
                long   n   = arr[0];
                long   m   = arr[1];
                LowerBoundSortedSet <long> root = new LowerBoundSortedSet <long>();
                arr = Array.ConvertAll(ReadingTestCases.ReadLine().Split(' '), long.Parse);
                long max = long.MinValue;

                long prefix = 0;
                for (int i = 0; i < arr.Length; i++)
                {
                    prefix = (prefix % m + arr[i] % m) % m;
                    long a = root.FindLowerBound(prefix + 1);
                    max = Math.Max((prefix - a + m) % m, max);
                    root.Add(prefix);
                }
                Console.WriteLine(max);
                //sb.AppendLine(max.ToString()); //109391481
            }
            //  ReadingTestCases.WriteLine(sb.ToString());
            return(new List <int>());
        }
        // O(N2)
        public List <int> Go()
        {
            ReadingTestCases.ReadAllText();
            int t = Int32.Parse(ReadingTestCases.ReadLine());

            while (t > 0)
            {
                t--;
                int   m  = Int32.Parse(ReadingTestCases.ReadLine());
                int   n  = Int32.Parse(ReadingTestCases.ReadLine());
                int[] ar = Array.ConvertAll(ReadingTestCases.ReadLine().Split(' '), Int32.Parse);
                bool  isInternalLoopBreak = false;
                for (int i = 0; i < n - 1; i++)
                {
                    for (int j = i + 1; j < n; j++)
                    {
                        if (ar[i] + ar[j] == m)
                        {
                            Console.WriteLine((i + 1) + " " + (j + 1));
                            isInternalLoopBreak = true;
                            break;
                        }
                    }
                    if (isInternalLoopBreak)
                    {
                        break;
                    }
                }
            }
            return(new List <int>());
        }
        public List <long> Go()
        {
            ReadingTestCases.ReadAllText();
            int n = Int32.Parse(ReadingTestCases.ReadLine());

            long[]  arr  = Array.ConvertAll(ReadingTestCases.ReadLine().Split(' '), Int64.Parse);
            Point[] arrp = new Point[n];
            for (int i = 0; i < n; i++)
            {
                arrp[i] = new Point(arr[i], i);
            }
            long min = long.MaxValue;

            Array.Sort(arrp);
            for (int i = n - 1; i >= 1; i--)
            {
                for (int j = i - 1; j >= 0; j--)
                {
                    if (arrp[i].index > arrp[j].index)
                    {
                        continue;
                    }
                    long dif = arrp[i].val - arrp[j].val;
                    if (dif < 0)
                    {
                        continue;
                    }
                    min = Math.Min(min, dif);
                    break;
                }
            }
            Console.Write(min);
            return(new List <long>());
        }
Example #5
0
        public List <long> Go()
        {
            ReadingTestCases.ReadAllText();
            int n = Int32.Parse(ReadingTestCases.ReadLine());
            int N = 10;

            int[] a = new int[2 << (2 * N + 1)];
            int[] b = new int[4];
            int   K = 0;
            int   t = 0;

            int[] values = Array.ConvertAll(ReadingTestCases.ReadLine().Split(' '), Int32.Parse);
            for (int i = 0; i < values.Length; i++)
            {
                K |= ((values[i] - 1) << (t * 2));
                t++;
            }
            a[0] = 1;
            List <int> Q = new List <int> {
                0
            };
            int ind = 0;

            while (true)
            {
                int x = Q[ind];
                ind++;
                if (x == K)
                {
                    Console.WriteLine(a[x] - 1);
                    return(new List <long>());
                }
                for (int i = 0; i < b.Length; i++)
                {
                    b[i] = 1000;
                }
                for (int i = n - 1; i >= 0; i--)
                {
                    b[(3 & (x >> (i * 2)))] = i;
                }
                for (int i = 0; i < 4; i++)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        if (b[i] < b[j])
                        {
                            int y = x + ((j - i) << (b[i] * 2));
                            if (a[y] == 0)
                            {
                                a[y] = a[x] + 1;
                                Q.Add(y);
                            }
                        }
                    }
                }
            }
            return(new List <long>());
        }
Example #6
0
        public List <int> Go()
        {
            ReadingTestCases.ReadAllText();
            int         N        = Convert.ToInt32(ReadingTestCases.ReadLine());
            Stack <int> stack    = new Stack <int>();
            int         curMax   = Int32.MinValue;
            Stack <int> stackMax = new Stack <int>();

            while (N-- > 0)
            {
                string query = ReadingTestCases.ReadLine().Trim();


                if (query.Length > 1)
                {
                    string[] arr = query.Split(' ');
                    int      val = Convert.ToInt32(arr[1]);
                    stack.Push(val);
                    if (val > curMax)
                    {
                        curMax = val;
                        stackMax.Push(curMax);
                    }
                }
                else
                {
                    if (query == "2")
                    {
                        int popVal = stack.Pop();
                        if (popVal == curMax)
                        {
                            if (stackMax.Count > 0)
                            {
                                stackMax.Pop();
                                if (stackMax.Count > 0)
                                {
                                    curMax = stackMax.Peek();
                                }
                                else
                                {
                                    curMax = Int32.MinValue;
                                }
                            }
                            else
                            {
                                curMax = Int32.MinValue;
                            }
                        }
                    }
                    else
                    {
                        ReadingTestCases.WriteLine(curMax.ToString());
                    }
                }
            }
            return(new List <int>());
        }
Example #7
0
        public List <int> Go()
        {
            ReadingTestCases.ReadAllText();
            /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */
            int n = Int32.Parse(ReadingTestCases.ReadLine());

            long[]        arr      = Array.ConvertAll(ReadingTestCases.ReadLine().Split(' '), long.Parse);
            long          total    = arr.Sum();
            List <string> nodesStr = new List <string>();
            Dictionary <long, List <long> > dataind = new Dictionary <long, List <long> >();
            int count = n;

            while (n > 1)
            {
                n--;
                nodesStr.Add(ReadingTestCases.ReadLine());
            }
            long        min  = -1;
            long        prev = 0;
            List <long> list = new List <long>();

            for (int i = 0; i < count - 1; i++)
            {
                long[] nodarr = Array.ConvertAll(nodesStr[i].Split(' '), long.Parse);
                list.Add(nodarr[0]);
                list.Add(nodarr[1]);

                if (dataind.ContainsKey(nodarr[0]))
                {
                    dataind[nodarr[0]].Add(prev++);
                }
                else
                {
                    dataind.Add(nodarr[0], new List <long> {
                        prev++
                    });
                }

                if (dataind.ContainsKey(nodarr[1]))
                {
                    dataind[nodarr[1]].Add(prev++);
                }
                else
                {
                    dataind.Add(nodarr[1], new List <long> {
                        prev++
                    });
                }
            }

            load(dataind, list, arr, 1, -1, ref min, total);
            Console.WriteLine(min);
            return(new List <int>());
        }
Example #8
0
        public BinarySearch()
        {
            ReadingTestCases.ReadAllText();
            initarr = ReadingTestCases.ReadLine().Split(' ').Select(Int32.Parse).ToArray();
            Array.Sort(initarr);

            /* Random rnd = new Random();
             * initarr = initarr.Select(x => rnd.Next()).ToArray();
             * int index = rnd.Next(0, 1000);
             * initarr[index] = target;
             * initarr= initarr.OrderBy(x => x).ToArray();*/
        }
        public List <int> main()
        {
            /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */

            ReadingTestCases.ReadAllText();
            int n = Int32.Parse(ReadingTestCases.ReadLine());

            for (int i = 0; i < n; i++)
            {
                String s = ReadingTestCases.ReadLine();
                sortNext(s);
            }
            return(new List <int>());
        }
Example #10
0
        public List <int> Go()
        {
            ReadingTestCases.ReadAllText();
            int T = Int32.Parse(ReadingTestCases.ReadLine());

            while (T > 0)
            {
                T--;
                int[]             nm                 = Array.ConvertAll(ReadingTestCases.ReadLine().Split(' '), Int32.Parse);
                int               N                  = nm[0];
                int               M                  = nm[1];
                char [][]         forest             = new char[N][];
                Coordinate        portkey            = new Coordinate();
                Coordinate        startPosition      = new Coordinate();
                List <Coordinate> turningCoordinates = new List <Coordinate>();
                List <Coordinate> neuboList          = new List <Coordinate>
                {
                    new Coordinate(1, 0),
                    new Coordinate(-1, 0),
                    new Coordinate(0, 1),
                    new Coordinate(0, -1)
                };
                bool [,] visited = new bool[N, M];
                // visited[startPosition.N, startPosition.M] = true;
                for (int i = 0; i < N; i++)
                {
                    string s = ReadingTestCases.ReadLine();
                    for (int j = 0; j < M; j++)
                    {
                        if (s[j] == '*')
                        {
                            portkey.N = i;
                            portkey.M = j;
                        }
                        if (s[j] == 'M')
                        {
                            startPosition.N = i;
                            startPosition.M = j;
                        }
                    }
                    forest[i] = s.ToCharArray();
                }
                int K     = Int32.Parse(ReadingTestCases.ReadLine());
                int total = 0;
                bst(forest, neuboList, startPosition, portkey, visited, N, M, ref total);
                Console.WriteLine(total == K ? "Impressed" : "Oops!");
            }
            return(new List <int>());
        }
        public InterpolationSearch()
        {
            string s = "194729";
            bool   t = s.Contains("4729");

            ReadingTestCases.ReadAllText();
            arr = ReadingTestCases.ReadLine().Split(' ').Select(Int32.Parse).ToArray();
            Array.Sort(arr);

            /* Random rnd = new Random();
             * values = values.Select(x => rnd.Next()).ToArray();
             * int index = rnd.Next(0, 1000);
             * values[index] = target;
             * values = values.OrderBy(x => x).ToArray();*/
        }
        public List <int> start()
        {
            ReadingTestCases.ReadAllText();
            int n = Int32.Parse(ReadingTestCases.ReadLine());

            for (int i = 0; i < n; i++)
            {
                String s       = ReadingTestCases.ReadLine();
                int    start   = -1;
                char[] chararr = s.ToCharArray();
                for (int j = 0; j < chararr.Length - 1; j++)
                {
                    if (chararr[j] < chararr[j + 1])
                    {
                        start = j;
                    }
                }
                if (start == -1)
                {
                    Console.WriteLine("no answer");
                    break;
                }
                int end = -1;
                for (int j = start + 1; j < chararr.Length; j++)
                {
                    if (chararr[start] < chararr[j])
                    {
                        end = j;
                    }
                }
                char temp = chararr[start];
                chararr[start] = chararr[end];
                chararr[end]   = temp;
                char[] chararrcopy = new char[chararr.Length - (start + 1)];
                for (int j = start + 1, k = 0; j < chararr.Length; j++, k++)
                {
                    chararrcopy[k] = chararr[j];
                }

                Array.Sort(chararrcopy);
                for (int j = start + 1; j < chararr.Length; j++)
                {
                    chararr[j] = chararrcopy[j - start - 1];
                }
                Console.WriteLine(new string(chararr));
            }
            return(new List <int>());
        }
        public List <int> Go()
        {
            int[] ar = new[] { 1 };
            ReadingTestCases.ReadAllText();

            int N = Int32.Parse(ReadingTestCases.ReadLine());
            int n = 0;

            string[] nodesStr = new string[N];
            while (n < N)
            {
                nodesStr[n] = ReadingTestCases.ReadLine();
                n++;
            }

            Node root = new Node();

            root.Value  = 1;
            root.Height = 1;
            int           H = 1;
            List <string> l = nodesStr.ToList();

            l.Insert(0, "1");
            fillNodes(root, 1, l, H);
            H = GetHeight(root);
            int Kcount = Int32.Parse(ReadingTestCases.ReadLine());


            while (Kcount > 0)
            {
                int k = Int32.Parse(ReadingTestCases.ReadLine());
                int i = 2;
                int p = k;
                while (p <= H)
                {
                    swap(root, p);
                    p = k * i;
                    i++;
                }
                traverseInOrder(root);
                Console.Write("\n");
                Kcount--;
            }

            return(new List <int>());
        }
Example #14
0
        public List <int> Go()
        {
            ReadingTestCases.ReadAllText();
            int N = Int32.Parse(ReadingTestCases.ReadLine());

            long[] array = Array.ConvertAll(ReadingTestCases.ReadLine().Split(' '), long.Parse);
            int    Q     = Int32.Parse(ReadingTestCases.ReadLine());

            long[]             queries = Array.ConvertAll(ReadingTestCases.ReadLine().Split(' '), long.Parse);
            IEnumerable <long> ar      = array;

            for (int i = 0; i < Q; i++)
            {
                var i1 = i;
                ar = ar.Select(x => x + queries[i1]).AsParallel();
                //long res = ar.Su;
                Console.WriteLine(ar);
            }
            return(new List <int>());
        }
        public List <int> Go()
        {
            ReadingTestCases.ReadAllText();
            string[] tokens_n = ReadingTestCases.ReadLine().Split(' ');
            int      n        = Convert.ToInt32(tokens_n[0]);
            int      k        = Convert.ToInt32(tokens_n[1]);

            string[] x_temp = ReadingTestCases.ReadLine().Split(' ');
            int[]    x      = Array.ConvertAll(x_temp, Int32.Parse);
            Array.Sort(x);
            int range = k * 2;
            int count = 0;

            for (int i = 0; i < x.Length;)
            {
                int  h        = x[i];
                int  ind      = i + 1;
                bool isExists = false;
                while (ind < x.Length && x[ind] - h <= k)
                {
                    isExists = true;
                    ind++;
                }
                count++;
                if (ind < x.Length && isExists)
                {
                    h = x[--ind];
                    ind++;
                    while (ind < x.Length && x[ind] - h <= k)
                    {
                        //isExists=true;
                        ind++;
                    }
                }
                i = ind;
                //Console.WriteLine(ind);
            }
            Console.WriteLine(count);
            return(new List <int>());
        }
        // O(N)
        public List <int> GoON()
        {
            ReadingTestCases.ReadAllText();
            Dictionary <int, int> d = new Dictionary <int, int>();

            for (int i = 0; i < d.Count; i++)
            {
            }
            int t = Int32.Parse(ReadingTestCases.ReadLine());

            while (t > 0)
            {
                t--;
                int         m      = Int32.Parse(ReadingTestCases.ReadLine());
                int         n      = Int32.Parse(ReadingTestCases.ReadLine());
                int[]       ar     = Array.ConvertAll(ReadingTestCases.ReadLine().Split(' '), Int32.Parse);
                IceCream [] icearr = new IceCream[n];
                for (int i = 0; i < n; i++)
                {
                    icearr[i] = new IceCream(ar[i], i);
                }

                Array.Sort(icearr);
                for (int i = 0; i < n - 1; i++)
                {
                    int search = m - icearr[i].Cost;
                    if (search >= icearr[i].Cost)
                    {
                        int res = binarySearch(icearr, i + 1, n - 1, search);
                        if (res != -1)
                        {
                            Console.WriteLine(Math.Min(icearr[i].Index + 1, res + 1) + " " + Math.Max(icearr[i].Index + 1, res + 1));
                            break;
                        }
                    }
                }
            }
            return(new List <int>());
        }
Example #17
0
        public static List <int> Go()
        {
            ReadingTestCases.ReadAllText();
            /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */
            long[] ar                        = Array.ConvertAll(ReadingTestCases.ReadLine().Split(' '), long.Parse);
            long   n                         = ar[0];
            long   m                         = ar[1];
            long   k                         = ar[2];
            long   totalTrainArea            = 0;
            Dictionary <long, ColRange> dict = new Dictionary <long, ColRange>();

            while (k > 0)
            {
                k--;
                ar = Array.ConvertAll(ReadingTestCases.ReadLine().Split(' '), long.Parse);
                long r     = ar[0];
                long start = ar[1];
                long end   = ar[2];
                if (dict.ContainsKey(r))
                {
                    dict[r].updateRange(start, end);
                }
                else
                {
                    dict.Add(r, new ColRange(start, end));
                }
            }
            foreach (var kvp in dict)
            {
                totalTrainArea += kvp.Value.getTotalArea();
            }
            long totalAreaCity = m * n;

            //Console.WriteLine(totalTrainArea);
            Console.WriteLine(totalAreaCity - totalTrainArea);
            return(new List <int>());
        }
        public List <string> Go()
        {
            ReadingTestCases.ReadAllText();
            int T = Int32.Parse(ReadingTestCases.ReadLine());

            while (T > 0)
            {
                T--;
                string s          = ReadingTestCases.ReadLine();
                int    totalCount = 0;

                for (int i = 0; i < s.Length - 1; i++)
                {
                    for (int j = i + 1; j < s.Length; j++)
                    {
                        int[] first     = new int[26];
                        int[] second    = new int[26];
                        int   bindleft  = i;
                        int   bindright = j;
                        while (bindright < s.Length)
                        {
                            first[s[bindleft] - 97]++;
                            second[s[bindright] - 97]++;
                            bindleft++;
                            bindright++;
                            if (compare(first, second))
                            {
                                totalCount++;
                            }
                        }
                    }
                }
                Console.WriteLine(totalCount);
            }
            return(new List <string>());
        }
Example #19
0
        public List <long> Go()
        {
            ReadingTestCases.ReadAllText();
            string s = ReadingTestCases.ReadLine();
            Dictionary <char, List <long> > dict = new Dictionary <char, List <long> >();

            for (int i = 0; i < s.Length; i++)
            {
                if (dict.ContainsKey(s[i]))
                {
                    dict[s[i]].Add(i);
                }
                else
                {
                    dict.Add(s[i], new List <long> {
                        i
                    });
                }
            }
            BigInteger total = 0;
            int        p     = 4;
            int        mod   = 1000000007;

            foreach (var kvp in dict)
            {
                int n = kvp.Value.Count;
                if (n <= 1)
                {
                    continue;
                }
                BigInteger res = 0;
                if (n >= p)
                {
                    res = 1;
                    for (int i = 1; i <= p; i++)
                    {
                        res = res * (n - p + i) / i;
                    }
                }
                //total = (total%mod+ res%mod) % mod;
                var externalList = kvp.Value;
                foreach (var kvpIn in dict)
                {
                    if (kvpIn.Value.Count <= 1)
                    {
                        continue;
                    }
                    //if (kvp.Key == kvpIn.Key) continue;
                    var     internalList = kvpIn.Value;
                    Point[] arr          = new Point[internalList.Count];
                    long    firstExt     = externalList[0];
                    long    lastExt      = externalList[externalList.Count - 1];
                    int     start        = 0;
                    int     end          = 0;
                    int     prevInt      = 0;
                    for (int i = 0; i < externalList.Count; i++)
                    {
                        if (i == 0)
                        {
                            // Determine start index for the second part of the palindrome
                            for (int j = 0; j < internalList.Count; j++)
                            {
                                if (firstExt > internalList[j])
                                {
                                    continue;
                                }
                                start = j + 1;
                                break;
                            }
                            // Determine end index for the second part of the palindrome
                            for (int j = internalList.Count - 1; j >= 0; j--)
                            {
                                if (lastExt < internalList[j])
                                {
                                    continue;
                                }
                                end = j;
                                break;
                            }
                            int lastIndexExt = externalList.Count - 1;
                            int prev         = -1;

                            while (start <= end)
                            {
                                Point point = new Point();
                                while (lastIndexExt >= 0 && internalList[end] < externalList[lastIndexExt])
                                {
                                    point.cur++;
                                    lastIndexExt--;
                                }
                                if (prev > 0)
                                {
                                    point.cur    = point.cur + arr[prev].cur;
                                    point.total  = point.cur + arr[prev].total;
                                    point.tottot = point.total + arr[prev].tottot;
                                }
                                else
                                {
                                    point.total  = point.cur;
                                    point.tottot = point.cur;
                                }
                                prev     = end;
                                arr[end] = point;
                                end--;
                            }
                            prevInt = start == 0 ? 0 : start - 1;
                        }
                        long aftotal = 0;
                        if (externalList[i] > internalList[internalList.Count - 1])
                        {
                            continue;
                        }
                        for (int j = prevInt; j < internalList.Count - 1; j++)
                        {
                            if (externalList[i] > internalList[j])
                            {
                                continue;
                            }
                            prevInt = j;
                            aftotal = (aftotal + arr[j + 1].tottot) % mod;
                            break;
                        }
                        total = (total + aftotal) % mod;
                    }
                }
            }
            Console.WriteLine(total % mod);
            return(new List <long>());
        }
        public List <string> Go()
        {
            ReadingTestCases.ReadAllText();
            string s = ReadingTestCases.ReadLine();
            Dictionary <char, int> dict = new Dictionary <char, int>();
            char         prev           = s[0];
            Point        prevPoint      = new Point(s[0] - 96, s[0]);
            List <Point> lp             = new List <Point>();

            if (s.Length == 1)
            {
                lp.Add(prevPoint);
            }
            else
            {
                for (int i = 1; i < s.Length; i++)
                {
                    if (prev == s[i])
                    {
                        prevPoint.Sum += s[i] - 96;
                    }
                    else
                    {
                        lp.Add(prevPoint);
                        prevPoint = new Point(s[i] - 96, s[i]);
                        prev      = s[i];
                        if (i == s.Length - 1)
                        {
                            lp.Add(prevPoint);
                        }
                    }
                }
            }

            int n = Convert.ToInt32(ReadingTestCases.ReadLine());

            for (int a0 = 0; a0 < n; a0++)
            {
                int  x     = Convert.ToInt32(ReadingTestCases.ReadLine());
                bool isYes = false;
                foreach (var p in lp)
                {
                    int dif = p.Sum - x;
                    if (dif < 0)
                    {
                        continue;
                    }
                    if (dif == 0 || dif % ((int)p.Charp - 96) == 0)
                    {
                        ReadingTestCases.WriteLine("Yes");
                        isYes = true;
                        break;
                    }
                    //  Console.WriteLine(p.Charp+ " "+ p.Sum);
                }

                if (isYes)
                {
                    continue;
                }
                ReadingTestCases.WriteLine("No");
                // your code goes here
            }
            return(new List <string>());
        }
        public List <string> Go()
        {
            int l = (int)'l';

            ReadingTestCases.ReadAllText();
            int n = Convert.ToInt32(ReadingTestCases.ReadLine());

            for (int a0 = 0; a0 < n; a0++)
            {
                string s     = ReadingTestCases.ReadLine();
                int    count = 0;
                string p     = "";
                for (int i = 0; i < s.Length;)
                {
                    int lenfin     = 0;
                    int len        = 0;
                    int lastindfin = 0;
                    int inc        = 0;
                    for (int j = 0; j < p.Length; j++)
                    {
                        if (i + inc < s.Length)
                        {
                            if (p[j] == s[i + inc])
                            {
                                len++;
                                inc++;
                            }
                        }

                        if (p[j] != s[i] || j == p.Length - 1 || i == s.Length - 1 || i + inc < s.Length)
                        {
                            if (lenfin < len)
                            {
                                lenfin     = len;
                                lastindfin = inc + i;
                                //    Console.WriteLine(i + " " + inc + " "+ lastindfin);
                                len = 0;
                                inc = 0;
                            }
                        }
                    }
                    //Console.WriteLine(i);
                    string part = "";
                    if (lenfin > 0)
                    {
                        i    = lastindfin;
                        part = s.Substring(lastindfin - lenfin, lenfin);

                        //Console.WriteLine(lastindfin + " " + lenfin);
                        // Console.WriteLine(part);
                    }
                    else
                    {
                        part = s[i].ToString();
                        i++;
                        count++;
                    }

                    //   Console.WriteLine(i);
                    p += part;
                    // Console.WriteLine(p);
                }
                Console.WriteLine(count);
            }
            return(new List <string>());
        }
        public List <int> Go()
        {
            ReadingTestCases.ReadAllText();
            int[] arr   = Array.ConvertAll(ReadingTestCases.ReadLine().Split(' '), Int32.Parse);
            long  total = 0;

            long[] totarr = new long[3010];
            Array.Sort(arr);
            int A = arr[0];
            int B = arr[1];
            int C = arr[2];
            int D = arr[3];

            int[,] cnt = new int[3010, 4200];

            int xor = 0;

            //Count number of different pair {a,b} such that, a <= b and within limit
            for (int f = 1; f <= A; f++)
            {
                for (int s = f; s <= B; s++)
                {
                    totarr[s]++;
                }
            }
            //Create cumulative sum, such that, total[B] gives number of pair {a,b}, where b <= B
            for (int i = 1; i <= 3000; i++)
            {
                totarr[i] += totarr[i - 1];
            }
            //Count number of pairs {a,b} whose xor value, a^b is x. Store it in cnt[b][x]
            for (int f = 1; f <= A; f++)
            {
                for (int s = f; s <= B; s++)
                {
                    int x = f ^ s;
                    cnt[s, x]++;
                }
            }
            for (int f = 1; f <= 3000; f++)
            {
                for (int s = 0; s <= 4100; s++)
                {
                    cnt[f, s] += cnt[f - 1, s];
                }
            }
            long res = 0;

            for (int i = 1; i <= C; i++)
            {
                for (int j = i; j <= D; j++)
                {
                    int y = i ^ j;
                    res += totarr[i] - cnt[i, y];
                }
            }

            //Create cumulative array, so that, cnt[B][x] gives all pairs {a,b}, where b <= B and a^b = x.
            Console.WriteLine(res);
            return(new List <int>());
        }