N = 2 A = [2,1] A.insert(0,0) X = 0 Y = 0 MaxT = [0, A[1]] MaxD = [0, 0, A[1]] if N == 1: print(A[1]) exit() else: MaxT.append(A[2]) for i in range (3, N+1): if MaxT[i-2] >= MaxD[i-2]: X = MaxT[i-2] + A[i] Y = MaxD[i-2] + A[i-1] MaxT.append(X) MaxD.append(Y) else: X = MaxD[i-2] + A[i] Y = MaxD[i-2] + A[i-1] MaxT.append(X) MaxD.append(Y) if MaxT[N] >= MaxD[N]: print(MaxT[N]) else: print(MaxD[N])