Problem p03096 (python)

Fixed submission:
N = int(input())
C = [-1]

for _ in range(N):
    c = int(input())
    if c == C[-1]:
        continue
    else:
        C.append(c)

MOD = 10**9+7
dp = 1
prev = [0]*(max(C)+1)

for c in C[1:]:
    dp = (dp+prev[c]) % MOD
    prev[c] = dp
print(dp)

Buggy submission (verdict: Runtime Error):
N = int(input())
C = [-1]

for _ in range(N):
    c = int(input())
    if c == C[-1]:
        continue
    else:
        C.append(c)

MOD = 10**9+7
dp = 1
prev = [0]*(max(C)+1)

for c in enumerate(C[1:]):
    dp = (dp+prev[c]) % MOD
    prev[c] = dp
print(dp)

Buggy submission (verdict: Runtime Error):
N = int(input())
C = [-1]

prev = -1
for _ in range(N):
    c = int(input())
    if c == prev:
        continue
    else:
        C.append(c)
        prev = c

MOD = 10**9+7
n = len(C)
dp = [0]*(n+2)
last = [-1]*(N*2)
dp[0] = 1
for i in range(1, n):
    if last[C[i]] == -1:
        last[C[i]] = i
        dp[i] = dp[i-1]
    else:
        dp[i] = dp[i-1]+dp[last[C[i]]]
        dp[i] %= MOD
        last[C[i]] = i
print(max(dp))

Buggy submission (verdict: Runtime Error):
N = int(input())
C = [-1]

prev = -1
for _ in range(N):
    c = int(input())
    if c == prev:
        continue
    else:
        C.append(c)
        prev = c

MOD = 10**9+7
n = len(C)
dp = [0]*(n+2)
last = [-1]*(N*10)
dp[0] = 1
for i in range(1, n+1):
    if last[C[i]] == -1:
        last[C[i]] = i
        dp[i] = dp[i-1]
    else:
        dp[i] = dp[i-1]+dp[last[C[i]]]
        dp[i] %= MOD
        last[C[i]] = i
print(max(dp))

Buggy submission (verdict: Runtime Error):
N = int(input())
C = [-1]

prev = -1
for _ in range(N):
    c = int(input())
    if c == prev:
        continue
    else:
        C.append(c)
        prev = c

MOD = 10**9+7
n = len(C)
dp = [0]*(n+2)
last = [-1]*(N+N)
dp[0] = 1
for i in range(1, n+1):
    if last[C[i]] == -1:
        last[C[i]] = i
        dp[i] = dp[i-1]
    else:
        dp[i] = dp[i-1]+dp[last[C[i]]]
        dp[i] %= MOD
        last[C[i]] = i
print(max(dp))

Buggy submission (verdict: Runtime Error):
N = int(input())
C = [-1]

prev = -1
for _ in range(N):
    c = int(input())
    if c == prev:
        continue
    else:
        C.append(c)
        prev = c

MOD = 10**9+7
n = len(C)
dp = [0]*(n+1)
last = [-1]*(N+N)
dp[0] = 1
for i in range(1, n+1):
    if last[C[i]] == -1:
        last[C[i]] = i
        dp[i] = dp[i-1]
    else:
        dp[i] = dp[i-1]+dp[last[C[i]]]
        dp[i] %= MOD
        last[C[i]] = i
print(max(dp))

Buggy submission (verdict: Runtime Error):
N = int(input())
C = [-1]

prev = -1
for _ in range(N):
    c = int(input())
    if c == prev:
        continue
    else:
        C.append(c)
        prev = c

MOD = 10**9+7
n = len(C)
dp = [0]*(n+1)
last = [-1]*(N+1)
dp[0] = 1
for i in range(1, n+1):
    if last[C[i]] == -1:
        last[C[i]] = i
        dp[i] = dp[i-1]
    else:
        dp[i] = dp[i-1]+dp[last[C[i]]]
        dp[i] %= MOD
        last[C[i]] = i
print(max(dp))

Buggy submission (verdict: Runtime Error):
N = int(input())
C = [-1]

prev = -1
for _ in range(N):
    c = int(input())
    if c == prev:
        continue
    else:
        C.append(c)
        prev = c

MOD = 10**9+7
n = len(C)-1
dp = [0]*(n+1)
last = [-1]*(n+1)
dp[0] = 1
for i in range(1, n+1):
    if last[C[i]] == -1:
        last[C[i]] = i
        dp[i] = dp[i-1]
    else:
        dp[i] = dp[i-1]+dp[last[C[i]]]
        dp[i] %= MOD
        last[C[i]] = i
print(dp[-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
C = [0]

prev = -1
for _ in range(N):
    c = int(input())
    if c == prev:
        continue
    else:
        C.append(c)
        prev = c

MOD = 10**9+7
dp = [0]*(max(C)+1)
last = [-1]*(max(C)+1)
dp[0] = 1
for i in range(1, len(C)):
    if last[C[i]] == -1:
        last[C[i]] = i
        dp[i] = dp[i-1]
    else:
        dp[i] = dp[i-1]+dp[last[C[i]]]
        dp[i] %= MOD
        last[C[i]] = i
print(max(dp))

Buggy submission (verdict: Runtime Error):
N = int(input())
C = [0]

prev = -1
for _ in range(N):
    c = int(input())
    if c == prev:
        continue
    else:
        C.append(c)
        prev = c

MOD = 10**9+7
dp = [0]*(N+4)
last = [-1]*(N+4)
dp[0] = 1
for i in range(1, len(C)):
    if last[C[i]] == -1:
        last[C[i]] = i
        dp[i] = dp[i-1]
    else:
        dp[i] = dp[i-1]+dp[last[C[i]]]
        dp[i] %= MOD
        last[C[i]] = i
print(max(dp[-1]))

Buggy submission (verdict: Runtime Error):
N = int(input())
C = [0]

prev = -1
for _ in range(N):
    c = int(input())
    if c == prev:
        continue
    else:
        C.append(c)
        prev = c

MOD = 10**9+7
dp = [0]*(N+1)
last = [-1]*(N+1)
dp[0] = 1
for i in range(1, len(C)):
    if last[C[i]] == -1:
        last[C[i]] = i
        dp[i] = dp[i-1]
    else:
        dp[i] = dp[i-1]+dp[last[C[i]]]
        dp[i] %= MOD
        last[C[i]] = i
print(dp[-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
C = [0]

prev = -1
for _ in range(N):
    c = int(input())
    if c == prev:
        continue
    else:
        C.append(c)
        prev = c

MOD = 10**9+7
dp = [0]*(N+4)
last = [-1]*(N+4)
dp[0] = 1
for i in range(1, len(C)):
    if last[C[i]] == -1:
        last[C[i]] = i
        dp[i] = dp[i-1]
    else:
        dp[i] = dp[i-1]+dp[last[C[i]]]
        dp[i] %= MOD
        last[C[i]] = i
print(max(dp))

Buggy submission (verdict: Runtime Error):
N = int(input())
C = [0]

prev = -1
for _ in range(N):
    c = int(input())
    if c == prev:
        continue
    else:
        C.append(c)
        prev = c

MOD = 10**9+7
dp = [0]*(N+2)
last = [-1]*(N+2)
N = len(C)-1
dp[0] = 1
for i in range(1, len(C)):
    if last[C[i]] == -1:
        last[C[i]] = i
        dp[i] = dp[i-1]
    else:
        dp[i] = dp[i-1]+dp[last[C[i]]]
        dp[i] %= MOD
        last[C[i]] = i
print(max(dp))

Buggy submission (verdict: Runtime Error):
N = int(input())
C = [0]

prev = -1
for _ in range(N):
    c = int(input())
    if c == prev:
        continue
    else:
        C.append(c)
        prev = c

MOD = 10**9+7
n = len(C)
dp = [0]*(n+2)
last = [-1]*(n+2)
dp[0] = 1
for i in range(1, n):
    if last[C[i]] == -1:
        last[C[i]] = i
        dp[i] = dp[i-1]
    else:
        dp[i] = dp[i-1]+dp[last[C[i]]]
        dp[i] %= MOD
        last[C[i]] = i
print(max(dp))

Buggy submission (verdict: Runtime Error):
N = int(input())
C = [0]

prev = -1
for _ in range(N):
    c = int(input())
    if c == prev:
        continue
    else:
        C.append(c)
        prev = c

MOD = 10**9+7
n = len(C)
dp = [0]*(n+1)
last = [-1]*(n+1)
dp[0] = 1
for i in range(1, n):
    if last[C[i]] == -1:
        last[C[i]] = i
        dp[i] = dp[i-1]
    else:
        dp[i] = dp[i-1]+dp[last[C[i]]]
        dp[i] %= MOD
        last[C[i]] = i
print(dp[-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
C = [0]

prev = -1
for _ in range(N):
    c = int(input())
    if c == prev:
        continue
    else:
        C.append(c)
        prev = c

MOD = 10**9+7
n = len(C)-1
dp = [0]*(n+1)
last = [-1]*(n+1)
dp[0] = 1
for i in range(1, n+1):
    if last[C[i]] == -1:
        last[C[i]] = i
        dp[i] = dp[i-1]
    else:
        dp[i] = dp[i-1]+dp[last[C[i]]]
        dp[i] %= MOD
        last[C[i]] = i
print(dp[-1])

Buggy submission (verdict: Runtime Error):
from itertools import accumulate
from collections import Counter
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

MOD = 10**9+7


def comb2(N):
    return int(N*(N-1)/2)


N = int(input())
prev = -1
Col = []
for _ in range(N):
    c = int(input())
    if c == prev:
        continue
    else:
        prev = c
        Col.append(c)


cntF = [0]*(N+1)
forward = [0]*(len(Col)+1)
for i, c in enumerate(Col):
    forward[i] = cntF[c]
    cntF[c] += 1

cntB = [0]*(N+1)
back = [0]*(len(Col)+1)
for i in reversed(range(len(Col))):
    c = Col[i]
    back[i] = cntB[c]
    cntB[c] += 1

backr = back[::-1]
backr = list(accumulate(backr))
back = backr[::-1]
# print(forward)
# print(back)
ans = 1
for i in range(len(Col)):
    tmp = forward[i]*(back[i+1]+1)
   #print("tmp->", tmp)
    ans += tmp
    ans %= MOD
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

MOD = 10**9+7


def comb2(N):
    return int(N*(N-1)/2)


N = int(input())
prev = -1
Col = []
for _ in range(N):
    c = int(input())
    if c == prev:
        continue
    else:
        prev = c
        Col.append(c)


cntF = [0]*(N+1)
forward = [0]*(len(Col)+1)
for i, c in enumerate(Col):
    forward[i] = cntF[c]
    cntF[c] += 1

cntB = [0]*(N+1)
back = [0]*(len(Col)+1)
for i in reversed(range(len(Col))):
    c = Col[i]
    back[i] = cntB[c]
    cntB[c] += 1

ans = 1+sum(forward)
for i in range(1, len(Col)-1):
    ans = ans + forward[i]*back[i+1]
    ans %= MOD
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

MOD = 10**9+7


def comb2(N):
    return int(N*(N-1)/2)


N = int(input())
prev = -1
Col = []
for _ in range(N):
    c = int(input())
    if c == prev:
        continue
    else:
        prev = c
        Col.append(c)


cntF = [0]*(N+1)
forward = [0]*len(Col+1)
for i, c in enumerate(Col):
    forward[i] = cntF[c]
    cntF[c] += 1

cntB = [0]*(N+1)
back = [0]*(len(Col)+1)
for i in reversed(range(len(Col))):
    c = Col[i]
    back[i] = cntB[c]
    cntB[c] += 1

ans = 1+sum(forward)
for i in range(1, len(Col)-1):
    ans = ans + forward[i]*back[i+1]
    ans %= MOD
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

MOD = 10**9+7


def comb2(N):
    return int(N*(N-1)/2)


N = int(input())
prev = -1
Col = []
for _ in range(N):
    c = int(input())
    if c == prev:
        continue
    else:
        prev = c
        Col.append(c)


cntF = [0]*(N+1)
forward = [0]*len(Col)
for i, c in enumerate(Col):
    forward[i] = cntF[c]
    cntF[c] += 1

cntB = [0]*(N+1)
back = [0]*(len(Col))
for i in reversed(range(len(Col))):
    c = Col[i]
    back[i] = cntB[c]
    cntB[c] += 1

ans = 1+sum(forward)
for i in range(1, len(Col)-1):
    ans = ans + forward[i]*back[i+1]
    ans %= MOD
print(ans)