Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
c = [int(input()) for i in range(n)]
dp = [1 for i in range(2*(10**5)+1)]
dp2 = [-1 for i in range(2*(10**5)+1)]
dp3 = [0 for i in range(2*(10**5)+1)]

ans = 1

def count(s):
  memo = {}
  res = 1
  for i in range(len(s)):
    if s[i] not in memo:
      memo[s[i]] = 1
    else:
      memo[s[i]] += 1
  for i in memo:
    res = res*2**(memo[i]-1)
  return res


dp2[c[0]] = 0
dp3[c[0]] += 1
#print("dp",dp)
#print("dp2",dp2)
     
for i in range(1,n):
  
  if c[i] != c[i-1]:
    if dp2[c[i]] == -1:
      dp2[c[i]] = i
      dp3[c[i]] += 1
    else:
      dp[c[i]] = count(c[dp2[c[i]]:i])*dp[c[i]]*(dp3[c[i]])
      ans += dp[c[i]]
      ans = ans % 1000000007 
      dp3[c[i]] += 1
      
      dp2[c[i]] = i
#  print(i,"dp",dp)
#  print(i,"dp2",dp2)
#  print(i,ans)
print(ans)

Fixed submission:
n = int(input())
cc = [int(input()) for i in range(n)]
c = [cc[0]]
for i in range(1,n):
  if cc[i] != cc[i-1]:
    c.append(cc[i])

n = len(c)
dp = [0 for i in range(n)]
pos_dp = [-1 for i in range(2*10**5+1)]

dp[0] = 1
pos_dp[c[0]] = 0
     
for i in range(1,n):
  if pos_dp[c[i]]!=-1:
    dp[i] = (dp[i-1] + dp[pos_dp[c[i]]])%1000000007
  else:
    dp[i] = dp[i-1] 
  pos_dp[c[i]] = i

print(dp[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
c = [int(input()) for i in range(n)]
dp = [1 for i in range(2*(10**5)+1)]
dp2 = [-1 for i in range(2*(10**5)+1)]
dp3 = [0 for i in range(2*(10**5)+1)]

ans = 1

def count(s):
  memo = {}
  res = 1
  for i in range(len(s)):
    if s[i] not in memo:
      memo[s[i]] = 1
    else:
      memo[s[i]] += 1
  for i in memo:
    res = res*2**(memo[i]-1)
  return res


dp2[c[0]] = 0
dp3[c[0]] += 1
#print("dp",dp)
#print("dp2",dp2)
     
for i in range(1,n):
  
  if c[i] != c[i-1]:
    if dp2[c[i]] == -1:
      dp2[c[i]] = i
      dp3[c[i]] += 1
    else:
      dp[c[i]] = count(c[dp2[c[i]]:i])*dp[c[i]]*(dp3[c[i]])
      ans += dp[c[i]]
      dp3[c[i]] += 1
      
      dp2[c[i]] = i
#  print(i,"dp",dp)
#  print(i,"dp2",dp2)
#  print(i,ans)
print(ans)

Fixed submission:
n = int(input())
cc = [int(input()) for i in range(n)]
c = [cc[0]]
for i in range(1,n):
  if cc[i] != cc[i-1]:
    c.append(cc[i])

n = len(c)
dp = [0 for i in range(n)]
pos_dp = [-1 for i in range(2*10**5+1)]

dp[0] = 1
pos_dp[c[0]] = 0
     
for i in range(1,n):
  if pos_dp[c[i]]!=-1:
    dp[i] = (dp[i-1] + dp[pos_dp[c[i]]])%1000000007
  else:
    dp[i] = dp[i-1] 
  pos_dp[c[i]] = i

print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
import bisect
n = int(input())
c = [int(input()) for i in range(n)]
dp = [1 for i in range(n)]
dp2 = [-1 for i in range(n)]
memo = {}
ans = 0

def count(s):
  memo = {}
  res = 1
  for i in range(len(s)):
    if s[i] not in memo:
      memo[s[i]] = 1
    else:
      memo[s[i]] += 1
  for i in memo:
    res = res*((memo[i]*(memo[i]+1))//2)
  return res


dp2[c[0]] = 0
#print("dp",dp)
#print("dp2",dp2)
     
for i in range(1,n):
  
  if c[i] != c[i-1]:
    if dp2[c[i]] == -1:
      dp2[c[i]] = i
    else:
      dp[c[i]] = count(c[dp2[c[i]]:i])*dp[c[i]]
      ans += dp[c[i]]
      dp2[c[i]] = i

 # print(i,"dp",dp)
  #print(i,"dp2",dp2)
  #print(ans)   
#    for j in range(9):
#      ans += len()-1
#      bisect.bisect_left(li[i],)
print(ans)

Fixed submission:
n = int(input())
cc = [int(input()) for i in range(n)]
c = [cc[0]]
for i in range(1,n):
  if cc[i] != cc[i-1]:
    c.append(cc[i])

n = len(c)
dp = [0 for i in range(n)]
pos_dp = [-1 for i in range(2*10**5+1)]

dp[0] = 1
pos_dp[c[0]] = 0
     
for i in range(1,n):
  if pos_dp[c[i]]!=-1:
    dp[i] = (dp[i-1] + dp[pos_dp[c[i]]])%1000000007
  else:
    dp[i] = dp[i-1] 
  pos_dp[c[i]] = i

print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
import bisect
n = int(input())
c = [int(input()) for i in range(n)]

ans = 1
li = [[] for i in range(9)]
for i in range(n):
  if not li[c[i]]:
    li[c[i]].append(i)
  else:
#    if li[c[i]] != li[c[i]][-1]

    li[c[i]].append(i)
    ans += len(li[c[i]]) - 1
#    for j in range(9):
#      ans += len()-1
#      bisect.bisect_left(li[i],)
print(ans)

Fixed submission:
n = int(input())
cc = [int(input()) for i in range(n)]
c = [cc[0]]
for i in range(1,n):
  if cc[i] != cc[i-1]:
    c.append(cc[i])

n = len(c)
dp = [0 for i in range(n)]
pos_dp = [-1 for i in range(2*10**5+1)]

dp[0] = 1
pos_dp[c[0]] = 0
     
for i in range(1,n):
  if pos_dp[c[i]]!=-1:
    dp[i] = (dp[i-1] + dp[pos_dp[c[i]]])%1000000007
  else:
    dp[i] = dp[i-1] 
  pos_dp[c[i]] = i

print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
import bisect
n = int(input())
c = [int(input()) for i in range(n)]

ans = 1
li = [[] for i in range(9)]
for i in range(n):
  if not li[c[i]]:
    li[c[i]].append(i)
    print(i)
  else:
#    if li[c[i]] != li[c[i]][-1]

    li[c[i]].append(i)
    ans += len(li[c[i]]) - 1
#    for j in range(9):
#      ans += len()-1
#      bisect.bisect_left(li[i],)
print(ans)

Fixed submission:
n = int(input())
cc = [int(input()) for i in range(n)]
c = [cc[0]]
for i in range(1,n):
  if cc[i] != cc[i-1]:
    c.append(cc[i])

n = len(c)
dp = [0 for i in range(n)]
pos_dp = [-1 for i in range(2*10**5+1)]

dp[0] = 1
pos_dp[c[0]] = 0
     
for i in range(1,n):
  if pos_dp[c[i]]!=-1:
    dp[i] = (dp[i-1] + dp[pos_dp[c[i]]])%1000000007
  else:
    dp[i] = dp[i-1] 
  pos_dp[c[i]] = i

print(dp[n-1])