using System.Collections.Generic;
static string dataAsText = @"75
41 41 26 56 83 40 80 70 33
41 48 72 33 47 32 37 16 94 29
53 71 44 65 25 43 91 52 97 51 14
70 11 33 28 77 73 17 78 39 68 17 57
91 71 52 38 17 14 91 43 58 50 27 29 48
63 66 04 68 89 53 67 30 73 16 69 87 40 31
04 62 98 27 23 09 70 98 73 93 38 53 60 04 23";
public static List<List<int>> ConvertToLists(string data)
return data.Replace("\r", "").Split('\n').Select(x =>x.Split(' ').Select(int.Parse).ToList()).ToList();
public static int MaxPath(List<List<int>> data)
for (int i = 1; i < data.Count; i++)
for (int j = 0; j < data[i].Count; j++)
data[i][j] += data[i - 1][j];
else if (j == data[i].Count - 1)
data[i][j] += data[i - 1][j - 1];
data[i][j] += Math.Max(data[i - 1][j - 1], data[i - 1][j]);
return data[data.Count - 1].Max();
public static void Main(string[] args)
var data = ConvertToLists(dataAsText);