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: Wrong Answer

Solution code:
def factorial(n):
    val = 1
    for i in range(2, n + 1):
        val *= i
    return val

def ncr(n, r):
    r = min(r, n - r)
    if r == 0:
        return 1
    if r == 1:
        return n
    numerator = [n - r + i + 1 for i in range(r)]
    denominator  = [i + 1 for i in range(r)]
    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1: 
            result *= numerator[k]
    return result

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

n = len(S)
n_unique = len(set(S))

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

sum = 0

for m in range(1, n_unique + 1):
    #sum += factorial(n) / (factorial(m) * factorial(n - m))
    sum += ncr(n, m)
    for v in dic.values():
        if v >= 2 and m > 1:
            if m > v:
                #sum -= factorial(m) / (factorial(v) * factorial(m - v))
                sum -= ncr(m, v)
            else:
                #sum -= factorial(v) / (factorial(m) * factorial(v - m))
                sum -= ncr(v, m)

print(int(sum) % (10 ** 9 + 7))

Submission status: Wrong Answer

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

ans = 2**N-1

tmp = []
x = set(S)
cnt = 0
for s in x:
  if(S.count(s) != 1):
    cnt += 1
    tmp.append(len(S[S.index(s):]))

for t in tmp:
  ans -= t*cnt
  cnt -= 1
print(ans%mod)

Submission status: Wrong Answer

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

x="abcdefghijklmnopqrstuvwxyz"

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

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

Submission status: Wrong Answer

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

ans = 2**N-1

tmp = []
x = set(S)
cnt = 0
for s in x:
  if(S.count(s) != 1):
    cnt += 1
    tmp.append(len(S[S.index(s):]))

for t in tmp:
  ans -= t*cnt
  cnt -= 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

mod=10**9+7
z=list(set(s))
m=len(z)
ans=pow(2,m,mod)-1
for i in range(m):
    
    ans+=(s.count(z[i])-1)*(pow(2,m-1,mod))%mod
print((ans)%mod)

Submission status: Wrong Answer

Solution code:
Num = int(input()) 
string = input() 


A= string.count('a')
B =string.count('b')
C =string.count('c')
D =string.count('d')
E =string.count('e')
F =string.count('f')
G =string.count('g')
H =string.count('h')
I =string.count('i')
J =string.count('j')
K =string.count('k')
L =string.count('l')
M =string.count('m')
N =string.count('n')
O =string.count('o')
P =string.count('p')
Q =string.count('q')
R =string.count('r')
S =string.count('s')
T =string.count('t')
U =string.count('u')
V =string.count('v')
W =string.count('w')
X =string.count('x')
Y =string.count('y')
Z =string.count('z')




answer = (1+A)*(1+B)*(1+C)*(1+D)*(1+E) % (10^9+7)
answer *= (1+F)*(1+G)*(1+H)*(1+I)*(1+J) % (10^9+7)
answer *= (1+K)*(1+L)*(1+M)*(1+N)*(1+O) % (10^9+7)
answer *= (1+P)*(1+Q)*(1+R)*(1+S)*(1+T) % (10^9+7)
answer*= (1+U)*(1+V)*(1+W)*(1+X)*(1+Y)*(1+Z) 

while answer > (10^9+7):
    answer = answer %(10^9+7)
print(answer -1)

Submission status: Wrong Answer

Solution code:
Num = int(input()) 
string = input() 


A= string.count('a')
B =string.count('b')
C =string.count('c')
D =string.count('d')
E =string.count('e')
F =string.count('f')
G =string.count('g')
H =string.count('h')
I =string.count('i')
J =string.count('j')
K =string.count('k')
L =string.count('l')
M =string.count('m')
N =string.count('n')
O =string.count('o')
P =string.count('p')
Q =string.count('q')
R =string.count('r')
S =string.count('s')
T =string.count('t')
U =string.count('u')
V =string.count('v')
W =string.count('w')
X =string.count('x')
Y =string.count('y')
Z =string.count('z')




answer = (1+A)*(1+B)*(1+C)*(1+D)*(1+E) % (10^9+7)
answer *= (1+F)*(1+G)*(1+H)*(1+I)*(1+J) % (10^9+7)
answer *= (1+K)*(1+L)*(1+M)*(1+N)*(1+O) % (10^9+7)
answer *= (1+P)*(1+Q)*(1+R)*(1+S)*(1+T) % (10^9+7)
answer*= (1+U)*(1+V)*(1+W)*(1+X)*(1+Y)*(1+Z) 

while answer < (10^9+7):
    answer = answer 
print(answer -1)

Submission status: Wrong Answer

Solution code:
import math
def combinations_count(n, r):
    if n<r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

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

    souwa += combinations_count(N, i)
    #print(souwa)

minus=0
kaburi=False
for i in range(2,N):
    tame=0
    for j in range(26):
        if v[j]>=2:
            if i<v[j]:
                tame+=math.factorial(v[j])
            tame+=combinations_count(i, v[j])
            #print(combinations_count(i, v[j]))

            kaburi=True
    if tame<=combinations_count(N, i):
        souwa-=tame
    else:
        souwa-=combinations_count(N, i)
if not kaburi:
    souwa+=1
print(souwa-minus)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = [s for s in input()]

array = []
for s in set(S):
    array.append(S.count(s))

len_array = len(array)

def recall(cur,t=1,total=0):
    if cur==len_array:
        return t
    for i in [array[cur],1]:
        total += recall(cur+1,t*i)
    return total

print(recall(0)-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=list(input())
ans=0
mod=10**9+7
z=list(set(s))
m=len(z)
for i in range(m):
    ans+=s.count(z[i])*(pow(2,m-1,mod))%mod
print((ans-m+1)%mod)

Submission status: Wrong Answer

Solution code:
def main31():
    import itertools
    import functools
    import operator
    prod = functools.partial(functools.reduce, operator.mul)

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

    S = sorted(S)  #  アルファベット順に並べ替え
    U = [0] * 26  #  ユニーク数数え上げ
    tmp = "0"
    count = 0
    u_count = 0
    for i in range(N):
        if i > 0:
            if tmp == S[i]:
                U[count] += 1
            else:
                tmp = S[i]
                count += 1
                U[count] += 1
        else:
            tmp = S[i]
            U[count] += 1

    for u in range(26):
        if U[u] != 0:
            u_count += 1

    U = sorted(U)

    for i in range(len(U)):
        if U[0] == 0:
            U.pop(0)

    count = 0

    for i in range(1, u_count+1):
        answer_list = list(itertools.combinations(U, i))
        count += sum(list(map(prod, answer_list)))
        
    if count < (10 ** 9 + 7):
        print(count % (10 ** 9 + 7))
    else:
        print(count)
main31()

Submission status: Wrong Answer

Solution code:
import itertools
def main():
    N = int(input())
    S = input()

    flags = dict_gen()
    counts = dict_gen()
    for i in S:
        flags[i] = 1
        counts[i] += 1

    counter = flag_counter(flags)
    print(counter)


def flag_counter(flags):
    alphabet = "abcdefghijklmnopqrstuvwxyz"
    counter = 0
    for i in alphabet:
        counter += flags[i]
    return counter    

def dict_gen():
    alphabet = "abcdefghijklmnopqrstuvwxyz"
    flags = {}
    for i in alphabet:
        flags[i] = 0
    return flags


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

result = 0
route = [x for _,x in collections.Counter(S).items()]

if len(route) == N:
    result = 2**len(route) - 1
else:
    for i in route:
        result += i**len(route)
print(result%(10**9+7))

Submission status: Wrong Answer

Solution code:
Num = int(input()) 
string = input() 


A= string.count('a')
B =string.count('b')
C =string.count('c')
D =string.count('d')
E =string.count('e')
F =string.count('f')
G =string.count('g')
H =string.count('h')
I =string.count('i')
J =string.count('j')
K =string.count('k')
L =string.count('l')
M =string.count('m')
N =string.count('n')
O =string.count('o')
P =string.count('p')
Q =string.count('q')
R =string.count('r')
S =string.count('s')
T =string.count('t')
U =string.count('u')
V =string.count('v')
W =string.count('w')
X =string.count('x')
Y =string.count('y')
Z =string.count('z')




answer = (1+A)*(1+B)*(1+C)*(1+D)*(1+E)*(1+F)*(1+G)*(1+H)*(1+I)*(1+J)*(1+K) \
        *(1+L)*(1+M)*(1+N)*(1+O)*(1+P)*(1+Q)*(1+R)*(1+S)*(1+T)*(1+U)*(1+V) \
        *(1+W)*(1+X)*(1+Y)*(1+Z) -1

print(answer % (10^9+7))

Submission status: Wrong Answer

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

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

print(ans - 1)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
N = int(input())
S = list(input().strip())
d = {}
for c in S:
  if c in d.keys():
    d[c] += 1
  else:
    d[c] = 1
ans = 0
for i in range(1, len(d.keys())+1):
  for com in combinations(d.keys(),i):
    tmp = 1
    for c in com:
      tmp *= d[c]
    ans += tmp
print(ans)

Submission status: Wrong Answer

Solution code:
Num = int(input()) 
string = input() 


A= string.count('a')
B =string.count('b')
C =string.count('c')
D =string.count('d')
E =string.count('e')
F =string.count('f')
G =string.count('g')
H =string.count('h')
I =string.count('i')
J =string.count('j')
K =string.count('k')
L =string.count('l')
M =string.count('m')
N =string.count('n')
O =string.count('o')
P =string.count('p')
Q =string.count('q')
R =string.count('r')
S =string.count('s')
T =string.count('t')
U =string.count('u')
V =string.count('v')
W =string.count('w')
X =string.count('x')
Y =string.count('y')
Z =string.count('z')




answer = (1+A)*(1+B)*(1+C)*(1+D)*(1+E)*(1+F)*(1+G)*(1+H)*(1+I)*(1+J)*(1+K) \
        *(1+L)*(1+M)*(1+N)*(1+O)*(1+P)*(1+Q)*(1+R)*(1+S)*(1+T)*(1+U)*(1+V) \
        *(1+W)*(1+X)*(1+Y)*(1+Z) -1

print(answer/(10^9+7))

Submission status: Wrong Answer

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

counter = Counter(s)
counts = 0
vals = np.array(list(counter.values()))
counts = np.prod(vals + 1) - 1
q, mod = divmod(counts, 1e9 + 7)
print(int(mod))

Submission status: Wrong Answer

Solution code:
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input())
S = str(input())
l = []
count = 0
for j in S:
    l.append(j)
l_unique = list(set(l))
for k in l_unique:
    c = l.count(k)
    if c > 1:
        count += 1
s = 0
s_a = 0

for i in range(N):
    s += combinations_count(N, i+1)
    if i <= N - 2:
        s_a += combinations_count(N-2, i) * count

if count <= 1:
    ans = s - s_a
else:
    add = (N-3) * combinations_count(count, 2)
    ans = s - s_a + add
print(ans % (10 ** 9 + 7))

Submission status: Wrong Answer

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

total = 2**n-1
k = 0
for i in string.ascii_lowercase:
    c = s.count(i)
    if c > 1:
        l = 2**(n-c)
        total -= l
        k += c - 1

if k > 1:
    total += k

print(total)

Submission status: Wrong Answer

Solution code:
import itertools

def is_uniqe(x):
    return len(x) == len(set(x))
n = int(input())
s = input()
count = 0
for i in range(n):
    for j in filter(lambda x:is_uniqe(x),itertools.combinations(s,i)):
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
_=input()
print('YES')
print('1 0 2 3')

Submission status: Wrong Answer

Solution code:
import numpy as np

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

print(func(alpha))

Submission status: Wrong Answer

Solution code:
Num = int(input()) 
string = input() 


A= string.count('a')
B =string.count('b')
C =string.count('c')
D =string.count('d')
E =string.count('e')
F =string.count('f')
G =string.count('g')
H =string.count('h')
I =string.count('i')
J =string.count('j')
K =string.count('k')
L =string.count('l')
M =string.count('m')
N =string.count('n')
O =string.count('o')
P =string.count('p')
Q =string.count('q')
R =string.count('r')
S =string.count('s')
T =string.count('t')
U =string.count('u')
V =string.count('v')
W =string.count('w')
X =string.count('x')
Y =string.count('y')
Z =string.count('z')




answer = (1+A)*(1+B)*(1+C)*(1+D)*(1+E)*(1+F)*(1+G)*(1+H)*(1+I)*(1+J)*(1+K) \
        *(1+L)*(1+M)*(1+N)*(1+O)*(1+P)*(1+Q)*(1+R)*(1+S)*(1+T)*(1+U)*(1+V) \
        *(1+W)*(1+X)*(1+Y)*(1+Z) -1

print(answer)

Submission status: Wrong Answer

Solution code:
import sys,itertools,math
input = sys.stdin.readline
N = int(input().strip())
S = input().strip()
le = [S.count(s) for s in set(S)]
cnt = 0
for i in range(len(le)):
    for s in itertools.combinations(le,i+1):
        t=1
        for tt in [x for x in s if x > 1]:
            t*=tt
        cnt+=t
print(cnt)

Submission status: Wrong Answer

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

mod = 10 ** 9 + 7


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


def power_mod(a, b):
    if b == 0:
        return 1
    elif b == 1:
        return a % mod
    elif b % 2:
        return (power_mod(a, ((b - 1) // 2)) ** 2) * a % mod
    else:
        return (power_mod(a, (b // 2)) ** 2) % mod


def div_mod(a, b):
    return mul_mod(a, power_mod(b, mod - 2))


def comb_mod(n, k):
    result = 1
    for i in range(k):
        result = mul_mod(result, n - i)
    for i in range(1, k + 1):
        result = div_mod(result, i)
    return result

kind = set(S)
each_char = []

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

length = len(kind)
over_stock = len(S) - len(kind)

count = 0
for i in range(over_stock + 1):
    count = (count + mul_mod(2 ** (length - i), comb_mod(over_stock, i))) % mod

print((count - 1) % mod)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

counter = Counter(s)
counts = 0
vals = np.array(list(counter.values()))
counts = np.prod(vals + 1) - 1
ans = int(counts % (1e9 + 7))
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
S = input()

sums = 0
def f(m, sub, nums):
  global n, S, sums
  for i in range(m, n):
    if i > nums[-1] and not S[i] in sub:
      sums += 1
      f(m+1, sub+[S[i]], nums+[i])
f(0, [], [-1])
print(sums%(10e9+7))

Submission status: Wrong Answer

Solution code:
import string
import re
n = int(input())
s = input()

total = 2**n-1
k = 0
for i in string.ascii_lowercase:
    c = s.count(i)
    if c > 1:
        l = 2**(n-c)
        total -= l
        k += 1

if k > 1:
    total += k

print(total)

Submission status: Wrong Answer

Solution code:
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
from operator import itemgetter
#以下てんぷら
def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")

def ip():
    return int(input())

rem = pow(10,9)+7

n = ip()                                     #入力整数1つ
#x,y,z= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[input() for i in range(x)]    #入力セット(整数改行あり)(2/2)

#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#こっから本文
s = set()
bs = []
cs = []
l = []
for i in range(n):
    l.append(a[i])
    if a[i] not in s:
        bs.append([1,a[i]])
        cs.append(a[i])
        s.add(a[i])
    else:
        p = cs.index(a[i])
        bs[p][0]+=1
bs.sort()
print(bs)
ans  = 1

f = []
for i in range(len(s)):
    a = [bs[i][1] for k in range(bs[i][0])]
    f.extend(a)
print(f)
if len(s) == n: print(pow(2,n)-1)
else :
    l.sort()
    for i in range(n-1):
        c = 0
        for k in range(i,n):
            if f[i] != f[k]:c+=1
        if c == 0: break
        else: ans *=c
    print((n+ans)%rem)

Submission status: Wrong Answer

Solution code:
import itertools
N = int(input())
S = input()
c = itertools.permutations(S)
com =map(lambda x:len(x)==len(set(x)), c)
print(sum(com)%(10**9+7))

Submission status: Wrong Answer

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

counter = Counter(s)
counts = 0
vals = np.array(list(counter.values()))
counts = np.prod(vals + 1) - 1
print(int(counts) % (1e9 + 7))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import numpy as np

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

print(func(alpha))

Submission status: Wrong Answer

Solution code:
import sys,itertools,math
input = sys.stdin.readline
N = int(input().strip())
S = input().strip()
le = [S.count(s) for s in set(S)]
cnt = 0
for i in range(len(le)):
    for s in itertools.combinations(le,i+1):
        t=1
        for tt in [x for x in s if x > 1]:
            t*=tt
        cnt+=t
print(cnt)

Submission status: Wrong Answer

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

counter = Counter(s)
counts = 0
vals = np.array(list(counter.values()))
counts = np.prod(vals + 1) - 1
print(int(counts % (1000000007)))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

def sub(s):
  if len(s) == 0:
    return 1
  n = s.count(s[0])
  return (n + 1) * sub(s.replace(s[0], ""))

print(sub(S) - 1)

Submission status: Wrong Answer

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

counter = Counter(s)
counts = 0
vals = np.array(list(counter.values()))
counts = np.prod(vals + 1) - 1
print(int(counts))

Submission status: Wrong Answer

Solution code:
def main31():
    import itertools
    import functools
    import operator
    prod = functools.partial(functools.reduce, operator.mul)
    
    N = int(input())
    S = list(input())  # len:N

    S = sorted(S)  #  アルファベット順に並べ替え
    U = [0] * 26  #  ユニーク数数え上げ
    tmp = "0"
    count = 0
    u_count = 0
    for i in range(N):
        if i > 0:
            if tmp == S[i]:
                U[count] += 1
            else:
                tmp = S[i]
                count += 1
                U[count] += 1
        else:
            tmp = S[i]
            U[count] += 1

    for u in range(26):
        if U[u] != 0:
            u_count += 1

    U = sorted(U)

    for i in range(len(U)):
        if U[0] == 0:
            U.pop(0)

    count = 0

    for i in range(1, u_count+1):
        answer_list = list(itertools.combinations(U, i))
        for a in answer_list:
            count += prod(a)

    print(count)
main31()

Submission status: Wrong Answer

Solution code:
import numpy as np
 
N=int(input())
S=input()
#list化
T=[0]*N
for i in range(N):
  T[i]=S[i]
T.sort()
 
U=np.ones(26)#26でいいけど余裕を見て30
j=0
for i in range(N):
  if i!=0:
    if T[i]!=T[i-1]:
      j=j+1
  U[j]=U[j]+1
 
res=1
for i in range(26):
  res=res*U[i]
res=(res -1) % (10**9 + 7)
print(int(res))

Submission status: Wrong Answer

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

counter = Counter(s)
counts = 0
vals = np.array(list(counter.values()))
counts = np.prod(vals + 1) - 1
print(int(counts % (1e9 + 7)))

Submission status: Wrong Answer

Solution code:
mod=1000000007

n=int(input())#整数
s=input()#文字列
s_list=list(s)#リスト

count_alphabet=[]
alphabet=["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"]
for j in range(len(alphabet)):
    number=count_alphabet.append(s_list.count(alphabet[j]))#個数の配列ができる

number=len(set(s_list))

if number>=10:
    exit()

total=0

for i in range(2**number):
    combination=[]
    multiply=1
    if i!=0:
        for j in range(number):
            if (i>>j)&1:
                combination.append(j)
        for j in combination:
            multiply=(multiply*count_alphabet[j])%mod

        total=(total+multiply)%mod


print((total)%mod)

Submission status: Wrong Answer

Solution code:
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N = int(input())
S = str(input())
l = []
count = 0
for j in S:
    l.append(j)
l_unique = list(set(l))
for k in l_unique:
    c = l.count(k)
    if c > 1:
        count += 1
s = 0
s_a = 0

for i in range(N):
    s += combinations_count(N, i+1)
for m in range(N-2+1):
    s_a += combinations_count(N-2, m) * count
if count <= 1:
    ans = s - s_a
else:
    add = (N-3) * combinations_count(count, 2)
    ans = s - s_a + add
print(ans % (10 ** 9 + 7))

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
S = input()
alpha = np.zeros(26)
Alp = [chr(i) for i in range(97, 97+26)]
for s in S:
  alpha[Alp.index(s)] += 1
alpha = alpha[np.nonzero(alpha)]

Size = alpha.shape[0]
#mae =alpha[:int(Size/2)]
#ushiro = alpha[int(Size/2):]
ans = 0
nisin = 2**Size
for i in range(1, nisin):
  lst = []
  for k in range(Size):
    lst.append(i%2)
    i //= 2 # 必須
  sub_array = alpha[np.array(lst)==1]
  ans += sub_array.prod()
print(int(ans))

Submission status: Wrong Answer

Solution code:
mod=1000000007

n=int(input())#整数
s=input()#文字列
s_list=list(s)#リスト

count_alphabet=[]
alphabet=["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"]
for j in range(len(alphabet)):
    number=count_alphabet.append(s_list.count(alphabet[j]))#個数の配列ができる

number=len(set(s_list))

total=0

for i in range(2**number):
    combination=[]
    multiply=1
    if i!=0:
        for j in range(number):
            if (i>>j)&1:
                combination.append(j)
        for j in combination:
            multiply=(multiply*count_alphabet[j])%mod

        total=(total+multiply)%mod


print((total)%mod)

Submission status: Wrong Answer

Solution code:
import re
n=int(input())
s=input()
x = 0
y=[]

for i in range(n):
	if s[i] in y:
		continue
	x = x + s.count(s[i])-1
	y.append(s[i])
	print(x)

a = x*(2**(n-2))
b = 2**n
ans = b-1-a%(10**9+7)
print(ans,n,x,a,b)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
c = 0
for i in range(N+1):
    for e in range(i,N+1):
        if len(S[i:e])==len(set(S[i:e])):
            c+=1
print(c%(10**9+7))

Submission status: Wrong Answer

Solution code:
import numpy as np
 
N=int(input())
S=input()
#list化
T=[0]*N
for i in range(N):
  T[i]=S[i]
T.sort()
 
U=np.ones(30)#26でいいけど余裕を見て30
j=0
for i in range(N):
  if i!=0:
    if T[i]!=T[i-1]:
      j=j+1
  U[j]=U[j]+1
 
res=1
for i in range(30):
  res=res*U[i]
res=(res -1) % (10**9 + 7)
print(res)

Submission status: Wrong Answer

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

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

print(counter-1)

Submission status: Wrong Answer

Solution code:
import itertools
n = input()
N = int(n[0])

st = input()
S = list(st)

count = N
for i, _ in enumerate(S, 2):
    for j in itertools.combinations(S, i):
        if len(j) == len(set(j)):
            count += 1
print(count % 1000000007)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = [s for s in input()]

array = []
for s in set(S):
    array.append(S.count(s))

len_array = len(array)

def recall(cur,l,total):
    if cur==len_array:
        _sum = 1
        for i in range(len_array):
            if l[i]:
                _sum *= array[i]*l[i]
        total += _sum
        return total
    for i in [1,0]:
        total = recall(cur+1,l+[i],total)
    return total

print(recall(0,[],0) -1)

Submission status: Wrong Answer

Solution code:
mod=1000000007

n=int(input())#整数
s=input()#文字列
s_list=list(s)#リスト

count_alphabet=[]
alphabet=["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"]
for j in range(len(alphabet)):
    number=count_alphabet.append(s_list.count(alphabet[j]))#個数の配列ができる

number=len(set(s_list))

total=0

for i in range(2**number):
    combination=[]
    multiply=1
    if i!=0:
        for j in range(number):
            if (i>>j)&1:
                combination.append(j)
        for j in combination:
            multiply=multiply*count_alphabet[j]

        total=(total+multiply)%mod


print((total)%mod)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = input()
iD = 10**9+7
aT={}
for s in S:
    if s in aT:
        aT[s]+=1
    else:
        aT[s]=1
iRes = (2**N)%iD - 1

iC2 = 0
for s in aT:
    iT = aT[s]
    if 1 < iT:
        iRes -= 2**(N-iT)%iD
        if 0 < iC2 :
            iRes += 2**(N-iC2-iT)%iD
        iC2 += iT
print((iRes+iD) % iD)

Submission status: Wrong Answer

Solution code:
import itertools
n,s,cnt = int(input()),input(),0
o = n-len(set(s))
for i in range(1,n+1):
    cnt = (cnt+len(list(itertools.combinations(s, i))))%(10**9+7)
if n==2:
    print(cnt-o*1)
elif n==3:
    print(cnt-o*2)
else:
    print(cnt-o*n)

Submission status: Wrong Answer

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

s = set(S)
cnt = 0
tmp = 0
for ss in s:
  if(S.count(ss) != 1):
    cnt += S.count(ss)
    tmp += 1
x = cnt**tmp
if(tmp == cnt == 0):
  x = 0
if(x != 0):
  print((2**N-x+1)%mod)
else:
  print((2**N-x-1)%mod)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from itertools import combinations
n = int(input())
s = input()
# s = 'aabbb'
counter = Counter(s)
counts = 0
vals = list(counter.values())
for x in range(1, len(counter) + 1):
    for pairs in combinations(vals, x):
        product = 1
        for v in pairs:
            product *= v
        counts += product
print(int(counts % (1e9 + 7)))

Submission status: Wrong Answer

Solution code:
import itertools
n = input()
N = int(n[0])

st = input()
S = list(st)

count = N
for i in range(N-1):
    for j in itertools.combinations(S, i+2):
        if len(j) == len(set(j)):
            count += 1
print(count % 1000000007)

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

Solution code:
import itertools
N = int(input())
S = input()
subsets = itertools.permutations(S)
c = 0
for i in subsets:
  if len(i)==len(set(i)):c+=1
print(c%(10**9+7))

Submission status: Wrong Answer

Solution code:
def main31():
    import itertools
    import numpy as np

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

    S = sorted(S)  #  アルファベット順に並べ替え
    U = [0] * 26  #  ユニーク数数え上げ
    tmp = "0"
    count = 0
    u_count = 0
    for i in range(N):
        if i > 0:
            if tmp == S[i]:
                U[count] += 1
            else:
                tmp = S[i]
                count += 1
                U[count] += 1
        else:
            tmp = S[i]
            U[count] += 1

    for u in range(26):
        if U[u] != 0:
            u_count += 1

    U = sorted(U)

    for i in range(len(U)):
        if U[0] == 0:
            U.pop(0)

    count = 0

    for i in range(1, u_count+1):
        answer_list = list(itertools.combinations(U, i))
        for j in range(len(answer_list)):
            answer = np.array(answer_list[j])
            count += np.prod(answer)

    print(count)

main31()

Submission status: Wrong Answer

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

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

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

print(res)