using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp5 { class Program { static int[] splitted = { 1, 2, 5, 4, 3, 6, 2 }; static void Main(string[] args) { int res = 0; for (int i = 0; i < splitted.Count(); i++) { var field = check(i); if (field > res) { res = field; } } } static private int check(int i) { int leftCount = nextLeft(splitted[i], i - 1); int rightCount = nextRight(splitted[i], i + 1); return (leftCount + 1 + rightCount) * splitted[i]; } static private int nextRight(int value, int i) { if (i == splitted.Count()) { return 0; } if (splitted[i] >= value) { return 1 + nextRight(value, i + 1); } return 0; } static private int nextLeft(int value, int i) { if (i == -1) { return 0; } if (splitted[i] >= value) { return 1 + nextLeft(value, i - 1); } return 0; } } }