lines = [] print("Paste triangle here:") while True: line = input() if line: lines.append(line) else: break text = ' '.join(lines) numbers = list(map(int, (list(text.split(" "))))) noprimelist = [] for s in numbers: if s > 1: for i in range(2, s): if (s % i) == 0: noprimelist.append(s) break else: noprimelist.append(0) elif s == 1: noprimelist.append(s) rowamount1 = int((((8*(len(noprimelist)) + 1)** 0.5) - 1)//2) rowlist = [] for a in range(rowamount1): b = a + 1 x = (a*(a + 1))//2 y = (b*(b +1))//2 rowlist.append(noprimelist[x:y]) for t in range(len(rowlist)): if t == 0 and sum(rowlist[t]) == 0: del rowlist[0: len(rowlist)] rowlist.append([0]) break if t > 0 and sum(rowlist[t]) == 0: del rowlist[t: (len(rowlist))] break else: pass n = len(rowlist) - 1 if len(rowlist) == 1 and rowlist[0][0] == 0: print("Maximum sum: 0") elif len(rowlist) == 1 and rowlist[0][0] != 0: print("Maximum sum:", rowlist[0][0]) else: s = 0 nextrange = range(n, 0, -1) for n in nextrange: while s < n: res1 = rowlist[n][s] + rowlist[n - 1][s] res2 = rowlist[n][s + 1] + rowlist[n - 1][s] if res1 > res2: rowlist[n - 1][s] = res1 else: rowlist[n - 1][s] = res2 s = s + 1 s = 0 print("Maximum sum:", rowlist[0][0])