TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: You are given an integer N. Find the number of strings of length N that satisfy the following conditions, modulo 10^9+7:    * The string does not contain characters other than `A`, `C`, `G` and `T`.   * The string does not contain `AGC` as a substring.   * The condition above cannot be violated by swapping two adjacent characters once.

Submission attempts (in order):

# import sys


# from collections import deque
from decorator import stop_watch


@stop_watch
def solve(N):
    mod = 10 ** 9 + 7
    dp = [{} for _ in range(N + 1)]
    dp[0].setdefault('TTT', 1)

    def check(last4):
        for i in range(4):
            x = list(last4)
            if i > 0:
                x[i], x[i - 1] = x[i - 1], x[i]
            if ''.join(x).count('AGC') >= 1:
                return False
        return True

    for i in range(1, N + 1):
        for last3, count in dp[i - 1].items():
            for c in 'AGCT':
                if check(last3 + c):
                    new_last3 = last3[1:] + c
                    dp[i].setdefault(last3[1:] + c, 0)
                    dp[i][new_last3] = (dp[i][new_last3] + count) % mod

    print(sum(dp[-1].values()) % mod)


if __name__ == '__main__':
    N = int(input())
    solve(N)

    # # test
    # from random import randint
    # from func import random_str
    # solve()



# import sys


# from collections import deque
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(N):
    mod = 10 ** 9 + 7
    dp = [{} for _ in range(N + 1)]
    dp[0].setdefault('TTT', 1)

    def check(last4):
        for i in range(4):
            x = list(last4)
            if i > 0:
                x[i], x[i - 1] = x[i - 1], x[i]
            if ''.join(x).count('AGC') >= 1:
                return False
        return True

    for i in range(1, N + 1):
        for last3, count in dp[i - 1].items():
            for c in 'AGCT':
                if check(last3 + c):
                    new_last3 = last3[1:] + c
                    dp[i].setdefault(last3[1:] + c, 0)
                    dp[i][new_last3] = (dp[i][new_last3] + count) % mod

    print(sum(dp[-1].values()) % mod)


if __name__ == '__main__':
    N = int(input())
    solve(N)

    # # test
    # from random import randint
    # from func import random_str
    # solve()


Verdicts: Runtime Error

Accepted
Problem: You are given an integer N. Find the number of strings of length N that satisfy the following conditions, modulo 10^9+7:    * The string does not contain characters other than `A`, `C`, `G` and `T`.   * The string does not contain `AGC` as a substring.   * The condition above cannot be violated by swapping two adjacent characters once.

Submission attempts (in order):
N = int(input())

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

# dp[i][j][k][l]




dp[0][3][3][3] = 1
MOD = 10**9 + 7

for i in range(N):
    for j in range(4):
        for k in range(4):
            for l in range(4):
                if dp[i][j][k][l] == 0: 
                    continue
                for add in range(4): 
                    
                    if add == 2 and j == 1 and k == 0:
                        continue
                    if add == 2 and j == 0 and k == 1:
                        continue
                    if add == 1 and j == 2 and k == 0:
                        continue
                    if add == 2 and j == 1 and l == 0:
                        continue
                    if add == 2 and k == 1 and l == 0:
                        continue
                    
                    
                    dp[i+1][add][j][k] += dp[i][j][k][l]
                    dp[i+1][add][j][k] %= MOD

ans = 0
for j in range(4):
    for k in range(4):
        for l in range(4):
            ans += dp[N][j][k][l]
            ans %= MOD

print(ans)

N = int(input())

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

# dp[i][j][k][l]




dp[0][3][3][3] = 1
MOD = 10**9 + 7

for i in range(N):
    for j in range(4):
        for k in range(4):
            for l in range(4):
                
                    #continue
                for add in range(4): 
                    
                    if add == 2 and j == 1 and k == 0:
                        continue
                    if add == 2 and j == 0 and k == 1:
                        continue
                    if add == 1 and j == 2 and k == 0:
                        continue
                    if add == 2 and j == 1 and l == 0:
                        continue
                    if add == 2 and k == 1 and l == 0:
                        continue
                    
                    
                    dp[i+1][add][j][k] += dp[i][j][k][l]
                    dp[i+1][add][j][k] %= MOD

ans = 0
for j in range(4):
    for k in range(4):
        for l in range(4):
            ans += dp[N][j][k][l]
            ans %= MOD

print(ans)

Verdicts: Wrong Answer

Accepted
Problem: You are given an integer N. Find the number of strings of length N that satisfy the following conditions, modulo 10^9+7:    * The string does not contain characters other than `A`, `C`, `G` and `T`.   * The string does not contain `AGC` as a substring.   * The condition above cannot be violated by swapping two adjacent characters once.

Submission attempts (in order):
n, mod = int(input()), 10 ** 9 + 7
memo = [{} for i in range(n+1)]
def check(l):
    for i in range(4):
        t = list(l)
        if i >= 1:
            t[i-1], t[i] = t[i], t[i-1] 
        if ''.join(t).count('AGC') >= 1:
            return False
    return True

def dfs(cur, last3):
    if last3 in memo[cur]:
        return memo[cur][last3]
    if cur == n:
        return 1
    ret = 0
    for c in 'ACGT':
        if check(last3 + c):
            ret = (ret + dfs(cur + 1, last3[1:] + c)) % mod
    memo[cur][last3] = ret
    print(memo)
    return ret

print(dfs(0, 'TTT'))




n, mod = int(input()), 10 ** 9 + 7
memo = [[[[0 for _ in range(4)] for _ in range(4)] for _ in range(4)] for _ in range(n + 1)]
memo[0][3][3][3] = 1
for length in range(n):
    for s3 in range(4):  
        for s2 in range(4):  
            for s1 in range(4):  
                # if memo[length][s3][s2][s1] == 0: continue
                
                for s4 in range(4):
                    
                    if s4 == 2 and s3 == 1 and s2 == 0: continue
                    if s4 == 2 and s3 == 0 and s2 == 1: continue
                    if s4 == 1 and s3 == 2 and s2 == 0: continue
                    if s4 == 2 and s3 == 1 and s1 == 0: continue
                    if s4 == 2 and s2 == 1 and s1 == 0: continue
                    
                    memo[length + 1][s4][s3][s2] += memo[length][s3][s2][s1]
                    memo[length + 1][s4][s3][s2] %= mod
ans = 0
for i in range(4):
    for j in range(4):
        for k in range(4):
            ans += memo[n][i][j][k]
            ans %= mod

print(ans)


Verdicts: Runtime Error

Accepted
Problem: You are given an integer N. Find the number of strings of length N that satisfy the following conditions, modulo 10^9+7:    * The string does not contain characters other than `A`, `C`, `G` and `T`.   * The string does not contain `AGC` as a substring.   * The condition above cannot be violated by swapping two adjacent characters once.

Submission attempts (in order):
oteage

n=int(input())
mod=10**9+7
memo=[{} for i in range(n+1)]

def ok(last4):
  for i in range(4):
    t=list(last4)
    if i>=1:
      t[i-1],t[i]=t[i],t[i-1]
    if "".join(t).count("AGC")>=1:
      return False
  return True

def dfs(cur,last3):
  if last3 in memo[cur]:
    return memo[cur][last3]
  if cur==n:
    return 1
  res=0
  for c in "ACGT":
    if ok(last3+c):
      res=(res+dfs(cur+1,last3[1:]+c))%mod
  memo[cur][last3]=res
  return res

print(dfs(0,"TTT"))




Verdicts: Runtime Error

Accepted
Problem: You are given an integer N. Find the number of strings of length N that satisfy the following conditions, modulo 10^9+7:    * The string does not contain characters other than `A`, `C`, `G` and `T`.   * The string does not contain `AGC` as a substring.   * The condition above cannot be violated by swapping two adjacent characters once.

Submission attempts (in order):
N = int(input())
mod = 10 ** 9 + 7
D = [{} for i in range(N + 1)]

def check(last4):
    t = list(last4)
    for i in range(4):
        if i >= 1:
            t[i], t[i - 1] = t[i - 1], t[i]
        if ''.join(t).count('AGC') == 1:
            return False
    return True
    
def dfs(cur, last3):
    if last3 in D[cur]:
        return D[cur][last3]
    if cur == N:
        return 1
    res = 0
    for c in 'ACGT':
        if check(last3 + c):
            res = (res + dfs(cur + 1, last3[1:] + c)) % mod
    D[cur][last3] = res
    return res
    
print(dfs(0, '000'))

N = int(input())
mod = 10 ** 9 + 7
D = [[[[0] * 4 for i in range(4)] for i in range(4)] for i in range(101)]

D[0][3][3][3] = 1
for i in range(100):
    for j in range(4):
        for k in range(4):
            for l in range(4):
                for x in range(4):
                    if k == 0 and l == 1 and x == 2:
                        continue
                    if k == 0 and l == 2 and x == 1:
                        continue
                    if k == 1 and l == 0 and x == 2:
                        continue
                    if j == 0 and l == 1 and x == 2:
                        continue
                    if j == 0 and k == 1 and x == 2:
                        continue
                    D[i + 1][k][l][x] += D[i][j][k][l] % mod
                    D[i + 1][k][l][x] %= mod
                    
ans = 0
for j in range(4):
    for k in range(4):
        for l in range(4):
            ans += D[N][j][k][l]
            ans %= mod
                    
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: You are given an integer N. Find the number of strings of length N that satisfy the following conditions, modulo 10^9+7:    * The string does not contain characters other than `A`, `C`, `G` and `T`.   * The string does not contain `AGC` as a substring.   * The condition above cannot be violated by swapping two adjacent characters once.

Submission attempts (in order):
n=int(input())
alph=["A","C","G","T"]
a=[alph[i]+alph[j]+alph[k] for i in range(4) for j in range(4) for k in range(4)]
d1={l:0 for l in a}
for i in d1:
    if i!="AGC" and i!="ACG" and i!="GAC":
        d1[i]=1
d2={l:0 for l in a}
for i in range(n-3):
    for j in d1:
        next=[j+alph[k] for k in range(4)]
        for k in range(4):
            l=next[k]
            check1=l[1:]=="GAC" or l[1:]=="ACG" or l[1:]=="AGC"
            check2=l[1:]=="GAC" or l[1:]=="ACG" or l[1:]=="AGC"
            if (not check1) and (not check2)
                d2[l[1:]]+=d1[j]
    for j in d1:
        d1[j]=d2[j]%1000000007
        d2[j]=0
print(sum(d1.values())%1000000007)

n=int(input())
alph=["A","C","G","T"]
a=[alph[i]+alph[j]+alph[k] for i in range(4) for j in range(4) for k in range(4)]
#print(len(a))
d1={l:0 for l in a}
for i in d1:
    if i!="AGC" and i!="ACG" and i!="GAC":
        d1[i]=1
d2={l:0 for l in a}
for i in range(n-3):
    for j in d1:
        next=[j+alph[k] for k in range(4)]
        for k in range(4):
            l=next[k]
            if l[1:]=="GAC" or l[1:]=="ACG" or l[1:]=="AGC":
                #print(l)
                pass
            elif l[0]=="A" and l[3]=="C" and (l[1]=="G" or l[2]=="G"):
                #rint(l)
                pass
            else:
                d2[l[1:]]+=d1[j]
    for j in d1:
        d1[j]=d2[j]
        d2[j]=0
print(sum(d1.values())%(1000000007))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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
if result%2:
  print(pow(2,result//2 +1,p)-1)
else:
  print(pow(2,(result-1)//2,p)*3 -1)

import sys
n=int(input())
c=[int(i) for i in sys.stdin]
x=[0]*(200001)
c.append(0)
x[c[0]]+= 1
num=1
p=10**9 +7
for i in c:
  if c[i]-c[i-1]:
    x[c[i]]+= num
    x[c[i]]= x[c[i]]%p
  if c[i]-c[i+1]:
    num=x[c[i]]
  else:
    num=0
print(num)

import sys
n=int(input())
c=[int(i) for i in sys.stdin]

d=[]

stack=0
for i in c:
  if i!=stack:
    d.append(i)
  stack=i

x=[0]*200001
sum=1
p=10**9+7
for i in range(1,len(d)):
  x[d[i]]= (x[d[i]]+sum)%p
  sum=x[d[i]]%p
print(sum)

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
if result%2:
  print(pow(2,result//2 +1,p)-1)
else:
  print((pow(2,result-1//2 +1,p)-1)

import sys
n=int(input())
c=[int(i) for i in sys.stdin]

d=[]

stack=0
for i in c:
  if i!=stack:
    d.append(i)
  stack=i

x=[0]*200001
sum=1
for i in range(1,len(d)):
  x[d[i]]+= sum
  sum=x[d[i]]
print(sum)

import sys
n=int(input())
c=[int(i) for i in sys.stdin]

d=[]

stack=0
for i in c:
  if i!=stack:
    d.append(i)
  stack=i

x=[0]*200001
sum=1
p=10**9+7
for i in range(0,len(d)):
  x[d[i]]= (x[d[i]]+sum)%p
  sum=x[d[i]]%p
print(sum)

Verdicts: Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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)
    
    
    return pdt.numerator
for a in c.values():
  answer+=comb(a,2)
  answer%=mod
print(answer)

N=int(input())
MOD=10**9+7
memo={}


prev_num=1
prev=None

for _ in range(N):
  c=int(input())
  if c==prev:
    continue
  tmp=prev_num
  if c in memo:
    tmp+=memo[c]
  tmp%=MOD
  
  
  memo[c]=tmp
  prev_num=tmp
  prev=c
print(prev_num)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
from collections import defaultdict
import itertools
from functools import reduce


def analyze(string):
  s_count = defaultdict(int)
  for s in string:
    s_count[s] += 1
  counts = tuple(s_count.values())
  return counts

N = int(input())
string = input()

def search(N, string):
    memo = {}
    def count(counts, num_set):
        if (counts, num_set) in memo:
            return memo[(counts, num_set)]

        if num_set == 1:
            ans = sum(counts)
        elif num_set == 2:
            num_sum = sum(counts)
            ans = 0
            for i in range(len(counts)):
                num_sum -= counts[i]
                ans += counts[i] * num_sum
        else:
            ans = 0
            for i in range(len(counts) - 1):
                ans += counts[i] * count(counts[i + 1:], num_set - 1)

        memo[(counts, num_set)] = ans
        return ans

    counts = analyze(string)
    ans = 0
    for i in range(1, len(counts) + 1):
        ans += count(counts, i)
    print(ans % (10**9 + 7))

search(N, string)


from collections import defaultdict


def search(colors):
    dp = [1] * len(colors)
    c_dict = defaultdict(list)
    c_sum = defaultdict(int, {colors[0]:1})
    for i in range(1, len(colors)):
        color = colors[i]
        dp[i] = dp[i-1]
        if color != colors[i-1]:
            dp[i] += c_sum[color]
            c_sum[color] = dp[i]
    print(dp[-1] % (10**9 + 7))

N = int(input())
colors = []
for _ in range(N):
    colors.append(int(input()))

search(colors)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
mod = 10 ** 9 + 7

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

mod = 10 ** 9 + 7
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])

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 + 1)]
color_sum[cc[0]] = 1
for i in range(2, n + 1):
    dp[i] = dp[i - 1]
    if cc[i - 2] == cc[i - 1]:
        continue
    dp[i] += color_sum[cc[i - 1]]
    dp[i] %= mod
    color_sum[c[i - 1]] += dp[i - 1]
    color_sum[c[i - 1]] %= mod
print(dp[n])

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
 = [0 for i in range(N)]
alpha = {}
for i in range(N):
    C[i] = int(input())
    if C[i] in alpha.keys():
        alpha[C[i]].append(i)
    else:
        alpha[C[i]] = [i]
sosu = 10 ** 9 + 7

dp = [1 for i in range(N)]
mae = C[1]
for i in range(2,N):
    dp[i] = dp[i-1]
    if C[i] != mae:
        numlist = alpha[C[i]]
        for j in numlist:
            if j < i and j>=1:
                dp[i] += dp[j-1]
            elif j == 0:
                dp[i] += 1
            else:
                break
    mae = C[i]
    dp[i] = dp[i] % sosu
print(dp[N-1])


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

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

sosu = 10 ** 9 + 7

dp = [1 for i in range(N)]
alpha = {}
alpha[C[0]] = [0]
mae = C[0]
for i in range(1,N):
    dp[i] = dp[i-1]
    if C[i] != mae:
        if C[i] in alpha.keys():
            length = len(alpha[C[i]])
            lastnum = alpha[C[i]][length - 1]
            dp[i] += dp[lastnum]
            alpha[C[i]].append(i)
        else:
            alpha[C[i]] = [i]
    mae = C[i]
    dp[i] = dp[i] % sosu
print(dp[N-1])


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
C = [int(input()) for _ in range(N)]
subC = [-2] * (2 * 10 ** 5 + 10)
cntC = [-1]*N
for num, i in enumerate(C):
    cntC[num] = subC[i]+1
    subC[i] = num

print(cntC)

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]
    else:
        dp[i + 1] = dp[i] + dp[cntC[i]]


print(dp[N])

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

# print(cntC)

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])

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
c = [0] + [int(input()) for _ in range(200001)]
dp = [0] * (n+1)
num = 1
for i in range(n):
    if c[i]!=c[i+1]:
        num += dp[c[i+1]]
        dp[c[i+1]] = num
print(num%(10**9+7))

n = int(input())
c = [0] + [int(input()) for _ in range(n)]
dp = [0] * (200001)
num = 1
for i in range(n):
    if c[i]!=c[i+1]:
        num += dp[c[i+1]]
        dp[c[i+1]] = num
print(num%(10**9+7))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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(c))

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))

mod=7+10**9
n=int(input())
c=[int(input()) for _ in [0]*n]
data=[0]*n
def dp(k,l):
    if data[k]>0:
        return data[k]
    if len(l)<=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(c))

mod=7+10**9
n=int(input())
c=['$']+[int(input()) for _ in [0]*n]
data=[1]+[0]*n
s={}

for i in range(1,n+1):
  if c[i] in s.keys():
    if c[i]!=c[i-1]:
      s[c[i]]+=data[i-1]
      s[c[i]]%=mod
  else:
    s[c[i]]=data[i-1]
  data[i]=s[c[i]]%mod
        
print(data[n])


Verdicts: Runtime Error

Wrong Answer

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
from collections import defaultdict

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

d = defaultdict(int)

ans=0
for i,c in enumerate(C):
    if i>=1 and C[i-1]==C[i]:
        continue
    else:
        ans+=d[c]
        d[c]=ans
print(ans)

from collections import defaultdict

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

d = defaultdict(int)

ans=1
for i,c in enumerate(C):
    if i>=1 and C[i-1]==C[i]:
        continue
    else:
        ans+=d[c]
        d[c]=ans
        
        ans%=10**9+7
        d[c]%=10**9+7
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import sys
input = sys.stdin.readline

INF = 10 ** 9
MOD = 10 **9 + 7

N = int(input())

C = [int(input()) for _ in range(N)]
lst = [INF] * (2 * 10 ** 5 + 10) 
ans = [1] * N
 
lst[C[-1]] = N - 1

for i in range(N - 2, -1, -1):
    c = C[i]
    if lst[c] == INF or lst[c] == i + 1:
        ans[i] = ans[i + 1]
    else:
        ans[i] = ans[i + 1] + ans[lst[c]]
    lst[c] = i

print (ans)
print (ans[0] % MOD)

import sys
input = sys.stdin.readline

INF = 10 ** 9
MOD = 10 **9 + 7

N = int(input())

C = [int(input()) for _ in range(N)]
lst = [INF] * (2 * 10 ** 5 + 10) 
ans = [1] * N
 
lst[C[-1]] = N - 1

for i in range(N - 2, -1, -1):
    c = C[i]
    if lst[c] == INF or lst[c] == i + 1:
        ans[i] = ans[i + 1]
    else:
        ans[i] = ans[i + 1] + ans[lst[c]]
    ans[i] %= MOD
    lst[c] = i

# print (ans)
print (ans[0] % MOD)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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())

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
    cnt_clr = defaultdict(int)
    for i, c in enumerate(C):
        ret = dp[i]
        ret += cnt_clr[c]
        cnt_clr[c] = ret
        dp[i + 1] = ret % MOD

    ans = dp[len(C)]

    return ans % MOD

print(main())

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import numpy as np
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
L = len(C)
A = np.array(C)

ans = 1
f = np.ones(L + 1, dtype="int")
for i in range(2, L):
    ans += np.sum(f[A[:i-1] == A[i]])
    f[i + 1] = ans

print(ans)

import sys

N = int(input())
C = [0]
for line in sys.stdin:
    c = int(line)
    if c[-1] == c:
        continue
    else:
        C.append(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 % (10 ** 9 + 7))

import sys
from collections import defaultdict

N = int(input())
C = [0]
for _ in range(N):
    c = int(sys.stdin.readline())
    if C[-1] != c:
        C.append(c)

ans = 1
dic = defaultdict(lambda: 0)
mod = 10 ** 9 + 7
for c in C:
    a = dic[c]
    dic[c] += ans
    ans = (ans + a) % mod

print(ans % mod)


Verdicts: Time Limit Exceeded

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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):
    
    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)))

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):
    
    dp = [1] * len(A) + [1]

    current_dic = {}

    MOD = 10**9 + 7

    for i in range(len(A)):

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

            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)))


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
#b
import math
def cc(n, r):
    return math.factorial(n) / math.factorial(n - r) / math.factorial(r)
n = int(input())
c = [int(input()) for _ in range(n)]
d = dict()
i = 1
while i < n:
    if c[i] == c[i-1]:
        del c[i]
        n -= 1
    else:
        i += 1
for i in c:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1
cnt = 0
for i in d:
    if d[i] >= 2:
        cnt += cc(d[i],2)
print(cnt)

n = int(input())
oth = [int(input()) for _ in range(n)]
mod = 10**9 + 7
l = list()
for x in oth:
    if l and l[-1] == x:
        continue
    l.append(x)
lenl = len(l)
last = [-1] * 200001
l2 = [-1] * 200001
for i, a in enumerate(l):
    l2[i] = last[a]
    last[a] = i

dp = [0] * lenl
dp[0] = 1
for i in range(1, lenl):
    prev = 0 if l2[i] < 0 else dp[l2[i]]
    dp[i] = (dp[i - 1] + prev) % mod
print(dp[-1])


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
C = dict()
i, cp, r = 0, 0, ['x'] * N
for _ in range(N):
    c = int(input())
    if c != cp:
        if c in C.keys():
            r[C[c]] = i
        C[c], cp = i, c
        i += 1
length = i
hist, add, l, temp, ans = [0] * length, [0] * length, 0, 0, 0
for l in range(length):
    temp += add[l]
    hist[l] = temp
    if r[l] != 'x':
        add[r[l]] += temp + 1
        ans += temp + 1
#print((ans+1) % (10**9+7))

N = int(input())
C = dict()
i, cp, lr = 0, 0, dict()
for _ in range(N):
    c = int(input())
    if c != cp:
        if c in C.keys():
            if C[c] in lr.keys():
                lr[C[c]] = [i]
        C[c], cp = i, c
        i += 1
length = i
hist, add, i, ans = [0] * length, [0] * length, 0, 0
for l in list(lr.keys()):
    for r in lr[l]:
        while i <= l:
            hist[i] = hist[i-1] + add[i]
            i += 1
        add[r] += hist[l] + 1
        ans += hist[l] + 1
print((ans+1) % (10**9+7))

N = int(input())
C = dict()
i, cp, hist, ans = 0, 0, [0]*N, 0
for _ in range(N):
    c = int(input())
    if c != cp:
        if c in C.keys():
            temp = hist[C[c]] + 1
            hist[i] = hist[i-1] + temp
            ans += temp
        else:
            hist[i] += hist[i-1]
        C[c], cp = i, c
        i += 1
print((ans+1) % (10**9+7))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
arr=[int(input()) for _ in range(n)]
dp=[0]*n
dp[0]=1
mod=10**9+7
record={arr[0]:0}
for i,v in enumerate(arr):
  if i==0:
    continue
  dp[i]=dp[i-1]
  if record[v] and record[v]<i-1:
    dp[i]+=dp[record[v]]
    dp[i]=dp[i]%mod
print(dp[-1])

n=int(input())
arr=[int(input()) for _ in range(n)]
mod=10**9+7

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

record={arr[0]:0}

for i,v in enumerate(arr):
  if i==0:
    continue
  dp[i]=dp[i-1]
  if v in record and record[v]<i-1:
    dp[i]+=dp[record[v]]
    dp[i]=dp[i]%mod
  record[v]=i
print(dp[-1])


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N=int(input()) 
clist=[-1]
mod=10**9+7
for i in range(N):
  t=int(input())
  if t==clist[-1]:
    continue
  clist.append(t)
  
colorlast=[-1]*(3*10**5)
poslp=[-1]*(N+2)

for e,c in enumerate(clist,1):
  if colorlast[c]!=-1:
    poslp[e]=colorlast[c]
    colorlast[c]=e
  else:
    colorlast[c]=e

dp=[0]*(N+1)
dp[0]=1
for e,c in enumerate(clist,1):
  if poslp[e]!=-1:
    dp[e]=(dp[e-1])%mod
  else:
    dp[e]=(dp[e-1]+dp[poslp[e]])%mod
print(dp[len(clist)]%mod)
    


def solve():
    
    
    
    N = int(input())
    X = [int(input()) for _ in range(N)]
    MOD = int(1e9)+7
    
    colors = set()
    NoDouble = [-1]
    for x in X:
        colors.add(x)
        if x == NoDouble[-1]:
            continue
        NoDouble.append(x)
    del NoDouble[0]
    N = len(NoDouble)
    C = len(colors)

    ForIdxLastNum = [-1] * N 
    
    Onetime_colors = [-1] * (2*10**5+1)

    for e,c in enumerate(NoDouble):
        if Onetime_colors[c] == -1:
            
            Onetime_colors[c] = e
        else:
            ForIdxLastNum[e] = Onetime_colors[c]
            Onetime_colors[c] = e
    
    
    DP = [0] * (N+1) 
    DP[0] = 1

    for e,c in enumerate(NoDouble):
        if ForIdxLastNum[e] == -1:
            
            DP[e+1] = DP[e]
        else:
            lastIdx = ForIdxLastNum[e]
            DP[e+1] = (DP[lastIdx+1] + DP[e]) % MOD
    
    print(DP[N] % MOD)

            
    
    


if __name__ == "__main__":
    solve()

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
MOD = 10**9 + 7

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

dp = [0]*(N+1)
lis = [-1] * (2 * 10**5 + 1)
dp[0] = 1
lis[C[0]] = 0
for i,c in enumerate(C[1:],1):
    prev_i = c_to_i[c]
    dp[i] = dp[i-1]
    if prev_i != i-1:
        dp[i] += dp[prev_i]
        dp[i] %= MOD
    lis[c] = i

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



MOD = 10**9 + 7
N = int(input())
C = [int(input()) for _ in range(N)]
dp = [0]*(N+1)
lis = [-1] * (2 * 10**5 + 1)
dp[0] = 1
lis[C[0]] = 0
for i,c in enumerate(C[1:],1):
    prev_i = lis[c]
    dp[i] = dp[i-1]
    if prev_i != i-1:
        dp[i] += dp[prev_i]
        dp[i] %= MOD
    lis[c] = i
answer = dp[N-1]
print(answer)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
# 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))

# 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]%(10**9+7))

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N=int(input())
lst=[0]
mod=10**9+7

for i in range(N):
  a=int(input())
  if lst[-1]==a:
    continue　
  else:
    lst.append(a)

    
length=len(lst)



L=[0]*(2*10**5+1)
DP=[0]*(length-1)
DP.insert(0,1)
for i in range(1,length):
  if L[lst[i]]==0:
    DP[i]=DP[i-1]%mod
    L[lst[i]]=i
  else:
    j=L[lst[i]]
    DP[i]=(DP[i-1]+DP[j])%mod
    L[lst[i]]=i
print(DP[-1])


N=int(input())
lst=[0]
mod=10**9+7

for i in range(N):
  a=int(input())
  if lst[-1]==a:
    continue　
  else:
    lst.append(a)

    
length=len(lst)



L=[0]*(2*10**5+1)
DP=[0]*(length-1)
DP.insert(0,1)
for i in range(1,length):
  if L[lst[i]]==0:
    DP[i]=DP[i-1]%mod
    L[lst[i]]=i
  else:
    j=L[lst[i]]
    DP[i]=(DP[i-1]+DP[j])%mod
    L[lst[i]]=i
print(DP[-1])


N=int(input())
lst=[0]
mod=10**9+7
for i in range(N):
  a=int(input())
  if lst[-1]==a:
    continue
  else:
    lst.append(a)
length=len(lst)
L=[0]*(2*10**5+1);DP=[0]*(length-1)
DP.insert(0,1)
for i in range(1,length):
  if L[lst[i]]==0:
    DP[i]=DP[i-1]%mod
    L[lst[i]]=i
  else:
    j=L[lst[i]]
    DP[i]=(DP[i-1]+DP[j])%mod
    L[lst[i]]=i
print(DP[-1])


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import bisect
n = int(input())
c = [int(input()) for i in range(n)]

ans = 1
li = [[] for i in range(9)]
for i in range(n):
  if not li[c[i]]:
    li[c[i]].append(i)
  else:
#    if li[c[i]] != li[c[i]][-1]

    li[c[i]].append(i)
    ans += len(li[c[i]]) - 1
#    for j in range(9):
#      ans += len()-1

print(ans)

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

ans = 1
li = [[] for i in range(9)]
for i in range(n):
  if not li[c[i]]:
    li[c[i]].append(i)
    print(i)
  else:
#    if li[c[i]] != li[c[i]][-1]

    li[c[i]].append(i)
    ans += len(li[c[i]]) - 1
#    for j in range(9):
#      ans += len()-1

print(ans)

import bisect
n = int(input())
c = [int(input()) for i in range(n)]
dp = [1 for i in range(n)]
dp2 = [-1 for i in range(n)]
memo = {}
ans = 0

def count(s):
  memo = {}
  res = 1
  for i in range(len(s)):
    if s[i] not in memo:
      memo[s[i]] = 1
    else:
      memo[s[i]] += 1
  for i in memo:
    res = res*((memo[i]*(memo[i]+1))//2)
  return res


dp2[c[0]] = 0
#print("dp",dp)
#print("dp2",dp2)
     
for i in range(1,n):
  
  if c[i] != c[i-1]:
    if dp2[c[i]] == -1:
      dp2[c[i]] = i
    else:
      dp[c[i]] = count(c[dp2[c[i]]:i])*dp[c[i]]
      ans += dp[c[i]]
      dp2[c[i]] = i

 # print(i,"dp",dp)
  #print(i,"dp2",dp2)
  #print(ans)   
#    for j in range(9):
#      ans += len()-1

print(ans)

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

dp = [0]*(n+1)
dp[0] = 1
memo = {}
for i in range(n):
    if c[i] not in memo:
        memo[c[i]] = i
        dp[i+1] = dp[i]
    else:
        if c[i]==c[i-1]:
            dp[i+1] = dp[i]
            memo[c[i]] = i
            continue
        
        dp[i+1] += dp[memo[c[i]]+1]
        
        dp[i+1] += dp[i]
        
        memo[c[i]] = i
        dp[i+1] %= MOD
print(dp[-1] % MOD)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
# coding: utf-8
# Your code here!


N=int(input())

C=[0]*2*10**5

ans=1
pre=-1


for _ in range(N):
    c=int(input())
    if pre!=c:
        ans+=C[c]
        C[c]+=1*ans
    pre=c
    print(ans,C[:10])
#print(ans)
    


# coding: utf-8
# Your code here!
N=int(input())

l=[0]*2*10**5
k=[0]*2*10**5

ans=1
pre=-1
for _ in range(N):
    c=int(input())-1
    if pre==c:
        continue
    l[c]+=1
    ans+=k[c]*min(l[c]-1,1)
    k[c]=ans
    pre=c
    """
    print(c+1)
    print(l[:5],k[:5])
    print(ans)
    """
print(ans%(10**9+7))


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N=int(input())
l=[]
l_value=[]
i=0
stack=-1
for i in range(N):
    if i <= N:
        stack=input()
        l.append(stack)
list_simple=[]
for i in l:
    if stack != i:
        list_simple.append(i)
dp_dict=[]
dp=1
for i in list_simple:
    if c not in dp_dict:
        dp_dict[c] = 0
    dp = dp_dict[c] +dp
    dp_dict[c] = dp
print(dp)


N=int(input())
l=[]
l_value=[]
i=0
stack=-1
for i in range(N):
    if i < N:
        l.append(input())
list_simple=[]
for i in l:
    if stack != i:
        list_simple.append(i)
    stack = i
dp_dict=[0]*200001
dp=1
for i in list_simple:
    i=int(i)
    dp = dp_dict[i] +dp
    dp_dict[i] = dp
print(dp%(10**9+7))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
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)

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)

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)

from collections import defaultdict as dd
d = dd(int)
r = 1
p = ""
for _ in range(int(input())):
  c = input()
  if c != p:
    r = (r + d[c]) % (10**9 + 7)
    d[c] = r
  p = c
print(r)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted