Buggy python submission (verdict: Time Limit Exceeded):
#import time
#t = []

N = int(input())

#st = time.time()

sums = [1]  # pair number sum until index
#cpos = [-1] * (2 * 10 ** 5 + 1)    # positions of each color
cpos = {}
lastc = -1  # last color of input
C = []      # color stone list

#print("prepare time [ms] = {}".format(1000 * (time.time() - st)))

for i in range(N):
    c = int(input())

#    sti = time.time()
#    st = time.time()

    if(lastc != c):
        lastc = c
        C.append(c)
        cnt = len(C)
#        print("lastc = {}, cnt = {}, C = {}".format(lastc, cnt, C))

#        print("prepare time in loop [ms] = {}".format(1000 * (time.time() - st)))
#        st = time.time()

        if(c in cpos):
            s = sums[-1]
            for pos in cpos[c]:
                s += sums[pos - 1]
            sums.append(s)
            cpos[c].append(cnt)
        else:
            sums.append(sums[-1])
            cpos[c] = [cnt]

#        print("calc time [ms] = {}".format(1000 * (time.time() - st)))
#        print("cpos = " + str(cpos))

#    print("iteration time [ms] = {}".format(1000 * (time.time() - sti)))

#print("C = " + str(C))
#print("cpos = " + str(cpos))
#print("sums = " + str(sums))

print(sums[-1] % (10 ** 9 + 7))


Fixed submission:
sums = [1]  # pair number sum until index
csums = {}  # pair number sum of each color

N = int(input())
C = []      # color stone list
lastc = -1  # last color of input
for i in range(N):
    c = int(input())
    if(lastc == c):
        continue
    lastc = c
    C.append(c)

#print("C = " + str(C))

for i, c in enumerate(C, 1):
    if(c in csums):
        sums.append(sums[-1] + csums[c])
        csums[c] += sums[i - 1]
    else:
        sums.append(sums[-1])
        csums[c] = sums[i - 1]

#    print("i = {}, c = {}".format(i, c))
#    print("csums = " + str(csums))
#    print("sums = " + str(sums))

print(sums[-1] % (10 ** 9 + 7))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
sums = [1]  # pair number sum until index
cpos = [-1] * (2 * 10 ** 5 + 1)    # positions of each color
#cpos = [-1] * (10)
lastc = -1  # last color of input
C = []      # color stone list
for i in range(N):
    c = int(input())
    if(lastc != c):
        lastc = c
        C.append(c)
        cnt = len(C)
#        print("lastc = {}, cnt = {}, C = {}".format(lastc, cnt, C))
        if(-1 == cpos[c]):
            cpos[c] = [cnt]
            sums.append(sums[-1])
        else:
            s = sums[-1]
            for pos in cpos[c]:
                s += sums[pos - 1]
            sums.append(s)
            cpos[c].append(cnt)
#        print("cpos = " + str(cpos))

#print("C = " + str(C))
#print("cpos = " + str(cpos))
#print("sums = " + str(sums))

print(sums[-1] % (10 ** 9 + 7))


Fixed submission:
sums = [1]  # pair number sum until index
csums = {}  # pair number sum of each color

N = int(input())
C = []      # color stone list
lastc = -1  # last color of input
for i in range(N):
    c = int(input())
    if(lastc == c):
        continue
    lastc = c
    C.append(c)

#print("C = " + str(C))

for i, c in enumerate(C, 1):
    if(c in csums):
        sums.append(sums[-1] + csums[c])
        csums[c] += sums[i - 1]
    else:
        sums.append(sums[-1])
        csums[c] = sums[i - 1]

#    print("i = {}, c = {}".format(i, c))
#    print("csums = " + str(csums))
#    print("sums = " + str(sums))

print(sums[-1] % (10 ** 9 + 7))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
C = []
for i in range(N):
    c = int(input())
    C.append(c)

pairs = []
pairnum = 0
for i in range(N - 2):
    if(C[i + 1] == C[i]):
#        print("col = {} : [{} - {}] : same -> skip".format(C[i], i, i + 1))
        continue
    prev = 0
    for j in range(i + 2, N):
#        print("C[{}] = {}, C[{}] = {}".format(i, C[i], j, C[j]))
        if(prev == C[j]):
            continue
        if(C[j] == C[i]):
#            print("col = {} : [{} - {}]".format(C[i], i, j))
            pairs.append([i, j])
            pairnum = pairnum + 1
        prev = C[j]
#print(str(pairs))

ans = 0
for i in range(1, 2 ** pairnum):
    lastidx = -1
    nocount = 0
#    print("check pair pattern = " + hex(i))
    for j in range(pairnum):
#        print("last idx = {}".format(lastidx))
        if(1 == ((i >> j) & 1)):
            if(lastidx >= pairs[j][0]):
                nocount = 1
                break
            else:
                lastidx = pairs[j][1]
    if(0 == nocount):
        ans = ans + 1
#        print("add pair pattern = " + hex(i))
ans = ans + 1
print(ans % (10 ** 9 + 7))


Fixed submission:
sums = [1]  # pair number sum until index
csums = {}  # pair number sum of each color

N = int(input())
C = []      # color stone list
lastc = -1  # last color of input
for i in range(N):
    c = int(input())
    if(lastc == c):
        continue
    lastc = c
    C.append(c)

#print("C = " + str(C))

for i, c in enumerate(C, 1):
    if(c in csums):
        sums.append(sums[-1] + csums[c])
        csums[c] += sums[i - 1]
    else:
        sums.append(sums[-1])
        csums[c] = sums[i - 1]

#    print("i = {}, c = {}".format(i, c))
#    print("csums = " + str(csums))
#    print("sums = " + str(sums))

print(sums[-1] % (10 ** 9 + 7))