def isPrime(num): if num == 1: return False for i in range(2, num): if num % i == 0: return False return True def maxSum(tri, i, j, size): if(i == size or isPrime(tri[i][j])): return 0 res = tri[i][j] res += max(maxSum(tri, i + 1, j, size), maxSum(tri, i + 1, j + 1, size)) return res f = open("/content/drive/My Drive/input.txt","r") text = f.read() rows = text.split('\n') pyramid = [] for row in rows: currentRow = row.split(' ') pyramid.append(currentRow) for row in pyramid: for i in range(len(row)): row[i] = int(row[i]) for row in pyramid: for i in range(len(pyramid[-1])-len(row)): row.append(0) print("The maximum sum is ", maxSum(pyramid, 0, 0, len(pyramid)))