Problem:


				Max Score: 250 Points 

Problem Statement

					Mr.X, who the handle name is T, looked at the list which written N handle names, S_1, S_2, ..., S_N. 

					But he couldn't see some parts of the list. Invisible part is denoted ?. 

					Please calculate all possible index of the handle name of Mr.X when you sort N+1 handle names (S_1, S_2, ..., S_N and T) in lexicographical order. 

					Note: If there are pair of people with same handle name, either one may come first. 

Input

						The input is given from standard input in the following format.

N
S_1
S_2
 :
S_N
T

Output

Calculate the possible index and print in sorted order. The output should be separated with a space. Don't print a space after last number.

Put a line break in the end.

Constraints

1 ≤ N ≤ 10000

1 ≤ |S_i|, |T| ≤ 20 (|A| is the length of A.)

S_i consists from lower-case alphabet and ?.

T consists from lower-case alphabet.

Scoring

Subtask 1 [ 130 points ]

There are no ?'s.

Subtask 2 [ 120 points ]

There are no additional constraints.

Sample Input 1

2
tourist
petr
e

Sample Output 1

1

					There are no invisible part, so there are only one possibility.
					The sorted handle names are e, petr, tourist, so e comes first.

Sample Input 2

2
?o?r?s?
?et?
e



Sample input:
2
tourist
petr
e


Sample output:
1

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
 
a = list(map(int, input().split()))
 
min_cost = float("inf")
for i in range(2**n):
    if bin(i).count("1") != k:
        continue
 
    min_h = a[0]
    cost = 0
    for j in range(1, n):
        if i >> j & 1:
            min_h += 1
            cost += max(0, min_h-a[j])
 
        min_h = max(min_h, a[j])
 
    min_cost = min(min_cost, cost)
 
print(min_cost)

Submission status: Runtime Error

Solution code:
n,k = list(map(int, input().split()))
a=list(map(int, input().split()))

ans=[]
    


for i in range(1<<n):
    
    if bin(i).count("1")==k:
        cst=0
        use=a.copy()
        for u in range(1,n):
            if(i>>u&1):
                left_max=max(use[:u])
                cst+=left_max-use[u]+1
                use[u]= left_max+1
        ans.append(cst)   
print(min(ans))

Submission status: Runtime Error

Solution code:
def LI(): return list(map(int,input().split()))
N,K = LI()
a = LI()
ans = float('INF')
for i in range(2**(N-1)):
    bit = [i>>j&1 for j in range(N-1)]
    if K-1!=sum(bit):
        continue
    cost,kijun = 0,a[0]
    for k in range(N-1):
        if bit[k]==0:
            kijun = max(kijun,a[k+1])
        else:
            if a[k+1]>=kijun+1:
                kijun = a[k+1]
                continue
            cost += (kijun+1)-a[k+1]
            kijun += 1
    ans = min(ans,cost)
print(ans)

Submission status: Runtime Error

Solution code:
#recursion-version

#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_5_A&lang=jp
#http://penguinshunya.hatenablog.com/entry/2019/07/09/003006

import sys
sys.setrecursionlimit(10000)

inpPh = 0
debug = True
#debug = False
if not debug:
    inpPh = 0

input1 ='''
4
1 2
2 3
2 4
'''[1:]

input2 ='''
4
1 2
2 4
4 3
'''[1:]

input1bk ='''
4
0 1 2
1 2 1
1 3 3
'''[1:]



#input1 = input2

output1_2='''
5 7
'''

inputXs = [input1, input2,None]

if debug:
    try:
        inputXs.append(inputA0)
    except:
        pass
    else:
        pass

inploc = inpPh - 1 #0,1,2

if inpPh > 0:
    #print('selected_input:\n'+inputXs[inploc])
    #print('')
    pass

inpX_lst = []
if debug and inpPh > 0:
    inpX_lst = inputXs[inploc].splitlines()


if inpPh ==0:
    n = int(input())
else:
    n = int(inpX_lst.pop(0) )

st_list = []
noe_vwise = [0 for _ in range(n)]

for i in range(n-1):
    if inpPh ==0:
        si,ti = tuple(map(lambda x: int(x), input().split() ) )
    else:
        si,ti = tuple(map(lambda x: int(x), inpX_lst.pop(0).split() ) )
    
    noe_vwise[si-1] += 1
    #noe_vwise[ti-1] += 1
    st_list.append((si-1,ti-1))

#print(st_list)

from collections import namedtuple
INF = float('inf')

Edge = namedtuple('Edge', ['to', 'value'])
def Edge(x,y):
    return (x,y)

def reroot(n, es_vwise, dp_es_vwise, e_init, noe_vwise, pe_vwise):

    def dfs1(v,v_par):
        nonlocal es_vwise, dp_es_vwise, e_init, vpar_v, noe_vwise
        stack = [(v,v_par)]
        while stack:
            (v,v_par) = stack.pop()
        
        #print('es_vwise[v]',v,es_vwise[v])
        ret = e
        #ret = Edge(-INF,-INF)
        ret = (0, 0)
        
        for i in range(len(es_vwise[v]) ):
            e_local = es_vwise[v][i]
            if (e_local[0] == v_par):
                print('this-part should not be printed')
                vpar_v[v] = i
                continue
            
            dp_es_vwise[v][i] = lift(dfs1(e_local[0], v), e_local[1]  )
            #dp_es_vwise[v][i] = lift(dfs1(e_local[0], v), e_local[1] )
            ret = merge(ret, dp_es_vwise[v][i] )
        return ret

    def dfs2(v, t):
        # bundlable_parental_edge = t
        nonlocal ans, es_vwise, dp_es_vwise, vpar_v, e_init, noe_vwise
        nonlocal pe_vwise
        
        if (vpar_v[v] is not None):
            pass
            #lift(parental_edge, gparental_edge)
            #dp_es_vwise[v][vpar_v[v]] = lift(t,es_vwise[v][vpar_v[v]][1] )
        
        l = len(es_vwise[v])
        dpl = [e_init for i in range(l+1) ]
        dpr = [e_init for i in range(l+1) ]
     
        if (pe_vwise[v] is not None):
            v0, v1, w = pe_vwise[v]            
            dpr[l] = lift(t,w)    
    
        for i in range(l):
            dpl[i+1] = merge(dpl[i], dp_es_vwise[v][i])
        for i in range(l-1,-1,-1):
            dpr[i] = merge(dpr[i+1], dp_es_vwise[v][i])
            #l: 0->1, l-1->l
            #r: l->l-1, 1->0

        ans[v] = dpr[0]

        for i in range(l):
            if (i == vpar_v[v]):
                print('continue, l',0)
                continue
            u = es_vwise[v][i][0]
                
            dfs2(u, merge(dpl[i], dpr[i+1]) )

    def lift(a,w):
        if a[1] == 0:
            return (w,1)
        
        return ( (a[0] / a[1]) + w, 1)
        #w is 1, though...
        #return Edge(max(0,a[0]) +w, -INF)
    
    def merge(a,b):
        # print("merge:",a,b)
        return (a[0] + b[0], a[1]+b[1])

    nov = n
    vpar_v = [None for i in range(nov)]
    vpar_v0 = [None for i in range(nov)]
    
    for i in range(len(es_vwise)):
        for e in es_vwise[i]:
            vpar_v0[e[0]] = i
    
    ans = [Edge(0,-INF) for i in range(nov)]
    
    dfs1(0,None)   
    #0 must be root?
    dfs2(0,None)
    ret = 0
    
    for i in range(len(ans)):
        #print(f'i:{i} ans:{ans[i]}')
        print(float(ans[i][0] / ans[i][1]))

    return ans


class reroot_init:
    def __init__(self,n,noe_vwise):
        self.n = n
        self.es_vwise = [ [] for i in range(n)]
        self.dp_es_vwise = [ [] for i in range(n)]
        self.pe_vwise = [ None for i in range(n)]
        
        parental_edge_vwise = self.pe_vwise
    
    def movemain(self):
        reroot(n,self.es_vwise, self.dp_es_vwise, (-INF,-INF), noe_vwise, {})

def main():
    rri = reroot_init(n, noe_vwise)
    es_vwise = [ [] for i in range(n)]
    dp_es_vwise = [ [] for i in range(n)]
    pe_vwise = [ None for i in range(n)]    
    
    edges_vwise = es_vwise ; parental_edge_vwise = pe_vwise

    def v_add_edge(v,u,w):
        es_vwise[v].append((u,w))
        dp_es_vwise[v].append((0, -INF))
    
    for st in st_list:
        s,t = st
        #print(stw)
        v_add_edge(s,t,1)
        pe_vwise[t] = (s,t,1)
        
    e_init = (0,0)

    reroot(n, es_vwise, dp_es_vwise, e_init, noe_vwise, pe_vwise)

main()

Submission status: Runtime Error

Solution code:
n=int(input())
s = [input()for _ in range(n)]
t = input()
s += t
a = s.copy()
z = s.copy()
for i in range(n):
  a[i] = a[i].replace('?', 'a')
  z[i] = z[i].replace('?', 'z')
a.sort()
z.sort()
idx1 = z.index(t)
idx2 = a.index(t)
print(' '.join(map(str,range(idx1 + 1, idx2 + 2))))