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: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce
import itertools

n = int(input())
s = list(input())
listS=[]
listSN=[]
index=0
while index < n:
    if s[index] in listS:
        tarI = listS.index(s[index])
        listSN[tarI]+=1
    else:
        listS.append(s[index])
        listSN.append(1)
    index+=1

sum=0
index2=1
while index2 < len(listSN)+1:
    for elem in itertools.combinations(listSN, index2):
        sum+=reduce(mul, elem)%(10**9+7)
        sum%=(10**9+7)
    index2+=1
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
s = list(map(str,input()))
count = 0
unique = len(set(s))
for i in range(1, len(s)+1):
    cand = list(itertools.combinations(s, i))

    if i<= unique:
        for j in range(len(cand)):
            if len(set(cand[j])) == i:
                count +=1
print(count % (10**9 + 7))

Submission status: Time Limit Exceeded

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def ni(): return int(stdin.readline())
def ns(): return stdin.readline().rstrip()

N = ni()
S = ns()
#  S = 'abcab'
#  N = len(S)

num_comb = 0
state = []
selected = set()

def iter_helper(idx):
    # print(idx)
    for i in range(idx, N):
        if S[i] in selected:
            continue
        else:
            state.append(S[i])
            selected.add(S[i])
            # print(f'add {S[i]} at {i}')
            iter_helper(i + 1)
            global num_comb
            num_comb += 1
            # print(state)
            # print(f'discard {S[i]} at {i}')
            selected.discard(S[i])
            state.pop()
iter_helper(0)
print(num_comb % (10**9 +7))

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

#文字数ごとに探索
cnt = 0

for length in range(1, n+1):
  patterns = list(itertools.combinations(s, length))
  patterns = [pattern for pattern in patterns if len(pattern) == len(set(pattern))]
  # print(patterns)
  cnt += len(patterns)
  
print(cnt)

Submission status: Time Limit Exceeded

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

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

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

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

Submission status: Time Limit Exceeded

Solution code:
input()
S = list(input())
count = 0
limit = 10**9 + 7
for mask in range(1, 2 << len(S)-1):
	temp = {}
	for i, v in enumerate(S):
		if 0 != mask & (1 << i):
			if v in temp:
				break
			temp[v] = True
	else:
		count += 1
		if limit <= count:
			break
print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=input()
from collections import Counter
c= Counter(s)
ans=0
vals=list(c.values())
for i in range(1,1<<len(c)):
    tmpans=1
    for j in range(len(c)):
        if ((i>>j) &1) == 1:
            tmpans*=vals[j]
    ans+=tmpans
print(ans%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
import sys,itertools
input = sys.stdin.readline
N = int(input().strip())
S = input().strip()

def isUnique(a):
    return len(a) == len(set(a))

master = []
for i in range(N):
    for j in itertools.combinations(S,i+1):
        if isUnique(j):
            master.append(j)
        else:
            continue

print(len(master)%((10**9)+7))

Submission status: Time Limit Exceeded

Solution code:
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
  return s_count

def count_up(s_count):
  strings = list(s_count.keys())
  ans = 0
  for num in range(1, len(strings) + 1):
    for s_list in itertools.combinations(strings, num):
      num_list = [s_count[s] for s in s_list]
      ans += reduce((lambda x, y: x * y), num_list)
  print(ans % (10**9 + 7))

N = int(input())
string = input()

s_count = analyze(string)
count_up(s_count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
lis = list(input())
c = Counter(lis)
lisc = list(c)

sum = 0


for i in range(1,1 << len(lisc)):
    point = 1
    for j in range(len(lisc)):
        if ((i >> j) & 1) == 1:
            point = (c[lisc[j]] * point)%(10**9+7)
    sum += point

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

s = input()

x = []

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

m = len(set(x))

import itertools

cnt = 0
for i in range(1, m+1):
    p = list(itertools.combinations(s,i))
    cnt += sum(len(pp) == len(set(pp)) for pp in p)

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

ans = 0
for i in range(1, N+1):
    tmp = 0
    lst = list(combinations(S, i))
    for l in lst:
        if len(set(l)) == len(l):
            tmp += 1
    ans += tmp
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
import itertools

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

ans = 0

for i in range(1,N+1):
  tmp_s_list = list(itertools.combinations(S,i))
  for s in tmp_s_list:
    tmp_count = collections.Counter(s)
    if max(tmp_count.values()) == 1:
      ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce
import itertools

n = int(input())
s = list(input())
listS=[]
listSN=[]
index=0
while index < n:
    if s[index] in listS:
        tarI = listS.index(s[index])
        listSN[tarI]+=1
    else:
        listS.append(s[index])
        listSN.append(1)
    index+=1

sum=0
index2=1
while index2 < len(listSN)+1:
    for i in itertools.combinations(listSN, index2):
        sum += reduce(mul, list(i)) % (10**9+7)
        sum %= (10**9+7)
    index2+=1
print(sum%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
lis = list(input())
c = Counter(lis)
lisc = list(c)

sum = 0


for i in range(1,1 << len(lisc)):
    point = 1
    for j in range(len(lisc)):
        if ((i >> j) & 1) == 1:
            point = (c[lisc[j]] * point)%(10**9+7)
    sum += (point%(10**9+7))

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
import sys
input = sys.stdin.readline
#a,b = map(int, input().split())

n=int(input())
A =input().strip()
#A=input()
d={}
for i in A:
    if i not in d:
        d[i]=1
    else:
        d[i]+=1
#print(d)
#print(len(d))
#for i in range(len(d)):
arr=[value for value in d.values()]
#    print(value)
value=0
for num in range(len(arr)):
    for v in itertools.combinations(arr, num+1):
        tmp=1
        for i in v:
            tmp*=i
        value+=tmp
print(value%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
import sys,itertools
input = sys.stdin.readline
N = int(input().strip())
S = input().strip()

master = []
for i in range(N):
    existed = False
    for j in itertools.combinations(S,i+1):
        for a in j:
            if j.count(a) > 1:
                existed=True
                break
        if existed:
            existed = False
            continue
        master.append(j)
print(len(master)%((10**9)+7))

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce
import itertools

n = int(input())
s = list(input())
listS=[]
listSN=[]
index=0
while index < n:
    if s[index] in listS:
        tarI = listS.index(s[index])
        listSN[tarI]+=1
    else:
        listS.append(s[index])
        listSN.append(1)
    index+=1

sum=0
index2=1
while index2 < len(listSN)+1:
    for i in itertools.combinations(listSN, index2):
        sum+=reduce(mul, list(i))
    index2+=1
print(sum%(10**9+7))

Submission status: Time Limit Exceeded

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

S = list(S)

cnt = 0
for i in range(N+1):
    for v in itertools.combinations(S,i):
        if len(v) == len(set(v)) & len(v)!=0:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N=int(input())
S=list(input())
answer=0

def is_unique(seq):
    return len(seq) == len(set(seq))

for i in range(N):
    counter=0
    C=list(itertools.combinations(S, i+1))
    for j in range(len(C)):
        if is_unique(C[j]):
            counter+=1
    answer+=counter
print(answer%(7+10**9))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
lis = list(input())
c = Counter(lis)
lisc = list(c)

sum = 0


for i in range(1,1 << len(lisc)):
    point = 1
    for j in range(len(lisc)):
        if ((i >> j) & 1) == 1:
            point *= c[lisc[j]]
    sum += (point%(10**9+7))

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

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce
import itertools

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

n = int(input())
s = list(input())
listS=[]
listSN=[]
index=0
while index < n:
    if s[index] in listS:
        tarI = listS.index(s[index])
        listSN[tarI]+=1
    else:
        listS.append(s[index])
        listSN.append(1)
    index+=1

from operator import mul
from functools import reduce

sum=0
index2=1
while index2 < len(listSN)+1:
    for i in itertools.combinations(listSN, index2):
        sum+=reduce(mul, list(i))
    index2+=1
print(sum%(10**9+7))

Submission status: Time Limit Exceeded

Solution code:
#import math
def printSubsequences(arr, n) :
    opsize = 2**n
    ans=0
    for counter in range( 1, (int)(opsize)) :
        ans2=1
        for j in range(0, n) :
            if (counter & (1<<j)) : 
                ans2=(ans2*arr[j])%1000000007
        #print(ans2)
        ans+=(ans2%1000000007)

    return(ans) 

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

c=[0]*26
for i in range (n):
    c[ord(s[i])-97]+=1

ar=[]

for i in range (26):
    if(c[i]>0):
        ar.append(c[i])
#print(ar)
x=printSubsequences(ar,len(ar))
print(x%1000000007)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
S = [s for s in input()]
ans = 0
for n in range(1,N+1):
    a = list(itertools.combinations(S,n))
    a = [i for i in a if len(i) == len(set(i))]
    ans += len(a)
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

s = input()

x = []

for i in range(n):
    x.append(s[i])
    
m = len(set(x))

import itertools

cnt = 0
for i in range(1,m+1):
    p = list(itertools.combinations(s,i))

    for pp in p:
        if len(pp) == len(set(pp)):
            cnt = cnt + 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#import math
def printSubsequences(arr, n) :
    opsize = 2**n
    ans=0
    for counter in range( 1, (int)(opsize)) :
        ans2=1
        for j in range(0, n) :
            if (counter & (1<<j)) : 
                ans2*=arr[j]
        #print(ans2)
        ans+=(ans2%1000000007)

    return(ans) 

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

c=[0]*26
for i in range (n):
    c[ord(s[i])-97]+=1

ar=[]

for i in range (26):
    if(c[i]>0):
        ar.append(c[i])
#print(ar)
x=printSubsequences(ar,len(ar))
print(x%1000000007)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

s = input()

x = []

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

import itertools

cnt = 0
for i in range(1,n+1):
    p = list(itertools.combinations(s,i))

    for pp in p:
        if len(pp) == len(set(pp)):
            cnt = cnt + 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
from itertools import combinations

n=int(input())
s=input()
mod=10**9+7
c=Counter(s).most_common()
m=len(c)
l=[]
for x in c:
    l.append(x[1])

ans=0
for i in range(1,m+1):
    for v in combinations(l,i):
        sum=1
        for j in range(i):
            sum*=v[j]
            sum=sum%mod
        ans+=sum
        ans=ans%mod
print(ans%mod)

Submission status: Time Limit Exceeded

Solution code:
input()
S = list(input())
count = 0
for mask in range(1, 2 << len(S)-1):
	temp = {}
	for i, v in enumerate(S):
		if 0 != mask & (1 << i):
			if v in temp:
				break
			temp[v] = True
	else:
		count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
#A問題
import sys
sys.setrecursionlimit(500000)
N=int(input())
S=str(input())
Slist=list(S)
count=-1
kari=[]
def ans(n):
    global count
    global Slist
    if n == N-1:
        if Slist[n] in kari:
            count+=1
            return
        else:
            count+=2
            return
    else:
        if Slist[n] in kari:
            ans(n+1)
        else:
            kari.append(Slist[n])
            ans(n+1)
            kari.remove(Slist[n])
            ans(n+1)
ans(0)
count%=1000000007
print(count)

Submission status: Time Limit Exceeded

Solution code:
import math
def printSubsequences(arr, n) :
    opsize = math.pow(2, n)
    ans=0
    for counter in range( 1, (int)(opsize)) :
        ans2=1
        for j in range(0, n) :
            if (counter & (1<<j)) : 
                ans2*=arr[j]
        #print(ans2)
        ans+=(ans2%1000000007)

    return(ans) 

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

c=[0]*26
for i in range (n):
    c[ord(s[i])-97]+=1

ar=[]

for i in range (26):
    if(c[i]>0):
        ar.append(c[i])
#print(ar)
x=printSubsequences(ar,len(ar))
print(x%1000000007)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
S = list(input())
S_set = set(S)
ans = 0
minus = 0
for i in range(2, N+1):
    comb_list = list(itertools.combinations(S, i))
    for li in comb_list:
        if(len(li) != len(set(li))):
            minus += 1
    ans += len(comb_list)
print(ans + N - minus)

Submission status: Time Limit Exceeded

Solution code:
import math
def printSubsequences(arr, n) :
    opsize = math.pow(2, n)
    ans=0
    for counter in range( 1, (int)(opsize)) :
        ans2=1
        for j in range(0, n) :
            if (counter & (1<<j)) : 
                ans2*=arr[j]
        #print(ans2)
        ans+=ans2

    return(ans) 

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

c=[0]*26
for i in range (n):
    c[ord(s[i])-97]+=1

ar=[]

for i in range (26):
    if(c[i]>0):
        ar.append(c[i])
#print(ar)
x=printSubsequences(ar,len(ar))
print(x%1000000007)

Submission status: Time Limit Exceeded

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

ref = ["0"]

for i in range(len(s)):
    for j in range(len(ref)):
        if s[i] not in ref[j]:
            ref.append(ref[j]+s[i])

print(len(ref)-1)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
import itertools


def analyze(string):
  s_count = defaultdict(int)
  for s in string:
    s_count[s] += 1
  return s_count

def count_up(s_count):
  strings = list(s_count.keys())
  ans = 0
  for num in range(1, len(strings) + 1):
    for s_list in itertools.combinations(strings, num):
      a = 1
      for s in s_list:
        a *= s_count[s]
      ans += a
  print(ans % (10**9 + 7))

N = int(input())
string = input()

s_count = analyze(string)
count_up(s_count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
count = 0
for i in range(1,2 ** n):
    s_i = bin(i)[2:].zfill(n)
    tmp = []
    for j in range(n):
        if s_i[j] == '1':
            tmp.append(s[j])
            if s_i[j] in tmp:
                break
    if len(tmp) == len(set(tmp)):
        count += 1

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

Submission status: Time Limit Exceeded

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

sys.setrecursionlimit(100000)


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


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


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


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


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


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


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


def mt(f):
    import time

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

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

    return wrap


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

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

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

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



@mt
def slv(N, S):

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

    cs = tuple(CC.keys())
    for i in range(1, len(cs)+1):
        for k in combinations(cs, i):
            tmp = 1
            for c in k:
                tmp = m.mul(tmp, CC[c])
            ans = m.add(ans, tmp)
            
        

    return ans


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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
#a,b = map(int, input().split())
n=int(input())
A=input()
d={}
for i in A:
    if i not in d:
        d[i]=1
    else:
        d[i]+=1
#print(d)
#print(len(d))
arr=[]
#for i in range(len(d)):
for value in d.values():
    arr.append(value)
#    print(value)
value=0
for num in range(len(arr)):
    for v in itertools.combinations(arr, num+1):
        tmp=1
        for i in v:
            tmp*=i
        value+=tmp
print(value%(10**9+7))

Submission status: Time Limit Exceeded

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

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

ans = -1
for i in itertools.product(range(2),repeat=len(li)):
#  print(i)
  tmp = 1
  for j in range(len(li)):
    if i[j] != 0:
      tmp = tmp * li[j]
  ans = ans + tmp
  ans = ans%1000000007
print(ans%1000000007)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

count = 0
for i in range(n):
    strings = itertools.combinations(s, i+1)
    for string in strings:
        count += 1
        for j in range(i):
            if string[j] in string[j+1:]:
                count -= 1
                break

print(count)

Submission status: Time Limit Exceeded

Solution code:
input()
S = list(input())
count = 0
for mask in range(1, 2 << len(S)-1):
	temp = []
	for i, v in enumerate(S):
		if 0 != mask & (1 << i):
			temp.append(v)
	if len(temp) == len(set(temp)):
		count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = input()
tmp = ''
ans = 0
for i in range(1,2**N):
    #部分列取得
    tmp = ''
    for j in range(N):
        if (i>>j)&1 == 1:
            tmp += S[j]

    #チェック
    if len(tmp)==len(set(tmp)):
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

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

ans = 0
for i in itertools.product(range(2),repeat=len(li)):
#  print(i)
  tmp = 1
  for j in range(len(li)):
    if i[j] != 0:
      tmp = tmp * li[j]
  ans = ans + tmp
print((ans-1)%1000000007)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
s = list(map(str,input()))
count =0
for i in range(1, len(s)+1):
    cand = list(itertools.combinations(s, i))
    if i ==1:
        count += len(cand)
    else:
        for j in range(len(cand)):
            if len(set(cand[j])) == i:
                count +=1
print(count % (10**9 + 7 ))

Submission status: Time Limit Exceeded

Solution code:
#A問題
import collections
N=int(input())
S=str(input())
Slist=list(S)
count=0
maxn=2**N
for i in range(maxn):
    I=bin(i)
    I=I.lstrip("0b")
    Ilen=len(I)
    if Ilen<N:
        Id=N-Ilen
        j=0
        for j in range(Id):
            I="0"+I
    
    k=0
    klist=[]
    flag=0
    for k in range(N):
        if I[k]=="0":
            pass
        else:
            if Slist[k] in klist:
                flag=1
                break
            else:
                klist.append(Slist[k])
    if flag == 0 and len(klist)>0:
        count+=1
    count=count%1000000007
print(count)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations 
n=int(input())
s=input()
ans=0
for i in range(1,n+1):
    koho=tuple(combinations([j for j in s],i))
    for j in range(len(koho)):
        if len(koho[j])==len(tuple(set(koho[j]))):
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

tmp = [S[0], '']

for s in S[1:]:

    length = len(tmp)

    for i in range(length):
        if s not in tmp[i]:
            tmp.append(tmp[i]+s)

print(len(tmp)-1)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = input()
count = 0
for i in range(1,2 ** n):
    s_i = bin(i)[2:].zfill(n)
    tmp = []
    for j in range(n):
        if s_i[j] == '1':
            tmp.append(s[j])
    if len(tmp) == len(set(tmp)):
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools


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

ptn = [i for i in range(N)]

cnt = 0
for i in range(1, N+1):
    c = list(itertools.combinations(ptn, i))
    for v in c:
        tmp = ''
        for _ in v:
            tmp += S[_]
        if (len(tmp) == len(set(tmp))):
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools


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

ptn = [i for i in range(N)]

ans = []
for i in range(1, N+1):
    c = list(itertools.combinations(ptn, i))
    for v in c:
        tmp = ''
        for _ in v:
            tmp += S[_]
        ans.append(tmp)

cnt = 0

for _ in (ans):
    if (len(_) == len(set(_))):
        cnt += 1

amari = 10**9 + 7
print(cnt%amari)

Submission status: Accepted

Solution code:
import sys, math, re
from functools import lru_cache
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    S = input()
    d = {}
    for i in range(N):
        if not S[i] in d:
            d[S[i]] = 1
        d[S[i]] += 1

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

    ans -= 1
    print(ans%MOD)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
mod = 10**9 + 7
n = int(input())
s = input()
dic = {}
for si in s:
  if si not in dic:
    dic[si] = 0
  dic[si] += 1
ans = 1
for k, v in dic.items():
  ans = ans * ((v+1) % mod) % mod
print((ans-1)%mod)

Submission status: Accepted

Solution code:
import sys
def input():
  return sys.stdin.readline().rstrip()

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

MOD=10**9+7
num=[0]*30

for c in S:
  num[ord(c)-ord("a")]+=1

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

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

Submission status: Accepted

Solution code:
mod = 10**9+7

n = int(input())
S = input()

alp = [chr(i) for i in range(97, 97+26)]

cnt = []
for a in alp:
    cnt.append(S.count(a))

ans = 1
for c in cnt:
    if c:
        ans *= (c+1)

print((ans-1)%mod)

Submission status: Accepted

Solution code:
N = int(input())
S = str(input())
V = 'abcdefghijklmnopqrstuvwxyz'
Lavida = [1]*26
for i in range (0, N):
	Lavida[V.index(S[i])]+=1

count = 1
for i in range (0, 26):
	count*=Lavida[i]
	count=count%(10**9+7)

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

Submission status: Accepted

Solution code:
from string import ascii_lowercase
from functools import reduce
from operator import mul
n = int(input())
S = input()
mod = 10**9 + 7
print(reduce(lambda x, y: x*y % mod, (S.count(c)+1 for c in ascii_lowercase))-1)

Submission status: Accepted

Solution code:
from string import ascii_lowercase
n = int(input())
S = input()
mod = 10**9 + 7
s = 1
for c in ascii_lowercase:
  s *= S.count(c)+1
  s %= mod
print(s-1)

Submission status: Accepted

Solution code:

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

    CNT = Counter(S)
    ans = 1
    for v in CNT.values():
        ans *= v + 1
        ans %= MOD

    print(ans - 1)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

print((ans-1)%MOD)

Submission status: Accepted

Solution code:
n=int(input())
s=input()
m=10**9+7
dict={}
for i in s:
  if i not in dict:
    dict[i]=1
  else:
    dict[i]+=1
ans=1
for i in dict:
  ans*=dict[i]+1
print((ans-1)%m)

Submission status: Accepted

Solution code:
# A - Colorful Subsequence AC (hint)
import collections
N = int(input())
S = input()
MOD = 10**9+7

cnt = collections.Counter(S)

# 文字の選び方
# 1 個選ぶ or 2 選ぶ or 3 個選ぶ or ... cnt 個選ぶ or 選ばない
# (cnt + 1) 通り
ans = 1
for value in cnt.values():
    ans = (ans*(value+1))%MOD
print(ans - 1)

Submission status: Accepted

Solution code:
n = int(input())
a = list(input())
b = list(set(a))
ans = 1
for i in b:
    ans %= 10**9+7
    ans *= a.count(i)+1
print((ans-1)%(10**9+7))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 1
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

n = k()
s = X()

count = list(Counter(s).most_common())

for i in count:
    ans *= i[1]+1

ans -= 1
print(ans%mod)

Submission status: Accepted

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

print((ans-1)%MOD)

Submission status: Accepted

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n = I()
    s = S()
    ans = 1
    num = 10**9 + 7
    count = collections.Counter(s)

    for value in count.values():
        ans *= value+1
        ans %= num

    ans -= 1
    ans % num
    print(ans)
        
main()

Submission status: Accepted

Solution code:
from collections import Counter
N=int(input())
S = input()
ss = list(Counter(S).most_common())
#print(ss)
ans = 1
MOD = 10**9 + 7
for i in range(len(ss)):
    ans *= ss[i][1] +1
    ans %= MOD
print(ans-1)

Submission status: Accepted

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

for s in S:
  dic[s] += 1
  
ans = 1
for value in dic.values():
  ans *= (value + 1)
  ans %= MOD
  
print((ans - 1) % MOD)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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



main()

Submission status: Accepted

Solution code:
from collections import Counter
input()
cnt=Counter(input())

ans=1
mod=10**9+7

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

print((ans-1)%mod)

Submission status: Accepted

Solution code:
input()
S=input()
s=set(S)
a=1
for c in s:a=a*(S.count(c)+1)%(10**9+7)
print(a-1)

Submission status: Accepted

Solution code:
import operator
import functools
N = int(input())
S = input()
c = [1] * 26
for s in S:
    c[ord(s)-ord('a')] += 1
print((functools.reduce(operator.mul,c)-1) % (10**9+7))

Submission status: Accepted

Solution code:
from collections import Counter

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

cnt = Counter(s)

ans = 1

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

print(ans - 1)

Submission status: Accepted

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

print(ans - 1)