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: Runtime Error

Solution code:
N,S=input().split()
ans=1
c=[1]*26
for i in S:
        c[ord(i)-ord('a')]+=1
for i in c:
        ans*=i
print(ans%1000000007-1)

Submission status: Runtime Error

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

counter_s = Counter(s).most_common()
ans = 1
for i in counter_s:
    ans *= i[1] + 1

ans -= 1
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()
ans=0
for i in range(n-1):
  ans+=1
  for j in range(i+1,n+1):
    if s[i]==s[j]:
      break
    ans+=1
  ans%=(10**9+7)
ans+=1
ans%=10**9+7
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()
ans=0
for i in range(n):
  ans+=1
  for j in range(i+1,n+1):
    if s[i]==s[j]:
      break
    ans+=1
  ans%=(10**9+7)
print(ans)

Submission status: Runtime Error

Solution code:
c = [1]*("z".encode()-"a".encode()+1)
for x in map(lambda x: x-"a".encode(), input().encode()):
	c[x] += 1

m = 1
for x in c:
  m *= c

print(m-1)

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;
#define mod 1000000007
int main(){
  int n;cin>>n;
  string s;cin>>s;
  int i,j;
  int a[26];
  for(i=0;i<26;i++){
    a[i]=0;
  }
  for(i=0;i<n;i++){
    a[s[i]-'a']++;
  }
  int ans=1;
  for(i=0;i<26;i++){
    ans*=a[i]+1;
    //cout<<ans<<endl;
    ans%=mod;
  }
  ans--;
  cout<<ans<<endl;
}

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()
csum = [1]

for i in range(1, n):
    if s[i] in s[:i]:
        csum.append(int(csum[-1] * 1.5 + 0.5))
    else:
        csum.append(csum[-1] * 2 + 1)

print(csum[-1])

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

const ll MOD = 1e9+7;

int main()
{
  int N;
  string S;
  cin >> N >> S;
  map<int, int> cnt;

  for (int i = 0; i < S.size(); ++i) {
    cnt[S[i]-'a']++;
  }

  ll ans = 1;
  for (auto v : cnt) {
    ans *= (v.second+1)%MOD;
  }

  cout << ans - 1 << endl;
}

Submission status: Runtime Error

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

Submission status: Runtime Error

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

c = collections.Counter(s)

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

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

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**10)
N = int(input())
S = input()

count = -1

def dfs(index, moji):
    global N,S,count
    if index==N:
        count+=1
        return
    if S[index] in moji:
        dfs(index+1, moji)
    else:
        dfs(index+1, moji)
        dfs(index+1, moji+S[index])

dfs(0,'')
print(count)

Submission status: Runtime Error

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

count = -1

def dfs(index, moji):
    global N,S,count
    if index==N:
        count+=1
        return
    if S[index] in moji:
        dfs(index+1, moji)
    else:
        dfs(index+1, moji)
        dfs(index+1, moji+S[index])

dfs(0,'')
print(count)

Submission status: Runtime Error

Solution code:
n=int(input())
s=input()
ans=0
for i in range(n):
    for j in range(i,j):
        if s[j] in s[i:j]:
            break
        ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
@parallel
@roles('allgame')
def _last_redis_save():
	with cd(get_deploy_path()):
		redisSet = set()
		ret = run('supervisorctl status')
		for line in ret.split('\n'):
			line = line.strip()
			if line.find('RUNNING') >= 0 and line.find('redis') >= 0:
				name = line.split()[0].strip()
				redisSet.add(name)

		ret = []
		with cd('db'):
			for redis in sorted(list(redisSet)):
				port = redis[5:]
				ret.append(run('ls -l -h game%s.rdb' % port))
		return '\n'.join(ret)

def last_redis_save():
	result = execute(_last_redis_save)
	for k in sorted(result.keys()):
		print '-'*20
		print k, ':'
		v = result[k]
		print v

Submission status: Runtime Error

Solution code:
MOD = 10**9+7
N = int(input())
C = [int(input()) for i in range(N)]

dp = [0 for i in range(N)]
dp[0] = 1

color = {}
for c in C:
    color[c] = 0
color[C[0]] = 1

for i in range(1,N):
    dp[i] = dp[i-1]
    if C[i-1] != C[i]:
        dp[i] = (dp[i] + color[C[i]])%MOD
    color[C[i]] = dp[i]
print(dp[-1])

Submission status: Runtime Error

Solution code:
N=int(input())
BBB=[int(x) for x in input().split()]

BB=[0 for i in range(N)]
def re(B,n):
  global BB
  if n==1:
    BB[0]=B[0]
    for i in BB:
      print(i)
    exit()
  for i in range(n):
    if B[i]>i+1:
      return 1
    if B[i]==i+1:
      BB[n-1]=B[i]
      re(B[:i]+B[i+1:n],n-1)
  return -1

result=re(BBB,N)
print(-1)

Submission status: Runtime Error

Solution code:
N=int(input())
b=list(map(int,input().split()))
flg=True

ans = [0 for i in range(N)]
for i in range(N):
    for j in range(N-i):
        if b[N-i-j-1]==N-i-j:
            del b[N-i-j-1]
            #print(b)
            ans[N-i-1]=N-i-j
            break

for a in ans:
    if a==0:
        flg=False
        break
#print(ans)
if flg:
    for a in ans:
        print(a)
else:
    print(-1)

Submission status: Runtime Error

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

T = ''

cnt = 0
cnt_list = []
for i in S:
  if len(T)==0:
    cnt+=1
    bef = i
  elif bef!=i:
    cnt+=1
    bef = i
  elif bef==i:
    cnt_list.append(cnt)
    cnt = 0
    
m = max(cnt_list)
print(m%(10**9+7))

Submission status: Runtime Error

Solution code:
N, A, B = list(map(int, input().split(' ')))

C = A^B
c = format(A^B, 'b')
p = list()
p.append(A)
for i in range(len(c)):
    if int(c[len(c)-1-i]) == 1:
        tmp = p[-1] ^ (C & (1 << i))
        p.append(tmp)
for i in range(2**N-len(p)):
    p.append(p[-2])
if B == p[2**N-1]:
    print('YES')
    for i in range(len(p)):
        print(p[i], end=' ')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <map>
#include <string>

using namespace std;

int main() {
    int N;
    string S;
    cin >> N;
    cin >> S;
    map<char, int> m;
    for (int i=0; i<N; i++) {
            m[S[i]]++;
    }
    map<char, int>::iterator it;
    int ans = 1;
    for(it = m.begin(); it != m.end(); it++) {
        ans *= it->second + 1;
    }
    cout << ans - 1 << endl;
}

Submission status: Runtime Error

Solution code:

alphabet = "abcdefghijklmnopqrstuvwxyz"
indmap = {}
for i, c in enumerate(alphabet):
    indmap[c] = i

MOD = 10L**9 + 7L

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

    counts = [0L]*26
    for c in s:
        counts[indmap[c]] += 1L

    #print(counts)
    total = 1L
    for k in counts:
        total *= (k+1L)
        total % MOD
    print(total-1)

main()

Submission status: Runtime Error

Solution code:

alphabet = "abcdefghijklmnopqrstuvwxyz"
indmap = {}
for i, c in enumerate(alphabet):
    indmap[c] = i

MOD = 10L**9L + 7L

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

    counts = [0L]*26
    for c in s:
        counts[indmap[c]] += 1L

    #print(counts)
    total = 1L
    for k in counts:
        total *= (k+1L)
        total % MOD
    print(total-1)

main()

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>

using namespace std;


int main() {
  unsigned long long co=0;
  int N;
  string S;
  //入力受付
  cin >> N;
  cin >> S;
  string str="";
  vector<int> n;
  int index =0;
  
  for(int i=0;i<N;i++){
    index=str.find(S[i]);
    if(index== string::npos){
      str +=S[i];
      n.push_back(2);
    }else{
      n[index]++;
    }
  }

  co = 1;
  for(int i=0; i<n.size();i++){
    co = co * n[i];
  }
  co--;  
  cout << co % 1000000007;

}

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>

using namespace std;


int main() {
  unsigned long long co=0;
  int N;
  string S;
  //入力受付
  cin >> N;
  cin >> S;
  string str="";
  vector<int> n;
  int index =0;
  
  for(int i=0;i<N;i++){
    index=str.find(S[i]);
    if(index== string::npos){
      str +=S[i];
      n.push_back(2);
    }else{
      n[index]++;
    }
  }

  co = 1;
  for(int i=0; i<n.size();i++){
    co = (co * n[i]) % 1000000007;
  }
  co--;  
  cout << co % 1000000007;

}

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
  
co = 0
index =0
n =[]
str = ""

for i in range(N):
  index=str.find(S[i])
  if index == -1 :
    str += S[i]
    n.append(2)
  else :
    n[i] += 1

co = 1
for i in range(len(n)):
  co = co * n[i]
co -= 1

print(co % 1000000007)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
  
co = 0
index =0
n =[]
str = ""

for i in range(N):
  index=str.find(S[i])
  if index == -1 :
    str += S[i]
    n.append(2)
  else :
    n[i] += 1

co = 1
for i in range(len(n)):
  co = co * n[i]
co -= 1

print(co % 1000000007)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
  
co = 0
index =0
n =[]
str = ""

for i in range(N):
  index=str.find(S[i])
  if index == -1 :
    str += S[i]
    n.append(2)
  else :
    n[i]++

co = 1
for i in range(len(n)):
  co = co * n[i]
co -= 1

print(co % 1000000007)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
  
co = 0
index =0
n =[]
str = ""

for i in range(N):
  index=str.find(S[i])
  if index == -1 :
    str += S[i]
    n.append(2)
  else :
    n[i]++

co = 1
for i in range(n.size()):
  co = co * n[i]
co--;

print(co % 1000000007)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
  
co = 0
index =0
n =[]
str = ""

for i in N:
  index=str.find(S[i])
  if index == -1 :
    str += S[i]
    n.append(2)
  else :
    n[i]++

co = 1
for i in n.size():
  co = co * n[i]
co--;

print(co % 1000000007)

Submission status: Runtime Error

Solution code:
N = int(input())
S = input()
def f(s, c):
    if not s: return 0
    if s.find(c) == -1:
        return 2**len(s)                                                        
    return f(s[:s.find(c)], c) + f(s[s.find(c)+1:], c)

ans = 1
for i in range(N):
    ans += f(S[:i], S[i])
print(ans)

Submission status: Runtime Error

Solution code:
num = int(input())
arr = [0] * 26
x = input()
words = list(x)

temp = 0
for i in range(num):
    temp = ord(words[i]) - 97
    arr[temp] += 1

tmp  = 1
for i in range(num):
    tmp *= (arr[i] + 1)

print(tmp-1)

Submission status: Runtime Error

Solution code:
import collections
N = int(input())
l = list(input())
c = collections.Counter(l)
m = 1
for k, v in c.items():
    m *= (v + 1)
print(m - 1)
import collections
N = int(input())
l = list(input())
c = collections.Counter(l)
m = 1
for k, v in c.items():
    m *= (v + 1)
m = m - 1
m = m % (10^9 + 7)
import collections
N = int(input())
l = list(input())
c = collections.Counter(l)
m = 1
for k, v in c.items():
    m *= (v + 1)
print(m - 1)
import collections
N = int(input())
l = list(input())
c = collections.Counter(l)
m = 1
for k, v in c.items():
    m *= (v + 1)
m = m - 1
m = m % (10^9 + 7)
print(m)

Submission status: Runtime Error

Solution code:
import collections
N = int(input())
l = list(input())
c = collections.Counter(l)
m = 1
for k, v in c.items():
    m *= (v + 1)
print(m - 1)
import collections
N = int(input())
l = list(input())
c = collections.Counter(l)
m = 1
for k, v in c.items():
    m *= (v + 1)
m = m - 1
m = m % (10^9 + 7)

Submission status: Runtime Error

Solution code:
# 2019/03/16
# AtCoder Grand Contest 031 - A

# Input
n = int(input())
s = input()

aprcnt = [1] * 26

# Count up Alphabets
for idx in range(n):
    w_idx = ord(s[idx]) - 97
    aprcnt[w_idx] += 1

# Calc Combination count
ans = 1
for idx in range(n):
    ans = ans * aprcnt[idx]

# Reduces 1 in choose nothing case
ans -= 1

# Output
print(ans)

Submission status: Runtime Error

Solution code:
s = list(input())

import collections

t = s.values()

x = len(t)

r = 1

for i in range(x):
    r = (r*(t[i]+1))%(10**9+7)
print(r+1)

Submission status: Runtime Error

Solution code:
nCr={}
def cmb(n, r):
  if r==0 or r==n:
    return 1
  if r==1 or n-r==1:
    return n
  if (n,r) in nCr:
    return nCr[(n,r)]
  nCr[(n,r)] = cmb(n-1,r)+cmb(n-1,r-1)
  return nCr[(n,r)]

N=int(input())
S=input()
ans=N
for r in range(2, N+1):
  ans+=cmb(N, r)

str_num = {i: S.count(i) for i in set(S) if S.count(i) > 1}
for s, n in str_num.items():
  ans -= 2**(N-n)
if len(str_num) > 1:
  ans += 2**(N-sum(str_num.values()))

print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
S=input()
ans=N
for i in range(2, N+1):
  sub=[x for x in list(itertools.combinations(S, i)) if len(x) == len(set(x))]
  ans+=len(sub)
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
S=input()
ans=N
for i in range(2, N+1):
  sub=[x for x in list(itertools.combinations(S, i)) if len(x) == len(set(x))]
  ans+=len(sub)
  print(sub, ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
from functools import reduce
 
def counter(list_1):
	return ((reduce(lambda a,b:a*b,map(lambda x:x+1,list_1))-1)%(10**9+7))
  
N=input()
S=input()
answer=counter(Counter(S))
print(answer)

Submission status: Runtime Error

Solution code:
from collections import Counter
from functools import reduce
 
def counter(list_1):
	return ((reduce(lambda a,b:a*b,map(lambda x:x+1,list_1))-1)%(10**9+7))
  
N=input()
S=list(input())
answer=counter(S)
print(answer)

Submission status: Runtime Error

Solution code:
from collections import Counter
 
def counter(list_1):
	return (reduce(lambda a,b:a*b,map(lambda x:x+1,list_1))-1)%(10**9+7)
  
N=input()
S=list(input())
answer=counter(S)
print(answer)

Submission status: Runtime Error

Solution code:
from collections import Counter
 
def counter(list_1):
	return reduce(lambda a,b:a*b,map(lambda x:x+1,list_1))

N=input()
S=list(input())
answer=counter(S)
print(answer)

Submission status: Runtime Error

Solution code:
from collections import Counter
 
def counter(list_1):
	return reduce(lambda a,b:a*b,map(lambda x:x+1,list_1))

N=input()
S=list(input())
answer=counter(s)
print(answer)

Submission status: Runtime Error

Solution code:
from collections import Counter

def counter(list_1):
	return reduce(lambda a,b:a*b,map(lambda x:x+1,list_1))

if __name__ == '__main__':
  N=input()
  S=list(input())
  answer=counter(s)
  print(answer)

Submission status: Runtime Error

Solution code:
N=int(input())
S=list(map(lambda x: ord(x),input()))
MOD = 10e9 + 7


# 各文字列について、出現回数+1(1つ取るか、一切とらない)
# それを全部かければ良い

AppearCount = [ 0 for _ in range(26)]

for n in range(N):
	AppearCount[S[n]-ord('a')] += 1

ans = 1

for n in range(N):
	if AppearCount[n] != 0:
		ans *= (AppearCount[n]+1)
		if MOD <= ans:
			ans -= MOD

print(ans-1)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

import sys

def parse_input(lines_as_string = None):


    lines = []
    if lines_as_string is None:
        lines.append(input())
        lines.append(input())
    else:
        lines = [e for e in lines_as_string.split("\n")][1:-1]
 
    tokens = lines[0].split(" ")
    n = int(tokens[0])
    tokens = lines[1].split(" ")
    s = tokens[0]

    return (n, s)


def solve(n, s):

    d = dict([(c, 0) for c in "abcddfghijklmnopqrstuvwxyz"])

    for c in s:
        d[c] = d[c] + 1

    count = 1
    for v in [v for v in d.values() if v > 0]:
        count = count * (v+1)
    

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

def main():
    # 出力

    print("%s" % solve(*parse_input()))

if __name__ == '__main__':

    main()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

import sys

def parse_input(lines_as_string = None):


    lines = []
    if lines_as_string is None:
        lines.append(input())
        lines.append(input())
    else:
        lines = [e for e in lines_as_string.split("\n")][1:-1]
 
    tokens = lines[0].split(" ")
    n = int(tokens[0])
    tokens = lines[1].split(" ")
    s = tokens[0]

    return (n, s)


def solve(n, s):

    d = dict([(c, 0) for c in "abcddfghijklmnopqrstuvwxyz"])

    for c in s:
        d[c] = d[c] + 1

    count = 1
    for v in [v for v in d.values() if v > 0]:
        count = count * (v+1)
    

    return count - 1

def main():
    # 出力

    print("%s" % solve(*parse_input()))

if __name__ == '__main__':

    main()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

import sys

def parse_input(lines_as_string = None):


    lines = []
    if lines_as_string is None:
        lines.append(input())
        lines.append(input())
    else:
        lines = [e for e in lines_as_string.split("\n")][1:-1]
 
    tokens = lines[0].split(" ")
    n = int(tokens[0])
    tokens = lines[1].split(" ")
    s = tokens[0]

    return (n, s)


def solve(n, s):

    d = dict([(c, 0) for c in "abcddfghijklmnopqrstuvwxyz"])

    for c in s:
        d[c] = d[c] + 1

    count = 1
    for v in d.values():
        count = count * (v+1)
    

    return count - 1

def main():
    # 出力

    print("%s" % solve(*parse_input()))

if __name__ == '__main__':

    main()

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
for t in range(int(input())):
	s=input()
	freq=[0]*(26)
	ct=0
	for i in range(len(s)):
		freq[ord(s[i])-ord('a')]+=1
		if freq[ord(s[i])-ord('a')]==1:
			ct+=1
	ans=1
	for i in range(26):
		if freq[i]>0:
			ans=(ans*(freq[i]+1))
	print((ans-1)%1000000007)

Submission status: Runtime Error

Solution code:
# test for NO is correct 
N,A,B= list(map(int,input().split()))
B1 = A^B


from collections import defaultdict
d = defaultdict(list)
for i in range(2**N):
    bits_total = bin(i)[2:].count('1')
    d[bits_total].append(i)
def count_bits(n):
    return bin(n)[2:].count('1')

def int_to_bin(n):
    return list(reversed(list((map(lambda x:x=='1',bin(n)[2:])))))+[0]*N
def bin_to_int(V):
    ans = 0
    for i,val in enumerate(V):
        ans += val *(2 **i)
    return ans

assert bin_to_int([1])==1
assert bin_to_int([0,1])==2

def movable(i):
    res = set()
    for bit_num in range(N):
        if i>= 2**bit_num and bin(i)[2:][-bit_num-1]=='1':
            res.add(i - 2**bit_num)
        else:
            res.add(i+2**bit_num)
    return res

used = set()
i=0
next = -1
used.add(0)
order = [0]
try:
    while len(used) < 2**N:
        next = max(movable(i) - used)
        used.add(next)
        i=next
        order.append(i)
except:
    print("NO")
    exit()

if count_bits(next)!= count_bits(B1):
    print("NO")
    exit()
raise


def find_all(x):
    res = []
    for bit_num in range(N):
        if x>= 2**bit_num and bin(x)[2:][-bit_num-1]=='1':
            res.append(bit_num)
    return res
a= find_all(B1)
b= find_all(next)

def convert(x,p,q):
    V = int_to_bin(x)
    for i in range(len(p)):
        tmp = V[p[i]]
        V[p[i]]=V[q[i]]
        V[q[i]]= tmp
    return bin_to_int(V)

print("YES")
print(" ".join([str(convert(n,a,b) ^A) for n in order]))

Submission status: Runtime Error

Solution code:
from collections import Counter
N = int( input())
S = int( input())
Q = 10**9+7
C = Counter(S)
ans = 1
for c in C:
    ans *= C[c]+1
    ans %= Q
print((ans-1)%Q)

Submission status: Runtime Error

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


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

U = list(map(lambda x:x+1, U))
print(np.array(U).prod()-1)

Submission status: Runtime Error

Solution code:
import collections

n = int(input())
s = raw_input()
cnt = 0
dictionary = {}

for i in range(n)[::-1]:
  if s[i] in dictionary.keys():
    dictionary[s[i]] += 1
  else:
    dictionary[s[i]] = 1
  ch = s[i:]
  tmp_cnt = 1
  for k,v in dictionary.items():
    if k != s[i]:
      tmp_cnt *= (v+1)
  cnt += tmp_cnt %(10**9+7)
print(cnt%(10**9+7))

Submission status: Runtime Error

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

dp = [0] * (N+1)
A = [0] * 256

for i in range(N):
    A[ord(S[i])] = A[ord(S[i])] + 1
    count = A[S[i]]
    dp[i+1] = dp[i] + dp[i]/count + 1

print(dp[N]%1000000007)

Submission status: Runtime Error

Solution code:
import math
import copy
 
 
 
 
def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:
 
            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l
 

n=input()
s=input()

mod=int(math.pow(10, 9)+7)
def help1(a):
    all=0
    a1=1
    b1=1
    while a!=0:
        a1=a1*a;
        if(b1!=0): 
            a1=a1/b1;
        b1+=1
        a=a-1
        all=(all+a1)%mod
    return int(all)

def func():
    count=help1(len(s))
    dic={}

    for c in s:
        if c in dic:
            dic[c]=dic[c]+1
        else:
            dic[c]=1
    res=len(s)
    l=[]
    for k in dic:
        if dic[k]==1:
            l.append(k)
    for obj in l:
        del dic[obj]
        
    count2=1
    sum1=0
    for k in dic:
        sum1+=dic[k]
        count2=count2*(1+dic[k])



    number3=help1(sum1)-count2+1

    number4=help1(len(s)-sum1)+1

    number3=number3*number4
    return count-number3
  

print(func())

Submission status: Runtime Error

Solution code:
import itertools

N = int(input())
String_List = list(input())
#print(String_List)
total_number = 2 ** N -1

pair = len(String_List) - len(set(String_List))
if pair != 0:
    global last
    last = 2 ** (len(String_List) - 2) * pair - ((pair-1)* (len(String_List)-pair*2)*2)
else:
    last = 0

print(total_number - last　% (10**9 +7)

Submission status: Runtime Error

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

dp = [0] * (N+1)
A = [0] * 256

for i in range(N):
    A[int(S[i])] = A[int(S[i])] + 1
    count = A[S[i]]
    dp[i+1] = dp[i] + dp[i]/count + 1

print(dp[N]%1000000007)

Submission status: Runtime Error

Solution code:
import math
import copy
 
 
 
 
def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:
 
            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l
 

n=input()
s=input()

mod=int(math.pow(10, 9)+7)
def help1(a):
    all=0
    a1=1
    b1=1
    while a!=0:
        a1=a1*a;
        if(b1==0): 
            break
        a1=a1/b1;
        b1+=1
        a=a-1
        all=(all+a1)%mod
    return int(all)

def func():
    count=help1(len(s))
    dic={}

    for c in s:
        if c in dic:
            dic[c]=dic[c]+1
        else:
            dic[c]=1
    res=len(s)
    l=[]
    for k in dic:
        if dic[k]==1:
            l.append(k)
    for obj in l:
        del dic[obj]
        
    count2=1
    sum1=0
    for k in dic:
        sum1+=dic[k]
        count2=count2*(1+dic[k])



    number3=help1(sum1)-count2+1

    number4=help1(len(s)-sum1)+1

    number3=number3*number4
    return count-number3
  

print(func())

Submission status: Runtime Error

Solution code:
import math
import copy
 
 
 
 
def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:
 
            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l
 

n=input()
s=input()

mod=int(math.pow(10, 9)+7)
def help1(a):
    all=0
    a1=1
    b1=1
    while a!=0:
        a1=a1*a;
        a1=a1/b1;
        b1+=1
        a=a-1
        all=(all+a1)%mod
    return int(all)

def func():
    count=help1(len(s))
    dic={}

    for c in s:
        if c in dic:
            dic[c]=dic[c]+1
        else:
            dic[c]=1
    res=len(s)
    l=[]
    for k in dic:
        if dic[k]==1:
            l.append(k)
    for obj in l:
        del dic[obj]
        
    count2=1
    sum1=0
    for k in dic:
        sum1+=dic[k]
        count2=count2*(1+dic[k])



    number3=help1(sum1)-count2+1

    number4=help1(len(s)-sum1)+1

    number3=number3*number4
    return count-number3
  

print(func())

Submission status: Runtime Error

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

dp = [0] * N+1
A = [0] * 256

for i in range(N):
    A[S[i]] = A[S[i]] + 1
    count = A[S[i]]
    dp[i+1] = dp[i] + dp[i]/count + 1

print(dp[N]%1000000007)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [[] for row in range(200000)]
b = 0
e = [int(input()) for i in range(n)]
d = [0]
mini_ans = 0
for i,c in enumerate(e):
  if b != c:
    for j in a[c]:
      mini_ans += d[j] + 1
    a[c].append(i)
  d.append(mini_ans)
  b = c
print(d[-1]+1)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from itertools import combinations
N = int(input())
S = list(input())

kaisu = range(N+1)
subsets = [subsets.append(len(t) == len(set(t))) for i in kaisu for t in combinations(S, i)]
        
print((len(subsets) - 1) % (10**9+7))

Submission status: Runtime Error

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

dp = [0] * N+1
A = [0] * 256

for i in range(N):
  A[S[i]]++
  count = A[S[i]]
  dp[i+1] = dp[i] + dp[i]/count + 1
  
print(dp[N]%1000000007)

Submission status: Runtime Error

Solution code:
import math
import copy
 
 
 
 
def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:
 
            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l
 

n=input()
s=input()

mod=1000000007
def help1(a):
    all=0
    a1=1

    
    b1=1
    while a!=0:
        a1=a1*a;
        a1=a1/b1;
        b1+=1
       
        a=a-1
        all=(all+a1)%mod
    return int(all)

def func():
    count=help1(len(s))
    dic={}

    for c in s:
        if c in dic:
            dic[c]=dic[c]+1
        else:
            dic[c]=1
    res=len(s)
    l=[]
    for k in dic:
        if dic[k]==1:
            l.append(k)
    for obj in l:
        del dic[obj]
        
    count2=1
    sum1=0
    for k in dic:
        sum1+=dic[k]
        count2=count2*(1+dic[k])



    number3=help1(sum1)-count2+1

    number4=help1(len(s)-sum1)+1

    number3=number3*number4
    return count-number3
  

print(func())

Submission status: Runtime Error

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

used_list = []
num = 0
a = 10**9 +7 

def DFS(i,used_list,num):
    if i == N:
        num += 1
        num = num % a
        return num

    s = S[i]
    # S[i]を使わない場合
    num = DFS(i+1,used_list,num) % a

    # S[i]を使う場合
    if s not in used_list:
        used_list.append(s)
        num=DFS(i+1,used_list,num) % a

        used_list.pop(-1)
    return num
    
       
ans = DFS(0,used_list,num)
ans = ans-1

print(ans)

Submission status: Runtime Error

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

dp = [0] * N+1
A = [0] * 256

for i in range(N):
  A[S[i]]++
  count = A[S[i]]
  dp[i+1] = dp[i] + dp[i]/count + 1
  
print(dp[N]%1000000007)

Submission status: Runtime Error

Solution code:
import math

n, s = input().split()
N = int(n)
S = [str(i) for i in s] 

counter = [0] * 26
alp = ['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 i in range(26):
    counter[i] = S.count(alp[i])

syu = 0
for i in range(26):
    if counter[i] > 0:
        syu += 1

ans = 0
for k in range(1,syu+1):
    ans += math.factorial(N) // (math.factorial(N - k) * math.factorial(k))
    #print(ans)

for a in range(26):
    num = counter[a]
    mod = N - num 
    if num == 2:
        ans -= num - 1
        for k in range(3,syu+1):
            #print(k)
            ans -= math.factorial(mod) // (math.factorial(mod - k+num) * math.factorial(k-num))
    if num > 2:
        itr = math.factorial(num) // (math.factorial(num - 2) * math.factorial(2))
        ans -= (num - 1) * itr
        for k in range(3,syu+1):
            itr = math.factorial(num) // (math.factorial(num - k) * math.factorial(k))
            ans -= (math.factorial(mod) // (math.factorial(mod - k+num) * math.factorial(k-num)))*itr

print(ans)

Submission status: Runtime Error

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

used_list = []
num = 0
a = 10**9 +7 

def DFS(i,used_list,num):
    if i == N:
        num += 1
        return num

    s = S[i]
    # S[i]を使わない場合
    num = DFS(i+1,used_list,num) % a

    # S[i]を使う場合
    if s not in used_list:
        used_list.append(s)
        num=DFS(i+1,used_list,num) % a

        used_list.pop(-1)
    return num
    
       
ans = DFS(0,used_list,num)
ans = (ans-1) % a

print(ans)

Submission status: Runtime Error

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

used_list = []
num = 0
a = 10**9 +7 

def DFS(i,used_list,num):
    if i == N:
        num += 1
        return num

    s = S[i]
    # S[i]を使わない場合
    num = DFS(i+1,used_list,num)

    # S[i]を使う場合
    if s not in used_list:
        used_list.append(s)
        num=DFS(i+1,used_list,num)

        used_list.pop(-1)
    return num
    
       
ans = DFS(0,used_list,num)
ans = (ans-1) % a

print(ans)

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(33554432)

def a(miteru: str, nokori: str) -> int:
    if sorted(list(miteru)) == sorted(list(set(miteru))):
        if len(nokori) == 0:
            return 1
        else:
            return a(miteru, nokori[1:]) + a(miteru + nokori[0], nokori[1:])
    else:
        return 0


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

ans = 0
if n==0:
    print(0)
elif n==1:
    print(1)
else:
    ans = a('', s[1:]) + a(s[0], s[1:])
    print((ans - 1) % 1000000007)