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:
from collections import Counter
mod = 10 ** 9 + 7
n = int(input())
s = input()
cnt = Counter(s)
ans = 1
for k in cnt.keys():
    ans *= (cnt[k] + 1) % mod
print((ans - 1) % mod)

Submission status: Accepted

Solution code:
from collections import Counter
from functools import reduce


def main():
    n = int(input())
    s = input()

    c = Counter(s)
    ans = reduce(lambda x, y: x * y, map(lambda x: x + 1, c.values())) - 1
    print(ans % (10**9+7))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from collections import defaultdict

n = ni()
s = ns()

dic = defaultdict(lambda: 1)
for i in range(n):
    dic[s[i]] += 1

ans = 1
for k, v in dic.items():
    ans *= v
    ans %= mod

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

Submission status: Accepted

Solution code:
import collections
N=int(input())
S=list(input())
l=[]
c=collections.Counter(S)
num=1
p=10**9+7
values=list(c.values())	#aのCollectionのvalue値のリスト(n_1こ、n_2こ…)
key=list(c.keys())	#先のvalue値に相当する要素のリスト(要素1,要素2,…)
for i in range(len(key)):
    l.append([key[i],values[i]])#lは[要素i,n_i]の情報を詰めたmatrix
#print(l)
for i in range(len(l)):
    num=num*(l[i][1]+1)
print((num-1)%p)

Submission status: Accepted

Solution code:
from collections import defaultdict as dd
n=int(input())
s=input()
mod=10**9+7

d=dd(int)
for ss in s:
    d[ss]+=1

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

Submission status: Accepted

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

x = 1
for v in s.values():
  x *= (v+1)
ans = x - 1
print(ans%mod)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import Counter
n = int(input())
a = Counter(input())
ans = 1
for v,c in a.items(): ans = ans * (1+c)%1000000007
print(ans-1)

Submission status: Accepted

Solution code:
# Problem A - Colorful Subsequence

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

# initialization
word_dic = {}
ans = 1
INF = 10**9 + 7

# word count
for s in S:
    if not s in word_dic:
        word_dic[s] = 1
    else:
        word_dic[s] += 1

# output
for w in word_dic:
    tmp = word_dic[w]
    ans = (ans * (tmp + 1))%INF
ans -= 1
print(ans % INF)

Submission status: Accepted

Solution code:
#set(s)種類の文字で作れる文字列を考える
#s=abcab なら 
# 2個のaのどちらを使うか＋使わない => 3
# 2個のbのどれを使うか　＋　使わない => 3
# 1個のcを使うか　＋　使わない　=> 2
#3*3*2 からどれも使わない場合を覗くので3*3*2-1
from collections import Counter
n = int(input())
s = input()
a = Counter(s).values()
ans = 1
for i in a:
    ans *= i+1
print((ans-1)%1000000007)

Submission status: Accepted

Solution code:
from collections import Counter

mod = 10 ** 9 + 7
n = int(input())
s = input()
d = Counter(s)
res = 1
for v in d.values():
    res = res * (v + 1) % mod

print(res - 1)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
mod = 10**9 + 7

n = int(input())
s = input().rstrip()

from collections import Counter

c = Counter(s)

n_ = len(c.keys())

ans = 1

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

ans -= 1

print(ans)

Submission status: Accepted

Solution code:
import sys
class alphabet: #Trueなら大文字
    def __init__(self, capitalize):
        self.num = dict()
        self.index = dict()
        self.abc = ["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"]
        if capitalize: 
            for i in range(26): self.abc[i] = self.abc[i].upper()
        for i, a in enumerate(self.abc):
            self.num[a] = i
            self.index[i] = a

def solve():
    input = sys.stdin.readline
    N = int(input())
    S = input().strip("\n")
    AB = alphabet(False)
    Count = [1] * 26
    for i in range(len(S)):
        Count[AB.num[S[i]]] += 1
    mod = 7 + 10 ** 9
    Ans = 1
    for i, n in enumerate(Count):
        Ans *= n
        Ans %= mod
    print((Ans - 1 + mod) % mod)


    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

mod = 10**9 +7

d = {}
for i in range(n):
    if s[i] not in d:
        d[s[i]] = 1
    else:
        d[s[i]] += 1

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

Submission status: Accepted

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

MOD = 10**9+7
class Mint:
    def __init__(self, value=0):
        self.value = value % MOD
        if self.value < 0: self.value += MOD

    @staticmethod
    def get_value(x): return x.value if isinstance(x, Mint) else x

    def inverse(self):
        a, b = self.value, MOD
        u, v = 1, 0
        while b:
            t = a // b
            b, a = a - t * b, b
            v, u = u - t * v, v
        if u < 0: u += MOD
        return u

    def __repr__(self): return str(self.value)
    def __eq__(self, other): return self.value == other.value
    def __neg__(self): return Mint(-self.value)
    def __hash__(self): return hash(self.value)
    def __bool__(self): return self.value != 0

    def __iadd__(self, other):
        self.value += Mint.get_value(other)
        if self.value >= MOD: self.value -= MOD
        return self
    def __add__(self, other):
        new_obj = Mint(self.value)
        new_obj += other
        return new_obj
    __radd__ = __add__

    def __isub__(self, other):
        self.value -= Mint.get_value(other)
        if self.value < 0: self.value += MOD
        return self
    def __sub__(self, other):
        new_obj = Mint(self.value)
        new_obj -= other
        return new_obj
    def __rsub__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj -= self
        return new_obj

    def __imul__(self, other):
        self.value = self.value * Mint.get_value(other) % MOD
        return self
    def __mul__(self, other):
        new_obj = Mint(self.value)
        new_obj *= other
        return new_obj
    __rmul__ = __mul__

    def __ifloordiv__(self, other):
        other = other if isinstance(other, Mint) else Mint(other)
        self *= other.inverse()
        return self
    def __floordiv__(self, other):
        new_obj = Mint(self.value)
        new_obj //= other
        return new_obj
    def __rfloordiv__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj //= self
        return new_obj

from collections import Counter
C = Counter(S)
ans = Mint(1)
for c in C.values():
    ans *= c + 1
print(ans - 1)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
s = input()
mod = 10 ** 9+7
a = Counter(s)
ans = 1

for v in a.values():
    ans *= (v+1)

print((ans-1)%mod)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    S = input()
    MOD = 10**9 + 7
    from collections import Counter
    c = Counter(S)
    ans = 1
    for v in c.values():
        ans *= (v+1)
        ans %= MOD
    print(ans-1)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

MOD = 10 ** 9 + 7

from collections import Counter

Scnt = Counter(S)

# 任意の文字列について、
# どれかを取り出す or どれも取り出さない

ans = 1
for cnt in Scnt.values():
    ans = (ans * (cnt + 1)) % MOD

ans -= 1

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = list(input())
mod = 10**9+7
alp = [0] * 26

for i in range(n):
    alp[ord(s[i]) - ord("a")] += 1

ans = 1
for c in alp:
    if (c != 0):
        ans *= (c+1)

print((ans - 1) % mod)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
s = input()
mod = 10 ** 9 + 7
cnt = 1
for i in Counter(list(s)).values():
    cnt *= (i + 1)
print((cnt - 1) % mod)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
s = input()
mod = 10**9 + 7

c = Counter(s)
ans = 1

for i in range(ord("a"), ord("z")+1):
    ans *= (c[chr(i)] + 1)

print((ans - 1)%mod)

Submission status: Accepted

Solution code:
import collections
n=int(input())
s=input()
c=collections.Counter(s)
mod=10**9+7

ans=1
for i,m in c.items():
    ans*=(m+1)
    ans%=mod
print(ans-1)

Submission status: Accepted

Solution code:
n = int(input())
s = str(input())
mod = 10**9+7
d = {}
for i in range(n):
    if s[i] not in d:
        d[s[i]] = 1
    else:
        d[s[i]] += 1
ans = 1
for v in d.values():
    ans *= (v+1)%mod
ans -= 1
print(ans%mod)

Submission status: Accepted

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

MOD = 1000000007

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

result = 1
for x in d.values():
    result *= x + 1
    result %= MOD
result += MOD - 1
result %= MOD

print(result)

Submission status: Accepted

Solution code:
from collections import Counter

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

cnter = Counter(S)
alpha = set(cnter)

ans = 1

for i in alpha:
    ans *= (cnter[i] + 1)

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

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
cnt_list = Counter(input())
mod = 10**9+7
total = 1

for v in cnt_list.values():
    total = (total*(v+1))%mod
print(total-1)

Submission status: Accepted

Solution code:
def main():
    length = int(input())
    word = input()
    count = {}
    for i in range(length):
        if word[i] in count:
            count[word[i]] += 1
        else:
            count[word[i]] = 2
    mod = 10 ** 9 + 7
    answer = 1
    for c in count.values():
        answer = (answer * c) % mod
    print(answer - 1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict

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

M = 10**9 + 7
count_dict = defaultdict(int)

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

ans = 1
for v in count_dict.values():
    ans *= (v + 1)
    ans %= M

print(ans - 1)

Submission status: Accepted

Solution code:
import collections
MOD=10**9+7
N=int(input())
S=list(input())
c = collections.Counter(S)

cnt=1
for i in c.values():
  cnt*=(i+1)
  
ans=cnt-1
print(ans%MOD)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
S = input()
char = set(list(S))
mod = 10**9+7
ans = 1
for c in char:
    ans *= S.count(c) + 1
    ans %= mod
ans -=1
print(ans)

Submission status: Accepted

Solution code:
mod = 10 ** 9 + 7

n = int(input())
s = input()
a = ord('a')

counter = {chr(a + i): 0 for i in range(26)}

for c in s:
  counter[c] += 1
  
result = 1
for v in counter.values():
  result = result * (v + 1) % mod
print(result - 1)

Submission status: Accepted

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

from collections import Counter
c = Counter()

for si in S:
    c[si] += 1

# print(c.values())

ans = 1
for n in c.values():
    ans *= n + 1
    ans = ans % (10 ** 9 + 7)

ans -= 1
print(ans)

Submission status: Accepted

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

from collections import Counter
c = Counter()

for si in S:
    c[si] += 1

# print(c.values())

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

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

Submission status: Accepted

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

from collections import Counter
freq = Counter(S)

div = int(1e9 + 7)
total = 1
for c in freq.keys():
  #print(c, freq[c])
  total = total * (freq[c] + 1) % div

ans = total - 1
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
S = input()

import collections
n_frq_dict = collections.defaultdict(int)
for s in S:
    n_frq_dict[s] += 1

mod=10**9+7
ret = 1
for frq in n_frq_dict.values():
    ret *= frq + 1
    ret %= mod
    
print(ret - 1)

Submission status: Accepted

Solution code:
mod = 10**9 + 7

def main():
    N = int(input())
    S = input()
    num_chars = 0
    A = {}
    for s in S:
        if s not in A:
            A[s] = 0
            num_chars += 1
        A[s] += 1
    # print(num_chars, A)
    B = [(a, A[a]) for a in A]

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

n = int(input())
s = list(input())
t = []
ans = 1
count= []

t = set(s)
t = list(t)

for i in range(len(t)):
    count.append(s.count(t[i]))

for j in range(len(count)):
    ans *= (count[j] + 1)

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
mod = 10**9+7
#文字ごとの累積和を取っておく
acc_char = [0 for i in range(26)]
ans = 0
for i in range(n):
    #今回の数字は使うの確定
    char = s[i]
    plus = 1
    for j in range(len(acc_char)):
        if (ord(char) - ord('a')) != j:
            plus *= acc_char[j] + 1
    ans += plus
    ans %= mod
    acc_char[ord(char) - ord('a')] += 1
print(ans%mod)

Submission status: Accepted

Solution code:
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))

import string

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

cnt = [0 for i in range(26)]

for i in range(N):
    mm = ord(S[i])-97
    cnt[mm] += 1

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

Submission status: Accepted

Solution code:
a=int(input())
b=input()
b=list(b)
c=[0]*26
ans=0
t=0
for i in range(a):
	c[ord(b[i])-97]=c[ord(b[i])-97]+1

for j in range(26):
	t=c[j]
	for k in range(j+1,26):
		t=t*(c[k]+1)
	ans=ans+t
print(ans%(10**9+7))

Submission status: Accepted

Solution code:
from collections import Counter

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

n = Counter(S)
ans = 1
for i, j in n.items():
  ans *= (j+1)
print((ans-1)%mod)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
m = 10 ** 9 + 7
S_li = list(set(S))
ans = 1
for sl in S_li:
    ans *= S.count(sl) + 1
print((ans - 1) % m)

Submission status: Accepted

Solution code:
from string import ascii_lowercase
from collections import defaultdict


N = int(input())
S = input().strip()
MOD = 10 ** 9 + 7


c = defaultdict(int)
for i in range(N):
    c[S[i]] += 1

ans = 1
for x in ascii_lowercase:
    ans *= c[x] + 1
    ans %= MOD
ans -= 1
ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
MOD=10**9+7
x=dict()
for s in S:
    x[s]=x.get(s,0)+1
retval=1
for c in x:
    retval*=(x[c]+1)
    retval=retval%MOD
print((retval-1)%MOD)

Submission status: Accepted

Solution code:
N=int(input())
S=input()
MOD=10**9+7
x=dict()
for s in S:
    x[s]=x.get(s,0)+1
retval=1
for c in x:
    retval*=(x[c]+1)
print((retval-1)%MOD)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
s_set=set(list(s))
t=len(s_set)
cnt=1

for s1 in s_set:
	cnt*=(1+s.count(s1))
	
print((cnt-1)%(10**9+7))

Submission status: Accepted

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

A = [0]*26
for e in S:
    A[ord(e)-97] += 1

ans = 1
for e in A:
    ans *= e+1
    ans %= MOD
print((ans-1)%MOD)

Submission status: Accepted

Solution code:
#解説参照済み
n=int(input())
a=list(input())
from collections import defaultdict
d=defaultdict(int)
for i in a:
    d[i]+=1
cnt=[]
for i in d.values():
    cnt.append(i+1)
ans=1
mod=10**9+7
for i in cnt:
    ans*=i
    ans%=mod
print(ans-1)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
S = input()
count = Counter(S)
mod = 10**9+7
ans = 1
for k, v in count.items():
    ans = ans * (v+1) % mod
print(ans-1)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    S = input()
    MOD = 10**9 + 7
    ans = 1
    from collections import Counter
    c = Counter(S)
    for v in c.values():
        ans *= (v+1)
        ans %= MOD
    print(ans - 1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
S=input()
MOD=10**9+7
ALP='qazwsxcedrfvtgbyhnujmikolp'
cnt={}
for s in ALP:
  cnt[s]=0
for s in S:
  cnt[s]+=1
ans=1
for s in ALP:
  ans*=cnt[s]+1
ans-=1
print(ans%MOD)

Submission status: Accepted

Solution code:
MOD = 10 ** 9 + 7
N = int(input())
from collections import Counter
c = Counter(input())

x = 1
for v in c.values():
  x *= (v + 1)

ans = x - 1
print(ans%MOD)

Submission status: Accepted

Solution code:
def solve():
    n = int(input())
    s = input()
    ans = 1
    mod = 1000000007
    for i in range(26):
        c = chr(ord('a') + i)
        a = s.count(c)
        a = (a + 1) % mod
        ans = (ans * a) % mod

    ans = (ans + mod - 1) % mod
    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
import sys
from collections import Counter
def main():
    input = sys.stdin.readline
    N = int(input())
    S = input().rstrip()

    C = Counter(S)
    ans = Mint(1)
    for a in C.values():
        ans *= a+1
    print(ans - 1)

class Mint:
    def __init__(self, value=0, mod=10**9+7):
        self.value = ((value % mod) + mod) % mod
        self.mod = mod

    @staticmethod
    def get_value(x): return x.value if isinstance(x, Mint) else x

    def inverse(self):
        a, b = self.value, self.mod
        u, v = 1, 0
        while b:
            t = a // b
            b, a = a - t * b, b
            v, u = u - t * v, v
        return (u + self.mod) % self.mod

    def __repr__(self): return str(self.value)
    def __eq__(self, other): return self.value == other.val
    def __neg__(self): return Mint(-self.value, self.mod)
    def __hash__(self): return hash(self.value)
    def __bool__(self): return self.value != 0

    def __iadd__(self, other):
        self.value = (self.value + Mint.get_value(other)) % self.mod
        return self
    def __add__(self, other):
        new_obj = Mint(self.value, self.mod)
        new_obj += other
        return new_obj
    __radd__ = __add__

    def __isub__(self, other):
        self.value = (self.value - Mint.get_value(other) + self.mod) % self.mod
        return self
    def __sub__(self, other):
        new_obj = Mint(self.value, self.mod)
        new_obj -= other
        return new_obj
    def __rsub__(self, other):
        new_obj = Mint(Mint.get_value(other), self.mod)
        new_obj -= self
        return new_obj

    def __imul__(self, other):
        self.value = self.value * Mint.get_value(other) % self.mod
        return self
    def __mul__(self, other):
        new_obj = Mint(self.value, self.mod)
        new_obj *= other
        return new_obj
    __rmul__ = __mul__

    def __ifloordiv__(self, other):
        other = other if isinstance(other, Mint) else Mint(other, self.mod)
        self *= other.inverse
        return self
    def __floordiv__(self, other):
        new_obj = Mint(self.value, self.mod)
        new_obj //= other
        return new_obj
    def __rfloordiv__(self, other):
        new_obj = Mint(Mint.get_value(other), self.mod)
        new_obj //= self
        return new_obj

if __name__ == '__main__':
    main()

Submission status: Accepted

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

MOD = 10**9 + 7

from collections import Counter

Scnt = Counter(list(S))

ans = 1
for cnt in Scnt.values():
    ans = (ans * (cnt + 1)) % MOD

ans -= 1

print(ans % MOD)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
from collections import Counter
ctr = Counter(S)
MOD = 10**9+7
ans = 1
for v in ctr.values():
    ans *= (v+1)
ans -= 1
print(ans%MOD)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
s = input()
c = Counter(s)
res = 1
for key in list(c):
    res *= c[key]+1
    res %= mod
print(res-1)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
s = input()
c = Counter(s)
res = 1
for key in list(c):
    res *= c[key]+1
    res %= mod
print((res-1)%mod)

Submission status: Accepted

Solution code:
def main():
    MOD = 10**9 + 7
    n = int(input())
    s = input().rstrip()
    alp = [1]*26
    ans = 0
    for c in s:
        p = ord(c) - ord("a")
        alp[p] += 1
        x = 1
        for i in range(26):
            if i == p:
                continue
            x *= alp[i]
            x %= MOD
        ans += x
        ans %= MOD
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

ans=0
log=[1]*26
for item in S:
    item=ord(item)-97
    log[item]+=1

ans=1
for item in log:
    ans*=max(item,1)

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

Submission status: Accepted

Solution code:
n = int(input())
s = input()
import collections
c = collections.Counter(s)
res = 1
m = 10 ** 9 + 7
for k in c:
    res *= (c[k] + 1)
    res %= m
res -= 1
res %= m
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
s = input()
c = Counter(list(s))
total = 1
for v in c.values():
  total = (total * (v + 1)) % 1000000007
print(total - 1)

Submission status: Accepted

Solution code:
from collections import Counter

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

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

Submission status: Accepted

Solution code:
n=int(input())
s=input()
t=sorted(s)
t.append("X")
cnt=1
ans=1
for i in range(n):
    if t[i]==t[i+1]:
        cnt+=1
    else:
        ans*=(cnt+1)
        cnt=1
print((ans-1)%(10**9+7))

Submission status: Accepted

Solution code:
from collections import Counter
MOD = 1000000007
N = int(input())
S = input()

count = Counter(S)
ans = 1
for k, v in count.items():
    ans *= (v+1)
    ans %= MOD
print((ans - 1) % MOD)

Submission status: Accepted

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

s = sorted(s)
s += '#'
count = 1
ans = 1
for i in range(1, n+1):
    if s[i] == s[i-1]:
        count += 1
    else:
        ans = (ans * (count+1)) % mod
        count = 1
print(ans-1)

Submission status: Accepted

Solution code:
MOD=10**9+7
class Fp(int):
    def __new__(self,x=0):return super().__new__(self,x%MOD)
    def inv(self):return self.__class__(super().__pow__(MOD-2,MOD))
    def __add__(self,value):return self.__class__(super().__add__(value))
    def __sub__(self,value):return self.__class__(super().__sub__(value))
    def __mul__(self,value):return self.__class__(super().__mul__(value))
    def __floordiv__(self,value):return self.__class__(self*self.__class__(value).inv())
    def __pow__(self,value):return self.__class__(super().__pow__(value%(MOD-1), MOD))
    __radd__=__add__
    __rmul__=__mul__
    def __rsub__(self,value):return self.__class__(-super().__sub__(value))
    def __rfloordiv__(self,value):return self.__class__(self.inv()*value)
    def __iadd__(self,value):self=self+value;return self
    def __isub__(self,value):self=self-value;return self
    def __imul__(self,value):self=self*value;return self
    def __ifloordiv__(self,value):self=self //value;return self
    def __ipow__(self,value):self=self**value;return self
    def __neg__(self):return self.__class__(super().__neg__())

from collections import Counter
def main():
    N=int(input())
    S=input()
    C=Counter(S)
    ans=Fp(1)
    for v in C.values():
        ans*=v+1
    print(ans-1)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

d = {}
for x in s:
    if x in d:
        d[x] += 1
    else:
        d[x] = 1

ans = 1
for x in d.values():
    ans *= x+1

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

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
s = input()

mod = 10**9+7

scnt = Counter(s).most_common()
ans = 1

for i in range(len(scnt)):
    ans = ans*(scnt[i][1]+1)%mod
ans = (ans - 1 + mod)%mod
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
s=list(str(input()))
s.sort()
cnt=2
ans=1
for i in range(n-1):
    if s[i]==s[i+1]:
        cnt+=1
    else:
        ans*=cnt
        cnt=2
ans*=cnt
print((ans-1)%(10**9+7))

Submission status: Accepted

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

MOD = 10**9 + 7

from collections import Counter

ctr = Counter(s)

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

Submission status: Accepted

Solution code:
from itertools import groupby as gb
n,s=open(0)
n=int(n)
s=sorted(s[:-1])

ans=1
mod=10**9+7
for i,x in gb(s):
  ans=ans*(len(list(x))+1)%mod
print(ans-1)

Submission status: Accepted

Solution code:
from itertools import groupby as gb
n=int(input())
s=sorted(input())
ans=1
mod=10**9+7
for i,x in gb(s):
  ans=ans*(len(list(x))+1)%mod
print(ans-1)

Submission status: Accepted

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

C = collections.Counter(S)
ans = 1

for value in C.values():
    ans *= (value + 1)
print((ans-1)%mod)

Submission status: Accepted

Solution code:
import collections
MOD = 10 ** 9 + 7
N = int(input())
P = input()
C = collections.Counter(P)
ans = 1
for v in C.values():
	ans *= (v + 1)
print((ans - 1)%MOD)

Submission status: Accepted

Solution code:
def main():
    from collections import Counter

    MOD = 10 ** 9 + 7

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

    ctr = Counter(S)

    ret = 1
    for count in ctr.values():
        ret = (ret * (count + 1)) % MOD
    print(ret - 1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# A - Colorful Subsequence
from collections import defaultdict as dd
n=int(input())
s=input()
mod=10**9+7
ans=1
c=dd(int)

for ss in s:
    c[ord(ss)-97]+=1

for i in range(26):
    ans*=c[i]+1
    ans%=mod

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

Submission status: Accepted

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

t = [0 for i in range(26)]

for i in range(n):
    t[ord(s[i]) - ord("a")] += 1

ans = 1
for i in range(26):
    if t[i] == 0:
        continue
    if t[i] == 1:
        ans *= 2
    elif t[i] > 1:
        ans *= t[i] + 1

print((ans-1) % MOD)

Submission status: Accepted

Solution code:
from sys import stdin
import string
from itertools import groupby

n = int(stdin.readline().rstrip())
s = list(stdin.readline().rstrip())
s.sort()
lin = []
for key, value in groupby(s):
    lin.append(len(list(value)))
point = 1
for i in lin:
    point *= i+1
    point %= 10**9+7
print(point-1)

Submission status: Accepted

Solution code:
import collections
n,s=int(input()),list(input())
l=(collections.Counter(s)).values()
ans=1
for x in l:
  ans*=(x+1)
print((ans-1)%(10**9+7))

Submission status: Accepted

Solution code:
n = int(input())
sl = list(input())

from collections import defaultdict
dic = defaultdict(int)

for s in sl:
    dic[s] += 1

ans = 1
for i in dic.values():
    ans *= i + 1
    ans %= 10**9 + 7

print(ans -1)

Submission status: Accepted

Solution code:
from collections import Counter
lim=10**9+7
N=int(input())
S=input()
d=Counter(S)
ans = 1
for s in d.keys():
    ans = (ans*(d[s]+1))%lim
    #print(ans)
print(ans-1)

Submission status: Accepted

Solution code:
N = int(input())
S = input()
MOD = 10**9+7
d = {}
for i in range(N):
  if S[i] in d:
    d[S[i]].append(i)
  else:
    d[S[i]] = [i]
ans = 1
for k,v in d.items():
  ans *= len(v)+1
  ans %= MOD
print((ans-1)%MOD)

Submission status: Accepted

Solution code:
p = 10**9+7
N = int(input())
S = input().strip()
C = {chr(i):[] for i in range(97,123)}
for i in range(N):
    C[S[i]].append(i)
cnt = 1
for j in range(97,123):
    cnt = (cnt*(1+len(C[chr(j)])))%p
print((cnt-1)%p)

Submission status: Accepted

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

for i in range(n):
	car[ord(s[i])-97] += 1

ans = 1
for i in range(26):
	if car[i] == 0:
		continue
	else:
		ans *= (car[i]+1)
		ans %= mod

print(ans - 1)

Submission status: Accepted

Solution code:
mod = 10**9 + 7
N = int(input())
S = list(input())
al = [chr(ord("a") + i ) for i in range(26)]
cntAl = [ S.count(chr(ord("a") + i )) for i in range(26)]
ans = 1
for a in cntAl:
    if a != 0:ans *= (a+1)%mod
print((ans-1)%mod)

Submission status: Accepted

Solution code:
import collections
N=int(input())
S=[i[1] for i in collections.Counter(list(input())).most_common()]
mod=10**9+7
count=0
ruiseki=0
for i in S:
    count+=i + count * i
    count%=mod
print(count)