Problem:
 Score : 700 points    Problem Statement There are N stones arranged in a row. The i -th stone from the left is painted in the color C_i .  Snuke will perform the following operation zero or more times:   Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones.   Find the number of possible final sequences of colors of the stones, modulo 10^9+7 .      Constraints  1 \leq N \leq 2\times 10^5  1 \leq C_i \leq 2\times 10^5(1\leq i\leq N)  All values in input are integers.         Input Input is given from Standard Input in the following format:  N  C_1  :  C_N       Output Print the number of possible final sequences of colors of the stones, modulo 10^9+7 .        Sample Input 1 5
1
2
1
2
2      Sample Output 1 3  We can make three sequences of colors of stones, as follows:   (1,2,1,2,2) , by doing nothing.  (1,1,1,2,2) , by choosing the first and third stones to perform the operation.  (1,2,2,2,2) , by choosing the second and fourth stones to perform the operation.        Sample Input 2 6
4
2
5
4
2
4      Sample Output 2 5       Sample Input 3 7
1
3
1
2
3
3
2      Sample Output 3 5

Solution (Python):
n = int(input())

M = pow(10, 9) + 7
import sys

dc = {}
al = [0]

rr = [1]


def search(ss, start, end):
    z = al[(start + end)//2]
    nz = al[(start + end)//2+1]
    if z <= ss and ss < nz:
        return (start+end)//2
    elif ss < z:
        return search(ss, start, (start+end)//2)
    else:
        return search(ss, (start+end)//2+1, end)

c = 0
cn = 0
for line in sys.stdin:
    a = int(line)
    if a in dc:
        ss = dc[a]
        if ss != c-1:
            if ss >= al[cn]:
                rr.append((rr[cn]*2)%M)
            else:
                i = search(ss, 0, cn)
                rr.append((rr[cn] + rr[i])%M)
            al.append(c)
            cn += 1
    dc[a] = c
    c += 1
print(rr[cn]%M)

Solution (Python):
N = int(input())
C = [int(input()) for _ in range(N)]

MOD = 10 ** 9 + 7
recent = [-1 for _ in range(max(C))]
hist = []

ans = 1
for i in range(N):
    c = C[i] - 1
    if recent[c] >= 0 and recent[c] != i-1:
        ans = (ans + hist[recent[c]]) % MOD
    recent[c] = i
    hist.append(ans)
    
print(ans)

Solution (Python):
n = int(input())
c = [int(input()) for _ in range(n)]
m = 10**9+7

dp = [-1] * n
dp[0] = 1
last_dic = {}
for i in range(n):
    if c[i] in last_dic.keys() and i - last_dic[c[i]] >= 2:
        dp[i] = (dp[i-1] + dp[last_dic[c[i]]]) % m
    elif i:
        dp[i] = dp[i-1]
    last_dic[c[i]] = i
print(dp[-1])

Solution (Python):
import sys
input = sys.stdin.readline
mod = 10**9 +7
N = int(input())
C = [input() for _ in range(N)]
dic ={}
lis = [1]
before =C.pop(0)
dic[before]=[0]

for i,s in enumerate(C):
    lis.append(lis[-1])
    if s in dic.keys():
        if s != before:
            lis[-1] += lis[dic[s][-1]+1]
            
            
            dic[s].append(i)
    else:
        dic[s] = [i]
    before = s
    lis[-1] = lis[-1]%mod
print(lis[-1])

Solution (Python):
mod = 1000000007

N = int(input())
C = []
for i in range(N):
    c = int(input())
    if i == 0 or C[-1] != c:
        C.append(c)
cases = [1] * (len(C) + 1)
indexes = dict()
for i in range(1, 1 + len(C)):
    c = C[i - 1]
    if c not in indexes:
        cases[i] = cases[i - 1]
    else:
        cases[i] = (cases[i - 1] + cases[indexes[c]]) % mod
    indexes[c] = i
print(cases[len(C)])

Solution (Python):
N = int(input())
MODN = int(1e9 + 7)

D = {}
X = [0] * N

for i in range(N):
  c = int(input())
  if not c in D:
    X[i] = 1 if i == 0 else X[i-1]
    D[c] = i
    continue
    
  X[i] = (X[i-1] + X[D[c]]) % MODN if D[c] < i-1 else X[i-1]
  D[c] = i
    
print(X[N-1])

Solution (Python):
n = int(input())

mod = 10**9 + 7

dict = dict()
list = []
res = 1
for i in range(n):
  x = input()
  list.append(x)
  if x in dict and list[i - 1] != x:
    res += dict[x]
    dict[x] = res
  elif x not in dict:
    dict[x] = res

print(res % mod)

Solution (Python):
n = int(input())
c = [int(input())]
last = [-1 for _ in range(2 * (10 ** 5) + 1)]
for i in range(1, n):
    _c = int(input())
    if _c != c[-1]:  
        c.append(_c)

out = [0 for _ in range(len(c))]
out[0] = 1
last[c[0]] = 0
for i in range(1, len(c)):
    out[i] = out[i-1]
    if last[c[i]] >= 0:
        
        out[i] += out[last[c[i]]]
        out[i] %= 10 ** 9 + 7
    last[c[i]] = i
    
    
print(out[-1] % (10 ** 9 + 7))

Solution (Python):
n=int(input())
s=[[]for i in range(2*10**5+1)]
d=[1]
s[int(input())].append(0)
for i in range(1,n):
    j=int(input())
    t=0
    s[j].append(i)
    if len(s[j])>1:
        if s[j][-2]!=s[j][-1]-1:
            t+=d[i-1]+d[s[j][-2]]
        else:
            t+=d[i-1]
    else: 
        t+=d[i-1]
    d.append(t)
print(d[-1]%(10**9+7))

Solution (Python):
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline

    n = int(input())
    color_dict = {}
    ans = 1
    front_c = 0
    for _ in range(n):
        c = input().rstrip()
        if c != front_c:
            try:
                ans += color_dict[c]
                color_dict[c] = ans
            except KeyError:
                color_dict[c] = ans
            front_c = c
    print(ans%(10**9+7))

Solution (Python):

"""
Created on Sat Mar 16 20:36:58 2019

@author: Yamazaki Kenichi
"""

N = int(input())
C = [int(input()) for i in range(N)]
mod = 10**9+7
T = [[0] for i in range(2*10**5+1)]
ans = [1 for i in range(N+1)]
for i in range(N): 
    if i == 0 or C[i] != C[i-1]:
        T[C[i]][0] += 1
        T[C[i]].append(i)
        if T[C[i]][0] >=2:
            ans[i] = (ans[i-1] + ans[T[C[i]][-2]])%mod
        else:
            ans[i] = ans[i-1]%mod
    else:
        ans[i] = ans[i-1]%mod
        
print(ans[N-1]%mod)

Solution (Python):
N = int(input())
C = [int(input()) for _ in range(N)]
before = [-1] * (2 * 10**5 + 1)
count = [0] * (N + 1)
count[-1] = 1
mod = 10**9 + 7
for i in range(N):
    count[i] = count[i - 1]
    if 0 <= before[C[i]] < i - 1:
        count[i] += count[before[C[i]]]
        count[i] %= mod
    before[C[i]] = i
print(count[N - 1])

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import Counter, defaultdict

def compress(s):
    ret = []
    for i, si in enumerate(s):
        if i == 0:
            ret.append(si)
        else:
            if si == ret[-1]:
                continue
            else:
                ret.append(si)
                
    return ret

def removeonly1(s):
    cnt = Counter(s)
    ret = []
    
    for si in s:
        if cnt[si] == 1:
            continue
        else:
            ret.append(si)
            
    return ret

n = ni()
c = [ni() for _ in range(n)]
MOD = 10**9+7

colors = removeonly1(compress(c))


dp = [0 for _ in range(len(colors)+1)]

dp[0] = 1
idxs = defaultdict(list)
keys = set()

for i, ci in enumerate(colors):
    dp[i+1] = dp[i]
    
    if ci in keys:
        dp[i+1] += dp[idxs[ci][-1]+1]
        dp[i+1] %= MOD
        
    idxs[ci].append(i)
    keys.add(ci)
        
print(dp[len(colors)])

Solution (Python):
def int_raw():
    return int(raw_input())

def ss_raw():
    return raw_input().split()

def ints_raw():
    return map(int,ss_raw())

INF = 1<<29

DIV = 10**9+7

def make2d_arr(w,h,val =INF):
    return [[val]*w for i in xrange(h)]

def floyd_warshall(costs):
    N = len(costs)
    for k in xrange(N):
        for i in xrange(N):
            for j in xrange(N):
                costs[i][j]  = min(costs[i][j],costs[i][k]+costs[k][j])
    return costs

N = int_raw()
C =[]
dp = [0 for i in xrange(N)]

m_prev = {}
prevs = [-1 for i in xrange(N)]

for i in xrange(N):
    c = int_raw()
    C.append(c)
    if c in m_prev:
        prevs[i] = m_prev[c]
        m_prev[c]= i
    else:
        m_prev[c]=i
    
dp[0] =1

for x in xrange(1,N):
    cx = C[x]
    dp[x] = dp[x-1]
    if cx == C[x-1]:
        continue
    y = prevs[x]
    if y != -1:
        dp[x]+=dp[y]
        dp[x]= dp[x]%DIV        
    """for y in xrange(x-2,-1,-1):
        cy = C[y]
        if cx == cy:
            dp[x]+=dp[y]
            dp[x]= dp[x]%DIV
            break"""

print dp[-1]

Solution (Python):
n = int(input())
c = [int(input()) for _ in range(n)]

mod = 10**9 + 7

if n <= 2:
    print(1)
    exit()


a = [c[0]]
m = 1
for c1, c2 in zip(c, c[1:]):
    if c2 != c1:
        a.append(c2)
        m += 1

memo = [-1] * (2 * 10**5 + 1)
ans = 1
dp = [0] * (m+1)
dp[0] = 1

for i in range(m):
    if memo[a[i]] == -1:
        memo[a[i]] = i
        dp[i+1] = dp[i]
    else:
        idx = memo[a[i]] + 1
        dp[i+1] += dp[i] + dp[idx]
        dp[i+1] %= mod
        memo[a[i]] = i

print(dp[m] % mod)

Solution (Python):
import sys

MOD = 10**9 + 7

N = int(input())
Cs = [int(sys.stdin.readline())-1 for _ in range(N)]

numCs = [0] * (2 * 10**5)
anss = [0] * N
numCs[Cs[0]] = 1
anss[0] = 1
for i, C in enumerate(Cs[1:], 1):
    if C == Cs[i-1]:
        anss[i] = anss[i-1]
    else:
        numCs[C] += anss[i-1]
        anss[i] = numCs[C] % MOD

print(anss[-1])

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007


def A():
    n = I()
    s = S()
    d = defaultdict(int)
    for i in s:
        d[i] += 1
    ans = 1
    for i in d.keys():
        ans *= d[i]+1
        ans %= mod
    print(ans-1)

def B():
    n = I()
    c = IR(n)
    v = [[i+1] for i in range(n-1)]
    v.append([])
    d = defaultdict(deque)
    for i in range(n):
        d[c[i]].append(i)
    for i in d.keys():
        x = None
        while d[i]:
            y = d[i].popleft()
            if x != None and y != x+1:
                v[x].append(y)
            x = y
    path = [0]*(n)
    path[0] = 1
    q = [0]
    while q:
        x = heappop(q)
        for y in v[x]:
            if path[y] == 0:
                heappush(q,y)
            path[y] += path[x]
            path[y] %= mod
    print(path[-1])

def C():
    return


def D():
    return


def E():
    return


def F():
    return


def G():
    return


def H():
    return


if __name__ == "__main__":
    B()

Solution (Python):
from collections import defaultdict
mod = 10**9 + 7
n = int(input())
prev = None
s = []
d = defaultdict(list)
cnt = 0
for i in range(n):
    c = int(input())
    if prev == c:
        continue
    prev = c
    s.append(c)
    d[c].append(cnt)
    cnt += 1

DP = [0]*cnt
DP[0] = 1
e = {}
for i, c in enumerate(s):
    if i == cnt-1:
        break
    e[c] = e.get(c, 0) + 1
    j = e[c]
    DP[i+1] = (DP[i+1] + DP[i]) % mod
    if j < len(d[c]):
        DP[d[c][j]] = (DP[d[c][j]] + DP[i]) % mod
    
print(DP[-1])

Solution (Python):

from bisect import bisect, bisect_left
from collections import defaultdict

def inpl(): return list(map(int, input().split()))
MOD = 10**9 + 7
N = int(input())
C = [-1]
for i in range(N):
    c = int(input())
    if c != C[-1]:
        C.append(c)
C = C[1:]
N = len(C)
DP = [1]*N

ixs = defaultdict(lambda: [-1])
ixs[C[0]].append(0)

for i, c in enumerate(C[1:], start=1):
    l = ixs[c][bisect_left(ixs[c], i) - 1]
    if l != -1:
        DP[i] = (DP[i-1] + DP[l])%MOD
    else:
        DP[i] = (DP[i-1])%MOD
    ixs[c].append(i)
print(DP[-1])

Solution (Python):
from collections import defaultdict

MOD = int(1e9) + 7


def main():
    N = int(input())
    C = [int(input()) for _ in range(N)]
    dp = [1] * (N+1)
    last = defaultdict(lambda: -1)
    for i in range(N):
        c = C[i]
        if last[c] != -1 and last[c] != i-1:
            dp[i+1] = (dp[i] + dp[last[c]+1]) % MOD
        else:
            dp[i+1] = dp[i]
        last[c] = i
    print(dp[N])


if __name__ == "__main__":
    main()

Solution (Python):
n = int(raw_input())
c = [int(raw_input()) for i in range(n)]
mod = 1000000007

dp = [0] * len(c)
last = [-1] * 200001
dp[0] = 1
last[c[0]] = 0
for i in range(1, len(c)):
    dp[i] = dp[i - 1]
    if last[c[i]] >= 0 and last[c[i]] < i - 1:
        dp[i] = (dp[i] + dp[last[c[i]]]) % mod
    last[c[i]] = i

print dp[-1]

Solution (Python):
import sys
sys.setrecursionlimit(2000000000)
input=lambda : sys.stdin.readline().rstrip('\n')

n=int(input())
dic={}
c=[0]
for i in range(n):
    t=int(input())
    if c[-1]!=t:
        c.append(t)
g=[[i+1] for i in range(len(c)-1)]
g.append([])
for i in range(len(c)):
    if c[i] in dic:
        g[dic[c[i]]].append(i)
        dic[c[i]]=i
    else:
        dic[c[i]]=i
ans_table=[0 for i in range(len(c))]
ans_table[-1]=1
for i in range(len(c)-1):
    i=len(c)-2-i
    for to in g[i]:
        ans_table[i]+=ans_table[to]
print(ans_table[0]%(10**9+7))

Solution (Python):
N=int(input())
mod=10**9+7
dp=[0]*N
idx=dict()
idx[int(input())]=0
dp[0]=1
for i in range(1,N):
    C=int(input())
    if C in idx.keys():
        if idx[C]<i-1:
            dp[i]=(dp[idx[C]]+dp[i-1])%mod
        else:
            dp[i]=dp[i-1]
    else:
        dp[i]=dp[i-1]
    idx[C]=i
print(dp[-1])

Solution (Python):
from collections import defaultdict

M = 10**9 + 7
N = int(input())
C = [0]*N
for i in range(N):
    C[i] = int(input())

class increment:
    def __init__(self, start=0):
        self.index = start-1

    def __call__(self):
        self.index += 1
        return self.index

ui = defaultdict(increment())
clists = []
Nc = 0
for i in range(N):
    n = ui[C[i]]
    if n >= Nc:
        clists.append([i])
        Nc += 1
    else:
        clists[n].append(i)

P = [0]*N
Q = [0]*N
Q[0] = 1
QS = [0]*Nc
QS[ui[C[0]]] = 1
for i in range(1,N):
    if C[i] == C[i-1]:
        Q[i] = 0
    else:
        Q[i] = (P[i-1] + Q[i-1]) % M
    
    cind = ui[C[i]]
    P[i] = QS[cind]
    QS[cind] = (QS[cind] + Q[i]) % M

print((P[N-1]+Q[N-1]) % M)

Solution (Python):



n=int(input())
c = [int(input()) for i in range(n)]

r = [-1]*n
d=dict()
for i, cc in enumerate(c):
    if cc in d:
        r[i] = d[cc]
        d[cc] = i
    else:
        d[cc] = i



dp=[1]*n
dp[0]=1
for i in range(1,n):
    if r[i] == -1:
        dp[i] = dp[i-1]
    elif r[i] == i-1:
        dp[i] = dp[i-1]
    else:
        dp[i] = (dp[i-1] + dp[r[i]])%(10**9+7)


print(dp[n-1])

Solution (Python):
mod = 10**9+7
N = int(input())
Ca = [int(input())-1 for i in range(N)]
C = []
p = -1
for c in Ca:
    if p != c:
        C.append(c)
    p = c

N = len(C)
if N<=2:
    print(1)
    exit()
L = [-1]*(2*10**5)
dp = [0]*N
dp[0] = 1
L[C[0]] = 0


for i, c in enumerate(C[1:], 1):
    if L[c] == -1:
        L[c] = i
        dp[i] = dp[i-1]
        continue
    else:
        dp[i] = (dp[i-1] + dp[L[c]]) % mod
        L[c] = i
print(dp[-1])

Solution (Python):
import sys,bisect

sys.setrecursionlimit(10000000)
N = int(input())
C = [int(input()) for _ in range(N)] 
v = 10**9+7
from collections import defaultdict
d = defaultdict(list)
for i,c in enumerate(C):
    d[c].append(i)


def guchoku(l):
    assert isinstance(l,list)
    if len(l) <=2:
        return 1
    top_coor = l[0]
    if top_coor in l[1:] and l[0] != l[1]:
        _index= l[1:].index(top_coor)
        return guchoku(l[_index+1:])+ guchoku(l[1:])
    return guchoku(l[1:])

cache = dict()
cache[N] = 1
cache[N-1] = 1
cache[N-2] = 1

def check(i):
    index = bisect.bisect_left(d[C[i]],i+1)

    if index==len(d[C[i]]):
        return -1
    
    return d[C[i]][index]

def guchoku_i(i):
    
    if i<0:
        raise
    if i in cache:
        return cache[i]
    c = check(i)
    if C[i] != C[i+1] and c !=-1 :
        cache[i]= guchoku_i(i+1) + guchoku_i(c) %v
        return cache[i]
    cache[i]=  guchoku_i(i+1) %v
    return cache[i]


print(guchoku_i(0)%v )

Solution (Python):
N = int(input())
C = [int(input()) for _ in range(N)]
MOD = 10**9 + 7
subC = [-2] * (2 * 10 ** 5 + 10)
cntC = [-1]*N
for num, i in enumerate(C):
    cntC[num] = subC[i]+1
    subC[i] = num



dp = [0] * (N + 10)
dp[0] = 1
for i in range(N):
    if cntC[i] < 0 or cntC[i] == i:
        dp[i + 1] = dp[i] % MOD
    else:
        dp[i + 1] = (dp[i] + dp[cntC[i]]) % MOD


print(dp[N])

Solution (Python):
n = int(input())
mod = 10**9 + 7
c = [int(input()) for i in range(n)]

dp = [0 for i in range(n)]
dp[0] = 1
memo = {c[0]:0}
for i in range(1,n):
    if c[i] in memo:
        if memo[c[i]] != i-1:
            dp[i] =(dp[i-1] + dp[memo[c[i]]])%mod
            memo[c[i]] = i
        else:
            dp[i] = dp[i-1]
            memo[c[i]] = i
    else:
        dp[i] = dp[i-1]
        memo[c[i]] = i

print(dp[n-1])

Solution (Python):
N = int(input())
C = [int(input()) for _ in range(N)]

p = [0 for _ in range((2 * 10**5) + 1)]
dp = [0 for _ in range(N)]
p[C[-1]] = -1
dp[-1] = 1
for i in range(2, N + 1):
    if p[C[-i]] == 0 or p[C[-i]] == -i + 1:
        dp[-i] = dp[-i + 1]
    else:
        dp[-i] = (dp[-i + 1] + dp[p[C[-i]]]) % (10**9 + 7)
    p[C[-i]] = -i

ans = dp[0]
print(ans)

Solution (Python):
N = int(input())
C = [int(input()) for i in range(N)]
MOD = 10**9+7

A = []
for c in C:
    if A and A[-1]==c: continue
    A.append(c)

last = [-1] * 200001
B = [-1] * len(A)
for i,a in enumerate(A):
    B[i] = last[a]
    last[a] = i

dp = [0] * (len(A))
dp[0] = 1
for i in range(1,len(A)):
    bk = 0 if B[i] < 0 else dp[B[i]]
    dp[i] = (dp[i-1] + bk) % MOD
print(dp[-1])

Solution (Python):
mod = 10**9+7
n = int(input())
C = []
prev = None
for i in range(n):
	tmp = int(input())
	if tmp==prev:
		n -= 1
		continue
	else:
		C.append(tmp)
		prev = tmp
dp = [0]*n
dp[0] = 1
table = {C[0]:1}

for i in range(n-1):
	if C[i+1] not in table:
		table[C[i+1]]= 0 
	dp[i+1] = dp[i] + table[C[i+1]]  
	table[C[i+1]] += dp[i]
	dp[i+1] %= mod
	table[C[i+1]] %= mod

print(dp[n-1])

Solution (Python):
import sys

N=int(input())
C=[int(input()) for i in range(N)]
mod=10**9+7

if N==1:
    print(1)
    sys.exit()

S=[C[0]]

for i in range(1,N):
    if C[i]!=C[i-1]:
        S.append(C[i])

L=len(S)

if L==1:
    print(1)
    sys.exit()

AL=[[] for i in range(2*10**5+1)]

for i in range(L):
    AL[S[i]].append(i)

PLUS=[0]*(2*10**5+1)

NOW=1

for i in range(L):
    NOW,PLUS[S[i]]=(NOW+PLUS[S[i]])%mod,(PLUS[S[i]]+NOW)%mod
    
    

    


print(NOW)

Solution (Python):
import sys

N=int(input())
C=[int(input()) for i in range(N)]
mod=10**9+7

if N==1:
    print(1)
    sys.exit()

S=[C[0]]

for i in range(1,N):
    if C[i]!=C[i-1]:
        S.append(C[i])

L=len(S)

if L==1:
    print(1)
    sys.exit()

AL=[[] for i in range(2*10**5+1)]

for i in range(L):
    AL[S[i]].append(i)

PLUS=[0]*(2*10**5+1)

NOW=1

for i in range(L):
    NOW,PLUS[S[i]]=(NOW+PLUS[S[i]])%mod,(PLUS[S[i]]+NOW)%mod
    
    

    


print(NOW)

Solution (Python):
import sys
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
n = int(input())
a = [int(input()) for i in range(n)]
mod = 10**9+7
dp = [0]*(n+1)
mae = [-2]*(max(a)+1)
mae2 = [0]*(max(a)+1)
dp[0] = 1
for i in range(n):
        if mae[a[i]] != -2 and mae[a[i]] != i-1:
                dp[i+1] = dp[i] + mae2[a[i]]
        else:
                dp[i+1] = dp[i]
        dp[i+1] %= mod
        if mae[a[i]] == i-1:
                mae[a[i]] = i
                continue
        mae[a[i]] = i
        mae2[a[i]] += dp[i]
        mae2[a[i]] %= mod
print(dp[n]%mod)

Solution (Python):
from collections import Counter, defaultdict


def main():
    
    
    
    
    
    V = 10 ** 9 + 7
    n = int(input())
    c = [int(input()) for _ in range(n)]

    table = [0] * (n + 1)
    table[0] = 1

    D = defaultdict(lambda: 0)

    for i in range(n):
        ci = c[i]
        if i != 0:
            if c[i - 1] == ci:
                table[i + 1] = table[i] % V
                continue

        res = table[i]
        pre = D[ci]
        res += pre
        table[i + 1] = res % V

        D[ci] = D[ci] + table[i] % V

    print(table[-1])


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
DP = [0] * (N+1)
DP[0] = 1
su = [0] * (2*(10**5)+1)
prev = None
MOD = 10**9+7
for i in range(N):
    C = int(input())
    if prev == C:
        DP[i+1] = DP[i]
    else:
        su[C] += DP[i]
        su[C] %= MOD
        DP[i+1] = su[C]
    DP[i+1] %= MOD
    prev = C
print(DP[N])

Solution (Python):
import sys


fin = sys.stdin.readline
MOD = 10**9 + 7
N = int(fin())
C_list = tuple(int(fin()) for _ in range(N))

dp = [0] * N
dp[0] = 1
past_idx = {C_list[0]: 0}
for i, C in enumerate(C_list[1:], start=1):
    if C in past_idx:
        dp[i] = dp[i - 1] + dp[past_idx[C]] if i - past_idx[C] > 1 else dp[i - 1]

    else:
        dp[i] = dp[i - 1]
    past_idx[C] = i
    dp[i] %= MOD

print(dp[-1])

Solution (Python):
MOD = 10**9 + 7
N = int(input())
C = []
for i in range(N):
    c = int(input())-1
    if not C or C[-1] != c:
        C.append(c)
N = len(C)

prev = [None]*(max(C)+1)

dp = [0]*(N+1)
dp[0] = 1

for i,c in enumerate(C):
    if prev[c] is None:
        dp[i+1] = dp[i]
    else:
        dp[i+1] = dp[i] + dp[prev[c]+1]
    dp[i+1] %= MOD

    prev[c] = i

print(dp[N])

Solution (Python):
N = int(input())
C = [int(input()) for _ in range(N)]

dp = [0 for _ in range(N)]
dp[0] = 1

MOD = 10**9 + 7

r = [-1 for _ in range(N)]
prev = [-1 for _ in range(max(C) + 1)]

for i in range(N):
    if prev[C[i]] != -1 and prev[C[i]] + 1 != i:
        r[prev[C[i]]] = i
    prev[C[i]] = i

for i in range(N - 1):
    if r[i] != -1:
        dp[r[i]] += dp[i]
        dp[r[i]] %= MOD
    dp[i + 1] += dp[i]
    dp[i + 1] %= MOD

print(dp[N-1] % MOD)

Solution (Python):
MOD = 10 ** 9 + 7
n = int(input())
c = [int(input()) for _ in range(n)]
d = [c[0]]
for i in range(1, n):
	if c[i] != d[-1]:
		d.append(c[i])

n = len(d)
rightmost = [-1] * 200001
seg = []
for i in range(n):
	if rightmost[d[i]] >= 0:
		seg.append([rightmost[d[i]], i])
	rightmost[d[i]] = i


dp = [1 for _ in range(n)]
M = len(seg)
cnt = 0
for i in range(1, n):
	if cnt == M:
		dp[i] = dp[i-1]
	elif i == seg[cnt][1]:
		dp[i] = dp[i-1] + dp[seg[cnt][0]]
		cnt += 1
	else:
		dp[i] = dp[i-1]
	dp[i] %= MOD
print(dp[-1])

Solution (Python):

"""
This file is part of https://github.com/cheran-senthil/PyRival
Copyright 2019 Cheran Senthilkumar <hello@cheran.io>

"""
from __future__ import division, print_function

import itertools
import os
import sys
from atexit import register
from cStringIO import StringIO
from collections import Counter

range = xrange

filter = itertools.ifilter
map = itertools.imap
zip = itertools.izip

sys.stdout = StringIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = StringIO(os.read(0, os.fstat(0).st_size)).readline

MOD = 10**9 + 7
MODF = float(MOD)

MAGIC = 6755399441055744.0
SHRT = 65536.0

MODF_INV = 1.0 / MODF
SHRT_INV = 1.0 / SHRT

fround = lambda x: (x + MAGIC) - MAGIC
fmod = lambda a: a - MODF * fround(MODF_INV * a)
fmul = lambda a, b, c=0.0: fmod(fmod(a * SHRT) * fround(SHRT_INV * b) + a * (b - SHRT * fround(b * SHRT_INV)) + c)


def main():
    n = int(input())
    c = [int(input()) for _ in range(n)]

    _c, prev = [], 0
    for i in range(n):
        if c[i] != prev:
            _c.append(c[i])
        prev = c[i]
    c = _c
    n = len(c)

    prev_occur = [0] * (2 * 10**5 + 1)
    res, counts = [1.0] * (n + 1), Counter()
    for i in range(n):
        ind = prev_occur[c[i]]
        if ind != 0:
            res[i + 1] = fmod(res[i] + res[ind])
        else:
            res[i + 1] = res[i]

        counts[c[i]] += 1
        prev_occur[c[i]] = i + 1

    print(int(res[-1]) % MOD)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
MOD = 10 ** 9 + 7
memo = {}
prev_num = 1
prev = None
for _ in range(N):
  c = int(input())
  if prev == c:
    continue
  tmp = prev_num
  if c in memo:
    tmp += memo[c]
  tmp %= MOD
  memo[c] = tmp
  prev_num = tmp
  prev = c
print(prev_num % MOD)

Solution (Python):

N = int(input())
C_list = [0]*N
for i in range(N):
    C_list[i] = int(input()) - 1
    
LARGE = 10**9+7

T = 1
DP = [0]*(max(C_list) + 1)

for i in range(N):
    c = C_list[i]
    if i > 0:
        if C_list[i] == C_list[i-1]:
            pass
        else:
            T, DP[c] = (T + DP[c]) % LARGE, (DP[c] + T) % LARGE
    else:
        T, DP[c] = (T + DP[c]) % LARGE, (DP[c] + T) % LARGE
print(T)

Solution (Python):
from sys import exit, setrecursionlimit, stderr, stdin
from functools import reduce
from itertools import *
from collections import defaultdict, Counter
from bisect import bisect

setrecursionlimit(10**7)

M = 10 ** 9 + 7

def input():
  return stdin.readline().strip()

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

def solve():
  N = read()
  C = [-1] * N
  p = 0
  for i in range(N):
    c = read() - 1
    if C[p-1] != c:
      C[p] = c
      p += 1
  N = p
  del C[N:]

  dp = [0] * (N+1)
  dp[0] = 1
  last = [0] * (2 * 10**5 + 10)
  for i in range(N):
    c = C[i]
    last[c] = (last[c] + dp[i]) % M
    dp[i+1] = last[c]
  
  print(dp[-1])

solve()

Solution (Python):
import sys
from collections import defaultdict

n = int(input())
stones = [-1]
for line in sys.stdin:
    c = int(line)
    if stones[-1] == c:
        continue
    stones.append(c)

dp = 1
prev = defaultdict(lambda: 0)
MOD = 10 ** 9 + 7
for s in stones[1:]:
    dp = (dp + prev[s]) % MOD
    prev[s] = dp
print(dp)

Solution (Python):
N = input()
C = [input()-1 for _ in range(N)]

P = [-1]*(2*10**5)
T = [0]*N
M = 10**9+7
T[0] = 1
P[C[0]] = 0
for i in range(1,N):
  T[i] = T[i-1]
  p = P[C[i]]
  if p>=0 and i-p>=2:
    T[i] += T[p]
    T[i] %= M
  P[C[i]] = i
print T[-1]

Solution (Python):
import collections
MOD = int(1e9 + 7)
n = int(input())
dic = {}
f = [0] * (n + 1)
f[0] = 1
for i in range(n):
	x = int(input())
	if x not in dic:
		f[i + 1] = f[i]
	elif dic[x] == i - 1:
		f[i + 1] = f[i]
	else:
		f[i + 1] = (f[i] + f[dic[x] + 1]) % MOD
	dic[x] = i

print(f[-1] % MOD)