M=10**9+7

def div_conq(l,r,c)
  return 1 if r-l<=1
  m=(l+r)/2
  l_num=div_conq(l,m-1,c)
  r_num=div_conq(m,r,c)
  sum=l_num*r_num
  l_h=Hash.new(0)
  r_h=Hash.new(0)
  ret=0
  prev=c[m]
  (m-1).downto(l){|k|
    l_h[c[k]]+=1 if prev!=c[k]
    prev=c[k]
  }
  prev=c[m-1]
  m.upto(r){|k|
    r_h[c[k]]+=1 if prev!=c[k]
    prev=c[k]
  }
  l_h.each{|key,val|ret+=val*r_h[key]}
  #p [l,r,(ret+sum)%M,ret,l_num,r_num]
  (ret+sum)#%M
end

n=gets.to_i
c=n.times.map{gets.to_i}

puts div_conq(0,n-1,c)