Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
C = dict()
i, cp, r = 0, 0, ['x'] * N
for _ in range(N):
    c = int(input())
    if c != cp:
        if c in C.keys():
            r[C[c]] = i
        C[c], cp = i, c
        i += 1
length = i
hist, add, temp, ans = [0] * length, [0] * length, 0, 0
for l in range(length):
    temp += add[l]
    hist[l] = temp
    if r[l] != 'x':
        add[r[l]] += temp + 1
        ans += temp + 1
print((ans+1) % (10**9+7))

Fixed submission:
N = int(input())
C = dict()
i, cp, hist, ans = 0, 0, [0]*N, 0
for _ in range(N):
    c = int(input())
    if c != cp:
        if c in C.keys():
            temp = hist[C[c]] + 1
            hist[i] = hist[i-1] + temp
            ans += temp
        else:
            hist[i] += hist[i-1]
        C[c], cp = i, c
        i += 1
print((ans+1) % (10**9+7))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
C = dict()
i, cp, r = 0, 0, ['x'] * N
for _ in range(N):
    c = int(input())
    if c != cp:
        if c in C.keys():
            r[C[c]] = i
        C[c], cp = i, c
        i += 1
length = i
hist, add, ans = [0] * length, [0] * length, 0
for l in range(length):
    hist[l] = hist[l-1] + add[l]    
    if r[l] != 'x':
        add[r[l]] += hist[l] + 1
        ans += hist[l] + 1
print((ans+1) % (10**9+7))

Fixed submission:
N = int(input())
C = dict()
i, cp, hist, ans = 0, 0, [0]*N, 0
for _ in range(N):
    c = int(input())
    if c != cp:
        if c in C.keys():
            temp = hist[C[c]] + 1
            hist[i] = hist[i-1] + temp
            ans += temp
        else:
            hist[i] += hist[i-1]
        C[c], cp = i, c
        i += 1
print((ans+1) % (10**9+7))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
C = dict()
i, cp, lr = 0, 0, []
for _ in range(N):
    c = int(input())
    if c != cp:
        if c in C.keys():
            lr.append([C[c], i])
        C[c] = i
        cp = c
        i += 1
length = i
lr.sort()
hist, add, i, ans = [0] * length, [0] * length, 0, 0
for l, r in lr:
    while i <= l:
        hist[i] = hist[i-1] + add[i]
        ans += add[i]
        i += 1
    add[r] += hist[l] + 1
if len(lr) != 0:
    for i in range(l+1, length):
        ans += add[i]
print((ans+1) % (10**9+7))

Fixed submission:
N = int(input())
C = dict()
i, cp, hist, ans = 0, 0, [0]*N, 0
for _ in range(N):
    c = int(input())
    if c != cp:
        if c in C.keys():
            temp = hist[C[c]] + 1
            hist[i] = hist[i-1] + temp
            ans += temp
        else:
            hist[i] += hist[i-1]
        C[c], cp = i, c
        i += 1
print((ans+1) % (10**9+7))

Buggy python submission (verdict: Runtime Error):
N = int(input())
C = dict()
i, cp, lr = 0, 0, []
for _ in range(N):
    c = int(input())
    if c != cp:
        if c in C.keys():
            lr.append([C[c], i])
        C[c] = i
        cp = c
        i += 1
length = i
lr.sort()
hist, add, i, ans = [0] * length, [0] * length, 0, 0
for l, r in lr:
    while i <= l:
        hist[i] = hist[i-1] + add[i]
        ans += add[i]
        i += 1
    add[r] += hist[l] + 1
for i in range(l+1, length):
    ans += add[i]
print((ans+1) % (10**9+7))

Fixed submission:
N = int(input())
C = dict()
i, cp, hist, ans = 0, 0, [0]*N, 0
for _ in range(N):
    c = int(input())
    if c != cp:
        if c in C.keys():
            temp = hist[C[c]] + 1
            hist[i] = hist[i-1] + temp
            ans += temp
        else:
            hist[i] += hist[i-1]
        C[c], cp = i, c
        i += 1
print((ans+1) % (10**9+7))

Buggy python submission (verdict: Runtime Error):
N = int(input())
C = dict()
i, cp, lr = 0, 0, []
for _ in range(N):
    c = int(input())
    if c != cp:
        if c in C.keys():
            lr.append([C[c], i])
        C[c] = i
        cp = c
        i += 1
lr.sort()
hist, add, i, ans = [0] * N, [0] * N, 0, 0
for l, r in lr:
    while i <= l:
        hist[i] = hist[i-1] + add[i]
        ans += add[i]
        i += 1
    add[r] += hist[l] + 1
for i in range(l+1, N):
    ans += add[i]
print(ans+1)

Fixed submission:
N = int(input())
C = dict()
i, cp, hist, ans = 0, 0, [0]*N, 0
for _ in range(N):
    c = int(input())
    if c != cp:
        if c in C.keys():
            temp = hist[C[c]] + 1
            hist[i] = hist[i-1] + temp
            ans += temp
        else:
            hist[i] += hist[i-1]
        C[c], cp = i, c
        i += 1
print((ans+1) % (10**9+7))