Problem p03095 (python)

Fixed submission:
import math
import copy
from collections import Counter
 
 
 
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=7+10**9


def func():

    dic = Counter(s)
    ans = 1
    for x in dic:
        ans = ans*(dic[x]+1)%mod
    return ans-1
    
print(func())

Buggy submission (verdict: Runtime Error):
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())

Buggy submission (verdict: Runtime Error):
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())

Buggy submission (verdict: Runtime Error):
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())

Buggy submission (verdict: Runtime Error):
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())

Buggy submission (verdict: Runtime Error):
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
    a2=1
    
    b1=1
    while a!=0:
        a1=a1*a
        a2=a2*b1
        b1+=1
        tmp=(int)(a1/a2)
        a=a-1
        all=(all+tmp)%mod
    return 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())

Buggy submission (verdict: Runtime Error):

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
    a2=1
    
    b1=1
    while a!=0:
        a1=a1*a
        a2=a2*b1
        b1+=1
        tmp=(int)(a1/a2)
        a=a-1
        all=(all+tmp)%mod
    return 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
    for k in dic:
        if dic[k]>1:

            count=(count+mod-(help1(dic[k])+mod-dic[k])*help1(len(s)-dic[k])%mod)%mod
    return count
  

print(func())