<commit_before>﻿namespace CardGame
{
    using System;
    using System.Linq;
    using System.Numerics;

    public class Program
    {
        private static int n;
        private static Node leftNode;

        public static void Main(string[] args)
        {
            ReadCards();
            CalculateMaximumPointsReachable();
        }

        private static void ReadCards()
        {
            n = int.Parse(Console.ReadLine());
            var nodeValues = Console.ReadLine()
                .Split(new char[]{ ' ' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(i => BigInteger.Parse(i))
                .ToArray();

            leftNode = new Node(nodeValues[0]);
            var middleNode = new Node(nodeValues[1]);
            leftNode.Right = middleNode;
            middleNode.Left = leftNode;
            var rightNode = new Node(nodeValues[2]);
            middleNode.Right = rightNode;
            rightNode.Left = middleNode;

            var lastNode = rightNode;

            for (int i = 3; i < n; i++)
            {
                var newNode = new Node(nodeValues[i]);
                lastNode.Right = newNode;
                newNode.Left = lastNode;
                lastNode = newNode;
            }

            //while (leftNode.Right != null)
            //{
            //    Console.Write(leftNode.Value + " ");
            //    leftNode = leftNode.Right;
            //}
        }

        private static void CalculateMaximumPointsReachable()
        {
            BigInteger maxPoints = 0;
            while (n > 2)
            {
                var toRemoveNode = leftNode.Right;
                var minNodeVal = toRemoveNode.Value;
                // var max = toRemoveNode.Value * (toRemoveNode.Left.Value + toRemoveNode.Right.Value);
                var currentNode = leftNode.Right;

                if (n > 3)
                {
                    while (currentNode.Right != null && currentNode.Right.Right != null)
                    {
                        // && currentNode.Right.Right != null
                        if (currentNode.Right.Value < minNodeVal)
                        {
                            toRemoveNode = currentNode.Right;
                            minNodeVal = toRemoveNode.Value;
                        }
                        else if (currentNode.Right.Value == minNodeVal)
                        {
                            var left = toRemoveNode.Value * (toRemoveNode.Left.Value + toRemoveNode.Right.Value);
                            var right = currentNode.Right.Value * (currentNode.Value + currentNode.Right.Right.Value);
                            if (right > left)
                            {
                                toRemoveNode = currentNode.Right;
                                // currentNode = currentNode.Right;
                            }
                        }

                        currentNode = currentNode.Right;
                    }
                }

                maxPoints += toRemoveNode.Value * (toRemoveNode.Left.Value + toRemoveNode.Right.Value); ;
                toRemoveNode.Left.Right = toRemoveNode.Right;
                toRemoveNode.Right.Left = toRemoveNode.Left;
                n--;
            }

            Console.WriteLine(maxPoints);
        }
    }

    public class Node
    {
        public Node(BigInteger value)
        {
            this.Value = value;
        }

        public BigInteger Value { get; set; }

        public Node Left { get; set; }

        public Node Right { get; set; }
    }
}
<commit_msg>CardGame tsuky<commit_after>﻿namespace CardGame
{
    using System;
    using System.Linq;

    public class Program
    {
        public static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] numbers = Console.ReadLine().Split(' ')
                .Select(int.Parse).ToArray();

            int[,] dp = new int[n, n];

            for (int length = 3; length <= n; length++)
            {
                for (int i = 0; i <= n - length; i++)
                {
                    // i, i + length - 1
                    for (int j = i + 1; j < i + length - 1; j++)
                    {
                        int current = dp[i, j] + dp[j, i + length - 1] + (numbers[j] * (numbers[i] + numbers[i + length - 1]));

                        if (dp[i, i + length - 1] < current)
                        {
                            dp[i, i + length - 1] = current;
                        }
                    }
                }
            }

            Console.WriteLine(dp[0, n - 1]);
        }
    }
}
{'fraction_non_alphanumeric': 0.09954945290710147, 'fraction_numerical': 0.003861832224844454, 'mean_word_length': 1.0962230215827338, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7228787', 'n_tokens_mistral': 1227, 'n_tokens_neox': 1142, 'n_words': 266}