using System.Collections.Generic;
using System.Threading.Tasks;
namespace ConsoleApplication3
public static int CountSubstring(string text, string value)
int count = 0, minIndex = text.IndexOf(value, 0);
minIndex = text.IndexOf(value, minIndex + value.Length);
public static bool IsPrime(int number)
if (number == 1) return false;
if (number == 2) return true;
if (number % 2 == 0) return false;
var boundary = (int)Math.Floor(Math.Sqrt(number));
for (int i = 3; i <= boundary; i += 2)
if (number % i == 0) return false;
static void Main(string[] args)
Console.Write("Please Enter to Number of Line of TRIANGLE:");
int inputLineCount = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < inputLineCount; i++)
Console.WriteLine("Please Enter To " + (i + 1) + ". Line Values (Please put the space between values)");
string currentInput = Console.ReadLine();
int valueCount = CountSubstring(input, " ");
Console.WriteLine("You must enter to " + (i+1).ToString() +" value");
input = currentInput + " " + input;
int[,] list = new int[18, 19];
20 76 87 11 32 07 07 49 18
27 83 58 35 71 11 25 57 29 85
14 64 36 96 27 11 58 56 92 18 55
02 90 03 60 48 49 41 46 33 36 47 23
92 50 48 02 36 59 42 79 72 20 82 77 42
56 78 38 80 39 75 02 71 66 66 01 03 55 72
44 25 67 84 71 67 11 61 40 57 58 89 40 56 36
85 32 25 85 57 48 84 35 47 62 17 01 01 99 89 52
06 71 28 75 94 48 37 10 23 51 06 48 53 18 74 98 15
27 02 92 23 08 71 76 84 15 52 92 63 81 10 44 10 69 93";
var charArray = input1.Split('\n');
for (int i = 0; i < charArray.Length; i++)
var numArr = charArray[i].Trim().Split(' ');
for (int j = 0; j < numArr.Length; j++)
int number = Convert.ToInt32(numArr[j]);
for (int i = 16; i >= 0; i--)
for (int j = 0; j < 18; j++)
list[i, j] = Math.Max(list[i, j] + list[i + 1, j], list[i, j] + list[i + 1, j + 1]);
Console.WriteLine(string.Format("Maximum total: {0}", list[0, 0]));
Console.WriteLine(input1);