N = 15 A = [0,0,0,1,1,0,0,0,1,0,1,0,0,1,1] S = [0] * N now = 0 end = 0 while now < N - 1: if A[now] == 0: S[now] = 0 now += 1 continue for i in range(now,N-1): if A[i+1] == A[i]: end = i+1 break for i in range(now,end,2): S[i] = end - i now = end sum = 0 for i in range(N): sum += S[i] print(sum) #多分ok