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:
n=int(input())

latest_dic = {}
array   = []
answers = []

for i in range(n):
    c = int(input())
    array.append(c)

for i,c in enumerate(array):
    if i==0:
        answers.append(1)
        latest_dic[c] = 1
    else:
        cnt = answers[i-1]
        if (c in latest_dic) and (c!=array[i-1]):
            cnt += latest_dic[c]
            answers.append(cnt)
        else:
            answers.append(cnt)
        latest_dic[c]=cnt

print(answers[n-1])

Submission status: Wrong Answer

Solution code:
n=int(input());d=[0]*200001;a=1;b=-1
for i in range(n):
    c=int(input())
    if b!=c:
        a+=d[c]
        d[c]=a
    b=c
print(a%(10**9+9))

Submission status: Wrong Answer

Solution code:
N = int(input())
L = [input() for i in range(N)]

dp = [1 for i in range(N)]

last = {}

for i in range(N) :
    if i == 0 :
        last[L[i]] = i
    else :
        if L[i] not in last :
            dp[i] = dp[i-1]
        elif L[i] == L[i-1] :
            dp[i] = dp[i-1]
        else :
            j = last[L[i]]
            dp[i] = dp[i-1] + dp[j]
        
        last[L[i]] = i

ans = dp[N-1]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
c = [0]
d = defaultdict(list)
r = defaultdict(list)

idx = 1
for i in range(n):
    tmp = int(input())
    if c[-1] != tmp:
        r[idx] += d[tmp]
        d[tmp].append(idx)
        c.append(tmp)
        idx += 1

n = len(c)
dp = [0]*(n)
dp[0] = 1
for i in range(1, n):
    dp[i] = dp[i-1]
    for j in r[i]:
        dp[i] += dp[j-1]
print(dp[-1])

Submission status: Wrong Answer

Solution code:
import collections
from fractions import Fraction

N=int(input())
before=0
Reversi=[]
answer=1
mod=10**9+7

for _ in range(N):
  C=int(input())
  if before!=C:
    Reversi.append(C)
  before=C

c=dict(collections.Counter(Reversi))
print(c)

def comb(n, k):
    
    if n < 0 or k < 0:
        pdt = 0
    
    else:
        pdt = 1
        for s in range(1, k + 1):
            pdt *= Fraction(n - s + 1, s)
    
    # 戻り値をint型にするために分子を取り出す
    return pdt.numerator
for a in c.values():
  answer+=comb(a,2)
  answer%=mod
print(answer)

Submission status: Wrong Answer

Solution code:
import sys


def tran(A):
    temp = []
    for i in range(len(A)):
        if i == 0:
            temp += [A[i]]
        elif A[i] != A[i - 1]:
            temp += [A[i]]
    return temp


def find(A):
    # assume consecutive elements
    dp = [1] * len(A) + [1]

    current_dic = {}

    MOD = 10**9 + 7

    for i in range(len(A)):

        if i == 0:
            current_dic[A[i]] = [i]
        else:
            temp = dp[i - 1]
            if A[i] in current_dic:
                for x in current_dic[A[i]]:
                    temp += dp[x - 1]
                    temp %= MOD
                current_dic[A[i]] += [i]
            else:
                current_dic[A[i]] = [i]

            dp[i] = temp
    print(dp)
    return dp[-2] % MOD




N=int(input())
A=[]
for i in range(N):
    A+=[int(input())]

print(find(tran(A)))

Submission status: Wrong Answer

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

i=0
while i+1<len(C):
    if C[i]==C[i+1]:
        C.pop(i+1)
    else:
        i+=1

DP = [1]
dic = {}

for i in range(len(C)):
    DP.append((DP[-1] + dic.get(C[i],0))%(10**9*7))
    dic[C[i]] = DP[-1]
print(DP[-1])

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
c2 = [int(input()) for _ in range(N)]
mod = 10**9+7
#圧縮
c = [c2[0]-1]
n = N
for i in range(1,N):
    if c2[i] == c2[i-1]:
        n -= 1
        continue
    c.append(c2[i]-1)

#used[i]:色iが最後に登場したindex
#初期値:-1
used = [-1]*(max(c)+1)
used[c[0]] = 0
#dp[i]:i番目まででの場合の数
dp = [0]*n
dp[0] = 1
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]]]
    used[c[i]] = i

print(dp[-1])

Submission status: Wrong Answer

Solution code:
N = int(input())
C = [int(input()) for _ in range(N)]
   
i=0 
while i+1<len(C):
    if C[i]==C[i+1]:
        C.pop(i+1)
    else:
        i+=1
        
DP = [1]
CDP = [0]*(2*(10**5)+5) 
for i in range(len(C)):  
    DP.append(DP[-1]+CDP[C[i]])
    CDP[C[i]] = DP[-1]
print(DP[-1])

Submission status: Wrong Answer

Solution code:
from collections import deque
N = int(input())
C = [int(input()) for i in range(N)]
dq = deque()
dq.append(C[0])
for c in C:
    if c != dq[-1]:
        dq.append(c)
C = list(dq)
N = len(C)
dp = [0]*(N+1)
dp[0] = 1
acc = [0]*(2*pow(10,5)+1)
for i in range(1,N+1):
    dp[i] = dp[i-1]
    dp[i] += acc[C[i-1]]
    acc[C[i-1]] += dp[i-1]
ans = dp[N]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
C = [int(input()) for _ in range(N)]
p = 10**9+7
dp = [[1, 0] for _ in range(N)]
prev = [-1 for i in range(max(C)+1)]
prev[C[0]] = 0
for i in range(1, N):
    if prev[C[i]] == -1:
        dp[i][0] = dp[i-1][0]
    elif prev[C[i]] == i-1:
        dp[i][0] = dp[i-1][0]
        dp[i][1] = dp[i-1][1]
    else:
        idx = prev[C[i]]
        dp[i][1] = dp[idx][0] + max(dp[idx][1]-1, 0)
        dp[i][0] = (dp[i-1][0] + dp[i][1])%p
    prev[C[i]] = i
print(dp[-1][0])

Submission status: Wrong Answer

Solution code:
# coding:utf-8

import sys
from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n = II()
    C = [II() for _ in range(n)]

    dp = [0] * (n + 1)
    dp[0] = 1
    color_index = defaultdict(int)
    for i, c in enumerate(C):
        if not color_index[c]:
            color_index[c] = i + 1
            dp[i + 1] = dp[i]
        else:
            if color_index[c] == i:
                dp[i + 1] = dp[i]
            else:
                dp[i + 1] = dp[i] + dp[color_index[c]]
            color_index[c] = i + 1

    return dp[-1]


print(main())

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

N = int(input())
c = [int(input()) for _ in range(N)]

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

d = defaultdict(lambda: -1)

for i, cc in enumerate(c, 1):
    if c[i - 1] == c[i - 2]:
        dp[i] = dp[i - 1]
    elif d[cc] == -1:
        # 初めて出現した色
        dp[i] = dp[i - 1]
    else:
        dp[i] = dp[i - 1] + dp[d[cc]]
    d[cc] = i
    # print(d)
    # print(dp)
print(dp[N])

Submission status: Wrong Answer

Solution code:
pre = -1
N = int(input())
C = []
X = [[] for _ in range(2*10**5+10)]
i = 0
for _ in range(N):
    a = int(input())
    if a != pre:
        C.append(a)
        X[a].append(i)
        i += 1
    pre = a

N = len(C)
dp = [1] + [0] * N
P = 10**9+7

for i in range(1, N+1):
    dp[i] = dp[i-1]
    for j in X[C[i-1]]:
        if j >= i - 1:
            break
        print(i, j, X[C[i-1]])
        dp[i] += dp[j]
        dp[i] %= P
print(dp[N])

Submission status: Wrong Answer

Solution code:
pre = -1
N = int(input())
C = []
X = [[] for _ in range(2*10**5+10)]
i = 0
for _ in range(N):
    a = int(input())
    if a != pre:
        C.append(a)
        X[a].append(i)
        i += 1
    pre = a

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

for i in range(1, N+1):
    dp[i] = dp[i-1]
    for j in X[C[i-1]]:
        if j >= i - 1:
            break
        dp[i] += dp[j]
print(dp[N])

Submission status: Wrong Answer

Solution code:
N = int(input())
C = [0 for i in range(N)]
p = 10**9 + 7
if N <= 2:
    print(1)
else:
    prevprev = int(input())
    prev = int(input())
    C[0] = prevprev
    C[1] = prev
    part = []
    dp = [[1, 0] for i in range(N)]
    if prevprev == prev:
        dp[1][1] = 1
    for i in range(2, N):
        current = int(input())
        C[i] = current
        part.insert(0, prevprev)
        dp[i][0] = dp[i-1][0]
        if current == prev:
            dp[i][1] = dp[i-1][1]
        elif current in part:
            idx = i - 2 - part.index(current)
            dp[i][1] = sum(dp[idx])
            dp[i][0] += dp[i][1]
            dp[i][0] = dp[i][0]%p
        prev, prevprev = current, prev
    print(dp[N-1][0])

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N = int(input())
C = [int(input()) for _ in range(N)]
dic = defaultdict(list)
for i in range(N):
    dic[C[i]].append(i)
es = [[] for _ in range(N)]
for i in range(N - 1):
    es[i].append(i + 1)
for key in dic:
    if len(dic[key]) == 1:
        continue
    i, L, v1, v2 = 1, len(dic[key]) - 1, dic[key][0], dic[key][1]
    while True:
        if v1 + 1 != v2:
            es[v1].append(v2)
        v1 = v2
        if i < L:
            i += 1
            v2 = dic[key][i]
        else:
            break
dp = [0 for _ in range(N)]
dp[0] = 1
for i in range(N - 1):
    for j in es[i]:
        dp[j] += dp[i]
print(dp[N - 1])

Submission status: Wrong Answer

Solution code:
N = int(input())

maxpos_of_color = {}
num_of_color = {}
count_before = {}
sum_countbefore = {-1:0, 0:0}
precol = 0
mod = 10**9+7

for i in range(N):
    c = int(input())
    if not c in num_of_color:
        num_of_color[c] = 0
    if precol != c:
        if num_of_color[c] > 0:
            count_before[i] = num_of_color[c]
            count_before[i] += sum_countbefore[maxpos_of_color[c]-1]
        num_of_color[c] += 1
        maxpos_of_color[c] = i
    if i > 0:
        if not i in count_before:
            sum_countbefore[i] = sum_countbefore[i-1]
        else:
            sum_countbefore[i] = sum_countbefore[i-1] + count_before[i]
        sum_countbefore[i]%=mod
    precol = c

print((sum_countbefore[N-1]+1)%mod)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

N = int(input())
C = []


for _ in range(N):
    tmp = int(input())
    C.append(tmp)

dp = [0]*(len(C)+1)
place = {}
dp[0] = 1

for i in range(len(C)):
    if place.get(C[i]) != None:
        dp[i+1] = dp[i] + dp[place.get(C[i])]
    else:
        dp[i+1] = dp[i]
    place[C[i]] = i+1
    
print(dp[-1]%(10**9+7))

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
C = []
pre = 0
for _ in range(N):
    c = int(sys.stdin.readline())
    if pre == c:
        continue
    else:
        C.append(c)
        pre = c

ans = 1
dic = {}
for c in C:
    if c in dic.keys():
        a = dic[c]
        dic[c] += ans
        ans += a
    else:
        dic[c] = ans

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = []
s = {}
pair = []
for i in range(n):
  ci = int(input())
  if ci in s:
    j = s[ci]
    if j != len(c) - 1:
      pair.append([j, len(c)])
  c.append(ci)
  s[ci] = len(c) - 1
ans = 1
l = len(pair)
dp = [0] * l
for i in range(l)[::-1]:
  end = pair[i][1]
  for j in range(i, l):
    if end <= pair[j][0]:
      dp[i] = 1 + dp[j]
      break
  else:
    dp[i] = 1
print((sum(dp)+1)%(10**9+7))

Submission status: Wrong Answer

Solution code:
N = int(input())
C = []
mod = 10**9+7
for i in range(N):
	C.append(int(input()))
D = [C[0]]
for i in range(1,N):
	if C[i] != C[i-1]:
		D.append(C[i])
num = [0] * (max(D)+1)
for i in range(len(D)):
	num[D[i]] += 1
ans = 0
# print(num)
for i in range(1,len(num)):
	if num[i] >= 2:
		ans += 2**(num[i]-1)
if ans == 0:
	print(1)
elif ans == 2:
  	print(2)
else:
	print((ans-1)%mod)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = []
s = {}
pair = []
for i in range(n):
  ci = int(input())
  if ci in s:
    j = s[ci]
    if j != len(c) - 1:
      pair.append([j, len(c)])
  c.append(ci)
  s[ci] = len(c) - 1
ans = 1
l = len(pair)
dp = [0] * l
for i in range(l)[::-1]:
  end = pair[i][1]
  for j in range(i, l):
    if end <= pair[j][0]:
      dp[i] = 1 + dp[j]
      break
  else:
    dp[i] = 1
print(sum(dp)+1)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = []
s = {}
pair = []
for i in range(n):
  ci = int(input())
  if ci in s:
    j = s[ci]
    if j != len(c) - 1:
      pair.append([j, len(c)])
  c.append(ci)
  s[ci] = len(c)
ans = 1
l = len(pair)
dp = [0] * l
for i in range(l)[::-1]:
  end = pair[i][1]
  for j in range(i, l):
    if end < pair[j][0]:
      dp[i] = 1 + dp[j]
      break
  else:
    dp[i] = 1
print(sum(dp)+1)

Submission status: Wrong Answer

Solution code:
m = 10 ** 9 + 7
d = {}
r = 1
p = 0
for _ in range(int(input())):
  c = int(input())
  if c != p:
    r = (r + d[c]) % m if c in d else r
    d[c] = r
    p = c
#print(r)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

N = int(input())
C = []

prev = -1

for _ in range(N):
    tmp = int(input())
    if tmp != prev:
        C.append(tmp)
    prev = tmp

dp = [0]*(len(C)+1)
place = {}
dp[0] = 1

for i in range(len(C)):
    if place.get(C[i]) != None:
        dp[i+1] = dp[i] + dp[place.get(C[i])]
    else:
        dp[i+1] = dp[i]
    place[C[i]] = i+1
    print(dp)
    
print(dp[-1]%(10**9+7))

Submission status: Wrong Answer

Solution code:
m = 10 ** 9 + 7
d = {}
r = 1
p = 0
for _ in range(int(input())):
  c = int(input())
  if c == p:
    continue
  if c in d:
    r += d[c]
  r %= m
  d[c] = r
  p = c
#print(r)

Submission status: Wrong Answer

Solution code:
N = int(input())

maxpos_of_color = {}
num_of_color = {}
count_before = {}
sum_countbefore = {-1:0, 0:0}
precol = 0
mod = 10**9+7

for i in range(N):
    c = int(input())
    if not c in num_of_color:
        num_of_color[c] = 0
    if precol != c:
        if num_of_color[c] > 0:
            count_before[i] = num_of_color[c]
            count_before[i] += sum_countbefore[maxpos_of_color[c]-1]
        num_of_color[c] += 1
    if i > 0:
        if not i in count_before:
            sum_countbefore[i] = sum_countbefore[i-1]
        else:
            sum_countbefore[i] = sum_countbefore[i-1] + count_before[i]
        sum_countbefore[i]%=mod
    maxpos_of_color[c] = i
    precol = c

print((sum_countbefore[N-1]+1)%mod)

Submission status: Wrong Answer

Solution code:
mod=7+10**9
n=int(input())
c=[int(input()) for _ in [0]*n]
data=[0]*n+[1]
def dp(k,l):
    if data[k]>0:
        return data[k]
    if k>=n-1:
        return 1
    ans=0
    i=0
    while i<len(l):
        if l[i]==l[0]:
            j=i
            while j<len(l) and l[j]==l[0]:
                j+=1
            ans+=dp(j,l[j:])
            ans%=mod
            i=j
        i+=1
    data[k]=ans%mod
    return data[k]
print(dp(0,c))

Submission status: Wrong Answer

Solution code:
N = int(input())

maxpos_of_color = {}
num_of_color = {}
count_before = {}
sum_countbefore = {-1:0, 0:0}
precol = 0
mod = 10**9+7

for i in range(N):
    c = int(input())
    if not c in num_of_color:
        num_of_color[c] = 0
    if precol != c:
        if num_of_color[c] > 0:
            count_before[i] = num_of_color[c]
            count_before[i] += sum_countbefore[maxpos_of_color[c]-1]
        num_of_color[c] += 1
    if i > 0:
        if not i in count_before:
            sum_countbefore[i] = sum_countbefore[i-1]
        else:
            sum_countbefore[i] = sum_countbefore[i-1] + count_before[i]
    maxpos_of_color[c] = i
    precol = c

print((sum(count_before.values())+1)%mod)

Submission status: Wrong Answer

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

C2 = []
re = ""
L = {}
LL = [-1] * N
for i in C:
  if i != re:
    if i in L:
      LL[L[i]] = len(C2)
      L[i] = len(C2)
    else:
      L[i] = len(C2)
    C2.append(i)
  re = i

DP = [-1] * (len(C2) + 1)

DP[-1] = 1
for i in range(len(C2) - 1, -1, -1):
  DP[i] = DP[i + 1]
  if LL[i] != -1:
    DP[i] += DP[LL[i]]

print(DP[0])

Submission status: Wrong Answer

Solution code:
N = int(input())

maxpos_of_color = {}
num_of_color = {}
count_before = {}
sum_countbefore = {-1:0, 0:0}
precol = 0

for i in range(N):
    c = int(input())
    if not c in num_of_color:
        num_of_color[c] = 0
    if precol != c:
        if num_of_color[c] > 0:
            count_before[i] = num_of_color[c]
            count_before[i] += sum_countbefore[maxpos_of_color[c]-1]
        num_of_color[c] += 1
    if i > 0:
        if not i in count_before:
            sum_countbefore[i] = sum_countbefore[i-1]
        else:
            sum_countbefore[i] = sum_countbefore[i-1] + count_before[i]
    maxpos_of_color[c] = i
    precol = c

print(sum(count_before.values())+1)

Submission status: Wrong Answer

Solution code:
N = int(input())

maxpos_of_color = {}
num_of_color = {}
count_before = {}
sum_countbefore = {0:0}
precol = 0

for i in range(N):
    c = int(input())
    if not c in num_of_color:
        num_of_color[c] = 0
    if precol != c:
        if num_of_color[c] > 0:
            count_before[i] = num_of_color[c]
            count_before[i] += sum_countbefore[maxpos_of_color[c]]
        num_of_color[c] += 1
    if i > 0:
        if not i in count_before:
            sum_countbefore[i] = sum_countbefore[i-1]
        else:
            sum_countbefore[i] = sum_countbefore[i-1] + count_before[i]
    maxpos_of_color[c] = i
    precol = c

print(sum(count_before.values())+1)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

N = int(input())
numberlist = [[] for i in range(200011)]
number = []
for i in range(N):
    a = int(input())
    if i > 0:
        if number[len(number)-1] == a:
            continue
        else:
            number.append(a)
            numberlist[a].append(i)
    else:
        number.append(a)
        numberlist[a].append(i)
periodlist = []
for i in range(N+1):
    for j in range(max(0, len(numberlist[i]) - 1)):
        if j == 0:
            periodlist.append([numberlist[i][j], numberlist[i][j+1]])
        else:
            periodlist.append([numberlist[i][j]+1, numberlist[i][j+1]])
periodlist.sort(key=itemgetter(1))
calculate = 0
dp = [0 for i in range(200011)]
dp[0] = 1
dp[-1] = 1
for i in range(len(periodlist)):
    for j in range(calculate, periodlist[i][1]):
        dp[j+1] = dp[j]
    dp[periodlist[i][1]] += dp[periodlist[i][0]-1]
    dp[periodlist[i][1]] %= 1000000007
    calculate = periodlist[i][1]

print(dp[calculate]%1000000007)

Submission status: Wrong Answer

Solution code:
import copy

N = int(input())
C = [input() for i in range(N)]

C2 = []
re = ""
L = {}
for i in C:
  if i != re:
    if i in L:
      L[i].append(len(C2))
    else:
      L[i] = [len(C2)]
    C2.append(i)
  re = i
LL = [-1] * len(C2)
for i in L:
  k = L[i][0]
  for j in L[i][1:]:
    LL[k] = j
    k = j
DP = [-1] * (len(C2) + 1)

DP[-1] = 1
for i in range(len(C2) - 1, -1, -1):
  DP[i] = DP[i + 1]
  if LL[i] != -1:
    DP[i] += DP[LL[i]]

print(DP[0])

Submission status: Wrong Answer

Solution code:
m=10**9+7
r=range(int(input()))
A=[int(input()) for i in r]
S=[0 for i in r]
E=[0 for i in r]
sb=set()
sf=set()
for i in r:
  ab=A[-(i+1)]
  if ab in sb and ab !=anb:
    S[-(i+1)]=1
  sb |= {ab}
  anb=ab

  af=A[i]
  if af in sf and af !=anf:
    E[i]=1
  sf |= {af}
  anf=af
er=0
c=1
for i in r:
  if E[i]:
    c += 1
    er+=1
  if S[i] and c !=1:
    c *= 2 
    c -= er 
print(c%m)

Submission status: Wrong Answer

Solution code:
m=10**9+7
r=range(int(input()))
A=[int(input()) for i in r]
S=[0 for i in r]
E=[0 for i in r]
C=[1 for i in r]
s=set()
for i in range(1,len(A)+1):
  a=A[-i]
  if a in s and a !=an:
    S[-i]=1
  s |= {a}
  an=a
s=set()

for i in r:
  a=A[i]
  if a in s and a !=an:
    E[i]=1
  s |= {a}
  an=a
er=0
c=1
for i in r:
  s=S[i]
  e=E[i]
  if e:
    c += 1
  if s and c !=1:
    c *= 2 
    c -= 1
    
print(c%m)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

N = int(input())
C = []

prev = -1

for _ in range(N):
    tmp = int(input())
    if tmp != prev:
        C.append(tmp)
    prev = tmp

dp = [0]*(len(C)+1)
place = {}
dp[0] = 1

for i in range(len(C)):
    if place.get(C[i]) != None:
        dp[i+1] = dp[i] + dp[place.get(C[i])]
    else:
        dp[i+1] = dp[i]
    place[C[i]] = i+1
    
print(dp[-1])

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

def main():
    N = II()
    C = []
    for _ in range(N):
        c = II()
        if len(C) == 0 or c != C[-1]:
            C.append(c)
    global ans
    ans = 0
    dp = [1] + [0] * N
    from collections import defaultdict
    idxs = defaultdict(list)
    for i, c in enumerate(C):
        ret = dp[i]
        if c in idxs.keys():
            for j in idxs[c]:
                ret += dp[j]
        dp[i + 1] = ret % MOD
        idxs[c].append(i)

    ans = dp[N]

    return ans % MOD

print(main())

Submission status: Wrong Answer

Solution code:
r=range(int(input()))
A=[int(input()) for i in r]
S=[0 for i in r]
E=[0 for i in r]
sb=set()
sf=set()
for i in r:
  ab=A[-(i+1)]
  if ab in sb and ab !=anb:
    S[-(i+1)]=1
  sb |= {ab}
  anb=ab

  af=A[i]
  if af in sf and af !=anf:
    E[i]=1
  sf |= {af}
  anf=af
er=0
ans=0
c=1
for i in r:
  if E[i]:
    c += 1
    er+=1
    c *= 2 
  if S[i]:
    
    ans += c - 1
  
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
listC=list()
for n in range(N):
  listC.append(int(input()))

def reversi(li, ss, count):
  for n in range(ss, N-1):
    print(n)
    print(count)
    print(li)
    for i in range(n+1, N):
      if li[i] == li[n]:
        if i-n <= 1:
          break;
        else:
          newList = li
          count += 1
          count += reversi(li, n+1, 0)
          for s in range(n+1, i):
            newList[s] = li[i]
          count += reversi(newList, i, 0)
          break
    
  return count

print(reversi(listC, 0, 1))

Submission status: Wrong Answer

Solution code:
N = int(input())
C = []
tmp_b = -1
for _ in range(N):
  tmp_n = int(input())
  if tmp_n != tmp_b:
    C.append(tmp_n)
    tmp_b = tmp_n

N = 0

for idx in range(len(C)):
  list_ = C[idx:]
  while len(list_) > 1:
    ini = list_[0]
    if ini in list_[1:]:
      list_ = list_[1:]
      list_ = list_[list_.index(ini)+1:]
      N += 1
    else:
      list_ = list_[1:]

print(N+1 % (10**9+7))

Submission status: Wrong Answer

Solution code:
N = int(input())
C = []
i = 1
places = {}
for _ in range(N):
    c = int(input())
    if C != [] and c != C[-1]:
        C.append(c)
        if c not in places:
            places[c] = [i]
        else:
            places[c].append(i)
        i += 1
    if C == []:
        C.append(c)
        places[c] = [i]
        i += 1
dp = [1]
# print(C)
# print(places)
for i in range(1, len(C)+1):
    c = C[i-1]
    next_dp = dp[i-1]
    if len(places[c]) >= 2:
        for pos in places[c]:
            if pos >= i:
                break
            next_dp += dp[pos-1]
    dp.append(next_dp)
# print(dp)
print(dp[len(C)])

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
p=10**9 +7
n=int(input())
c=[int(i) for i in sys.stdin]
dic = dict()
for i in c:
    if i in dic:
        if dic[i]:
            dic[i] = False
    else:
        dic[i] = True
newline=[]
stack=0
for i in range(n):
  k=c.pop()
  if dic[k]:
    stack=k
    continue
  else:
    if stack!=k:
      newline.append(k)
    stack=k
result=sum([i-1 for i in Counter(newline).values()])%p
print((2*result-1)%p)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

N = int(input())
numberlist = [[] for i in range(200011)]
number = []
for i in range(N):
    a = int(input())
    if i > 0:
        if number[len(number)-1] == a:
            continue
        else:
            number.append(a)
            numberlist[a].append(i)
    else:
        number.append(a)
        numberlist[a].append(i)
periodlist = []
for i in range(N+1):
    for j in range(max(0, len(numberlist[i]) - 1)):
        if j == 0:
            periodlist.append([numberlist[i][j], numberlist[i][j+1]])
        else:
            periodlist.append([numberlist[i][j]+1, numberlist[i][j+1]])
periodlist.sort(key=itemgetter(1))
calculate = 0
dp = [0 for i in range(200012)]
dp[0] = 1
dp[-1] = 1
for i in range(len(periodlist)):
    for j in range(calculate, periodlist[i][1]):
        dp[j+1] = dp[j]
    dp[periodlist[i][1]] += dp[periodlist[i][0]-1]
    calculate = periodlist[i][1]
print(max(dp)%1000000007)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

N = int(input())
numberlist = [[] for i in range(200011)]
number = []
for i in range(N):
    a = int(input())
    if i > 0:
        if number[len(number)-1] == a:
            continue
        else:
            number.append(a)
            numberlist[a].append(i)
    else:
        number.append(a)
        numberlist[a].append(i)
periodlist = []
for i in range(N+1):
    for j in range(max(0, len(numberlist[i]) - 1)):
        if j == 0:
            periodlist.append([numberlist[i][j], numberlist[i][j+1]])
        else:
            periodlist.append([numberlist[i][j]+1, numberlist[i][j+1]])
periodlist.sort(key=itemgetter(1))
calculate = 0
dp = [0 for i in range(200012)]
dp[0] = 1
dp[-1] = 1
for i in range(len(periodlist)):
    for j in range(calculate, periodlist[i][1]):
        dp[j+1] = dp[j]
    dp[periodlist[i][1]] += dp[periodlist[i][0]-1]
    dp[periodlist[i][1]] %= 1000000007
    calculate = periodlist[i][1]
print(max(dp)%1000000007)

Submission status: Wrong Answer

Solution code:
import copy

N = int(input())
C = [input() for i in range(N)]

C2 = []
re = ""
L = {}
for i in C:
  if i != re:
    if i in L:
      L[i].insert(0, len(C2))
    else:
      L[i] = []
    C2.append(i)
  re = i

LL = [-1] * len(C2)
for i in range(len(C2)):
  if L[C2[i]] != []:
    LL[i] = copy.deepcopy(L[C2[i]])
    L[C2[i]].pop()

DP = [-1] * (len(C2) + 1)

DP[-1] = 1
for i in range(len(C2) - 1, -1, -1):
  DP[i] = DP[i + 1]
  if LL[i] != -1:
    for j in LL[i]:
      DP[i] += DP[j + 1]

print(DP[0])

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

N = int(input())
numberlist = [[] for i in range(200001)]
number = []
for i in range(N):
    a = int(input())
    if i > 0:
        if number[len(number)-1] == a:
            continue
        else:
            number.append(a)
            numberlist[a].append(i)
    else:
        number.append(a)
        numberlist[a].append(i)
periodlist = []
for i in range(N+1):
    for j in range(max(0, len(numberlist[i]) - 1)):
        if j == 0:
            periodlist.append([numberlist[i][j], numberlist[i][j+1]])
        else:
            periodlist.append([numberlist[i][j]+1, numberlist[i][j+1]])
periodlist.sort(key=itemgetter(1))
calculate = 0
dp = [0 for i in range(200002)]
dp[0] = 1
dp[-1] = 1
for i in range(len(periodlist)):
    for j in range(calculate, periodlist[i][1]):
        dp[j+1] = dp[j]
    dp[periodlist[i][1]] += dp[periodlist[i][0]-1]
    dp[periodlist[i][1]] %= 100000007
    calculate = periodlist[i][1]
print(max(dp)%100000007)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
p=10**9 +7
n=int(input())
c=[int(i) for i in sys.stdin]
dic = dict()
for i in c:
    if i in dic:
        if dic[i]:
            dic[i] = False
    else:
        dic[i] = True
newline=[]
stack=0
for i in range(n):
  k=c.pop()
  if dic[k]:
    stack=k
    continue
  else:
    if stack!=k:
      newline.append(k)
    stack=k
result=sum([i-1 for i in Counter(newline).values()])%p
print(((2*result)%p)-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
C = []
i = 1
places = {}
for _ in range(N):
    c = int(input())
    if C != [] and c != C[-1]:
        C.append(c)
        if c not in places:
            places[c] = [i]
        else:
            places[c].append(i)
        i += 1
dp = [1]
for i in range(1, len(C)+1):
    c = C[i]
    next_dp = dp[i-1]
    if len(places[c]) >= 2:
        for pos in places[c]:
            if pos >= i:
                break
            next_dp += dp[pos-1]
print(dp[len(C)])

Submission status: Wrong Answer

Solution code:
#B
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
n=int(input())
C=[int(input()) for _ in range(n)]
A=[0]*(2*10**5+1) #A[i]:色iが最後に使われた場所(1-indexed)
B=[1]
for i,c in enumerate(C):
    #print(A[c])
    tmp=B[-1]
    if A[c]!=i and A[c]!=0:
        tmp+=B[A[c]]
    A[c]=i+1
    B.append(tmp)
#print(B)
print(B[-1])

Submission status: Wrong Answer

Solution code:
from operator import itemgetter

N = int(input())
numberlist = [[] for i in range(200001)]
number = []
for i in range(N):
    a = int(input())
    if i > 0:
        if number[len(number)-1] == a:
            continue
        else:
            number.append(a)
            numberlist[a].append(i)
    else:
        number.append(a)
        numberlist[a].append(i)
periodlist = []
for i in range(N+1):
    for j in range(max(0, len(numberlist[i]) - 1)):
        if j == 0:
            periodlist.append([numberlist[i][j], numberlist[i][j+1]])
        else:
            periodlist.append([numberlist[i][j]+1, numberlist[i][j+1]])
periodlist.sort(key=itemgetter(1))
calculate = 0
dp = [0 for i in range(200002)]
dp[0] = 1
dp[-1] = 1
for i in range(len(periodlist)):
    for j in range(calculate, periodlist[i][1]):
        dp[j+1] = dp[j]
    dp[periodlist[i][1]] += dp[periodlist[i][0]-1]
    dp[periodlist[i][1]] %= 100000007
    calculate = periodlist[i][1]
print(max(dp))

Submission status: Wrong Answer

Solution code:
r=range(int(input()))
A=[int(input()) for i in r]
S=[0 for i in r]
E=[0 for i in r]
sb=set()
sf=set()
for i in r:
  ab=A[-(i+1)]
  if ab in sb and ab !=anb:
    S[-(i+1)]=1
  sb |= {ab}
  anb=ab

  af=A[i]
  if af in sf and af !=anf:
    E[i]=1
  sf |= {af}
  anf=af
er=0
c=1
for i in r:
  if E[i]:
    c += 1
    er+=1
  if S[i] and c !=1:
    c *= 2 
    c -= er 
print(c)

Submission status: Wrong Answer

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

from collections import defaultdict
dl = defaultdict(int)
dr = defaultdict(int)
cc = c

n = len(cc)
a = [[0, 0] for i in range(n)]
for i in range(0, n):
  if i!=0:
    a[i][0] = dl[cc[i]]
    a[n-i-2][1] = a[n-i-1][1] + dr[cc[n-i-1]]
  dl[cc[i]] += 1
  dr[cc[n-i-1]] += 1
a[n-1][1] = 0

ans = 1
for ele in a:
  if ele[0]>0:
    ans = (ans+ele[0]%MOD*(ele[1]%MOD+1))%MOD
print(ans)