Buggy python submission (verdict: Time Limit Exceeded):
def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def main():
    mod = 10 ** 9 + 7
    N = int(input())
    C = [int(input()) for _ in range(N)]

    dp = [1] * (N + 1)
    dp[0] = 1
    D = {c: set() for c in set(C)}
    pre = -1
    for n in range(N):
        c = C[n]
        S = D[c]
        dp[n + 1] = dp[n]
        if pre == c:
            dp[n] = 0
            continue

        if len(S) != 0:
            dp[n + 1] = (dp[n + 1] + sum(dp[s] for s in S)) % mod
        D[c].add(n)
        pre = c
    print(dp[-1])


if __name__ == "__main__":
    main()


Fixed submission:
def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def main():
    mod = 10 ** 9 + 7
    N = int(input())

    dp = [1] * (N + 1)
    dp[0] = 1
    D = {}
    pre = -1
    for n in range(N):
        c = int(input())
        dp[n + 1] = dp[n]
        if pre == c:
            dp[n] = 0
            continue
        r = D.setdefault(c, 0)
        dp[n + 1] = (dp[n + 1] + r) % mod
        D[c] = r + dp[n]
        pre = c
    print(dp[-1])


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def main():
    mod = 10 ** 9 + 7
    N = int(input())
    C = [int(input()) for _ in range(N)]

    dp = [1] * (N + 1)
    dp[0] = 1
    D = {}
    pre = -1
    for n in range(N):
        c = C[n] 
        S = D.setdefault(c, set())
        dp[n + 1] = dp[n]
        if pre == c:
            dp[n] = 0
            continue
        for s in S:
            dp[n + 1] = (dp[n + 1] + dp[s]) % mod 
        pre = c
        D.setdefault(c, set()).add(n)
    print(dp[-1])


if __name__ == "__main__":
    main()


Fixed submission:
def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def main():
    mod = 10 ** 9 + 7
    N = int(input())

    dp = [1] * (N + 1)
    dp[0] = 1
    D = {}
    pre = -1
    for n in range(N):
        c = int(input())
        dp[n + 1] = dp[n]
        if pre == c:
            dp[n] = 0
            continue
        r = D.setdefault(c, 0)
        dp[n + 1] = (dp[n + 1] + r) % mod
        D[c] = r + dp[n]
        pre = c
    print(dp[-1])


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def main():
    mod = 10 ** 9 + 7
    N = int(input())
    C = [int(input()) for _ in range(N)]

    dp = [1] * (N + 1)
    dp[0] = 1
    D = {}
    pre = -1
    for n in range(N):
        c = C[n] 
        S = D.setdefault(c, set())
        dp[n + 1] = dp[n]
        if pre == c:
            dp[n] = 0
            continue
        for s in S:
            dp[n + 1] = (dp[n + 1] + dp[s]) % mod 
        pre = c
        D.setdefault(c, set()).add(n)
    print(dp[-1])


if __name__ == "__main__":
    main()


Fixed submission:
def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def main():
    mod = 10 ** 9 + 7
    N = int(input())

    dp = [1] * (N + 1)
    dp[0] = 1
    D = {}
    pre = -1
    for n in range(N):
        c = int(input())
        dp[n + 1] = dp[n]
        if pre == c:
            dp[n] = 0
            continue
        r = D.setdefault(c, 0)
        dp[n + 1] = (dp[n + 1] + r) % mod
        D[c] = r + dp[n]
        pre = c
    print(dp[-1])


if __name__ == "__main__":
    main()