def Solve(S, n):
def MaxStudents(i, c):
if i >= n:
return 0
if c == 2:
return MaxStudents(i + 1, 0)
use = MaxStudents(i + 1, c + 1) + S[i]
skip = MaxStudents(i + 1, 0)
return max(use, skip)
return MaxStudents(0, 0)
def Solve(S, n):
def MaxStudents(i):
if i >= n:
return 0
if i == n - 1:
return S[n - 1]
if i == n - 2:
return S[n - 2] + S[n - 1]
skip = MaxStudents(i + 1)
use = S[i] + MaxStudents(i + 2)
demo = S[i] + S[i + 1] + MaxStudents(i + 3)
return max(skip, use, demo)
return MaxStudents(0)