text
stringlengths
198
433k
conversation_id
int64
0
109k
Provide tags and a correct Python 3 solution for this coding contest problem. Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere. Zahar has n stones which are rectangular parallelepipeds. The edges sizes of the i-th of them are ai, bi and ci. He can take no more than two stones and present them to Kostya. If Zahar takes two stones, he should glue them together on one of the faces in order to get a new piece of rectangular parallelepiped of marble. Thus, it is possible to glue a pair of stones together if and only if two faces on which they are glued together match as rectangles. In such gluing it is allowed to rotate and flip the stones in any way. Help Zahar choose such a present so that Kostya can carve a sphere of the maximum possible volume and present it to Zahar. Input The first line contains the integer n (1 ≀ n ≀ 105). n lines follow, in the i-th of which there are three integers ai, bi and ci (1 ≀ ai, bi, ci ≀ 109) β€” the lengths of edges of the i-th stone. Note, that two stones may have exactly the same sizes, but they still will be considered two different stones. Output In the first line print k (1 ≀ k ≀ 2) the number of stones which Zahar has chosen. In the second line print k distinct integers from 1 to n β€” the numbers of stones which Zahar needs to choose. Consider that stones are numbered from 1 to n in the order as they are given in the input data. You can print the stones in arbitrary order. If there are several answers print any of them. Examples Input 6 5 5 5 3 2 4 1 4 1 2 1 3 3 2 4 3 3 4 Output 1 1 Input 7 10 7 8 5 10 3 4 2 6 5 5 5 10 2 8 4 2 1 7 7 7 Output 2 1 5 Note In the first example we can connect the pairs of stones: * 2 and 4, the size of the parallelepiped: 3 Γ— 2 Γ— 5, the radius of the inscribed sphere 1 * 2 and 5, the size of the parallelepiped: 3 Γ— 2 Γ— 8 or 6 Γ— 2 Γ— 4 or 3 Γ— 4 Γ— 4, the radius of the inscribed sphere 1, or 1, or 1.5 respectively. * 2 and 6, the size of the parallelepiped: 3 Γ— 5 Γ— 4, the radius of the inscribed sphere 1.5 * 4 and 5, the size of the parallelepiped: 3 Γ— 2 Γ— 5, the radius of the inscribed sphere 1 * 5 and 6, the size of the parallelepiped: 3 Γ— 4 Γ— 5, the radius of the inscribed sphere 1.5 Or take only one stone: * 1 the size of the parallelepiped: 5 Γ— 5 Γ— 5, the radius of the inscribed sphere 2.5 * 2 the size of the parallelepiped: 3 Γ— 2 Γ— 4, the radius of the inscribed sphere 1 * 3 the size of the parallelepiped: 1 Γ— 4 Γ— 1, the radius of the inscribed sphere 0.5 * 4 the size of the parallelepiped: 2 Γ— 1 Γ— 3, the radius of the inscribed sphere 0.5 * 5 the size of the parallelepiped: 3 Γ— 2 Γ— 4, the radius of the inscribed sphere 1 * 6 the size of the parallelepiped: 3 Γ— 3 Γ— 4, the radius of the inscribed sphere 1.5 It is most profitable to take only the first stone. Tags: data structures, hashing Correct Solution: ``` def define_nearest_primes(n): primes=[11,17,19,23,29,53,97,193,389,769,1543,3079,6151,12289,24593,49157,98317,1572869] for i in range(0, len(primes)): if primes[i]>1.5*n: p=primes[i] break return p def sort_box(box): if box[0]>box[1]: if box[0]>box[2]: if box[1]>box[2]: box=[box[2],box[1],box[0]] else: box=[box[1],box[2],box[0]] else: box=[box[1],box[0],box[2]] else: if box[0]<box[2]: if box[1]<box[2]: box=[box[0],box[1],box[2]] else: box=[box[0],box[2],box[1]] else: box=[box[2],box[0],box[1]] return(box) def hash_func(box,i,hash_table,biggest_merged_rectangular,p): index=(50033*box[2]+box[1]) % p while (len(hash_table[index])>0 and (box[1]!=hash_table[index][0][2] or box[2]!=hash_table[index][0][3])): index=(index+1) % p #print(box,index) if len(hash_table[index])==2: if box[0]>hash_table[index][0][1]: if hash_table[index][0][1]<hash_table[index][1][1]: hash_table[index][0]=[i,box[0],box[1],box[2]] else: hash_table[index][1]=[i,box[0],box[1],box[2]] else: if box[0]>hash_table[index][1][1]: hash_table[index][1]=[i,box[0],box[1],box[2]] temp_box=[hash_table[index][0][2],hash_table[index][0][3],hash_table[index][0][1]+hash_table[index][1][1]] temp_box=sort_box(temp_box) if biggest_merged_rectangular[2]<temp_box[0]: biggest_merged_rectangular=[hash_table[index][0][0],hash_table[index][1][0],temp_box[0]] else: if len(hash_table[index])==1: hash_table[index].append([i,box[0],box[1],box[2]]) temp_box=[hash_table[index][0][2],hash_table[index][0][3],hash_table[index][0][1]+hash_table[index][1][1]] temp_box=sort_box(temp_box) if biggest_merged_rectangular[2]<temp_box[0]: biggest_merged_rectangular=[hash_table[index][0][0],hash_table[index][1][0],temp_box[0]] else: hash_table[index].append([i,box[0],box[1],box[2]]) return hash_table, biggest_merged_rectangular def print_result(biggest_rectangular,biggest_merged_rectangular): if biggest_rectangular[1]>biggest_merged_rectangular[2]: print('1'+'\n'+str(biggest_rectangular[0])) else: if (biggest_merged_rectangular[0]<biggest_merged_rectangular[1]): print('2'+'\n'+str(biggest_merged_rectangular[0])+' '+str(biggest_merged_rectangular[1])) else: print('2'+'\n'+str(biggest_merged_rectangular[1])+' '+str(biggest_merged_rectangular[0])) def main(): n=int(input()) #the number of boxes p=define_nearest_primes(n) hash_table=[[] for i in range(0,p)] biggest_rectangular=[0,0] #we will also search in online format for largest rectangular: [index,radius] biggest_merged_rectangular=[0,0,0] #and merged rectangular: [index1,index2,radius] for i in range(1,n+1): box=input().split(" ") box=[int(box[0]),int(box[1]),int(box[2])] #print(box) if box[1]==box[0] and box[0]==box[2]: if biggest_rectangular[1]<box[0]: biggest_rectangular[0]=i biggest_rectangular[1]=box[0] else: box=sort_box(box) #now sides of the box are sorted from smallest to largest #print(sort_box(box)) if biggest_rectangular[1]<box[0]: biggest_rectangular[0]=i biggest_rectangular[1]=box[0] hashing=hash_func(box,i,hash_table,biggest_merged_rectangular,p) #online hashing process hash_table=hashing[0] #include the box into hash table biggest_merged_rectangular=hashing[1] #update the merged rectangular #print(biggest_merged_rectangular) #print(biggest_rectangular) print_result(biggest_rectangular,biggest_merged_rectangular) #f=open("output.txt", "w") #f.write(chosen_boxes[0]+'\n') if __name__ == "__main__": main() ```
100,800
Provide tags and a correct Python 3 solution for this coding contest problem. Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere. Zahar has n stones which are rectangular parallelepipeds. The edges sizes of the i-th of them are ai, bi and ci. He can take no more than two stones and present them to Kostya. If Zahar takes two stones, he should glue them together on one of the faces in order to get a new piece of rectangular parallelepiped of marble. Thus, it is possible to glue a pair of stones together if and only if two faces on which they are glued together match as rectangles. In such gluing it is allowed to rotate and flip the stones in any way. Help Zahar choose such a present so that Kostya can carve a sphere of the maximum possible volume and present it to Zahar. Input The first line contains the integer n (1 ≀ n ≀ 105). n lines follow, in the i-th of which there are three integers ai, bi and ci (1 ≀ ai, bi, ci ≀ 109) β€” the lengths of edges of the i-th stone. Note, that two stones may have exactly the same sizes, but they still will be considered two different stones. Output In the first line print k (1 ≀ k ≀ 2) the number of stones which Zahar has chosen. In the second line print k distinct integers from 1 to n β€” the numbers of stones which Zahar needs to choose. Consider that stones are numbered from 1 to n in the order as they are given in the input data. You can print the stones in arbitrary order. If there are several answers print any of them. Examples Input 6 5 5 5 3 2 4 1 4 1 2 1 3 3 2 4 3 3 4 Output 1 1 Input 7 10 7 8 5 10 3 4 2 6 5 5 5 10 2 8 4 2 1 7 7 7 Output 2 1 5 Note In the first example we can connect the pairs of stones: * 2 and 4, the size of the parallelepiped: 3 Γ— 2 Γ— 5, the radius of the inscribed sphere 1 * 2 and 5, the size of the parallelepiped: 3 Γ— 2 Γ— 8 or 6 Γ— 2 Γ— 4 or 3 Γ— 4 Γ— 4, the radius of the inscribed sphere 1, or 1, or 1.5 respectively. * 2 and 6, the size of the parallelepiped: 3 Γ— 5 Γ— 4, the radius of the inscribed sphere 1.5 * 4 and 5, the size of the parallelepiped: 3 Γ— 2 Γ— 5, the radius of the inscribed sphere 1 * 5 and 6, the size of the parallelepiped: 3 Γ— 4 Γ— 5, the radius of the inscribed sphere 1.5 Or take only one stone: * 1 the size of the parallelepiped: 5 Γ— 5 Γ— 5, the radius of the inscribed sphere 2.5 * 2 the size of the parallelepiped: 3 Γ— 2 Γ— 4, the radius of the inscribed sphere 1 * 3 the size of the parallelepiped: 1 Γ— 4 Γ— 1, the radius of the inscribed sphere 0.5 * 4 the size of the parallelepiped: 2 Γ— 1 Γ— 3, the radius of the inscribed sphere 0.5 * 5 the size of the parallelepiped: 3 Γ— 2 Γ— 4, the radius of the inscribed sphere 1 * 6 the size of the parallelepiped: 3 Γ— 3 Γ— 4, the radius of the inscribed sphere 1.5 It is most profitable to take only the first stone. Tags: data structures, hashing Correct Solution: ``` n = int(input()) lst = [] for i in range(n): lst.append([i + 1] + sorted([int(x) for x in input().split(' ')])) d = {} for elem in lst: if (elem[3], elem[2]) in d: d[(elem[3], elem[2])].append((elem[0], elem[1])) else: d[(elem[3], elem[2])] = [(elem[0], elem[1])] m = 0 ans = [] # print(d) for pair in d: m1, m2 = 0, 0 i1, i2 = 0, 0 for i in range(0, len(d[pair])): if d[pair][i][1] > m2: m1 = m2 m2 = d[pair][i][1] i1 = i2 i2 = d[pair][i][0] elif d[pair][i][1] > m1: m1 = d[pair][i][1] i1 = d[pair][i][0] # print(pair) # print(d[pair]) if i1 > 0: a = min(pair[0], pair[1], m1 + m2) if a > m: m = a ans = [i1, i2] else: a = min(pair[0], pair[1], m2) if a > m: m = a ans = [i2] # print(a, m, ans) print(len(ans)) print(' '.join([str(x) for x in ans])) ```
100,801
Provide tags and a correct Python 3 solution for this coding contest problem. Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere. Zahar has n stones which are rectangular parallelepipeds. The edges sizes of the i-th of them are ai, bi and ci. He can take no more than two stones and present them to Kostya. If Zahar takes two stones, he should glue them together on one of the faces in order to get a new piece of rectangular parallelepiped of marble. Thus, it is possible to glue a pair of stones together if and only if two faces on which they are glued together match as rectangles. In such gluing it is allowed to rotate and flip the stones in any way. Help Zahar choose such a present so that Kostya can carve a sphere of the maximum possible volume and present it to Zahar. Input The first line contains the integer n (1 ≀ n ≀ 105). n lines follow, in the i-th of which there are three integers ai, bi and ci (1 ≀ ai, bi, ci ≀ 109) β€” the lengths of edges of the i-th stone. Note, that two stones may have exactly the same sizes, but they still will be considered two different stones. Output In the first line print k (1 ≀ k ≀ 2) the number of stones which Zahar has chosen. In the second line print k distinct integers from 1 to n β€” the numbers of stones which Zahar needs to choose. Consider that stones are numbered from 1 to n in the order as they are given in the input data. You can print the stones in arbitrary order. If there are several answers print any of them. Examples Input 6 5 5 5 3 2 4 1 4 1 2 1 3 3 2 4 3 3 4 Output 1 1 Input 7 10 7 8 5 10 3 4 2 6 5 5 5 10 2 8 4 2 1 7 7 7 Output 2 1 5 Note In the first example we can connect the pairs of stones: * 2 and 4, the size of the parallelepiped: 3 Γ— 2 Γ— 5, the radius of the inscribed sphere 1 * 2 and 5, the size of the parallelepiped: 3 Γ— 2 Γ— 8 or 6 Γ— 2 Γ— 4 or 3 Γ— 4 Γ— 4, the radius of the inscribed sphere 1, or 1, or 1.5 respectively. * 2 and 6, the size of the parallelepiped: 3 Γ— 5 Γ— 4, the radius of the inscribed sphere 1.5 * 4 and 5, the size of the parallelepiped: 3 Γ— 2 Γ— 5, the radius of the inscribed sphere 1 * 5 and 6, the size of the parallelepiped: 3 Γ— 4 Γ— 5, the radius of the inscribed sphere 1.5 Or take only one stone: * 1 the size of the parallelepiped: 5 Γ— 5 Γ— 5, the radius of the inscribed sphere 2.5 * 2 the size of the parallelepiped: 3 Γ— 2 Γ— 4, the radius of the inscribed sphere 1 * 3 the size of the parallelepiped: 1 Γ— 4 Γ— 1, the radius of the inscribed sphere 0.5 * 4 the size of the parallelepiped: 2 Γ— 1 Γ— 3, the radius of the inscribed sphere 0.5 * 5 the size of the parallelepiped: 3 Γ— 2 Γ— 4, the radius of the inscribed sphere 1 * 6 the size of the parallelepiped: 3 Γ— 3 Γ— 4, the radius of the inscribed sphere 1.5 It is most profitable to take only the first stone. Tags: data structures, hashing Correct Solution: ``` N = int(input()) maxr = 0 maxi = [-1] sides = {} for x in range(N): cords = [int(x) for x in input().split()] cords.sort() if (cords[1], cords[2]) in sides: sides[(cords[1], cords[2])][0].append(cords[0]) sides[(cords[1], cords[2])][1].append(x+1) else: sides[(cords[1], cords[2])] = [ [cords[0]], [x+1], cords[1] ] if cords[0] > maxr: maxr = cords[0] maxi = [x + 1] for key in sides: maxA = 0 maxB = 0 Ai = 0 Bi = 0 for i,val in enumerate(sides[key][0]): if maxA < val: maxA = val Ai = i for i,val in enumerate(sides[key][0]): if i != Ai and maxB < val: maxB = val Bi = i newr2 = min(maxB+maxA, sides[key][2]) if newr2 > maxr: maxr = newr2 maxi = [ sides[key][1][Ai], sides[key][1][Bi] ] if len(maxi) == 1: print(1) print(maxi[0]) else: print(2) print(maxi[0], maxi[1]) ```
100,802
Provide tags and a correct Python 3 solution for this coding contest problem. Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere. Zahar has n stones which are rectangular parallelepipeds. The edges sizes of the i-th of them are ai, bi and ci. He can take no more than two stones and present them to Kostya. If Zahar takes two stones, he should glue them together on one of the faces in order to get a new piece of rectangular parallelepiped of marble. Thus, it is possible to glue a pair of stones together if and only if two faces on which they are glued together match as rectangles. In such gluing it is allowed to rotate and flip the stones in any way. Help Zahar choose such a present so that Kostya can carve a sphere of the maximum possible volume and present it to Zahar. Input The first line contains the integer n (1 ≀ n ≀ 105). n lines follow, in the i-th of which there are three integers ai, bi and ci (1 ≀ ai, bi, ci ≀ 109) β€” the lengths of edges of the i-th stone. Note, that two stones may have exactly the same sizes, but they still will be considered two different stones. Output In the first line print k (1 ≀ k ≀ 2) the number of stones which Zahar has chosen. In the second line print k distinct integers from 1 to n β€” the numbers of stones which Zahar needs to choose. Consider that stones are numbered from 1 to n in the order as they are given in the input data. You can print the stones in arbitrary order. If there are several answers print any of them. Examples Input 6 5 5 5 3 2 4 1 4 1 2 1 3 3 2 4 3 3 4 Output 1 1 Input 7 10 7 8 5 10 3 4 2 6 5 5 5 10 2 8 4 2 1 7 7 7 Output 2 1 5 Note In the first example we can connect the pairs of stones: * 2 and 4, the size of the parallelepiped: 3 Γ— 2 Γ— 5, the radius of the inscribed sphere 1 * 2 and 5, the size of the parallelepiped: 3 Γ— 2 Γ— 8 or 6 Γ— 2 Γ— 4 or 3 Γ— 4 Γ— 4, the radius of the inscribed sphere 1, or 1, or 1.5 respectively. * 2 and 6, the size of the parallelepiped: 3 Γ— 5 Γ— 4, the radius of the inscribed sphere 1.5 * 4 and 5, the size of the parallelepiped: 3 Γ— 2 Γ— 5, the radius of the inscribed sphere 1 * 5 and 6, the size of the parallelepiped: 3 Γ— 4 Γ— 5, the radius of the inscribed sphere 1.5 Or take only one stone: * 1 the size of the parallelepiped: 5 Γ— 5 Γ— 5, the radius of the inscribed sphere 2.5 * 2 the size of the parallelepiped: 3 Γ— 2 Γ— 4, the radius of the inscribed sphere 1 * 3 the size of the parallelepiped: 1 Γ— 4 Γ— 1, the radius of the inscribed sphere 0.5 * 4 the size of the parallelepiped: 2 Γ— 1 Γ— 3, the radius of the inscribed sphere 0.5 * 5 the size of the parallelepiped: 3 Γ— 2 Γ— 4, the radius of the inscribed sphere 1 * 6 the size of the parallelepiped: 3 Γ— 3 Γ— 4, the radius of the inscribed sphere 1.5 It is most profitable to take only the first stone. Tags: data structures, hashing Correct Solution: ``` def add_side(side1, side2, side3, side_dict, num): if (side1, side2) not in side_dict: side_dict[(side1, side2)] = [(side3, num)] else: side_dict[(side1, side2)].append((side3, num)) if len(side_dict[(side1, side2)]) > 2: side_dict[(side1, side2)] = sorted(side_dict[(side1, side2)])[1:3] n = int(input()) ans_k = 1 k1 = -1 ans = 0 side_dict = dict() cubes = list() for i in range(n): sides = sorted([int(x) for x in input().split()]) cubes.append(sides) if sides[0] / 2 > ans: k1 = i + 1 ans = sides[0] / 2 add_side(sides[0], sides[1], sides[2], side_dict, i) if sides[0] == sides[1] and sides[1] == sides[2]: pass else: if sides[0] == sides[1]: add_side(sides[0], sides[2], sides[1], side_dict, i) elif sides[1] == sides[2]: add_side(sides[1], sides[2], sides[0], side_dict, i) else: add_side(sides[0], sides[2], sides[1], side_dict, i) add_side(sides[1], sides[2], sides[0], side_dict, i) for pair in side_dict: if len(side_dict[pair]) > 1: sides = sorted([pair[0], pair[1], side_dict[pair][0][0] + side_dict[pair][1][0]]) if sides[0] / 2 > ans: ans = sides[0] / 2 ans_k = 2 k1 = side_dict[pair][0][1] + 1 k2 = side_dict[pair][1][1] + 1 print(ans_k) if ans_k == 1: print(k1) else: print(k1, k2) ```
100,803
Provide tags and a correct Python 3 solution for this coding contest problem. Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere. Zahar has n stones which are rectangular parallelepipeds. The edges sizes of the i-th of them are ai, bi and ci. He can take no more than two stones and present them to Kostya. If Zahar takes two stones, he should glue them together on one of the faces in order to get a new piece of rectangular parallelepiped of marble. Thus, it is possible to glue a pair of stones together if and only if two faces on which they are glued together match as rectangles. In such gluing it is allowed to rotate and flip the stones in any way. Help Zahar choose such a present so that Kostya can carve a sphere of the maximum possible volume and present it to Zahar. Input The first line contains the integer n (1 ≀ n ≀ 105). n lines follow, in the i-th of which there are three integers ai, bi and ci (1 ≀ ai, bi, ci ≀ 109) β€” the lengths of edges of the i-th stone. Note, that two stones may have exactly the same sizes, but they still will be considered two different stones. Output In the first line print k (1 ≀ k ≀ 2) the number of stones which Zahar has chosen. In the second line print k distinct integers from 1 to n β€” the numbers of stones which Zahar needs to choose. Consider that stones are numbered from 1 to n in the order as they are given in the input data. You can print the stones in arbitrary order. If there are several answers print any of them. Examples Input 6 5 5 5 3 2 4 1 4 1 2 1 3 3 2 4 3 3 4 Output 1 1 Input 7 10 7 8 5 10 3 4 2 6 5 5 5 10 2 8 4 2 1 7 7 7 Output 2 1 5 Note In the first example we can connect the pairs of stones: * 2 and 4, the size of the parallelepiped: 3 Γ— 2 Γ— 5, the radius of the inscribed sphere 1 * 2 and 5, the size of the parallelepiped: 3 Γ— 2 Γ— 8 or 6 Γ— 2 Γ— 4 or 3 Γ— 4 Γ— 4, the radius of the inscribed sphere 1, or 1, or 1.5 respectively. * 2 and 6, the size of the parallelepiped: 3 Γ— 5 Γ— 4, the radius of the inscribed sphere 1.5 * 4 and 5, the size of the parallelepiped: 3 Γ— 2 Γ— 5, the radius of the inscribed sphere 1 * 5 and 6, the size of the parallelepiped: 3 Γ— 4 Γ— 5, the radius of the inscribed sphere 1.5 Or take only one stone: * 1 the size of the parallelepiped: 5 Γ— 5 Γ— 5, the radius of the inscribed sphere 2.5 * 2 the size of the parallelepiped: 3 Γ— 2 Γ— 4, the radius of the inscribed sphere 1 * 3 the size of the parallelepiped: 1 Γ— 4 Γ— 1, the radius of the inscribed sphere 0.5 * 4 the size of the parallelepiped: 2 Γ— 1 Γ— 3, the radius of the inscribed sphere 0.5 * 5 the size of the parallelepiped: 3 Γ— 2 Γ— 4, the radius of the inscribed sphere 1 * 6 the size of the parallelepiped: 3 Γ— 3 Γ— 4, the radius of the inscribed sphere 1.5 It is most profitable to take only the first stone. Tags: data structures, hashing Correct Solution: ``` def main(): d, m = {}, 0 for i in range(1, int(input()) + 1): a, b, c = sorted(map(int, input().split())) if (b, c) in d: x, y, z, t = d[b, c] if a > z: d[b, c] = (a, i, x, y) if a > x else (x, y, a, i) else: d[b, c] = (a, i, 0, 0) for (a, b), (x, y, z, t) in d.items(): if a > m < x + z: m, res = x + z if a > x + z else a, (y, t) print(("2\n%d %d" % res) if res[1] else ("1\n%d" % res[0])) if __name__ == '__main__': main() ```
100,804
Provide tags and a correct Python 3 solution for this coding contest problem. Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere. Zahar has n stones which are rectangular parallelepipeds. The edges sizes of the i-th of them are ai, bi and ci. He can take no more than two stones and present them to Kostya. If Zahar takes two stones, he should glue them together on one of the faces in order to get a new piece of rectangular parallelepiped of marble. Thus, it is possible to glue a pair of stones together if and only if two faces on which they are glued together match as rectangles. In such gluing it is allowed to rotate and flip the stones in any way. Help Zahar choose such a present so that Kostya can carve a sphere of the maximum possible volume and present it to Zahar. Input The first line contains the integer n (1 ≀ n ≀ 105). n lines follow, in the i-th of which there are three integers ai, bi and ci (1 ≀ ai, bi, ci ≀ 109) β€” the lengths of edges of the i-th stone. Note, that two stones may have exactly the same sizes, but they still will be considered two different stones. Output In the first line print k (1 ≀ k ≀ 2) the number of stones which Zahar has chosen. In the second line print k distinct integers from 1 to n β€” the numbers of stones which Zahar needs to choose. Consider that stones are numbered from 1 to n in the order as they are given in the input data. You can print the stones in arbitrary order. If there are several answers print any of them. Examples Input 6 5 5 5 3 2 4 1 4 1 2 1 3 3 2 4 3 3 4 Output 1 1 Input 7 10 7 8 5 10 3 4 2 6 5 5 5 10 2 8 4 2 1 7 7 7 Output 2 1 5 Note In the first example we can connect the pairs of stones: * 2 and 4, the size of the parallelepiped: 3 Γ— 2 Γ— 5, the radius of the inscribed sphere 1 * 2 and 5, the size of the parallelepiped: 3 Γ— 2 Γ— 8 or 6 Γ— 2 Γ— 4 or 3 Γ— 4 Γ— 4, the radius of the inscribed sphere 1, or 1, or 1.5 respectively. * 2 and 6, the size of the parallelepiped: 3 Γ— 5 Γ— 4, the radius of the inscribed sphere 1.5 * 4 and 5, the size of the parallelepiped: 3 Γ— 2 Γ— 5, the radius of the inscribed sphere 1 * 5 and 6, the size of the parallelepiped: 3 Γ— 4 Γ— 5, the radius of the inscribed sphere 1.5 Or take only one stone: * 1 the size of the parallelepiped: 5 Γ— 5 Γ— 5, the radius of the inscribed sphere 2.5 * 2 the size of the parallelepiped: 3 Γ— 2 Γ— 4, the radius of the inscribed sphere 1 * 3 the size of the parallelepiped: 1 Γ— 4 Γ— 1, the radius of the inscribed sphere 0.5 * 4 the size of the parallelepiped: 2 Γ— 1 Γ— 3, the radius of the inscribed sphere 0.5 * 5 the size of the parallelepiped: 3 Γ— 2 Γ— 4, the radius of the inscribed sphere 1 * 6 the size of the parallelepiped: 3 Γ— 3 Γ— 4, the radius of the inscribed sphere 1.5 It is most profitable to take only the first stone. Tags: data structures, hashing Correct Solution: ``` n = int(input()) ar = [] for i in range(n): kek = list(map(int, input().split())) kek.sort() ar.append(kek + [i + 1]) ans = 0 kek = [0, 0] for i in range(n): if min(ar[i][0], ar[i][1], ar[i][2]) > ans: ans = min(ar[i][0], ar[i][1], ar[i][2]) kek[0] = ar[i][3] ar.sort(key=lambda x: [x[0], x[1], x[2]]) for i in range(1, n): if ar[i][0] == ar[i - 1][0] and ar[i][1] == ar[i - 1][1]: if min((ar[i][2] + ar[i - 1][2]), ar[i][0], ar[i][1]) > ans: ans = min((ar[i][2] + ar[i - 1][2]), ar[i][0], ar[i][1]) kek = [ar[i][3], ar[i - 1][3]] ar.sort(key=lambda x: [x[1], x[2], x[0]]) for i in range(1, n): if ar[i][2] == ar[i - 1][2] and ar[i][1] == ar[i - 1][1]: if min((ar[i][0] + ar[i - 1][0]), ar[i][2], ar[i][1]) > ans: ans = min((ar[i][0] + ar[i - 1][0]), ar[i][2], ar[i][1]) kek = [ar[i][3], ar[i - 1][3]] ar.sort(key=lambda x: [x[2], x[0], x[1]]) for i in range(1, n): if ar[i][2] == ar[i - 1][2] and ar[i][0] == ar[i - 1][0]: if min((ar[i][1] + ar[i - 1][1]), ar[i][0], ar[i][2]) > ans: min((ar[i][1] + ar[i - 1][1]), ar[i][0], ar[i][2]) kek = [ar[i][3], ar[i - 1][3]] ar.sort(key=lambda x:x[3]) if kek[1] == 0: print(1) print(kek[0]) else: print(2) print(*kek) ```
100,805
Provide tags and a correct Python 3 solution for this coding contest problem. Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere. Zahar has n stones which are rectangular parallelepipeds. The edges sizes of the i-th of them are ai, bi and ci. He can take no more than two stones and present them to Kostya. If Zahar takes two stones, he should glue them together on one of the faces in order to get a new piece of rectangular parallelepiped of marble. Thus, it is possible to glue a pair of stones together if and only if two faces on which they are glued together match as rectangles. In such gluing it is allowed to rotate and flip the stones in any way. Help Zahar choose such a present so that Kostya can carve a sphere of the maximum possible volume and present it to Zahar. Input The first line contains the integer n (1 ≀ n ≀ 105). n lines follow, in the i-th of which there are three integers ai, bi and ci (1 ≀ ai, bi, ci ≀ 109) β€” the lengths of edges of the i-th stone. Note, that two stones may have exactly the same sizes, but they still will be considered two different stones. Output In the first line print k (1 ≀ k ≀ 2) the number of stones which Zahar has chosen. In the second line print k distinct integers from 1 to n β€” the numbers of stones which Zahar needs to choose. Consider that stones are numbered from 1 to n in the order as they are given in the input data. You can print the stones in arbitrary order. If there are several answers print any of them. Examples Input 6 5 5 5 3 2 4 1 4 1 2 1 3 3 2 4 3 3 4 Output 1 1 Input 7 10 7 8 5 10 3 4 2 6 5 5 5 10 2 8 4 2 1 7 7 7 Output 2 1 5 Note In the first example we can connect the pairs of stones: * 2 and 4, the size of the parallelepiped: 3 Γ— 2 Γ— 5, the radius of the inscribed sphere 1 * 2 and 5, the size of the parallelepiped: 3 Γ— 2 Γ— 8 or 6 Γ— 2 Γ— 4 or 3 Γ— 4 Γ— 4, the radius of the inscribed sphere 1, or 1, or 1.5 respectively. * 2 and 6, the size of the parallelepiped: 3 Γ— 5 Γ— 4, the radius of the inscribed sphere 1.5 * 4 and 5, the size of the parallelepiped: 3 Γ— 2 Γ— 5, the radius of the inscribed sphere 1 * 5 and 6, the size of the parallelepiped: 3 Γ— 4 Γ— 5, the radius of the inscribed sphere 1.5 Or take only one stone: * 1 the size of the parallelepiped: 5 Γ— 5 Γ— 5, the radius of the inscribed sphere 2.5 * 2 the size of the parallelepiped: 3 Γ— 2 Γ— 4, the radius of the inscribed sphere 1 * 3 the size of the parallelepiped: 1 Γ— 4 Γ— 1, the radius of the inscribed sphere 0.5 * 4 the size of the parallelepiped: 2 Γ— 1 Γ— 3, the radius of the inscribed sphere 0.5 * 5 the size of the parallelepiped: 3 Γ— 2 Γ— 4, the radius of the inscribed sphere 1 * 6 the size of the parallelepiped: 3 Γ— 3 Γ— 4, the radius of the inscribed sphere 1.5 It is most profitable to take only the first stone. Tags: data structures, hashing Correct Solution: ``` import random def get_size(N): sizes = [23, 71, 151, 571, 1021, 1571, 5795, 11311, 15451, 50821, 96557, 160001, 262419] size = 11 idx = 0 while size < 2*N: size = sizes[idx] idx += 1 return size class Hash(object): def __init__(self, size): self.size = size self.items = [[] for i in range(size)] self.p1 = random.randint(1, size - 1) self.p2 = random.randint(1, size - 1) def count_index(self, b, c): return (b*self.p1 + c*self.p2) % self.size def get_pair(self, item): a, b, c, num = item idx = self.count_index(b, c) arr = self.items[idx] cur = None for i, cur in enumerate(arr): if cur[1] == b and cur[2] == c: break cur = None if cur: if cur[0] >= a: return cur[-1], item[-1], cur[0] + a else: self.items[idx][i] = item return item[-1], cur[-1], cur[0] + a else: self.items[idx].append(item) return None N = int(input()) R_max = 0 best_one = None best_pair = None if_one = True size = get_size(N) hash = Hash(size) for i in range(N): box = input().split() box = sorted([int(side) for side in box]) + [i + 1] if box[0] > R_max: best_one = i + 1 R_max = box[0] if_one = True cur_pair = hash.get_pair(box) if cur_pair: R_paired = min(box[1:-1] + [cur_pair[-1]]) if R_paired > R_max: R_max = R_paired best_pair = cur_pair[:-1] if_one = False #file = open('output.txt', 'w') if if_one: #file.write(str(1) + '\n' + str(best_one) + '\n' + str(R_max)) print(1) print(best_one) else: #file.write(str(2) + '\n' + str(best_pair[0]) + ' ' + str(best_pair[1]) + '\n' + str(R_max)) print(2) print(str(best_pair[0]) + ' ' + str(best_pair[1])) ```
100,806
Provide tags and a correct Python 3 solution for this coding contest problem. Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere. Zahar has n stones which are rectangular parallelepipeds. The edges sizes of the i-th of them are ai, bi and ci. He can take no more than two stones and present them to Kostya. If Zahar takes two stones, he should glue them together on one of the faces in order to get a new piece of rectangular parallelepiped of marble. Thus, it is possible to glue a pair of stones together if and only if two faces on which they are glued together match as rectangles. In such gluing it is allowed to rotate and flip the stones in any way. Help Zahar choose such a present so that Kostya can carve a sphere of the maximum possible volume and present it to Zahar. Input The first line contains the integer n (1 ≀ n ≀ 105). n lines follow, in the i-th of which there are three integers ai, bi and ci (1 ≀ ai, bi, ci ≀ 109) β€” the lengths of edges of the i-th stone. Note, that two stones may have exactly the same sizes, but they still will be considered two different stones. Output In the first line print k (1 ≀ k ≀ 2) the number of stones which Zahar has chosen. In the second line print k distinct integers from 1 to n β€” the numbers of stones which Zahar needs to choose. Consider that stones are numbered from 1 to n in the order as they are given in the input data. You can print the stones in arbitrary order. If there are several answers print any of them. Examples Input 6 5 5 5 3 2 4 1 4 1 2 1 3 3 2 4 3 3 4 Output 1 1 Input 7 10 7 8 5 10 3 4 2 6 5 5 5 10 2 8 4 2 1 7 7 7 Output 2 1 5 Note In the first example we can connect the pairs of stones: * 2 and 4, the size of the parallelepiped: 3 Γ— 2 Γ— 5, the radius of the inscribed sphere 1 * 2 and 5, the size of the parallelepiped: 3 Γ— 2 Γ— 8 or 6 Γ— 2 Γ— 4 or 3 Γ— 4 Γ— 4, the radius of the inscribed sphere 1, or 1, or 1.5 respectively. * 2 and 6, the size of the parallelepiped: 3 Γ— 5 Γ— 4, the radius of the inscribed sphere 1.5 * 4 and 5, the size of the parallelepiped: 3 Γ— 2 Γ— 5, the radius of the inscribed sphere 1 * 5 and 6, the size of the parallelepiped: 3 Γ— 4 Γ— 5, the radius of the inscribed sphere 1.5 Or take only one stone: * 1 the size of the parallelepiped: 5 Γ— 5 Γ— 5, the radius of the inscribed sphere 2.5 * 2 the size of the parallelepiped: 3 Γ— 2 Γ— 4, the radius of the inscribed sphere 1 * 3 the size of the parallelepiped: 1 Γ— 4 Γ— 1, the radius of the inscribed sphere 0.5 * 4 the size of the parallelepiped: 2 Γ— 1 Γ— 3, the radius of the inscribed sphere 0.5 * 5 the size of the parallelepiped: 3 Γ— 2 Γ— 4, the radius of the inscribed sphere 1 * 6 the size of the parallelepiped: 3 Γ— 3 Γ— 4, the radius of the inscribed sphere 1.5 It is most profitable to take only the first stone. Tags: data structures, hashing Correct Solution: ``` n = int(input()) sidesInfo = {} lengthsToIndex = {} for i in range(n): sides = [int(side) for side in input().split()] sides.sort() if sides[2] not in sidesInfo: sidesInfo[sides[2]] = {} if sides[1] not in sidesInfo[sides[2]]: sidesInfo[sides[2]][sides[1]] = [] #record stone info; sidesInfo[sides[2]][sides[1]].append(sides[0]) if f"{sides[0]}_{sides[1]}_{sides[2]}" not in lengthsToIndex: lengthsToIndex[f"{sides[0]}_{sides[1]}_{sides[2]}"] = [] lengthsToIndex[f"{sides[0]}_{sides[1]}_{sides[2]}"].append(i + 1) max_amount = 1 max_combination = "" max_radius = 0 for sideLen in sidesInfo: for sideWid in sidesInfo[sideLen]: heightChosen = [] if len(sidesInfo[sideLen][sideWid]) >= 2: sidesInfo[sideLen][sideWid].sort() heightChosen.append(sidesInfo[sideLen][sideWid][-2]) heightChosen.append(sidesInfo[sideLen][sideWid][-1]) else: heightChosen.append(sidesInfo[sideLen][sideWid][0]) radiusMax = min(sideLen, sideWid, sum(heightChosen)) if radiusMax > max_radius: max_radius = radiusMax max_amount = len(heightChosen) if max_amount == 2: pair = [] pair.append(lengthsToIndex[f"{heightChosen[0]}_{sideWid}_{sideLen}"][0]) if heightChosen[0] == heightChosen[1]: pair.append(lengthsToIndex[f"{heightChosen[1]}_{sideWid}_{sideLen}"][1]) else: pair.append(lengthsToIndex[f"{heightChosen[1]}_{sideWid}_{sideLen}"][0]) pair.sort() max_combination = ' '.join(str(i) for i in pair) else: max_combination = lengthsToIndex[f"{heightChosen[0]}_{sideWid}_{sideLen}"][0] print(max_amount) print(max_combination) ```
100,807
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere. Zahar has n stones which are rectangular parallelepipeds. The edges sizes of the i-th of them are ai, bi and ci. He can take no more than two stones and present them to Kostya. If Zahar takes two stones, he should glue them together on one of the faces in order to get a new piece of rectangular parallelepiped of marble. Thus, it is possible to glue a pair of stones together if and only if two faces on which they are glued together match as rectangles. In such gluing it is allowed to rotate and flip the stones in any way. Help Zahar choose such a present so that Kostya can carve a sphere of the maximum possible volume and present it to Zahar. Input The first line contains the integer n (1 ≀ n ≀ 105). n lines follow, in the i-th of which there are three integers ai, bi and ci (1 ≀ ai, bi, ci ≀ 109) β€” the lengths of edges of the i-th stone. Note, that two stones may have exactly the same sizes, but they still will be considered two different stones. Output In the first line print k (1 ≀ k ≀ 2) the number of stones which Zahar has chosen. In the second line print k distinct integers from 1 to n β€” the numbers of stones which Zahar needs to choose. Consider that stones are numbered from 1 to n in the order as they are given in the input data. You can print the stones in arbitrary order. If there are several answers print any of them. Examples Input 6 5 5 5 3 2 4 1 4 1 2 1 3 3 2 4 3 3 4 Output 1 1 Input 7 10 7 8 5 10 3 4 2 6 5 5 5 10 2 8 4 2 1 7 7 7 Output 2 1 5 Note In the first example we can connect the pairs of stones: * 2 and 4, the size of the parallelepiped: 3 Γ— 2 Γ— 5, the radius of the inscribed sphere 1 * 2 and 5, the size of the parallelepiped: 3 Γ— 2 Γ— 8 or 6 Γ— 2 Γ— 4 or 3 Γ— 4 Γ— 4, the radius of the inscribed sphere 1, or 1, or 1.5 respectively. * 2 and 6, the size of the parallelepiped: 3 Γ— 5 Γ— 4, the radius of the inscribed sphere 1.5 * 4 and 5, the size of the parallelepiped: 3 Γ— 2 Γ— 5, the radius of the inscribed sphere 1 * 5 and 6, the size of the parallelepiped: 3 Γ— 4 Γ— 5, the radius of the inscribed sphere 1.5 Or take only one stone: * 1 the size of the parallelepiped: 5 Γ— 5 Γ— 5, the radius of the inscribed sphere 2.5 * 2 the size of the parallelepiped: 3 Γ— 2 Γ— 4, the radius of the inscribed sphere 1 * 3 the size of the parallelepiped: 1 Γ— 4 Γ— 1, the radius of the inscribed sphere 0.5 * 4 the size of the parallelepiped: 2 Γ— 1 Γ— 3, the radius of the inscribed sphere 0.5 * 5 the size of the parallelepiped: 3 Γ— 2 Γ— 4, the radius of the inscribed sphere 1 * 6 the size of the parallelepiped: 3 Γ— 3 Γ— 4, the radius of the inscribed sphere 1.5 It is most profitable to take only the first stone. Submitted Solution: ``` import math,sys,bisect,heapq from collections import defaultdict,Counter,deque from itertools import groupby,accumulate #sys.setrecursionlimit(200000000) input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__ ilele = lambda: map(int,input().split()) alele = lambda: list(map(int, input().split())) def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] #MOD = 1000000000 + 7 def Y(c): print(["NO","YES"][c]) def y(c): print(["no","yes"][c]) def Yy(c): print(["No","Yes"][c]) N = int(input()) G= defaultdict(list) for i in range(N): a,b,c = ilele() C = sorted([a,b,c]) a,b,c = C l = i+1 if a==b == c: G[(a,b)].append((c,l)) elif a==b: G[(a,b)].append((c,l)) G[(b,c)].append((a,l)) elif b == c: G[(b,c)].append((a,l)) G[(a,b)].append((c,l)) else: G[(a,b)].append((c,l)) G[(b,c)].append((a,l)) G[(a,c)].append((b,l)) #print(G) maxi= 0 choose1 = None;choose2 = None for i,j in G.items(): if len(j) == 1: m = min(i[0],i[1],j[0][0]) if m> maxi: maxi = m choose1 = j[0][1] choose2 = None else: r = heapq.nlargest(2,j) m = min(r[0][0] + r[1][0],i[0],i[1]) if m>maxi: maxi = m choose1 = r[0][1] choose2 = r[1][1] if choose2 == None: print(1) print(choose1) else: print(2) print(choose1,choose2) ``` Yes
100,808
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere. Zahar has n stones which are rectangular parallelepipeds. The edges sizes of the i-th of them are ai, bi and ci. He can take no more than two stones and present them to Kostya. If Zahar takes two stones, he should glue them together on one of the faces in order to get a new piece of rectangular parallelepiped of marble. Thus, it is possible to glue a pair of stones together if and only if two faces on which they are glued together match as rectangles. In such gluing it is allowed to rotate and flip the stones in any way. Help Zahar choose such a present so that Kostya can carve a sphere of the maximum possible volume and present it to Zahar. Input The first line contains the integer n (1 ≀ n ≀ 105). n lines follow, in the i-th of which there are three integers ai, bi and ci (1 ≀ ai, bi, ci ≀ 109) β€” the lengths of edges of the i-th stone. Note, that two stones may have exactly the same sizes, but they still will be considered two different stones. Output In the first line print k (1 ≀ k ≀ 2) the number of stones which Zahar has chosen. In the second line print k distinct integers from 1 to n β€” the numbers of stones which Zahar needs to choose. Consider that stones are numbered from 1 to n in the order as they are given in the input data. You can print the stones in arbitrary order. If there are several answers print any of them. Examples Input 6 5 5 5 3 2 4 1 4 1 2 1 3 3 2 4 3 3 4 Output 1 1 Input 7 10 7 8 5 10 3 4 2 6 5 5 5 10 2 8 4 2 1 7 7 7 Output 2 1 5 Note In the first example we can connect the pairs of stones: * 2 and 4, the size of the parallelepiped: 3 Γ— 2 Γ— 5, the radius of the inscribed sphere 1 * 2 and 5, the size of the parallelepiped: 3 Γ— 2 Γ— 8 or 6 Γ— 2 Γ— 4 or 3 Γ— 4 Γ— 4, the radius of the inscribed sphere 1, or 1, or 1.5 respectively. * 2 and 6, the size of the parallelepiped: 3 Γ— 5 Γ— 4, the radius of the inscribed sphere 1.5 * 4 and 5, the size of the parallelepiped: 3 Γ— 2 Γ— 5, the radius of the inscribed sphere 1 * 5 and 6, the size of the parallelepiped: 3 Γ— 4 Γ— 5, the radius of the inscribed sphere 1.5 Or take only one stone: * 1 the size of the parallelepiped: 5 Γ— 5 Γ— 5, the radius of the inscribed sphere 2.5 * 2 the size of the parallelepiped: 3 Γ— 2 Γ— 4, the radius of the inscribed sphere 1 * 3 the size of the parallelepiped: 1 Γ— 4 Γ— 1, the radius of the inscribed sphere 0.5 * 4 the size of the parallelepiped: 2 Γ— 1 Γ— 3, the radius of the inscribed sphere 0.5 * 5 the size of the parallelepiped: 3 Γ— 2 Γ— 4, the radius of the inscribed sphere 1 * 6 the size of the parallelepiped: 3 Γ— 3 Γ— 4, the radius of the inscribed sphere 1.5 It is most profitable to take only the first stone. Submitted Solution: ``` from collections import defaultdict n = int(input()) ab, bc, ca = defaultdict(list), defaultdict(list), defaultdict(list) single, double = 0, 0 sidx, didx = None, None for i in range(1, n + 1): a, b, c = sorted(map(int, input().split())) ab[(a, b)].append((c, i)) bc[(b, c)].append((a, i)) ca[(c, a)].append((b, i)) m = min(a, b, c) if m > single: single = m sidx = i for d in [ab, bc, ca]: for (p, q), v in d.items(): if len(v) <= 1: continue *_, (x, xi), (y, yi) = sorted(v) m = min(p, q, x + y) if m > double: double = m didx = (xi, yi) if single >= double: print("1\n%d" % sidx) else: print("2\n%d %d" % didx) ``` Yes
100,809
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere. Zahar has n stones which are rectangular parallelepipeds. The edges sizes of the i-th of them are ai, bi and ci. He can take no more than two stones and present them to Kostya. If Zahar takes two stones, he should glue them together on one of the faces in order to get a new piece of rectangular parallelepiped of marble. Thus, it is possible to glue a pair of stones together if and only if two faces on which they are glued together match as rectangles. In such gluing it is allowed to rotate and flip the stones in any way. Help Zahar choose such a present so that Kostya can carve a sphere of the maximum possible volume and present it to Zahar. Input The first line contains the integer n (1 ≀ n ≀ 105). n lines follow, in the i-th of which there are three integers ai, bi and ci (1 ≀ ai, bi, ci ≀ 109) β€” the lengths of edges of the i-th stone. Note, that two stones may have exactly the same sizes, but they still will be considered two different stones. Output In the first line print k (1 ≀ k ≀ 2) the number of stones which Zahar has chosen. In the second line print k distinct integers from 1 to n β€” the numbers of stones which Zahar needs to choose. Consider that stones are numbered from 1 to n in the order as they are given in the input data. You can print the stones in arbitrary order. If there are several answers print any of them. Examples Input 6 5 5 5 3 2 4 1 4 1 2 1 3 3 2 4 3 3 4 Output 1 1 Input 7 10 7 8 5 10 3 4 2 6 5 5 5 10 2 8 4 2 1 7 7 7 Output 2 1 5 Note In the first example we can connect the pairs of stones: * 2 and 4, the size of the parallelepiped: 3 Γ— 2 Γ— 5, the radius of the inscribed sphere 1 * 2 and 5, the size of the parallelepiped: 3 Γ— 2 Γ— 8 or 6 Γ— 2 Γ— 4 or 3 Γ— 4 Γ— 4, the radius of the inscribed sphere 1, or 1, or 1.5 respectively. * 2 and 6, the size of the parallelepiped: 3 Γ— 5 Γ— 4, the radius of the inscribed sphere 1.5 * 4 and 5, the size of the parallelepiped: 3 Γ— 2 Γ— 5, the radius of the inscribed sphere 1 * 5 and 6, the size of the parallelepiped: 3 Γ— 4 Γ— 5, the radius of the inscribed sphere 1.5 Or take only one stone: * 1 the size of the parallelepiped: 5 Γ— 5 Γ— 5, the radius of the inscribed sphere 2.5 * 2 the size of the parallelepiped: 3 Γ— 2 Γ— 4, the radius of the inscribed sphere 1 * 3 the size of the parallelepiped: 1 Γ— 4 Γ— 1, the radius of the inscribed sphere 0.5 * 4 the size of the parallelepiped: 2 Γ— 1 Γ— 3, the radius of the inscribed sphere 0.5 * 5 the size of the parallelepiped: 3 Γ— 2 Γ— 4, the radius of the inscribed sphere 1 * 6 the size of the parallelepiped: 3 Γ— 3 Γ— 4, the radius of the inscribed sphere 1.5 It is most profitable to take only the first stone. Submitted Solution: ``` n = int(input()) a = [] ans,u,v = 0,-1,-1 for i in range(n): t = [int(x) for x in input().split()] t.sort() if ans < t[0]: ans = t[0] u = v = i t.append(i) a.append(t) from operator import itemgetter a.sort(key=itemgetter(1,2,0),reverse=True) i = 0 while i+1 < n: if a[i][1:3]==a[i+1][1:3]: t = min(a[i][0]+a[i+1][0],a[i][1]) if ans < t: ans = t u = a[i][3] v = a[i+1][3] i += 1 while (i==0 or a[i][1:3]==a[i-1][1:3]) and i+1<len(a): i += 1 if u == v: print(1) print(u+1) else: print(2) print(u+1,v+1) ``` Yes
100,810
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere. Zahar has n stones which are rectangular parallelepipeds. The edges sizes of the i-th of them are ai, bi and ci. He can take no more than two stones and present them to Kostya. If Zahar takes two stones, he should glue them together on one of the faces in order to get a new piece of rectangular parallelepiped of marble. Thus, it is possible to glue a pair of stones together if and only if two faces on which they are glued together match as rectangles. In such gluing it is allowed to rotate and flip the stones in any way. Help Zahar choose such a present so that Kostya can carve a sphere of the maximum possible volume and present it to Zahar. Input The first line contains the integer n (1 ≀ n ≀ 105). n lines follow, in the i-th of which there are three integers ai, bi and ci (1 ≀ ai, bi, ci ≀ 109) β€” the lengths of edges of the i-th stone. Note, that two stones may have exactly the same sizes, but they still will be considered two different stones. Output In the first line print k (1 ≀ k ≀ 2) the number of stones which Zahar has chosen. In the second line print k distinct integers from 1 to n β€” the numbers of stones which Zahar needs to choose. Consider that stones are numbered from 1 to n in the order as they are given in the input data. You can print the stones in arbitrary order. If there are several answers print any of them. Examples Input 6 5 5 5 3 2 4 1 4 1 2 1 3 3 2 4 3 3 4 Output 1 1 Input 7 10 7 8 5 10 3 4 2 6 5 5 5 10 2 8 4 2 1 7 7 7 Output 2 1 5 Note In the first example we can connect the pairs of stones: * 2 and 4, the size of the parallelepiped: 3 Γ— 2 Γ— 5, the radius of the inscribed sphere 1 * 2 and 5, the size of the parallelepiped: 3 Γ— 2 Γ— 8 or 6 Γ— 2 Γ— 4 or 3 Γ— 4 Γ— 4, the radius of the inscribed sphere 1, or 1, or 1.5 respectively. * 2 and 6, the size of the parallelepiped: 3 Γ— 5 Γ— 4, the radius of the inscribed sphere 1.5 * 4 and 5, the size of the parallelepiped: 3 Γ— 2 Γ— 5, the radius of the inscribed sphere 1 * 5 and 6, the size of the parallelepiped: 3 Γ— 4 Γ— 5, the radius of the inscribed sphere 1.5 Or take only one stone: * 1 the size of the parallelepiped: 5 Γ— 5 Γ— 5, the radius of the inscribed sphere 2.5 * 2 the size of the parallelepiped: 3 Γ— 2 Γ— 4, the radius of the inscribed sphere 1 * 3 the size of the parallelepiped: 1 Γ— 4 Γ— 1, the radius of the inscribed sphere 0.5 * 4 the size of the parallelepiped: 2 Γ— 1 Γ— 3, the radius of the inscribed sphere 0.5 * 5 the size of the parallelepiped: 3 Γ— 2 Γ— 4, the radius of the inscribed sphere 1 * 6 the size of the parallelepiped: 3 Γ— 3 Γ— 4, the radius of the inscribed sphere 1.5 It is most profitable to take only the first stone. Submitted Solution: ``` def define_nearest_primes(n): primes = [11, 17, 19, 23, 29, 53, 97, 193, 389, 769, 1543, 3079, 6151, 12289, 24593, 49157, 98317, 1572869] for i in range(0, len(primes)): if primes[i] > 1.5 * n: return primes[i] return primes[-1] def hash_func(box, i, hash_table, biggest_merged_rectangular, p): index = (50033 * box[2] + box[1]) % p while len(hash_table[index]) > 0 and (box[1] != hash_table[index][0][2] or box[2] != hash_table[index][0][3]): index = (index + 1) % p # print(index) if len(hash_table[index]) == 2: if box[0] > hash_table[index][0][1]: if hash_table[index][0][1] < hash_table[index][1][1]: hash_table[index][0] = [i, box[0], box[1], box[2]] else: hash_table[index][1] = [i, box[0], box[1], box[2]] elif box[0] > hash_table[index][1][1]: hash_table[index][1] = [i, box[0], box[1], box[2]] temp_box = [hash_table[index][0][2], hash_table[index][0][3], hash_table[index][0][1] + hash_table[index][1][1]] temp_box = sorted(temp_box) if biggest_merged_rectangular[2] < temp_box[0]: biggest_merged_rectangular = [hash_table[index][0][0], hash_table[index][1][0], temp_box[0]] else: if len(hash_table[index]) == 1: hash_table[index].append([i, box[0], box[1], box[2]]) temp_box = [hash_table[index][0][2], hash_table[index][0][3], hash_table[index][0][1] + hash_table[index][1][1]] temp_box = sorted(temp_box) if biggest_merged_rectangular[2] < temp_box[0]: biggest_merged_rectangular = [hash_table[index][0][0], hash_table[index][1][0], temp_box[0]] else: if biggest_merged_rectangular[2] < box[0]: biggest_merged_rectangular = [i, None, box[0]] hash_table[index].append([i, box[0], box[1], box[2]]) return hash_table, biggest_merged_rectangular if __name__ == "__main__": n = int(input()) # the number of boxes p = define_nearest_primes(n) hash_table = [[] for _ in range(0, p)] biggest_merged_rectangular = [0, 0, 0] # [index1,index2,radius] for i in range(1, n + 1): box = list(map(int, input().split())) box = sorted(box) # print(box) hashing = hash_func(box, i, hash_table, biggest_merged_rectangular, p) # online hashing process hash_table, biggest_merged_rectangular = hashing if biggest_merged_rectangular[1] is None: print('1\n{}'.format(biggest_merged_rectangular[0])) else: inds = sorted(biggest_merged_rectangular[:2]) print('2\n{} {}'.format(inds[0], inds[1])) ``` Yes
100,811
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere. Zahar has n stones which are rectangular parallelepipeds. The edges sizes of the i-th of them are ai, bi and ci. He can take no more than two stones and present them to Kostya. If Zahar takes two stones, he should glue them together on one of the faces in order to get a new piece of rectangular parallelepiped of marble. Thus, it is possible to glue a pair of stones together if and only if two faces on which they are glued together match as rectangles. In such gluing it is allowed to rotate and flip the stones in any way. Help Zahar choose such a present so that Kostya can carve a sphere of the maximum possible volume and present it to Zahar. Input The first line contains the integer n (1 ≀ n ≀ 105). n lines follow, in the i-th of which there are three integers ai, bi and ci (1 ≀ ai, bi, ci ≀ 109) β€” the lengths of edges of the i-th stone. Note, that two stones may have exactly the same sizes, but they still will be considered two different stones. Output In the first line print k (1 ≀ k ≀ 2) the number of stones which Zahar has chosen. In the second line print k distinct integers from 1 to n β€” the numbers of stones which Zahar needs to choose. Consider that stones are numbered from 1 to n in the order as they are given in the input data. You can print the stones in arbitrary order. If there are several answers print any of them. Examples Input 6 5 5 5 3 2 4 1 4 1 2 1 3 3 2 4 3 3 4 Output 1 1 Input 7 10 7 8 5 10 3 4 2 6 5 5 5 10 2 8 4 2 1 7 7 7 Output 2 1 5 Note In the first example we can connect the pairs of stones: * 2 and 4, the size of the parallelepiped: 3 Γ— 2 Γ— 5, the radius of the inscribed sphere 1 * 2 and 5, the size of the parallelepiped: 3 Γ— 2 Γ— 8 or 6 Γ— 2 Γ— 4 or 3 Γ— 4 Γ— 4, the radius of the inscribed sphere 1, or 1, or 1.5 respectively. * 2 and 6, the size of the parallelepiped: 3 Γ— 5 Γ— 4, the radius of the inscribed sphere 1.5 * 4 and 5, the size of the parallelepiped: 3 Γ— 2 Γ— 5, the radius of the inscribed sphere 1 * 5 and 6, the size of the parallelepiped: 3 Γ— 4 Γ— 5, the radius of the inscribed sphere 1.5 Or take only one stone: * 1 the size of the parallelepiped: 5 Γ— 5 Γ— 5, the radius of the inscribed sphere 2.5 * 2 the size of the parallelepiped: 3 Γ— 2 Γ— 4, the radius of the inscribed sphere 1 * 3 the size of the parallelepiped: 1 Γ— 4 Γ— 1, the radius of the inscribed sphere 0.5 * 4 the size of the parallelepiped: 2 Γ— 1 Γ— 3, the radius of the inscribed sphere 0.5 * 5 the size of the parallelepiped: 3 Γ— 2 Γ— 4, the radius of the inscribed sphere 1 * 6 the size of the parallelepiped: 3 Γ— 3 Γ— 4, the radius of the inscribed sphere 1.5 It is most profitable to take only the first stone. Submitted Solution: ``` hash_table = {} n = int(input()) max_diam = 0 ordinal_numbers = [0] for i in range(1, n+1): seq = sorted(list(map(int, input().split())), reverse=True) + [i] face = (seq[0], seq[1]) try: best = hash_table[face] except: best = None if best is not None: new_z = seq[2] + best[2] diam = min(seq[:2] + [new_z]) if diam > max_diam: ordinal_numbers = [best[3], i] max_diam = diam if best[2] < seq[2]: hash_table[face] = seq else: if seq[2] > max_diam: ordinal_numbers = [i] max_diam = seq[2] hash_table[face] = seq print(len(ordinal_numbers)) print(" ".join(map(str, ordinal_numbers)), end='') ``` No
100,812
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere. Zahar has n stones which are rectangular parallelepipeds. The edges sizes of the i-th of them are ai, bi and ci. He can take no more than two stones and present them to Kostya. If Zahar takes two stones, he should glue them together on one of the faces in order to get a new piece of rectangular parallelepiped of marble. Thus, it is possible to glue a pair of stones together if and only if two faces on which they are glued together match as rectangles. In such gluing it is allowed to rotate and flip the stones in any way. Help Zahar choose such a present so that Kostya can carve a sphere of the maximum possible volume and present it to Zahar. Input The first line contains the integer n (1 ≀ n ≀ 105). n lines follow, in the i-th of which there are three integers ai, bi and ci (1 ≀ ai, bi, ci ≀ 109) β€” the lengths of edges of the i-th stone. Note, that two stones may have exactly the same sizes, but they still will be considered two different stones. Output In the first line print k (1 ≀ k ≀ 2) the number of stones which Zahar has chosen. In the second line print k distinct integers from 1 to n β€” the numbers of stones which Zahar needs to choose. Consider that stones are numbered from 1 to n in the order as they are given in the input data. You can print the stones in arbitrary order. If there are several answers print any of them. Examples Input 6 5 5 5 3 2 4 1 4 1 2 1 3 3 2 4 3 3 4 Output 1 1 Input 7 10 7 8 5 10 3 4 2 6 5 5 5 10 2 8 4 2 1 7 7 7 Output 2 1 5 Note In the first example we can connect the pairs of stones: * 2 and 4, the size of the parallelepiped: 3 Γ— 2 Γ— 5, the radius of the inscribed sphere 1 * 2 and 5, the size of the parallelepiped: 3 Γ— 2 Γ— 8 or 6 Γ— 2 Γ— 4 or 3 Γ— 4 Γ— 4, the radius of the inscribed sphere 1, or 1, or 1.5 respectively. * 2 and 6, the size of the parallelepiped: 3 Γ— 5 Γ— 4, the radius of the inscribed sphere 1.5 * 4 and 5, the size of the parallelepiped: 3 Γ— 2 Γ— 5, the radius of the inscribed sphere 1 * 5 and 6, the size of the parallelepiped: 3 Γ— 4 Γ— 5, the radius of the inscribed sphere 1.5 Or take only one stone: * 1 the size of the parallelepiped: 5 Γ— 5 Γ— 5, the radius of the inscribed sphere 2.5 * 2 the size of the parallelepiped: 3 Γ— 2 Γ— 4, the radius of the inscribed sphere 1 * 3 the size of the parallelepiped: 1 Γ— 4 Γ— 1, the radius of the inscribed sphere 0.5 * 4 the size of the parallelepiped: 2 Γ— 1 Γ— 3, the radius of the inscribed sphere 0.5 * 5 the size of the parallelepiped: 3 Γ— 2 Γ— 4, the radius of the inscribed sphere 1 * 6 the size of the parallelepiped: 3 Γ— 3 Γ— 4, the radius of the inscribed sphere 1.5 It is most profitable to take only the first stone. Submitted Solution: ``` # I took these from https://planetmath.org/goodhashtableprimes, these numbers # should reduce the number of collisions PRIMES = [23, 53, 97, 193, 389, 769, 1543, 3079, 6151, 12289, 24593, 49157, 98317, 196613, 393241, 786433, 1572869, 3145739, 6291469, 12582917, 25165843, 50331653, 100663319, 201326611, 402653189, 805306457, 1610612741] class HashTable: """ This hash table will only work with integer pairs as keys. It will possibly be several times slower than the default Python implementation, since I will make no effort to replace lists by arrays, avoid long arithmetic in the hashing function, or otherwise optimize the performance. Conceptually though, this class is a real hash table without using any embedded associative arrays. To deal with collisions, I used chaining and prime table sizes. I expand the table when load factor is >0.75 and contract it when it is <0.25. """ def __init__(self, m=PRIMES[0]): self.size = 0 self.prime_index = 0 self.buckets = [[] for _ in range(m)] self.m = m def __getitem__(self, item): item_hash = self._hash(item) for key, value in self.buckets[item_hash]: if key[0] == item[0] and key[1] == item[1]: return value raise KeyError def __setitem__(self, item, _value): item_hash = self._hash(item) for i, (key, value) in enumerate(self.buckets[item_hash]): if key[0] == item[0] and key[1] == item[1]: self.buckets[item_hash][i][1] = _value return self.buckets[item_hash].append([item, _value]) self.size += 1 if self._load_factor() > 0.75: self._rehash(up=True) def __delitem__(self, item): item_hash = self._hash(item) for i, (key, value) in enumerate(self.buckets[item_hash]): if key[0] == item[0] and key[1] == item[1]: self.buckets[item_hash].pop(i) self.size -= 1 if self._load_factor() < 0.25 and self.m >= PRIMES[1]: self._rehash(up=False) break def __contains__(self, item): item_hash = self._hash(item) for i, (key, value) in enumerate(self.buckets[item_hash]): if key[0] == item[0] and key[1] == item[1]: return True return False def __len__(self): return self.size def _load_factor(self): return self.size / self.m def _hash(self, key): # trivial but working return (3 * key[0] + key[1]) % self.m def _rehash(self, up=True): old_buckets = self.buckets if up: # expansion to the next "good prime" size if self.prime_index < len(PRIMES) - 1: self.m = PRIMES[self.prime_index + 1] self.prime_index += 1 else: self.m = 2 * self.m + 1 else: # contraction to the previous "good prime" size if (self.m // 2 + 1 < PRIMES[-1]) and self.m > PRIMES[-1]: self.m = PRIMES[-1] self.prime_index = len(PRIMES) - 1 elif self.prime_index > 0: self.m = PRIMES[self.prime_index - 1] self.prime_index -= 1 self.buckets = [[] for _ in range(self.m)] self.size = 0 for bucket in old_buckets: for key, value in bucket: self[key] = value if __name__ == '__main__': boxes = dict() box_count = int(input()) max_ball_diameter = 0 max_ball_indices = [0, -1] for i in range(box_count): c, b, a = sorted(map(int, input().split())) if (a, b) in boxes: edges, indices = boxes[(a, b)] if c > edges[0]: edges = [c, edges[0]] indices = [i, indices[0]] elif c > edges[1]: edges = [edges[0], c] indices = [indices[0], i] diameter_candidate = min(a, b, edges[0] + edges[1]) if diameter_candidate > max_ball_diameter: max_ball_indices = indices max_ball_diameter = diameter_candidate else: boxes[(a, b)] = ([c, 0], [i, -1]) if c > max_ball_diameter: max_ball_diameter = c max_ball_indices = [i, -1] max_ball_indices = sorted(max_ball_indices) if max_ball_indices[0] == -1: print('1\n' + '{}\n'.format(max_ball_indices[1] + 1)) else: print('2\n' + '{} {}\n'.format(max_ball_indices[0] + 1, max_ball_indices[1] + 1)) ``` No
100,813
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere. Zahar has n stones which are rectangular parallelepipeds. The edges sizes of the i-th of them are ai, bi and ci. He can take no more than two stones and present them to Kostya. If Zahar takes two stones, he should glue them together on one of the faces in order to get a new piece of rectangular parallelepiped of marble. Thus, it is possible to glue a pair of stones together if and only if two faces on which they are glued together match as rectangles. In such gluing it is allowed to rotate and flip the stones in any way. Help Zahar choose such a present so that Kostya can carve a sphere of the maximum possible volume and present it to Zahar. Input The first line contains the integer n (1 ≀ n ≀ 105). n lines follow, in the i-th of which there are three integers ai, bi and ci (1 ≀ ai, bi, ci ≀ 109) β€” the lengths of edges of the i-th stone. Note, that two stones may have exactly the same sizes, but they still will be considered two different stones. Output In the first line print k (1 ≀ k ≀ 2) the number of stones which Zahar has chosen. In the second line print k distinct integers from 1 to n β€” the numbers of stones which Zahar needs to choose. Consider that stones are numbered from 1 to n in the order as they are given in the input data. You can print the stones in arbitrary order. If there are several answers print any of them. Examples Input 6 5 5 5 3 2 4 1 4 1 2 1 3 3 2 4 3 3 4 Output 1 1 Input 7 10 7 8 5 10 3 4 2 6 5 5 5 10 2 8 4 2 1 7 7 7 Output 2 1 5 Note In the first example we can connect the pairs of stones: * 2 and 4, the size of the parallelepiped: 3 Γ— 2 Γ— 5, the radius of the inscribed sphere 1 * 2 and 5, the size of the parallelepiped: 3 Γ— 2 Γ— 8 or 6 Γ— 2 Γ— 4 or 3 Γ— 4 Γ— 4, the radius of the inscribed sphere 1, or 1, or 1.5 respectively. * 2 and 6, the size of the parallelepiped: 3 Γ— 5 Γ— 4, the radius of the inscribed sphere 1.5 * 4 and 5, the size of the parallelepiped: 3 Γ— 2 Γ— 5, the radius of the inscribed sphere 1 * 5 and 6, the size of the parallelepiped: 3 Γ— 4 Γ— 5, the radius of the inscribed sphere 1.5 Or take only one stone: * 1 the size of the parallelepiped: 5 Γ— 5 Γ— 5, the radius of the inscribed sphere 2.5 * 2 the size of the parallelepiped: 3 Γ— 2 Γ— 4, the radius of the inscribed sphere 1 * 3 the size of the parallelepiped: 1 Γ— 4 Γ— 1, the radius of the inscribed sphere 0.5 * 4 the size of the parallelepiped: 2 Γ— 1 Γ— 3, the radius of the inscribed sphere 0.5 * 5 the size of the parallelepiped: 3 Γ— 2 Γ— 4, the radius of the inscribed sphere 1 * 6 the size of the parallelepiped: 3 Γ— 3 Γ— 4, the radius of the inscribed sphere 1.5 It is most profitable to take only the first stone. Submitted Solution: ``` import random def get_size(N): sizes = [23, 71, 151, 571, 1021, 1571, 5795, 11311, 15451, 50821, 96557, 160001, 262419] size = 11 idx = 0 while size < 2*N: size = sizes[idx] idx += 1 return size class Hash(object): def __init__(self, size): self.size = size self.items = [[] for i in range(size)] self.p1 = random.randint(1, size - 1) self.p2 = random.randint(1, size - 1) def count_index(self, b, c): return (b*self.p1 + c*self.p2)//self.size def get_pair(self, item): a, b, c, num = item idx = self.count_index(b, c) arr = self.items[idx] print(item, ':', idx, arr) cur = None for i, cur in enumerate(arr): if cur[1] == b and cur[2] == c: break cur = None if cur: print('cur', cur, cur[0] + a) if cur[0] >= a: return cur[-1], item[-1], cur[0] + a else: self.items[idx][i] = item return item[-1], cur[-1], cur[0] + a else: self.items[idx].append(item) return None N = int(input()) R_max = 0 best_one = None best_pair = None if_one = True size = get_size(N) hash = Hash(size) for i in range(N): box = input().split() box = sorted([int(side) for side in box]) + [i + 1] if box[0] > R_max: best_one = i + 1 R_max = box[0] if_one = True cur_pair = hash.get_pair(box) if cur_pair: box[0] = cur_pair[-1] R_paired = min(box[:-1]) if R_paired > R_max: R_max = R_paired best_pair = cur_pair[:-1] if_one = False #file = open('output.txt', 'w') if if_one: #file.write(str(1) + '\n' + str(best_one) + '\n' + str(R_max)) print(1) print(best_one) else: #file.write(str(2) + '\n' + str(best_pair[0]) + ' ' + str(best_pair[1]) + '\n' + str(R_max)) print(2) print(str(best_pair[0]) + ' ' + str(best_pair[1])) ``` No
100,814
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere. Zahar has n stones which are rectangular parallelepipeds. The edges sizes of the i-th of them are ai, bi and ci. He can take no more than two stones and present them to Kostya. If Zahar takes two stones, he should glue them together on one of the faces in order to get a new piece of rectangular parallelepiped of marble. Thus, it is possible to glue a pair of stones together if and only if two faces on which they are glued together match as rectangles. In such gluing it is allowed to rotate and flip the stones in any way. Help Zahar choose such a present so that Kostya can carve a sphere of the maximum possible volume and present it to Zahar. Input The first line contains the integer n (1 ≀ n ≀ 105). n lines follow, in the i-th of which there are three integers ai, bi and ci (1 ≀ ai, bi, ci ≀ 109) β€” the lengths of edges of the i-th stone. Note, that two stones may have exactly the same sizes, but they still will be considered two different stones. Output In the first line print k (1 ≀ k ≀ 2) the number of stones which Zahar has chosen. In the second line print k distinct integers from 1 to n β€” the numbers of stones which Zahar needs to choose. Consider that stones are numbered from 1 to n in the order as they are given in the input data. You can print the stones in arbitrary order. If there are several answers print any of them. Examples Input 6 5 5 5 3 2 4 1 4 1 2 1 3 3 2 4 3 3 4 Output 1 1 Input 7 10 7 8 5 10 3 4 2 6 5 5 5 10 2 8 4 2 1 7 7 7 Output 2 1 5 Note In the first example we can connect the pairs of stones: * 2 and 4, the size of the parallelepiped: 3 Γ— 2 Γ— 5, the radius of the inscribed sphere 1 * 2 and 5, the size of the parallelepiped: 3 Γ— 2 Γ— 8 or 6 Γ— 2 Γ— 4 or 3 Γ— 4 Γ— 4, the radius of the inscribed sphere 1, or 1, or 1.5 respectively. * 2 and 6, the size of the parallelepiped: 3 Γ— 5 Γ— 4, the radius of the inscribed sphere 1.5 * 4 and 5, the size of the parallelepiped: 3 Γ— 2 Γ— 5, the radius of the inscribed sphere 1 * 5 and 6, the size of the parallelepiped: 3 Γ— 4 Γ— 5, the radius of the inscribed sphere 1.5 Or take only one stone: * 1 the size of the parallelepiped: 5 Γ— 5 Γ— 5, the radius of the inscribed sphere 2.5 * 2 the size of the parallelepiped: 3 Γ— 2 Γ— 4, the radius of the inscribed sphere 1 * 3 the size of the parallelepiped: 1 Γ— 4 Γ— 1, the radius of the inscribed sphere 0.5 * 4 the size of the parallelepiped: 2 Γ— 1 Γ— 3, the radius of the inscribed sphere 0.5 * 5 the size of the parallelepiped: 3 Γ— 2 Γ— 4, the radius of the inscribed sphere 1 * 6 the size of the parallelepiped: 3 Γ— 3 Γ— 4, the radius of the inscribed sphere 1.5 It is most profitable to take only the first stone. Submitted Solution: ``` n = int(input()) a = [] ans,u,v = 0,-1,-1 for i in range(n): t = [int(x) for x in input().split()] t.sort() if ans < t[0]: ans = t[0] u = v = i t.append(i) a.append(t) b = [] for x in a: if x[1] >= ans: b.append(x) for x in b: for y in b: if x[3] != y[3]: if x[1:2] == y[1:2]: t = max(x[0]+y[0],x[1]) if ans < t: ans = t u = x[3] v = y[3] if u == v: print(1) print(u+1) else: print(2) print(u+1,v+1) ``` No
100,815
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10k. In the given number of n Polycarp wants to remove the least number of digits to get a number that is divisible by 10k. For example, if k = 3, in the number 30020 it is enough to delete a single digit (2). In this case, the result is 3000 that is divisible by 103 = 1000. Write a program that prints the minimum number of digits to be deleted from the given integer number n, so that the result is divisible by 10k. The result should not start with the unnecessary leading zero (i.e., zero can start only the number 0, which is required to be written as exactly one digit). It is guaranteed that the answer exists. Input The only line of the input contains two integer numbers n and k (0 ≀ n ≀ 2 000 000 000, 1 ≀ k ≀ 9). It is guaranteed that the answer exists. All numbers in the input are written in traditional notation of integers, that is, without any extra leading zeros. Output Print w β€” the required minimal number of digits to erase. After removing the appropriate w digits from the number n, the result should have a value that is divisible by 10k. The result can start with digit 0 in the single case (the result is zero and written by exactly the only digit 0). Examples Input 30020 3 Output 1 Input 100 9 Output 2 Input 10203049 2 Output 3 Note In the example 2 you can remove two digits: 1 and any 0. The result is number 0 which is divisible by any number. Tags: brute force, greedy Correct Solution: ``` n,k=list(map(int,input().split())) ans,c=0,0 while k>0 and n>0: if n % 10 == 0: k -= 1 else: ans += 1 n //= 10 c += 1 print(ans if n>0 else max(0,c-1)) ```
100,816
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10k. In the given number of n Polycarp wants to remove the least number of digits to get a number that is divisible by 10k. For example, if k = 3, in the number 30020 it is enough to delete a single digit (2). In this case, the result is 3000 that is divisible by 103 = 1000. Write a program that prints the minimum number of digits to be deleted from the given integer number n, so that the result is divisible by 10k. The result should not start with the unnecessary leading zero (i.e., zero can start only the number 0, which is required to be written as exactly one digit). It is guaranteed that the answer exists. Input The only line of the input contains two integer numbers n and k (0 ≀ n ≀ 2 000 000 000, 1 ≀ k ≀ 9). It is guaranteed that the answer exists. All numbers in the input are written in traditional notation of integers, that is, without any extra leading zeros. Output Print w β€” the required minimal number of digits to erase. After removing the appropriate w digits from the number n, the result should have a value that is divisible by 10k. The result can start with digit 0 in the single case (the result is zero and written by exactly the only digit 0). Examples Input 30020 3 Output 1 Input 100 9 Output 2 Input 10203049 2 Output 3 Note In the example 2 you can remove two digits: 1 and any 0. The result is number 0 which is divisible by any number. Tags: brute force, greedy Correct Solution: ``` n,k=map(int,input().split()) if(n==0): print(0) exit() x=[] while(n>0): x.append(n%10) n=n//10 c1=0 c2=0 for i in range (len(x)): if(x[i]==0): c1+=1 if(c1==k): break if(x[i]!=0): c2+=1 #print(c1,c2) if(c1<k): print(len(x)-1) else: print(c2) ```
100,817
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10k. In the given number of n Polycarp wants to remove the least number of digits to get a number that is divisible by 10k. For example, if k = 3, in the number 30020 it is enough to delete a single digit (2). In this case, the result is 3000 that is divisible by 103 = 1000. Write a program that prints the minimum number of digits to be deleted from the given integer number n, so that the result is divisible by 10k. The result should not start with the unnecessary leading zero (i.e., zero can start only the number 0, which is required to be written as exactly one digit). It is guaranteed that the answer exists. Input The only line of the input contains two integer numbers n and k (0 ≀ n ≀ 2 000 000 000, 1 ≀ k ≀ 9). It is guaranteed that the answer exists. All numbers in the input are written in traditional notation of integers, that is, without any extra leading zeros. Output Print w β€” the required minimal number of digits to erase. After removing the appropriate w digits from the number n, the result should have a value that is divisible by 10k. The result can start with digit 0 in the single case (the result is zero and written by exactly the only digit 0). Examples Input 30020 3 Output 1 Input 100 9 Output 2 Input 10203049 2 Output 3 Note In the example 2 you can remove two digits: 1 and any 0. The result is number 0 which is divisible by any number. Tags: brute force, greedy Correct Solution: ``` n,k = [x for x in input().split()] k = int(k) ans = 0 stack = 0 if k == 0: print(0) if n.count('0') < k: print(len(n)-1) else: for i in n[::-1]: if stack == k: break if i=="0": stack+=1 else: ans += 1 print(ans) ```
100,818
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10k. In the given number of n Polycarp wants to remove the least number of digits to get a number that is divisible by 10k. For example, if k = 3, in the number 30020 it is enough to delete a single digit (2). In this case, the result is 3000 that is divisible by 103 = 1000. Write a program that prints the minimum number of digits to be deleted from the given integer number n, so that the result is divisible by 10k. The result should not start with the unnecessary leading zero (i.e., zero can start only the number 0, which is required to be written as exactly one digit). It is guaranteed that the answer exists. Input The only line of the input contains two integer numbers n and k (0 ≀ n ≀ 2 000 000 000, 1 ≀ k ≀ 9). It is guaranteed that the answer exists. All numbers in the input are written in traditional notation of integers, that is, without any extra leading zeros. Output Print w β€” the required minimal number of digits to erase. After removing the appropriate w digits from the number n, the result should have a value that is divisible by 10k. The result can start with digit 0 in the single case (the result is zero and written by exactly the only digit 0). Examples Input 30020 3 Output 1 Input 100 9 Output 2 Input 10203049 2 Output 3 Note In the example 2 you can remove two digits: 1 and any 0. The result is number 0 which is divisible by any number. Tags: brute force, greedy Correct Solution: ``` n,k = input().split() k = int(k) n = list(map(int,list(n))) l = len(n) j = l-1 while(j>-1 and k>0): if(n[j]!=0): del n[j] else: k -= 1 j -= 1 if(n[0]==0): print(l-1) else: print(l-len(n)) ```
100,819
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10k. In the given number of n Polycarp wants to remove the least number of digits to get a number that is divisible by 10k. For example, if k = 3, in the number 30020 it is enough to delete a single digit (2). In this case, the result is 3000 that is divisible by 103 = 1000. Write a program that prints the minimum number of digits to be deleted from the given integer number n, so that the result is divisible by 10k. The result should not start with the unnecessary leading zero (i.e., zero can start only the number 0, which is required to be written as exactly one digit). It is guaranteed that the answer exists. Input The only line of the input contains two integer numbers n and k (0 ≀ n ≀ 2 000 000 000, 1 ≀ k ≀ 9). It is guaranteed that the answer exists. All numbers in the input are written in traditional notation of integers, that is, without any extra leading zeros. Output Print w β€” the required minimal number of digits to erase. After removing the appropriate w digits from the number n, the result should have a value that is divisible by 10k. The result can start with digit 0 in the single case (the result is zero and written by exactly the only digit 0). Examples Input 30020 3 Output 1 Input 100 9 Output 2 Input 10203049 2 Output 3 Note In the example 2 you can remove two digits: 1 and any 0. The result is number 0 which is divisible by any number. Tags: brute force, greedy Correct Solution: ``` n, k = input().split() n, k = n[::-1], int(k) r = 0 for i in range(len(n)): if n[i] != '0': r += 1 if i-r+1 == k: break else: r = len(n)-1 print(r) ```
100,820
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10k. In the given number of n Polycarp wants to remove the least number of digits to get a number that is divisible by 10k. For example, if k = 3, in the number 30020 it is enough to delete a single digit (2). In this case, the result is 3000 that is divisible by 103 = 1000. Write a program that prints the minimum number of digits to be deleted from the given integer number n, so that the result is divisible by 10k. The result should not start with the unnecessary leading zero (i.e., zero can start only the number 0, which is required to be written as exactly one digit). It is guaranteed that the answer exists. Input The only line of the input contains two integer numbers n and k (0 ≀ n ≀ 2 000 000 000, 1 ≀ k ≀ 9). It is guaranteed that the answer exists. All numbers in the input are written in traditional notation of integers, that is, without any extra leading zeros. Output Print w β€” the required minimal number of digits to erase. After removing the appropriate w digits from the number n, the result should have a value that is divisible by 10k. The result can start with digit 0 in the single case (the result is zero and written by exactly the only digit 0). Examples Input 30020 3 Output 1 Input 100 9 Output 2 Input 10203049 2 Output 3 Note In the example 2 you can remove two digits: 1 and any 0. The result is number 0 which is divisible by any number. Tags: brute force, greedy Correct Solution: ``` n, k = input().split() n = list(n) k = int(k) zeroes = 0 digits_to_remove = 0 i = len(n) - 1 while True: if zeroes < k: if i == 0: digits_to_remove += len(n) - 1 break elif n[i] == '0': zeroes += 1 else: del n[i] digits_to_remove += 1 i -= 1 else: break print(digits_to_remove) ```
100,821
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10k. In the given number of n Polycarp wants to remove the least number of digits to get a number that is divisible by 10k. For example, if k = 3, in the number 30020 it is enough to delete a single digit (2). In this case, the result is 3000 that is divisible by 103 = 1000. Write a program that prints the minimum number of digits to be deleted from the given integer number n, so that the result is divisible by 10k. The result should not start with the unnecessary leading zero (i.e., zero can start only the number 0, which is required to be written as exactly one digit). It is guaranteed that the answer exists. Input The only line of the input contains two integer numbers n and k (0 ≀ n ≀ 2 000 000 000, 1 ≀ k ≀ 9). It is guaranteed that the answer exists. All numbers in the input are written in traditional notation of integers, that is, without any extra leading zeros. Output Print w β€” the required minimal number of digits to erase. After removing the appropriate w digits from the number n, the result should have a value that is divisible by 10k. The result can start with digit 0 in the single case (the result is zero and written by exactly the only digit 0). Examples Input 30020 3 Output 1 Input 100 9 Output 2 Input 10203049 2 Output 3 Note In the example 2 you can remove two digits: 1 and any 0. The result is number 0 which is divisible by any number. Tags: brute force, greedy Correct Solution: ``` n,m=input().split();n,m=list(n)[::-1],int(m);k=0;i=0;ans=0;p=len(n) if p<=m:print(p-1) else: if n.count('0')<m:print(p-1) else: while k!=m and i<p: if n[i]=='0':k+=1 else:ans+=1 i+=1 print(ans) ```
100,822
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10k. In the given number of n Polycarp wants to remove the least number of digits to get a number that is divisible by 10k. For example, if k = 3, in the number 30020 it is enough to delete a single digit (2). In this case, the result is 3000 that is divisible by 103 = 1000. Write a program that prints the minimum number of digits to be deleted from the given integer number n, so that the result is divisible by 10k. The result should not start with the unnecessary leading zero (i.e., zero can start only the number 0, which is required to be written as exactly one digit). It is guaranteed that the answer exists. Input The only line of the input contains two integer numbers n and k (0 ≀ n ≀ 2 000 000 000, 1 ≀ k ≀ 9). It is guaranteed that the answer exists. All numbers in the input are written in traditional notation of integers, that is, without any extra leading zeros. Output Print w β€” the required minimal number of digits to erase. After removing the appropriate w digits from the number n, the result should have a value that is divisible by 10k. The result can start with digit 0 in the single case (the result is zero and written by exactly the only digit 0). Examples Input 30020 3 Output 1 Input 100 9 Output 2 Input 10203049 2 Output 3 Note In the example 2 you can remove two digits: 1 and any 0. The result is number 0 which is divisible by any number. Tags: brute force, greedy Correct Solution: ``` n,k=map(str,input().split()) a=list(n) k=int(k) if((10**k)>int(n)): print(len(n)-1) else: if((int(n)%(10**k))==0): print(0) else: c=0 z=0 for i in range(len(a)-1,-1,-1): if(z==k): break if(a[i]!='0'): c=c+1 if(a[i]=='0'): z=z+1 if(z<k): print(len(a)-1) else: print(c) ```
100,823
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10k. In the given number of n Polycarp wants to remove the least number of digits to get a number that is divisible by 10k. For example, if k = 3, in the number 30020 it is enough to delete a single digit (2). In this case, the result is 3000 that is divisible by 103 = 1000. Write a program that prints the minimum number of digits to be deleted from the given integer number n, so that the result is divisible by 10k. The result should not start with the unnecessary leading zero (i.e., zero can start only the number 0, which is required to be written as exactly one digit). It is guaranteed that the answer exists. Input The only line of the input contains two integer numbers n and k (0 ≀ n ≀ 2 000 000 000, 1 ≀ k ≀ 9). It is guaranteed that the answer exists. All numbers in the input are written in traditional notation of integers, that is, without any extra leading zeros. Output Print w β€” the required minimal number of digits to erase. After removing the appropriate w digits from the number n, the result should have a value that is divisible by 10k. The result can start with digit 0 in the single case (the result is zero and written by exactly the only digit 0). Examples Input 30020 3 Output 1 Input 100 9 Output 2 Input 10203049 2 Output 3 Note In the example 2 you can remove two digits: 1 and any 0. The result is number 0 which is divisible by any number. Submitted Solution: ``` L = input() L = L.split() n = L[0] k = int(L[1]) def Div(N, K): N = int(N) if N%10**K == 0: return True else: return False c = 0 f = len(n) while f != 1: f -= 1 if n[f] != '0' and not(Div(n,k)): b = n[:f] + n[f +1:] n = b c += 1 else: b = n if int(n) == 0: print (c) else: nd = len(b) nceros = nd -1 if nceros < k: c = nceros + c print (c) ``` Yes
100,824
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10k. In the given number of n Polycarp wants to remove the least number of digits to get a number that is divisible by 10k. For example, if k = 3, in the number 30020 it is enough to delete a single digit (2). In this case, the result is 3000 that is divisible by 103 = 1000. Write a program that prints the minimum number of digits to be deleted from the given integer number n, so that the result is divisible by 10k. The result should not start with the unnecessary leading zero (i.e., zero can start only the number 0, which is required to be written as exactly one digit). It is guaranteed that the answer exists. Input The only line of the input contains two integer numbers n and k (0 ≀ n ≀ 2 000 000 000, 1 ≀ k ≀ 9). It is guaranteed that the answer exists. All numbers in the input are written in traditional notation of integers, that is, without any extra leading zeros. Output Print w β€” the required minimal number of digits to erase. After removing the appropriate w digits from the number n, the result should have a value that is divisible by 10k. The result can start with digit 0 in the single case (the result is zero and written by exactly the only digit 0). Examples Input 30020 3 Output 1 Input 100 9 Output 2 Input 10203049 2 Output 3 Note In the example 2 you can remove two digits: 1 and any 0. The result is number 0 which is divisible by any number. Submitted Solution: ``` n, k = list(map(int, input().split())) n = list(str(n)) a = len(n) if n.count('0') < k: print(a-1) else: cz = 0 ca = 0 for i in n[::-1]: if i == '0': cz += 1 else: ca += 1 if cz == k: print(ca) break ``` Yes
100,825
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10k. In the given number of n Polycarp wants to remove the least number of digits to get a number that is divisible by 10k. For example, if k = 3, in the number 30020 it is enough to delete a single digit (2). In this case, the result is 3000 that is divisible by 103 = 1000. Write a program that prints the minimum number of digits to be deleted from the given integer number n, so that the result is divisible by 10k. The result should not start with the unnecessary leading zero (i.e., zero can start only the number 0, which is required to be written as exactly one digit). It is guaranteed that the answer exists. Input The only line of the input contains two integer numbers n and k (0 ≀ n ≀ 2 000 000 000, 1 ≀ k ≀ 9). It is guaranteed that the answer exists. All numbers in the input are written in traditional notation of integers, that is, without any extra leading zeros. Output Print w β€” the required minimal number of digits to erase. After removing the appropriate w digits from the number n, the result should have a value that is divisible by 10k. The result can start with digit 0 in the single case (the result is zero and written by exactly the only digit 0). Examples Input 30020 3 Output 1 Input 100 9 Output 2 Input 10203049 2 Output 3 Note In the example 2 you can remove two digits: 1 and any 0. The result is number 0 which is divisible by any number. Submitted Solution: ``` s, k = input().split() k = int(k) v, w, l = 0, 0, len(s) for i in reversed(range(l)): if s[i] == '0': v += 1 elif not v >= k: w += 1 if v >= k: print(w) else: print(l-1) ``` Yes
100,826
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10k. In the given number of n Polycarp wants to remove the least number of digits to get a number that is divisible by 10k. For example, if k = 3, in the number 30020 it is enough to delete a single digit (2). In this case, the result is 3000 that is divisible by 103 = 1000. Write a program that prints the minimum number of digits to be deleted from the given integer number n, so that the result is divisible by 10k. The result should not start with the unnecessary leading zero (i.e., zero can start only the number 0, which is required to be written as exactly one digit). It is guaranteed that the answer exists. Input The only line of the input contains two integer numbers n and k (0 ≀ n ≀ 2 000 000 000, 1 ≀ k ≀ 9). It is guaranteed that the answer exists. All numbers in the input are written in traditional notation of integers, that is, without any extra leading zeros. Output Print w β€” the required minimal number of digits to erase. After removing the appropriate w digits from the number n, the result should have a value that is divisible by 10k. The result can start with digit 0 in the single case (the result is zero and written by exactly the only digit 0). Examples Input 30020 3 Output 1 Input 100 9 Output 2 Input 10203049 2 Output 3 Note In the example 2 you can remove two digits: 1 and any 0. The result is number 0 which is divisible by any number. Submitted Solution: ``` a = list(input().split()) n = a[0] k = int(a[1]) c = 0 f = 0 for x in range(-1, -len(n)-1, -1): if n[x] == "0": c = c + 1 if c == k: print( -x-k ) f = 1 break if f == 0: print(len(n) - 1) ``` Yes
100,827
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10k. In the given number of n Polycarp wants to remove the least number of digits to get a number that is divisible by 10k. For example, if k = 3, in the number 30020 it is enough to delete a single digit (2). In this case, the result is 3000 that is divisible by 103 = 1000. Write a program that prints the minimum number of digits to be deleted from the given integer number n, so that the result is divisible by 10k. The result should not start with the unnecessary leading zero (i.e., zero can start only the number 0, which is required to be written as exactly one digit). It is guaranteed that the answer exists. Input The only line of the input contains two integer numbers n and k (0 ≀ n ≀ 2 000 000 000, 1 ≀ k ≀ 9). It is guaranteed that the answer exists. All numbers in the input are written in traditional notation of integers, that is, without any extra leading zeros. Output Print w β€” the required minimal number of digits to erase. After removing the appropriate w digits from the number n, the result should have a value that is divisible by 10k. The result can start with digit 0 in the single case (the result is zero and written by exactly the only digit 0). Examples Input 30020 3 Output 1 Input 100 9 Output 2 Input 10203049 2 Output 3 Note In the example 2 you can remove two digits: 1 and any 0. The result is number 0 which is divisible by any number. Submitted Solution: ``` n,k=list(map(int,input().split())) ans,c=0,0 while k>0 and n>0: if n % 10 == 0: k -= 1 else: ans += 1 n //= 10 c += 1 print(ans if n>0 else c-1) ``` No
100,828
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10k. In the given number of n Polycarp wants to remove the least number of digits to get a number that is divisible by 10k. For example, if k = 3, in the number 30020 it is enough to delete a single digit (2). In this case, the result is 3000 that is divisible by 103 = 1000. Write a program that prints the minimum number of digits to be deleted from the given integer number n, so that the result is divisible by 10k. The result should not start with the unnecessary leading zero (i.e., zero can start only the number 0, which is required to be written as exactly one digit). It is guaranteed that the answer exists. Input The only line of the input contains two integer numbers n and k (0 ≀ n ≀ 2 000 000 000, 1 ≀ k ≀ 9). It is guaranteed that the answer exists. All numbers in the input are written in traditional notation of integers, that is, without any extra leading zeros. Output Print w β€” the required minimal number of digits to erase. After removing the appropriate w digits from the number n, the result should have a value that is divisible by 10k. The result can start with digit 0 in the single case (the result is zero and written by exactly the only digit 0). Examples Input 30020 3 Output 1 Input 100 9 Output 2 Input 10203049 2 Output 3 Note In the example 2 you can remove two digits: 1 and any 0. The result is number 0 which is divisible by any number. Submitted Solution: ``` n,k=input ().split (); k = int (k); n=n [::-1]; for i in range (0,100) : if n [:i].count ("0")>=k : print (i); break; else : print (str (len (n)-1)) ``` No
100,829
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10k. In the given number of n Polycarp wants to remove the least number of digits to get a number that is divisible by 10k. For example, if k = 3, in the number 30020 it is enough to delete a single digit (2). In this case, the result is 3000 that is divisible by 103 = 1000. Write a program that prints the minimum number of digits to be deleted from the given integer number n, so that the result is divisible by 10k. The result should not start with the unnecessary leading zero (i.e., zero can start only the number 0, which is required to be written as exactly one digit). It is guaranteed that the answer exists. Input The only line of the input contains two integer numbers n and k (0 ≀ n ≀ 2 000 000 000, 1 ≀ k ≀ 9). It is guaranteed that the answer exists. All numbers in the input are written in traditional notation of integers, that is, without any extra leading zeros. Output Print w β€” the required minimal number of digits to erase. After removing the appropriate w digits from the number n, the result should have a value that is divisible by 10k. The result can start with digit 0 in the single case (the result is zero and written by exactly the only digit 0). Examples Input 30020 3 Output 1 Input 100 9 Output 2 Input 10203049 2 Output 3 Note In the example 2 you can remove two digits: 1 and any 0. The result is number 0 which is divisible by any number. Submitted Solution: ``` n,k=map(str,input().strip().split()) k=int(k) num=str(10**k) if(len(n)<len(num)): print(len(n)-1) else: c,z=0,0 for i in range(len(n)-1,-1,-1): if(n[i]!='0'): c+=1 else: z+=1 if(z==k): break print(c) ``` No
100,830
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10k. In the given number of n Polycarp wants to remove the least number of digits to get a number that is divisible by 10k. For example, if k = 3, in the number 30020 it is enough to delete a single digit (2). In this case, the result is 3000 that is divisible by 103 = 1000. Write a program that prints the minimum number of digits to be deleted from the given integer number n, so that the result is divisible by 10k. The result should not start with the unnecessary leading zero (i.e., zero can start only the number 0, which is required to be written as exactly one digit). It is guaranteed that the answer exists. Input The only line of the input contains two integer numbers n and k (0 ≀ n ≀ 2 000 000 000, 1 ≀ k ≀ 9). It is guaranteed that the answer exists. All numbers in the input are written in traditional notation of integers, that is, without any extra leading zeros. Output Print w β€” the required minimal number of digits to erase. After removing the appropriate w digits from the number n, the result should have a value that is divisible by 10k. The result can start with digit 0 in the single case (the result is zero and written by exactly the only digit 0). Examples Input 30020 3 Output 1 Input 100 9 Output 2 Input 10203049 2 Output 3 Note In the example 2 you can remove two digits: 1 and any 0. The result is number 0 which is divisible by any number. Submitted Solution: ``` '''input 100 9 ''' n, k = map(int, input().split()) if str(n).count('0') >= k: x = str(n)[::-1] for l in range(1,len(x)): if x[:l].count('0') == k: print(l-k) else: print(len(str(n))-1) ``` No
100,831
Provide tags and a correct Python 3 solution for this coding contest problem. Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the message she is asked to deliver states: "Send the fool further!", and upon reading it the recipient will ask Heidi to deliver the same message to yet another friend (that the recipient has in common with Heidi), and so on. Heidi believes that her friends want to avoid awkward situations, so she will not be made to visit the same person (including Jenny) twice. She also knows how much it costs to travel between any two of her friends who know each other. She wants to know: what is the maximal amount of money she will waste on travel if it really is a prank? Heidi's n friends are labeled 0 through n - 1, and their network of connections forms a tree. In other words, every two of her friends a, b know each other, possibly indirectly (there is a sequence of friends starting from a and ending on b and such that each two consecutive friends in the sequence know each other directly), and there are exactly n - 1 pairs of friends who know each other directly. Jenny is given the number 0. Input The first line of the input contains the number of friends n (3 ≀ n ≀ 100). The next n - 1 lines each contain three space-separated integers u, v and c (0 ≀ u, v ≀ n - 1, 1 ≀ c ≀ 104), meaning that u and v are friends (know each other directly) and the cost for travelling between u and v is c. It is guaranteed that the social network of the input forms a tree. Output Output a single integer – the maximum sum of costs. Examples Input 4 0 1 4 0 2 2 2 3 3 Output 5 Input 6 1 2 3 0 2 100 1 4 2 0 3 7 3 5 10 Output 105 Input 11 1 0 1664 2 0 881 3 2 4670 4 2 1555 5 1 1870 6 2 1265 7 2 288 8 7 2266 9 2 1536 10 6 3378 Output 5551 Note In the second example, the worst-case scenario goes like this: Jenny sends Heidi to the friend labeled by number 2 (incurring a cost of 100), then friend 2 sends her to friend 1 (costing Heidi 3), and finally friend 1 relays her to friend 4 (incurring an additional cost of 2). Tags: dfs and similar, graphs, trees Correct Solution: ``` # maa chudaaye duniya from collections import defaultdict graph = defaultdict(list) n = int(input()) weights = {} for _ in range(n-1): a, b, w = map(int, input().split()) edge1 = '{} : {}'.format(a, b) edge2 = '{} : {}'.format(b, a) graph[a].append(b) graph[b].append(a) weights[edge1] = w weights[edge2] = w maxsf = [-10**9] visited = [False for i in range(n+1)] def dfs(node, parent, dist): visited[node] = True # print(maxsf) # print('checking ', node, parent) # print(visited) if parent != -1: e ='{} : {}'.format(parent, node) e1 = '{} : {}'.format(node, parent) if e in weights: dist += weights[e] # print(e, dist) else: dist += weights[e1] # print(e1, dist) if dist > maxsf[0]: maxsf[0] = dist for children in graph[node]: if not visited[children]: dfs(children, node, dist) dfs(0, -1, 0) print(*maxsf) ```
100,832
Provide tags and a correct Python 3 solution for this coding contest problem. Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the message she is asked to deliver states: "Send the fool further!", and upon reading it the recipient will ask Heidi to deliver the same message to yet another friend (that the recipient has in common with Heidi), and so on. Heidi believes that her friends want to avoid awkward situations, so she will not be made to visit the same person (including Jenny) twice. She also knows how much it costs to travel between any two of her friends who know each other. She wants to know: what is the maximal amount of money she will waste on travel if it really is a prank? Heidi's n friends are labeled 0 through n - 1, and their network of connections forms a tree. In other words, every two of her friends a, b know each other, possibly indirectly (there is a sequence of friends starting from a and ending on b and such that each two consecutive friends in the sequence know each other directly), and there are exactly n - 1 pairs of friends who know each other directly. Jenny is given the number 0. Input The first line of the input contains the number of friends n (3 ≀ n ≀ 100). The next n - 1 lines each contain three space-separated integers u, v and c (0 ≀ u, v ≀ n - 1, 1 ≀ c ≀ 104), meaning that u and v are friends (know each other directly) and the cost for travelling between u and v is c. It is guaranteed that the social network of the input forms a tree. Output Output a single integer – the maximum sum of costs. Examples Input 4 0 1 4 0 2 2 2 3 3 Output 5 Input 6 1 2 3 0 2 100 1 4 2 0 3 7 3 5 10 Output 105 Input 11 1 0 1664 2 0 881 3 2 4670 4 2 1555 5 1 1870 6 2 1265 7 2 288 8 7 2266 9 2 1536 10 6 3378 Output 5551 Note In the second example, the worst-case scenario goes like this: Jenny sends Heidi to the friend labeled by number 2 (incurring a cost of 100), then friend 2 sends her to friend 1 (costing Heidi 3), and finally friend 1 relays her to friend 4 (incurring an additional cost of 2). Tags: dfs and similar, graphs, trees Correct Solution: ``` import sys;readline = sys.stdin.readline def i1(): return int(readline()) def nl(): return [int(s) for s in readline().split()] def nn(n): return [int(readline()) for i in range(n)] def nnp(n,x): return [int(readline())+x for i in range(n)] def nmp(n,x): return (int(readline())+x for i in range(n)) def nlp(x): return [int(s)+x for s in readline().split()] def nll(n): return [[int(s) for s in readline().split()] for i in range(n)] def mll(n): return ([int(s) for s in readline().split()] for i in range(n)) def s1(): return readline().rstrip() def sl(): return [s for s in readline().split()] def sn(n): return [readline().rstrip() for i in range(n)] def sm(n): return (readline().rstrip() for i in range(n)) def redir(s): global readline;import os;fn=sys.argv[0] + f'/../in-{s}.txt';readline = open(fn).readline if os.path.exists(fn) else readline redir('j') n = i1() nodes = [[] for i in range(n+1)] costs = [[] for i in range(n+1)] seen = [False] * n for i in range(n-1): u,v,c = [int(i) for i in readline().split()] nodes[u].append(v) nodes[v].append(u) costs[u].append(c) costs[v].append(c) # print(n, nodes, costs) stk = [[0,len(nodes[0])]] seen[0] = True ccc = [0]*n # _ = 0 while stk: top = stk[-1] r = top[0] idx = top[1] - 1 ch = nodes[r] # _ += 1 # print('-'*_, top, idx, ch) while idx >= 0 and seen[ch[idx]]: idx -= 1 if idx < 0: stk.pop() continue top[-1] = idx # print(i, ch, ch[idx]) c = ch[idx] stk.append([c, len(nodes[c])]) seen[c] = True ccc[c] = ccc[r] + costs[r][idx] print(max(ccc)) ```
100,833
Provide tags and a correct Python 3 solution for this coding contest problem. Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the message she is asked to deliver states: "Send the fool further!", and upon reading it the recipient will ask Heidi to deliver the same message to yet another friend (that the recipient has in common with Heidi), and so on. Heidi believes that her friends want to avoid awkward situations, so she will not be made to visit the same person (including Jenny) twice. She also knows how much it costs to travel between any two of her friends who know each other. She wants to know: what is the maximal amount of money she will waste on travel if it really is a prank? Heidi's n friends are labeled 0 through n - 1, and their network of connections forms a tree. In other words, every two of her friends a, b know each other, possibly indirectly (there is a sequence of friends starting from a and ending on b and such that each two consecutive friends in the sequence know each other directly), and there are exactly n - 1 pairs of friends who know each other directly. Jenny is given the number 0. Input The first line of the input contains the number of friends n (3 ≀ n ≀ 100). The next n - 1 lines each contain three space-separated integers u, v and c (0 ≀ u, v ≀ n - 1, 1 ≀ c ≀ 104), meaning that u and v are friends (know each other directly) and the cost for travelling between u and v is c. It is guaranteed that the social network of the input forms a tree. Output Output a single integer – the maximum sum of costs. Examples Input 4 0 1 4 0 2 2 2 3 3 Output 5 Input 6 1 2 3 0 2 100 1 4 2 0 3 7 3 5 10 Output 105 Input 11 1 0 1664 2 0 881 3 2 4670 4 2 1555 5 1 1870 6 2 1265 7 2 288 8 7 2266 9 2 1536 10 6 3378 Output 5551 Note In the second example, the worst-case scenario goes like this: Jenny sends Heidi to the friend labeled by number 2 (incurring a cost of 100), then friend 2 sends her to friend 1 (costing Heidi 3), and finally friend 1 relays her to friend 4 (incurring an additional cost of 2). Tags: dfs and similar, graphs, trees Correct Solution: ``` from collections import defaultdict graph = defaultdict(list) d = {} n = int(input()) for i in range(n-1): u,v,cost = list(map(int,input().split())) graph[u].append(v) graph[v].append(u) x = str(u)+':'+str(v) y = str(v)+':'+str(u) d[x] = cost d[y] = cost q = [[0,0]] ans = [] visited = [False for i in range(n)] visited[0] = True while q!=[]: node,cost = q[0][0],q[0][1] q.pop(0) leaf = True for v in graph[node]: if visited[v]==False: visited[v]=True leaf = False x = str(node)+':'+str(v) y = str(v)+':'+str(node) if x in d: c = d[x] else: c = d[y] q.append([v,cost+c]) if leaf: ans.append(cost) print(max(ans)) ```
100,834
Provide tags and a correct Python 3 solution for this coding contest problem. Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the message she is asked to deliver states: "Send the fool further!", and upon reading it the recipient will ask Heidi to deliver the same message to yet another friend (that the recipient has in common with Heidi), and so on. Heidi believes that her friends want to avoid awkward situations, so she will not be made to visit the same person (including Jenny) twice. She also knows how much it costs to travel between any two of her friends who know each other. She wants to know: what is the maximal amount of money she will waste on travel if it really is a prank? Heidi's n friends are labeled 0 through n - 1, and their network of connections forms a tree. In other words, every two of her friends a, b know each other, possibly indirectly (there is a sequence of friends starting from a and ending on b and such that each two consecutive friends in the sequence know each other directly), and there are exactly n - 1 pairs of friends who know each other directly. Jenny is given the number 0. Input The first line of the input contains the number of friends n (3 ≀ n ≀ 100). The next n - 1 lines each contain three space-separated integers u, v and c (0 ≀ u, v ≀ n - 1, 1 ≀ c ≀ 104), meaning that u and v are friends (know each other directly) and the cost for travelling between u and v is c. It is guaranteed that the social network of the input forms a tree. Output Output a single integer – the maximum sum of costs. Examples Input 4 0 1 4 0 2 2 2 3 3 Output 5 Input 6 1 2 3 0 2 100 1 4 2 0 3 7 3 5 10 Output 105 Input 11 1 0 1664 2 0 881 3 2 4670 4 2 1555 5 1 1870 6 2 1265 7 2 288 8 7 2266 9 2 1536 10 6 3378 Output 5551 Note In the second example, the worst-case scenario goes like this: Jenny sends Heidi to the friend labeled by number 2 (incurring a cost of 100), then friend 2 sends her to friend 1 (costing Heidi 3), and finally friend 1 relays her to friend 4 (incurring an additional cost of 2). Tags: dfs and similar, graphs, trees Correct Solution: ``` def helper(curr,g,visited): ans=0 for i in g[curr]: if i[0] not in visited: visited.add(i[0]) ans=max(ans,i[1]+helper(i[0],g,visited)) visited.remove(i[0]) return ans n=int(input()) g=[[] for i in range(n)] for i in range(n-1): a,b,c=[int(x) for x in input().split()] g[a].append([b,c]) g[b].append([a,c]) visited=set() visited.add(0) print(helper(0,g,visited)) ```
100,835
Provide tags and a correct Python 3 solution for this coding contest problem. Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the message she is asked to deliver states: "Send the fool further!", and upon reading it the recipient will ask Heidi to deliver the same message to yet another friend (that the recipient has in common with Heidi), and so on. Heidi believes that her friends want to avoid awkward situations, so she will not be made to visit the same person (including Jenny) twice. She also knows how much it costs to travel between any two of her friends who know each other. She wants to know: what is the maximal amount of money she will waste on travel if it really is a prank? Heidi's n friends are labeled 0 through n - 1, and their network of connections forms a tree. In other words, every two of her friends a, b know each other, possibly indirectly (there is a sequence of friends starting from a and ending on b and such that each two consecutive friends in the sequence know each other directly), and there are exactly n - 1 pairs of friends who know each other directly. Jenny is given the number 0. Input The first line of the input contains the number of friends n (3 ≀ n ≀ 100). The next n - 1 lines each contain three space-separated integers u, v and c (0 ≀ u, v ≀ n - 1, 1 ≀ c ≀ 104), meaning that u and v are friends (know each other directly) and the cost for travelling between u and v is c. It is guaranteed that the social network of the input forms a tree. Output Output a single integer – the maximum sum of costs. Examples Input 4 0 1 4 0 2 2 2 3 3 Output 5 Input 6 1 2 3 0 2 100 1 4 2 0 3 7 3 5 10 Output 105 Input 11 1 0 1664 2 0 881 3 2 4670 4 2 1555 5 1 1870 6 2 1265 7 2 288 8 7 2266 9 2 1536 10 6 3378 Output 5551 Note In the second example, the worst-case scenario goes like this: Jenny sends Heidi to the friend labeled by number 2 (incurring a cost of 100), then friend 2 sends her to friend 1 (costing Heidi 3), and finally friend 1 relays her to friend 4 (incurring an additional cost of 2). Tags: dfs and similar, graphs, trees Correct Solution: ``` n = int(input()) matrix = [[] for i in range(n)] for i in range(n - 1): a = list(map(int, input().split())) matrix[a[0]].append([a[1], a[2]]) matrix[a[1]].append([a[0], a[2]]) way = [float('inf') for i in range(n)] used = [False for i in range(n)] v = 0 way[0] = 0 for i in range(n): used[v] = True for j in matrix[v]: way[j[0]] = min(way[j[0]], way[v] + j[1]) m = float('inf') for j in range(n): if way[j] < m and not used[j]: m = way[j] v = j print(max(way)) ```
100,836
Provide tags and a correct Python 3 solution for this coding contest problem. Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the message she is asked to deliver states: "Send the fool further!", and upon reading it the recipient will ask Heidi to deliver the same message to yet another friend (that the recipient has in common with Heidi), and so on. Heidi believes that her friends want to avoid awkward situations, so she will not be made to visit the same person (including Jenny) twice. She also knows how much it costs to travel between any two of her friends who know each other. She wants to know: what is the maximal amount of money she will waste on travel if it really is a prank? Heidi's n friends are labeled 0 through n - 1, and their network of connections forms a tree. In other words, every two of her friends a, b know each other, possibly indirectly (there is a sequence of friends starting from a and ending on b and such that each two consecutive friends in the sequence know each other directly), and there are exactly n - 1 pairs of friends who know each other directly. Jenny is given the number 0. Input The first line of the input contains the number of friends n (3 ≀ n ≀ 100). The next n - 1 lines each contain three space-separated integers u, v and c (0 ≀ u, v ≀ n - 1, 1 ≀ c ≀ 104), meaning that u and v are friends (know each other directly) and the cost for travelling between u and v is c. It is guaranteed that the social network of the input forms a tree. Output Output a single integer – the maximum sum of costs. Examples Input 4 0 1 4 0 2 2 2 3 3 Output 5 Input 6 1 2 3 0 2 100 1 4 2 0 3 7 3 5 10 Output 105 Input 11 1 0 1664 2 0 881 3 2 4670 4 2 1555 5 1 1870 6 2 1265 7 2 288 8 7 2266 9 2 1536 10 6 3378 Output 5551 Note In the second example, the worst-case scenario goes like this: Jenny sends Heidi to the friend labeled by number 2 (incurring a cost of 100), then friend 2 sends her to friend 1 (costing Heidi 3), and finally friend 1 relays her to friend 4 (incurring an additional cost of 2). Tags: dfs and similar, graphs, trees Correct Solution: ``` # Fast IO Region import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # Get out of main function def main(): pass # decimal to binary def binary(n): return (bin(n).replace("0b", "")) # binary to decimal def decimal(s): return (int(s, 2)) # power of a number base 2 def pow2(n): p = 0 while n > 1: n //= 2 p += 1 return (p) # if number is prime in √n time def isPrime(n): if (n == 1): return (False) else: root = int(n ** 0.5) root += 1 for i in range(2, root): if (n % i == 0): return (False) return (True) # list to string ,no spaces def lts(l): s = ''.join(map(str, l)) return s # String to list def stl(s): # for each character in string to list with no spaces --> l = list(s) # for space in string --> # l=list(s.split(" ")) return l # Returns list of numbers with a particular sum def sq(a, target, arr=[]): s = sum(arr) if (s == target): return arr if (s >= target): return for i in range(len(a)): n = a[i] remaining = a[i + 1:] ans = sq(remaining, target, arr + [n]) if (ans): return ans # Sieve for prime numbers in a range def SieveOfEratosthenes(n): cnt = 0 prime = [True for i in range(n + 1)] p = 2 while (p * p <= n): if (prime[p] == True): for i in range(p * p, n + 1, p): prime[i] = False p += 1 for p in range(2, n + 1): if prime[p]: cnt += 1 # print(p) return (cnt) # for positive integerse only def nCr(n, r): f = math.factorial return f(n) // f(r) // f(n - r) # 1000000007 mod = int(1e9) + 7 import math #import random #import bisect #from fractions import Fraction #from collections import OrderedDict #from collections import deque ######################## mat=[[0 for i in range(n)] for j in range(m)] ######################## ######################## list.sort(key=lambda x:x[1]) for sorting a list according to second element in sublist ######################## ######################## Speed: STRING < LIST < SET,DICTIONARY ######################## ######################## from collections import deque ######################## ######################## ASCII of A-Z= 65-90 ######################## ######################## ASCII of a-z= 97-122 ######################## ######################## d1.setdefault(key, []).append(value) ######################## #sys.setrecursionlimit(300000) #Gives memory limit exceeded if used a lot #for ___ in range(int(input())): n=int(input()) d={} visited=[0]*n dist={} for _ in range(n-1): u,v,c=map(int,input().split()) d.setdefault(u,[]).append(v) d.setdefault(v,[]).append(u) dist[(min(u,v),max(u,v))]=c stack=[[0,0]] ans=-1 while(stack!=[]): temp=stack.pop() node=temp[0] distance=temp[1] visited[node]=1 for child in d[node]: if(visited[child]==0): stack.append([child,distance+dist[min(node,child),max(node,child)]]) ans=max(ans,distance) print(ans) ```
100,837
Provide tags and a correct Python 3 solution for this coding contest problem. Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the message she is asked to deliver states: "Send the fool further!", and upon reading it the recipient will ask Heidi to deliver the same message to yet another friend (that the recipient has in common with Heidi), and so on. Heidi believes that her friends want to avoid awkward situations, so she will not be made to visit the same person (including Jenny) twice. She also knows how much it costs to travel between any two of her friends who know each other. She wants to know: what is the maximal amount of money she will waste on travel if it really is a prank? Heidi's n friends are labeled 0 through n - 1, and their network of connections forms a tree. In other words, every two of her friends a, b know each other, possibly indirectly (there is a sequence of friends starting from a and ending on b and such that each two consecutive friends in the sequence know each other directly), and there are exactly n - 1 pairs of friends who know each other directly. Jenny is given the number 0. Input The first line of the input contains the number of friends n (3 ≀ n ≀ 100). The next n - 1 lines each contain three space-separated integers u, v and c (0 ≀ u, v ≀ n - 1, 1 ≀ c ≀ 104), meaning that u and v are friends (know each other directly) and the cost for travelling between u and v is c. It is guaranteed that the social network of the input forms a tree. Output Output a single integer – the maximum sum of costs. Examples Input 4 0 1 4 0 2 2 2 3 3 Output 5 Input 6 1 2 3 0 2 100 1 4 2 0 3 7 3 5 10 Output 105 Input 11 1 0 1664 2 0 881 3 2 4670 4 2 1555 5 1 1870 6 2 1265 7 2 288 8 7 2266 9 2 1536 10 6 3378 Output 5551 Note In the second example, the worst-case scenario goes like this: Jenny sends Heidi to the friend labeled by number 2 (incurring a cost of 100), then friend 2 sends her to friend 1 (costing Heidi 3), and finally friend 1 relays her to friend 4 (incurring an additional cost of 2). Tags: dfs and similar, graphs, trees Correct Solution: ``` import sys sys.setrecursionlimit(10**6) ans = 0 def solve(): n = int(input()) Adj = [[] for i in range(n)] for i in range(n - 1): ai, bi, ci = map(int, sys.stdin.readline().split()) Adj[ai].append((bi, ci)) Adj[bi].append((ai, ci)) dfs(n, Adj, -1, 0, 0) print(ans) def dfs(n, Adj, p, u, cost): if u != 0 and len(Adj[u]) == 1: global ans ans = max(ans, cost) return for (v, c) in Adj[u]: if p == v: continue dfs(n, Adj, u, v, cost + c) if __name__ == '__main__': solve() ```
100,838
Provide tags and a correct Python 3 solution for this coding contest problem. Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the message she is asked to deliver states: "Send the fool further!", and upon reading it the recipient will ask Heidi to deliver the same message to yet another friend (that the recipient has in common with Heidi), and so on. Heidi believes that her friends want to avoid awkward situations, so she will not be made to visit the same person (including Jenny) twice. She also knows how much it costs to travel between any two of her friends who know each other. She wants to know: what is the maximal amount of money she will waste on travel if it really is a prank? Heidi's n friends are labeled 0 through n - 1, and their network of connections forms a tree. In other words, every two of her friends a, b know each other, possibly indirectly (there is a sequence of friends starting from a and ending on b and such that each two consecutive friends in the sequence know each other directly), and there are exactly n - 1 pairs of friends who know each other directly. Jenny is given the number 0. Input The first line of the input contains the number of friends n (3 ≀ n ≀ 100). The next n - 1 lines each contain three space-separated integers u, v and c (0 ≀ u, v ≀ n - 1, 1 ≀ c ≀ 104), meaning that u and v are friends (know each other directly) and the cost for travelling between u and v is c. It is guaranteed that the social network of the input forms a tree. Output Output a single integer – the maximum sum of costs. Examples Input 4 0 1 4 0 2 2 2 3 3 Output 5 Input 6 1 2 3 0 2 100 1 4 2 0 3 7 3 5 10 Output 105 Input 11 1 0 1664 2 0 881 3 2 4670 4 2 1555 5 1 1870 6 2 1265 7 2 288 8 7 2266 9 2 1536 10 6 3378 Output 5551 Note In the second example, the worst-case scenario goes like this: Jenny sends Heidi to the friend labeled by number 2 (incurring a cost of 100), then friend 2 sends her to friend 1 (costing Heidi 3), and finally friend 1 relays her to friend 4 (incurring an additional cost of 2). Tags: dfs and similar, graphs, trees Correct Solution: ``` count=[] def DFs(d,node,visited,c): visited.add(node) for i in d[node]: if i[0] not in visited: #c=c+i[1] DFs(d,i[0],visited,c+i[1]) count.append(c) def dfs(d,n): visited=set() for i in d.keys(): if i not in visited: c=0 DFs(d,i,visited,c) #count.append(a) n=int(input()) d={} for i in range(n): d[i]=[] for i in range(n-1): u,v,c=map(int,input().split(' ')) d[u].append([v,c]) d[v].append([u,c]) dfs(d,n) print(max(count)) ```
100,839
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the message she is asked to deliver states: "Send the fool further!", and upon reading it the recipient will ask Heidi to deliver the same message to yet another friend (that the recipient has in common with Heidi), and so on. Heidi believes that her friends want to avoid awkward situations, so she will not be made to visit the same person (including Jenny) twice. She also knows how much it costs to travel between any two of her friends who know each other. She wants to know: what is the maximal amount of money she will waste on travel if it really is a prank? Heidi's n friends are labeled 0 through n - 1, and their network of connections forms a tree. In other words, every two of her friends a, b know each other, possibly indirectly (there is a sequence of friends starting from a and ending on b and such that each two consecutive friends in the sequence know each other directly), and there are exactly n - 1 pairs of friends who know each other directly. Jenny is given the number 0. Input The first line of the input contains the number of friends n (3 ≀ n ≀ 100). The next n - 1 lines each contain three space-separated integers u, v and c (0 ≀ u, v ≀ n - 1, 1 ≀ c ≀ 104), meaning that u and v are friends (know each other directly) and the cost for travelling between u and v is c. It is guaranteed that the social network of the input forms a tree. Output Output a single integer – the maximum sum of costs. Examples Input 4 0 1 4 0 2 2 2 3 3 Output 5 Input 6 1 2 3 0 2 100 1 4 2 0 3 7 3 5 10 Output 105 Input 11 1 0 1664 2 0 881 3 2 4670 4 2 1555 5 1 1870 6 2 1265 7 2 288 8 7 2266 9 2 1536 10 6 3378 Output 5551 Note In the second example, the worst-case scenario goes like this: Jenny sends Heidi to the friend labeled by number 2 (incurring a cost of 100), then friend 2 sends her to friend 1 (costing Heidi 3), and finally friend 1 relays her to friend 4 (incurring an additional cost of 2). Submitted Solution: ``` import sys import threading from collections import defaultdict adj=defaultdict(list) n=int(input()) for _ in range(n-1): x,y,b=list(map(int,input().split())) adj[x].append((y,b)) adj[y].append((x,b)) def fun(node,par,x): y=x for ch,b in adj[node]: if ch!=par: y=max(fun(ch,node,x+b),y) return y def main(): print(fun(0,-1,0)) if __name__=="__main__": sys.setrecursionlimit(10**6) threading.stack_size(10**8) t = threading.Thread(target=main) t.start() t.join() ``` Yes
100,840
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the message she is asked to deliver states: "Send the fool further!", and upon reading it the recipient will ask Heidi to deliver the same message to yet another friend (that the recipient has in common with Heidi), and so on. Heidi believes that her friends want to avoid awkward situations, so she will not be made to visit the same person (including Jenny) twice. She also knows how much it costs to travel between any two of her friends who know each other. She wants to know: what is the maximal amount of money she will waste on travel if it really is a prank? Heidi's n friends are labeled 0 through n - 1, and their network of connections forms a tree. In other words, every two of her friends a, b know each other, possibly indirectly (there is a sequence of friends starting from a and ending on b and such that each two consecutive friends in the sequence know each other directly), and there are exactly n - 1 pairs of friends who know each other directly. Jenny is given the number 0. Input The first line of the input contains the number of friends n (3 ≀ n ≀ 100). The next n - 1 lines each contain three space-separated integers u, v and c (0 ≀ u, v ≀ n - 1, 1 ≀ c ≀ 104), meaning that u and v are friends (know each other directly) and the cost for travelling between u and v is c. It is guaranteed that the social network of the input forms a tree. Output Output a single integer – the maximum sum of costs. Examples Input 4 0 1 4 0 2 2 2 3 3 Output 5 Input 6 1 2 3 0 2 100 1 4 2 0 3 7 3 5 10 Output 105 Input 11 1 0 1664 2 0 881 3 2 4670 4 2 1555 5 1 1870 6 2 1265 7 2 288 8 7 2266 9 2 1536 10 6 3378 Output 5551 Note In the second example, the worst-case scenario goes like this: Jenny sends Heidi to the friend labeled by number 2 (incurring a cost of 100), then friend 2 sends her to friend 1 (costing Heidi 3), and finally friend 1 relays her to friend 4 (incurring an additional cost of 2). Submitted Solution: ``` def dfs(d,di): stack = [[0,0]] mark = {i:False for i in range(n)} mark[0]=True res=[] while stack: s = stack.pop() x,cost=s[0],s[1] res.append(cost) for i,y in enumerate(d[x]): if mark[y]==False: if di.get((x,y))==None: new_cost=di[(y,x)] else:new_cost=di[(x,y)] stack.append([y,cost+new_cost]) mark[y]=True print(max(res)) n = int(input()) di,d={},{} for i in range(n-1): u,v,c = map(int,input().split()) di[(u,v)]=c if d.get(u)==None:d[u]=[] if d.get(v)==None:d[v]=[] d[u].append(v) d[v].append(u) dfs(d,di) ``` Yes
100,841
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the message she is asked to deliver states: "Send the fool further!", and upon reading it the recipient will ask Heidi to deliver the same message to yet another friend (that the recipient has in common with Heidi), and so on. Heidi believes that her friends want to avoid awkward situations, so she will not be made to visit the same person (including Jenny) twice. She also knows how much it costs to travel between any two of her friends who know each other. She wants to know: what is the maximal amount of money she will waste on travel if it really is a prank? Heidi's n friends are labeled 0 through n - 1, and their network of connections forms a tree. In other words, every two of her friends a, b know each other, possibly indirectly (there is a sequence of friends starting from a and ending on b and such that each two consecutive friends in the sequence know each other directly), and there are exactly n - 1 pairs of friends who know each other directly. Jenny is given the number 0. Input The first line of the input contains the number of friends n (3 ≀ n ≀ 100). The next n - 1 lines each contain three space-separated integers u, v and c (0 ≀ u, v ≀ n - 1, 1 ≀ c ≀ 104), meaning that u and v are friends (know each other directly) and the cost for travelling between u and v is c. It is guaranteed that the social network of the input forms a tree. Output Output a single integer – the maximum sum of costs. Examples Input 4 0 1 4 0 2 2 2 3 3 Output 5 Input 6 1 2 3 0 2 100 1 4 2 0 3 7 3 5 10 Output 105 Input 11 1 0 1664 2 0 881 3 2 4670 4 2 1555 5 1 1870 6 2 1265 7 2 288 8 7 2266 9 2 1536 10 6 3378 Output 5551 Note In the second example, the worst-case scenario goes like this: Jenny sends Heidi to the friend labeled by number 2 (incurring a cost of 100), then friend 2 sends her to friend 1 (costing Heidi 3), and finally friend 1 relays her to friend 4 (incurring an additional cost of 2). Submitted Solution: ``` n = int(input()) li = [[] for i in range(0,n)] for i in range(n-1): u, v, c = map(int,input().split()) li[u].append((v,c)) li[v].append((u,c)) mc = 0 cost = 0 visited = [False] * n def DFS(num,visited,cost): global mc if cost > mc: mc = cost visited[num] = True for i in range(len(li[num])): if not visited[li[num][i][0]]: DFS(li[num][i][0],visited,cost+li[num][i][1]) DFS(0,visited,0) print(mc) ``` Yes
100,842
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the message she is asked to deliver states: "Send the fool further!", and upon reading it the recipient will ask Heidi to deliver the same message to yet another friend (that the recipient has in common with Heidi), and so on. Heidi believes that her friends want to avoid awkward situations, so she will not be made to visit the same person (including Jenny) twice. She also knows how much it costs to travel between any two of her friends who know each other. She wants to know: what is the maximal amount of money she will waste on travel if it really is a prank? Heidi's n friends are labeled 0 through n - 1, and their network of connections forms a tree. In other words, every two of her friends a, b know each other, possibly indirectly (there is a sequence of friends starting from a and ending on b and such that each two consecutive friends in the sequence know each other directly), and there are exactly n - 1 pairs of friends who know each other directly. Jenny is given the number 0. Input The first line of the input contains the number of friends n (3 ≀ n ≀ 100). The next n - 1 lines each contain three space-separated integers u, v and c (0 ≀ u, v ≀ n - 1, 1 ≀ c ≀ 104), meaning that u and v are friends (know each other directly) and the cost for travelling between u and v is c. It is guaranteed that the social network of the input forms a tree. Output Output a single integer – the maximum sum of costs. Examples Input 4 0 1 4 0 2 2 2 3 3 Output 5 Input 6 1 2 3 0 2 100 1 4 2 0 3 7 3 5 10 Output 105 Input 11 1 0 1664 2 0 881 3 2 4670 4 2 1555 5 1 1870 6 2 1265 7 2 288 8 7 2266 9 2 1536 10 6 3378 Output 5551 Note In the second example, the worst-case scenario goes like this: Jenny sends Heidi to the friend labeled by number 2 (incurring a cost of 100), then friend 2 sends her to friend 1 (costing Heidi 3), and finally friend 1 relays her to friend 4 (incurring an additional cost of 2). Submitted Solution: ``` import sys,os,io import math,bisect,operator inf,mod = float('inf'),10**9+7 # sys.setrecursionlimit(10 ** 6) from itertools import groupby,accumulate from heapq import heapify,heappop,heappush from collections import deque,Counter,defaultdict I = lambda : int(sys.stdin.buffer.readline()) Neo = lambda : list(map(int, sys.stdin.buffer.readline().split())) n = I() Ans = 0 G = defaultdict(list) C = defaultdict(int) for i in range(n-1): a,b,c = Neo() G[a].append(b) G[b].append(a) C[(a,b)] = c C[(b,a)] = c def hello(node,cost,vis): vis[node] = 1 global Ans # print(vis,node) for i in G[node]: if not vis[i]: hello(i,cost+C[(node,i)],vis[:]) else: Ans = max(Ans,cost) vis = [0]*(n) hello(0,0,vis) print(Ans) ``` Yes
100,843
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the message she is asked to deliver states: "Send the fool further!", and upon reading it the recipient will ask Heidi to deliver the same message to yet another friend (that the recipient has in common with Heidi), and so on. Heidi believes that her friends want to avoid awkward situations, so she will not be made to visit the same person (including Jenny) twice. She also knows how much it costs to travel between any two of her friends who know each other. She wants to know: what is the maximal amount of money she will waste on travel if it really is a prank? Heidi's n friends are labeled 0 through n - 1, and their network of connections forms a tree. In other words, every two of her friends a, b know each other, possibly indirectly (there is a sequence of friends starting from a and ending on b and such that each two consecutive friends in the sequence know each other directly), and there are exactly n - 1 pairs of friends who know each other directly. Jenny is given the number 0. Input The first line of the input contains the number of friends n (3 ≀ n ≀ 100). The next n - 1 lines each contain three space-separated integers u, v and c (0 ≀ u, v ≀ n - 1, 1 ≀ c ≀ 104), meaning that u and v are friends (know each other directly) and the cost for travelling between u and v is c. It is guaranteed that the social network of the input forms a tree. Output Output a single integer – the maximum sum of costs. Examples Input 4 0 1 4 0 2 2 2 3 3 Output 5 Input 6 1 2 3 0 2 100 1 4 2 0 3 7 3 5 10 Output 105 Input 11 1 0 1664 2 0 881 3 2 4670 4 2 1555 5 1 1870 6 2 1265 7 2 288 8 7 2266 9 2 1536 10 6 3378 Output 5551 Note In the second example, the worst-case scenario goes like this: Jenny sends Heidi to the friend labeled by number 2 (incurring a cost of 100), then friend 2 sends her to friend 1 (costing Heidi 3), and finally friend 1 relays her to friend 4 (incurring an additional cost of 2). Submitted Solution: ``` import math,sys,bisect,heapq from collections import defaultdict,Counter,deque from itertools import groupby,accumulate #sys.setrecursionlimit(200000000) int1 = lambda x: int(x) - 1 #def input(): return sys.stdin.readline().strip() input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__ ilele = lambda: map(int,input().split()) alele = lambda: list(map(int, input().split())) ilelec = lambda: map(int1,input().split()) alelec = lambda: list(map(int1, input().split())) def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] #MOD = 1000000000 + 7 def Y(c): print(["NO","YES"][c]) def y(c): print(["no","yes"][c]) def Yy(c): print(["No","Yes"][c]) N= int(input()) G = defaultdict(list) mark = {} def addEdge(a,b,c): G[a].append(b) G[b].append(a) mark[(a,b)] = c mark[(b,a)] = c Ans = [] def dfs(node,par = -1,tot = 0): Ans.append(tot) if len(G[node]) == 1: return 0 c = 0 for i in G[node]: if i != par: c = max(c, dfs(i,node,tot + mark[(i,node)])) return c for i in range(N-1): a,b,c = ilele() addEdge(a,b,c) dfs(0) if Ans: print(max(Ans)) exit(0) print(0) ``` No
100,844
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the message she is asked to deliver states: "Send the fool further!", and upon reading it the recipient will ask Heidi to deliver the same message to yet another friend (that the recipient has in common with Heidi), and so on. Heidi believes that her friends want to avoid awkward situations, so she will not be made to visit the same person (including Jenny) twice. She also knows how much it costs to travel between any two of her friends who know each other. She wants to know: what is the maximal amount of money she will waste on travel if it really is a prank? Heidi's n friends are labeled 0 through n - 1, and their network of connections forms a tree. In other words, every two of her friends a, b know each other, possibly indirectly (there is a sequence of friends starting from a and ending on b and such that each two consecutive friends in the sequence know each other directly), and there are exactly n - 1 pairs of friends who know each other directly. Jenny is given the number 0. Input The first line of the input contains the number of friends n (3 ≀ n ≀ 100). The next n - 1 lines each contain three space-separated integers u, v and c (0 ≀ u, v ≀ n - 1, 1 ≀ c ≀ 104), meaning that u and v are friends (know each other directly) and the cost for travelling between u and v is c. It is guaranteed that the social network of the input forms a tree. Output Output a single integer – the maximum sum of costs. Examples Input 4 0 1 4 0 2 2 2 3 3 Output 5 Input 6 1 2 3 0 2 100 1 4 2 0 3 7 3 5 10 Output 105 Input 11 1 0 1664 2 0 881 3 2 4670 4 2 1555 5 1 1870 6 2 1265 7 2 288 8 7 2266 9 2 1536 10 6 3378 Output 5551 Note In the second example, the worst-case scenario goes like this: Jenny sends Heidi to the friend labeled by number 2 (incurring a cost of 100), then friend 2 sends her to friend 1 (costing Heidi 3), and finally friend 1 relays her to friend 4 (incurring an additional cost of 2). Submitted Solution: ``` import math,sys,bisect,heapq from collections import defaultdict,Counter,deque from itertools import groupby,accumulate #sys.setrecursionlimit(200000000) int1 = lambda x: int(x) - 1 #def input(): return sys.stdin.readline().strip() input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__ ilele = lambda: map(int,input().split()) alele = lambda: list(map(int, input().split())) ilelec = lambda: map(int1,input().split()) alelec = lambda: list(map(int1, input().split())) def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] #MOD = 1000000000 + 7 def Y(c): print(["NO","YES"][c]) def y(c): print(["no","yes"][c]) def Yy(c): print(["No","Yes"][c]) N= int(input()) G = defaultdict(list) mark = {} def addEdge(a,b,c): G[a].append(b) G[b].append(a) mark[(a,b)] = c mark[(b,a)] = c Ans = 0 def dfs(node,par = -1,tot = 0): global Ans Ans = max(Ans,tot) if len(G[node]) == 1: return 0 c = 0 for i in G[node]: if i != par: c = max(c, dfs(i,node,tot + mark[(i,node)])) Ans = max(Ans,c) return c for i in range(N-1): a,b,c = ilele() addEdge(a,b,c) dfs(0) print(Ans) ``` No
100,845
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the message she is asked to deliver states: "Send the fool further!", and upon reading it the recipient will ask Heidi to deliver the same message to yet another friend (that the recipient has in common with Heidi), and so on. Heidi believes that her friends want to avoid awkward situations, so she will not be made to visit the same person (including Jenny) twice. She also knows how much it costs to travel between any two of her friends who know each other. She wants to know: what is the maximal amount of money she will waste on travel if it really is a prank? Heidi's n friends are labeled 0 through n - 1, and their network of connections forms a tree. In other words, every two of her friends a, b know each other, possibly indirectly (there is a sequence of friends starting from a and ending on b and such that each two consecutive friends in the sequence know each other directly), and there are exactly n - 1 pairs of friends who know each other directly. Jenny is given the number 0. Input The first line of the input contains the number of friends n (3 ≀ n ≀ 100). The next n - 1 lines each contain three space-separated integers u, v and c (0 ≀ u, v ≀ n - 1, 1 ≀ c ≀ 104), meaning that u and v are friends (know each other directly) and the cost for travelling between u and v is c. It is guaranteed that the social network of the input forms a tree. Output Output a single integer – the maximum sum of costs. Examples Input 4 0 1 4 0 2 2 2 3 3 Output 5 Input 6 1 2 3 0 2 100 1 4 2 0 3 7 3 5 10 Output 105 Input 11 1 0 1664 2 0 881 3 2 4670 4 2 1555 5 1 1870 6 2 1265 7 2 288 8 7 2266 9 2 1536 10 6 3378 Output 5551 Note In the second example, the worst-case scenario goes like this: Jenny sends Heidi to the friend labeled by number 2 (incurring a cost of 100), then friend 2 sends her to friend 1 (costing Heidi 3), and finally friend 1 relays her to friend 4 (incurring an additional cost of 2). Submitted Solution: ``` import os, sys from io import BytesIO, IOBase def main(): n = rint() g = graph(n) for i in range(n - 1): u, v, c = rints() g.addEdge(u, v, c) g.dfsUtil(0) class graph: def __init__(self, n): self.gdict, self.n = [[] for _ in range(n)], n def addEdge(self, node1, node2, w=None): self.gdict[node1].append((node2, w)) self.gdict[node2].append((node1, w)) def dfsUtil(self, v): stack, self.visit, ans = [(v, 0)], [0] * self.n, 0 while (stack): s, c = stack.pop() for i1, i2 in self.gdict[s]: if not self.visit[i1]: stack.append((i1, i2 + c)) self.visit[i1] = True ans = max(ans, i2 + c) print(ans) # FASTIO REGION class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") BUFSIZE = 8192 sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") rstr = lambda: input().strip() rstrs = lambda: [str(x) for x in input().split()] rstr_2d = lambda n: [rstr() for _ in range(n)] rint = lambda: int(input()) rints = lambda: [int(x) for x in input().split()] rint_2d = lambda n: [rint() for _ in range(n)] rints_2d = lambda n: [rints() for _ in range(n)] ceil1 = lambda a, b: (a + b - 1) // b if __name__ == '__main__': main() ``` No
100,846
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the message she is asked to deliver states: "Send the fool further!", and upon reading it the recipient will ask Heidi to deliver the same message to yet another friend (that the recipient has in common with Heidi), and so on. Heidi believes that her friends want to avoid awkward situations, so she will not be made to visit the same person (including Jenny) twice. She also knows how much it costs to travel between any two of her friends who know each other. She wants to know: what is the maximal amount of money she will waste on travel if it really is a prank? Heidi's n friends are labeled 0 through n - 1, and their network of connections forms a tree. In other words, every two of her friends a, b know each other, possibly indirectly (there is a sequence of friends starting from a and ending on b and such that each two consecutive friends in the sequence know each other directly), and there are exactly n - 1 pairs of friends who know each other directly. Jenny is given the number 0. Input The first line of the input contains the number of friends n (3 ≀ n ≀ 100). The next n - 1 lines each contain three space-separated integers u, v and c (0 ≀ u, v ≀ n - 1, 1 ≀ c ≀ 104), meaning that u and v are friends (know each other directly) and the cost for travelling between u and v is c. It is guaranteed that the social network of the input forms a tree. Output Output a single integer – the maximum sum of costs. Examples Input 4 0 1 4 0 2 2 2 3 3 Output 5 Input 6 1 2 3 0 2 100 1 4 2 0 3 7 3 5 10 Output 105 Input 11 1 0 1664 2 0 881 3 2 4670 4 2 1555 5 1 1870 6 2 1265 7 2 288 8 7 2266 9 2 1536 10 6 3378 Output 5551 Note In the second example, the worst-case scenario goes like this: Jenny sends Heidi to the friend labeled by number 2 (incurring a cost of 100), then friend 2 sends her to friend 1 (costing Heidi 3), and finally friend 1 relays her to friend 4 (incurring an additional cost of 2). Submitted Solution: ``` def dfs(s = 0, p = -1): global a global n if len(a[s]) == 1: return a[s][0][1] o = -1 pp = -1 for i in range(len(a[s])): if a[s][i][0] != p: if o == -1: o = dfs(a[s][i][0], s) else: o = max(o, dfs(a[s][i][0], s)) else: pp = i if p != -1: return o + a[s][pp][1] return o n = int(input()) a = [[] for i in range(n)] for i in range(n-1): x, y, z = map(int, input().split()) a[x] += [[y, z]] a[y] += [[x, z]] print(dfs()) ``` No
100,847
Provide tags and a correct Python 3 solution for this coding contest problem. Ivan wants to write a letter to his friend. The letter is a string s consisting of lowercase Latin letters. Unfortunately, when Ivan started writing the letter, he realised that it is very long and writing the whole letter may take extremely long time. So he wants to write the compressed version of string s instead of the string itself. The compressed version of string s is a sequence of strings c1, s1, c2, s2, ..., ck, sk, where ci is the decimal representation of number ai (without any leading zeroes) and si is some string consisting of lowercase Latin letters. If Ivan writes string s1 exactly a1 times, then string s2 exactly a2 times, and so on, the result will be string s. The length of a compressed version is |c1| + |s1| + |c2| + |s2|... |ck| + |sk|. Among all compressed versions Ivan wants to choose a version such that its length is minimum possible. Help Ivan to determine minimum possible length. Input The only line of input contains one string s consisting of lowercase Latin letters (1 ≀ |s| ≀ 8000). Output Output one integer number β€” the minimum possible length of a compressed version of s. Examples Input aaaaaaaaaa Output 3 Input abcab Output 6 Input cczabababab Output 7 Note In the first example Ivan will choose this compressed version: c1 is 10, s1 is a. In the second example Ivan will choose this compressed version: c1 is 1, s1 is abcab. In the third example Ivan will choose this compressed version: c1 is 2, s1 is c, c2 is 1, s2 is z, c3 is 4, s3 is ab. Tags: dp, hashing, string suffix structures, strings Correct Solution: ``` s=input() n=len(s) def f(s): n=len(s) ar=[0]*n i,j=1,0 while i<n: if(s[i]==s[j]): j+=1 ar[i]=j i+=1 else: if(j!=0):j=ar[j-1] else:i+=1 return ar dp=[n+1]*(n)+[0] for i in range(n-1,-1,-1): ar=f(s[i:]) for j in range(len(ar)): T=1 k=j+1 if(k%(k-ar[j])==0):T=k//(k-ar[j]) dp[i]=min(dp[i],len(str(T))+k//T+dp[i+k]) print(dp[0]) ```
100,848
Provide tags and a correct Python 3 solution for this coding contest problem. Ivan wants to write a letter to his friend. The letter is a string s consisting of lowercase Latin letters. Unfortunately, when Ivan started writing the letter, he realised that it is very long and writing the whole letter may take extremely long time. So he wants to write the compressed version of string s instead of the string itself. The compressed version of string s is a sequence of strings c1, s1, c2, s2, ..., ck, sk, where ci is the decimal representation of number ai (without any leading zeroes) and si is some string consisting of lowercase Latin letters. If Ivan writes string s1 exactly a1 times, then string s2 exactly a2 times, and so on, the result will be string s. The length of a compressed version is |c1| + |s1| + |c2| + |s2|... |ck| + |sk|. Among all compressed versions Ivan wants to choose a version such that its length is minimum possible. Help Ivan to determine minimum possible length. Input The only line of input contains one string s consisting of lowercase Latin letters (1 ≀ |s| ≀ 8000). Output Output one integer number β€” the minimum possible length of a compressed version of s. Examples Input aaaaaaaaaa Output 3 Input abcab Output 6 Input cczabababab Output 7 Note In the first example Ivan will choose this compressed version: c1 is 10, s1 is a. In the second example Ivan will choose this compressed version: c1 is 1, s1 is abcab. In the third example Ivan will choose this compressed version: c1 is 2, s1 is c, c2 is 1, s2 is z, c3 is 4, s3 is ab. Tags: dp, hashing, string suffix structures, strings Correct Solution: ``` def prefix(s): p = [0] for i in range(1, len(s)): j = p[-1] while j > 0 and s[j] != s[i]: j = p[j - 1] if s[i] == s[j]: j += 1 p.append(j) return p s = input() n = len(s) ans = [0] * (n + 1) i = n - 1 while i >= 0: p = prefix(s[i:]) ans[i] = 2 + ans[i + 1] for j in range(len(p)): z = 1 if (j + 1) % (j + 1 - p[j]) == 0: z = (j + 1) // (j + 1 - p[j]) res = len(str(z)) + (j + 1) // z + ans[i + j + 1] ans[i] = min(ans[i], res) i -= 1 print(ans[0]) ```
100,849
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ivan wants to write a letter to his friend. The letter is a string s consisting of lowercase Latin letters. Unfortunately, when Ivan started writing the letter, he realised that it is very long and writing the whole letter may take extremely long time. So he wants to write the compressed version of string s instead of the string itself. The compressed version of string s is a sequence of strings c1, s1, c2, s2, ..., ck, sk, where ci is the decimal representation of number ai (without any leading zeroes) and si is some string consisting of lowercase Latin letters. If Ivan writes string s1 exactly a1 times, then string s2 exactly a2 times, and so on, the result will be string s. The length of a compressed version is |c1| + |s1| + |c2| + |s2|... |ck| + |sk|. Among all compressed versions Ivan wants to choose a version such that its length is minimum possible. Help Ivan to determine minimum possible length. Input The only line of input contains one string s consisting of lowercase Latin letters (1 ≀ |s| ≀ 8000). Output Output one integer number β€” the minimum possible length of a compressed version of s. Examples Input aaaaaaaaaa Output 3 Input abcab Output 6 Input cczabababab Output 7 Note In the first example Ivan will choose this compressed version: c1 is 10, s1 is a. In the second example Ivan will choose this compressed version: c1 is 1, s1 is abcab. In the third example Ivan will choose this compressed version: c1 is 2, s1 is c, c2 is 1, s2 is z, c3 is 4, s3 is ab. Submitted Solution: ``` # D # s = input() # t = input() # # count_q = s.count('?') # set_t = set(t) # # c_s = {i: s.count(i) for i in set_t} # c_s['?'] = s.count('?') # # c_t = {i: t.count(i) for i in set_t} # # max_n = sum(c_s.values()) // sum(c_t.values()) # for i in set_t: # c_s[i] -= (c_t[i] * max_n) # # while True: # ss = c_s['?'] # for i in c_s.values(): # if i < 0: # ss += i # # if ss >= 0: # break # elif ss < 0: # for i in set_t: # c_s[i] += c_t[i] # # for i in set_t: # if c_s[i] < 0: # s = s.replace('?', i, -c_s[i]) # s = s.replace('?', 'a') # # print(s) # n, m = map(int, input().split()) # n, m = 3, 3 # a = ['1 2', # '1 3', # '3 2'] # N = [set() for _ in range(n+1)] # # for i in range(m): # # v, u = map(int, input().split()) # v, u = map(int, a[i].split()) # N[v].add(u) # # print(N) strs = input() res = [] while len(strs) > 0: n = 1 # print('s ', strs) for i in range(1, len(strs) // 2 + 1): # print(strs[i:], strs[:i], i) p = strs[:i] if strs[i:].startswith(p): while strs[i:].startswith(p): i += len(p) n += 1 strs = strs[i:] # print(res) res.append((n, p)) break else: if len(res) > 0 and res[-1][0] == 1: pp = res.pop() res.append((1, pp[1] + strs[0])) else: res.append((1, strs[0])) strs = strs[1:] size_res = 0 for i in res: size_res += len(str(i[0])) size_res += len(i[1]) # print(res) print(size_res) ``` No
100,850
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ivan wants to write a letter to his friend. The letter is a string s consisting of lowercase Latin letters. Unfortunately, when Ivan started writing the letter, he realised that it is very long and writing the whole letter may take extremely long time. So he wants to write the compressed version of string s instead of the string itself. The compressed version of string s is a sequence of strings c1, s1, c2, s2, ..., ck, sk, where ci is the decimal representation of number ai (without any leading zeroes) and si is some string consisting of lowercase Latin letters. If Ivan writes string s1 exactly a1 times, then string s2 exactly a2 times, and so on, the result will be string s. The length of a compressed version is |c1| + |s1| + |c2| + |s2|... |ck| + |sk|. Among all compressed versions Ivan wants to choose a version such that its length is minimum possible. Help Ivan to determine minimum possible length. Input The only line of input contains one string s consisting of lowercase Latin letters (1 ≀ |s| ≀ 8000). Output Output one integer number β€” the minimum possible length of a compressed version of s. Examples Input aaaaaaaaaa Output 3 Input abcab Output 6 Input cczabababab Output 7 Note In the first example Ivan will choose this compressed version: c1 is 10, s1 is a. In the second example Ivan will choose this compressed version: c1 is 1, s1 is abcab. In the third example Ivan will choose this compressed version: c1 is 2, s1 is c, c2 is 1, s2 is z, c3 is 4, s3 is ab. Submitted Solution: ``` from sys import stdin, stdout EPS = 10 ** (-20) INF = float('inf') sze = 26 s = stdin.readline().strip() dp = [INF for i in range(len(s) + 10)] dp[0] = 2 dp.append(0) for i in range(1, len(s)): dp[i] = i + 2 for z in range(i): q = s[z: i + 1] dividers = [] for j in range(1, int((i - z + 1) ** 0.5) + 1): if not (i - z + 1) % j: dividers.append(j) if i - z + 1 == int((i - z + 1) ** 0.5): dividers = list(set(dividers)) for v in dividers: label = 1 ind = 0 while ind < len(q): if q[ind: ind + v] != q[:v]: label = 0 ind += v if label: dp[i] = min(dp[i], dp[z - 1] + len(str(len(q) // v)) + v) stdout.write(str(dp[len(s) - 1])) ``` No
100,851
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ivan wants to write a letter to his friend. The letter is a string s consisting of lowercase Latin letters. Unfortunately, when Ivan started writing the letter, he realised that it is very long and writing the whole letter may take extremely long time. So he wants to write the compressed version of string s instead of the string itself. The compressed version of string s is a sequence of strings c1, s1, c2, s2, ..., ck, sk, where ci is the decimal representation of number ai (without any leading zeroes) and si is some string consisting of lowercase Latin letters. If Ivan writes string s1 exactly a1 times, then string s2 exactly a2 times, and so on, the result will be string s. The length of a compressed version is |c1| + |s1| + |c2| + |s2|... |ck| + |sk|. Among all compressed versions Ivan wants to choose a version such that its length is minimum possible. Help Ivan to determine minimum possible length. Input The only line of input contains one string s consisting of lowercase Latin letters (1 ≀ |s| ≀ 8000). Output Output one integer number β€” the minimum possible length of a compressed version of s. Examples Input aaaaaaaaaa Output 3 Input abcab Output 6 Input cczabababab Output 7 Note In the first example Ivan will choose this compressed version: c1 is 10, s1 is a. In the second example Ivan will choose this compressed version: c1 is 1, s1 is abcab. In the third example Ivan will choose this compressed version: c1 is 2, s1 is c, c2 is 1, s2 is z, c3 is 4, s3 is ab. Submitted Solution: ``` # D # s = input() # t = input() # # count_q = s.count('?') # set_t = set(t) # # c_s = {i: s.count(i) for i in set_t} # c_s['?'] = s.count('?') # # c_t = {i: t.count(i) for i in set_t} # # max_n = sum(c_s.values()) // sum(c_t.values()) # for i in set_t: # c_s[i] -= (c_t[i] * max_n) # # while True: # ss = c_s['?'] # for i in c_s.values(): # if i < 0: # ss += i # # if ss >= 0: # break # elif ss < 0: # for i in set_t: # c_s[i] += c_t[i] # # for i in set_t: # if c_s[i] < 0: # s = s.replace('?', i, -c_s[i]) # s = s.replace('?', 'a') # # print(s) # n, m = map(int, input().split()) # n, m = 3, 3 # a = ['1 2', # '1 3', # '3 2'] # N = [set() for _ in range(n+1)] # # for i in range(m): # # v, u = map(int, input().split()) # v, u = map(int, a[i].split()) # N[v].add(u) # # print(N) strs = input() res = [] while len(strs) > 0: temp = [] # print('s ', strs) for i in range(len(strs) // 2 + 1, 0, - 1): n = 1 # print(strs[i:], strs[:i], i) p = strs[:i] if strs[i:].startswith(p): while strs[i:].startswith(p): i += len(p) n += 1 temp.append((n, p)) # print(temp) if len(temp) > 0: m = max(temp, key=lambda x: (x[0] * len(x[1])) - (len(str(x[0]) + x[1]))) off = m[0] * len(m[1]) res.append(m) strs = strs[off:] else: if len(res) > 0 and res[-1][0] == 1: pp = res.pop() res.append((1, pp[1] + strs[0])) else: res.append((1, strs[0])) strs = strs[1:] size_res = 0 for i in res: size_res += len(str(i[0])) size_res += len(i[1]) print(size_res) ``` No
100,852
Provide tags and a correct Python 3 solution for this coding contest problem. A never-ending, fast-changing and dream-like world unfolds, as the secret door opens. A world is an unordered graph G, in whose vertex set V(G) there are two special vertices s(G) and t(G). An initial world has vertex set {s(G), t(G)} and an edge between them. A total of n changes took place in an initial world. In each change, a new vertex w is added into V(G), an existing edge (u, v) is chosen, and two edges (u, w) and (v, w) are added into E(G). Note that it's possible that some edges are chosen in more than one change. It's known that the capacity of the minimum s-t cut of the resulting graph is m, that is, at least m edges need to be removed in order to make s(G) and t(G) disconnected. Count the number of non-similar worlds that can be built under the constraints, modulo 109 + 7. We define two worlds similar, if they are isomorphic and there is isomorphism in which the s and t vertices are not relabelled. Formally, two worlds G and H are considered similar, if there is a bijection between their vertex sets <image>, such that: * f(s(G)) = s(H); * f(t(G)) = t(H); * Two vertices u and v of G are adjacent in G if and only if f(u) and f(v) are adjacent in H. Input The first and only line of input contains two space-separated integers n, m (1 ≀ n, m ≀ 50) β€” the number of operations performed and the minimum cut, respectively. Output Output one integer β€” the number of non-similar worlds that can be built, modulo 109 + 7. Examples Input 3 2 Output 6 Input 4 4 Output 3 Input 7 3 Output 1196 Input 31 8 Output 64921457 Note In the first example, the following 6 worlds are pairwise non-similar and satisfy the constraints, with s(G) marked in green, t(G) marked in blue, and one of their minimum cuts in light blue. <image> In the second example, the following 3 worlds satisfy the constraints. <image> Tags: combinatorics, dp, flows, graphs Correct Solution: ``` mod = int(1e9 + 7) n, m = map(int, input().split()) f = [ [0 for i in range(60)] for j in range(60) ] g = [ [0 for i in range(60)] for j in range(60) ] s = [ [0 for i in range(60)] for j in range(60) ] inv = [ 1 ] f[0][0] = s[0][0] = 1 def pow(x, exp) : res = 1 for i in range(0, 31) : if exp & 1 : res = res * x % mod exp >>= 1 if exp == 0 : break x = x * x % mod return res for i in range(1, n + 1) : inv.append( pow(i, mod - 2) ) for node in range(1, n + 1) : for cut in range(1, n + 1) : tmp = 0 for ln in range(node) : for lc in range(cut - 1, n + 1) : if f[ln][lc] == 0 : continue if lc == cut - 1 : tmp = ( tmp + f[ln][lc] * s[node - ln - 1][cut - 1] ) % mod else : tmp = ( tmp + f[ln][lc] * f[node - ln - 1][cut - 1] ) % mod cnt = 1 if tmp != 0 : cn, cc = 0, 0 for i in range(1, n + 1) : cn += node cc += cut cnt = cnt * (tmp + i - 1) % mod * inv[i] % mod if cn > n or cc > n : break for j in range(n - cn, -1, -1) : for k in range(n - cc, -1, -1) : if f[j][k] == 0 : continue g[j + cn][k + cc] += f[j][k] * cnt g[j + cn][k + cc] %= mod for i in range(n + 1) : for j in range(n + 1) : f[i][j] = (f[i][j] + g[i][j]) % mod g[i][j] = 0 for cut in range(n, -1, -1) : s[node][cut] = ( s[node][cut + 1] + f[node][cut] ) % mod print(f[n][m - 1]) ```
100,853
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a1, a2, ..., an consisting of n integers, and an integer k. You have to split the array into exactly k non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the k obtained minimums. What is the maximum possible integer you can get? Definitions of subsegment and array splitting are given in notes. Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 105) β€” the size of the array a and the number of subsegments you have to split the array to. The second line contains n integers a1, a2, ..., an ( - 109 ≀ ai ≀ 109). Output Print single integer β€” the maximum possible integer you can get if you split the array into k non-empty subsegments and take maximum of minimums on the subsegments. Examples Input 5 2 1 2 3 4 5 Output 5 Input 5 1 -4 -5 -3 -2 -1 Output -5 Note A subsegment [l, r] (l ≀ r) of array a is the sequence al, al + 1, ..., ar. Splitting of array a of n elements into k subsegments [l1, r1], [l2, r2], ..., [lk, rk] (l1 = 1, rk = n, li = ri - 1 + 1 for all i > 1) is k sequences (al1, ..., ar1), ..., (alk, ..., ark). In the first example you should split the array into subsegments [1, 4] and [5, 5] that results in sequences (1, 2, 3, 4) and (5). The minimums are min(1, 2, 3, 4) = 1 and min(5) = 5. The resulting maximum is max(1, 5) = 5. It is obvious that you can't reach greater result. In the second example the only option you have is to split the array into one subsegment [1, 5], that results in one sequence ( - 4, - 5, - 3, - 2, - 1). The only minimum is min( - 4, - 5, - 3, - 2, - 1) = - 5. The resulting maximum is - 5. Tags: greedy Correct Solution: ``` n, k = map(int, input().split(' ')) arr = list(map(int, input().split(' '))) if k > 2: print(sorted(arr)[-1]) elif k == 2: if arr[0] > arr[-1]: print(arr[0]) else: print(arr[-1]) elif k == 1: print(sorted(arr)[0]) ```
100,854
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a1, a2, ..., an consisting of n integers, and an integer k. You have to split the array into exactly k non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the k obtained minimums. What is the maximum possible integer you can get? Definitions of subsegment and array splitting are given in notes. Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 105) β€” the size of the array a and the number of subsegments you have to split the array to. The second line contains n integers a1, a2, ..., an ( - 109 ≀ ai ≀ 109). Output Print single integer β€” the maximum possible integer you can get if you split the array into k non-empty subsegments and take maximum of minimums on the subsegments. Examples Input 5 2 1 2 3 4 5 Output 5 Input 5 1 -4 -5 -3 -2 -1 Output -5 Note A subsegment [l, r] (l ≀ r) of array a is the sequence al, al + 1, ..., ar. Splitting of array a of n elements into k subsegments [l1, r1], [l2, r2], ..., [lk, rk] (l1 = 1, rk = n, li = ri - 1 + 1 for all i > 1) is k sequences (al1, ..., ar1), ..., (alk, ..., ark). In the first example you should split the array into subsegments [1, 4] and [5, 5] that results in sequences (1, 2, 3, 4) and (5). The minimums are min(1, 2, 3, 4) = 1 and min(5) = 5. The resulting maximum is max(1, 5) = 5. It is obvious that you can't reach greater result. In the second example the only option you have is to split the array into one subsegment [1, 5], that results in one sequence ( - 4, - 5, - 3, - 2, - 1). The only minimum is min( - 4, - 5, - 3, - 2, - 1) = - 5. The resulting maximum is - 5. Tags: greedy Correct Solution: ``` n,k=map(int,input().split()) a=list(map(int,input().split())) if k==1: print(min(a)) #vibora net - minimum elif k==2: if a[0]>=a[n-1]: print(a[0]) else: # mojno videlit krainiy print(a[n-1]) elif k%2==1: print(max(a)) # mojno videlit max v 1[] else: print(max(a)) #4 and more k ```
100,855
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a1, a2, ..., an consisting of n integers, and an integer k. You have to split the array into exactly k non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the k obtained minimums. What is the maximum possible integer you can get? Definitions of subsegment and array splitting are given in notes. Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 105) β€” the size of the array a and the number of subsegments you have to split the array to. The second line contains n integers a1, a2, ..., an ( - 109 ≀ ai ≀ 109). Output Print single integer β€” the maximum possible integer you can get if you split the array into k non-empty subsegments and take maximum of minimums on the subsegments. Examples Input 5 2 1 2 3 4 5 Output 5 Input 5 1 -4 -5 -3 -2 -1 Output -5 Note A subsegment [l, r] (l ≀ r) of array a is the sequence al, al + 1, ..., ar. Splitting of array a of n elements into k subsegments [l1, r1], [l2, r2], ..., [lk, rk] (l1 = 1, rk = n, li = ri - 1 + 1 for all i > 1) is k sequences (al1, ..., ar1), ..., (alk, ..., ark). In the first example you should split the array into subsegments [1, 4] and [5, 5] that results in sequences (1, 2, 3, 4) and (5). The minimums are min(1, 2, 3, 4) = 1 and min(5) = 5. The resulting maximum is max(1, 5) = 5. It is obvious that you can't reach greater result. In the second example the only option you have is to split the array into one subsegment [1, 5], that results in one sequence ( - 4, - 5, - 3, - 2, - 1). The only minimum is min( - 4, - 5, - 3, - 2, - 1) = - 5. The resulting maximum is - 5. Tags: greedy Correct Solution: ``` nums = input().split() nums = [int(x) for x in nums] other_nums = input().split() other_nums = [int(x) for x in other_nums] if nums[1] == 1: print(min(other_nums)) elif nums[1] == 2: first = other_nums[0] last = other_nums[-1] if first < last: print(last) else: print(first) elif nums[1] >= 3: print(max(other_nums)) ```
100,856
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a1, a2, ..., an consisting of n integers, and an integer k. You have to split the array into exactly k non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the k obtained minimums. What is the maximum possible integer you can get? Definitions of subsegment and array splitting are given in notes. Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 105) β€” the size of the array a and the number of subsegments you have to split the array to. The second line contains n integers a1, a2, ..., an ( - 109 ≀ ai ≀ 109). Output Print single integer β€” the maximum possible integer you can get if you split the array into k non-empty subsegments and take maximum of minimums on the subsegments. Examples Input 5 2 1 2 3 4 5 Output 5 Input 5 1 -4 -5 -3 -2 -1 Output -5 Note A subsegment [l, r] (l ≀ r) of array a is the sequence al, al + 1, ..., ar. Splitting of array a of n elements into k subsegments [l1, r1], [l2, r2], ..., [lk, rk] (l1 = 1, rk = n, li = ri - 1 + 1 for all i > 1) is k sequences (al1, ..., ar1), ..., (alk, ..., ark). In the first example you should split the array into subsegments [1, 4] and [5, 5] that results in sequences (1, 2, 3, 4) and (5). The minimums are min(1, 2, 3, 4) = 1 and min(5) = 5. The resulting maximum is max(1, 5) = 5. It is obvious that you can't reach greater result. In the second example the only option you have is to split the array into one subsegment [1, 5], that results in one sequence ( - 4, - 5, - 3, - 2, - 1). The only minimum is min( - 4, - 5, - 3, - 2, - 1) = - 5. The resulting maximum is - 5. Tags: greedy Correct Solution: ``` first_line = input().split(" ") array_size = int(first_line[0]) subsegments = int(first_line[1]) # print(subsegments) array = input().split(" ") desired_array = [int(numeric_string) for numeric_string in array] int_array = [int(numeric_string) for numeric_string in array] desired_array.sort(reverse=True) # print(subsegments) if (subsegments == 1): print(desired_array[-1]) elif (subsegments >= 3): print(desired_array[0]) else: if (int_array[0] > int_array[-1]): print(int_array[0]) else: print(int_array[-1]) ```
100,857
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a1, a2, ..., an consisting of n integers, and an integer k. You have to split the array into exactly k non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the k obtained minimums. What is the maximum possible integer you can get? Definitions of subsegment and array splitting are given in notes. Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 105) β€” the size of the array a and the number of subsegments you have to split the array to. The second line contains n integers a1, a2, ..., an ( - 109 ≀ ai ≀ 109). Output Print single integer β€” the maximum possible integer you can get if you split the array into k non-empty subsegments and take maximum of minimums on the subsegments. Examples Input 5 2 1 2 3 4 5 Output 5 Input 5 1 -4 -5 -3 -2 -1 Output -5 Note A subsegment [l, r] (l ≀ r) of array a is the sequence al, al + 1, ..., ar. Splitting of array a of n elements into k subsegments [l1, r1], [l2, r2], ..., [lk, rk] (l1 = 1, rk = n, li = ri - 1 + 1 for all i > 1) is k sequences (al1, ..., ar1), ..., (alk, ..., ark). In the first example you should split the array into subsegments [1, 4] and [5, 5] that results in sequences (1, 2, 3, 4) and (5). The minimums are min(1, 2, 3, 4) = 1 and min(5) = 5. The resulting maximum is max(1, 5) = 5. It is obvious that you can't reach greater result. In the second example the only option you have is to split the array into one subsegment [1, 5], that results in one sequence ( - 4, - 5, - 3, - 2, - 1). The only minimum is min( - 4, - 5, - 3, - 2, - 1) = - 5. The resulting maximum is - 5. Tags: greedy Correct Solution: ``` n, k = map(int, input().split()) a = list(map(int, input().split())) mx = a.index(max(a)) nk = n - k RL = [] if mx - nk < 0: st = 0 else: st = mx - nk if mx + nk > n - 1: en = n - 1 else: en = mx + nk if k == 1: print(min(a)) elif k == 2: print(max(a[0], a[n - 1])) else: for i in range(st, mx + 1): RL.append(a[i]) for j in range(mx, en + 1): RL.append(a[j]) print(max(RL)) ```
100,858
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a1, a2, ..., an consisting of n integers, and an integer k. You have to split the array into exactly k non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the k obtained minimums. What is the maximum possible integer you can get? Definitions of subsegment and array splitting are given in notes. Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 105) β€” the size of the array a and the number of subsegments you have to split the array to. The second line contains n integers a1, a2, ..., an ( - 109 ≀ ai ≀ 109). Output Print single integer β€” the maximum possible integer you can get if you split the array into k non-empty subsegments and take maximum of minimums on the subsegments. Examples Input 5 2 1 2 3 4 5 Output 5 Input 5 1 -4 -5 -3 -2 -1 Output -5 Note A subsegment [l, r] (l ≀ r) of array a is the sequence al, al + 1, ..., ar. Splitting of array a of n elements into k subsegments [l1, r1], [l2, r2], ..., [lk, rk] (l1 = 1, rk = n, li = ri - 1 + 1 for all i > 1) is k sequences (al1, ..., ar1), ..., (alk, ..., ark). In the first example you should split the array into subsegments [1, 4] and [5, 5] that results in sequences (1, 2, 3, 4) and (5). The minimums are min(1, 2, 3, 4) = 1 and min(5) = 5. The resulting maximum is max(1, 5) = 5. It is obvious that you can't reach greater result. In the second example the only option you have is to split the array into one subsegment [1, 5], that results in one sequence ( - 4, - 5, - 3, - 2, - 1). The only minimum is min( - 4, - 5, - 3, - 2, - 1) = - 5. The resulting maximum is - 5. Tags: greedy Correct Solution: ``` n,k=map(int,input().split()) l=list(map(int,input().split())) M=max(l) m=min(l) if k==1: print(m) elif k>=3: print(M) else: if l.index(M)==0 or l.index(M)==len(l)-1: print(M) else : if l.index(m)==0: print(l[len(l)-1]) elif l.index(m)==len(l)-1: print(l[0]) else : print(max(l[0],l[len(l)-1])) ```
100,859
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a1, a2, ..., an consisting of n integers, and an integer k. You have to split the array into exactly k non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the k obtained minimums. What is the maximum possible integer you can get? Definitions of subsegment and array splitting are given in notes. Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 105) β€” the size of the array a and the number of subsegments you have to split the array to. The second line contains n integers a1, a2, ..., an ( - 109 ≀ ai ≀ 109). Output Print single integer β€” the maximum possible integer you can get if you split the array into k non-empty subsegments and take maximum of minimums on the subsegments. Examples Input 5 2 1 2 3 4 5 Output 5 Input 5 1 -4 -5 -3 -2 -1 Output -5 Note A subsegment [l, r] (l ≀ r) of array a is the sequence al, al + 1, ..., ar. Splitting of array a of n elements into k subsegments [l1, r1], [l2, r2], ..., [lk, rk] (l1 = 1, rk = n, li = ri - 1 + 1 for all i > 1) is k sequences (al1, ..., ar1), ..., (alk, ..., ark). In the first example you should split the array into subsegments [1, 4] and [5, 5] that results in sequences (1, 2, 3, 4) and (5). The minimums are min(1, 2, 3, 4) = 1 and min(5) = 5. The resulting maximum is max(1, 5) = 5. It is obvious that you can't reach greater result. In the second example the only option you have is to split the array into one subsegment [1, 5], that results in one sequence ( - 4, - 5, - 3, - 2, - 1). The only minimum is min( - 4, - 5, - 3, - 2, - 1) = - 5. The resulting maximum is - 5. Tags: greedy Correct Solution: ``` n , m = map(int , input().split()) li = list(map(int , input().split())) if m == 1 : print(min(li)) elif m == 2 : print(max(li[0], li[-1])) else: print(max(li)) ```
100,860
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an array a1, a2, ..., an consisting of n integers, and an integer k. You have to split the array into exactly k non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the k obtained minimums. What is the maximum possible integer you can get? Definitions of subsegment and array splitting are given in notes. Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 105) β€” the size of the array a and the number of subsegments you have to split the array to. The second line contains n integers a1, a2, ..., an ( - 109 ≀ ai ≀ 109). Output Print single integer β€” the maximum possible integer you can get if you split the array into k non-empty subsegments and take maximum of minimums on the subsegments. Examples Input 5 2 1 2 3 4 5 Output 5 Input 5 1 -4 -5 -3 -2 -1 Output -5 Note A subsegment [l, r] (l ≀ r) of array a is the sequence al, al + 1, ..., ar. Splitting of array a of n elements into k subsegments [l1, r1], [l2, r2], ..., [lk, rk] (l1 = 1, rk = n, li = ri - 1 + 1 for all i > 1) is k sequences (al1, ..., ar1), ..., (alk, ..., ark). In the first example you should split the array into subsegments [1, 4] and [5, 5] that results in sequences (1, 2, 3, 4) and (5). The minimums are min(1, 2, 3, 4) = 1 and min(5) = 5. The resulting maximum is max(1, 5) = 5. It is obvious that you can't reach greater result. In the second example the only option you have is to split the array into one subsegment [1, 5], that results in one sequence ( - 4, - 5, - 3, - 2, - 1). The only minimum is min( - 4, - 5, - 3, - 2, - 1) = - 5. The resulting maximum is - 5. Tags: greedy Correct Solution: ``` a, c = map(int,input().split()) N = list(map(int,input().split())) if c == 2: print(max(N[-1],N[0])) elif c > 1: print(max(N)) else: print(min(N)) ```
100,861
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a1, a2, ..., an consisting of n integers, and an integer k. You have to split the array into exactly k non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the k obtained minimums. What is the maximum possible integer you can get? Definitions of subsegment and array splitting are given in notes. Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 105) β€” the size of the array a and the number of subsegments you have to split the array to. The second line contains n integers a1, a2, ..., an ( - 109 ≀ ai ≀ 109). Output Print single integer β€” the maximum possible integer you can get if you split the array into k non-empty subsegments and take maximum of minimums on the subsegments. Examples Input 5 2 1 2 3 4 5 Output 5 Input 5 1 -4 -5 -3 -2 -1 Output -5 Note A subsegment [l, r] (l ≀ r) of array a is the sequence al, al + 1, ..., ar. Splitting of array a of n elements into k subsegments [l1, r1], [l2, r2], ..., [lk, rk] (l1 = 1, rk = n, li = ri - 1 + 1 for all i > 1) is k sequences (al1, ..., ar1), ..., (alk, ..., ark). In the first example you should split the array into subsegments [1, 4] and [5, 5] that results in sequences (1, 2, 3, 4) and (5). The minimums are min(1, 2, 3, 4) = 1 and min(5) = 5. The resulting maximum is max(1, 5) = 5. It is obvious that you can't reach greater result. In the second example the only option you have is to split the array into one subsegment [1, 5], that results in one sequence ( - 4, - 5, - 3, - 2, - 1). The only minimum is min( - 4, - 5, - 3, - 2, - 1) = - 5. The resulting maximum is - 5. Submitted Solution: ``` x = list(map(int, input().split())) n = x[0] k = x[1] a = list(map(int, input().split())) A = max(a) if k == 1: ans = min(a) elif k == 2: ans = max(a[0], a[-1]) else: ans = A print(ans) ``` Yes
100,862
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a1, a2, ..., an consisting of n integers, and an integer k. You have to split the array into exactly k non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the k obtained minimums. What is the maximum possible integer you can get? Definitions of subsegment and array splitting are given in notes. Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 105) β€” the size of the array a and the number of subsegments you have to split the array to. The second line contains n integers a1, a2, ..., an ( - 109 ≀ ai ≀ 109). Output Print single integer β€” the maximum possible integer you can get if you split the array into k non-empty subsegments and take maximum of minimums on the subsegments. Examples Input 5 2 1 2 3 4 5 Output 5 Input 5 1 -4 -5 -3 -2 -1 Output -5 Note A subsegment [l, r] (l ≀ r) of array a is the sequence al, al + 1, ..., ar. Splitting of array a of n elements into k subsegments [l1, r1], [l2, r2], ..., [lk, rk] (l1 = 1, rk = n, li = ri - 1 + 1 for all i > 1) is k sequences (al1, ..., ar1), ..., (alk, ..., ark). In the first example you should split the array into subsegments [1, 4] and [5, 5] that results in sequences (1, 2, 3, 4) and (5). The minimums are min(1, 2, 3, 4) = 1 and min(5) = 5. The resulting maximum is max(1, 5) = 5. It is obvious that you can't reach greater result. In the second example the only option you have is to split the array into one subsegment [1, 5], that results in one sequence ( - 4, - 5, - 3, - 2, - 1). The only minimum is min( - 4, - 5, - 3, - 2, - 1) = - 5. The resulting maximum is - 5. Submitted Solution: ``` a = [int(s) for s in input().split()] b = [int(s) for s in input().split()] if (a[1] == 1): minimum = b[0] for i in range(a[0]): if (minimum > b[i]): minimum = b[i] print(minimum) elif (a[1] >= 3): maximum = b[0] for i in range(a[0]): if (maximum < b[i]): maximum = b[i] print(maximum) elif (a[1] == 2 and a[0] == 2): print(max(b[0], b[1])) else: print(max(b[0], b[a[0] - 1])) ``` Yes
100,863
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a1, a2, ..., an consisting of n integers, and an integer k. You have to split the array into exactly k non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the k obtained minimums. What is the maximum possible integer you can get? Definitions of subsegment and array splitting are given in notes. Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 105) β€” the size of the array a and the number of subsegments you have to split the array to. The second line contains n integers a1, a2, ..., an ( - 109 ≀ ai ≀ 109). Output Print single integer β€” the maximum possible integer you can get if you split the array into k non-empty subsegments and take maximum of minimums on the subsegments. Examples Input 5 2 1 2 3 4 5 Output 5 Input 5 1 -4 -5 -3 -2 -1 Output -5 Note A subsegment [l, r] (l ≀ r) of array a is the sequence al, al + 1, ..., ar. Splitting of array a of n elements into k subsegments [l1, r1], [l2, r2], ..., [lk, rk] (l1 = 1, rk = n, li = ri - 1 + 1 for all i > 1) is k sequences (al1, ..., ar1), ..., (alk, ..., ark). In the first example you should split the array into subsegments [1, 4] and [5, 5] that results in sequences (1, 2, 3, 4) and (5). The minimums are min(1, 2, 3, 4) = 1 and min(5) = 5. The resulting maximum is max(1, 5) = 5. It is obvious that you can't reach greater result. In the second example the only option you have is to split the array into one subsegment [1, 5], that results in one sequence ( - 4, - 5, - 3, - 2, - 1). The only minimum is min( - 4, - 5, - 3, - 2, - 1) = - 5. The resulting maximum is - 5. Submitted Solution: ``` s = [int(i) for i in input().split()] a = [int(i) for i in input().split()] n = s[0] k = s[1] if k == 1: print(min(a)) elif k == 2: print(max(a[-1], a[0])) else: print(max(a)) ``` Yes
100,864
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a1, a2, ..., an consisting of n integers, and an integer k. You have to split the array into exactly k non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the k obtained minimums. What is the maximum possible integer you can get? Definitions of subsegment and array splitting are given in notes. Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 105) β€” the size of the array a and the number of subsegments you have to split the array to. The second line contains n integers a1, a2, ..., an ( - 109 ≀ ai ≀ 109). Output Print single integer β€” the maximum possible integer you can get if you split the array into k non-empty subsegments and take maximum of minimums on the subsegments. Examples Input 5 2 1 2 3 4 5 Output 5 Input 5 1 -4 -5 -3 -2 -1 Output -5 Note A subsegment [l, r] (l ≀ r) of array a is the sequence al, al + 1, ..., ar. Splitting of array a of n elements into k subsegments [l1, r1], [l2, r2], ..., [lk, rk] (l1 = 1, rk = n, li = ri - 1 + 1 for all i > 1) is k sequences (al1, ..., ar1), ..., (alk, ..., ark). In the first example you should split the array into subsegments [1, 4] and [5, 5] that results in sequences (1, 2, 3, 4) and (5). The minimums are min(1, 2, 3, 4) = 1 and min(5) = 5. The resulting maximum is max(1, 5) = 5. It is obvious that you can't reach greater result. In the second example the only option you have is to split the array into one subsegment [1, 5], that results in one sequence ( - 4, - 5, - 3, - 2, - 1). The only minimum is min( - 4, - 5, - 3, - 2, - 1) = - 5. The resulting maximum is - 5. Submitted Solution: ``` n,k=list(map(int,input().split())) a=list(map(int,input().split())) m=0 if k==1: print(min(a)) elif k>=3: print(max(a)) else: print(max(a[0],a[-1])) ``` Yes
100,865
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a1, a2, ..., an consisting of n integers, and an integer k. You have to split the array into exactly k non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the k obtained minimums. What is the maximum possible integer you can get? Definitions of subsegment and array splitting are given in notes. Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 105) β€” the size of the array a and the number of subsegments you have to split the array to. The second line contains n integers a1, a2, ..., an ( - 109 ≀ ai ≀ 109). Output Print single integer β€” the maximum possible integer you can get if you split the array into k non-empty subsegments and take maximum of minimums on the subsegments. Examples Input 5 2 1 2 3 4 5 Output 5 Input 5 1 -4 -5 -3 -2 -1 Output -5 Note A subsegment [l, r] (l ≀ r) of array a is the sequence al, al + 1, ..., ar. Splitting of array a of n elements into k subsegments [l1, r1], [l2, r2], ..., [lk, rk] (l1 = 1, rk = n, li = ri - 1 + 1 for all i > 1) is k sequences (al1, ..., ar1), ..., (alk, ..., ark). In the first example you should split the array into subsegments [1, 4] and [5, 5] that results in sequences (1, 2, 3, 4) and (5). The minimums are min(1, 2, 3, 4) = 1 and min(5) = 5. The resulting maximum is max(1, 5) = 5. It is obvious that you can't reach greater result. In the second example the only option you have is to split the array into one subsegment [1, 5], that results in one sequence ( - 4, - 5, - 3, - 2, - 1). The only minimum is min( - 4, - 5, - 3, - 2, - 1) = - 5. The resulting maximum is - 5. Submitted Solution: ``` n, k = map(int, input().split(' ')) inp = input() if k == 2: print(max(int(inp[0]), int(inp[-1]))) else: a = list(map(int, inp.split(' '))) if k == 1: print(min(a)) else: print(max(a)) ``` No
100,866
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a1, a2, ..., an consisting of n integers, and an integer k. You have to split the array into exactly k non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the k obtained minimums. What is the maximum possible integer you can get? Definitions of subsegment and array splitting are given in notes. Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 105) β€” the size of the array a and the number of subsegments you have to split the array to. The second line contains n integers a1, a2, ..., an ( - 109 ≀ ai ≀ 109). Output Print single integer β€” the maximum possible integer you can get if you split the array into k non-empty subsegments and take maximum of minimums on the subsegments. Examples Input 5 2 1 2 3 4 5 Output 5 Input 5 1 -4 -5 -3 -2 -1 Output -5 Note A subsegment [l, r] (l ≀ r) of array a is the sequence al, al + 1, ..., ar. Splitting of array a of n elements into k subsegments [l1, r1], [l2, r2], ..., [lk, rk] (l1 = 1, rk = n, li = ri - 1 + 1 for all i > 1) is k sequences (al1, ..., ar1), ..., (alk, ..., ark). In the first example you should split the array into subsegments [1, 4] and [5, 5] that results in sequences (1, 2, 3, 4) and (5). The minimums are min(1, 2, 3, 4) = 1 and min(5) = 5. The resulting maximum is max(1, 5) = 5. It is obvious that you can't reach greater result. In the second example the only option you have is to split the array into one subsegment [1, 5], that results in one sequence ( - 4, - 5, - 3, - 2, - 1). The only minimum is min( - 4, - 5, - 3, - 2, - 1) = - 5. The resulting maximum is - 5. Submitted Solution: ``` a,b=map(int,input().split(' ')) arr=list(map(int,input().split(' '))) m=arr arr.sort() if b==1: print(arr[0]) elif b==2: print(max(arr[-1],arr[0])) else: print(arr[-1]) ``` No
100,867
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a1, a2, ..., an consisting of n integers, and an integer k. You have to split the array into exactly k non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the k obtained minimums. What is the maximum possible integer you can get? Definitions of subsegment and array splitting are given in notes. Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 105) β€” the size of the array a and the number of subsegments you have to split the array to. The second line contains n integers a1, a2, ..., an ( - 109 ≀ ai ≀ 109). Output Print single integer β€” the maximum possible integer you can get if you split the array into k non-empty subsegments and take maximum of minimums on the subsegments. Examples Input 5 2 1 2 3 4 5 Output 5 Input 5 1 -4 -5 -3 -2 -1 Output -5 Note A subsegment [l, r] (l ≀ r) of array a is the sequence al, al + 1, ..., ar. Splitting of array a of n elements into k subsegments [l1, r1], [l2, r2], ..., [lk, rk] (l1 = 1, rk = n, li = ri - 1 + 1 for all i > 1) is k sequences (al1, ..., ar1), ..., (alk, ..., ark). In the first example you should split the array into subsegments [1, 4] and [5, 5] that results in sequences (1, 2, 3, 4) and (5). The minimums are min(1, 2, 3, 4) = 1 and min(5) = 5. The resulting maximum is max(1, 5) = 5. It is obvious that you can't reach greater result. In the second example the only option you have is to split the array into one subsegment [1, 5], that results in one sequence ( - 4, - 5, - 3, - 2, - 1). The only minimum is min( - 4, - 5, - 3, - 2, - 1) = - 5. The resulting maximum is - 5. Submitted Solution: ``` import sys def greedy_solution(nums, num_set): if num_set > 1: return max(nums) else: return min(nums) def main(): line = sys.stdin.readline().split() num_int, num_set = int(line[0]), int(line[1]) line = sys.stdin.readline().split() nums = [int(s) for s in line] result = greedy_solution(nums, num_set) sys.stdout.write("{}\n".format(result)) if __name__ == '__main__': main() ``` No
100,868
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an array a1, a2, ..., an consisting of n integers, and an integer k. You have to split the array into exactly k non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the k obtained minimums. What is the maximum possible integer you can get? Definitions of subsegment and array splitting are given in notes. Input The first line contains two integers n and k (1 ≀ k ≀ n ≀ 105) β€” the size of the array a and the number of subsegments you have to split the array to. The second line contains n integers a1, a2, ..., an ( - 109 ≀ ai ≀ 109). Output Print single integer β€” the maximum possible integer you can get if you split the array into k non-empty subsegments and take maximum of minimums on the subsegments. Examples Input 5 2 1 2 3 4 5 Output 5 Input 5 1 -4 -5 -3 -2 -1 Output -5 Note A subsegment [l, r] (l ≀ r) of array a is the sequence al, al + 1, ..., ar. Splitting of array a of n elements into k subsegments [l1, r1], [l2, r2], ..., [lk, rk] (l1 = 1, rk = n, li = ri - 1 + 1 for all i > 1) is k sequences (al1, ..., ar1), ..., (alk, ..., ark). In the first example you should split the array into subsegments [1, 4] and [5, 5] that results in sequences (1, 2, 3, 4) and (5). The minimums are min(1, 2, 3, 4) = 1 and min(5) = 5. The resulting maximum is max(1, 5) = 5. It is obvious that you can't reach greater result. In the second example the only option you have is to split the array into one subsegment [1, 5], that results in one sequence ( - 4, - 5, - 3, - 2, - 1). The only minimum is min( - 4, - 5, - 3, - 2, - 1) = - 5. The resulting maximum is - 5. Submitted Solution: ``` import sys; #sys.stdin = open("input.txt", "r"); #sys.stdout = open("output.txt", "w"); def ria(): return [int(x) for x in input().split()]; n, k = (int(x) for x in input().split()); a = ria(); if ( k == 1 ): ans = min(a); if ( k == 2 ): maks = -10000000; for i in range(n): if a[i] > maks: maks = a[i]; pos = i; if ( pos == 0 or pos == n-1 ): ans = maks; else: ans = max(min(a[0:pos]), min(a[pos+1:n])); if ( k > 2 ): ans = max(a); print(ans); #sys.stdout.close(); ``` No
100,869
Provide tags and a correct Python 3 solution for this coding contest problem. Are you going to Scarborough Fair? Parsley, sage, rosemary and thyme. Remember me to one who lives there. He once was the true love of mine. Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there. Willem asks his friend, Grick for directions, Grick helped them, and gave them a task. Although the girl wants to help, Willem insists on doing it by himself. Grick gave Willem a string of length n. Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed. Grick wants to know the final string after all the m operations. Input The first line contains two integers n and m (1 ≀ n, m ≀ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≀ l ≀ r ≀ n, c1, c2 are lowercase English letters), separated by space. Output Output string s after performing m operations described above. Examples Input 3 1 ioi 1 1 i n Output noi Input 5 3 wxhak 3 3 h x 1 5 x a 1 3 w g Output gaaak Note For the second example: After the first operation, the string is wxxak. After the second operation, the string is waaak. After the third operation, the string is gaaak. Tags: implementation Correct Solution: ``` # -*- coding: utf-8 -*- import sys import math import os import itertools import string import heapq import _collections from collections import Counter from collections import defaultdict from functools import lru_cache import bisect import re import queue from decimal import * class Scanner(): @staticmethod def int(): return int(sys.stdin.readline().rstrip()) @staticmethod def string(): return sys.stdin.readline().rstrip() @staticmethod def map_int(): return [int(x) for x in Scanner.string().split()] @staticmethod def string_list(n): return [input() for i in range(n)] @staticmethod def int_list_list(n): return [Scanner.map_int() for i in range(n)] @staticmethod def int_cols_list(n): return [int(input()) for i in range(n)] class Math(): @staticmethod def gcd(a, b): if b == 0: return a return Math.gcd(b, a % b) @staticmethod def lcm(a, b): return (a * b) // Math.gcd(a, b) @staticmethod def divisor(n): res = [] i = 1 for i in range(1, int(n ** 0.5) + 1): if n % i == 0: res.append(i) if i != n // i: res.append(n // i) return res @staticmethod def round_up(a, b): return -(-a // b) @staticmethod def is_prime(n): if n < 2: return False if n == 2: return True if n % 2 == 0: return False d = int(n ** 0.5) + 1 for i in range(3, d + 1, 2): if n % i == 0: return False return True def pop_count(x): x = x - ((x >> 1) & 0x5555555555555555) x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333) x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f x = x + (x >> 8) x = x + (x >> 16) x = x + (x >> 32) return x & 0x0000007f MOD = int(1e09) + 7 INF = int(1e15) def solve(): N, M = Scanner.map_int() S = Scanner.string() for _ in range(M): l, r, c, d = Scanner.string().split() l = int(l) - 1 r = int(r) - 1 T = list(S) for i in range(l, r + 1): if T[i] == c: T[i] = d S = ''.join(T) print(S) def main(): # sys.stdin = open("sample.txt") solve() if __name__ == "__main__": main() ```
100,870
Provide tags and a correct Python 3 solution for this coding contest problem. Are you going to Scarborough Fair? Parsley, sage, rosemary and thyme. Remember me to one who lives there. He once was the true love of mine. Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there. Willem asks his friend, Grick for directions, Grick helped them, and gave them a task. Although the girl wants to help, Willem insists on doing it by himself. Grick gave Willem a string of length n. Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed. Grick wants to know the final string after all the m operations. Input The first line contains two integers n and m (1 ≀ n, m ≀ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≀ l ≀ r ≀ n, c1, c2 are lowercase English letters), separated by space. Output Output string s after performing m operations described above. Examples Input 3 1 ioi 1 1 i n Output noi Input 5 3 wxhak 3 3 h x 1 5 x a 1 3 w g Output gaaak Note For the second example: After the first operation, the string is wxxak. After the second operation, the string is waaak. After the third operation, the string is gaaak. Tags: implementation Correct Solution: ``` import re n,m=list(map(int,input().split())) s=input() for _ in range(m): l,r,a,b=input().strip().split() l,r=int(l),int(r) s=s[:l-1]+re.sub(a,b,s[l-1:r])+s[r:] print(s) ```
100,871
Provide tags and a correct Python 3 solution for this coding contest problem. Are you going to Scarborough Fair? Parsley, sage, rosemary and thyme. Remember me to one who lives there. He once was the true love of mine. Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there. Willem asks his friend, Grick for directions, Grick helped them, and gave them a task. Although the girl wants to help, Willem insists on doing it by himself. Grick gave Willem a string of length n. Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed. Grick wants to know the final string after all the m operations. Input The first line contains two integers n and m (1 ≀ n, m ≀ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≀ l ≀ r ≀ n, c1, c2 are lowercase English letters), separated by space. Output Output string s after performing m operations described above. Examples Input 3 1 ioi 1 1 i n Output noi Input 5 3 wxhak 3 3 h x 1 5 x a 1 3 w g Output gaaak Note For the second example: After the first operation, the string is wxxak. After the second operation, the string is waaak. After the third operation, the string is gaaak. Tags: implementation Correct Solution: ``` n,m=list(map(int,input().split())) z=list(input()) for i in range(m): l,r,c1,c2=input().split() l=int(l) r=int(r) for i in range(l-1,r): if z[i]==c1: z[i]=c2 print("".join(z)) ```
100,872
Provide tags and a correct Python 3 solution for this coding contest problem. Are you going to Scarborough Fair? Parsley, sage, rosemary and thyme. Remember me to one who lives there. He once was the true love of mine. Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there. Willem asks his friend, Grick for directions, Grick helped them, and gave them a task. Although the girl wants to help, Willem insists on doing it by himself. Grick gave Willem a string of length n. Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed. Grick wants to know the final string after all the m operations. Input The first line contains two integers n and m (1 ≀ n, m ≀ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≀ l ≀ r ≀ n, c1, c2 are lowercase English letters), separated by space. Output Output string s after performing m operations described above. Examples Input 3 1 ioi 1 1 i n Output noi Input 5 3 wxhak 3 3 h x 1 5 x a 1 3 w g Output gaaak Note For the second example: After the first operation, the string is wxxak. After the second operation, the string is waaak. After the third operation, the string is gaaak. Tags: implementation Correct Solution: ``` n, m = map(int, input().split()) s = input() for _ in range(m): l, r, c1, c2 = input().split() for i in range(int(l)-1, int(r)): if s[i]==c1: s=s[:i]+c2+s[i+1:] print(s) ```
100,873
Provide tags and a correct Python 3 solution for this coding contest problem. Are you going to Scarborough Fair? Parsley, sage, rosemary and thyme. Remember me to one who lives there. He once was the true love of mine. Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there. Willem asks his friend, Grick for directions, Grick helped them, and gave them a task. Although the girl wants to help, Willem insists on doing it by himself. Grick gave Willem a string of length n. Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed. Grick wants to know the final string after all the m operations. Input The first line contains two integers n and m (1 ≀ n, m ≀ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≀ l ≀ r ≀ n, c1, c2 are lowercase English letters), separated by space. Output Output string s after performing m operations described above. Examples Input 3 1 ioi 1 1 i n Output noi Input 5 3 wxhak 3 3 h x 1 5 x a 1 3 w g Output gaaak Note For the second example: After the first operation, the string is wxxak. After the second operation, the string is waaak. After the third operation, the string is gaaak. Tags: implementation Correct Solution: ``` n,m = map(int,input().split()) k = list(input()) for i in range(m): l = input().split() for j in range(int(l[0])-1,int(l[1])): if k[j]==l[2]: k[j]=l[3] f = ''.join(k) print(f) ```
100,874
Provide tags and a correct Python 3 solution for this coding contest problem. Are you going to Scarborough Fair? Parsley, sage, rosemary and thyme. Remember me to one who lives there. He once was the true love of mine. Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there. Willem asks his friend, Grick for directions, Grick helped them, and gave them a task. Although the girl wants to help, Willem insists on doing it by himself. Grick gave Willem a string of length n. Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed. Grick wants to know the final string after all the m operations. Input The first line contains two integers n and m (1 ≀ n, m ≀ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≀ l ≀ r ≀ n, c1, c2 are lowercase English letters), separated by space. Output Output string s after performing m operations described above. Examples Input 3 1 ioi 1 1 i n Output noi Input 5 3 wxhak 3 3 h x 1 5 x a 1 3 w g Output gaaak Note For the second example: After the first operation, the string is wxxak. After the second operation, the string is waaak. After the third operation, the string is gaaak. Tags: implementation Correct Solution: ``` #Codeforce 897A n,m = (int(v) for v in input().split()) x=[v for v in input().strip("\n\r")] ans="" for i in range(m): l,r,c_1,c_2 = (v for v in input().split()) for j in range(int(l)-1,int(r)): if x[j] == c_1: x[j] = c_2 else: pass for k in range(len(x)): ans+=x[k] print(ans) ```
100,875
Provide tags and a correct Python 3 solution for this coding contest problem. Are you going to Scarborough Fair? Parsley, sage, rosemary and thyme. Remember me to one who lives there. He once was the true love of mine. Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there. Willem asks his friend, Grick for directions, Grick helped them, and gave them a task. Although the girl wants to help, Willem insists on doing it by himself. Grick gave Willem a string of length n. Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed. Grick wants to know the final string after all the m operations. Input The first line contains two integers n and m (1 ≀ n, m ≀ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≀ l ≀ r ≀ n, c1, c2 are lowercase English letters), separated by space. Output Output string s after performing m operations described above. Examples Input 3 1 ioi 1 1 i n Output noi Input 5 3 wxhak 3 3 h x 1 5 x a 1 3 w g Output gaaak Note For the second example: After the first operation, the string is wxxak. After the second operation, the string is waaak. After the third operation, the string is gaaak. Tags: implementation Correct Solution: ``` n, m = map(int, input().split()) string = list(input()) for i in range(m): a, b, x, y = input().split() a = int(a) b = int(b) for j in range(a - 1, b): if string[j] == x: string[j] = y print("".join(string)) ```
100,876
Provide tags and a correct Python 3 solution for this coding contest problem. Are you going to Scarborough Fair? Parsley, sage, rosemary and thyme. Remember me to one who lives there. He once was the true love of mine. Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there. Willem asks his friend, Grick for directions, Grick helped them, and gave them a task. Although the girl wants to help, Willem insists on doing it by himself. Grick gave Willem a string of length n. Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed. Grick wants to know the final string after all the m operations. Input The first line contains two integers n and m (1 ≀ n, m ≀ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≀ l ≀ r ≀ n, c1, c2 are lowercase English letters), separated by space. Output Output string s after performing m operations described above. Examples Input 3 1 ioi 1 1 i n Output noi Input 5 3 wxhak 3 3 h x 1 5 x a 1 3 w g Output gaaak Note For the second example: After the first operation, the string is wxxak. After the second operation, the string is waaak. After the third operation, the string is gaaak. Tags: implementation Correct Solution: ``` import bisect def list_output(s): print(' '.join(map(str, s))) def list_input(s='int'): if s == 'int': return list(map(int, input().split())) elif s == 'float': return list(map(float, input().split())) return list(map(str, input().split())) [n, m] = list(map(int, input().split())) s = list(input()) for _ in range(m): [l, r, c1, c2] = list(input().split()) l = int(l) r = int(r) l -= 1 r -= 1 for i in range(l, r+1): if s[i] == c1: s[i] = c2 print(''.join(map(str, s))) ```
100,877
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Are you going to Scarborough Fair? Parsley, sage, rosemary and thyme. Remember me to one who lives there. He once was the true love of mine. Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there. Willem asks his friend, Grick for directions, Grick helped them, and gave them a task. Although the girl wants to help, Willem insists on doing it by himself. Grick gave Willem a string of length n. Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed. Grick wants to know the final string after all the m operations. Input The first line contains two integers n and m (1 ≀ n, m ≀ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≀ l ≀ r ≀ n, c1, c2 are lowercase English letters), separated by space. Output Output string s after performing m operations described above. Examples Input 3 1 ioi 1 1 i n Output noi Input 5 3 wxhak 3 3 h x 1 5 x a 1 3 w g Output gaaak Note For the second example: After the first operation, the string is wxxak. After the second operation, the string is waaak. After the third operation, the string is gaaak. Submitted Solution: ``` n, m = map(int, input().split()) s = input() for i in range(m): l,r,c1,c2 = map(str,input().split()) l = int(l) r = int(r) l -=1 r -=1 j = l while j <= r: if s[j] == c1: s = s[:j] + c2 + s[j+1:] j += 1 print(s) ``` Yes
100,878
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Are you going to Scarborough Fair? Parsley, sage, rosemary and thyme. Remember me to one who lives there. He once was the true love of mine. Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there. Willem asks his friend, Grick for directions, Grick helped them, and gave them a task. Although the girl wants to help, Willem insists on doing it by himself. Grick gave Willem a string of length n. Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed. Grick wants to know the final string after all the m operations. Input The first line contains two integers n and m (1 ≀ n, m ≀ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≀ l ≀ r ≀ n, c1, c2 are lowercase English letters), separated by space. Output Output string s after performing m operations described above. Examples Input 3 1 ioi 1 1 i n Output noi Input 5 3 wxhak 3 3 h x 1 5 x a 1 3 w g Output gaaak Note For the second example: After the first operation, the string is wxxak. After the second operation, the string is waaak. After the third operation, the string is gaaak. Submitted Solution: ``` n,m=map(int,input().split()) s=list(input()) for i in range(m): x=input() r,c=map(int,x[:-4].split()) for j in range(r-1,c): if s[j]==x[-3]: s[j]=x[-1] print(''.join(s)) ``` Yes
100,879
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Are you going to Scarborough Fair? Parsley, sage, rosemary and thyme. Remember me to one who lives there. He once was the true love of mine. Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there. Willem asks his friend, Grick for directions, Grick helped them, and gave them a task. Although the girl wants to help, Willem insists on doing it by himself. Grick gave Willem a string of length n. Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed. Grick wants to know the final string after all the m operations. Input The first line contains two integers n and m (1 ≀ n, m ≀ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≀ l ≀ r ≀ n, c1, c2 are lowercase English letters), separated by space. Output Output string s after performing m operations described above. Examples Input 3 1 ioi 1 1 i n Output noi Input 5 3 wxhak 3 3 h x 1 5 x a 1 3 w g Output gaaak Note For the second example: After the first operation, the string is wxxak. After the second operation, the string is waaak. After the third operation, the string is gaaak. Submitted Solution: ``` n,m=[int(i) for i in input().split()] s=list(input()) #print(s) for i in range(m): l,r,c1,c2=[i for i in input().split()] l=int(l) r=int(r) for i in range(l-1,r): if s[i]==c1: s[i]=c2 print(''.join(s)) ``` Yes
100,880
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Are you going to Scarborough Fair? Parsley, sage, rosemary and thyme. Remember me to one who lives there. He once was the true love of mine. Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there. Willem asks his friend, Grick for directions, Grick helped them, and gave them a task. Although the girl wants to help, Willem insists on doing it by himself. Grick gave Willem a string of length n. Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed. Grick wants to know the final string after all the m operations. Input The first line contains two integers n and m (1 ≀ n, m ≀ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≀ l ≀ r ≀ n, c1, c2 are lowercase English letters), separated by space. Output Output string s after performing m operations described above. Examples Input 3 1 ioi 1 1 i n Output noi Input 5 3 wxhak 3 3 h x 1 5 x a 1 3 w g Output gaaak Note For the second example: After the first operation, the string is wxxak. After the second operation, the string is waaak. After the third operation, the string is gaaak. Submitted Solution: ``` x,y=[int(i) for i in input().split()] s=input() o=[] for i in range(x): o.append(s[i]) for i in range(y): p=input().split() l=int(p[0]) r=int(p[1]) c1=p[2] c2=p[3] if l!=r: for i in range(l-1,r): if o[i]==c1: o.pop(i) o.insert(i,c2) else: if o[l-1]==c1: o.pop(l-1) o.insert(l-1,c2) print("".join(o)) ``` Yes
100,881
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Are you going to Scarborough Fair? Parsley, sage, rosemary and thyme. Remember me to one who lives there. He once was the true love of mine. Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there. Willem asks his friend, Grick for directions, Grick helped them, and gave them a task. Although the girl wants to help, Willem insists on doing it by himself. Grick gave Willem a string of length n. Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed. Grick wants to know the final string after all the m operations. Input The first line contains two integers n and m (1 ≀ n, m ≀ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≀ l ≀ r ≀ n, c1, c2 are lowercase English letters), separated by space. Output Output string s after performing m operations described above. Examples Input 3 1 ioi 1 1 i n Output noi Input 5 3 wxhak 3 3 h x 1 5 x a 1 3 w g Output gaaak Note For the second example: After the first operation, the string is wxxak. After the second operation, the string is waaak. After the third operation, the string is gaaak. Submitted Solution: ``` class scarBoroughFair: def __init__(self, n, m): self.n = n self.m = m self.directions(self.n, self.m) def directions(self, n, m): str1 = input() str2 = "" list1 = list(str1) if(len(str1) == n): pass else: exit() for x in range(0, m): l, r, c1, c2 = map(str, input().split()) for x in range(0, int(r)): if(c1 == str1[x]): list1[x] = c2 str1 = ''.join(list1) print(str1) n,m = map(int,input().split()) scarBoroughFairObj = scarBoroughFair(n, m) ``` No
100,882
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Are you going to Scarborough Fair? Parsley, sage, rosemary and thyme. Remember me to one who lives there. He once was the true love of mine. Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there. Willem asks his friend, Grick for directions, Grick helped them, and gave them a task. Although the girl wants to help, Willem insists on doing it by himself. Grick gave Willem a string of length n. Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed. Grick wants to know the final string after all the m operations. Input The first line contains two integers n and m (1 ≀ n, m ≀ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≀ l ≀ r ≀ n, c1, c2 are lowercase English letters), separated by space. Output Output string s after performing m operations described above. Examples Input 3 1 ioi 1 1 i n Output noi Input 5 3 wxhak 3 3 h x 1 5 x a 1 3 w g Output gaaak Note For the second example: After the first operation, the string is wxxak. After the second operation, the string is waaak. After the third operation, the string is gaaak. Submitted Solution: ``` a=list(map(int,input().split())) n=a[0] m=a[1] s=input() for t in range(0,m): l,r,c1,c2=input().split() l=int(l) r=int(r) print("s[l-1:r] ",s[l-1:r]) s=s[0:l-1]+s[l-1:r].replace(c1,c2)+s[r:] print(s) ``` No
100,883
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Are you going to Scarborough Fair? Parsley, sage, rosemary and thyme. Remember me to one who lives there. He once was the true love of mine. Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there. Willem asks his friend, Grick for directions, Grick helped them, and gave them a task. Although the girl wants to help, Willem insists on doing it by himself. Grick gave Willem a string of length n. Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed. Grick wants to know the final string after all the m operations. Input The first line contains two integers n and m (1 ≀ n, m ≀ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≀ l ≀ r ≀ n, c1, c2 are lowercase English letters), separated by space. Output Output string s after performing m operations described above. Examples Input 3 1 ioi 1 1 i n Output noi Input 5 3 wxhak 3 3 h x 1 5 x a 1 3 w g Output gaaak Note For the second example: After the first operation, the string is wxxak. After the second operation, the string is waaak. After the third operation, the string is gaaak. Submitted Solution: ``` n,m = map(int,input().split()) k = list(input()) for i in range(m): l = input().split() for j in range(int(l[0])-1,int(l[1])): if k[j]==l[2]: k[j]=l[3] print(*k) ``` No
100,884
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Are you going to Scarborough Fair? Parsley, sage, rosemary and thyme. Remember me to one who lives there. He once was the true love of mine. Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there. Willem asks his friend, Grick for directions, Grick helped them, and gave them a task. Although the girl wants to help, Willem insists on doing it by himself. Grick gave Willem a string of length n. Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed. Grick wants to know the final string after all the m operations. Input The first line contains two integers n and m (1 ≀ n, m ≀ 100). The second line contains a string s of length n, consisting of lowercase English letters. Each of the next m lines contains four parameters l, r, c1, c2 (1 ≀ l ≀ r ≀ n, c1, c2 are lowercase English letters), separated by space. Output Output string s after performing m operations described above. Examples Input 3 1 ioi 1 1 i n Output noi Input 5 3 wxhak 3 3 h x 1 5 x a 1 3 w g Output gaaak Note For the second example: After the first operation, the string is wxxak. After the second operation, the string is waaak. After the third operation, the string is gaaak. Submitted Solution: ``` n,k=list(map(int,input().split())) s=input() p='' for i in range(k): l,r,c1,c2=input().split() for j in range(len(s)): if j in range(int(l)-1,int(r)): if s[j]==c1: p+=c2 else: p+=s[j] print(p) ``` No
100,885
Provide tags and a correct Python 3 solution for this coding contest problem. As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has n servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers. <image> Each ip is of form "a.b.c.d" where a, b, c and d are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has m commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip. Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him. Input The first line of input contains two integers n and m (1 ≀ n, m ≀ 1000). The next n lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1 ≀ |name| ≀ 10, name only consists of English lowercase letters). It is guaranteed that all ip are distinct. The next m lines contain the commands in the configuration file. Each line is of form "command ip;" (1 ≀ |command| ≀ 10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the n school servers. Output Print m lines, the commands in the configuration file after Dustin did his task. Examples Input 2 2 main 192.168.0.2 replica 192.168.0.1 block 192.168.0.1; proxy 192.168.0.2; Output block 192.168.0.1; #replica proxy 192.168.0.2; #main Input 3 5 google 8.8.8.8 codeforces 212.193.33.27 server 138.197.64.57 redirect 138.197.64.57; block 8.8.8.8; cf 212.193.33.27; unblock 8.8.8.8; check 138.197.64.57; Output redirect 138.197.64.57; #server block 8.8.8.8; #google cf 212.193.33.27; #codeforces unblock 8.8.8.8; #google check 138.197.64.57; #server Tags: implementation, strings Correct Solution: ``` m, n = map(int, input().split()) s1 = dict(reversed(input().split()) for _ in range(m)) for _ in range(n): l = input() #c, d = map(str, input().split()) c, d = l.split() print(l + ' #' + s1[d[:-1]]) # for x in s1: # if d[:-1] == s1[x]: # print(l +" #" + x) ```
100,886
Provide tags and a correct Python 3 solution for this coding contest problem. As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has n servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers. <image> Each ip is of form "a.b.c.d" where a, b, c and d are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has m commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip. Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him. Input The first line of input contains two integers n and m (1 ≀ n, m ≀ 1000). The next n lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1 ≀ |name| ≀ 10, name only consists of English lowercase letters). It is guaranteed that all ip are distinct. The next m lines contain the commands in the configuration file. Each line is of form "command ip;" (1 ≀ |command| ≀ 10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the n school servers. Output Print m lines, the commands in the configuration file after Dustin did his task. Examples Input 2 2 main 192.168.0.2 replica 192.168.0.1 block 192.168.0.1; proxy 192.168.0.2; Output block 192.168.0.1; #replica proxy 192.168.0.2; #main Input 3 5 google 8.8.8.8 codeforces 212.193.33.27 server 138.197.64.57 redirect 138.197.64.57; block 8.8.8.8; cf 212.193.33.27; unblock 8.8.8.8; check 138.197.64.57; Output redirect 138.197.64.57; #server block 8.8.8.8; #google cf 212.193.33.27; #codeforces unblock 8.8.8.8; #google check 138.197.64.57; #server Tags: implementation, strings Correct Solution: ``` n,m=map(int,input().split()) d=dict([input().split()[::-1] for i in range(n)]) l=[input().split() for i in range(m)] for i in l: print(i[0],i[1],'#'+d[i[1][:-1]],sep=' ') ```
100,887
Provide tags and a correct Python 3 solution for this coding contest problem. As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has n servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers. <image> Each ip is of form "a.b.c.d" where a, b, c and d are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has m commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip. Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him. Input The first line of input contains two integers n and m (1 ≀ n, m ≀ 1000). The next n lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1 ≀ |name| ≀ 10, name only consists of English lowercase letters). It is guaranteed that all ip are distinct. The next m lines contain the commands in the configuration file. Each line is of form "command ip;" (1 ≀ |command| ≀ 10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the n school servers. Output Print m lines, the commands in the configuration file after Dustin did his task. Examples Input 2 2 main 192.168.0.2 replica 192.168.0.1 block 192.168.0.1; proxy 192.168.0.2; Output block 192.168.0.1; #replica proxy 192.168.0.2; #main Input 3 5 google 8.8.8.8 codeforces 212.193.33.27 server 138.197.64.57 redirect 138.197.64.57; block 8.8.8.8; cf 212.193.33.27; unblock 8.8.8.8; check 138.197.64.57; Output redirect 138.197.64.57; #server block 8.8.8.8; #google cf 212.193.33.27; #codeforces unblock 8.8.8.8; #google check 138.197.64.57; #server Tags: implementation, strings Correct Solution: ``` x,y=map(int,input().split()) n=list() t=list() for i in range(x): n.append(input().split()) for i in range(y): t.append(input().split()) for i in range(y): for j in range(x): l=t[i][1][0:len(t[i][1])-1] if l == n[j][1]:print(t[i][0],t[i][1],"#"+n[j][0]) ```
100,888
Provide tags and a correct Python 3 solution for this coding contest problem. As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has n servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers. <image> Each ip is of form "a.b.c.d" where a, b, c and d are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has m commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip. Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him. Input The first line of input contains two integers n and m (1 ≀ n, m ≀ 1000). The next n lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1 ≀ |name| ≀ 10, name only consists of English lowercase letters). It is guaranteed that all ip are distinct. The next m lines contain the commands in the configuration file. Each line is of form "command ip;" (1 ≀ |command| ≀ 10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the n school servers. Output Print m lines, the commands in the configuration file after Dustin did his task. Examples Input 2 2 main 192.168.0.2 replica 192.168.0.1 block 192.168.0.1; proxy 192.168.0.2; Output block 192.168.0.1; #replica proxy 192.168.0.2; #main Input 3 5 google 8.8.8.8 codeforces 212.193.33.27 server 138.197.64.57 redirect 138.197.64.57; block 8.8.8.8; cf 212.193.33.27; unblock 8.8.8.8; check 138.197.64.57; Output redirect 138.197.64.57; #server block 8.8.8.8; #google cf 212.193.33.27; #codeforces unblock 8.8.8.8; #google check 138.197.64.57; #server Tags: implementation, strings Correct Solution: ``` import sys import math import bisect from sys import stdin, stdout from math import gcd, floor, sqrt, log from collections import defaultdict as dd from bisect import bisect_left as bl, bisect_right as br from collections import Counter #sys.setrecursionlimit(100000000) inp = lambda: int(input()) strng = lambda: input().strip() jn = lambda x, l: x.join(map(str, l)) strl = lambda: list(input().strip()) mul = lambda: map(int, input().strip().split()) mulf = lambda: map(float, input().strip().split()) seq = lambda: list(map(int, input().strip().split())) ceil = lambda x: int(x) if (x == int(x)) else int(x) + 1 ceildiv = lambda x, d: x // d if (x % d == 0) else x // d + 1 flush = lambda: stdout.flush() stdstr = lambda: stdin.readline() stdint = lambda: int(stdin.readline()) stdpr = lambda x: stdout.write(str(x)) stdarr = lambda: map(int, stdstr().split()) mod = 1000000007 n,m = stdarr() names = dict() for i in range(n): s = input().split() names[s[1]] = s[0] command = dict() for _ in range(m): s = input().split() print(s[0] + " " + s[1][:-1] + "; #" + names[s[1][:-1]]) ```
100,889
Provide tags and a correct Python 3 solution for this coding contest problem. As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has n servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers. <image> Each ip is of form "a.b.c.d" where a, b, c and d are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has m commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip. Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him. Input The first line of input contains two integers n and m (1 ≀ n, m ≀ 1000). The next n lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1 ≀ |name| ≀ 10, name only consists of English lowercase letters). It is guaranteed that all ip are distinct. The next m lines contain the commands in the configuration file. Each line is of form "command ip;" (1 ≀ |command| ≀ 10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the n school servers. Output Print m lines, the commands in the configuration file after Dustin did his task. Examples Input 2 2 main 192.168.0.2 replica 192.168.0.1 block 192.168.0.1; proxy 192.168.0.2; Output block 192.168.0.1; #replica proxy 192.168.0.2; #main Input 3 5 google 8.8.8.8 codeforces 212.193.33.27 server 138.197.64.57 redirect 138.197.64.57; block 8.8.8.8; cf 212.193.33.27; unblock 8.8.8.8; check 138.197.64.57; Output redirect 138.197.64.57; #server block 8.8.8.8; #google cf 212.193.33.27; #codeforces unblock 8.8.8.8; #google check 138.197.64.57; #server Tags: implementation, strings Correct Solution: ``` n,m=map(int,input().split()) server=[] cont=[] for i in range(n): s=input() server.append(s.split()) for j in range(m): s=input() cont.append(s.split()) for i in range(m): st=cont[i][1] st=st[:len(st)-1] for j in range(n): if(server[j][1]==st): print(cont[i][0],cont[i][1],'#'+server[j][0]) ```
100,890
Provide tags and a correct Python 3 solution for this coding contest problem. As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has n servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers. <image> Each ip is of form "a.b.c.d" where a, b, c and d are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has m commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip. Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him. Input The first line of input contains two integers n and m (1 ≀ n, m ≀ 1000). The next n lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1 ≀ |name| ≀ 10, name only consists of English lowercase letters). It is guaranteed that all ip are distinct. The next m lines contain the commands in the configuration file. Each line is of form "command ip;" (1 ≀ |command| ≀ 10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the n school servers. Output Print m lines, the commands in the configuration file after Dustin did his task. Examples Input 2 2 main 192.168.0.2 replica 192.168.0.1 block 192.168.0.1; proxy 192.168.0.2; Output block 192.168.0.1; #replica proxy 192.168.0.2; #main Input 3 5 google 8.8.8.8 codeforces 212.193.33.27 server 138.197.64.57 redirect 138.197.64.57; block 8.8.8.8; cf 212.193.33.27; unblock 8.8.8.8; check 138.197.64.57; Output redirect 138.197.64.57; #server block 8.8.8.8; #google cf 212.193.33.27; #codeforces unblock 8.8.8.8; #google check 138.197.64.57; #server Tags: implementation, strings Correct Solution: ``` lst=list(map(int, input().split())) m=lst[0] n=lst[1] table=list() for i in range(0,m): lst=list(map(str,input().split())) table.append(lst) for i in range(0,n): lstt=list(map(str,input().split())) for j in range(0,m): if lstt[1]==table[j][1]+';': print(lstt[0]+' '+lstt[1],end=' #') print(table[j][0]) break ```
100,891
Provide tags and a correct Python 3 solution for this coding contest problem. As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has n servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers. <image> Each ip is of form "a.b.c.d" where a, b, c and d are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has m commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip. Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him. Input The first line of input contains two integers n and m (1 ≀ n, m ≀ 1000). The next n lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1 ≀ |name| ≀ 10, name only consists of English lowercase letters). It is guaranteed that all ip are distinct. The next m lines contain the commands in the configuration file. Each line is of form "command ip;" (1 ≀ |command| ≀ 10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the n school servers. Output Print m lines, the commands in the configuration file after Dustin did his task. Examples Input 2 2 main 192.168.0.2 replica 192.168.0.1 block 192.168.0.1; proxy 192.168.0.2; Output block 192.168.0.1; #replica proxy 192.168.0.2; #main Input 3 5 google 8.8.8.8 codeforces 212.193.33.27 server 138.197.64.57 redirect 138.197.64.57; block 8.8.8.8; cf 212.193.33.27; unblock 8.8.8.8; check 138.197.64.57; Output redirect 138.197.64.57; #server block 8.8.8.8; #google cf 212.193.33.27; #codeforces unblock 8.8.8.8; #google check 138.197.64.57; #server Tags: implementation, strings Correct Solution: ``` #!/usr/bin/python3 import sys inf = [int(x) for x in sys.stdin.readline().split(" ")] ser = {} for i in range(inf[0]): new = sys.stdin.readline().split(" ") ser[new[1].strip()+";"] = new[0].strip() for i in range(inf[1]): new = sys.stdin.readline() print(new.strip() + " #"+ser[new.split(" ")[1].strip()]) sys.exit() ```
100,892
Provide tags and a correct Python 3 solution for this coding contest problem. As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has n servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers. <image> Each ip is of form "a.b.c.d" where a, b, c and d are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has m commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip. Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him. Input The first line of input contains two integers n and m (1 ≀ n, m ≀ 1000). The next n lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1 ≀ |name| ≀ 10, name only consists of English lowercase letters). It is guaranteed that all ip are distinct. The next m lines contain the commands in the configuration file. Each line is of form "command ip;" (1 ≀ |command| ≀ 10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the n school servers. Output Print m lines, the commands in the configuration file after Dustin did his task. Examples Input 2 2 main 192.168.0.2 replica 192.168.0.1 block 192.168.0.1; proxy 192.168.0.2; Output block 192.168.0.1; #replica proxy 192.168.0.2; #main Input 3 5 google 8.8.8.8 codeforces 212.193.33.27 server 138.197.64.57 redirect 138.197.64.57; block 8.8.8.8; cf 212.193.33.27; unblock 8.8.8.8; check 138.197.64.57; Output redirect 138.197.64.57; #server block 8.8.8.8; #google cf 212.193.33.27; #codeforces unblock 8.8.8.8; #google check 138.197.64.57; #server Tags: implementation, strings Correct Solution: ``` from collections import defaultdict final = defaultdict(list) n, m = map(int, input().split()) d, name, ip = [], [], [] # d = dict(input().split() for _ in range(n)) for _ in range(n): name = [] i = input().split() name.append(i[1]) name.append(i[0]) d.append(tuple(name)) # print(*d) for k, v in d: final[k].append(v) # print(final) test = [] for i in range(m): test = input().split() ans = test[1].strip(';') print(*test,'#',end='') # print(ans) # print(*test+'#'+*final[ans]) print(*final[ans]) ```
100,893
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has n servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers. <image> Each ip is of form "a.b.c.d" where a, b, c and d are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has m commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip. Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him. Input The first line of input contains two integers n and m (1 ≀ n, m ≀ 1000). The next n lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1 ≀ |name| ≀ 10, name only consists of English lowercase letters). It is guaranteed that all ip are distinct. The next m lines contain the commands in the configuration file. Each line is of form "command ip;" (1 ≀ |command| ≀ 10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the n school servers. Output Print m lines, the commands in the configuration file after Dustin did his task. Examples Input 2 2 main 192.168.0.2 replica 192.168.0.1 block 192.168.0.1; proxy 192.168.0.2; Output block 192.168.0.1; #replica proxy 192.168.0.2; #main Input 3 5 google 8.8.8.8 codeforces 212.193.33.27 server 138.197.64.57 redirect 138.197.64.57; block 8.8.8.8; cf 212.193.33.27; unblock 8.8.8.8; check 138.197.64.57; Output redirect 138.197.64.57; #server block 8.8.8.8; #google cf 212.193.33.27; #codeforces unblock 8.8.8.8; #google check 138.197.64.57; #server Submitted Solution: ``` n,m=[int(x) for x in input().split()] arr=[] for _ in range(n): name,ip=input().split() arr.append((name,ip)) for _ in range(m): name,ip=input().split() ip1=ip[:-1] for i,j in arr: if ip1==j: print(name,ip,'#'+i) ``` Yes
100,894
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has n servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers. <image> Each ip is of form "a.b.c.d" where a, b, c and d are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has m commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip. Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him. Input The first line of input contains two integers n and m (1 ≀ n, m ≀ 1000). The next n lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1 ≀ |name| ≀ 10, name only consists of English lowercase letters). It is guaranteed that all ip are distinct. The next m lines contain the commands in the configuration file. Each line is of form "command ip;" (1 ≀ |command| ≀ 10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the n school servers. Output Print m lines, the commands in the configuration file after Dustin did his task. Examples Input 2 2 main 192.168.0.2 replica 192.168.0.1 block 192.168.0.1; proxy 192.168.0.2; Output block 192.168.0.1; #replica proxy 192.168.0.2; #main Input 3 5 google 8.8.8.8 codeforces 212.193.33.27 server 138.197.64.57 redirect 138.197.64.57; block 8.8.8.8; cf 212.193.33.27; unblock 8.8.8.8; check 138.197.64.57; Output redirect 138.197.64.57; #server block 8.8.8.8; #google cf 212.193.33.27; #codeforces unblock 8.8.8.8; #google check 138.197.64.57; #server Submitted Solution: ``` n, m = input().split() n = int(n) m = int(m) arrayStringName = [] arrayStringIp = [] for _ in range(n): name, ip = input().split() name = str(name) ip = str(ip) arrayStringName.append(name) arrayStringIp.append(ip) for i in range(m): ip = "" commandIp = str(input()) for j in range(len(commandIp)): if commandIp[j].isnumeric() == True or commandIp[j] == ".": ip += commandIp[j] getIndexInArray = arrayStringIp.index(ip) print(commandIp + " #" + arrayStringName[getIndexInArray]) ``` Yes
100,895
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has n servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers. <image> Each ip is of form "a.b.c.d" where a, b, c and d are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has m commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip. Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him. Input The first line of input contains two integers n and m (1 ≀ n, m ≀ 1000). The next n lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1 ≀ |name| ≀ 10, name only consists of English lowercase letters). It is guaranteed that all ip are distinct. The next m lines contain the commands in the configuration file. Each line is of form "command ip;" (1 ≀ |command| ≀ 10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the n school servers. Output Print m lines, the commands in the configuration file after Dustin did his task. Examples Input 2 2 main 192.168.0.2 replica 192.168.0.1 block 192.168.0.1; proxy 192.168.0.2; Output block 192.168.0.1; #replica proxy 192.168.0.2; #main Input 3 5 google 8.8.8.8 codeforces 212.193.33.27 server 138.197.64.57 redirect 138.197.64.57; block 8.8.8.8; cf 212.193.33.27; unblock 8.8.8.8; check 138.197.64.57; Output redirect 138.197.64.57; #server block 8.8.8.8; #google cf 212.193.33.27; #codeforces unblock 8.8.8.8; #google check 138.197.64.57; #server Submitted Solution: ``` def find(s,ip): for i in range(len(ip)): if ip[i]==s: return i return -1 n,m=map(int,input().split()) ip,ip_dict=[],[] for i in range(n): s1=input().split() ip.append(s1[1]) ip_dict.append(s1[0]) for i in range(m): s1=input() s2=s1.split()[1] m=find(s2[:len(s2)-1],ip) print(s1,end='') print(" #",end='') print(ip_dict[m]) ``` Yes
100,896
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has n servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers. <image> Each ip is of form "a.b.c.d" where a, b, c and d are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has m commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip. Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him. Input The first line of input contains two integers n and m (1 ≀ n, m ≀ 1000). The next n lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1 ≀ |name| ≀ 10, name only consists of English lowercase letters). It is guaranteed that all ip are distinct. The next m lines contain the commands in the configuration file. Each line is of form "command ip;" (1 ≀ |command| ≀ 10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the n school servers. Output Print m lines, the commands in the configuration file after Dustin did his task. Examples Input 2 2 main 192.168.0.2 replica 192.168.0.1 block 192.168.0.1; proxy 192.168.0.2; Output block 192.168.0.1; #replica proxy 192.168.0.2; #main Input 3 5 google 8.8.8.8 codeforces 212.193.33.27 server 138.197.64.57 redirect 138.197.64.57; block 8.8.8.8; cf 212.193.33.27; unblock 8.8.8.8; check 138.197.64.57; Output redirect 138.197.64.57; #server block 8.8.8.8; #google cf 212.193.33.27; #codeforces unblock 8.8.8.8; #google check 138.197.64.57; #server Submitted Solution: ``` n, m = list(map(int, input().strip().split())) host = dict() guest = dict() for i in range(n): name, ip = input().strip().split() host[ip] = name for i in range(m): name, ip = input().strip().split() newline = "#" + host[ip[:-1]] print(name, ip, newline) ``` Yes
100,897
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has n servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers. <image> Each ip is of form "a.b.c.d" where a, b, c and d are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has m commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip. Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him. Input The first line of input contains two integers n and m (1 ≀ n, m ≀ 1000). The next n lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1 ≀ |name| ≀ 10, name only consists of English lowercase letters). It is guaranteed that all ip are distinct. The next m lines contain the commands in the configuration file. Each line is of form "command ip;" (1 ≀ |command| ≀ 10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the n school servers. Output Print m lines, the commands in the configuration file after Dustin did his task. Examples Input 2 2 main 192.168.0.2 replica 192.168.0.1 block 192.168.0.1; proxy 192.168.0.2; Output block 192.168.0.1; #replica proxy 192.168.0.2; #main Input 3 5 google 8.8.8.8 codeforces 212.193.33.27 server 138.197.64.57 redirect 138.197.64.57; block 8.8.8.8; cf 212.193.33.27; unblock 8.8.8.8; check 138.197.64.57; Output redirect 138.197.64.57; #server block 8.8.8.8; #google cf 212.193.33.27; #codeforces unblock 8.8.8.8; #google check 138.197.64.57; #server Submitted Solution: ``` a = [] a = list(map(int, input().split())) n = a[0] m = a[1] mymap = {} commands = [] for i in range(0, n): vin = list(input().split()) mymap[(vin[1])] = vin[0] for i in range(0, m): command = input().strip(';') commands.append(command) for i in range(0, m): command = commands[i]; ip = list(command.split())[1] output = (commands[i]) + ' #' + (mymap[ip]) print(output) ``` No
100,898
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has n servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of each server. For simplicity, we'll assume that an nginx command is of form "command ip;" where command is a string consisting of English lowercase letter only, and ip is the ip of one of school servers. <image> Each ip is of form "a.b.c.d" where a, b, c and d are non-negative integers less than or equal to 255 (with no leading zeros). The nginx configuration file Dustin has to add comments to has m commands. Nobody ever memorizes the ips of servers, so to understand the configuration better, Dustin has to comment the name of server that the ip belongs to at the end of each line (after each command). More formally, if a line is "command ip;" Dustin has to replace it with "command ip; #name" where name is the name of the server with ip equal to ip. Dustin doesn't know anything about nginx, so he panicked again and his friends asked you to do his task for him. Input The first line of input contains two integers n and m (1 ≀ n, m ≀ 1000). The next n lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1 ≀ |name| ≀ 10, name only consists of English lowercase letters). It is guaranteed that all ip are distinct. The next m lines contain the commands in the configuration file. Each line is of form "command ip;" (1 ≀ |command| ≀ 10, command only consists of English lowercase letters). It is guaranteed that ip belongs to one of the n school servers. Output Print m lines, the commands in the configuration file after Dustin did his task. Examples Input 2 2 main 192.168.0.2 replica 192.168.0.1 block 192.168.0.1; proxy 192.168.0.2; Output block 192.168.0.1; #replica proxy 192.168.0.2; #main Input 3 5 google 8.8.8.8 codeforces 212.193.33.27 server 138.197.64.57 redirect 138.197.64.57; block 8.8.8.8; cf 212.193.33.27; unblock 8.8.8.8; check 138.197.64.57; Output redirect 138.197.64.57; #server block 8.8.8.8; #google cf 212.193.33.27; #codeforces unblock 8.8.8.8; #google check 138.197.64.57; #server Submitted Solution: ``` def get_keys_with_value(dic, value): return [key for key, val in dic.items() if val == value] n,m=map(int,input().split()) server={} for i in range(n): n_=list(map(str,input().split())) server[n_[0]]=n_[1] #print(server) for i in range (m): m_=list(map(str,input().split())) m_[1] = m_[1].replace(";", "") for j in server.values(): if j == m_[1]: res=get_keys_with_value(server, j) res= "".join(map(str,res)) print(f"{m_[0]} {m_[1]}; #{res}") ``` No
100,899