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



Sample input:
5
1
2
1
2
2


Sample output:
3

Submission status: Wrong Answer

Solution code:
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
def solve_binary(mid,j):
    return pairs[mid][0] >= j

def binary_search(n,j):
    ok=n
    ng=0
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if solve_binary(mid,j):
            ok=mid
        else:
            ng=mid
    return ok

n = int(input())
C = [int(input()) for i in range(n)]
pairs = []
data = [-1]*(2*10**5+1)
for i,ci in enumerate(C):
  if data[ci] != -1 and abs(i-data[ci]) != 1:
    pairs.append((data[ci],i))
  data[ci] = i
pairs.sort()
l = len(pairs)
for i,j in pairs:
  k = binary_search(l,j)
  # print(k,12345)
  ans += l-k+1
  ans %= mod
print((ans+1)%mod)
# print(pairs)

Submission status: Wrong Answer

Solution code:
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
def solve_binary(mid,j):
    return pairs[mid][0] >= j

def binary_search(n,j):
    ok=n
    ng=0
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if solve_binary(mid,j):
            ok=mid
        else:
            ng=mid
    return ok

n = int(input())
C = [int(input()) for i in range(n)]
pairs = []
data = [-1]*(2*10**5+1)
for i,ci in enumerate(C):
  if data[ci] != -1 and abs(i-data[ci]) != 1:
    pairs.append((data[ci],i))
  data[ci] = i
pairs.sort()
l = len(pairs)
for i,j in pairs:
  k = binary_search(l,j)
  print(k,12345)
  ans += l-k+1
  ans %= mod
print((ans+1)%mod)
print(pairs)

Submission status: Wrong Answer

Solution code:
import sys,math,collections,itertools
input = sys.stdin.readline

N = int(input())
ans = 1
m=10**9+7
c=[]
for _ in range(N):
    c.append(int(input()))
dp = [1]*(N+1)#dp[i] i番目までの並び替え総数
last_color = [-1]*(max(c)+1)#最後にその色が出たindexの保存
last_color[c[0]] =0
for i in range(1,N):
    if c[i]==c[i-1]:#同じ色が続くとリバーシできない
        dp[i] = dp[i-1]
    else:
        if last_color[c[i]]==-1:#初めての色はリバーシできない
            dp[i] = dp[i-1]
            last_color[c[i]]=i
        else:#挟める石があるし色が連続してない
            dp[i] = dp[i-1]+dp[last_color[c[i]]]#最後に出た石と挟むか挟まないk
            last_color[c[i]]=i
print(dp[N-1])

Submission status: Wrong Answer

Solution code:
import sys,math,collections,itertools
input = sys.stdin.readline

N = int(input())
ans = 1
m=10**9+7
c=[]
for _ in range(N):
    c.append(int(input()))
dp = [1]*(N+1)#dp[i] i番目までの並び替え総数
last_color = [-1]*(max(c)+1)#最後にその色が出たindexの保存
last_color[c[0]] =1
for i in range(1,N):
    if c[i]==c[i-1]:#同じ色が続くとリバーシできない
        dp[i+1] = dp[i]
    else:
        if last_color[c[i]]==-1:#初めての色はリバーシできない
            dp[i+1] = dp[i]
            last_color[c[i]]=i+1
        else:#挟める石があるし色が連続してない
            dp[i+1] = dp[i]+dp[last_color[c[i]]]#最後に出た石と挟むか挟まないk
            last_color[c[i]]=i+1
print(dp[N])

Submission status: Wrong Answer

Solution code:
import sys,math,collections,itertools
input = sys.stdin.readline

N = int(input())
ans = 1
m=10**9+7
c=[]
for _ in range(N):
    c.append(int(input()))
dp = [1]*(N+1)#dp[i] i番目までの並び替え総数
last_color = [-1]*(max(c)+1)#最後にその色が出たindexの保存
last_color[c[0]] =1
for i in range(1,N):
    if c[i]==c[i-1]:#同じ色が続くとリバーシできない
        dp[i+1] = dp[i]
    else:
        if last_color[c[i]]==-1:#初めての色はリバーシできない
            dp[i+1] = dp[i]
            last_color[c[i]]=i
        else:#挟める石があるし色が連続してない
            dp[i+1] = dp[i]+dp[last_color[c[i]]]#最後に出た石と挟むか挟まないk
            last_color[c[i]]=i
print(dp[N])

Submission status: Wrong Answer

Solution code:
import sys,math,collections,itertools
input = sys.stdin.readline

N = int(input())
ans = 1
m=10**9+7
c=[]
for _ in range(N):
    c.append(int(input()))
dp = [1]*(N)#dp[i] i番目までの並び替え総数
last_color = [-1]*(max(c)+1)#最後にその色が出たindexの保存
last_color[c[0]] =0
for i in range(1,N):
    if c[i]==c[i-1]:#同じ色が続くとリバーシできない
        dp[i] = dp[i-1]
    else:
        if last_color[c[i]]==-1:#初めての色はリバーシできない
            dp[i] = dp[i-1]
            last_color[c[i]]=i
        else:#挟める石があるし色が連続してない
            dp[i] = dp[i-1]+dp[last_color[c[i]]]#最後に出た石と挟むか挟まないかの遷移
            last_color[c[i]]=i
print(dp[N-1])

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
tmp = -1
c = []
for _ in range(N):
	C = INT()
	if C != tmp:
		c.append(C)
	tmp = C

n = len(c)
dic = defaultdict(int)

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

for i in range(n):
	dp[i+1] = dp[i] + dic[c[i]]
	dic[c[i]] += dp[i]

print(dp[-1])

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

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

from collections import defaultdict
last = -1
dic = defaultdict(list)
idx = 0
lis = []
for i in range(N):
    c = int(input())
    if c==last:
        continue
    last = c
    dic[c].append(idx)
    lis.append(c)
    idx += 1
memo = {}
def dfs(i):
    if i==idx:
        return 1
    if i in memo.keys():
        return memo[i]
    v = lis[i]
    ret = 0
    for nx in dic[v]:
        if nx<=i: continue
        ret += dfs(nx+1)
    ret += dfs(i+1)
    memo[i] = ret
    return ret
print(dfs(0))

Submission status: Wrong Answer

Solution code:
import bisect
N = int(input())
C = []
dic = {}
for i in range(N):
  temp = int(input())
  C.append(temp)
  if temp not in dic:
    dic[temp] = [i]
  else:
    dic[temp].append(i)  
#print(C)
#print(dic)
dp = [0 for _ in range(N)]
dp[0] = 1
for i in range(N):
  #print(dp)
  if i>= 1 and C[i] == C[i-1]:
    dp[i] = dp[i-1]
    continue
  if i >= 1:
    dp[i] += dp[i-1]
  #print(dp,i)
  color = C[i]
  temp = bisect.bisect_left(dic[color],i)
  if temp == 0:
    continue
  loc = dic[color][temp-1]
  #print(i,temp,dp[loc])
  dp[i] += dp[loc]
print(dp[-1])

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

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

from collections import defaultdict
last = -1
dic = defaultdict(list)
idx = 0
lis = []
for i in range(N):
    c = int(input())
    if c==last:
        continue
    last = c
    dic[c].append(idx)
    lis.append(c)
    idx += 1

memo = {}
def dfs(i):
    if i==idx:
        return 1
    if i in memo:
        return memo[i]
    v = lis[i]
    ret = 0
    for nx in dic[v]:
        if nx<=i: continue
        ret += dfs(nx)
    ret += dfs(i+1)
    memo[i] = ret
    return ret
print(dfs(0))

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
c = np.array([int(input()) for _ in range(n)])

MOD = 10**9 + 7

# dpテーブル
dp = np.zeros(n, dtype=np.int64)
dp[0] = 1

used = np.full(c.max() + 1, -1, dtype=np.int64)

for i in range(1, n):
    if used[c[i]] == -1:
        dp[i] = dp[i - 1]
    else:
        dp[i] = (dp[i - 1] + dp[used[c[i]]]) % MOD
    used[c[i]] = i

print(dp[-1])

Submission status: Wrong Answer

Solution code:
from collections import deque
from heapq import heappush, heappop
import sys
input = sys.stdin.readline


def main():
    mod = 10**9 + 7
    n = int(input())
    colors = [int(input()) for _ in range(n)]
    pos_dict = {}
    for i, color in enumerate(colors):
        if color not in pos_dict:
            pos_dict[color] = deque([])
            continue
        pos_dict[color].append(i)

    branches = []
    base = 1
    for i, color in enumerate(colors):
        if branches and branches[0][0] == i:
            _, add = heappop(branches)
            base += add
            base &= mod

        if pos_dict[color]:
            next = pos_dict[color].popleft()
            if next == i+1:
                continue
            add = base
            heappush(branches, (next, add))

    print(base % mod)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import deque
from heapq import heappush, heappop
import sys
input = sys.stdin.readline


def main():
    n = int(input())
    colors = [int(input()) for _ in range(n)]
    pos_dict = {}
    for i, color in enumerate(colors):
        if color not in pos_dict:
            pos_dict[color] = deque([])
            continue
        pos_dict[color].append(i)

    branches = []
    base = 1
    for i, color in enumerate(colors):
        if branches and branches[0][0] == i:
            _, add = heappop(branches)
            base += add

        if pos_dict[color]:
            next = pos_dict[color].popleft()
            if next == i+1:
                continue
            add = base
            heappush(branches, (next, add))

    print(base)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from itertools import groupby

n = int(input())
C = [key for key, _ in groupby([int(input()) for _ in range(n)])]

N = len(C)

MOD = 10 ** 9 + 7

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

T = {}
T[C[0]] = 0

for i in range(1, N):
  if i == 0 or C[i - 1] == C[i] or C[i] not in T:
    dp[i] = dp[i - 1]
  else:
    j = T[C[i]]
    dp[i] = dp[i - 1] + dp[j]
  T[C[i]] = i

print(dp[N - 1])

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import bisect
import copy

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    last = [-1 for _ in range(2 * 10 ** 5 + 1)]
    d = []
    dp = [INF for _ in range(n + 1)]
    dp[0] = 1

    for i in range(n):
        di = ni()
        di -= 1
        if i > 0:
            if d[-1] == di:
                d.append(-1)
                continue
        d.append(di)

    for i, di in enumerate(d):
        dp[i + 1] = dp[i]
        if di == -1:
            last[di] = i
            continue
        if last[di] != -1:
            if i - last[di] != -1:
                dp[i + 1] += dp[last[di] + 1]
                dp[i + 1] %= MOD
        last[di] = i

    print(dp[n])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import bisect
import copy

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    last = [-1 for _ in range(2 * 10 ** 5 + 1)]
    d = []
    dp = [INF for _ in range(n + 1)]
    dp[0] = 1

    for i in range(n):
        di = ni()
        di -= 1
        if i > 0:
            if d[-1] == di:
                d.append(-1)
                continue
        d.append(di)

    for i, di in enumerate(d):
        dp[i + 1] = dp[i]
        if di == -1:
            last[di] = i
            continue
        if last[di] != -1:
            dp[i + 1] += dp[last[di] + 1]
            dp[i + 1] %= MOD
        last[di] = i

    print(dp[n])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import bisect
import copy

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    last = [-1 for _ in range(2 * 10 ** 5 + 1)]
    d = []
    dp = [INF for _ in range(n + 1)]
    dp[0] = 1

    for i in range(n):
        di = ni()
        di -= 1
        if i > 0:
            if d[-1] == di:
                d.append(-1)
                continue
        d.append(di)

    for i, di in enumerate(d):
        dp[i + 1] = dp[i]
        if di == -1:
            continue
        if last[di] != -1:
            dp[i + 1] += dp[last[di] + 1]
            dp[i + 1] %= MOD
        last[di] = i

    print(dp[n])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import bisect
import copy

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    idxlist = [[] for _ in range(2 * 10 ** 5 + 1)]
    d = []
    dp = [INF for _ in range(n + 1)]
    dp[0] = 1

    for i in range(n):
        di = ni()
        di -= 1
        if i > 0:
            if d[-1] == di:
                d.append(-1)
                continue
        d.append(di)
        idxlist[di].append(i)

    for i, di in enumerate(d):
        # print(i)
        dp[i + 1] = dp[i]
        if di == -1:
            continue
        bidx = bisect.bisect_left(idxlist[di], i)
        if bidx - 1 >= 0:
            dp[i + 1] += dp[idxlist[di][bidx - 1] + 1]
            dp[i + 1] %= MOD

    print(dp[n])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import bisect
import copy

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    idxlist = [[] for _ in range(2 * 10 ** 5 + 1)]
    d = []
    dp = [INF for _ in range(n + 1)]
    dp[0] = 1

    for i in range(n):
        di = ni()
        di -= 1
        if i > 0:
            if d[-1] == di:
                d.append(-1)
                continue
        d.append(di)
        idxlist[di].append(i)

    for i, di in enumerate(d):
        print(i)
        dp[i + 1] = dp[i]
        if di == -1:
            continue
        bidx = bisect.bisect_left(idxlist[di], i)
        if bidx - 1 >= 0:
            dp[i + 1] += dp[idxlist[di][bidx - 1] + 1]
            dp[i + 1] %= MOD

    print(dp[n])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#AGC032-B
"""
dp解法。
そこまでにその色で出来た組み合わせの総和がいくつかを保持する配列を
持っておく。
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n = int(readline())
lst1 = []
bef = -1
for i in range(n):
    res = int(readline())
    if bef == res:
        continue
    else:
        lst1.append(res)
        bef = res

n = len(lst1)
lst2 = [-1]*(2*10**5+1)
dp = [0]*(n+1)
dp[0] = 1
for i in range(1,n+1):
    c = lst1[i-1]
    if lst2[c]==-1:
        lst2[c] = i
        dp[i] = dp[i-1]
    else:
        dp[i] = dp[i-1] + dp[lst2[c]]%(10**9+7)
        lst2[c] = i

print(dp[-1])

Submission status: Wrong Answer

Solution code:
n,*cc = map(int, open(0).read().split())
MOD = 10**9+7

from collections import defaultdict
d = {}
dp = defaultdict(lambda: 1)

for i,c in enumerate(cc):
    dp[i] = dp[i-1]
    if c in d:
        j = d[c]
        if i - j <= 1:
            continue
        dp[i] += dp[j]
        dp[i] %= MOD
    d[c] = i

print(dp[n-1])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
C = {A[0]:1}
for i in range(1,N):
    if A[i]!=A[i-1]:
        if A[i] not in C:
            C[A[i]] = 0
        C[A[i]] += 1
cnt = 1
for a in C:
    cnt += (C[a]*(C[a]-1))//2
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
MOD = 10**9+7
n = int(input())
colors = defaultdict(list)
next_v = [-1]*n
for i in range(n):
    c = int(input())
    if colors[c]:
        next_v[colors[c][-1]] = i
    colors[c].append(i)

ans = 1
visited = [0]*n
for i in range(n):
    if visited[i]:
        continue
    visited[i] = 1
    cnt = 0
    while True:
        x = next_v[i]
        if x == -1:
            while i < n:
                if visited[i]:
                    i += 1
                    continue
                visited[i] = 1
                break
            else:
                break
            continue
        visited[x] = 1
        if i+1 == x:
            i = x
            continue
        cnt += 1
        i = x
    ans += pow(2, cnt, MOD)-1
    ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = []
for _ in range(n):
    c.append(int(input()))

dp = [0] * n
dp[0] = 1

pre = [-1] * n
tmp = [-1] * (2*10**5+10)

for i in range(n):
    pre[i] = tmp[c[i]-1]
    tmp[c[i]-1] = i

for i in range(1,n):
    dp[i] = dp[i-1]
    if pre[i] != -1 and c[i] != c[i-1]:
        dp[i] += dp[pre[i]]

print(dp[-1])

Submission status: Wrong Answer

Solution code:
N = int(input())
s = set()
dic = {}
memo = [0]*(N+1)
memo[0] = 1
P = 10**9 + 7

for i in range(1,N+1):
  c = int(input())
  if c not in s:
    s.add(c)
    dic[c] = [i]
    memo[i] = memo[i-1]
  else:
    memo[i] = memo[i-1]
    if dic[c][-1] != i-1:
      for j in dic[c]:
        memo[i] += memo[j-1]
        memo[i] %= P
      dic[c].append(i)
      
print(memo[N])

Submission status: Wrong Answer

Solution code:
import sys


input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	n = int(input())
	#b , c = tin()
	#s = input()
	dd = dict()
	
	v = int(input())
	dd[v] = 0
	ll=[0]*n
	ll[0]=1
	for i in range(1, n):
		v = int(input())
		if v not in dd or dd[v] == i-1:
			ll[i] = ll[i-1]
			dd[v] = i
		else:
			ll[i] = ll[i-1] + ll[dd[v]]
			dd[v] = i
	return ll[-1]
			
		
	
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]

na = [a[0]]
for i in range(n-1):
    if a[i] != a[i+1]:
        na.append(a[i+1])
        
m = len(na)
cur = [-1]*(max(na)+1)

dp = [0]*(m+1)
dp[0] = 1
for i in range(m):
    if cur[na[i]] != -1:
        dp[i+1] = dp[i] + dp[cur[na[i]]]
        cur[na[i]] = i+1
    else:
        cur[na[i]] = i+1
        dp[i+1] = dp[i]
        
print(dp[m])

Submission status: Wrong Answer

Solution code:
N = int(input())
L = [-1] * (2 * 10 ** 5 + 1)

dp = [0] * (N + 1)

dp[0] = 1

for i in range(N):
    dp[i+1] += dp[i]
    color = int(input())
    if L[color] != -1 and L[color] != i:
        dp[i+1] += dp[L[color]]
    L[color] = i+1

print(dp[N])

Submission status: Wrong Answer

Solution code:
def resolve():
    n = int(input())
    c = [int(input()) for i in range(n)]
    lac = [-1]* 200010
    dp = [0]*n

    dp[0] = 1
    lac[c[0]] = 0
    for i in range(1, n):
        color =c[i]
        if c[i] == c[i-1]:
            dp[i] = dp[i-1]
        elif lac[color] == -1:
            dp[i] = dp[i-1]
        else:
            dp[i] = dp[i-1] + dp[lac[color]]
        lac[color] = i
    print(dp[-1])
resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    n = int(input())
    c = [int(input()) for i in range(n)]
    lac = [-1]* 200010
    dp = [0]*n
    nc = [c[0]]
    for i in range(1, n):
        if nc[-1] == c[i]:
            continue
        else:
            nc.append(c[i])
    dp[0] = 1
    lac[nc[0]] = 0
    for i in range(1, len(nc)):
        color =nc[i]
        if lac[color] == -1:
            dp[i] = dp[i-1]
        else:
            dp[i] = dp[i-1] + dp[lac[color]]
        lac[color] = i
    print(dp[len(nc)-1])
resolve()

Submission status: Wrong Answer

Solution code:
n=int(input())
c=[]
cnt=[]
d={}
for i in range(n):
  c.append(int(input()))
  if c[-1] in d:
    cnt.append(len(d[c[-1]]))
    d[c[-1]].append(i)
  else:
    cnt.append(0)
    d[c[-1]]=[i]

dp=[0 for i in range(n+1)]
dp[0]=1
for i in range(n):
  col=c[i]
  ccnt=cnt[i]
  if ccnt+1!=len(d[col]):
    cnext=d[col][ccnt+1]
    if cnext-i!=1:
      dp[cnext]+=dp[i]
  dp[i+1]+=dp[i]
print(dp[-1])

Submission status: Wrong Answer

Solution code:
n = int(input())
c = [int(input()) for _ in range(n)]
v_c = []
for i,v in enumerate(c):
    if i > 0 and v == c[i-1]:
        continue
    v_c.append(v)

dp = [1]*(n+1)
color_cnt = [-1]*(2*10**5+5)
for i in range(1, len(v_c)+1):
    color = v_c[i-1]
    if color_cnt[color] > 0:
        dp[i] = dp[i-1] + dp[color_cnt[color]]
    else:
        dp[i] = dp[i-1]
    color_cnt[color] = i
print(dp[len(v_c)])

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
input = sys.stdin.readline
input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')

#import numpy as np

def main():
	n=II()
	C=[]
	pre=0
	for i in range(n):
		a=II()
		if a!=pre:
			C.append(a)
		pre=a
	#print(C)

	n=len(C)
	dp=[0]*(n+1)
	dp[1]=1
	li=[0]*(max(C)+10)
	li[C[0]]=1

	for i in range(1,n):
		#print(dp)
		#print(li)
		dp[i+1]=dp[i]+dp[li[C[i]]]
		li[C[i]]=i+1
	print(dp[-1])


if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
n = int(input())
c = [-1] + [int(input()) for i in range(n)]

count = [0]*(200005)
dp = [0]*(n+1)
dp[0] = 1
mod = 10**9+7
#dp[i]: i番目までの場合の数
for i in range(n):
    dp[i+1] = dp[i]
    if c[i+1] != c[i]:
        dp[i+1] += count[c[i+1]]
        dp[i+1] %= mod
    count[c[i+1]] += dp[i]
    count[c[i+1]] %= mod

print(dp[n]%mod)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = [-1] + [int(input()) for i in range(n)]

count = [0]*(200005)
dp = [0]*(n+1)
dp[0] = 1
mod = 10**9+7
#dp[i]: i番目までの場合の数
for i in range(n):
    dp[i+1] = dp[i]
    if c[i+1] != c[i]:
        dp[i+1] += count[c[i+1]]
        dp[i+1] %= mod
    count[c[i+1]] += dp[i]
    count[c[i+1]] %= mod

print(dp[n])

Submission status: Wrong Answer

Solution code:
mod = 10 ** 9 + 7
n = int(input())
c = [int(input()) for _ in range(n)]
import copy
cc = copy.deepcopy(c)
color_sum = {i: 0 for i in range(10 ** 6)}
dp = [1 for _ in range(n)]
color_sum[cc[0]] = 1
for i in range(1, n):
    dp[i] = dp[i - 1]
    if cc[i - 1] == cc[i]:
        continue
    dp[i] += color_sum[cc[i]]
    dp[i] %= mod
    color_sum[c[i]] += dp[i]
    color_sum[c[i]] %= mod
print(dp[n - 1])

Submission status: Wrong Answer

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

color_sum = {i: 0 for i in range(10 ** 6)}
dp = [1 for _ in range(n+1)]
dp[0] = 1
dp[1] = 1
color_sum[c[0]] = 1

for i in range(2, n+1):
    dp[i] = dp[i-1]

    if c[i-2] == c[i-1]:
        continue

    dp[i] += color_sum[c[i-1]]

    color_sum[c[i-1]] += dp[i-1]


print(dp[n])

Submission status: Wrong Answer

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

color_sum = {i: 0 for i in range(10 ** 6)}
dp = [0 for _ in range(n)]
dp[0] = 1
color_sum[c[0]] += dp[0]
for i in range(1, n):
    dp[i] = dp[i-1]

    if c[i-1] == c[i]:
        continue

    dp[i] += color_sum[c[i]]

    color_sum[c[i]] = dp[i]

print(dp[n-1])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N=int(input())
C=[]
MAX=-1
for i in range(N):
    c=int1(input())
    MAX=max(MAX,c)
    if not C or (C and C[-1]!=c):
        C.append(c)
M=len(C)
dp=[0]*(M+1)
dp[0]=1
last=[-1]*(MAX+1)
for i in range(M):
    if last[C[i]]!=-1:
        dp[i+1]+=dp[i]+dp[last[C[i]]]
    else:
        dp[i+1]=dp[i]
    dp[i+1]%MOD
    last[C[i]]=i+1
print(dp[-1])

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


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


def main():
    N = int(input())
    C = [int(input()) for _ in range(N)] + [None]
    C = [C[i] for i in range(N) if C[i] != C[i + 1]]

    N = len(C)
    # dp[i] := i個までの色の塗り方の総和
    dp = [0] * N
    dp[0] = 1
    used = [-1] * (max(C) + 1)
    used[C[0]] = 0

    for i in range(1, N):
        if used[C[i]] == -1:
            dp[i] = dp[i-1]
        else:
            dp[i] = dp[i-1] + dp[used[C[i]]]

        dp[i - 1] %= MOD
        used[C[i]] = i

    print(dp[-1])


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


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


def main():
    N = int(input())
    C = [int(input()) for _ in range(N)] + [None]
    C = [C[i] for i in range(N) if C[i] != C[i + 1]]

    N = len(C)
    # dp[i] := i個までの色の塗り方の総和
    dp = [0] * (N + 1)
    dp[0] = 1
    used = [-1] * (max(C) + 1)

    for i in range(N):
        if used[C[i]] == -1:
            dp[i + 1] = dp[i]
        else:
            dp[i + 1] = dp[i] + dp[used[C[i]]]

        dp[i + 1] %= MOD
        used[C[i]] = i

    print(dp[-1])


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    N = NI()
    CMAX = 2*10**5
    A = [0 for _ in range(CMAX+1)]
    S = [1 for _ in range(CMAX+1)]
    C = [NI() for _ in range(N)]
    P = 1
    A[C[0]] = 1
    for i in range(1,N):
        if C[i] != C[i-1] and A[C[i]] > 0:
            S[C[i]] = S[C[i]] + P
        else:
            S[C[i]] = P
        A[C[i]] = 1
        P = S[C[i]]
    print(P)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
c=[int(input()) for _ in range(n)]
color_sum=[0]*200001
color_place=[[]for _ in range(200001)]
for i,ci in enumerate(c):
  color_place[ci].append(i)

dp=[0]*(n+1)
dp[0]=1
dp[1]=1
color_sum[c[0]]+=1
# i個目まで考えたときの解。求めるのはdp[n]
# dp[i]:i個目より前で、i個目と同じ色の石があるところをjとして、dp[j-1]の和+dp[i-1]
for i in range(1,n): #二個目からn-1個目の計算をする。
  dp[i+1]=dp[i]
  if c[i]==c[i-1]:
    continue
  dp[i+1]+=color_sum[c[i]]
  color_sum[c[i]]=dp[i+1]
print(dp[n])

Submission status: Wrong Answer

Solution code:
n=int(input())
c=[int(input()) for _ in range(n)]
color_place=[[]for _ in range(200001)]
for i,ci in enumerate(c):
  color_place[ci].append(i)
dp=[0]*(n+1)
dp[0]=1
dp[1]=1
# i個目まで考えたときの解。求めるのはdp[n]
# dp[i]:i個目より前で、i個目と同じ色の石があるところをjとして、dp[j-1]の和+dp[i-1]
for i in range(1,n):
  dp[i+1]=dp[i]
  if c[i]==c[i-1]:
    continue
  idxs=[j for j in color_place[c[i]] if j<i]
  for j in idxs:
    dp[i+1]+=dp[j]
print(dp[n])

Submission status: Wrong Answer

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

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

N = len(newC)
L = [0]*(N+1)
L[0] = 1
idx = [-1]*(max(newC)+1)
for i in range(N):
    if idx[newC[i]] >= 0:
        L[i+1] += L[idx[newC[i]]]
        
    L[i+1] += L[i]
    idx[newC[i]] = i+1

print(L[-1])

Submission status: Wrong Answer

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

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

N = len(newC)
L = [0]*N
L[0] = 1
idx = [-1]*(max(newC)+1)
for i in range(N):
    if idx[newC[i]] >= 0:
        L[i] += L[idx[newC[i]]]
        
    L[i] += L[i-1]
    idx[newC[i]] = i

print(L[-1])

Submission status: Wrong Answer

Solution code:
n = int(input())

cl = []

for i in range(n):
    cl.append(int(input()))


ans = [1 for i in range(n)]

mod = 1**9+7

stones = dict()

stones[cl[-1]] = n-1

for i in range(n-1):
    cur = cl[n-i-2]

    if cur in stones and stones[cur] != n-i-1:
        ans[n-i-2] = ans[n-i-1] + ans[stones[cur]]
        ans[n-i-2] %= mod
    else:
        ans[n-i-2] = ans[n-i-1] % mod
    stones[cur] = n-i-2

print(ans[0])

Submission status: Wrong Answer

Solution code:
n = int(input())
c = [int(input()) for _i in range(n)]
c.append(-1)
dic = {}
dp = [0 for _i in range(n+1)]
dp[n] = 1
mod = 10**9 +7
for i in range(n):
    if c[i-1] != c[i]:
        if c[i] in dic:
            dp[i] = (dp[i-1] + dic[c[i]])%mod
        else:
            dp[i] = dp[i-1]
        dic[c[i]] = dp[i-1]
    else:
        dp[i] = dp[i-1]
    
print(dp[n-1])