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:
from collections import Counter
from itertools import combinations
import numpy as np
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):
        counts += np.prod(pairs)
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):
    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:
n=input()
s=list(input())
    
num_s=[]
s_sub=list(set(s))
sum=1
for i in range(len(s_sub)):
    num_s.append(s.count(s_sub[i]))
    sum*=(num_s[i]+1)
    
print(sum-1)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import bisect as bs
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 *= l_dic[key] - bs.bisect_right(dic[key], i) + 1
        sub %= 1000000007
    ans += sub
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import bisect as bs
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])
    ans += l_dic[key]
for i in range(L):
    sub = 1
    for key in dic:
        if key == S[i]:
            continue
        sub *= l_dic[key] - bs.bisect_right(dic[key], i) + 1
        sub %= 1000000007
    ans += sub - 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

ans = 2 ** N -1
cnt = 0
for a in alphabet:
  if a >= 2:
    for i in range(2, a + 1):
      ans -= 2 ** (N - i) * (a - i + 1) - cnt
      cnt += 2
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

mod = 1000000007

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
from itertools import combinations
import numpy as np
n = int(input())
s = input()
counter = Counter(s)
counts = 0
for x in range(1, len(counter) + 1):
    for pairs in combinations(counter, x):
        values = np.array([counter[index] for index in pairs])
        counts += np.prod(values)
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):
        if len(j) == len(set(j)):
            count += 1
print(count % 1000000007)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(100000)

n = int(input())
s = input()
s_set = set(s)
S = []
for i in s_set:
    S.append(s.count(i))

def cal(n, S):
    if n == 1:
        ans = sum(S)
        ans %= 10 ** 9 +7
        return ans
    if n == 2:
        ans = 0
        for i in range(len(S) - 1):
            for j in range(i+1, len(S)):
                ans += S[i] * S[j]
            ans %= 10 ** 9 + 7
        return ans
    else:
        ans = 0
        for i in range(len(S) - n + 1):
            ans += S[i] * cal(n-1, S[i+1:])
            #ans %= 10 ** 9 +7
        return ans

ans = 0
for i in range(n):
    ans += cal(i+1, S)

print(ans)

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce

N = int(input())
S = input()
clean_set = [i for i in S]
clean_set = set(clean_set)
counts = []
k = len(clean_set)
if k == N:
    print(2**N-1)
else:
    for i in clean_set:
        counts.append(S.count(i))
        ans = 0
    for i in range(k):
        a = 0
        for j in range(i+1):
            a += reduce(mul, counts[i-j:i+1])
        ans += a * (N - sum(counts[:i+1]))
    print(ans+N)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
l = list(input())
cl = collections.Counter(l)
d = dict(cl)
l = list(cl)
s = len(l)
lo=[]
ans = 0
dl = 0
for i in range(s):
    if d[l[i]]!=1:
        ans += ((2**s-2**(s-1))*d[l[i]]+1)
        dl+=1
    else:
        lo.append(l[i])
leo = len(lo)
m = max(0,dl)
ans -= (2**leo-1)*(m-1)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(100000)

n = int(input())
s = input()
s_set = set(s)
S = []
for i in s_set:
    S.append(s.count(i))

def cal(n, S):
    if n == 1:
        return sum(S)
    if n == 2:
        ans = 0
        for i in range(len(S) - 1):
            for j in range(i+1, len(S)):
                ans += S[i] * S[j]
            ans %= 10 ** 9 + 7
        return ans
    else:
        ans = 0
        for i in range(len(S) - n + 1):
            ans += S[i] * cal(n-1, S[i+1:])
            ans %= 10 ** 9 +7
        return ans

ans = 0
for i in range(n):
    ans += cal(i+1, S)

print(ans)

Submission status: Wrong Answer

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

dic = {"":1}
ans = 0

for c in S:
    dic_new = {}         
    for k in dic:    
        if not(c in k):    
            ans += dic[k]    
            ans %= 10**9 + 7    
            dic_new[k+c] = (dic_new.get(k+c,0)+1) % (10**9+7)
    for k in dic_new:    
        dic[k] = (dic.get(k,0)+dic_new[k])%(10**9+7)
print(ans)

Submission status: Wrong Answer

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

A = list(alphabets.keys())
for i in range(1 << len(A)):
    output = []
    c = 1
    for j in range(len(A)):
        if ((i >> j) & 1) == 1:
            c *= alphabets[A[j]]
    ans += c%mod
print(ans-1)

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
if(tmp == 1):
  tmp *= cnt
x = tmp**cnt
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:
import collections
n = int(input())
l = list(input())
cl = collections.Counter(l)
d = dict(cl)
l = list(cl)
s = len(l)
lo=[]
ans = 0
dl = 0
for i in range(s):
    if d[l[i]]!=1:
        ans += ((2**s-2**(s-1))*d[l[i]]+1)
        dl+=1
    else:
        lo.append(l[i])
leo = len(lo)
m = max(0,dl)
ans -= (2**leo-1)*m
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(input())
count = 0
for i in range(2**n):
    ls = []
    bi = list(bin(i))[2::]
    while(len(bi) < n):
        bi.insert(0,'0')
    for j in range(n):
        if bi[-1*j-1] == '1':
            ls.append(s[-1*j-1])
    print(ls)
    if(len(ls) == len(set(ls))):
        count += 1
print(count-1)

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce

mod = 10**9 + 7

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

def comb(r,n):
  r = min(n-r,r)
  if r == 0: return 1
  over = reduce(mul, range(n, n - r, -1))
  under = reduce(mul, range(1,r + 1))
  return over // under

ans = 0

q = []

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

#print q

for a in range(1,min(26+1,n+1)):
  ans += comb(a,n)
  ans %= mod
  for b in range(len(q)):
    if q[b] > 1 and a > 1:
      #print a,q[b]
      #print comb(2,q[b]) * comb(a-2,n-2)
      ans -= comb(2,q[b]) * comb(a-2,n-2)
      for c in range(b+1,len(q)):
        if q[c] > 1 and a > 3:
          ans += comb(2,q[b]) * comb(2,q[c]) * comb(a-2-2,n-2-2)

print ans % mod

Submission status: Wrong Answer

Solution code:
def chk(st):
    d = {}
    for i in st:
        d[i] = 1

    if len(d) != len(st):
        return False

    return True

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

if not chk(s):
    allnum = pow(2,n)-1

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

    minus = 0
    alld = 0
    f = 0
    for key in d.keys():
        if d[key] != 1:
            alld = alld+d[key]
            f=f+1
    #print(alld)

    for key in d.keys():
        if d[key] != 1:
            #print(pow(2,n-d[key]))
            #print(alld-d[key])
            minus = minus + (pow(2,n-d[key]))
            if f>1:
                minus = minus - (alld-d[key]-1)
    print(allnum-minus%(pow(10,9)+7))
else:
    print(pow(2,n)-1%(pow(10,9)+7))

Submission status: Wrong Answer

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

count = 0
sub_seq = None

for i in range(n): 
    sub_seq = []
    sub_seq.append(s[i])
    count += 1
   
    for k in range(i + 1, n):
        if s[k] not in sub_seq:
            sub_seq.append(s[k])
            count += 1
          
          

print(count)

Submission status: Wrong Answer

Solution code:
import itertools

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

m = len(set(s))
count = m

for i in range(1, m):
    strings = itertools.combinations(s, i+1)
    for string in strings:
        if len(set(string)) == i+1:
            count += 1

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

Submission status: Wrong Answer

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

A = list(alphabets.keys())
for i in range(1 << len(A)):
    output = []
    c = 1
    for j in range(len(A)):
        if ((i >> j) & 1) == 1:
            c *= alphabets[A[j]]
    ans += c
print(ans-1)

Submission status: Wrong Answer

Solution code:
from sys import exit
L = int(input())
# a = [int(input()) for _ in range(N)]
S = str(input())
dic = {}
for s in S:
    if not s in dic:
        dic[s] = 1
    else:
        dic[s]+=1
kind = list(dic.keys())
kind_num = len(kind)
ans = 0
for bit in range(1,(1 << kind_num)):
    V = []
    tmp = 1
    for i in range(0,kind_num):
        if(bit & (1 << i)):
            V.append(i)
            tmp*=dic[kind[i]]
    # print(V)
    #     print(kind[i])
    # print(tmp)
    ans+=tmp
print(ans)
exit()

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)
l=[0]*m
for i in range(m):
    l[i]=s.count(z[i])
for i in range(m):
    for j in range(m,i-1,-1):
        g=1
        for k in l[i:j+1]:
            g*=k%mod
        ans+=g
print(ans%mod)

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]
ans = 0
nisin = 2**Size
for i in range(1, nisin):
  lst = []
  for k in range(Size):
    lst.append(i%2)
    i //= 2 # 必須
  lst.reverse()
  sub_array = alpha[lst==1]
  ans += sub_array.prod()
print(int(ans))

Submission status: Wrong Answer

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

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


print(counta)

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)
l=[0]*m
for i in range(m):
    l[i]=s.count(z[i])
for i in range(m):
    for j in range(m,i-1,-1):
        g=1
        for k in l[i:j+1]:
            g*=k%mod
    ans+=g
print(ans%mod)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
l = list(input())
cl = collections.Counter(l)
d = dict(cl)
l = list(cl)
s = len(l)
lo=[]
ans = 0
for i in range(s):
    if d[l[i]]!=1:
        ans += ((2**s-2**(s-1))*d[l[i]]+1)
    else:
        lo.append(l[i])
leo = len(lo)
ans -= (2**leo-1)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
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)
    """
    result = 0
    for i in range(1, counter+1):
        result += conbinations(counter, i)

    if counter != len(S):
        result += len(S) - counter
    """
    result = 0
    for i in range(1, N+1):
        result += conbinations(N, i)
    
    for i in range(1, N-counter+1):
        result -= conbinations(N-counter+1, i)
    result = math.floor(result)
    print(result)


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

def permutations(n, r):
    upper = 1
    down = 1
    for i in range(1, n+1):
        upper *= i
    for i in range(1, n-r+1):
        down *= i
    return upper / down

def conbinations(n, r):
    down = 1
    for i in range(1, r+1):
        down *= i
    return permutations(n, r) / down

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

dic = {"":1}
ans = 0

for c in S:
    dic_new = {}         
    for k in dic:    
        if not(c in k):    
            ans += dic[k]    
            ans %= 10**9 + 7    
            dic_new[k+c] = dic_new.get(k+c,0)+1    
    for k in dic_new:    
        dic[k] = dic.get(k,0)+dic_new[k]    
print(ans)

Submission status: Wrong Answer

Solution code:
def chk(st):
    d = {}
    for i in st:
        d[i] = 1

    if len(d) != len(st):
        return False

    return True

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

if not chk(s):
    allnum = pow(2,n)-1

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

    minus = 0
    alld = 0
    f = 0
    for key in d.keys():
        if d[key] != 1:
            alld = alld+d[key]
            f=f+1
    #print(alld)

    for key in d.keys():
        if d[key] != 1:
            #print(pow(2,n-d[key]))
            #print(alld-d[key])
            minus = minus + (pow(2,n-d[key]))
            if f>1:
                minus = minus - (alld-d[key]-1)
    print(allnum-minus)
else:
    print(pow(2,n)-1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
S = input()
setS = set(list(S))
result = 2**len(setS)
for i in setS:
    num = S.count(i)
    if num > 1:
        result *= (1 + num) / 2
result %= (10**9 + 7)
print("{}".format(int(result)-1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import exit
L = int(input())
# a = [int(input()) for _ in range(N)]
S = str(input())
dic = {}
for s in S:
    if not s in dic:
        dic[s] = 1
    else:
        dic[s]+=1
kind = list(dic.keys())
# print(kind)
# print(dic)
kind_num = len(kind)
ans = 0
for bit in range(1,(1 << kind_num)):
    V = []
    for i in range(0,kind_num):
        if(bit & (1 << i)):
            V.append(i)
    tmp = 1
    # print(V)
    for i in V:
        tmp*=dic[kind[i]]
    #     print(kind[i])
    # print(tmp)
    ans+=tmp
print(ans)
exit()

Submission status: Wrong Answer

Solution code:
def ckn(k,n):
    if k is n:
        return 1
    elif k is 1:
        return n
    else:
        ms = 1;ts = 1
        for i in range(1,k+1):
            ts = ts*(n-i+1)
            ms = ms *i
        return ts//ms
    
    
n = int(input())
s = input()
ans = 0
m  = (n-len(set(s)))*2
for i in range(1,n+1):
    ans += ckn(i,n)
for i in range(1,m):
    ans -= ckn(i,m)
print(ans%(1000000000+7))

Submission status: Wrong Answer

Solution code:
N = int( input())
S = input()
Q = 10**9 + 7
dp = [ [1] + [ 0]*27 for _ in range(N+1)]
dp[0][0] = 1
dp[0][-1] = 1
for i in range(1,N+1):
    a = ord(S[i-1]) - ord("a") + 1
    s = 1
    for j in range(1,27):
        if j == a:
            dp[i][j] = (dp[i-1][j] + dp[i-1][27] - dp[i-1][j])%Q
        else:
            dp[i][j] = (dp[i-1][j] + (dp[i-1][27]  - dp[i-1][a])*dp[i-1][j]//dp[i-1][27])%Q
    dp[i][27] = (dp[i-1][27]*2 - dp[i-1][a] )%Q
print( dp[-1][-1]-1)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
S = input()
Su = sorted(set(S), key=S.index)
cnt = 0
Nu = len(Su)
num = []

for i in range(0,Nu,1):
    num.append(S.count(Su[i]))

for i in range(2,Nu,1):
    for j in range(0,i,1):
        tempcnt = num[j]
        for k in range(j+1,Nu,1):
            tempcnt *= num[k]
        cnt += tempcnt
cnt += np.sum(num)
cnt += np.prod(num)
print(cnt%(10**9+7))

Submission status: Wrong Answer

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

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

Ans = 1
for i in range(N):
  Ans = (Ans * 2) % MOD
Ans -= 1
if Ans < 0:
  Ans += MOD

t = 0
k = 1
for i in L.values():
  N -= i
  tt = 1
  for j in range(N):
    tt = (tt * 2) % MOD
  ttt = 1
  for j in range(i):
    ttt = (ttt * 2) % MOD
  ttt -= i + 1
  if ttt < 0:
    ttt += MOD
  if i != 1:
    t += (k * tt * ttt) % MOD
  k *= i + 1

Ans -= t % MOD
if Ans < 0:
  Ans += MOD
print(int(Ans))

Submission status: Wrong Answer

Solution code:
# coding:utf-8

n = int(input())
s = input()
InWord={i:False for i in 'abcdefghijklmnopqrstuvwxyz'}
answer = 0
marker = 1

length = 1
InWord[s[0]]=True
for i in range(n):
  for j in range(marker,n):
    if InWord[s[j]] or j==n-1:
      length = j-i+1
      answer += length
      marker = j
      InWord[s[i]] = False
      break
    InWord[s[j]] = True   
print(answer%(10**9+7))

Submission status: Wrong Answer

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

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:
            #sum -= factorial(m) / (factorial(v) * factorial(m - v))
            sum -= ncr(m, v)

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

def list_up_dup(s):
    s_count = dict(Counter(s))
    dup = [v for v in s_count.values() if v > 1]
    return len(dup), dup

n = int(input())

s = input()
l, dup = list_up_dup(s)
# print(dup)

count = 0
for i in range(1, n+1-l):
    count += cmb(n, i)
    
    for d in dup:
        if d <= i:
            # print(i)
            count -= cmb(i, d)
    # count = count % (10 ** 9 + 7)
    
print(count)

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

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

Submission status: Wrong Answer

Solution code:
import scipy as sp
import itertools


count = 0

N = int(input())
S = input()
for j in range(1,N+1):
    for string in itertools.combinations(S, r = j):
        if len(set(string)) == len(string):
            print(string)
            count += 1


print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Ans = 1
for i in range(N):
  Ans = (Ans * 2) % MOD
Ans -= 1

t = 0
k = 1
for i in L.values():
  N -= i
  tt = 1
  for j in range(N):
    tt = (tt * 2) % MOD
  ttt = 1
  for j in range(i):
    ttt = (ttt * 2) % MOD
  ttt -= i + 1
  if ttt < 0:
    ttt += MOD
  if i != 1:
    t += (k * tt * ttt) % MOD
  k *= i + 1

Ans -= t % MOD
if Ans < 0:
  Ans += MOD
print(int(Ans))

Submission status: Wrong Answer

Solution code:
from collections import Counter
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

def list_up_dup(s):
    s_count = dict(Counter(s))
    dup = [v for v in s_count.values() if v > 1]
    return len(dup), dup

n = int(input())

s = input()
l, dup = list_up_dup(s)
print(dup)

count = 0
for i in range(1, n+1-l):
    count += cmb(n, i)
    
    for d in dup:
        if d <= i:
            # print(i)
            count -= cmb(i, d)
    count = count % (10 ** 9 + 7)
    
print(count)

Submission status: Wrong Answer

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

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

Ans = 1
for i in range(N):
  Ans = (Ans * 2) % MOD
Ans -= 1

t = 0
k = 1
for i in L.values():
  N -= i
  tt = 1
  for j in range(N):
    tt = (tt * 2) % MOD
  ttt = 1
  for j in range(i):
    ttt = (ttt * 2) % MOD
  ttt -= i + 1
  if ttt < 0:
    ttt += MOD
  if i != 1:
    t = (t + (k * tt * ttt) % MOD) % MOD
  k *= i + 1

Ans -= t
if Ans < 0:
  Ans += MOD
print(int(Ans))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
S = input()
result = 2**len(set(list(S)))
sub = []
for i in S:
    if i in sub:
        continue
    num = S.count(i)
    if num > 1:
        result *= (1 + 1/(2**(num-1)))
    sub.append(i)

result %= (10**9 + 7)
print("{}".format(int(result)-1))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

a = {}

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

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

print(n)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int( input())
S = input()
Q = 10**9 + 7
dp = [ [1] + [ 0]*27 for _ in range(N+1)]
dp[0][0] = 1
dp[0][-1] = 1
for i in range(1,N+1):
    a = ord(S[i-1]) - ord("a") + 1
    s = 1
    for j in range(1,27):
        if j == a:
            dp[i][j] = (dp[i-1][j] + dp[i-1][27] - dp[i-1][j])%Q
        else:
            dp[i][j] = (dp[i-1][j] + (dp[i-1][27]  - dp[i-1][a])*dp[i-1][j]//dp[i-1][27])%Q
    dp[i][27] = dp[i-1][27]*2 - dp[i-1][a] 
print( dp[-1][-1]-1)

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)

print(int((w-1)%(1e9+7)))

Submission status: Wrong Answer

Solution code:
from collections import Counter
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

def list_up_dup(s):
    s_count = dict(Counter(s))
    dup = [v for v in s_count.values() if v > 1]
    return len(dup), dup

n = int(input())

s = input()
l, dup = list_up_dup(s)

count = 0
for i in range(1, n+1-l):
    count += cmb(n, i)
    
    for d in dup:
        if d <= i:
            # print(i)
            count -= cmb(i, d)
    count = count % (10^9 + 7)
    
print(count)

Submission status: Wrong Answer

Solution code:
import collections

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

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

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

ans = sum(lst)
    
print(ans)

Submission status: Wrong Answer

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

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

Ans = 1
for i in range(N):
  Ans = (Ans * 2) % MOD
Ans -= 1

t = 0
k = 1
for i in L.values():
  N -= i
  tt = 1
  for j in range(N):
    tt = (tt * 2) % MOD
  ttt = 1
  for j in range(i):
    ttt = (ttt * 2) % MOD
  ttt -= i + 1
  if ttt < 0:
    ttt += MOD
  if i != 1:
    t += (k * tt * ttt) % MOD
  k *= i + 1

Ans -= t
if Ans < 0:
  Ans += MOD
print(int(Ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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))
    for v in dic.values():
        if v >= 2 and m > 1:
            sum -= factorial(m) / (factorial(v) * factorial(m - v))

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

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)

print(int(w%(1e9+7)-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])*(2**(m-1))%mod
print((ans-m*(m-1)//2)%mod)

Submission status: Wrong Answer

Solution code:
from collections import Counter

import scipy.misc as scm

n = int(input())
s = list(input())
tmp = len(set(s))
count_s = Counter(s)
count_s = count_s.most_common()
tips = []
ans = 1
minu = 0
over2 = 0
over2amo = 0
for i in range(tmp):
    if count_s[i][1] > 1:
        over2 += 1
        over2amo += count_s[i][1]
    else:
        break

for i in range(n):
    ans *= 2
    ans %= (10**9 + 7)
ans -= 1

# print(ans)
# print(count_s)
for i in range(tmp):
    minu = 0
    if count_s[i][1] > 1:
        minu = 1
        for j in range(n - count_s[i][1]):
            minu *= 2
            minu %= (10**9 + 7)
        # print(minu)
        ans -= minu

    else:
        break
if over2 > 1:
    ans += (over2 - 1) * (2**(n - over2amo)) % (10**9 + 7)
print(ans)

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]
ans = 0
nisin = 2**Size
for i in range(1, nisin):
  lst = []
  for k in range(Size):
    lst.append(i%2)
    i //= 2 # 必須
  lst.reverse()
  sub_ans = 0
  sub_array = alpha*lst
  sub_array = sub_array[np.nonzero(sub_array)]
  ans += sub_array.prod()
print(int(ans))

Submission status: Wrong Answer

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

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

Ans = 1
for i in range(N):
  Ans = (Ans * 2) % MOD
Ans -= 1

t = 0
k = 1
for i in L.values():
  N -= i
  tt = 1
  for j in range(N):
    tt = (tt * 2) % MOD
  ttt = 1
  for j in range(i):
    ttt = (ttt * 2) % MOD
  ttt -= i + 1
  if ttt < 0:
    ttt += MOD
  if i != 1:
    t += (k * tt * ttt) % MOD
  k *= i + 1

Ans -= t

print(int(Ans % MOD))