TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: Takahashi, who is a novice in competitive programming, wants to learn M algorithms. Initially, his _understanding level_ of each of the M algorithms is 0.  Takahashi is visiting a bookstore, where he finds N books on algorithms. The i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he buys and reads it, his understanding level of the j-th algorithm will increase by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the understanding levels of the algorithms.  Takahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.

Submission attempts (in order):
import numpy as np
N,M,X = map(int,input().split())
datas = []
point = [0]*M
m = 0
max = 0
count = 0
for i in range(N):
    datas.append(list(map(int,input().split())))
print(datas)
while 1:
    for data in datas:
        if sum(data[1:-1]) > max:
            ans = count
            max = sum(data[1:-1])
        count += 1
    for i in range(M):
        point[i] += datas[ans][i+1]
    m += datas[ans][0]
    if all([x >= 10 for x in point]):
        print(m)
        break
    datas.pop(ans)
    if len(datas) == 0:
        print(-1)
        break
    max,ans,count = 0,0,0


import itertools
N,M,X = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(N)]
B = list(itertools.product([0,1], repeat=N))
sums = {}
anss = []
for i in range(N):
    for b in B:
        ans = 0
        Point = [0]*M
        count = 0
        for z in b:
            if z == 1:
                for k in range(M):
                    Point[k] += A[count][k+1]
                ans += A[count][0]
                if M == len([Point[n] for n in range(M) if Point[n] >= X]):
                    anss.append(ans)
            count += 1
if len(anss) != 0:
    print(min(anss))
else:
    print(-1)


Verdicts: Runtime Error

Accepted
Problem: Takahashi, who is a novice in competitive programming, wants to learn M algorithms. Initially, his _understanding level_ of each of the M algorithms is 0.  Takahashi is visiting a bookstore, where he finds N books on algorithms. The i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he buys and reads it, his understanding level of the j-th algorithm will increase by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the understanding levels of the algorithms.  Takahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.

Submission attempts (in order):
import itertools

N, M, X = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(N)]
list_N = [i for i in range(N)]

ans = []
for num_book in range(1, N + 1):
    for i in itertools.combinations(list_N, num_book):
        #print(i)
        temp = 0
        for j in range(1, M + 1):
            sum_line = sum([s[i[k]][j] for k in range(num_book)])
            if sum_line < X:
                break
            temp += 1
            if temp == M:
                score=sum([s[i[k]][0] for k in range(num_book)])
                #print(score)
                ans.append(score)
    #if len(ans) != 0:
    #    break
if len(ans)==0:
    print(-1)
else:
    print(ans)
    print(min(ans))

import itertools

N, M, X = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(N)]
list_N = [i for i in range(N)]

ans = []
for num_book in range(1, N + 1):
    for i in itertools.combinations(list_N, num_book):
        #print(i)
        temp = 0
        for j in range(1, M + 1):
            sum_line = sum([s[i[k]][j] for k in range(num_book)])
            if sum_line < X:
                break
            temp += 1
            if temp == M:
                score=sum([s[i[k]][0] for k in range(num_book)])
                #print(score)
                ans.append(score)
    #if len(ans) != 0:
    #    break
if len(ans)==0:
    print(-1)
else:
    #print(ans)
    print(min(ans))


Verdicts: Wrong Answer

Accepted
Problem: Takahashi, who is a novice in competitive programming, wants to learn M algorithms. Initially, his _understanding level_ of each of the M algorithms is 0.  Takahashi is visiting a bookstore, where he finds N books on algorithms. The i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he buys and reads it, his understanding level of the j-th algorithm will increase by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the understanding levels of the algorithms.  Takahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.

Submission attempts (in order):
n,k=map(int,input().split())
l=list(map(int,input().split()))
list=[l[0]]
num=0
while True:
  if l[list[num]-1] in list:
    break
  list.append(l[list[num]-1])
  num+=1
y=list.index(l[list[num]-1])
x=len(list)-y
ans=list[y:]
print(ans[(k-y)%x-1])
n,k=map(int,input().split())
l=list(map(int,input().split()))
list=[l[0]]
num=0
while True:
  if l[list[num]-1] in set(list):
    break
  list.append(l[list[num]-1])
  num+=1
y=list.index(l[list[num]-1])
x=len(list)-y
ans=list[y:]
print(ans[(k-y)%x-1])
提出情報 


import itertools
n,m,x=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
sum=[0]*m
for i in range(n):
  for j in range(1,m+2):
    sum[j]+=l[i][j]
for ss in sum:
  if ss<x:
    print(-1)
    exit()
list=[]
for p in itertools.product([1,0],n)
  cnt=[0]*m
  ans=0
  for i in range(n):
    if p[i]==1:
      ans+=l[i][0]
      list.append(ans)
      for j in range(1,m+1)
        cnt[j]+=l[i][j]
print(min(list))

import itertools
n,m,x=map(in,input().split())
l=[list(map(int,input().split())) for i in range(n)]
costl=[]
for p in itertools.product([0,1],n):
  al=[0]*m
  cost=0
  for i in range(n):
    if p[i]==1:
      cost+=l[i][0]
      for j in range(1,m):
        al[j-1]+=l[i][j]
  if all(mm>=x for mm in m):
    costl.append(cost)
print(min(cost))
      
        
      

import itertools
n,m,x=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
costl=[]
for p in itertools.product([0,1],repeat=n):
  al=[0]*m
  cost=0
  for i in range(n):
    if p[i]==1:
      cost+=l[i][0]
      for j in range(1,m+1):
        al[j-1]+=l[i][j]
  if all(mm>=x for mm in al):
    costl.append(cost)
print(min(costl) if len(costl)>=1 else -1)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: Takahashi, who is a novice in competitive programming, wants to learn M algorithms. Initially, his _understanding level_ of each of the M algorithms is 0.  Takahashi is visiting a bookstore, where he finds N books on algorithms. The i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he buys and reads it, his understanding level of the j-th algorithm will increase by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the understanding levels of the algorithms.  Takahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.

Submission attempts (in order):
n, m, x = map(int, input().split())
prace = []
know = []
for i in range(n):
    acc = list(map(int, input().split()))
    prace.append(acc[0])
    know.append(acc[1:])

ans = 10**10
for i in range(2**n):
    und = [0 for i in range(m)]
    f = "{:b}".format(i)
    s = f.zfill(n)
    mm = 0
    print(s)
    for j in range(len(s)):
        if s[j] == '1':
            for k in range(m):
                und[k] += know[j][k]
            mm += prace[j]
    for j in range(m):
        if und[j] < x:
            break
    else:
        ans = min(ans, mm)
if ans == 10**10:
    print(-1)
else:
    print(ans)


n, m, x = map(int, input().split())
prace = []
know = []
for i in range(n):
    acc = list(map(int, input().split()))
    prace.append(acc[0])
    know.append(acc[1:])

ans = 10**10
for i in range(2**n):
    und = [0 for i in range(m)]
    f = "{:b}".format(i)
    s = f.zfill(n)
    mm = 0
    for j in range(len(s)):
        if s[j] == '1':
            for k in range(m):
                und[k] += know[j][k]
            mm += prace[j]
    for j in range(m):
        if und[j] < x:
            break
    else:
        ans = min(ans, mm)
if ans == 10**10:
    print(-1)
else:
    print(ans)


Verdicts: Wrong Answer

Accepted
Problem: Takahashi, who is a novice in competitive programming, wants to learn M algorithms. Initially, his _understanding level_ of each of the M algorithms is 0.  Takahashi is visiting a bookstore, where he finds N books on algorithms. The i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he buys and reads it, his understanding level of the j-th algorithm will increase by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the understanding levels of the algorithms.  Takahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.

Submission attempts (in order):
import numpy as np
import itertools
n, m, x = [int(k) for k in input().split()]
c = np.zeros(n, dtype=int)
a = np.zeros((n, m), dtype=int)
rikai_a = np.zeros(m, dtype=int)
bool_c = np.full(n, False)
for i in range(n):
    c[i], *a[i] = [int(k) for k in input().split()]
cost = np.sum(c) + 1
for nn in range(1,n+1):
    for k in itertools.combinations(np.argsort(c),nn):
        k = list(k)
        cs = sum(c[k].flatten())
        if cs > cost:
            break
        print(cs)
        rikai_a = np.sum(a[k],axis=0)
        if np.all(rikai_a >= x):
            cost = min(cost,cs)
            break
if cost < np.sum(c) + 1:
    print(cost)
else:
    print(-1)

import numpy as np
import itertools
n, m, x = [int(k) for k in input().split()]
c = np.zeros(n, dtype=int)
a = np.zeros((n, m), dtype=int)
for i in range(n):
    c[i], *a[i] = [int(k) for k in input().split()]
cost = np.sum(c) + 1
for nn in range(1,n+1):
    for k in itertools.combinations(np.argsort(c),nn):
        k = list(k)
        cs = np.sum(c[k].flatten())
        if cs > cost:
            continue
        rikai = np.sum(a[k],axis=0)
        if np.all(rikai >= x):
            cost = min(cost,cs)
if cost < np.sum(c) + 1:
    print(cost)
else:
    print(-1)

Verdicts: Wrong Answer

Accepted
Problem: Takahashi, who is a novice in competitive programming, wants to learn M algorithms. Initially, his _understanding level_ of each of the M algorithms is 0.  Takahashi is visiting a bookstore, where he finds N books on algorithms. The i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he buys and reads it, his understanding level of the j-th algorithm will increase by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the understanding levels of the algorithms.  Takahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.

Submission attempts (in order):
N, M, X = map(int, input().split())
List = [list(map(int, input().split())) for n in range(N)]
INF = 10**7
ans = INF
C_pro = list(itertools.product([0,1], repeat=N))

for c_pro in C_pro:
    count = 0
    cost = 0
    ans_list = [0 for i in range(M)]
    for c in c_pro:
        if c == 1:
            cost += List[count][0]
            ans_list = [ans+list for ans, list in zip(ans_list,List[count][1:])]
        count += 1
    if ans_list >= [X for i in range(M)]:
        ans = min(ans, cost)
    

if ans == INF:
    print(-1)
else:
    print(ans)

import itertools

N, M, X = map(int, input().split())
List = [list(map(int, input().split())) for n in range(N)]
INF = 10**7
ans = INF
C_pro = list(itertools.product([0,1], repeat=N))

for c_pro in C_pro:
    count = 0
    cost = 0
    ans_list = [0 for i in range(M)]
    for c in c_pro:
        if c == 1:
            cost += List[count][0]
            ans_list = [answ+list for answ, list in zip(ans_list,List[count][1:])]
        count += 1
    ok = True
    for i in range(len(ans_list)):
        if ans_list[i] < X:
            ok = False
            break
    if ok:
        ans = min(ans, cost)
    

if ans == 10**7:
    print(-1)
else:
    print(ans)

Verdicts: Runtime Error

Accepted
Problem: Takahashi, who is a novice in competitive programming, wants to learn M algorithms. Initially, his _understanding level_ of each of the M algorithms is 0.  Takahashi is visiting a bookstore, where he finds N books on algorithms. The i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he buys and reads it, his understanding level of the j-th algorithm will increase by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the understanding levels of the algorithms.  Takahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.

Submission attempts (in order):
import itertools
N,M,X=map(int, input().split())
List=[list(map(int,input().split())) for i in range(M)]


print(List)
flag=True
i=1
champ=100000
total_cost=100000
while flag:
    newlist=list(itertools.combinations(range(N),i))
    for j in range(len(newlist)):
        for s in range(1,M+1):
            if sum(List[t][s] for t in newlist[j])<X:
                flag2=False
                break
        if flag2!=False:    
            total_cost=sum(List[t][0] for t in newlist[j])
        if total_cost<champ:
            champ=total_cost
        flag2=True
    if champ!=100000:
        print(champ)
        flag=False
        break
    i=i+1
    if i==N+1:
        break

if flag:    
    print(-1)

N,M,X=map(int, input().split())
List=[list(map(int,input().split())) for i in range(N)]



ans=10000000000000
for j in range(1,2**(N+1)-1):
    combinationlist=list(map(int, [i for i in format(2**(N+1)+j,'b')]))
    del combinationlist[0]
    sumoflist=[sum(combinationlist[s]*List[s][k] for s in range(N)) for k in range(M+1)]
    flag=True
    for t in range(1,M+1):
        if sumoflist[t]<X:
            flag=False
            break
    if flag and sumoflist[0]<ans:
        ans=sumoflist[0]

if ans!=10000000000000:
    print(ans)
else:
    print(-1)

Verdicts: Runtime Error

Accepted
Problem: Takahashi, who is a novice in competitive programming, wants to learn M algorithms. Initially, his _understanding level_ of each of the M algorithms is 0.  Takahashi is visiting a bookstore, where he finds N books on algorithms. The i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he buys and reads it, his understanding level of the j-th algorithm will increase by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the understanding levels of the algorithms.  Takahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.

Submission attempts (in order):
N, M, X = map(int, input().split(" "))
B_list = []


for Books in range(N):
    B_list.append(list(map(int, input().split(" "))))
# print(B_list)

bug = []
for k in range(M + 1):
    bug.append(0)
#print(bug)
ways = []

for way in range(2**N):
    for book in range(N):
        if ((way >> book) & 1) == 1:
            for i in range(M + 1):
                bug[i] += B_list[book][i]

    # print(bug)
    clear = [l for l in bug if l >= X]
    #print(clear)
    bug.pop(0)
    O = clear.pop(0)

    if len(bug) == len(clear):
        ways.append(O)

    bug = []
    for k in range(M + 1):
        bug.append(0)

if len(ways) == 0:
    print(-1)
else:
    print(min(ways))

N, M, X = map(int, input().split(" "))
B_list = []


for Books in range(N):
    B_list.append(list(map(int, input().split(" "))))
# print(B_list)

bug = []
for k in range(M + 1):
    bug.append(0)
print(bug)
ways = []

for way in range(2**N):
    for book in range(N):
        if ((way >> book) & 1) == 1:
            for i in range(M + 1):
                bug[i] += B_list[book][i]

    # print(bug)
    clear = [l for l in bug if l >= X]
    print(clear)
    if len(bug) == len(clear):
        ways.append(bug[0])

    bug = []
    for k in range(M + 1):
        bug.append(0)

if len(ways) == 0:
    print(-1)
else:
    print(min(ways))


N, M, X = map(int, input().split(" "))
B_list = []


for Books in range(N):
    B_list.append(list(map(int, input().split(" "))))
# print(B_list)

bug = []
for k in range(M + 1):
    bug.append(0)
# print(bug)
ways = []

for way in range(2**N):
    for book in range(N):
        if ((way >> book) & 1) == 1:
            for i in range(M + 1):
                bug[i] += B_list[book][i]

    # print(bug)
    O = bug.pop(0)
    clear = [l for l in bug if l >= X]
    # print(clear)

    if len(bug) == len(clear):
        ways.append(O)

    bug = []
    for k in range(M + 1):
        bug.append(0)

if len(ways) == 0:
    print(-1)
else:
    print(min(ways))


Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: Takahashi, who is a novice in competitive programming, wants to learn M algorithms. Initially, his _understanding level_ of each of the M algorithms is 0.  Takahashi is visiting a bookstore, where he finds N books on algorithms. The i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he buys and reads it, his understanding level of the j-th algorithm will increase by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the understanding levels of the algorithms.  Takahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.

Submission attempts (in order):
import numpy as np
n,m,x=map(int,input().split())
flg=np.zeros((m+1),dtype=int)
minimn=-1
data=np.zeros((n,m+1))
for i in range(n):
    data[i]=list(map(int,input().split()))
for i in range(2**n):
    flg=np.zeros((m+1))
    for j in range(n):
        if (i>>j)&1:
            flg+=data[j]
    if all(flg[1:]>=x):
        if minimn==-1:
          minimn=flg[0]
        elif flg[0]<minimn:
          minimn=flg[0]
print(minimn)

import numpy as np
n,m,x=map(int,input().split())
flg=np.zeros((m+1),dtype=int)
minimn=-1
data=np.zeros((n,m+1))
for i in range(n):
    data[i]=list(map(int,input().split()))
for i in range(2**n):
    flg=np.zeros((m+1))
    for j in range(n):
        if (i>>j)&1:
            flg+=data[j]
    if all(flg[1:]>=x):
        if minimn==-1:
          minimn=flg[0]
        elif flg[0]<minimn:
          minimn=flg[0]
print(int(minimn))

Verdicts: Wrong Answer

Accepted
Problem: Takahashi, who is a novice in competitive programming, wants to learn M algorithms. Initially, his _understanding level_ of each of the M algorithms is 0.  Takahashi is visiting a bookstore, where he finds N books on algorithms. The i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he buys and reads it, his understanding level of the j-th algorithm will increase by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the understanding levels of the algorithms.  Takahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.

Submission attempts (in order):
n, m, x = map(int, input().split())
C = [list(map(int, input().split())) for _ in range(n)]
 
import itertools as it
import math
 
cost = math.inf
for comb in it.chain(*(it.combinations(C, r) for r in range(1, n+1))):
    print(comb)
    print(*comb)
    c, *a = map(sum, zip(*comb))
    print(c,a)
    if c < cost and min(a) >= x:
        cost = c
 
print(-1 if cost is math.inf else cost)

n, m, x = map(int, input().split())
C = [list(map(int, input().split())) for _ in range(n)]
 
import itertools as it
import math
 
cost = math.inf
for comb in it.chain(*(it.combinations(C, r) for r in range(1, n+1))):
    c, *a = map(sum, zip(*comb))
    if c < cost and min(a) >= x:
        cost = c
 
print(-1 if cost is math.inf else cost)

Verdicts: Wrong Answer

Accepted
Problem: Takahashi, who is a novice in competitive programming, wants to learn M algorithms. Initially, his _understanding level_ of each of the M algorithms is 0.  Takahashi is visiting a bookstore, where he finds N books on algorithms. The i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he buys and reads it, his understanding level of the j-th algorithm will increase by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the understanding levels of the algorithms.  Takahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.

Submission attempts (in order):
n,m,x=map(int,input().split())
ca=[list(map(int,input().split())) for i in range(n)]
ans=0
for i in range(2**n):
    check=[0]*m
    ans_=0
    for j in range(n):
        if ((i>>j)&1):
            ans_+=ca[j][0]
            for k in range(m):
                check[k]+=ca[j][k+1]
    if all([l>=x for l in check]):
        ans=min(ans,ans_)
if ans==0:
    print(-1)
else:
    print(ans)

n,m,x=map(int,input().split())
ca=[list(map(int,input().split())) for i in range(n)]
ans=0
for i in range(2**n):
    check=[0]*m
    ans_=0
    for j in range(n):
        if ((i>>j)&1):
            ans_+=ca[j][0]
            for k in range(m):
                check[k]+=ca[j][k+1]
    if all([l>=x for l in check]):
        ans=min(ans,ans_)
if ans==0:
    print(-1)
else:
    print(ans)

n,m,x=map(int,input().split())
ca=[list(map(int,input().split())) for i in range(n)]
ans=100000000000000000
for i in range(2**n):
    check=[0]*m
    ans_=0
    for j in range(n):
        if ((i>>j)&1):
            ans_+=ca[j][0]
            for k in range(m):
                check[k]+=ca[j][k+1]
    if all([l>=x for l in check]):
        ans=min(ans,ans_)
if ans==100000000000000000:
    print(-1)
else:
    print(ans)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Takahashi, who is a novice in competitive programming, wants to learn M algorithms. Initially, his _understanding level_ of each of the M algorithms is 0.  Takahashi is visiting a bookstore, where he finds N books on algorithms. The i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he buys and reads it, his understanding level of the j-th algorithm will increase by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the understanding levels of the algorithms.  Takahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.

Submission attempts (in order):
#N, M, X = [int(n) for n in input().split()]

#CA = [list(map(int, input().split())) for n in range(N)]

#print(N,M,X)
#print(CA)

min_cost = 12*10**5


def dfs(CA, cost, skills, cur, used, min_cost):
  #Pdb().set_trace()
  #print(cur)
  skills = [skills[i] + n for i, n in enumerate(CA[cur][1:])]
  used += [cur]
  cost += CA[cur][0]
  
  if all([s >= X for s in skills]):
  	return cost
  else:
    candidates = [n for n in range(N) if n not in used]
    prev_used = used
    prev_skills = skills
    prev_cost = cost
    for i in candidates:
        min_cost = min(min_cost, dfs(CA, prev_cost, prev_skills, i, prev_used, min_cost))
  return min_cost
       

for i in range(N):
  Pdb().set_trace()
  used = []
  cost = 0
  skills = [0] * M
  min_cost = min(min_cost, dfs(CA, cost, skills, i, used, min_cost)) 

print(min_cost)

N, M, X = [int(n) for n in input().split()]

CA = [list(map(int, input().split())) for n in range(N)]

ans = 10**10

for i in range(2**N):
  cost = 0
  skills = [0] * M
  for j in range(N):
    if ((i >> j) & 1):
      #print(i, j)
      for k in range(M):
        skills[k] += CA[j][1+k]
      cost += CA[j][0]
  
  if all([n >= X for n in skills]):
  	ans = min(ans, cost)
  #print("ans", ans)
if ans == 10**10:
  print(-1)
else:
  print(ans)

Verdicts: Runtime Error

Accepted
Problem: Takahashi, who is a novice in competitive programming, wants to learn M algorithms. Initially, his _understanding level_ of each of the M algorithms is 0.  Takahashi is visiting a bookstore, where he finds N books on algorithms. The i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he buys and reads it, his understanding level of the j-th algorithm will increase by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the understanding levels of the algorithms.  Takahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.

Submission attempts (in order):
n, m, x = map(int, input().split())
book = [list(map(int, input().split())) for _ in range(n)]
choose = 1
cost_min = 1000000 * n
for i in range(2 ** n - 1):
    a_list = [0] * (m + 1)
    c = bin(choose)[2:].zfill(n)
    for j in range(n):
        if c[n - j - 1] == '1':
            a_list = [x + y for (x, y) in zip(a_list, book[j])]
    choose += 1
    print(a_list)
    for k in a_list:
        if k < x:
            break
    else:
        cost = a_list[0]
        cost_min = min(cost_min, cost)
print(cost_min)

n, m, x = map(int, input().split())
book = [list(map(int, input().split())) for _ in range(n)]
choose = 1
cost_min = 10000000 * n
for i in range(2 ** n - 1):
    a_list = [0] * (m + 1)
    c = bin(choose)[2:].zfill(n)

    for j in range(n):
        if c[n - j - 1] == '1':
            a_list = [a + b for (a, b) in zip(a_list, book[j])]
    choose += 1
    
    for k in a_list[1:]:
        if k < x:
            break
    else:
        cost_min = min(cost_min, a_list[0])

if cost_min != 10000000 * n:
    print(cost_min)
else:
    print(-1)

Verdicts: Wrong Answer

Accepted
Problem: Takahashi, who is a novice in competitive programming, wants to learn M algorithms. Initially, his _understanding level_ of each of the M algorithms is 0.  Takahashi is visiting a bookstore, where he finds N books on algorithms. The i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he buys and reads it, his understanding level of the j-th algorithm will increase by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the understanding levels of the algorithms.  Takahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.

Submission attempts (in order):
n,m,x = map(int,input().split())

lst = []
for _ in range(n):
    lst.append(list(map(int,input().split())))

lst.sort(key=lambda x: sum(x[1:]) ,reverse=True)

rikaido = [0]*m
rikaido_check1 = [0]*m

rikaido2 = [0]*m
rikaido_check2 = [0]*m

ans1 = 0
ans2 = 0

check1 = 0
for i in lst:
    for j in range(m):
        rikaido[j] += i[j+1]
        if rikaido[j] >= x:
            rikaido_check1[j] = 1
    ans1 += i[0]
    if sum(rikaido_check1) == m:
        check1 = 1
        break

lst.sort(key=lambda x: x[0])

check2 = 0
for i in lst:
    for j in range(m):
        rikaido2[j] += i[j+1]
        if rikaido2[j] >= x:
            rikaido_check2[j] = 1
    ans2 += i[0]
    if sum(rikaido_check2) == m:
        check2 = 1
        break
print(lst)
if check1 == check2 == 0:
    print("-1")
else:
    print(min(ans1,ans2))

n,m,x = map(int,input().split())
c_lst = [0]*n
a_lst = [0]*n 
for i in range(n):
    lst = list(map(int,input().split()))
    c_lst[i] = lst[0]
    a_lst[i] = lst[1:]

ryoukin = float("inf")

for i in range(2**n):
    temporary = 0
    rikaido = [0]*m
    for j in range(n):
        if i&(1<<j):
            temporary += c_lst[j]
            for k in range(m):
                rikaido[k] += a_lst[j][k]
    
    for j in rikaido:
        if j >= x:
            continue
        else:
            break 
    else:
        if temporary < ryoukin:
            ryoukin = temporary

if ryoukin != float("inf"):
    print(ryoukin)
else:
    print("-1")

Verdicts: Wrong Answer

Accepted
Problem: Takahashi, who is a novice in competitive programming, wants to learn M algorithms. Initially, his _understanding level_ of each of the M algorithms is 0.  Takahashi is visiting a bookstore, where he finds N books on algorithms. The i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he buys and reads it, his understanding level of the j-th algorithm will increase by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the understanding levels of the algorithms.  Takahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.

Submission attempts (in order):
n,m,x = map(int, input().split())
l = [list(map(int, input().split())) for i in range(n)]
ans = float('inf')

for i in range(2**n):
    sum = [0]*(M+1)
    
    for j in range(n):
        
        if ((i >> j) & 1):
            for k in range(M+1):
                sum[k] += l[j][k]
    if sum[0] < ans:
        for a in range(1,m+1):
            if sum[a] < x:
                break
            else:
                ans = sum[0]
if ans == float('inf'):
    print(-1)
else:
    print(ans)

n,m,x = map(int, input().split())
l = [list(map(int, input().split())) for i in range(n)]
ans = float('inf')

for i in range(2**n):
    sum = [0]*(m+1)
    
    for j in range(n):
        
        if (i >> j) & 1:
            for k in range(m+1):
                sum[k] += l[j][k]
    if sum[0] < ans:
        for a in range(1,m+1):
            if sum[a] < x:
                break
        else:
            ans = sum[0]
if ans == float('inf'):
    print(-1)
else:
    print(ans)

Verdicts: Runtime Error

Accepted
Problem: Takahashi, who is a novice in competitive programming, wants to learn M algorithms. Initially, his _understanding level_ of each of the M algorithms is 0.  Takahashi is visiting a bookstore, where he finds N books on algorithms. The i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he buys and reads it, his understanding level of the j-th algorithm will increase by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the understanding levels of the algorithms.  Takahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.

Submission attempts (in order):
n,m,x = map(int, input().split())
c_a = []
for i in range(n):
      c_a.append(list(map(int, input().split())))

min_sum_answer = 0
for i in range(n**2):
      min_sum = 0
      get_score = []
      for m in range(m):
         get_score.append(0)   
      for j in range(n):
            if i >> j % 2 ==1:
                  mun_sum += c_a[j][0]
                  for l in range(m):
                        get_score[l] += c_a[j][l+1]
           
      pre = 0 
      for s in range(m):
            if(get_score[s} < x):
                  pre = 1
                  break
      
      if pre == 0:
            if min_sum_answer == 0:
                  min_sum_answer = min_sum 
            elif min_sum_answer > min_sum:
                  min_sum_answer = min_sum 

if min_sum_answer == 0:
      print(-1)
else:
      print(min_sum_answer)

n,m,x = map(int, input().split())
c_a = []
for i in range(n):
      c_a.append(list(map(int, input().split())))

min_sum_answer = -1
for i in range(2**n):
      min_sum = 0
      get_score = []
      for v in range(m):
         get_score.append(0)   
      for j in range(n):
            if (i >> j) & 1 ==1:
                  min_sum += c_a[j][0]
                  for l in range(m):
                        get_score[l] += c_a[j][l+1]
     
      #print(i)
      #print(min_sum)
      pre = 0 
      for s in range(m):
            if(get_score[s] < x):
                  pre = 1
                  break
      
      if pre == 0:
            if min_sum_answer == -1:
                  min_sum_answer = min_sum 
            elif min_sum_answer > min_sum:
                  min_sum_answer = min_sum 

if min_sum_answer == 0:
      print(-1)
else:
      print(min_sum_answer)
            
                  

Verdicts: Runtime Error

Accepted
Problem: Takahashi, who is a novice in competitive programming, wants to learn M algorithms. Initially, his _understanding level_ of each of the M algorithms is 0.  Takahashi is visiting a bookstore, where he finds N books on algorithms. The i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he buys and reads it, his understanding level of the j-th algorithm will increase by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the understanding levels of the algorithms.  Takahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.

Submission attempts (in order):
import itertools
import numpy as np
N,M,X=map(int,input().split())
lista=[]
for i in range(N):
    lista.append(list(map(int,input().split())))
lista=np.array(lista)
cost=1000000000000000
judge=[X]*M
data=[k for k in range(1,N+1)]
for i in range(1,N+1):
    a=list(itertools.combinations(data,i))
    for j in a:
        clist=np.array([0]*(M+1))
        for k in j:
            clist=clist+lista[k-1]
        if all(clist[1:]>=judge):
            if clist[0]<cost:
                cost=clist[0]
                m=j
c=0
for i in m:
    c+=lista[i][0]

print(c)    

import itertools
import numpy as np
N,M,X=map(int,input().split())
lista=[]
for i in range(N):
    lista.append(list(map(int,input().split())))
lista=np.array(lista)
cost=1000000000000000
judge=[X]*M
data=[k for k in range(1,N+1)]
for i in range(1,N+1):
    a=list(itertools.combinations(data,i))
    for j in a:
        clist=np.array([0]*(M+1))
        for k in j:
            clist=clist+lista[k-1]
        if all(clist[1:]>=judge):
            if clist[0]<cost:
                cost=clist[0]
                m=j
c=0
try:
    for i in m:
        c+=lista[i-1][0]

    print(c)
except:
    print(-1) 

Verdicts: Runtime Error

Accepted
Problem: Takahashi, who is a novice in competitive programming, wants to learn M algorithms. Initially, his _understanding level_ of each of the M algorithms is 0.  Takahashi is visiting a bookstore, where he finds N books on algorithms. The i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he buys and reads it, his understanding level of the j-th algorithm will increase by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the understanding levels of the algorithms.  Takahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it.

Submission attempts (in order):
import itertools

N, M, X = list(map(int, input().split()))
a = [list( map( int, input().split() ) ) for i in range(N)]

for x in itertools.product([0,1], repeat=2):
  cost = 0
  level = [] * M
  judge = True
  ans = 1234567
  for i in range(N):
    if a[i] == 1:
      cost += a[i][0]
      level = [y + z for (y, z) in zip(level, a[i][1:])]
  for j in range(M):
    if any(level[k] < x for k in range(M)):
      judge = False
  if judge:
    ans = min(ans, cost)

if ans == 1234567:
  print(-1)
else:
  print(ans)

from itertools import product
n,m,x=map(int,input().split())
ca=[list(map(int,input().split())) for i in range(n)]
ans=100000000000000000
for i in product([0,1],repeat=n):
    check=[0]*m
    ans_=0
    for j in range(n):
        if i[j]:
            
            ans_+=ca[j][0]
            for k in range(m):
                check[k]+=ca[j][k+1]
    if all([l>=x for l in check]):
        ans=min(ans,ans_)
if ans==100000000000000000:
    print(-1)
else:
    print(ans)

Verdicts: Runtime Error

Accepted
Problem: The Kingdom of Takahashi has N towns, numbered 1 through N.  There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i.  Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there.  Help the king by writing a program that answers this question.

Submission attempts (in order):
n,k=map(int,input().split())
a=list(map(int,input().split()))
roop=[]

a.insert(0, 0)
s=1
for i in range(k):
    s=a[s]
    if(s not in roop):
        roop.append(s)
    else:
        s_first=roop.index(s)
        roop=roop[s_first:]
        k-=(s_first+1)
#        print(k,roop,s_first)
#        print(roop[k%len(roop)])
        break


n,k=map(int,input().split())
a=list(map(int,input().split()))
roop=[]
roop_set=set([])

a.insert(0, 0)
s=1
for i in range(k):
    s=a[s]
    if(s not in roop_set):
        roop.append(s)
        roop_set.add(s)
    else:
        s_first=roop.index(s)
        roop=roop[s_first:]
        k-=(s_first+1)
#        print(k,roop,s_first)
        print(roop[k%len(roop)])
        break
else:
#    print(roop,k)
    print(roop[k-1])

Verdicts: Wrong Answer

Accepted
Problem: The Kingdom of Takahashi has N towns, numbered 1 through N.  There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i.  Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there.  Help the king by writing a program that answers this question.

Submission attempts (in order):
import sys
N,K = map(int,input().split())
tele = list(map(int,input().split()))
k = 1
goal = tele[0]
miti = [1]
while (goal in miti)!=1:
    k += 1
    miti.append(goal)
    goal = tele[goal-1]
    if k == K:
        goal = tele[goal-1]
        print(goal)
        sys.exit()
print(miti)

a = miti.index(goal)
loop = k-a
ans = miti[(K-a)%loop+a]

print(ans)


import sys
N,K = map(int,input().split())
tele = list(map(int,input().split()))
k = 1
flag = [0]*N
goal = tele[0]
miti = [1]
while (flag[goal-1])!=1:
    k += 1
    miti.append(goal)
    flag[goal-1] = 1
    goal = tele[goal-1]
    if k == K:
        print(goal)
        sys.exit()

a = miti.index(goal)
loop = k-a
ans = miti[(K-a)%loop+a]

print(ans)

Verdicts: Wrong Answer

Accepted
Problem: The Kingdom of Takahashi has N towns, numbered 1 through N.  There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i.  Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there.  Help the king by writing a program that answers this question.

Submission attempts (in order):
N,K=map(int,input().split())
A=list(map(int,input().split()))
for i in range(N):
    A[i]-=1


S = [0]*N
L = []
S[0]=1
L.append(1)
count=1
pos=A[0]


if A[0]==0:
    print(1)
    exit()

for i in range(N+1):
    
    if S[pos]==0:
        count+=1
        S[pos]=count
        L.append(pos+1)
        pos=A[pos]
        
    else:
        roopcount=count-S[pos]+1
        break


if count-1>=K:
    ans=L[K+1]

else:
    K=K-(count-roopcount)
    K=K%roopcount
    ans=L[K+count-roopcount]
    
print(ans,count,roopcount)

from collections import deque

N,K=map(int,input().split())
A=list(map(int,input().split()))
if A[0]==1:
    print(1)
    exit()
if K==1:
    print(A[0])
    exit()
for i in range(N):
    A[i]-=1



S = [0]*N
L = deque()
S[0]=1
L.append(1)
count=1
pos=A[0]

for i in range(N+1):
    
    if S[pos]==0:
        count+=1
        S[pos]=count
        L.append(pos+1)
        pos=A[pos]
        
    else:
        roopcount=count-S[pos]+1
        L.append(pos+1)
        break


if count>K:
    ans=L[K]

else:
    K=K-(count-roopcount)
    K=K%roopcount
    for i in range(count-roopcount):
        ret=L.popleft()
    ans=L[K]
    
print(ans,count,L)

from collections import deque

N,K=map(int,input().split())
A=list(map(int,input().split()))
if A[0]==1:
    print(1)
    exit()
if K==1:
    print(A[0])
    exit()
for i in range(N):
    A[i]-=1



S = [0]*N
L = deque()
S[0]=1
L.append(1)
count=1
pos=A[0]

for i in range(N+1):
    
    if S[pos]==0:
        count+=1
        S[pos]=count
        L.append(pos+1)
        pos=A[pos]
        
    else:
        roopcount=count-S[pos]+1
        L.append(pos+1)
        break


if count>K:
    ans=L[K]

else:
    K=K-(count-roopcount)
    K=K%roopcount
    for i in range(count-roopcount):
        ret=L.popleft()
    ans=L[K]
    
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: The Kingdom of Takahashi has N towns, numbered 1 through N.  There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i.  Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there.  Help the king by writing a program that answers this question.

Submission attempts (in order):

n,k = map(int,input().split())
alist = list(map(int,input().split()))

town_loop = [1]
used = [-1] * n

for i in range(k):
    next_town = alist[town_loop[i]-1]

    if used[next_town-1] == -1:
        town_loop.append(next_town)
        used[next_town-1] = 1
        break
    else:
        break

loop_start = town_loop.index(next_town)
if len(town_loop) == k+1:
    print(town_loop[k])
else:
    o = len(town_loop) - loop_start
    print(town_loop[((k-loop_start) % o) + loop_start])



n,k = map(int,input().split())
alist = list(map(int,input().split()))

town_loop = [1]

for i in range(k):
    next_town = alist[town_loop[i]-1]

    try:
        loop_start = town_loop.index(next_town)
        break
    except ValueError:
        town_loop.append(next_town)
        
if len(town_loop) == k-1:
    print(town_loop[k-1])
else:
    o = len(town_loop) - loop_start
    print(town_loop[((k+1) % o) + loop_start])



n,k = map(int,input().split())
alist = list(map(int,input().split()))

town_loop = [1]
used = [-1] * n

for i in range(k):
    next_town = alist[town_loop[i]-1]

    if used[next_town-1] == -1:
        town_loop.append(next_town)
        used[next_town-1] = 1
    else:
        break

loop_start = town_loop.index(next_town)
if len(town_loop) == k+1:
    print(town_loop[k])
else:
    o = len(town_loop) - loop_start
    print(town_loop[((k-loop_start) % o) + loop_start])


Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: The Kingdom of Takahashi has N towns, numbered 1 through N.  There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i.  Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there.  Help the king by writing a program that answers this question.

Submission attempts (in order):
import sys
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = []
cnt = 0
next_town = 0

l = len(a) + 1
for j in range(l):
    if j==0:
        b.append(a[0])
        next_town = a[0]
        continue
    
    b.append(a[next_town - 1])
    next_town = a[next_town -1]
print(b)
for i in range(l):
    if b.count(i+1)==2:
        cnt = b.index(i+1)
        k -= cnt
        indexes = [p for p, x in enumerate(b) if x == i+1]
        roop_list = b[indexes[0]:indexes[1]]
        roop_num = indexes[1]-indexes[0]
        last = k %roop_num

        print(roop_list[last-1])
        sys.exit()



N, K =map(int, input().split())
A = [int(a) - 1 for a in input().split()]
idx = 0
if K<=N:
    for i in range(K):
        idx = A[idx]
    print(idx + 1)
    exit() 

t = [-1] * N
t[0] = 0
for i in range(1, N):
    idx = A[idx]
    last = i
    if t[idx] != -1:
        break
    t[idx] = i

d = i - t[idx]
K = K - i
amari = K%d

for i in range(amari):
    idx = A[idx]
print(idx + 1)
    



Verdicts: Wrong Answer

Accepted
Problem: The Kingdom of Takahashi has N towns, numbered 1 through N.  There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i.  Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there.  Help the king by writing a program that answers this question.

Submission attempts (in order):
def main():

    import sys
    input = sys.stdin.readline

    N_ko, K_kai = map(int, input().split())
    
    teleport = list(map(int, input().split()))

    index = 0
    ctr = 0
    before_ctr = 0

    Visited = []
    Visited.append(ctr)

    for i in range(N_ko + 1):

        ctr += 1
        index = teleport[index] - 1
        Visited.append(index)
        
        if (index == 0):
            FLAG = 1
            break

        if (len(Visited) != len(set(Visited))):
            FLAG = 0
            break


    if (FLAG):
        mod = K_kai % ctr
        city = 0

        for i in range(mod):
            city = teleport[city] - 1

        ans = city + 1
    
    else:
        ans = 0


    # else:
    #     cnt = 0
    #     before_ctr = 0

    
    #         cnt += 1
    #         current_index = teleport[index] - 1
            
    #         if (current_index == index):
    #             before_ctr = cnt
    #             break
        
    
    #         city = 0
            
    
    #             city = teleport[city] - 1

    #         ans = city + 1

    #     else:
    #         ans = (K_kai - before_ctr) % (ctr - before_ctr)
    #         ans += 1
            

    # print(ans)


if __name__ == '__main__':
    main()

def main():

    N_machi, K_teleport = map(int, input().split())
    to_teleport = list(map(int, input().split()))

    visited_city = [1]
    order = [-1 for i in range(N_machi + 1)]
    order[1] = 0
    next_city = 1
    
    for i in range(N_machi):
        next_city = to_teleport[next_city - 1]
        tmp = order[next_city]
        
        if (tmp == -1):
            visited_city.append(next_city)
            order[next_city] = i + 1
        else:
            break
    
    first = order[next_city]
    len_loop = len(visited_city) - first
    
    if (K_teleport < first):
        ans = visited_city[K_teleport]
    else:
        mod = (K_teleport - first) % len_loop
        ans = visited_city[first + mod]
    
    print(ans)
        

if __name__ == '__main__':
    main()

Verdicts: Wrong Answer

Accepted