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:
#AGC031A
N=int(input())
S=input()
c={}
for s in S:
    c[s]=c.get(s,0)+1
ans=0
for s in S:
    c[s]-=1
    t=1
    for k in c.keys():
        if c[k]>0 and k!=s:
            t*=c[k]+1
    ans+=t
print(ans%(10**9+7))

Submission status: Accepted

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

D = {}
for s in S :
    if s not in D :
        D[s] = 1
    else :
        D[s] += 1

L = sorted(list(D.values()))

ans = 1
if N == 1 :
    ans = 1
elif len(L) == 1 :
    ans = L[0]
else :
    for i in range(len(L)) :
        ans *= (1+L[i])
        ans %= (10**9+7)
    ans -= 1
ans %= (10**9+7)
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
s = input()
mod = 10**9 + 7
q  =[c for c in s]
p = Counter(q)
#print(p)
ans = 1
for key in p:
    #print(p[key])
    ans *= (p[key]+1)
    ans%= mod

print(ans-1)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
score=1
mozis='abcdefghijklmnopqrstuvwxyz'
for i in mozis:
    point=S.count(i)+1
    score*=point

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

Submission status: Accepted

Solution code:
# coding: utf-8

import collections
line = int(input())
string = list(input())
data = collections.Counter(string)
sum = 1
for word in data:
    sum *= (data[word] + 1)
answer = (sum - 1)%(10**9 + 7)
print(answer)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
from collections import Counter
c= Counter(s)
ans=1
vals=list(c.values())
for i in range(len(c)):
    ans=ans*(1+vals[i])
print((ans-1)%(10**9+7))

Submission status: Accepted

Solution code:
n = int(input())
s = input()
t = list(set(s))
alpha = {}
for i in range(len(t)):
    alpha[t[i]] = s.count(t[i])

count = 1
for k, v in alpha.items():
    count *= (v + 1)
count -= 1
print(count%(10**9+7))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class Mod:
    def __init__(self, m):
        self.m = m
    
    def add(self, a, b):
        return (a + b ) % self.m

    def sub(self, a, b):
        return (a - b) % self.m
    
    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, self.pow(b, self.m-2))

    def pow(self, x, y):
        if y == 0: 
            return 1
        elif y == 1: 
            return x % self.m
        elif y % 2 == 0: 
            return self.pow(x, y//2)**2 % self.m
        else: 
            return self.pow(x, y//2)**2 * x % self.m



@mt
def slv(N, S):

    ans = 0
    CC = Counter()
    for c in S:
        CC[c] += 1
    
    m = Mod(10**9+7)

    cs = tuple(CC.values())
    @lru_cache(maxsize=None)
    def f(v):
        if not v:
            return 1
        
        c = v[0]
        v = v[1:]
        return m.add(m.mul(c, f(v)), f(v))
    return f(cs) - 1


def main():
    N = read_int()
    S = read_str()
    print(slv(N, S))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools
N = int(input())
S = input()
mod = 10**9 + 7
count = [1] * 26
for i in range(N):
    count[ord(S[i]) - 97] += 1
print((list(itertools.accumulate(count, lambda x, y: x * y % mod))[-1] - 1) %
      mod)

Submission status: Accepted

Solution code:
n=int(input())
S=input()
a='abcdefghijklmnopqrstuvwxyz'
ans=1
for i in range(26):
  cnt=S.count(a[i])
  ans=ans*(cnt+1)
ans-=1
ans=ans%(10**9+7)
print(int(ans))

Submission status: Accepted

Solution code:
# coding: utf-8
# 2^N-1が部分列の全通り
# その中で１つpこ同じ文字があれば、
# いいのは(p + 1)通り
# それに対して、全部空文字の１を引けばよい

MOD = 1000000007

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

l = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
     "k", "l", "m", "n", "o", "p", "q", "r", "s", "t",
     "u", "v", "w", "x", "y", "z"]
cnt = [0 for _ in range(26)]

for ch in S:
    for i in range(26):
        if ch == l[i]:
            cnt[i] += 1

ans = 1
for i in range(26):
    ans *= (cnt[i] + 1)
    ans = ans % MOD
    
print(ans - 1)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
a = [0] * 26
c = 1

for i in range(0, n):
    a[ord(s[i]) - ord("a")] += 1
    p = a[ord(s[i]) - ord("a")]
    c = c // p * (p + 1)
    
print((c - 1) % (10**9 + 7))

Submission status: Accepted

Solution code:
MOD = 1000000007
from collections import Counter
from functools import reduce

if __name__ == '__main__':
    n = int(input())
    s = input()
    counter = Counter(s)
    print(reduce(lambda x, y: (x * y) % MOD, (x + 1 for x in counter.values())) - 1)

Submission status: Accepted

Solution code:
n,s=open(0).read().split()
n=int(n)
ss=set(s)
mk=1
for x in ss:
    mk*=s.count(x)+1
print((mk-1)%1000000007)

Submission status: Accepted

Solution code:
import sys
from string import ascii_lowercase
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N = read_int()[0]
S = read_str()

res = 1
count = [0 for _ in range(26)]
alpha = ascii_lowercase

for i in range(N):
    st = alpha.find(S[i])
    count[st] += 1
    if count[st] > 1:
        res += res // count[st]
    else:
        res *= 2
res -= 1
big = 10**9 + 7
print(res % big)

Submission status: Accepted

Solution code:

n = int(input())

s = input()

x = []

for i in range(n):
    x.append(s[i])

import collections

clist = collections.Counter(x)

y = list(clist.values())

cnt = 1

for item in y:
    cnt = cnt * (item + 1)

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
listS = list(S)
set = list(set(listS))
countS=1
for i in range(len(set)):
  count = listS.count(set[i])
  countS *= count+1
countS -= 1
print(countS%(10**9+7))

Submission status: Accepted

Solution code:
from functools import reduce


def product(a, b):
    return a*b % (10**9+7)


N = int(input())
S = input()
count = 0
alpha = [1] * 26
left = 0
for s in S:
    #print(ord(s) - ord("a"), s)
    alpha[ord(s) - ord("a")] += 1
ans = reduce(product, alpha)
print(ans - 1)


"""
for i in range(len(S)):
    if alpha[ord(S[i]) - ord("a")] == -1:
        alpha[ord(S[i]) - ord("a")] == i
        continue
    else:
        count += sum_(i-left)
        count %= 10**9+7
        # 書き換える
        left = alpha[ord(S[i]) - ord("a")] + 1
        alpha[ord(S[i]) - ord("a")] = i
count += sum_((N - 1)-left)
count %= 10**9+7
print(count)
"""

Submission status: Accepted

Solution code:
n=int(input())
s=list(input())
A_to_Z=list("abcdefghijklmnopqrstuvwxyz")
p=10**9 +7
number=[]
ans=1
for i in A_to_Z:
  number.append(s.count(i)%p)
for i in number:
  ans= (ans*(i+1))%p
  ans= ans%p
print((ans-1)%p)

Submission status: Accepted

Solution code:
from collections import Counter

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


unique = 0
not_unique = 1
for v in Counter(S).values():
    if 1 == v:
        unique += 1
    else:
        not_unique *= v + 1

print((2 ** unique * not_unique - 1 ) % (10 ** 9 + 7))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000)
#def input():
#    return sys.stdin.readline()[:-1]

'''
n=int(input())
for i in range(n):
    a[i]=int(input())
    a[i],b[i]=map(int,input().split())
a=[int(x) for x in input().split()]
n,m=map(int,input.split())
from operator import itemgetter
a = [(1, "c", 1), (1, "b", 3), (2, "a", 0), (1, "a", 2)]
print(sorted(a))  # 0 番目の要素でソート、先頭の要素が同じなら 1 番目以降の要素も見る
print(sorted(a, key=itemgetter(0)))  # 0 番目の要素だけでソート
print(sorted(a, key=itemgetter(0, 2)))  # 0 番目と 2 番目の要素でソート
print(sorted(a, key=lambda x: x[0] * x[2]))  # 0 番目の要素 * 2 番目の要素でソート
print(sorted(a, reverse=True))  # 降順にソート
a.sort()  # 破壊的にソート、sorted() よりも高速
try: # エラーキャッチ list index out of range
    for i in range():
        k=b[i]
except IndexError as e:
    print(i)
'''

test_data1 = '''\
4
abcd
'''

test_data2 = '''\
3
baa
'''

test_data3 = '''\
5
abcab
'''
td_num=2

def GetTestData(index):
    if index==1:
        return test_data1
    if index==2:
        return test_data2
    if index==3:
        return test_data3
    
if False:
    with open("../test.txt", mode='w') as f:
        f.write(GetTestData(td_num))
    with open("../test.txt") as f:
        # Start Input code ---------------------------------------
        #n,m,c=map(int,f.readline().split())
        n=int(f.readline())
        s=str(f.readline())
        # End Input code ---------------------------------------
else:
    # Start Input code ---------------------------------------
    n=int(input())
    s=str(input())
    # End Input code ---------------------------------------
#print(n,s)
import string
al=string.ascii_lowercase
cnt=[]
for i in range(26):
    alc=s.count(al[i])
    #print(al[i])
    if alc!=0: cnt.append(alc)

#print(cnt)
m=len(cnt)
ans=1
mo=10**9 +7
counter=0
for i in range(m):
    ans*=(1+cnt[i]) % mo
ans-=1
'''
for i in range(1,2**m):
    counter+=1
    pat=1
    for j in range (m):
        #print(int((i % 2**(j+1)) / 2**j))
        ind=int((i % 2**(j+1)) / 2**j)
        pat*=max(1,cnt[j]*ind) % mo
        #print('ind,cnt[ind]=',ind,cnt[ind])
    ans+=pat
    #print(pat,ans)
    #print(bin(i))
'''
print(ans % mo)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
sosu = 10 ** 9 + 7
alpha = {}
for i in range(N):
    if S[i] in alpha.keys():
        alpha[S[i]].append(i)
    else:
        alpha[S[i]] = [i]
count = 1
for key in alpha.keys():
    count *= (len(alpha[key])+1) % sosu
count = (count + sosu -1 ) % sosu
print(count)

Submission status: Accepted

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

from collections import Counter
m = 10**9+7
sol = 1
for c in Counter(s).values():
    sol = (sol * (c + 1)) % m
sol = (sol - 1) % m
print(sol)

Submission status: Accepted

Solution code:
import collections
n=int(input())
l=list(input())
c=collections.Counter(l)
s=set(l)
ans=1
for i in s:
    ans*=(c[i]+1)
ans=ans-1
print(ans%(10**9+7))

Submission status: Accepted

Solution code:
n = int(input())
s = input().strip()
dics = {}
for _s in s:
  if _s in dics:
    dics[_s] += 1
  else:
    dics[_s] = 1

ans = 1
for v in dics.values():
  ans *= v + 1
ans -= 1
print(ans % 1000000007)

Submission status: Accepted

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

l = list(S)
MOD = 10**9 + 7

ans = 1
for c in range(ord('a'), ord('z') + 1):
    c = chr(c)
    ans *= (l.count(c) + 1)
    ans %= MOD
ans = (ans + MOD - 1) % MOD
print(ans)

Submission status: Accepted

Solution code:
import collections

_ = input()
s = input()

# s = "abcab"

c = collections.Counter(s)

ans = 1
big = 1000000000 + 7

for num in c.values():
    ans *= (num + 1)
    ans %= big

print((ans + big - 1) % big)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ch = [[],[]]
for i in S:
    if not i in ch[0]:
        ch[0].append(i)
        ch[1].append(1)
    else:
        idx = ch[0].index(i)
        ch[1][idx] += 1
ans = 1
for i in ch[1]:
    ans *= i + 1
ans -= 1
print(ans % (10**9 + 7))

Submission status: Accepted

Solution code:
_ = input()
s = input()

num = 1
for c in set(s):
	num = (num * (s.count(c) + 1)) % 1000000007
	
print(num-1)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
d = dict()
c = 0
ans = 1
for i in s:
    if i in d:
        d[i] += 1
    else:
        d[i] = 2
for i in d:
    ans *= d[i]
print((ans-1)%1000000007)

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
m=10**9+7
c=Counter(list(input()))
s=1
for i,j in c.most_common():
  s = (s * (j+1))%m
print(s-1)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
import collections
divisor = 10**9 + 7
dictvalues = collections.Counter(S).values()
ans = 1
for ele in dictvalues:
  ans *= ele + 1
  ans %= divisor
print(ans - 1)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
S = [i for i in input()]
NN = 10**9 + 7

values = list(Counter(S).values())
values = [i+1 for i in values]
X = 1
for i in values:
    X *= i

print((X-1) % NN)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
import collections
import numpy as np
divisor = 10**9 + 7
dictvalues = collections.Counter(S).values()
ans = 1
for ele in dictvalues:
  ans *= ele + 1
  ans %= divisor
print(ans - 1)

Submission status: Accepted

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

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

a = 1
for k in count:
  a = a * (1 + count[k])
a = a - 1
a = a % (10 ** 9 + 7)

print(a)

Submission status: Accepted

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

MOD = 1000000007  # type: int


def solve(N: int, S: str):
    abc = "abcdefghijklmnopqrstuvwxyz"
    ans = 2**N % MOD
    n = N
    pre = 1
    for c in abc:
        count = S.count(c)
        kaburi = ((2 ** count)-1-count)
        ans -= pre * kaburi * (2 ** (n - count))
        pre *= (1 + count) % MOD
        n -= count
        ans = ans % MOD
    print(int(ans-1))
    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a = int(input())  # 数値入力
str = input()
str = list(str)
str_unique = list(set(str))


ans = 1
for moji in str_unique:
    ans *= str.count(moji) + 1

print((ans-1) % 1000000007)

Submission status: Accepted

Solution code:
from collections import defaultdict

MOD = int(1e9) + 7


def main():
    N = int(input())
    S = input()
    cnt = defaultdict(lambda: 0)
    ans = 1
    for c in S:
        ans = ans + ans // (cnt[c]+1)
        cnt[c] += 1
    print(ans % MOD-1)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
mod = 10**9 + 7
n = int(input())
s = input()
ret = [0]*27
for c in s:
    i = ord(c) - ord("a")
    ret[i] += 1

DP = [[0]*28 for i in range(28)]
DP[0][0] = 1
for i in range(1,28):
    DP[i][0] = 1
    for j in range(1,28):
        DP[i][j] = (DP[i-1][j] + DP[i-1][j-1]*ret[i-1]) % mod
ans = 0
for i in DP[-1]:
    ans = (ans + i) % mod
print(ans -1)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
s = input()
l=[]
for c in s:
  l.append(c)
C=Counter(l)
ans=1
for v in C.values():
  ans = ans * (v + 1)
print((ans-1)%(10**9+7))

Submission status: Accepted

Solution code:
N = int(input())
S =list(input())
s = list(set(S))
m = 1
for i in range(len(s)):
    m *= (S.count(s[i]) + 1)
    
print((m - 1) % (10 ** 9 + 7))

Submission status: Accepted

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

s = [0] * 26
for c in S:
    s[ord(c) - 97] += 1
num = 1
for i in range(26):
    if s[i] > 0:
        num *= (s[i] + 1)
print((num - 1) % (10**9 + 7))

Submission status: Accepted

Solution code:
import collections
import numpy as np
aaa = 10 ** 9 + 7
N = int(input())
S =  [s for s in input()]
c = collections.Counter(S)
num = np.array(list(c.values()))
num = num + 1
count = 1
if N == 1:
    print(1)
else:
    for i in num:
        count *= i 
        count = count % aaa 
    print((count - 1))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 16 20:34:20 2019

@author: Yamazaki Kenichi
"""

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

abc = [chr(i) for i in range(97, 97+26)]
a = [0 for i in range(26)]
for i in range(26):
    a[i] = S.count(abc[i])

ans = 1 + a[0]
for i in range(1,26):
    ans += ans * a[i]
ans -= 1
print(ans%mod)

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
t = "abcdefghijklmnopqrstuvwxyz"
ans = 1

for i in range(26):
    ans *= (s.count(t[i]) + 1)

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

Submission status: Accepted

Solution code:
# A
N = int(input())
S = list(input())

LARGE = 10**9 + 7
count_dict = dict()
for i in range(N):
    s = S[i]
    if s in count_dict.keys():
        count_dict[s] += 1
    else:
        count_dict[s] = 1
        
res = 1
for c in count_dict.values():
    res = res*(c+1) % LARGE
    
print((res - 1) % LARGE)

Submission status: Accepted

Solution code:
n = int(input())
s = input()
lis = list(s)
sets=set(lis)
counts=[s.count(i) for i in sets]
ans = 1
for i in range(len(sets)):
    ans *= (counts[i]+1)
print((ans-1)%(10**9+7))

Submission status: Accepted

Solution code:
from itertools import product
N = int(input())
S = input()
MODN = int(10 ** 9 + 7)

'''
keys = list("abcdefghijklmnopqrstuvwxyz")
values = [0] * 26
D = dict(zip(keys, values))

print(D)
exit(0)
'''

D = {}

for ch in S:
  if ch in D:
    D[ch] += 1
  else:
    D[ch] = 1
    
V = list(D.values())
M = len(V)

ans = 1
for i in range(M):
  ans = ans * (V[i]+1) % MODN
  
print(ans - 1)

Submission status: Accepted

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


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


dic = {s: 0 for s in S}
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:
[n] = [int(i) for i in input().split()]
s = str(input())

char = {}

for c in s:
    if c not in char.keys():
        char[c] = 1
    else:
        char[c] = char[c] + 1

cnt = 1
for c in char.keys():
    cnt = (char[c] + 1) * cnt

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

Submission status: Accepted

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

dict = dict()
for a in s:
  if a in dict:
    dict[a] = dict[a] + 1
  else:
    dict[a] = 1
res = 1
for k in dict:
  res *= (dict[k] + 1)
res -= 1 
res %= (10**9 + 7) 
print(res)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
m = 10 ** 9 + 7
H = {}
for s in S:
  if not s in H:
    H[s] = 0
  H[s] += 1
#print(H)
ans = 1
for s, k in H.items():
  ans = (ans * (k + 1)) % m
print(ans-1)

Submission status: Accepted

Solution code:
from functools import reduce
import operator

mo = 10 ** 9 + 7

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

print((reduce(operator.mul, [s.count(c)+1 for c in set(s)], 1)-1) % mo)

Submission status: Accepted

Solution code:
def main():
    mod = 10 **9 +7
    n=int(input())
    s=input()
    alp = [0 for i in range(26)]
    for i in range(n):
        alp[ord(s[i])-97] += 1
    ans = 1
    for i in range(26):
        ans *= (alp[i]+1)


    print((ans-1)%mod)

main()

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
s = ns()

mod = 10**9+7

from collections import defaultdict

ans = 1
d = defaultdict(int)

for i in range(n):
	d[s[i]] += 1

for v in d.values():
	ans *= (v+1)
	ans = ans%mod

print(ans-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
hoge=input()
str=input()

dic={}
for alp in str:
    if alp in dic:
        dic[alp] += 1
    else:
        dic[alp] = 1

ans=1

for alp,num in dic.items():
    ans *= (num+1)

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

Submission status: Accepted

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

n = [1]*26
dict = {'a':0, 'b':1, 'c':2, 'd':3, 'e':4, 'f':5, 'g':6, 'h':7,
        'i':8, 'j':9, 'k':10, 'l':11, 'm':12, 'n':13, 'o':14,
        'p':15, 'q':16, 'r':17, 's':18, 't':19, 'u':20, 'v':21,
        'w':22, 'x':23, 'y':24, 'z':25}
for i in range(N):
	n[dict[S[i]]] += 1
ans = 1
# print(n)
for i in range(len(n)):
	ans *= n[i]
# print(ans)
mod = 10**9+7
print((ans-1)%mod)

Submission status: Accepted

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

memo = {}
for i in range(len(s)):
  if s[i] not in memo:
    memo[s[i]] = 1
  else:
    memo[s[i]] += 1
 
li = []
for i in memo.values() :
  li.append(i)

ans = 1
for i in li:
  ans = (ans*(i+1))%1000000007
print((ans-1)%1000000007)

Submission status: Accepted

Solution code:

def colorful_subsequence(N: int, S: str)->int:
    MOD = (10 ** 9) + 7
    cum = {}
    for c in S:
        cum.setdefault(c, 0)
        cum[c] += 1

    values = list(cum.values())
    count = 0
    for i, v in enumerate(values):
        temp = v
        for v in values[i+1:]:
            temp = (temp * (1 + v)) % MOD
        count = (count + temp) % MOD

    return count


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

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
s = input()

counter = Counter(s)

result = 1
for _, freq in counter.items():
    result *= (freq + 1)

print((result - 1) % 1000000007)

Submission status: Accepted

Solution code:
#w = "abcab"
n=input()
s = input()
counter = {}
for word in s:
    if word in counter:
        counter[word] += 1
    else:
        counter[word] = 1

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

Submission status: Accepted

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

word = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m"\
    ,"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y","z"]
count = [1] * 26
for i in range(N):
    count[word.index(S[i])] += 1
Total = 1
for c in count:
    Total *= c
    Total %= mod
print(Total - 1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = str(input())
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 = 1

for i in range(N):
	dic[S[i]] += 1

for key in list(dic.keys()):
	ans *= (dic[key]+1)

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

Submission status: Accepted

Solution code:
def int_raw():
    return int(raw_input())

def ss_raw():
    return raw_input().split()

def ints_raw():
    return map(int,ss_raw())

INF = 1<<29

DIV = 10**9+7

def make2d_arr(w,h,val =INF):
    return [[val]*w for i in xrange(h)]

def floyd_warshall(costs):
    N = len(costs)
    for k in xrange(N):
        for i in xrange(N):
            for j in xrange(N):
                costs[i][j]  = min(costs[i][j],costs[i][k]+costs[k][j])
    return costs

N = int_raw()
S = raw_input()

dp = {}

for s in S:
    if not (s in dp):
        dp[s] = 1
    else:
        dp[s]+=1

ans =1

for k,v in dp.items():
    ans*=(v+1)
    ans % DIV


print (ans-1+DIV)% DIV

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)

def main(n):
	s = input()
	a = [1] * 300
	ans = 1
	for i in s:
		a[ord(i)] += 1
	for i in a:
		ans = ans * i % 1000000007
	print(ans-1)
main(int(input()))

Submission status: Accepted

Solution code:
mod = int(10**9+7)
N = int(input())
S = input()
S = list(S)
alp = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
cnt = [S.count(c) for c in alp]
ans = 1
for i in range(len(cnt)):
    ans *= (cnt[i]+1) % mod
if ans == 0:
    print(mod-1)
else:
    print((ans-1) % mod)

Submission status: Accepted

Solution code:
mojisu=int(input())
moji=input()
mojilist=[]
zenlen=len(moji)
mojilist.append([moji[0], 1])
moji=moji[1:]
for i in range(len(moji)):
    molswi=0
    for mol in range(len(mojilist)):
        if mojilist[mol][0]==moji[i]:
            mojilist[mol][1]+=1
            molswi=1
        if mol==len(mojilist)-1 and molswi==0:
            mojilist.append([moji[i], 1])
#print(mojilist)

kazu=2**(mojisu)
amari=1
for mol in mojilist:
    amari=amari*(mol[1]+1)%(10**9+7)
print(amari-1)

Submission status: Accepted

Solution code:
nn = int(input())
s = str(input())
a = s.count('a')
b = s.count('b')
c = s.count('c')
d = s.count('d')
e = s.count('e')
f = s.count('f')
g = s.count('g')
h = s.count('h')
i = s.count('i')
j = s.count('j')
k = s.count('k')
l = s.count('l')
m = s.count('m')
n = s.count('n')
o = s.count('o')
p = s.count('p')
q = s.count('q')
r = s.count('r')
ss = s.count('s')
t = s.count('t')
u = s.count('u')
v = s.count('v')
w = s.count('w')
x = s.count('x')
y = s.count('y')
z = s.count('z')
print(((q+1)*(w+1)*(e+1)*(r+1)*(t+1)*(y+1)*(1+u)*(1+i)*(o+1)*(p+1)*(a+1)*(1+ss)*(1+d)*(1+f)*(1+g)*(1+h)*(1+j)*(1+k)*(1+l)*(1+z)*(x+1)*(c+1)*(1+v)*(b+1)*(n+1)*(m+1)-1)%(10**9+7))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!venv/bin/python

import math
import numpy as np
import random
import copy
import statistics 
import bisect
import heapq
from collections import defaultdict 

#A, B = [int(x) for x in input().split()]

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

num = defaultdict(int)

for s in S:
    num[s] += 1

cnt = 1
for s in num:
    cnt = cnt * (num[s] + 1)
    cnt = cnt % (10 ** 9 + 7)

cnt = cnt -1
cnt = cnt % (10 ** 9 + 7)

print (cnt)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 1
for c in range(ord('a'), ord('z') + 1):
	ans *= S.count(chr(c)) + 1
print((ans-1) % (10**9 + 7))

Submission status: Accepted

Solution code:
N = int(input())
S = input()
m = 10**9 + 7
nl = [0 for i in range(26)]
for s in S:
    nl[ord(s)-97] += 1
ans = 1
for i in range(26):
    if nl[i] == 0:
        continue
    else:
        ans *= nl[i] + 1
        ans = ans % m
print(ans-1)

Submission status: Accepted

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

m={}

for c in s:
    if c not in m:
        m[c]=1
    else:
        m[c]+=1
        
ans=1

for k in m.keys():
    ans*=(m[k]+1)

print((ans-1)%1000000007)

Submission status: Accepted

Solution code:
from collections import defaultdict
mod = 10**9+7
N = int(input())
S = input()
d = defaultdict(lambda:0)
for i in range(N):
    d[S[i]]+=1
ans = 1
for x in d:
    ans *= d[x]+1
    ans %= mod
ans -= 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = list(str(input()))
ch = list(set(S))
cal = []
for i in ch:
  cal.append(S.count(i))
ans = 1
for i in cal:
  ans *= i+1  
  ans = ans %(10**9+7)

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

Submission status: Accepted

Solution code:
import collections

mod = 1000000007

def add(a, b):
    return (a + b) % mod

def sub(a, b):
    return (a + mod - b) % mod

def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def power(x, y):
    if   y == 0     : return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y//2)**2 % mod
    else            : return power(x, y//2)**2 * x % mod

def div(a, b):
    return mul(a, power(b, mod-2))

def solve():
    N=int(input())
    S=list(input())
    c=collections.Counter(S)
    ans=1
    for k in c.keys():
        ans = mul(ans,c[k]+1)
    return sub(ans,1)

print(solve())

Submission status: Accepted

Solution code:
from collections import Counter
mod = 10 ** 9 + 7
n = int(input())
S = input()

ans = 1
for i in Counter(S).values():
    ans = ans * (i + 1) % mod

print(ans - 1)

Submission status: Accepted

Solution code:
INF = 1000000007

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

counts = {}
for s in S:
	counts[s] = counts.get(s, 0) + 1

pattern = 1
for count in counts.values():
	pattern *= 1 + count
	pattern %= INF
pattern -= 1
pattern %= INF

print(pattern)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
bet = list("abcdefghijklmnopqrstuvwxyz")
countlist = []
for i in range(len(bet)):
    if S.count(bet[i]) != 0:
        countlist.append(S.count(bet[i]))
result = 1

for j in range(len(countlist)):
    result *= countlist[j]+1
    result %= 10**9+7


print(result-1)

Submission status: Accepted

Solution code:
import collections
n = int(input())
s = input()
t = collections.Counter(s)
u = list(set(s))
cnt = 1
for i in range(len(u)):
    cnt *= t[u[i]]+1
print((cnt-1)%(10**9+7))

Submission status: Accepted

Solution code:
N = int(input())
S = input()
p = 10 ** 9 + 7
P = 1
for i in range(26):
  P *= S.count(chr(97 + i)) + 1
  P %= p
print(P - 1)

Submission status: Accepted

Solution code:
n = int(input())
s = [i for i in str(input())]
import collections
c = collections.Counter(s)
ans = 1
for v in c.values():
    ans = ans * (v+1)
ans = ans - 1
ans = ans % (10 ** 9 + 7)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
ans = 1
for i in range(97, 97+26):
    n = S.count(chr(i))
    ans = ans * (n+1)
print((ans -1)%(10**9+7))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
MOD = 1000000007

N = input()
S = input()

ans = 1
for i in range(26):
    c = chr(ord('a') + i)
    ans *= S.count(c) + 1
    ans %= MOD
    
print(ans-1)

Submission status: Accepted

Solution code:
dic ={}
N =input()
mod = 10**9 +7
for i in input():
    if i in dic.keys():
        dic[i] += 1
    else:
        dic[i] = 1
ans = 1
for i in dic.values():
    ans *= i+1
    ans = ans % mod
print(ans-1)

Submission status: Accepted

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

mod = 10 ** 9 + 7

import collections

c = collections.Counter(S)

result = 1
for key in c.keys():
    result *= (1 + c[key]) % mod

result = (result - 1) % mod

print(result)