Problem:


Score : 200 points

Problem Statement

You are given a string S of length N.
Among its subsequences, count the ones such that all characters are different, modulo 10^9+7. Two subsequences are considered different if their characters come from different positions in the string, even if they are the same as strings.

Here, a subsequence of a string is a concatenation of one or more characters from the string without changing the order.

Constraints

1 \leq N \leq 100000

S consists of lowercase English letters.

|S|=N

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the number of the subsequences such that all characters are different, modulo 10^9+7.

Sample Input 1

4
abcd

Sample Output 1

15

Since all characters in S itself are different, all its subsequences satisfy the condition.

Sample Input 2

3
baa

Sample Output 2

5

The answer is five: b, two occurrences of a, two occurrences of ba. Note that we do not count baa, since it contains two as.

Sample Input 3

5
abcab

Sample Output 3

17



Sample input:
4
abcd


Sample output:
15

Submission status: Accepted

Solution code:
N = int(input())
S = input()
d = {}
mod = 10**9 + 7
for key in S:
    if key in d:
        d[key] += 1
    else:
        d[key] = 1
ans = 1
for x in d.values():
    ans *= x+1
print(ans % mod -1)

Submission status: Accepted

Solution code:
n=int(input())
s=list(input())
mod=10**9+7
z=list(set(s))
ans=1

m=len(z)
for i in range(m):   
    ans*=(s.count(z[i])+1)%mod
    ans=ans%mod
print((ans-1)%mod)

Submission status: Accepted

Solution code:
for t in range(1):
	n=input()
	s=input()
	freq=[0]*(26)
	ct=0
	for i in range(len(s)):
		freq[ord(s[i])-ord('a')]+=1
		if freq[ord(s[i])-ord('a')]==1:
			ct+=1
	ans=1
	for i in range(26):
		if freq[i]>0:
			ans=(ans*(freq[i]+1))
	print((ans-1)%1000000007)

Submission status: Accepted

Solution code:
MOD = 10**9+7

N = int(input())
S = input().strip()

# nums[c]: Sの中の文字cの個数
nums = dict()
for c in S:
    if c in nums: nums[c] += 1
    else: nums[c] = 1  # 1個目

# print(nums)

res = 1
for _, v in nums.items():
    res = res * (v+1) % MOD

res -= 1
print(res)

Submission status: Accepted

Solution code:
#! usr/bin/env python
# -*- coding: utf-8 -*-


def main():
    N = int(input())
    S = input()

    cnt = [0] * 26
    for i in S:
        cnt[ord(i)-ord('a')] += 1

    ans = 1
    MOD = 10 ** 9 + 7
    for i in range(26):
        ans = ans * (cnt[i]+1) % MOD

    print(ans-1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from functools import reduce
from string import ascii_lowercase
n = int(input())
s = input()
cnt = [s.count(c) + 1 for c in ascii_lowercase]
print(reduce(lambda x, y: x * y % (10 ** 9 + 7), cnt) - 1)

Submission status: Accepted

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

N = int(input())

S = input()

ans = 1
tmp = 0
cnt = [0]*26
for s in S:
    cnt[ord(s)-ord('a')] += 1
    
for c in cnt:
    if c != 0:
        ans *= (c+1)
        ans %= 10**9+7
    
        
print(ans-1)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
M = 10**9+7

cnt = {}
for i in S:
    if i in cnt.keys():
        cnt[i] += 1
    else:
        cnt[i] = 1

ans = 1
for l in cnt.values():
    ans *= l + 1

print((ans-1)%M)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
d = {}
MOD = 10 ** 9 + 7
for key in S:
    if key in d:
        d[key] += 1 
    else:
        d[key] = 1 
ans = 1
for v in d.values():
    ans *= v+1
    ans %= MOD
print(ans - 1)

Submission status: Accepted

Solution code:
input()
S=input()
L=list("abcdefghijklmnopqrstuvwxyz")
C=[1]*26
for s in S:
    C[L.index(s)]+=1
ans=1
for c in C:
    ans=(ans*c)%(10**9+7)
print(ans-1)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
l=[1 for i in range(26)]
L=[chr(i) for i in range(97,97+26)]
for j in range(len(s)):
  l[L.index(s[j])]+=1
ans=1
for k in range(26):
  ans*=l[k]
  ans%=(10**9+7)
print(ans-1)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
f=[0]*(26)
for i in s:
	f[ord(i)-ord('a')]+=1
ans=1
for i in range(26):
	ans=(ans*(f[i]+1))%1000000007
print(ans-1)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
v = [0] * 26
for i in range(0, N):
    v[ord(S[i]) - 97] += 1
wa = 1

for i in range(len(v)):
    wa *= (v[i] + 1)
print((wa - 1) % (10 ** 9 + 7))

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter


def readln():
    return list(map(int, input().split()))


N = readln()[0]
S = input()
mod = 10**9+7

dic = Counter(S)

ans = 1
for count in dic.values():
    # print(count)
    ans *= (count + 1)
    ans %= mod

# print(ans)
print(ans-1)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
cnt=1
n = 10**9 + 7
for i in set(S):
    cnt*=(S.count(i)+1)
    cnt=cnt%n
 
print(cnt-1)

Submission status: Accepted

Solution code:
from collections import*
n=int(input())
ans=1
for i in Counter(input()).values():
    ans*=(i+1)
print((ans-1)%(10**9+7))

Submission status: Accepted

Solution code:
N = input()
S = input()
mod = 1000000007

d = {}
for c in S:
    if not c in d:
        d[c] = 1
    else:
        d[c] += 1

c = 1
for i in d.values():
    c *= (i+1)

print((c-1)%mod)

Submission status: Accepted

Solution code:
P=10**9+7
N=int(input())
S=input()
dict={}

for s in set(S):
    dict[s]=S.count(s)+1

ans=1

for d in dict.values():
  ans=(ans*d)%P
  
print(ans-1)

Submission status: Accepted

Solution code:
from collections import Counter
N = int( input())
S = input()
Q = 10**9+7
C = Counter(S)
ans = 1
for c in C:
    ans *= C[c]+1
    ans %= Q
print((ans-1)%Q)

Submission status: Accepted

Solution code:
n = int(input())
S = list(input())
dic = {}

for d in S:
    if d not in dic:
        dic[d] = 1
    else:
        dic[d] += 1
tot = 1
for d in dic:
    i = dic[d] + 1
    tot = tot*i % (10**9 + 7)

print((tot-1) % (10**9+7))

Submission status: Accepted

Solution code:
import sys,itertools
input = sys.stdin.readline
N = int(input().strip())
S = input().strip()

le = [S.count(s)+1 for s in set(S)]
cnt=1
for i in le:
    cnt*=i
print((cnt-1)%((10**9)+7))

Submission status: Accepted

Solution code:
#A問題
import collections
N=int(input())
S=str(input())
Slist=list(S)
c = collections.Counter(Slist)
d = c.most_common()
dlen=len(d)
count=1
for i in range(dlen):
    count*=(d[i][1]+1)
count-=1
count%=1000000007
print(count)

Submission status: Accepted

Solution code:
N = int(input())
S = input()

mod = 10 ** 9 + 7

kind = set(S)
each_char = []

for char in kind:
    each_char.append(S.count(char))

count = 1
for i in each_char:
    count = (count % mod) * ((i + 1) % mod) % mod

print((count - 1) % mod)

Submission status: Accepted

Solution code:
N = int( input())
S = input()
Q = 10**9+7
A = [1]*26
ANS = [0]*26
for i in range(N):
    s = ord(S[i]) - ord("a")
    ans = 1
    for j in range(26):
        if j != s:
            ans *= A[j]
            ans %= Q
    ANS[j] = (ANS[j] + ans)%Q
    A[s] += 1
print( sum(ANS))

Submission status: Accepted

Solution code:
from collections import defaultdict


def readln():
    return list(map(int, input().split()))


N = readln()[0]
S = input()
mod = 10**9+7

dic = defaultdict(lambda: 0)
for s in S:
    dic[s] += 1
ans = 1
for count in dic.values():
    # print(count)
    ans *= (count + 1)
    ans %= mod

# print(ans)
print(ans-1)

Submission status: Accepted

Solution code:
import math
import copy
from collections import Counter
 
 
 
def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:
 
            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l
 

n=input()
s=input()

mod=7+10**9


def func():

    dic = Counter(s)
    ans = 1
    for x in dic:
        ans = ans*(dic[x]+1)%mod
    return ans-1
    
print(func())

Submission status: Accepted

Solution code:

input();s=input()
a,*b=map(s.count,set(s));a+=1
for t in b:a=-~t*a%(10**9+7)
print(a-1)

Submission status: Accepted

Solution code:
N=list(range(int(input())))
S=list(input())
S=sorted(S)
answer=0

prev=S[0]
counts = []
counter=0

for k in S:
    if k==prev:
        counter+=1
    else:
        prev=k
        if counter!=0:
            counts.append(1+counter)
        counter=1
if counter!=0:
    counts.append(1+counter)

def soujou(li):
    atai=1
    for j in li:
        atai=j*atai
    return atai

answer=soujou(counts)-1
print(answer%(7+10**9))

Submission status: Accepted

Solution code:
import collections
N = int(input())
S = input()

result = 1
route = [x+1 for _,x in collections.Counter(S).items()]
for x in route:
    result = result*x
print((result-1)%(10**9+7))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
MOD = 10**9+7

from collections import defaultdict
import string
d = defaultdict(int)
let = string.ascii_lowercase

for ele in s:
  d[ele] += 1

ans = 1
for i in range(26):
  if d[let[i]]>0:
    ans = (ans * (d[let[i]]+1))%MOD
print(ans-1)

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import product
 
N = int(input())
S = input().strip()
dic = Counter(S)
mod = 10**9 + 7

ans = 1
for x in dic:
    ans = ans*(dic[x]+1)%mod
print(ans-1)

Submission status: Accepted

Solution code:
input();s=input()
a,*b=[s.count(i)+1for i in set(s)]
for t in b:a=t*a%(10**9+7)
print(a-1)

Submission status: Accepted

Solution code:
mod = 10**9 + 7

n = int(raw_input())
s = raw_input()

q = []

for a in "abcdefghijklmnopqrstuvwxyz":
  q.append( s.count(a) )

ans = 1

for a in q:
  ans *= (a+1)
  ans %= mod

print ans-1

Submission status: Accepted

Solution code:
N = int(input())
S = input()

char = []
num = 1
while(len(S) > 0):
    num = num * (S.count(S[0]) + 1)
#    print(S[0] + " : count = {}, num = {}".format(S.count(S[0]), num))
    S = S.replace(S[0], "")

num = num - 1
print(num % 1000000007)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
a = 1
for c in [chr(i) for i in range(97, 123)]:
    a = (a * (S.count(c) + 1)) % (1e9 + 7)
print(int((a - 1) % (1e9 + 7)))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
cnt = [0] * 26
for c in s:
    cnt[ord(c) - ord('a')] += 1
res = 1
for i in cnt:
        res *= i + 1
print((res - 1) % (10 ** 9 + 7))

Submission status: Accepted

Solution code:
from collections import defaultdict


def readln():
    return list(map(int, input().split()))


N = readln()[0]
S = input()
mod = 10**9+7

dic = defaultdict(lambda: 0)
for s in S:
    dic[s] += 1
ans = 1
for count in dic.values():
    # print(count)
    ans *= (count + 1)

# print(ans)
print((ans-1) % mod)

Submission status: Accepted

Solution code:
import collections

n = int(input())
s = input()
cnt = 0
dictionary = {}

for i in range(n)[::-1]:
  if s[i] in dictionary.keys():
    dictionary[s[i]] += 1
  else:
    dictionary[s[i]] = 1
  ch = s[i:]
  tmp_cnt = 1
  for k,v in dictionary.items():
    if k != s[i]:
      tmp_cnt *= (v+1)
  cnt += tmp_cnt % (10**9+7)
print(cnt % (10**9+7))

Submission status: Accepted

Solution code:
from collections import defaultdict


def readln():
    return list(map(int, input().split()))


N = readln()[0]
S = input()


dic = defaultdict(lambda: 0)
for s in S:
    dic[s] += 1
ans = 1
for count in dic.values():
    # print(count)
    ans *= count + 1

# print(ans)
print((ans-1) % (10**9+7))

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
s = input()

cnt = Counter(list(s))
num = 1
for i in cnt.values():
    num = num * (i+1)

out = (num - 1) % int(1e09 + 7)
print(out)

Submission status: Accepted

Solution code:
from collections import Counter
 
n = int(input())
s = input()
cnt = Counter(s)
ans = 1
MOD = 10 ** 9 + 7
for c, v in cnt.items():
    ans = ans * (v + 1) % MOD
print(ans - 1)

Submission status: Accepted

Solution code:
n=int(input())
s=list(input())
d=[1]*26
g=ord("a")
for i in range(n):
    d[ord(s[i])-g]+=1
p=1
for i in range(26):
    if d[i]!=0:
        p*=d[i]
else:
    print((p-1)%(10**9+7))

Submission status: Accepted

Solution code:
import collections

N = int(input())
S = list(input())

c = collections.Counter(S)
v = c.values()
count = 1
for v in c.values():
    count *= (v+1)
print((count-1)%(10**9+7))

Submission status: Accepted

Solution code:
n = int(input()) #整数
s = input() #文字列

x="abcdefghijklmnopqrstuvwxyz"
MOD = 1000000007

counter = list([])
for c in x:
    l = s.count(c)
    if l != 0:
        counter.append(l)

ans = 1
for i in counter:
    ans *= (i+1)
    ans %= MOD
ans -= 1

print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
N = int(input())
S = list(input().strip())
d = {}
for c in S:
  if c in d.keys():
    d[c] += 1
  else:
    d[c] = 1
ans = 0
for n in d.values():
  ans = (ans+n+ans*n)%(10**9+7)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()        

tmp = []
for a in "abcdefghijklmnopqrstuvwxyz":      
    tmp.append(S.count(a)+1)
    
ans = 1 
for i in tmp:
    ans = ans * i % (10**9+7)
    
print(ans-1)

Submission status: Accepted

Solution code:
import collections
N=input()
S=raw_input()

C=collections.Counter(S)

ans=1
for item, cnt in C.items():
	ans*=(cnt+1)

print (ans-1)%(10**9+7)

Submission status: Accepted

Solution code:
N = int(input())
S = input()

ans = 1
while len(S) > 0:
  n = S.count(S[0])
  ans *= n + 1
  S = S.replace(S[0], "")

print((ans - 1) % (10 ** 9 + 7))

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
S = input()
alpha = np.zeros(52)
Alp = [chr(i) for i in range(97, 97+52)]
for s in S:
  alpha[Alp.index(s)] += 1
alpha = alpha[np.nonzero(alpha)]
def func(alpha):
  Size = alpha.shape[0]
  ans = 0
  if Size>1:
    size=int(Size/2)
    m_ans = func(alpha[:size])
    u_ans = func(alpha[size:])
    ans = (m_ans+1)*(u_ans+1)-1
  else:
    ans = alpha[0]
  return int(ans)

print(func(alpha)%(10**9+7))

Submission status: Accepted

Solution code:
n=int(input())
s=input()
d={}
for i in range(n):
    if s[i] in list(d.keys()):
        d[s[i]]+=1
    else:
        d[s[i]]=1
w=1
for i in list(d.values()):
    w*=(i+1)
    w=w%(1e9+7)
if w==0:
    print(1e9+6)
else:
    print(int(w-1))

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline

    n = int(input())
    s = input().rstrip()
    eng_list = 'abcdefghigklmnopqrstuvwxyz'
    eng_dict = {}
    for i in eng_list:
        eng_dict[i] = 1
    for i in s:
        try:
            eng_dict[i] += 1
        except KeyError:
            eng_dict[i] = 2
    ans = 1
    size = 10**9+7
    for i in eng_dict.values():
        ans = (ans*i)%size
    print((ans-1)%size)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

def main(S):
    counter = {}
    for c in S:
        cnt = counter.setdefault(c, 1)
        counter[c] = cnt + 1
    #print(counter)
    n = 1
    for v in counter.values():
        n = (n * v) % 1000000007
        #n = (n * v)# % 1000000007
    return n-1

def test(S, e):
    import sys
    if main(S) != e:
        print("expected", e, "but", main(S))
        sys.exit(1)

test("abcd", 15)
test("baa", 5)
test("abcab", 17)
input()
S = input()
print(main(S))

Submission status: Accepted

Solution code:
import collections
M = pow(10, 9) + 7
input()
s = input().strip()
r=1
for x in collections.Counter(s).values():
    r = (r*(x+1)) %M
print(r-1)

Submission status: Accepted

Solution code:
mod = 1000000007
n = int(input())
s = input()
abets ="abcdefghijklmnopqrstuvwxyz"
counts = []
for c in abets:
  counts.append(s.count(c))
ans = 0
for cnt in counts:
  if cnt != 0:
    ans = (ans + ans*cnt + cnt) % mod
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
import bisect as bs
MOD = 10**9 + 7
L = int(input())
S = input()
dic, l_dic = defaultdict(list), {}
for i in range(L):
    dic[S[i]].append(i)
ans = 0
for key in dic:
    l_dic[key] = len(dic[key])
for i in range(L):
    sub = 1
    for key in dic:
        if key == S[i]:
            continue
        sub = sub * (l_dic[key] - bs.bisect_right(dic[key], i) + 1) % MOD
    ans = (ans + sub) % MOD
print(int(ans))

Submission status: Accepted

Solution code:
counter = 1
N = int(input())
S = input()

n = 10**9 + 7
for i in set(S):
    counter *= (S.count(i)+1)
    counter = counter % n
 
print(counter-1)

Submission status: Accepted

Solution code:
# coding:utf-8
 
n = int(input())
s = input()
LetterCount = {i:s.count(i) for i in 'abcdefghijklmnopqrstuvwxyz'}
answer = 1
for i in 'abcdefghijklmnopqrstuvwxyz':
  answer = answer * (LetterCount[i]+1) % (10**9+7)
print(answer-1)

Submission status: Accepted

Solution code:
import collections as c
ip = lambda : map(int, input().split())

#################
N = int(input())
S = input()

count = c.Counter(S)
res = 1
for i in count:
    res = res%(1e9+7)*(count[i]+1)
res -= 1

print(int(res%(1e9+7)))

Submission status: Accepted

Solution code:
N = int(input())
S = input()
alphabets = {}
ans = 0
mod = 10**9+7
for i in range(N):
    if not S[i] in alphabets:
        alphabets[S[i]] = 0
    alphabets[S[i]] += 1

ans = 1
for c in alphabets:
    ans = ans + ans * alphabets[c]
    ans %= mod
print((ans-1)%mod)

Submission status: Accepted

Solution code:
from collections import Counter
def solve(N, S):
    d = 10**9 + 7
    c = Counter(S)
    ans = 1
    for ch, count in c.items():
        ans *= (count + 1)
    ans %= d
    return ans - 1

if __name__ == "__main__":
    N = int(input())
    S = input()
    print(solve(N, S))

Submission status: Accepted

Solution code:
_=input()
s=input()
mod=7+10**9
ans=1
for i in range(26):
    ans*=1+s.count(chr(ord('a') + i))
    ans%=mod
print(ans-1)

Submission status: Accepted

Solution code:
n=input()
s=list(input())
    
num_s=[]
s_sub=list(set(s))
sum=1
for i in range(len(s_sub)):
    num_s.append(s.count(s_sub[i]))
    sum*=(num_s[i]+1)
    
print((sum-1)%(10**9+7))

Submission status: Accepted

Solution code:
import collections
import functools
import operator
N = int(input())
S = str(input())
c = collections.Counter(S)
count = c.most_common()
count = [x+1 for _, x in count]
count = functools.reduce(operator.mul, count) -1
print(int(count%(10**9+7)))

Submission status: Accepted

Solution code:
from collections import Counter

mod = 1000000007

N = int(input())
S = input()
c = Counter()
ans = 0
for i in range(N):
    ans += ans // (c[S[i]] + 1) + 1
    # ans %= mod
    c[S[i]] += 1
print(ans % mod)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
c=[0]*26
x=10**9+7

ans=0
for chr in range(n):
    c[ord(s[chr])-97]+=1
for i in range(26):
    ans=((ans%x)*((c[i]+1)%x))%x
    ans+=c[i]
    ans%=x
print(ans)

Submission status: Accepted

Solution code:
def f(S):
    source_str = 'abcdefghijklmnopqrstuvwxyz'
    a = [0] * len(source_str)
    for i in range(len(a)):
        a[i] = S.count(source_str[i])
    
    n = 1
    for i in range(len(a)):
        n *= (a[i] + 1)


    return n

def g(S):
    fs = f(S)
    N = int(1e9) + 7
    return (fs + N - 1) % N




N = int(input())
S = input()

print(g(S))

Submission status: Accepted

Solution code:
N = int(input())
S = input()
count = [0] * 26
for c in S:
    count[ord(c) - ord('a')] += 1
seq = 1
for c in count:
    if c != 0:
        seq *= (c + 1)
seq -= 1
print(seq % 1000000007)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
k=list(set(s))
d = {i: s.count(i) for i in k}
counta=0

for i in k:
    counta=counta*d[i]+d[i]+counta


print(counta%(10**9+7))

Submission status: Accepted

Solution code:
l = int(input())
s = input()
s_dict = {}
l = len(s)
for i in range(l):
    if not s[i] in s_dict:
        s_dict[s[i]] = 1
    else:
        s_dict[s[i]] += 1
ans = 1
for v in s_dict.values():
    if v == 1:
    	ans *= 2
    else:
        ans *= v+1

print(int(ans-1)%(10**9+7))

Submission status: Accepted

Solution code:
N = int(input())
S = input()
count = [0]*26
for ch in S:
    count[ord(ch)-ord('a')] += 1
ans = 1
for i in count:
    if i != 0:
        ans *= i+1
print((ans-1)%(10**9+7))

Submission status: Accepted

Solution code:
N = int(input())
S = input()

MOD = 1e9 + 7
L = {}
for i in S:
  if i in L:
    L[i] += 1
  else:
    L[i] = 1

Ans = 1
for i in L.values():
  Ans = Ans * (i + 1) % MOD

Ans -= 1
if Ans < 0:
  Ans += MOD

print(int(Ans))

Submission status: Accepted

Solution code:
N=int(input())
S=input()
R=""
L=[]
obj={}
for s in S:
    if s not in L:
        R+=s
        L.append(s)
        obj[s]=1
    else:
        obj[s]+=1

out=1
for a in obj.keys():
    out*=(obj[a]+1)
    if out>10**9+7:
        out=out%(10**9+7)
print(out-1)

Submission status: Accepted

Solution code:
from collections import Counter
N=int(input())
S=input()
l=list(S)
c=Counter(l)
l=c.most_common()
count=1
least=0
bin=[]
for i in range(len(l)):
    if l[i][1]>1:
        #most+=l[i][1]
        bin.append(1)
        count=count*(l[i][1]+1)
#        print("count",count)
    else:
        least+=1
count=count*2**least
ans=count-1
ans=ans%(10**9+7)
print(ans)

Submission status: Accepted

Solution code:
N = input() 
S = input()

a = {}

for i in range(len(S)):
    m = S[i]
    if m in a:
        a[m] += 1
    else:
        a[m] = 1

n = 1
for i in a.values():
    n = n * (i + 1)
n -= 1

print(n % 1000000007)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
A = 'abcdefghijklmnopqrstuvwxyz'
X = []
for var in A:
    X.append(S.count(var))
Y = X[0]

for i in range(1,26):  
    temp=1  
    for k in range(i+1):
        if k ==0:
            temp*=X[i]
        else:
            temp*=(X[i-k]+1)        
    Y+=temp
print(Y%(10**9+7))

Submission status: Accepted

Solution code:
import collections
n = int(input())
s = input()
c = collections.Counter(list(s))
a = list(c.values())
count = 0
r = 1
for i in range(len(a)):
    if a[i] == 1:
        count += 1
    else:
        r *= (a[i] + 1)

print((2 ** count * r - 1) % (10 ** 9 + 7))

Submission status: Accepted

Solution code:
import collections

N = int(input())
S = list(input())

lst = [0] * 26
for i in range(N):
    lst[ord(S[i]) - 97] += 1

for i in range(len(lst)):
    if i == 0:
        pass
    else:
        lst[i] += lst[i] * sum(lst[:i])

ans = sum(lst)
    
print(ans % (10**9 + 7))

Submission status: Accepted

Solution code:
N = int(input())
S = input()
D = 10**9+7

d = {}
for i,n in enumerate(S):
    if n in d.keys():
        d[n] += 1
    else:
        d[n] = 1

ans = 1
for i in d.values():
    ans *= i+1
print((ans-1)%D)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
c={}
for i in range(N):
    if S[i] in c:
        c[S[i]]+=1
    else:
        c[S[i]]=1
f=1
for i in c:
    f=f*(c[i]+1)
print((f-1)%(10**9+7))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys  # {{{
import os
import time
import re
from pydoc import help
import string
import math
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
# }}}

# pre-defined{{{
sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
ALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)]  # can also use string module
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 I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]
from inspect import currentframe
def dump(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' => '+repr(arg) for arg in args), file=sys.stderr)
# }}}

def local_input():# {{{
    from pcm.utils import set_stdin
    import sys
    from pathlib import Path
    parentdir = Path(os.path.dirname(__file__)).parent
    inputfile = parentdir.joinpath('test/sample-1.in')
    if len(sys.argv) == 1:
        set_stdin(inputfile)
# }}}

m = 10**9 + 7


def solve():
    global n,s;
    n  = int(input())
    s = input()

    res = 1
    for k, v in Counter(s).items():
        res *= (v+1)
        res %= m

    print(res-1)

    return 0

if __name__ == "__main__":# {{{
    try:
        local_input()
    except:
        pass
    solve()
# vim: set foldmethod=marker:}}}

Submission status: Accepted

Solution code:
from collections import Counter
input()
S = input().strip()
c = Counter(S)
ans = 1
for k,v in c.items():
  ans *= (v+1)
print((ans-1)%(10**9+7))

Submission status: Accepted

Solution code:
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    S = [str(c) for c in input().strip()]

    ans = 0
    d = {}
    for i in range(N-1, -1, -1):
        s = S[i]
        if s in d:
            d[s] += 1
        else:
            d[s] = 1

        t = 1
        for k in d:
            if k == s:
                continue

            t *= d[k] + 1

        ans += t
    
    print(ans % (10**9 + 7))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import collections
n=int(input())
s=list(str(input()))
c=collections.Counter(s)

testlist=list(c.values())
ans=1

for i in range(len(testlist)):
    ans=ans*(testlist[i]+1)
    ans=ans%(10**9+7)
ans=ans-1

print(int(ans))

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
S = Counter(input())

ans = 1

for value in S.values():
    if value == 1:
        ans *= 2
    else:
        ans *= (value+1)
print((ans-1)%(10**9+7))

Submission status: Accepted

Solution code:
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def cnt(l):
  num = 1
  for i in l:
    if i != s:
      num *= (i+1)
  return num

N = I()
s = S()

dic = {"a":0,"b":0,"c":0,"d":0,"e":0,"f":0,"g":0,"h":0,"i":0,"j":0,"k":0,\
  "l":0,"m":0,"n":0,"o":0,"p":0,"q":0,"r":0,"s":0,"t":0,"u":0,"v":0,"w":0,\
    "x":0,"y":0,"z":0,}

ans = 0
for i in range(N):
  ans += cnt(list(dic.values()))//(dic[s[i]]+1)
  dic[s[i]] += 1

print(ans%mod)

Submission status: Accepted

Solution code:
N=int(input())
S=list(input())
a=[0]*N
for i in range(N):
    a[i]=ord(S[i])-96
from collections import Counter
b=Counter(a)
c=b.most_common()
ans=1
for i in range(len(c)):
    ans*=(c[i][1]+1)
print((ans-1)%(10**9+7))

Submission status: Accepted

Solution code:
N = input()
s = input()
hoge = []
charlist = list(s)
result = 1
Alist = ["q","w","e","r","t","y","u","i","o","p","a","s","d","f","g","h","j","k","l","z","x","c","v","b","n","m"]
for i in Alist:
    hoge.append(charlist.count(i))
for j in hoge:
    result = result * (j + 1)
print((result -1) % (10 ** 9 + 7))

Submission status: Accepted

Solution code:
input()
s = input()

t = {}
for c in s:
    if c in t.keys():
        t[c]+=1
    else:
        t[c] = 2

s = 1
for i in t.values():
    s*=i
print((s-1) % (10**9+7))

Submission status: Accepted

Solution code:
mod = 10**9 + 7
N = int(input())
S = input()
al = [0]*26
ans = pow(2,N)-1
cnt = 1
for s in S:
    al[ord(s)-97] += 1
for e in al:
    if e >= 2:
        ans -= pow(2,N-e)*(pow(2,e)-(e+1))*cnt
        ans %= mod
        N -= e
        cnt *= (e+1)
ans %= mod
print(ans)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
n = int(input())
s = input()

alphabet_place = dict()
for idx, c in enumerate(s):
    if c in alphabet_place:
        alphabet_place[c].append(idx)
    else:
        alphabet_place[c] = [idx]

ans = 1
for alph, place in alphabet_place.items():
    # +1: unuse
    ans = (len(place) + 1) * ans

# all unuse
ans = ans - 1
print(ans % (10**9+7))

Submission status: Accepted

Solution code:
N = int(input())
S = input()
str_dict = {}

for s in S:
    if s not in str_dict:
        str_dict[s] = 1
    else:
        str_dict[s] = str_dict[s] + 1

single_char = {k: v for k, v in str_dict.items() if v == 1}
multiple_char = {k: v for k, v in str_dict.items() if v != 1}
single_char_num = len(single_char)

base_permutation = 2 ** single_char_num % (10 ** 9 + 7)

all_permutation = base_permutation
for v in multiple_char.values():
    all_permutation = all_permutation * (v + 1)
all_permutation = all_permutation - 1

print(all_permutation % (10 ** 9 + 7))

Submission status: Accepted

Solution code:
N = int(input())
S = input()

alp = "abcdefghijklmnopqrstuvwxyz"
x = [1] * 26
for i in range(N):
    x[alp.find(S[i])] += 1
plo = 1
for i in range(26):
    plo *= x[i]
print((plo-1)%(10**9+7))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
  input()
  string = input().strip()

  count = [0] * 26

  for c in string:
    count[ord(c) - 97] += 1

  table = count[:]
  value = sum(count)

  for _ in range(len(count) - 1):
    for i in range(len(count)):
      table[i] = count[i] * sum(table[i + 1:])

    value = (value + sum(table)) % int(1.0e+9 + 7)

  print(value, flush=True)


if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
S = [i for i in input()]
c = Counter(S)

ans = 1
for i in c.values():
    ans *= i + 1

ans -= 1
    
print(ans%(10**9+7))

Submission status: Accepted

Solution code:
N = int(input())
S = input()

MOD = 10 ** 9 + 7
alpha_dict = {}
for alpha in 'abcdefghijklmnopqrstuvwxyz':
    alpha_dict[alpha] = 1
     

for s in S:
    alpha_dict[s] += 1
ans = alpha_dict['a'] % MOD
for alpha in 'bcdefghijklmnopqrstuvwxyz':
    ans = (ans * (alpha_dict[alpha] % MOD)) % MOD
    
if ans == 0:
    print(MOD - 1)
else:
    print(ans - 1)

Submission status: Accepted

Solution code:
import collections
n = int(input())

a = list(input())

l = collections.Counter()
co = 1

for i in a:
    l[i] += 1
l = list(l.most_common())
for i in range(len(l)):
    co *= l[i][1]+1

print((co-1)%(10**9+7))