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 a s.       Sample Input 3 5
abcab      Sample Output 3 17

Solution (Python):
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))

Solution (Python):



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



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

Solution (Python):
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))

Solution (Python):
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()

Solution (Python):
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))

Solution (Python):
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))

Solution (Python):
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)

Solution (Python):
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))

Solution (Python):
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))

Solution (Python):
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))

Solution (Python):
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))

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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():
    
    ans = (len(place) + 1) * ans


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

Solution (Python):
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))

Solution (Python):
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))

Solution (Python):




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

Solution (Python):
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))

Solution (Python):
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)

Solution (Python):
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))

Solution (Python):

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

Solution (Python):
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)

Solution (Python):
from collections import Counter
n = int(input())
s = input()
mod = 10**9 + 7
q  =[c for c in s]
p = Counter(q)

ans = 1
for key in p:
    
    ans *= (p[key]+1)
    ans%= mod

print(ans-1)

Solution (Python):
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))

Solution (Python):


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)

Solution (Python):
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))

Solution (Python):
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))

Solution (Python):

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

Solution (Python):
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)

Solution (Python):
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))

Solution (Python):






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)

Solution (Python):
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))

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
from collections import Counter
c=Counter()
N=int(input())
c=Counter(input())
ans=1
for i,b in c.items():
    if b>1:
        ans*=(b+1)
    else:
        ans*=2
print(int((ans-1)%(10**9+7)))

Solution (Python):
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)

Solution (Python):

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)

Solution (Python):
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))

Solution (Python):
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:
    
    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)
"""

Solution (Python):
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)

Solution (Python):
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))

Solution (Python):
import sys
sys.setrecursionlimit(1000000)



'''
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))  
print(sorted(a, key=itemgetter(0)))  
print(sorted(a, key=itemgetter(0, 2)))  
print(sorted(a, key=lambda x: x[0] * x[2]))  
print(sorted(a, reverse=True))  
a.sort()  
try: 
    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:
        
        
        n=int(f.readline())
        s=str(f.readline())
        
else:
    
    n=int(input())
    s=str(input())
    

import string
al=string.ascii_lowercase
cnt=[]
for i in range(26):
    alc=s.count(al[i])
    
    if alc!=0: cnt.append(alc)


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):
        
        ind=int((i % 2**(j+1)) / 2**j)
        pat*=max(1,cnt[j]*ind) % mo
        
    ans+=pat
    
    
'''
print(ans % mo)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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))

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
import collections

_ = input()
s = input()



c = collections.Counter(s)

ans = 1
big = 1000000000 + 7

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

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

Solution (Python):
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))

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

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

Solution (Python):
import collections

TEISUU = 1000000007

S = input()
N = input()
c = collections.Counter(N)
lis = list(c.values())
ans = 1
for count in lis:
    ans *= int(count + 1)
    
ans -= 1
print(ans % TEISUU)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):

import sys

MOD = 1000000007  


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



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    S = next(tokens)  
    solve(N, S)


if __name__ == '__main__':
    main()

Solution (Python):
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)

Solution (Python):
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()

Solution (Python):
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)

Solution (Python):
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))

Solution (Python):
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))

Solution (Python):
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))

Solution (Python):
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))

Solution (Python):

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

Solution (Python):
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))

Solution (Python):

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)

Solution (Python):
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))

Solution (Python):
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)

Solution (Python):
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():
    
    ans *= count + 1


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

Solution (Python):
[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))

Solution (Python):
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)

Solution (Python):
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

ans = 1
for s, k in H.items():
  ans = (ans * (k + 1)) % m
print(ans-1)

Solution (Python):
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)

Solution (Python):
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()

Solution (Python):
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)

Solution (Python):
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))

Solution (Python):
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))

Solution (Python):
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

ans = 1
for s, k in H.items():
  ans = (ans * (k + 1)) % m
print(ans-1)

Solution (Python):
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

for i in range(len(n)):
	ans *= n[i]

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

Solution (Python):
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)

Solution (Python):

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)

Solution (Python):
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)

Solution (Python):

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

Solution (Python):
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)

Solution (Python):
from collections import Counter
MOD = 10**9 + 7
n = int(input())
s = list(input())
c = Counter(s)

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

Solution (Python):
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)))

Solution (Python):
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

Solution (Python):
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()))