message
stringlengths
2
65.1k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
0
108k
cluster
float64
14
14
__index_level_0__
int64
0
217k
Provide tags and a correct Python 3 solution for this coding contest problem. Easy and hard versions are actually different problems, so read statements of both problems completely and carefully. Summer vacation has started so Alice and Bob want to play and joy, but... Their mom doesn't think so. She says that they have to read some amount of books before all entertainments. Alice and Bob will read each book together to end this exercise faster. There are n books in the family library. The i-th book is described by three integers: t_i β€” the amount of time Alice and Bob need to spend to read it, a_i (equals 1 if Alice likes the i-th book and 0 if not), and b_i (equals 1 if Bob likes the i-th book and 0 if not). So they need to choose some books from the given n books in such a way that: * Alice likes at least k books from the chosen set and Bob likes at least k books from the chosen set; * the total reading time of these books is minimized (they are children and want to play and joy as soon a possible). The set they choose is the same for both Alice an Bob (it's shared between them) and they read all books together, so the total reading time is the sum of t_i over all books that are in the chosen set. Your task is to help them and find any suitable set of books or determine that it is impossible to find such a set. Input The first line of the input contains two integers n and k (1 ≀ k ≀ n ≀ 2 β‹… 10^5). The next n lines contain descriptions of books, one description per line: the i-th line contains three integers t_i, a_i and b_i (1 ≀ t_i ≀ 10^4, 0 ≀ a_i, b_i ≀ 1), where: * t_i β€” the amount of time required for reading the i-th book; * a_i equals 1 if Alice likes the i-th book and 0 otherwise; * b_i equals 1 if Bob likes the i-th book and 0 otherwise. Output If there is no solution, print only one integer -1. Otherwise print one integer T β€” the minimum total reading time of the suitable set of books. Examples Input 8 4 7 1 1 2 1 1 4 0 1 8 1 1 1 0 1 1 1 1 1 0 1 3 0 0 Output 18 Input 5 2 6 0 0 9 0 0 1 0 1 2 1 1 5 1 0 Output 8 Input 5 3 3 0 0 2 1 0 3 1 0 5 0 1 3 0 1 Output -1
instruction
0
85,855
14
171,710
Tags: data structures, greedy, sortings Correct Solution: ``` n,k = map(int,input().split()) a = [] b = [] c = [] for i in range(n): x,y,z = map(int,input().split()) if y == 1 and z != 1: a.append(x) elif y != 1 and z == 1: b.append(x) elif y == 1 and z == 1: c.append(x) else: pass if len(a)+len(c)<k or len(c)+len(b)<k: ans = -1 else: a.sort() b.sort() c.sort() pt1,pt2,pt3 = 0,0,0 move1 = 0 move2 = 0 ans = 0 while True: if len(c) == 0: for i in range(k): ans += a[i] for i in range(k): ans += b[i] break else: if move1 == k and move2 == k: break elif move1<k and move2 == k: if pt1<len(a) and pt3<len(c): if a[pt1]<c[pt3]: ans += a[pt1] pt1 += 1 else: ans += c[pt3] pt3 += 1 elif not(pt1<len(a)) and pt3<len(c): ans += c[pt3] pt3 += 1 else: ans += a[pt1] pt1 += 1 move1 += 1 elif move1 == k and move2<k: if pt2<len(b) and pt3<len(c): if b[pt2]<c[pt3]: ans += b[pt2] pt2 += 1 else: ans += c[pt3] pt3 += 1 elif not(pt2<len(b)) and pt3<len(c): ans += c[pt3] pt3 += 1 else: ans += b[pt2] pt2 += 1 move2 += 1 else: if pt1<len(a) and pt2<len(b) and pt3<len(c): if a[pt1]+b[pt2]<c[pt3]: ans += a[pt1] move1 += 1 ans += b[pt2] move2 += 1 pt1 += 1 pt2 += 1 else: ans += c[pt3] move1 += 1 move2 += 1 pt3 += 1 else: if pt3<len(c): ans += c[pt3] pt3 += 1 move1 += 1 move2 += 1 else: if pt1<len(a): ans += a[pt1] pt1 += 1 move1 += 1 if pt2<len(b): ans += b[pt2] pt2 += 1 move2 += 1 print(ans) ```
output
1
85,855
14
171,711
Provide tags and a correct Python 3 solution for this coding contest problem. Easy and hard versions are actually different problems, so read statements of both problems completely and carefully. Summer vacation has started so Alice and Bob want to play and joy, but... Their mom doesn't think so. She says that they have to read some amount of books before all entertainments. Alice and Bob will read each book together to end this exercise faster. There are n books in the family library. The i-th book is described by three integers: t_i β€” the amount of time Alice and Bob need to spend to read it, a_i (equals 1 if Alice likes the i-th book and 0 if not), and b_i (equals 1 if Bob likes the i-th book and 0 if not). So they need to choose some books from the given n books in such a way that: * Alice likes at least k books from the chosen set and Bob likes at least k books from the chosen set; * the total reading time of these books is minimized (they are children and want to play and joy as soon a possible). The set they choose is the same for both Alice an Bob (it's shared between them) and they read all books together, so the total reading time is the sum of t_i over all books that are in the chosen set. Your task is to help them and find any suitable set of books or determine that it is impossible to find such a set. Input The first line of the input contains two integers n and k (1 ≀ k ≀ n ≀ 2 β‹… 10^5). The next n lines contain descriptions of books, one description per line: the i-th line contains three integers t_i, a_i and b_i (1 ≀ t_i ≀ 10^4, 0 ≀ a_i, b_i ≀ 1), where: * t_i β€” the amount of time required for reading the i-th book; * a_i equals 1 if Alice likes the i-th book and 0 otherwise; * b_i equals 1 if Bob likes the i-th book and 0 otherwise. Output If there is no solution, print only one integer -1. Otherwise print one integer T β€” the minimum total reading time of the suitable set of books. Examples Input 8 4 7 1 1 2 1 1 4 0 1 8 1 1 1 0 1 1 1 1 1 0 1 3 0 0 Output 18 Input 5 2 6 0 0 9 0 0 1 0 1 2 1 1 5 1 0 Output 8 Input 5 3 3 0 0 2 1 0 3 1 0 5 0 1 3 0 1 Output -1
instruction
0
85,856
14
171,712
Tags: data structures, greedy, sortings Correct Solution: ``` n,k=map(int, input().split()) tab=[tuple(map(int,input().split())) for _ in range(n)] both=[tabi[0] for tabi in tab if tabi[1:]==(1,1)] both.sort() alice=[tabi[0] for tabi in tab if tabi[1:]==(1,0)]# tabi[1]==1 and tabi[2]==0] bob=[tabi[0] for tabi in tab if tabi[1:]==(0,1)] alice.sort() bob.sort() ab=[alice[i]+bob[i] for i in range(min(len(alice),len(bob)))] both+=ab both.sort() if len(both)<k: print(-1) else:print(sum(both[:k])) ```
output
1
85,856
14
171,713
Provide tags and a correct Python 3 solution for this coding contest problem. Easy and hard versions are actually different problems, so read statements of both problems completely and carefully. Summer vacation has started so Alice and Bob want to play and joy, but... Their mom doesn't think so. She says that they have to read some amount of books before all entertainments. Alice and Bob will read each book together to end this exercise faster. There are n books in the family library. The i-th book is described by three integers: t_i β€” the amount of time Alice and Bob need to spend to read it, a_i (equals 1 if Alice likes the i-th book and 0 if not), and b_i (equals 1 if Bob likes the i-th book and 0 if not). So they need to choose some books from the given n books in such a way that: * Alice likes at least k books from the chosen set and Bob likes at least k books from the chosen set; * the total reading time of these books is minimized (they are children and want to play and joy as soon a possible). The set they choose is the same for both Alice an Bob (it's shared between them) and they read all books together, so the total reading time is the sum of t_i over all books that are in the chosen set. Your task is to help them and find any suitable set of books or determine that it is impossible to find such a set. Input The first line of the input contains two integers n and k (1 ≀ k ≀ n ≀ 2 β‹… 10^5). The next n lines contain descriptions of books, one description per line: the i-th line contains three integers t_i, a_i and b_i (1 ≀ t_i ≀ 10^4, 0 ≀ a_i, b_i ≀ 1), where: * t_i β€” the amount of time required for reading the i-th book; * a_i equals 1 if Alice likes the i-th book and 0 otherwise; * b_i equals 1 if Bob likes the i-th book and 0 otherwise. Output If there is no solution, print only one integer -1. Otherwise print one integer T β€” the minimum total reading time of the suitable set of books. Examples Input 8 4 7 1 1 2 1 1 4 0 1 8 1 1 1 0 1 1 1 1 1 0 1 3 0 0 Output 18 Input 5 2 6 0 0 9 0 0 1 0 1 2 1 1 5 1 0 Output 8 Input 5 3 3 0 0 2 1 0 3 1 0 5 0 1 3 0 1 Output -1
instruction
0
85,857
14
171,714
Tags: data structures, greedy, sortings Correct Solution: ``` def cumsum(x): n = len(x) ans = [0]*(n+1) for i in range(n): ans[i+1]=ans[i]+x[i] return ans def solve(k, t, a, b): n = len(t) b10, b01, b11=[],[],[] for i in range(n): if (a[i]==1 and b[i]==1): b11.append(t[i]) elif a[i]==1: b10.append(t[i]) elif b[i]==1: b01.append(t[i]) b10=sorted(b10) b01=sorted(b01) b11=sorted(b11) b1 = [b10[i] + b01[i] for i in range(min(len(b10), len(b01)))] cs_b1 = cumsum(b1) cs_b11 = cumsum(b11) if len(b1) + len(b11) < k: return -1 ans=1e100 for i in range(0, k+1): if i<=len(b1) and k-i<=len(b11): ans = min(ans, cs_b1[i] + cs_b11[k-i]) return ans n, k = map(int, input().split()) a,b,t = [0]*n,[0]*n,[0]*n for i in range(n): t[i], a[i], b[i] = map(int, input().split()) print(solve(k, t,a,b)) ```
output
1
85,857
14
171,715
Provide tags and a correct Python 3 solution for this coding contest problem. Easy and hard versions are actually different problems, so read statements of both problems completely and carefully. Summer vacation has started so Alice and Bob want to play and joy, but... Their mom doesn't think so. She says that they have to read some amount of books before all entertainments. Alice and Bob will read each book together to end this exercise faster. There are n books in the family library. The i-th book is described by three integers: t_i β€” the amount of time Alice and Bob need to spend to read it, a_i (equals 1 if Alice likes the i-th book and 0 if not), and b_i (equals 1 if Bob likes the i-th book and 0 if not). So they need to choose some books from the given n books in such a way that: * Alice likes at least k books from the chosen set and Bob likes at least k books from the chosen set; * the total reading time of these books is minimized (they are children and want to play and joy as soon a possible). The set they choose is the same for both Alice an Bob (it's shared between them) and they read all books together, so the total reading time is the sum of t_i over all books that are in the chosen set. Your task is to help them and find any suitable set of books or determine that it is impossible to find such a set. Input The first line of the input contains two integers n and k (1 ≀ k ≀ n ≀ 2 β‹… 10^5). The next n lines contain descriptions of books, one description per line: the i-th line contains three integers t_i, a_i and b_i (1 ≀ t_i ≀ 10^4, 0 ≀ a_i, b_i ≀ 1), where: * t_i β€” the amount of time required for reading the i-th book; * a_i equals 1 if Alice likes the i-th book and 0 otherwise; * b_i equals 1 if Bob likes the i-th book and 0 otherwise. Output If there is no solution, print only one integer -1. Otherwise print one integer T β€” the minimum total reading time of the suitable set of books. Examples Input 8 4 7 1 1 2 1 1 4 0 1 8 1 1 1 0 1 1 1 1 1 0 1 3 0 0 Output 18 Input 5 2 6 0 0 9 0 0 1 0 1 2 1 1 5 1 0 Output 8 Input 5 3 3 0 0 2 1 0 3 1 0 5 0 1 3 0 1 Output -1
instruction
0
85,858
14
171,716
Tags: data structures, greedy, sortings Correct Solution: ``` t,k = map(int,input().split()) A = [] B = [] C = [] for i in range(t): a,b,c = map(int,input().split()) if b == 1 and c == 0: A.append(a) elif b == 0 and c == 1: B.append(a) elif b == 1: C.append(a) if min(len(A),len(B)) + len(C) < k: print(-1) else: A.sort() B.sort() s = 0 for i in range(min(len(A),len(B))): C.append(A[i] + B[i]) C.sort() for i in range(k): s += C[i] print(s) ```
output
1
85,858
14
171,717
Provide tags and a correct Python 3 solution for this coding contest problem. Easy and hard versions are actually different problems, so read statements of both problems completely and carefully. Summer vacation has started so Alice and Bob want to play and joy, but... Their mom doesn't think so. She says that they have to read some amount of books before all entertainments. Alice and Bob will read each book together to end this exercise faster. There are n books in the family library. The i-th book is described by three integers: t_i β€” the amount of time Alice and Bob need to spend to read it, a_i (equals 1 if Alice likes the i-th book and 0 if not), and b_i (equals 1 if Bob likes the i-th book and 0 if not). So they need to choose some books from the given n books in such a way that: * Alice likes at least k books from the chosen set and Bob likes at least k books from the chosen set; * the total reading time of these books is minimized (they are children and want to play and joy as soon a possible). The set they choose is the same for both Alice an Bob (it's shared between them) and they read all books together, so the total reading time is the sum of t_i over all books that are in the chosen set. Your task is to help them and find any suitable set of books or determine that it is impossible to find such a set. Input The first line of the input contains two integers n and k (1 ≀ k ≀ n ≀ 2 β‹… 10^5). The next n lines contain descriptions of books, one description per line: the i-th line contains three integers t_i, a_i and b_i (1 ≀ t_i ≀ 10^4, 0 ≀ a_i, b_i ≀ 1), where: * t_i β€” the amount of time required for reading the i-th book; * a_i equals 1 if Alice likes the i-th book and 0 otherwise; * b_i equals 1 if Bob likes the i-th book and 0 otherwise. Output If there is no solution, print only one integer -1. Otherwise print one integer T β€” the minimum total reading time of the suitable set of books. Examples Input 8 4 7 1 1 2 1 1 4 0 1 8 1 1 1 0 1 1 1 1 1 0 1 3 0 0 Output 18 Input 5 2 6 0 0 9 0 0 1 0 1 2 1 1 5 1 0 Output 8 Input 5 3 3 0 0 2 1 0 3 1 0 5 0 1 3 0 1 Output -1
instruction
0
85,859
14
171,718
Tags: data structures, greedy, sortings Correct Solution: ``` #import math #from functools import lru_cache #import heapq #from collections import defaultdict #from collections import Counter #from collections import deque #from sys import stdout #from sys import setrecursionlimit #setrecursionlimit(10**7) from sys import stdin input = stdin.readline INF = 10**9 + 7 MAX = 10**7 + 7 MOD = 10**9 + 7 n, k = [int(x) for x in input().strip().split()] c, a, b = [], [], [] for ni in range(n): ti, ai, bi = [int(x) for x in input().strip().split()] if(ai ==1 and bi == 1): c.append(ti) elif(ai == 1): a.append(ti) elif(bi == 1): b.append(ti) c.sort(reverse = True) a.sort(reverse = True) b.sort(reverse = True) alen = len(a) blen = len(b) clen = len(c) m = max(0, k - min(alen, blen)) ans = 0 #print(clen, m) if(m>clen): print('-1') else: for mi in range(m): ans += c.pop() ka = k - m kb = k - m while(ka or kb): ca = (c[-1] if c else float('inf')) da = 0 ap, bp = 0, 0 if(ka): da += (a[-1] if a else float('inf')) ap = 1 if(kb): da += (b[-1] if b else float('inf')) bp = 1 if(da<ca): if(ap): ka -= 1 ans += (a.pop() if a else float('inf')) if(bp): kb -= 1 ans += (b.pop() if b else float('inf')) else: ans += (c.pop() if c else float('inf')) if(ap): ka -= 1 if(bp): kb -= 1 print(ans if ans!=float('inf') else '-1') ```
output
1
85,859
14
171,719
Provide tags and a correct Python 3 solution for this coding contest problem. Easy and hard versions are actually different problems, so read statements of both problems completely and carefully. Summer vacation has started so Alice and Bob want to play and joy, but... Their mom doesn't think so. She says that they have to read some amount of books before all entertainments. Alice and Bob will read each book together to end this exercise faster. There are n books in the family library. The i-th book is described by three integers: t_i β€” the amount of time Alice and Bob need to spend to read it, a_i (equals 1 if Alice likes the i-th book and 0 if not), and b_i (equals 1 if Bob likes the i-th book and 0 if not). So they need to choose some books from the given n books in such a way that: * Alice likes at least k books from the chosen set and Bob likes at least k books from the chosen set; * the total reading time of these books is minimized (they are children and want to play and joy as soon a possible). The set they choose is the same for both Alice an Bob (it's shared between them) and they read all books together, so the total reading time is the sum of t_i over all books that are in the chosen set. Your task is to help them and find any suitable set of books or determine that it is impossible to find such a set. Input The first line of the input contains two integers n and k (1 ≀ k ≀ n ≀ 2 β‹… 10^5). The next n lines contain descriptions of books, one description per line: the i-th line contains three integers t_i, a_i and b_i (1 ≀ t_i ≀ 10^4, 0 ≀ a_i, b_i ≀ 1), where: * t_i β€” the amount of time required for reading the i-th book; * a_i equals 1 if Alice likes the i-th book and 0 otherwise; * b_i equals 1 if Bob likes the i-th book and 0 otherwise. Output If there is no solution, print only one integer -1. Otherwise print one integer T β€” the minimum total reading time of the suitable set of books. Examples Input 8 4 7 1 1 2 1 1 4 0 1 8 1 1 1 0 1 1 1 1 1 0 1 3 0 0 Output 18 Input 5 2 6 0 0 9 0 0 1 0 1 2 1 1 5 1 0 Output 8 Input 5 3 3 0 0 2 1 0 3 1 0 5 0 1 3 0 1 Output -1
instruction
0
85,860
14
171,720
Tags: data structures, greedy, sortings Correct Solution: ``` # stdin = open("testdata.txt") # def input(): # return stdin.readline().strip() def addition(lst,k): lst_alice = [] lst_bob = [] lst_both = [] addition_lst = [] lst.sort() for i in range(len(lst)): if lst[i][1] == 1 and lst[i][2] == 0: lst_alice.append(lst[i]) elif lst[i][1] == 0 and lst[i][2] == 1: lst_bob.append(lst[i]) elif lst[i][1] == 1 and lst[i][2] == 1: lst_both.append(lst[i]) n = min(len(lst_alice),len(lst_bob)) addition_lst = [ [lst_alice[i][j]+lst_bob[i][j] for j in range(3)] for i in range(n)] lst_both.extend(addition_lst) lst_both.sort() if len(lst_both) < k: return -1 ret = 0 for i in range(k): ret += lst_both[i][0] return ret n ,k = map(int,input().split()) lst = [] for _ in range(n): lst.append(list(map(int,input().split()))) print(addition(lst, k)) ```
output
1
85,860
14
171,721
Provide tags and a correct Python 3 solution for this coding contest problem. Easy and hard versions are actually different problems, so read statements of both problems completely and carefully. Summer vacation has started so Alice and Bob want to play and joy, but... Their mom doesn't think so. She says that they have to read some amount of books before all entertainments. Alice and Bob will read each book together to end this exercise faster. There are n books in the family library. The i-th book is described by three integers: t_i β€” the amount of time Alice and Bob need to spend to read it, a_i (equals 1 if Alice likes the i-th book and 0 if not), and b_i (equals 1 if Bob likes the i-th book and 0 if not). So they need to choose some books from the given n books in such a way that: * Alice likes at least k books from the chosen set and Bob likes at least k books from the chosen set; * the total reading time of these books is minimized (they are children and want to play and joy as soon a possible). The set they choose is the same for both Alice an Bob (it's shared between them) and they read all books together, so the total reading time is the sum of t_i over all books that are in the chosen set. Your task is to help them and find any suitable set of books or determine that it is impossible to find such a set. Input The first line of the input contains two integers n and k (1 ≀ k ≀ n ≀ 2 β‹… 10^5). The next n lines contain descriptions of books, one description per line: the i-th line contains three integers t_i, a_i and b_i (1 ≀ t_i ≀ 10^4, 0 ≀ a_i, b_i ≀ 1), where: * t_i β€” the amount of time required for reading the i-th book; * a_i equals 1 if Alice likes the i-th book and 0 otherwise; * b_i equals 1 if Bob likes the i-th book and 0 otherwise. Output If there is no solution, print only one integer -1. Otherwise print one integer T β€” the minimum total reading time of the suitable set of books. Examples Input 8 4 7 1 1 2 1 1 4 0 1 8 1 1 1 0 1 1 1 1 1 0 1 3 0 0 Output 18 Input 5 2 6 0 0 9 0 0 1 0 1 2 1 1 5 1 0 Output 8 Input 5 3 3 0 0 2 1 0 3 1 0 5 0 1 3 0 1 Output -1
instruction
0
85,861
14
171,722
Tags: data structures, greedy, sortings Correct Solution: ``` n, k = tuple(map(int, input().split())) alice = [] bob = [] both = [] for _ in range(n): t, a, b = tuple(map(int, input().split())) if a == 1 and b == 1: both.append(t) elif a == 1: alice.append(t) elif b == 1: bob.append(t) both.sort() alice.sort() bob.sort() remain = 0 if k <= len(both): result = sum(both[:k]) else: remain = k - len(both) if remain > len(bob) or remain > len(alice): result = -1 else: result = sum(both) result += sum(alice[:remain]) + sum(bob[:remain]) index = max(0, k - len(both)) lenbob = len(bob) lenalice = len(alice) if result != -1: for i in range(min(k, len(both)) - 1, -1, -1): if index > lenbob - 1 or index > lenalice - 1: break newresult = result - both[i] + alice[index] + bob[index] index += 1 if newresult < result: result = newresult else: break print(result) ```
output
1
85,861
14
171,723
Provide tags and a correct Python 3 solution for this coding contest problem. Easy and hard versions are actually different problems, so read statements of both problems completely and carefully. Summer vacation has started so Alice and Bob want to play and joy, but... Their mom doesn't think so. She says that they have to read some amount of books before all entertainments. Alice and Bob will read each book together to end this exercise faster. There are n books in the family library. The i-th book is described by three integers: t_i β€” the amount of time Alice and Bob need to spend to read it, a_i (equals 1 if Alice likes the i-th book and 0 if not), and b_i (equals 1 if Bob likes the i-th book and 0 if not). So they need to choose some books from the given n books in such a way that: * Alice likes at least k books from the chosen set and Bob likes at least k books from the chosen set; * the total reading time of these books is minimized (they are children and want to play and joy as soon a possible). The set they choose is the same for both Alice an Bob (it's shared between them) and they read all books together, so the total reading time is the sum of t_i over all books that are in the chosen set. Your task is to help them and find any suitable set of books or determine that it is impossible to find such a set. Input The first line of the input contains two integers n and k (1 ≀ k ≀ n ≀ 2 β‹… 10^5). The next n lines contain descriptions of books, one description per line: the i-th line contains three integers t_i, a_i and b_i (1 ≀ t_i ≀ 10^4, 0 ≀ a_i, b_i ≀ 1), where: * t_i β€” the amount of time required for reading the i-th book; * a_i equals 1 if Alice likes the i-th book and 0 otherwise; * b_i equals 1 if Bob likes the i-th book and 0 otherwise. Output If there is no solution, print only one integer -1. Otherwise print one integer T β€” the minimum total reading time of the suitable set of books. Examples Input 8 4 7 1 1 2 1 1 4 0 1 8 1 1 1 0 1 1 1 1 1 0 1 3 0 0 Output 18 Input 5 2 6 0 0 9 0 0 1 0 1 2 1 1 5 1 0 Output 8 Input 5 3 3 0 0 2 1 0 3 1 0 5 0 1 3 0 1 Output -1
instruction
0
85,862
14
171,724
Tags: data structures, greedy, sortings Correct Solution: ``` n,k=list(map(int,input().split())) x=[] y=[] z=[] for i in range(n): t,a,b=list(map(int,input().split())) if a==1 and b==1: z.append(t) elif a==0 and b==1: y.append(t) elif a==1 and b==0: x.append(t) x1=len(x) y1=len(y) z1=len(z) if min(x1,y1)+z1<k: print(-1) else: x.sort() y.sort() s=min(x1,y1) i=0 while i<s: z.append(x[i]+y[i]) i+=1 z.sort() print(sum(z[:k])) ```
output
1
85,862
14
171,725
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Easy and hard versions are actually different problems, so read statements of both problems completely and carefully. Summer vacation has started so Alice and Bob want to play and joy, but... Their mom doesn't think so. She says that they have to read some amount of books before all entertainments. Alice and Bob will read each book together to end this exercise faster. There are n books in the family library. The i-th book is described by three integers: t_i β€” the amount of time Alice and Bob need to spend to read it, a_i (equals 1 if Alice likes the i-th book and 0 if not), and b_i (equals 1 if Bob likes the i-th book and 0 if not). So they need to choose some books from the given n books in such a way that: * Alice likes at least k books from the chosen set and Bob likes at least k books from the chosen set; * the total reading time of these books is minimized (they are children and want to play and joy as soon a possible). The set they choose is the same for both Alice an Bob (it's shared between them) and they read all books together, so the total reading time is the sum of t_i over all books that are in the chosen set. Your task is to help them and find any suitable set of books or determine that it is impossible to find such a set. Input The first line of the input contains two integers n and k (1 ≀ k ≀ n ≀ 2 β‹… 10^5). The next n lines contain descriptions of books, one description per line: the i-th line contains three integers t_i, a_i and b_i (1 ≀ t_i ≀ 10^4, 0 ≀ a_i, b_i ≀ 1), where: * t_i β€” the amount of time required for reading the i-th book; * a_i equals 1 if Alice likes the i-th book and 0 otherwise; * b_i equals 1 if Bob likes the i-th book and 0 otherwise. Output If there is no solution, print only one integer -1. Otherwise print one integer T β€” the minimum total reading time of the suitable set of books. Examples Input 8 4 7 1 1 2 1 1 4 0 1 8 1 1 1 0 1 1 1 1 1 0 1 3 0 0 Output 18 Input 5 2 6 0 0 9 0 0 1 0 1 2 1 1 5 1 0 Output 8 Input 5 3 3 0 0 2 1 0 3 1 0 5 0 1 3 0 1 Output -1 Submitted Solution: ``` n,k=map(int,input().split()) x=[];y=[];z=[] for i in range(n): t,a,b=map(int,input().split()) if a and b:x.append(t) elif a==1:y.append(t) elif b==1:z.append(t) y.sort();z.sort() for p,q in zip(y,z): x.append(p+q) x.sort() if len(x)<k:print(-1) else:print(sum(x[:k])) ```
instruction
0
85,863
14
171,726
Yes
output
1
85,863
14
171,727
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Easy and hard versions are actually different problems, so read statements of both problems completely and carefully. Summer vacation has started so Alice and Bob want to play and joy, but... Their mom doesn't think so. She says that they have to read some amount of books before all entertainments. Alice and Bob will read each book together to end this exercise faster. There are n books in the family library. The i-th book is described by three integers: t_i β€” the amount of time Alice and Bob need to spend to read it, a_i (equals 1 if Alice likes the i-th book and 0 if not), and b_i (equals 1 if Bob likes the i-th book and 0 if not). So they need to choose some books from the given n books in such a way that: * Alice likes at least k books from the chosen set and Bob likes at least k books from the chosen set; * the total reading time of these books is minimized (they are children and want to play and joy as soon a possible). The set they choose is the same for both Alice an Bob (it's shared between them) and they read all books together, so the total reading time is the sum of t_i over all books that are in the chosen set. Your task is to help them and find any suitable set of books or determine that it is impossible to find such a set. Input The first line of the input contains two integers n and k (1 ≀ k ≀ n ≀ 2 β‹… 10^5). The next n lines contain descriptions of books, one description per line: the i-th line contains three integers t_i, a_i and b_i (1 ≀ t_i ≀ 10^4, 0 ≀ a_i, b_i ≀ 1), where: * t_i β€” the amount of time required for reading the i-th book; * a_i equals 1 if Alice likes the i-th book and 0 otherwise; * b_i equals 1 if Bob likes the i-th book and 0 otherwise. Output If there is no solution, print only one integer -1. Otherwise print one integer T β€” the minimum total reading time of the suitable set of books. Examples Input 8 4 7 1 1 2 1 1 4 0 1 8 1 1 1 0 1 1 1 1 1 0 1 3 0 0 Output 18 Input 5 2 6 0 0 9 0 0 1 0 1 2 1 1 5 1 0 Output 8 Input 5 3 3 0 0 2 1 0 3 1 0 5 0 1 3 0 1 Output -1 Submitted Solution: ``` import sys import math import collections import heapq def set_debug(debug_mode=False): if debug_mode: fin = open('input.txt', 'r') sys.stdin = fin def int_input(): return list(map(int, input().split())) if __name__ == '__main__': # set_debug(True) # t = int(input()) t = 1 for ti in range(1, t + 1): n, k = int_input() both = [] Ab = [] Bb = [] A = 0 B = 0 for _ in range(n): t, a, b = int_input() if a == 1 and b == 1: both.append(t) elif a == 1: Ab.append(t) elif b == 1: Bb.append(t) Ab.sort() Bb.sort() for i in range(min(len(Ab), len(Bb))): both.append(Ab[i] + Bb[i]) print(-1 if len(both) < k else sum(sorted(both)[:k])) ```
instruction
0
85,864
14
171,728
Yes
output
1
85,864
14
171,729
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Easy and hard versions are actually different problems, so read statements of both problems completely and carefully. Summer vacation has started so Alice and Bob want to play and joy, but... Their mom doesn't think so. She says that they have to read some amount of books before all entertainments. Alice and Bob will read each book together to end this exercise faster. There are n books in the family library. The i-th book is described by three integers: t_i β€” the amount of time Alice and Bob need to spend to read it, a_i (equals 1 if Alice likes the i-th book and 0 if not), and b_i (equals 1 if Bob likes the i-th book and 0 if not). So they need to choose some books from the given n books in such a way that: * Alice likes at least k books from the chosen set and Bob likes at least k books from the chosen set; * the total reading time of these books is minimized (they are children and want to play and joy as soon a possible). The set they choose is the same for both Alice an Bob (it's shared between them) and they read all books together, so the total reading time is the sum of t_i over all books that are in the chosen set. Your task is to help them and find any suitable set of books or determine that it is impossible to find such a set. Input The first line of the input contains two integers n and k (1 ≀ k ≀ n ≀ 2 β‹… 10^5). The next n lines contain descriptions of books, one description per line: the i-th line contains three integers t_i, a_i and b_i (1 ≀ t_i ≀ 10^4, 0 ≀ a_i, b_i ≀ 1), where: * t_i β€” the amount of time required for reading the i-th book; * a_i equals 1 if Alice likes the i-th book and 0 otherwise; * b_i equals 1 if Bob likes the i-th book and 0 otherwise. Output If there is no solution, print only one integer -1. Otherwise print one integer T β€” the minimum total reading time of the suitable set of books. Examples Input 8 4 7 1 1 2 1 1 4 0 1 8 1 1 1 0 1 1 1 1 1 0 1 3 0 0 Output 18 Input 5 2 6 0 0 9 0 0 1 0 1 2 1 1 5 1 0 Output 8 Input 5 3 3 0 0 2 1 0 3 1 0 5 0 1 3 0 1 Output -1 Submitted Solution: ``` from collections import deque n, k = list(map(int, input().split())) both_ls = [] a_ls = [] b_ls = [] for i in range(n): t, a, b = list(map(int, input().split())) if a == 1 and b == 0: a_ls.append(t) elif a == 0 and b == 1: b_ls.append(t) elif a == 1 and b == 1: both_ls.append(t) a_ls = sorted(a_ls) b_ls = sorted(b_ls) both_ls = sorted(both_ls) a_ls = deque(a_ls) b_ls = deque(b_ls) both_ls = deque(both_ls) res = 0 broke = False for i in range(k): if len(both_ls)>0 and len(a_ls)>0 and len(b_ls)>0: if both_ls[0] >= (a_ls[0] + b_ls[0]): res += a_ls.popleft() res += b_ls.popleft() else: res += both_ls.popleft() elif len(both_ls)>0: res += both_ls.popleft() elif len(a_ls)>0 and len(b_ls)>0: res += a_ls.popleft() res += b_ls.popleft() else: print(-1) broke = True break if not broke: print(res) ```
instruction
0
85,865
14
171,730
Yes
output
1
85,865
14
171,731
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Easy and hard versions are actually different problems, so read statements of both problems completely and carefully. Summer vacation has started so Alice and Bob want to play and joy, but... Their mom doesn't think so. She says that they have to read some amount of books before all entertainments. Alice and Bob will read each book together to end this exercise faster. There are n books in the family library. The i-th book is described by three integers: t_i β€” the amount of time Alice and Bob need to spend to read it, a_i (equals 1 if Alice likes the i-th book and 0 if not), and b_i (equals 1 if Bob likes the i-th book and 0 if not). So they need to choose some books from the given n books in such a way that: * Alice likes at least k books from the chosen set and Bob likes at least k books from the chosen set; * the total reading time of these books is minimized (they are children and want to play and joy as soon a possible). The set they choose is the same for both Alice an Bob (it's shared between them) and they read all books together, so the total reading time is the sum of t_i over all books that are in the chosen set. Your task is to help them and find any suitable set of books or determine that it is impossible to find such a set. Input The first line of the input contains two integers n and k (1 ≀ k ≀ n ≀ 2 β‹… 10^5). The next n lines contain descriptions of books, one description per line: the i-th line contains three integers t_i, a_i and b_i (1 ≀ t_i ≀ 10^4, 0 ≀ a_i, b_i ≀ 1), where: * t_i β€” the amount of time required for reading the i-th book; * a_i equals 1 if Alice likes the i-th book and 0 otherwise; * b_i equals 1 if Bob likes the i-th book and 0 otherwise. Output If there is no solution, print only one integer -1. Otherwise print one integer T β€” the minimum total reading time of the suitable set of books. Examples Input 8 4 7 1 1 2 1 1 4 0 1 8 1 1 1 0 1 1 1 1 1 0 1 3 0 0 Output 18 Input 5 2 6 0 0 9 0 0 1 0 1 2 1 1 5 1 0 Output 8 Input 5 3 3 0 0 2 1 0 3 1 0 5 0 1 3 0 1 Output -1 Submitted Solution: ``` n, k = [int(x) for x in input().split()] both = [] bob = [] alice = [] for i in range(n): t, a, b = [int(x) for x in input().split()] if(a==1 and b==1): both.append(t) elif(a==1): alice.append(t) elif(b==1): bob.append(t) both.sort() bob.sort() alice.sort() y = max(k-min(len(bob),len(alice)),0) soma_both=0 sa = 0 sb = 0 poss = (len(both)+min(len(alice),len(bob))>=k) if(poss): for i in range(y): soma_both+=both[i] for i in range(max(k-y,0)): sa += alice[i] for i in range(max(k-y,0)): sb += bob[i] ptr1 = k-y ptr2 = k-y resposta = sa+sb+soma_both for i in range(y,len(both)): ptr1-=1 ptr2-=1 if(ptr2==-1 or ptr1==-1): break soma_both+=both[i] sa-=alice[ptr1] sb-=bob[ptr2] if(soma_both+sa+sb>=0): resposta = min(resposta,soma_both+sa+sb) print(resposta) else: print(-1) ```
instruction
0
85,866
14
171,732
Yes
output
1
85,866
14
171,733
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Easy and hard versions are actually different problems, so read statements of both problems completely and carefully. Summer vacation has started so Alice and Bob want to play and joy, but... Their mom doesn't think so. She says that they have to read some amount of books before all entertainments. Alice and Bob will read each book together to end this exercise faster. There are n books in the family library. The i-th book is described by three integers: t_i β€” the amount of time Alice and Bob need to spend to read it, a_i (equals 1 if Alice likes the i-th book and 0 if not), and b_i (equals 1 if Bob likes the i-th book and 0 if not). So they need to choose some books from the given n books in such a way that: * Alice likes at least k books from the chosen set and Bob likes at least k books from the chosen set; * the total reading time of these books is minimized (they are children and want to play and joy as soon a possible). The set they choose is the same for both Alice an Bob (it's shared between them) and they read all books together, so the total reading time is the sum of t_i over all books that are in the chosen set. Your task is to help them and find any suitable set of books or determine that it is impossible to find such a set. Input The first line of the input contains two integers n and k (1 ≀ k ≀ n ≀ 2 β‹… 10^5). The next n lines contain descriptions of books, one description per line: the i-th line contains three integers t_i, a_i and b_i (1 ≀ t_i ≀ 10^4, 0 ≀ a_i, b_i ≀ 1), where: * t_i β€” the amount of time required for reading the i-th book; * a_i equals 1 if Alice likes the i-th book and 0 otherwise; * b_i equals 1 if Bob likes the i-th book and 0 otherwise. Output If there is no solution, print only one integer -1. Otherwise print one integer T β€” the minimum total reading time of the suitable set of books. Examples Input 8 4 7 1 1 2 1 1 4 0 1 8 1 1 1 0 1 1 1 1 1 0 1 3 0 0 Output 18 Input 5 2 6 0 0 9 0 0 1 0 1 2 1 1 5 1 0 Output 8 Input 5 3 3 0 0 2 1 0 3 1 0 5 0 1 3 0 1 Output -1 Submitted Solution: ``` import sys s = sys.stdin.readline().split() n, m, k = int(s[0]), int(s[1]), int(s[2]) elev = False all = [] All = [] Alice = [] Bob = [] Both = [] none = [] z = 1 while n: i = sys.stdin.readline().split() x = 3 i.append(z) while x: i[x - 1] = int(i[x - 1]) x -= 1 all.append(i) if i[1] == i[2]: if i[1] == 0: none.append(i) else: Both.append(i) else: if i[1] == 0: Bob.append(i) else: Alice.append(i) z += 1 n -= 1 Alice.sort(key=lambda x: x[0]) Bob.sort(key=lambda x: x[0]) Both.sort(key=lambda x: x[0]) none.sort(key=lambda x: x[0]) #print('Alice') #print(Alice) #print('Alice') #print('Bob') #print(Bob) #print('Bob') #print('Both') #print(Both) #print('Both') #print('none') #print(none) #print('none') if elev: print('Alice1 = ' + str(len(Alice))) print('Bob1 = ' + str(len(Bob))) print('Both1 = ' + str(len(Both))) print('none1 = ' + str(len(none))) if 2 * k > m: l = 2 * k - m if len(Both) >= l: tresult = Both[:l] Both = Both[l:] All = Alice + Both + Bob + none m = 2 * (m - k) k = k - l else: print(-1) exit() else: tresult = [] if elev: print('Both2 = ' + str(len(Both))) print('tresult = ' + str(len(tresult))) resulta = [] resultb = [] if k > 0: aaa = Alice + Both aaa.sort(key=lambda x: x[0]) if len(aaa) >= k: resulta = aaa[:k] else: print(-1) exit() col_totals1 = [sum(x) for x in zip(*resulta)] xx = col_totals1[2] yy = k - xx #Both = Both[xx:] #Alice = Alice[yy:] #k = k - xx if elev: print('xx, yy = ' + str(xx) + ', ' + str(yy)) print('resulta = ' + str(len(resulta))) print('Both3 = ' + str(len(Both))) print('Alice2 = ' + str(len(Alice))) print('k = ' + str(k)) #if k > 0: bbb = Bob + Both bbb.sort(key=lambda x: x[0]) if len(bbb) >= k: resultb = bbb[:k] else: print(-1) exit() col_totals2 = [sum(x) for x in zip(*resultb)] xxx = col_totals2[1] yyy = k - xxx if elev: print('xxx, xyy = ' + str(xxx) + ', ' + str(yyy)) print('resultb = ' + str(len(resultb))) print('Both4 = ' + str(len(Both))) print('Bob2 = ' + str(len(Bob))) if max(xx, xxx) == xx: resultb = [] Both = Both[xx:] Alice = Alice[yy:] k = k - xx if k > 0: bbb = Bob + Both bbb.sort(key=lambda x: x[0]) if len(bbb) >= k: resultb = bbb[:k] else: print(-1) exit() col_totals2 = [sum(x) for x in zip(*resultb)] xxx = col_totals2[1] yyy = k - xxx Both = Both[xxx:] Bob = Bob[yyy:] else: resulta = [] Both = Both[xxx:] Bob = Bob[yyy:] k = k -xxx if k > 0: aaa = Alice + Both aaa.sort(key=lambda x: x[0]) if len(aaa) >= k: resulta = aaa[:k] else: print(-1) exit() col_totals2 = [sum(x) for x in zip(*resultb)] xx = col_totals2[1] yy = k - xx Both = Both[xx:] Bob = Bob[yy:] if elev: print('xx, yy = ' + str(xx) + ', ' + str(yy)) print('xxx, yyy = ' + str(xxx)+', '+ str(yyy)) print('resultb = ' + str(len(resultb))) print(resultb) print('resulta = ' + str(len(resulta))) print(resulta) print('Bothf = ' + str(len(Both))) print('Bobf = ' + str(len(Bob))) print('Alicf = '+ str(len(Alice))) q = len(resultb) + len(resulta) q = m - q All = Both + Alice + Bob + none All.sort(key=lambda x: x[0]) if elev: print('q = ' + str(q)) print('All = ' + str(len(All))) result = All[:q] result = resulta + resultb + result + tresult result.sort(key=lambda x: x[0]) print(sum(row[0] for row in result)) print(' '.join([str(row[3]) for row in result])) ```
instruction
0
85,867
14
171,734
No
output
1
85,867
14
171,735
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Easy and hard versions are actually different problems, so read statements of both problems completely and carefully. Summer vacation has started so Alice and Bob want to play and joy, but... Their mom doesn't think so. She says that they have to read some amount of books before all entertainments. Alice and Bob will read each book together to end this exercise faster. There are n books in the family library. The i-th book is described by three integers: t_i β€” the amount of time Alice and Bob need to spend to read it, a_i (equals 1 if Alice likes the i-th book and 0 if not), and b_i (equals 1 if Bob likes the i-th book and 0 if not). So they need to choose some books from the given n books in such a way that: * Alice likes at least k books from the chosen set and Bob likes at least k books from the chosen set; * the total reading time of these books is minimized (they are children and want to play and joy as soon a possible). The set they choose is the same for both Alice an Bob (it's shared between them) and they read all books together, so the total reading time is the sum of t_i over all books that are in the chosen set. Your task is to help them and find any suitable set of books or determine that it is impossible to find such a set. Input The first line of the input contains two integers n and k (1 ≀ k ≀ n ≀ 2 β‹… 10^5). The next n lines contain descriptions of books, one description per line: the i-th line contains three integers t_i, a_i and b_i (1 ≀ t_i ≀ 10^4, 0 ≀ a_i, b_i ≀ 1), where: * t_i β€” the amount of time required for reading the i-th book; * a_i equals 1 if Alice likes the i-th book and 0 otherwise; * b_i equals 1 if Bob likes the i-th book and 0 otherwise. Output If there is no solution, print only one integer -1. Otherwise print one integer T β€” the minimum total reading time of the suitable set of books. Examples Input 8 4 7 1 1 2 1 1 4 0 1 8 1 1 1 0 1 1 1 1 1 0 1 3 0 0 Output 18 Input 5 2 6 0 0 9 0 0 1 0 1 2 1 1 5 1 0 Output 8 Input 5 3 3 0 0 2 1 0 3 1 0 5 0 1 3 0 1 Output -1 Submitted Solution: ``` import sys n, k = input().split() l = [] l1 = [] l2 = [] d = 0 e = 0 m = 0 for i in range(0, int(n)): t, a, b = input().split() if int(a) == 1 and int(b) == 1: l.append(int(t)) if int(a) == 1 and int(b) == 0: l1.append(int(t)) if int(a) == 0 and int(b) == 1: l2.append(int(t)) l.sort() l1.sort() l2.sort() x=len(l) y=len(l1) z=len(l2) if x>=int(k): x=int(k) elif x<int(k) and x!=0: s=int(k)-x else: x=0 m=min(int(y),int(z)) f=int(k)-m h=int(k)//3 v=int(k)%3 g=0 if f<=0: m=int(k) if x==int(k) and (y==0 or z==0): d = sum(l[0:x]) print(d) elif x==int(k) and y!=0 and z!=0 and m==int(k): d = sum(l[0:x]) e = sum(l1[0:m])+sum(l2[0:m]) if v==0: g=sum(l[0:h])+sum(l1[0:h])+sum(l2[0:h]) print(min(d,e,g)) else: print(min(d,e)) elif x==int(k) and y!=0 and z!=0 and m!=int(k): d = sum(l[0:x]) e = sum(l[0:f])+sum(l1[0:m])+sum(l2[0:m]) print(min(d,e)) elif x<int(k) and x!=0 and y!=0 and z!=0 and m==int(k): d = sum(l)+sum(l1[0:s])+sum(l2[0:s]) e = sum(l1[0:m])+sum(l2[0:m]) print(min(d,e)) elif x<int(k) and x!=0 and y!=0 and z!=0 and m!=int(k): if s>y or s>z: print("-1") else: d=sum(l)+sum(l1[0:s])+sum(l2[0:s]) print(d) else: print("-1") ```
instruction
0
85,868
14
171,736
No
output
1
85,868
14
171,737
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Easy and hard versions are actually different problems, so read statements of both problems completely and carefully. Summer vacation has started so Alice and Bob want to play and joy, but... Their mom doesn't think so. She says that they have to read some amount of books before all entertainments. Alice and Bob will read each book together to end this exercise faster. There are n books in the family library. The i-th book is described by three integers: t_i β€” the amount of time Alice and Bob need to spend to read it, a_i (equals 1 if Alice likes the i-th book and 0 if not), and b_i (equals 1 if Bob likes the i-th book and 0 if not). So they need to choose some books from the given n books in such a way that: * Alice likes at least k books from the chosen set and Bob likes at least k books from the chosen set; * the total reading time of these books is minimized (they are children and want to play and joy as soon a possible). The set they choose is the same for both Alice an Bob (it's shared between them) and they read all books together, so the total reading time is the sum of t_i over all books that are in the chosen set. Your task is to help them and find any suitable set of books or determine that it is impossible to find such a set. Input The first line of the input contains two integers n and k (1 ≀ k ≀ n ≀ 2 β‹… 10^5). The next n lines contain descriptions of books, one description per line: the i-th line contains three integers t_i, a_i and b_i (1 ≀ t_i ≀ 10^4, 0 ≀ a_i, b_i ≀ 1), where: * t_i β€” the amount of time required for reading the i-th book; * a_i equals 1 if Alice likes the i-th book and 0 otherwise; * b_i equals 1 if Bob likes the i-th book and 0 otherwise. Output If there is no solution, print only one integer -1. Otherwise print one integer T β€” the minimum total reading time of the suitable set of books. Examples Input 8 4 7 1 1 2 1 1 4 0 1 8 1 1 1 0 1 1 1 1 1 0 1 3 0 0 Output 18 Input 5 2 6 0 0 9 0 0 1 0 1 2 1 1 5 1 0 Output 8 Input 5 3 3 0 0 2 1 0 3 1 0 5 0 1 3 0 1 Output -1 Submitted Solution: ``` import sys from functools import lru_cache, cmp_to_key from heapq import merge, heapify, heappop, heappush, nsmallest from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf from collections import defaultdict as dd, deque, Counter as C from itertools import combinations as comb, permutations as perm from bisect import bisect_left as bl, bisect_right as br, bisect from time import perf_counter from fractions import Fraction # sys.setrecursionlimit(pow(10, 6)) # sys.stdin = open("input.txt", "r") # sys.stdout = open("output.txt", "w") mod = pow(10, 9) + 7 mod2 = 998244353 def data(): return sys.stdin.readline().strip() def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end) def l(): return list(sp()) def sl(): return list(ssp()) def sp(): return map(int, data().split()) def ssp(): return map(str, data().split()) def l1d(n, val=0): return [val for i in range(n)] def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)] """ pppppppppppppppppppp ppppp ppppppppppppppppppp ppppppp ppppppppppppppppppppp pppppppp pppppppppppppppppppppp pppppppppppppppppppppppppppppppp pppppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppppp ppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppp pppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppp ppppppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppp pppppppppppppppppppppppppppppppppppppppppppppppppp ppppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppppp ppppppppppppppppppppp ppppppppppppppppppppppppppppppppppppppppppppp pppppppppppppppppppppppp pppppppppppppppppppppppppppppppp pppppppppppppppppppppp pppppppp ppppppppppppppppppppp ppppppp ppppppppppppppppppp ppppp pppppppppppppppppppp """ def cmp1(a, b): if not a[1] and b[1]: return 1 if not b[1] and a[1]: return -1 if a[0] <= b[0]: return -1 return 1 def cmp2(a, b): if not a[2] and b[2]: return 1 if not b[2] and a[2]: return -1 if a[0] <= b[0]: return -1 return 1 n, k = sp() mat = [] a, b = 0, 0 for i in range(n): mat.append(l()) if mat[i][1]: a += 1 if mat[i][2]: b += 1 answer = 0 if a < k or b < k: out(-1) exit() if a <= b: mat.sort(key=cmp_to_key(cmp1)) b = 0 for i in range(k): answer += mat[i][0] if mat[i][2]: b += 1 mat[i][2] = 0 mat[i][0] = -1 if b < k: mat.sort(key=cmp_to_key(cmp2)) i = 0 cnt = 0 while cnt < k-b: if mat[i][0] == -1: i += 1 continue cnt += 1 answer += mat[i][0] i += 1 out(answer) exit() mat.sort(key=cmp_to_key(cmp2)) b = 0 for i in range(k): answer += mat[i][0] if mat[i][1]: b += 1 mat[i][1] = 0 mat[i][0] = -1 if b < k: mat.sort(key=cmp_to_key(cmp1)) i = 0 cnt = 0 while cnt < k-b: if mat[i][0] == -1: i += 1 continue cnt += 1 answer += mat[i][0] i += 1 out(answer) ```
instruction
0
85,869
14
171,738
No
output
1
85,869
14
171,739
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Easy and hard versions are actually different problems, so read statements of both problems completely and carefully. Summer vacation has started so Alice and Bob want to play and joy, but... Their mom doesn't think so. She says that they have to read some amount of books before all entertainments. Alice and Bob will read each book together to end this exercise faster. There are n books in the family library. The i-th book is described by three integers: t_i β€” the amount of time Alice and Bob need to spend to read it, a_i (equals 1 if Alice likes the i-th book and 0 if not), and b_i (equals 1 if Bob likes the i-th book and 0 if not). So they need to choose some books from the given n books in such a way that: * Alice likes at least k books from the chosen set and Bob likes at least k books from the chosen set; * the total reading time of these books is minimized (they are children and want to play and joy as soon a possible). The set they choose is the same for both Alice an Bob (it's shared between them) and they read all books together, so the total reading time is the sum of t_i over all books that are in the chosen set. Your task is to help them and find any suitable set of books or determine that it is impossible to find such a set. Input The first line of the input contains two integers n and k (1 ≀ k ≀ n ≀ 2 β‹… 10^5). The next n lines contain descriptions of books, one description per line: the i-th line contains three integers t_i, a_i and b_i (1 ≀ t_i ≀ 10^4, 0 ≀ a_i, b_i ≀ 1), where: * t_i β€” the amount of time required for reading the i-th book; * a_i equals 1 if Alice likes the i-th book and 0 otherwise; * b_i equals 1 if Bob likes the i-th book and 0 otherwise. Output If there is no solution, print only one integer -1. Otherwise print one integer T β€” the minimum total reading time of the suitable set of books. Examples Input 8 4 7 1 1 2 1 1 4 0 1 8 1 1 1 0 1 1 1 1 1 0 1 3 0 0 Output 18 Input 5 2 6 0 0 9 0 0 1 0 1 2 1 1 5 1 0 Output 8 Input 5 3 3 0 0 2 1 0 3 1 0 5 0 1 3 0 1 Output -1 Submitted Solution: ``` import sys s = sys.stdin.readline().split() n, m, k = int(s[0]), int(s[1]), int(s[2]) all = [] All = [] Alice = [] Bob = [] Both = [] none = [] z = 1 while n: i = sys.stdin.readline().split() x = 3 i.append(z) while x: i[x-1] = int(i[x - 1]) x -= 1 all.append(i) if i[1] == i[2]: if i[1] == 0: i[1] = 1 i[2] = 1 none.append(i) else: i[1] = 0 i[2] = 0 Both.append(i) else: if i[1] == 0: i[1] = 1 i[2] = 0 Bob.append(i) else: i[1] = 0 i[2] = 1 Alice.append(i) z += 1 n -= 1 Alice.sort(key=lambda x: x[0]) Bob.sort(key=lambda x: x[0]) Both.sort(key=lambda x: x[0]) none.sort(key=lambda x: x[0]) tresult = [] if 2 * k > m: l = 2 * k - m if len(Both) >= l: tresult = Both[:l] Both = Both[l:] All = Alice + Both + Bob + none m = 2 * (m - k) k = k - l else: print(-1) exit() else: tresult = [] tresult1 = [] if min(len(Alice), len(Bob)) == len(Alice): if len(Alice) < k: k1 = k - len(Alice) if len(Both) < k1: print(-1) exit() else: tresult1 = Both[:k1] Both = Both[k1:] k = k - k1 else: if len(Bob) < k: k1 = k - len(Bob) if len(Both) < k1: print(-1) exit() else: tresult1 = Both[:k1] Both = Both[k1:] k = k - k1 Alice1 = Alice[:k] Bob1 = Bob[:k] Alice = Alice[k:] Bob = Bob[k:] corr = [] elev = False while len(Alice1) > 0 and len(Bob1) > 0 and len(Both) > 0 and len(none) > 0 and Alice1[-1][0] + Bob1[-1][0] >= Both[0][0]: Alice.append(Alice1[-1]) Bob.append(Bob1[-1]) corr.append(Both[0]) Alice1.pop(-1) Bob1.pop(-1) Both.pop(0) q = len(tresult1) + len(corr) + len(Alice1) + len(Bob1) q = m - q All = Alice + Bob + Both + none All.sort(key=lambda x: x[0]) result = All[:q] result = result + tresult + tresult1 + corr + Alice1 + Bob1 #print(sum(row[0] for row in result)) sum = 0 for row in result: sum = sum + row[0] print(sum) if sum == 82207: result.sort(key=lambda x: x[0]) print(All[q-1]) print(All[q]) All = All[q:] print(q) print(result[-1]) print(All[0]) print(' '.join([str(row[3]) for row in result])) ```
instruction
0
85,870
14
171,740
No
output
1
85,870
14
171,741
Provide tags and a correct Python 3 solution for this coding contest problem. Some country is populated by wizards. They want to organize a demonstration. There are n people living in the city, x of them are the wizards who will surely go to the demonstration. Other city people (n - x people) do not support the wizards and aren't going to go to the demonstration. We know that the city administration will react only to the demonstration involving at least y percent of the city people. Having considered the matter, the wizards decided to create clone puppets which can substitute the city people on the demonstration. So all in all, the demonstration will involve only the wizards and their puppets. The city administration cannot tell the difference between a puppet and a person, so, as they calculate the percentage, the administration will consider the city to be consisting of only n people and not containing any clone puppets. Help the wizards and find the minimum number of clones to create to that the demonstration had no less than y percent of the city people. Input The first line contains three space-separated integers, n, x, y (1 ≀ n, x, y ≀ 104, x ≀ n) β€” the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly. Please note that y can exceed 100 percent, that is, the administration wants to see on a demonstration more people that actually live in the city ( > n). Output Print a single integer β€” the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than y percent of n (the real total city population). Examples Input 10 1 14 Output 1 Input 20 10 50 Output 0 Input 1000 352 146 Output 1108 Note In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone. In the second sample 10 people should come to the demonstration. The city has 10 wizards. They will all come to the demonstration, so nobody has to create any clones.
instruction
0
85,974
14
171,948
Tags: implementation, math Correct Solution: ``` import math n, x, z = map(int, input().split()) print(max(0, math.ceil(n / 100 * z) - x)) ```
output
1
85,974
14
171,949
Provide tags and a correct Python 3 solution for this coding contest problem. Some country is populated by wizards. They want to organize a demonstration. There are n people living in the city, x of them are the wizards who will surely go to the demonstration. Other city people (n - x people) do not support the wizards and aren't going to go to the demonstration. We know that the city administration will react only to the demonstration involving at least y percent of the city people. Having considered the matter, the wizards decided to create clone puppets which can substitute the city people on the demonstration. So all in all, the demonstration will involve only the wizards and their puppets. The city administration cannot tell the difference between a puppet and a person, so, as they calculate the percentage, the administration will consider the city to be consisting of only n people and not containing any clone puppets. Help the wizards and find the minimum number of clones to create to that the demonstration had no less than y percent of the city people. Input The first line contains three space-separated integers, n, x, y (1 ≀ n, x, y ≀ 104, x ≀ n) β€” the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly. Please note that y can exceed 100 percent, that is, the administration wants to see on a demonstration more people that actually live in the city ( > n). Output Print a single integer β€” the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than y percent of n (the real total city population). Examples Input 10 1 14 Output 1 Input 20 10 50 Output 0 Input 1000 352 146 Output 1108 Note In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone. In the second sample 10 people should come to the demonstration. The city has 10 wizards. They will all come to the demonstration, so nobody has to create any clones.
instruction
0
85,975
14
171,950
Tags: implementation, math Correct Solution: ``` import math n,w,p = map(int,input().split()) needed = int(math.ceil((n*p)/100)) ans = needed-w if ans > 0: print(ans) else: print(0) ```
output
1
85,975
14
171,951
Provide tags and a correct Python 3 solution for this coding contest problem. Some country is populated by wizards. They want to organize a demonstration. There are n people living in the city, x of them are the wizards who will surely go to the demonstration. Other city people (n - x people) do not support the wizards and aren't going to go to the demonstration. We know that the city administration will react only to the demonstration involving at least y percent of the city people. Having considered the matter, the wizards decided to create clone puppets which can substitute the city people on the demonstration. So all in all, the demonstration will involve only the wizards and their puppets. The city administration cannot tell the difference between a puppet and a person, so, as they calculate the percentage, the administration will consider the city to be consisting of only n people and not containing any clone puppets. Help the wizards and find the minimum number of clones to create to that the demonstration had no less than y percent of the city people. Input The first line contains three space-separated integers, n, x, y (1 ≀ n, x, y ≀ 104, x ≀ n) β€” the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly. Please note that y can exceed 100 percent, that is, the administration wants to see on a demonstration more people that actually live in the city ( > n). Output Print a single integer β€” the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than y percent of n (the real total city population). Examples Input 10 1 14 Output 1 Input 20 10 50 Output 0 Input 1000 352 146 Output 1108 Note In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone. In the second sample 10 people should come to the demonstration. The city has 10 wizards. They will all come to the demonstration, so nobody has to create any clones.
instruction
0
85,976
14
171,952
Tags: implementation, math Correct Solution: ``` from math import ceil def magicians(n, x, y): z = ceil(n * y / 100) if x < z: return z - x return 0 N, X, Y = [int(i) for i in input().split()] print(magicians(N, X, Y)) ```
output
1
85,976
14
171,953
Provide tags and a correct Python 3 solution for this coding contest problem. Some country is populated by wizards. They want to organize a demonstration. There are n people living in the city, x of them are the wizards who will surely go to the demonstration. Other city people (n - x people) do not support the wizards and aren't going to go to the demonstration. We know that the city administration will react only to the demonstration involving at least y percent of the city people. Having considered the matter, the wizards decided to create clone puppets which can substitute the city people on the demonstration. So all in all, the demonstration will involve only the wizards and their puppets. The city administration cannot tell the difference between a puppet and a person, so, as they calculate the percentage, the administration will consider the city to be consisting of only n people and not containing any clone puppets. Help the wizards and find the minimum number of clones to create to that the demonstration had no less than y percent of the city people. Input The first line contains three space-separated integers, n, x, y (1 ≀ n, x, y ≀ 104, x ≀ n) β€” the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly. Please note that y can exceed 100 percent, that is, the administration wants to see on a demonstration more people that actually live in the city ( > n). Output Print a single integer β€” the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than y percent of n (the real total city population). Examples Input 10 1 14 Output 1 Input 20 10 50 Output 0 Input 1000 352 146 Output 1108 Note In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone. In the second sample 10 people should come to the demonstration. The city has 10 wizards. They will all come to the demonstration, so nobody has to create any clones.
instruction
0
85,977
14
171,954
Tags: implementation, math Correct Solution: ``` import sys import math #to read string get_string = lambda: sys.stdin.readline().strip() #to read list of integers get_int_list = lambda: list( map(int,sys.stdin.readline().strip().split()) ) #to read integers get_int = lambda: int(sys.stdin.readline()) #to print fast pt = lambda x: sys.stdout.write(str(x)+'\n') #--------------------------------WhiteHat010--------------------------------------# n,x,y = get_int_list() req = math.ceil((y/100)*n) if req > x: print(req-x) else: print(0) ```
output
1
85,977
14
171,955
Provide tags and a correct Python 3 solution for this coding contest problem. Some country is populated by wizards. They want to organize a demonstration. There are n people living in the city, x of them are the wizards who will surely go to the demonstration. Other city people (n - x people) do not support the wizards and aren't going to go to the demonstration. We know that the city administration will react only to the demonstration involving at least y percent of the city people. Having considered the matter, the wizards decided to create clone puppets which can substitute the city people on the demonstration. So all in all, the demonstration will involve only the wizards and their puppets. The city administration cannot tell the difference between a puppet and a person, so, as they calculate the percentage, the administration will consider the city to be consisting of only n people and not containing any clone puppets. Help the wizards and find the minimum number of clones to create to that the demonstration had no less than y percent of the city people. Input The first line contains three space-separated integers, n, x, y (1 ≀ n, x, y ≀ 104, x ≀ n) β€” the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly. Please note that y can exceed 100 percent, that is, the administration wants to see on a demonstration more people that actually live in the city ( > n). Output Print a single integer β€” the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than y percent of n (the real total city population). Examples Input 10 1 14 Output 1 Input 20 10 50 Output 0 Input 1000 352 146 Output 1108 Note In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone. In the second sample 10 people should come to the demonstration. The city has 10 wizards. They will all come to the demonstration, so nobody has to create any clones.
instruction
0
85,978
14
171,956
Tags: implementation, math Correct Solution: ``` from math import ceil n, x, y = map(int, input().split()) goal = ceil(n * (y / 100)) print (max(goal - x, 0)) ```
output
1
85,978
14
171,957
Provide tags and a correct Python 3 solution for this coding contest problem. Some country is populated by wizards. They want to organize a demonstration. There are n people living in the city, x of them are the wizards who will surely go to the demonstration. Other city people (n - x people) do not support the wizards and aren't going to go to the demonstration. We know that the city administration will react only to the demonstration involving at least y percent of the city people. Having considered the matter, the wizards decided to create clone puppets which can substitute the city people on the demonstration. So all in all, the demonstration will involve only the wizards and their puppets. The city administration cannot tell the difference between a puppet and a person, so, as they calculate the percentage, the administration will consider the city to be consisting of only n people and not containing any clone puppets. Help the wizards and find the minimum number of clones to create to that the demonstration had no less than y percent of the city people. Input The first line contains three space-separated integers, n, x, y (1 ≀ n, x, y ≀ 104, x ≀ n) β€” the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly. Please note that y can exceed 100 percent, that is, the administration wants to see on a demonstration more people that actually live in the city ( > n). Output Print a single integer β€” the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than y percent of n (the real total city population). Examples Input 10 1 14 Output 1 Input 20 10 50 Output 0 Input 1000 352 146 Output 1108 Note In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone. In the second sample 10 people should come to the demonstration. The city has 10 wizards. They will all come to the demonstration, so nobody has to create any clones.
instruction
0
85,979
14
171,958
Tags: implementation, math Correct Solution: ``` import math n,x,y = map(int,input().split(' ')) a = int(math.ceil(float(n * y * 0.01))) if x >= a: print(0) else: print(a - x) ```
output
1
85,979
14
171,959
Provide tags and a correct Python 3 solution for this coding contest problem. Some country is populated by wizards. They want to organize a demonstration. There are n people living in the city, x of them are the wizards who will surely go to the demonstration. Other city people (n - x people) do not support the wizards and aren't going to go to the demonstration. We know that the city administration will react only to the demonstration involving at least y percent of the city people. Having considered the matter, the wizards decided to create clone puppets which can substitute the city people on the demonstration. So all in all, the demonstration will involve only the wizards and their puppets. The city administration cannot tell the difference between a puppet and a person, so, as they calculate the percentage, the administration will consider the city to be consisting of only n people and not containing any clone puppets. Help the wizards and find the minimum number of clones to create to that the demonstration had no less than y percent of the city people. Input The first line contains three space-separated integers, n, x, y (1 ≀ n, x, y ≀ 104, x ≀ n) β€” the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly. Please note that y can exceed 100 percent, that is, the administration wants to see on a demonstration more people that actually live in the city ( > n). Output Print a single integer β€” the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than y percent of n (the real total city population). Examples Input 10 1 14 Output 1 Input 20 10 50 Output 0 Input 1000 352 146 Output 1108 Note In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone. In the second sample 10 people should come to the demonstration. The city has 10 wizards. They will all come to the demonstration, so nobody has to create any clones.
instruction
0
85,980
14
171,960
Tags: implementation, math Correct Solution: ``` import sys import math n, x, y = [int(x) for x in (sys.stdin.readline()).split()] req = int(math.ceil(y / 100.0 * n)) if(req - x < 0): print(0) else: print(req - x) ```
output
1
85,980
14
171,961
Provide tags and a correct Python 3 solution for this coding contest problem. Some country is populated by wizards. They want to organize a demonstration. There are n people living in the city, x of them are the wizards who will surely go to the demonstration. Other city people (n - x people) do not support the wizards and aren't going to go to the demonstration. We know that the city administration will react only to the demonstration involving at least y percent of the city people. Having considered the matter, the wizards decided to create clone puppets which can substitute the city people on the demonstration. So all in all, the demonstration will involve only the wizards and their puppets. The city administration cannot tell the difference between a puppet and a person, so, as they calculate the percentage, the administration will consider the city to be consisting of only n people and not containing any clone puppets. Help the wizards and find the minimum number of clones to create to that the demonstration had no less than y percent of the city people. Input The first line contains three space-separated integers, n, x, y (1 ≀ n, x, y ≀ 104, x ≀ n) β€” the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly. Please note that y can exceed 100 percent, that is, the administration wants to see on a demonstration more people that actually live in the city ( > n). Output Print a single integer β€” the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than y percent of n (the real total city population). Examples Input 10 1 14 Output 1 Input 20 10 50 Output 0 Input 1000 352 146 Output 1108 Note In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone. In the second sample 10 people should come to the demonstration. The city has 10 wizards. They will all come to the demonstration, so nobody has to create any clones.
instruction
0
85,981
14
171,962
Tags: implementation, math Correct Solution: ``` n, x, y = map(int,input().split()) import math print (0 if x>=n*y/100 else math.ceil(n*y/100 - x)) ```
output
1
85,981
14
171,963
Provide tags and a correct Python 3 solution for this coding contest problem. A factory produces thimbles in bulk. Typically, it can produce up to a thimbles a day. However, some of the machinery is defective, so it can currently only produce b thimbles each day. The factory intends to choose a k-day period to do maintenance and construction; it cannot produce any thimbles during this time, but will be restored to its full production of a thimbles per day after the k days are complete. Initially, no orders are pending. The factory receives updates of the form di, ai, indicating that ai new orders have been placed for the di-th day. Each order requires a single thimble to be produced on precisely the specified day. The factory may opt to fill as many or as few of the orders in a single batch as it likes. As orders come in, the factory owner would like to know the maximum number of orders he will be able to fill if he starts repairs on a given day pi. Help the owner answer his questions. Input The first line contains five integers n, k, a, b, and q (1 ≀ k ≀ n ≀ 200 000, 1 ≀ b < a ≀ 10 000, 1 ≀ q ≀ 200 000) β€” the number of days, the length of the repair time, the production rates of the factory, and the number of updates, respectively. The next q lines contain the descriptions of the queries. Each query is of one of the following two forms: * 1 di ai (1 ≀ di ≀ n, 1 ≀ ai ≀ 10 000), representing an update of ai orders on day di, or * 2 pi (1 ≀ pi ≀ n - k + 1), representing a question: at the moment, how many orders could be filled if the factory decided to commence repairs on day pi? It's guaranteed that the input will contain at least one query of the second type. Output For each query of the second type, print a line containing a single integer β€” the maximum number of orders that the factory can fill over all n days. Examples Input 5 2 2 1 8 1 1 2 1 5 3 1 2 1 2 2 1 4 2 1 3 2 2 1 2 3 Output 3 6 4 Input 5 4 10 1 6 1 1 5 1 5 5 1 3 2 1 5 2 2 1 2 2 Output 7 1 Note Consider the first sample. We produce up to 1 thimble a day currently and will produce up to 2 thimbles a day after repairs. Repairs take 2 days. For the first question, we are able to fill 1 order on day 1, no orders on days 2 and 3 since we are repairing, no orders on day 4 since no thimbles have been ordered for that day, and 2 orders for day 5 since we are limited to our production capacity, for a total of 3 orders filled. For the third question, we are able to fill 1 order on day 1, 1 order on day 2, and 2 orders on day 5, for a total of 4 orders.
instruction
0
86,147
14
172,294
Tags: data structures Correct Solution: ``` from functools import reduce class SegmentTree(): def __init__(self, L, function = lambda x,y: x+y, initilizer = None): self.function = function self.initilizer = initilizer N = self.size = len(L) M = 1 << N.bit_length() self.margin = 2*M - N self.L = [None for i in range(self.margin)] + L for i in range(M-1, 0, -1): x, y = self.L[i<<1], self.L[i<<1|1] self.L[i] = None if x is None or y is None else function(x, y) def modify(self, pos, value): p = pos + self.margin self.L[p] = value while p > 1: x, y = self.L[p], self.L[p^1] if p&1: x, y = y, x self.L[p>>1] = None if x is None or y is None else self.function(x, y) p>>=1 def query(self, left, right): l, r = left + self.margin, right + self.margin stack = [] void = True if self.initilizer is not None: void = False result = self.initilizer while l < r: if l&1: if void: result = self.L[l] void = False else: result = self.function(result, self.L[l]) l+=1 if r&1: r-=1 stack.append(self.L[r]) l>>=1 r>>=1 init = stack.pop() if void else result return reduce(self.function, reversed(stack), init) import sys n, k, a, b, q = [int(x) for x in input().split()] orders = [0]*(n+2) a_tree, b_tree = SegmentTree(orders, initilizer = 0), SegmentTree(orders, initilizer = 0) for line in sys.stdin: s = [int(x) for x in line.split()] if s[0] == 1: orders[s[1]] += s[2] a_tree.modify(s[1], min(a, orders[s[1]])) b_tree.modify(s[1], min(b, orders[s[1]])) else: query = b_tree.query(0, s[1]) + a_tree.query(s[1]+k, n+1) print(query) ```
output
1
86,147
14
172,295
Provide tags and a correct Python 3 solution for this coding contest problem. A factory produces thimbles in bulk. Typically, it can produce up to a thimbles a day. However, some of the machinery is defective, so it can currently only produce b thimbles each day. The factory intends to choose a k-day period to do maintenance and construction; it cannot produce any thimbles during this time, but will be restored to its full production of a thimbles per day after the k days are complete. Initially, no orders are pending. The factory receives updates of the form di, ai, indicating that ai new orders have been placed for the di-th day. Each order requires a single thimble to be produced on precisely the specified day. The factory may opt to fill as many or as few of the orders in a single batch as it likes. As orders come in, the factory owner would like to know the maximum number of orders he will be able to fill if he starts repairs on a given day pi. Help the owner answer his questions. Input The first line contains five integers n, k, a, b, and q (1 ≀ k ≀ n ≀ 200 000, 1 ≀ b < a ≀ 10 000, 1 ≀ q ≀ 200 000) β€” the number of days, the length of the repair time, the production rates of the factory, and the number of updates, respectively. The next q lines contain the descriptions of the queries. Each query is of one of the following two forms: * 1 di ai (1 ≀ di ≀ n, 1 ≀ ai ≀ 10 000), representing an update of ai orders on day di, or * 2 pi (1 ≀ pi ≀ n - k + 1), representing a question: at the moment, how many orders could be filled if the factory decided to commence repairs on day pi? It's guaranteed that the input will contain at least one query of the second type. Output For each query of the second type, print a line containing a single integer β€” the maximum number of orders that the factory can fill over all n days. Examples Input 5 2 2 1 8 1 1 2 1 5 3 1 2 1 2 2 1 4 2 1 3 2 2 1 2 3 Output 3 6 4 Input 5 4 10 1 6 1 1 5 1 5 5 1 3 2 1 5 2 2 1 2 2 Output 7 1 Note Consider the first sample. We produce up to 1 thimble a day currently and will produce up to 2 thimbles a day after repairs. Repairs take 2 days. For the first question, we are able to fill 1 order on day 1, no orders on days 2 and 3 since we are repairing, no orders on day 4 since no thimbles have been ordered for that day, and 2 orders for day 5 since we are limited to our production capacity, for a total of 3 orders filled. For the third question, we are able to fill 1 order on day 1, 1 order on day 2, and 2 orders on day 5, for a total of 4 orders.
instruction
0
86,148
14
172,296
Tags: data structures Correct Solution: ``` import sys from math import * def minp(): return sys.stdin.readline().strip() def mint(): return int(minp()) def mints(): return map(int, minp().split()) def add(a,x,v): while x<len(a): a[x] += v x |= x+1 def get(a,x): r = 0 while x>=0: r += a[x] x = (x&(x+1))-1 return r n, k, a, b, q = mints() h1 = [0]*n h2 = [0]*n z = [0]*n for i in range(q): t = tuple(mints()) if t[0] == 1: p = z[t[1]-1] pp = p + t[2] add(h1, t[1]-1, min(a,pp)-min(a,p)) add(h2, t[1]-1, min(b,pp)-min(b,p)) z[t[1]-1] = pp else: print(get(h2,t[1]-2)+get(h1,n-1)-get(h1,t[1]+k-2)) ```
output
1
86,148
14
172,297
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A factory produces thimbles in bulk. Typically, it can produce up to a thimbles a day. However, some of the machinery is defective, so it can currently only produce b thimbles each day. The factory intends to choose a k-day period to do maintenance and construction; it cannot produce any thimbles during this time, but will be restored to its full production of a thimbles per day after the k days are complete. Initially, no orders are pending. The factory receives updates of the form di, ai, indicating that ai new orders have been placed for the di-th day. Each order requires a single thimble to be produced on precisely the specified day. The factory may opt to fill as many or as few of the orders in a single batch as it likes. As orders come in, the factory owner would like to know the maximum number of orders he will be able to fill if he starts repairs on a given day pi. Help the owner answer his questions. Input The first line contains five integers n, k, a, b, and q (1 ≀ k ≀ n ≀ 200 000, 1 ≀ b < a ≀ 10 000, 1 ≀ q ≀ 200 000) β€” the number of days, the length of the repair time, the production rates of the factory, and the number of updates, respectively. The next q lines contain the descriptions of the queries. Each query is of one of the following two forms: * 1 di ai (1 ≀ di ≀ n, 1 ≀ ai ≀ 10 000), representing an update of ai orders on day di, or * 2 pi (1 ≀ pi ≀ n - k + 1), representing a question: at the moment, how many orders could be filled if the factory decided to commence repairs on day pi? It's guaranteed that the input will contain at least one query of the second type. Output For each query of the second type, print a line containing a single integer β€” the maximum number of orders that the factory can fill over all n days. Examples Input 5 2 2 1 8 1 1 2 1 5 3 1 2 1 2 2 1 4 2 1 3 2 2 1 2 3 Output 3 6 4 Input 5 4 10 1 6 1 1 5 1 5 5 1 3 2 1 5 2 2 1 2 2 Output 7 1 Note Consider the first sample. We produce up to 1 thimble a day currently and will produce up to 2 thimbles a day after repairs. Repairs take 2 days. For the first question, we are able to fill 1 order on day 1, no orders on days 2 and 3 since we are repairing, no orders on day 4 since no thimbles have been ordered for that day, and 2 orders for day 5 since we are limited to our production capacity, for a total of 3 orders filled. For the third question, we are able to fill 1 order on day 1, 1 order on day 2, and 2 orders on day 5, for a total of 4 orders. Submitted Solution: ``` #!/usr/bin/env python3 n, k, a, b, q = [int(x) for x in input().split()] tree = [[0] * n, [0] * n] orders = [[0] * n, [0] * n] total = [0, 0] def add(d_i, a_i, b_i): total[0] += a_i # total[1] += b_i i = d_i while i < n: tree[0][i] += a_i # tree[1][i] += b_i i |= i + 1 def ask(p): # [1; p) - normal # [p; p + k) - maintanance # [p + k; n) - normal first_interval = [0, 0] i = p - 1 while i >= 0: # first_interval[0] += tree[0][i] first_interval[1] += tree[1][i] i &= i + 1 i -= 1 second_interval = [0, 0] i = p + k - 1 while i >= 0: second_interval[0] += tree[0][i] # second_interval[1] += tree[1][i] i &= i + 1 i -= 1 # ans = first_interval[0] + \ # second_interval[1] - first_interval[1] + \ # total[0] - second_interval[0] ans = first_interval[1] + \ total[0] - second_interval[0] # ans = second_interval[1] - first_interval[1] print(ans) for i in range(0, q): l = [int(x) for x in input().split()] if l[0] == 1: d_i, a_i, b_i = l[1] - 1, l[2], l[2] if orders[0][d_i] + a_i > a: a_i = a - orders[0][d_i] orders[0][d_i] = a else: orders[0][d_i] += a_i if orders[1][d_i] + b_i > b: b_i = b - orders[1][d_i] orders[1][d_i] = b else: orders[1][d_i] += b_i add(d_i, a_i, b_i) else: # assert l[0] == 2 p_i = l[1] - 1 ask(p_i) ```
instruction
0
86,149
14
172,298
No
output
1
86,149
14
172,299
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A factory produces thimbles in bulk. Typically, it can produce up to a thimbles a day. However, some of the machinery is defective, so it can currently only produce b thimbles each day. The factory intends to choose a k-day period to do maintenance and construction; it cannot produce any thimbles during this time, but will be restored to its full production of a thimbles per day after the k days are complete. Initially, no orders are pending. The factory receives updates of the form di, ai, indicating that ai new orders have been placed for the di-th day. Each order requires a single thimble to be produced on precisely the specified day. The factory may opt to fill as many or as few of the orders in a single batch as it likes. As orders come in, the factory owner would like to know the maximum number of orders he will be able to fill if he starts repairs on a given day pi. Help the owner answer his questions. Input The first line contains five integers n, k, a, b, and q (1 ≀ k ≀ n ≀ 200 000, 1 ≀ b < a ≀ 10 000, 1 ≀ q ≀ 200 000) β€” the number of days, the length of the repair time, the production rates of the factory, and the number of updates, respectively. The next q lines contain the descriptions of the queries. Each query is of one of the following two forms: * 1 di ai (1 ≀ di ≀ n, 1 ≀ ai ≀ 10 000), representing an update of ai orders on day di, or * 2 pi (1 ≀ pi ≀ n - k + 1), representing a question: at the moment, how many orders could be filled if the factory decided to commence repairs on day pi? It's guaranteed that the input will contain at least one query of the second type. Output For each query of the second type, print a line containing a single integer β€” the maximum number of orders that the factory can fill over all n days. Examples Input 5 2 2 1 8 1 1 2 1 5 3 1 2 1 2 2 1 4 2 1 3 2 2 1 2 3 Output 3 6 4 Input 5 4 10 1 6 1 1 5 1 5 5 1 3 2 1 5 2 2 1 2 2 Output 7 1 Note Consider the first sample. We produce up to 1 thimble a day currently and will produce up to 2 thimbles a day after repairs. Repairs take 2 days. For the first question, we are able to fill 1 order on day 1, no orders on days 2 and 3 since we are repairing, no orders on day 4 since no thimbles have been ordered for that day, and 2 orders for day 5 since we are limited to our production capacity, for a total of 3 orders filled. For the third question, we are able to fill 1 order on day 1, 1 order on day 2, and 2 orders on day 5, for a total of 4 orders. Submitted Solution: ``` n, k, a, b, q = map(int, input().split()) cnt = [0] * (n + 1) days = [0] * (n+1) for i in range(q): c = list(map(int, input().split())) if len(c) == 3: cnt[c[1] - 1] += cnt[c[1] - 2] + min(b, c[2]) days[c[1] - 1] += c[2] else: cop = cnt[::] cop[c[1]:c[1]+k] = [0]*k c[1] += k cop[c[1] - 1] = cnt[c[1] - k - 2] + min(a, days[c[1]-1]) cop[c[1]:] = [0]*(n - c[1]+1) for j in range(c[1], n+1): cop[j] = cop[j - 1] + min(a, days[j]) print(cop[-1]) ```
instruction
0
86,150
14
172,300
No
output
1
86,150
14
172,301
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A factory produces thimbles in bulk. Typically, it can produce up to a thimbles a day. However, some of the machinery is defective, so it can currently only produce b thimbles each day. The factory intends to choose a k-day period to do maintenance and construction; it cannot produce any thimbles during this time, but will be restored to its full production of a thimbles per day after the k days are complete. Initially, no orders are pending. The factory receives updates of the form di, ai, indicating that ai new orders have been placed for the di-th day. Each order requires a single thimble to be produced on precisely the specified day. The factory may opt to fill as many or as few of the orders in a single batch as it likes. As orders come in, the factory owner would like to know the maximum number of orders he will be able to fill if he starts repairs on a given day pi. Help the owner answer his questions. Input The first line contains five integers n, k, a, b, and q (1 ≀ k ≀ n ≀ 200 000, 1 ≀ b < a ≀ 10 000, 1 ≀ q ≀ 200 000) β€” the number of days, the length of the repair time, the production rates of the factory, and the number of updates, respectively. The next q lines contain the descriptions of the queries. Each query is of one of the following two forms: * 1 di ai (1 ≀ di ≀ n, 1 ≀ ai ≀ 10 000), representing an update of ai orders on day di, or * 2 pi (1 ≀ pi ≀ n - k + 1), representing a question: at the moment, how many orders could be filled if the factory decided to commence repairs on day pi? It's guaranteed that the input will contain at least one query of the second type. Output For each query of the second type, print a line containing a single integer β€” the maximum number of orders that the factory can fill over all n days. Examples Input 5 2 2 1 8 1 1 2 1 5 3 1 2 1 2 2 1 4 2 1 3 2 2 1 2 3 Output 3 6 4 Input 5 4 10 1 6 1 1 5 1 5 5 1 3 2 1 5 2 2 1 2 2 Output 7 1 Note Consider the first sample. We produce up to 1 thimble a day currently and will produce up to 2 thimbles a day after repairs. Repairs take 2 days. For the first question, we are able to fill 1 order on day 1, no orders on days 2 and 3 since we are repairing, no orders on day 4 since no thimbles have been ordered for that day, and 2 orders for day 5 since we are limited to our production capacity, for a total of 3 orders filled. For the third question, we are able to fill 1 order on day 1, 1 order on day 2, and 2 orders on day 5, for a total of 4 orders. Submitted Solution: ``` n, k, a, b, q = map(int, input().split()) g1 = [0] * (n + 1) g2 = [0] * (n + 1) p = [] for i in range(q): s = input().split() if len(s) == 3: h, d = int(s[1]), int(s[2]) g1[h] += d g2[h] += d else: pos = int(s[1]) sum = 0 for i in range(n + 1): sum += min(g1[i], b) g1[i] = sum sum = 0 for i in range(n + 1): sum += min(g2[i], a) g2[i] = sum sum1 = g1[max(pos - 1, 0)] - g1[0] sum2 = g2[-1] - g2[min(pos + k - 1, n)] print(sum1 + sum2) ```
instruction
0
86,151
14
172,302
No
output
1
86,151
14
172,303
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A factory produces thimbles in bulk. Typically, it can produce up to a thimbles a day. However, some of the machinery is defective, so it can currently only produce b thimbles each day. The factory intends to choose a k-day period to do maintenance and construction; it cannot produce any thimbles during this time, but will be restored to its full production of a thimbles per day after the k days are complete. Initially, no orders are pending. The factory receives updates of the form di, ai, indicating that ai new orders have been placed for the di-th day. Each order requires a single thimble to be produced on precisely the specified day. The factory may opt to fill as many or as few of the orders in a single batch as it likes. As orders come in, the factory owner would like to know the maximum number of orders he will be able to fill if he starts repairs on a given day pi. Help the owner answer his questions. Input The first line contains five integers n, k, a, b, and q (1 ≀ k ≀ n ≀ 200 000, 1 ≀ b < a ≀ 10 000, 1 ≀ q ≀ 200 000) β€” the number of days, the length of the repair time, the production rates of the factory, and the number of updates, respectively. The next q lines contain the descriptions of the queries. Each query is of one of the following two forms: * 1 di ai (1 ≀ di ≀ n, 1 ≀ ai ≀ 10 000), representing an update of ai orders on day di, or * 2 pi (1 ≀ pi ≀ n - k + 1), representing a question: at the moment, how many orders could be filled if the factory decided to commence repairs on day pi? It's guaranteed that the input will contain at least one query of the second type. Output For each query of the second type, print a line containing a single integer β€” the maximum number of orders that the factory can fill over all n days. Examples Input 5 2 2 1 8 1 1 2 1 5 3 1 2 1 2 2 1 4 2 1 3 2 2 1 2 3 Output 3 6 4 Input 5 4 10 1 6 1 1 5 1 5 5 1 3 2 1 5 2 2 1 2 2 Output 7 1 Note Consider the first sample. We produce up to 1 thimble a day currently and will produce up to 2 thimbles a day after repairs. Repairs take 2 days. For the first question, we are able to fill 1 order on day 1, no orders on days 2 and 3 since we are repairing, no orders on day 4 since no thimbles have been ordered for that day, and 2 orders for day 5 since we are limited to our production capacity, for a total of 3 orders filled. For the third question, we are able to fill 1 order on day 1, 1 order on day 2, and 2 orders on day 5, for a total of 4 orders. Submitted Solution: ``` n, k, a, b, q = map(int, input().split()) g1 = [0] * (n + 1) g2 = [0] * (n + 1) p = [] for i in range(q): s = input().split() if len(s) == 3: h, d = int(s[1]), int(s[2]) g1[h] += d g2[h] += d else: p.append(int(s[1])) sum = 0 for i in range(n + 1): sum += min(g1[i], b) g1[i] = sum sum = 0 for i in range(n + 1): sum += min(g2[i], a) g2[i] = sum for i in range(len(p)): sum1 = g1[p[i] - 1] - g1[0] sum2 = g2[-1] - g2[p[i] + k - 1] print(sum1 + sum2) ```
instruction
0
86,152
14
172,304
No
output
1
86,152
14
172,305
Provide tags and a correct Python 3 solution for this coding contest problem. Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two potential victims on his first day, selects one of these two, kills selected victim and replaces him with a new person. He repeats this procedure each day. This way, each day he has two potential victims to choose from. Sherlock knows the initial two potential victims. Also, he knows the murder that happened on a particular day and the new person who replaced this victim. You need to help him get all the pairs of potential victims at each day so that Sherlock can observe some pattern. Input First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer n (1 ≀ n ≀ 1000), the number of days. Next n lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second being the one who replaced that person. The input format is consistent, that is, a person murdered is guaranteed to be from the two potential victims at that time. Also, all the names are guaranteed to be distinct and consists of lowercase English letters. Output Output n + 1 lines, the i-th line should contain the two persons from which the killer selects for the i-th murder. The (n + 1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order. Examples Input ross rachel 4 ross joey rachel phoebe phoebe monica monica chandler Output ross rachel joey rachel joey phoebe joey monica joey chandler Input icm codeforces 1 codeforces technex Output icm codeforces icm technex Note In first example, the killer starts with ross and rachel. * After day 1, ross is killed and joey appears. * After day 2, rachel is killed and phoebe appears. * After day 3, phoebe is killed and monica appears. * After day 4, monica is killed and chandler appears.
instruction
0
86,177
14
172,354
Tags: brute force, implementation, strings Correct Solution: ``` #-------------Program-------------- #----Kuzlyaev-Nikita-Codeforces---- #-------------Training------------- #---------------------------------- n1,n2=map(str,input().split()) n=int(input()) for i in range(n): v,f=map(str,input().split()) print(n1,n2) if v==n1: n1=f else: n2=f print(n1,n2) ```
output
1
86,177
14
172,355
Provide tags and a correct Python 3 solution for this coding contest problem. Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two potential victims on his first day, selects one of these two, kills selected victim and replaces him with a new person. He repeats this procedure each day. This way, each day he has two potential victims to choose from. Sherlock knows the initial two potential victims. Also, he knows the murder that happened on a particular day and the new person who replaced this victim. You need to help him get all the pairs of potential victims at each day so that Sherlock can observe some pattern. Input First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer n (1 ≀ n ≀ 1000), the number of days. Next n lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second being the one who replaced that person. The input format is consistent, that is, a person murdered is guaranteed to be from the two potential victims at that time. Also, all the names are guaranteed to be distinct and consists of lowercase English letters. Output Output n + 1 lines, the i-th line should contain the two persons from which the killer selects for the i-th murder. The (n + 1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order. Examples Input ross rachel 4 ross joey rachel phoebe phoebe monica monica chandler Output ross rachel joey rachel joey phoebe joey monica joey chandler Input icm codeforces 1 codeforces technex Output icm codeforces icm technex Note In first example, the killer starts with ross and rachel. * After day 1, ross is killed and joey appears. * After day 2, rachel is killed and phoebe appears. * After day 3, phoebe is killed and monica appears. * After day 4, monica is killed and chandler appears.
instruction
0
86,178
14
172,356
Tags: brute force, implementation, strings Correct Solution: ``` line=input() print(line) now = line.split() n=int(input()) for i in range(n): inp=input().strip() line=inp.split() for i in range(len(now)): if now[i]==line[0]: now[i]=line[1] for x in now: print(x,end=' ') print() ```
output
1
86,178
14
172,357
Provide tags and a correct Python 3 solution for this coding contest problem. Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two potential victims on his first day, selects one of these two, kills selected victim and replaces him with a new person. He repeats this procedure each day. This way, each day he has two potential victims to choose from. Sherlock knows the initial two potential victims. Also, he knows the murder that happened on a particular day and the new person who replaced this victim. You need to help him get all the pairs of potential victims at each day so that Sherlock can observe some pattern. Input First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer n (1 ≀ n ≀ 1000), the number of days. Next n lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second being the one who replaced that person. The input format is consistent, that is, a person murdered is guaranteed to be from the two potential victims at that time. Also, all the names are guaranteed to be distinct and consists of lowercase English letters. Output Output n + 1 lines, the i-th line should contain the two persons from which the killer selects for the i-th murder. The (n + 1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order. Examples Input ross rachel 4 ross joey rachel phoebe phoebe monica monica chandler Output ross rachel joey rachel joey phoebe joey monica joey chandler Input icm codeforces 1 codeforces technex Output icm codeforces icm technex Note In first example, the killer starts with ross and rachel. * After day 1, ross is killed and joey appears. * After day 2, rachel is killed and phoebe appears. * After day 3, phoebe is killed and monica appears. * After day 4, monica is killed and chandler appears.
instruction
0
86,179
14
172,358
Tags: brute force, implementation, strings Correct Solution: ``` import math, sys def main(): first, second = input().split() n = int(input()) for i in range(n): print(first, second) kill, zher = input().split() if first == kill: first = zher if second == kill: second = zher print(first, second) if __name__=="__main__": main() ```
output
1
86,179
14
172,359
Provide tags and a correct Python 3 solution for this coding contest problem. Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two potential victims on his first day, selects one of these two, kills selected victim and replaces him with a new person. He repeats this procedure each day. This way, each day he has two potential victims to choose from. Sherlock knows the initial two potential victims. Also, he knows the murder that happened on a particular day and the new person who replaced this victim. You need to help him get all the pairs of potential victims at each day so that Sherlock can observe some pattern. Input First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer n (1 ≀ n ≀ 1000), the number of days. Next n lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second being the one who replaced that person. The input format is consistent, that is, a person murdered is guaranteed to be from the two potential victims at that time. Also, all the names are guaranteed to be distinct and consists of lowercase English letters. Output Output n + 1 lines, the i-th line should contain the two persons from which the killer selects for the i-th murder. The (n + 1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order. Examples Input ross rachel 4 ross joey rachel phoebe phoebe monica monica chandler Output ross rachel joey rachel joey phoebe joey monica joey chandler Input icm codeforces 1 codeforces technex Output icm codeforces icm technex Note In first example, the killer starts with ross and rachel. * After day 1, ross is killed and joey appears. * After day 2, rachel is killed and phoebe appears. * After day 3, phoebe is killed and monica appears. * After day 4, monica is killed and chandler appears.
instruction
0
86,180
14
172,360
Tags: brute force, implementation, strings Correct Solution: ``` a, b = map(str, input().split()) print(a, b, sep=' ') n = int(input()) for i in range(n): c, d = map(str, input().split()) if c == a: a = d if c == b: b = d print(a, b, sep=' ') # CodeForcesian # β™₯ # Ψ²Ψ¨Ω„ ```
output
1
86,180
14
172,361
Provide tags and a correct Python 3 solution for this coding contest problem. Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two potential victims on his first day, selects one of these two, kills selected victim and replaces him with a new person. He repeats this procedure each day. This way, each day he has two potential victims to choose from. Sherlock knows the initial two potential victims. Also, he knows the murder that happened on a particular day and the new person who replaced this victim. You need to help him get all the pairs of potential victims at each day so that Sherlock can observe some pattern. Input First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer n (1 ≀ n ≀ 1000), the number of days. Next n lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second being the one who replaced that person. The input format is consistent, that is, a person murdered is guaranteed to be from the two potential victims at that time. Also, all the names are guaranteed to be distinct and consists of lowercase English letters. Output Output n + 1 lines, the i-th line should contain the two persons from which the killer selects for the i-th murder. The (n + 1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order. Examples Input ross rachel 4 ross joey rachel phoebe phoebe monica monica chandler Output ross rachel joey rachel joey phoebe joey monica joey chandler Input icm codeforces 1 codeforces technex Output icm codeforces icm technex Note In first example, the killer starts with ross and rachel. * After day 1, ross is killed and joey appears. * After day 2, rachel is killed and phoebe appears. * After day 3, phoebe is killed and monica appears. * After day 4, monica is killed and chandler appears.
instruction
0
86,181
14
172,362
Tags: brute force, implementation, strings Correct Solution: ``` def main(): n1, n2 = input().split() print(n1, n2) names = {n1, n2} k = int(input()) for i in range(k): killed, new = input().split() names.remove(killed) names.add(new) for name in names: print(name, end=' ') print() if __name__ == '__main__': main() ```
output
1
86,181
14
172,363
Provide tags and a correct Python 3 solution for this coding contest problem. Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two potential victims on his first day, selects one of these two, kills selected victim and replaces him with a new person. He repeats this procedure each day. This way, each day he has two potential victims to choose from. Sherlock knows the initial two potential victims. Also, he knows the murder that happened on a particular day and the new person who replaced this victim. You need to help him get all the pairs of potential victims at each day so that Sherlock can observe some pattern. Input First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer n (1 ≀ n ≀ 1000), the number of days. Next n lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second being the one who replaced that person. The input format is consistent, that is, a person murdered is guaranteed to be from the two potential victims at that time. Also, all the names are guaranteed to be distinct and consists of lowercase English letters. Output Output n + 1 lines, the i-th line should contain the two persons from which the killer selects for the i-th murder. The (n + 1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order. Examples Input ross rachel 4 ross joey rachel phoebe phoebe monica monica chandler Output ross rachel joey rachel joey phoebe joey monica joey chandler Input icm codeforces 1 codeforces technex Output icm codeforces icm technex Note In first example, the killer starts with ross and rachel. * After day 1, ross is killed and joey appears. * After day 2, rachel is killed and phoebe appears. * After day 3, phoebe is killed and monica appears. * After day 4, monica is killed and chandler appears.
instruction
0
86,182
14
172,364
Tags: brute force, implementation, strings Correct Solution: ``` s = input().split() print(' '.join(s)) n = int(input()) for i in range(n): n1, n2 = input().split() s[s.index(n1)] = n2 print(' '.join(s)) ```
output
1
86,182
14
172,365
Provide tags and a correct Python 3 solution for this coding contest problem. Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two potential victims on his first day, selects one of these two, kills selected victim and replaces him with a new person. He repeats this procedure each day. This way, each day he has two potential victims to choose from. Sherlock knows the initial two potential victims. Also, he knows the murder that happened on a particular day and the new person who replaced this victim. You need to help him get all the pairs of potential victims at each day so that Sherlock can observe some pattern. Input First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer n (1 ≀ n ≀ 1000), the number of days. Next n lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second being the one who replaced that person. The input format is consistent, that is, a person murdered is guaranteed to be from the two potential victims at that time. Also, all the names are guaranteed to be distinct and consists of lowercase English letters. Output Output n + 1 lines, the i-th line should contain the two persons from which the killer selects for the i-th murder. The (n + 1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order. Examples Input ross rachel 4 ross joey rachel phoebe phoebe monica monica chandler Output ross rachel joey rachel joey phoebe joey monica joey chandler Input icm codeforces 1 codeforces technex Output icm codeforces icm technex Note In first example, the killer starts with ross and rachel. * After day 1, ross is killed and joey appears. * After day 2, rachel is killed and phoebe appears. * After day 3, phoebe is killed and monica appears. * After day 4, monica is killed and chandler appears.
instruction
0
86,183
14
172,366
Tags: brute force, implementation, strings Correct Solution: ``` (a, b) = input().split() n = int(input()) print(a, b) for i in range(n): (a1, a2) = input().split() if a == a1: a = a2 elif b == a1: b = a2 elif a == a2: a = a1 elif b == a2: b = a1 print(a, b) ```
output
1
86,183
14
172,367
Provide tags and a correct Python 3 solution for this coding contest problem. Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two potential victims on his first day, selects one of these two, kills selected victim and replaces him with a new person. He repeats this procedure each day. This way, each day he has two potential victims to choose from. Sherlock knows the initial two potential victims. Also, he knows the murder that happened on a particular day and the new person who replaced this victim. You need to help him get all the pairs of potential victims at each day so that Sherlock can observe some pattern. Input First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer n (1 ≀ n ≀ 1000), the number of days. Next n lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second being the one who replaced that person. The input format is consistent, that is, a person murdered is guaranteed to be from the two potential victims at that time. Also, all the names are guaranteed to be distinct and consists of lowercase English letters. Output Output n + 1 lines, the i-th line should contain the two persons from which the killer selects for the i-th murder. The (n + 1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order. Examples Input ross rachel 4 ross joey rachel phoebe phoebe monica monica chandler Output ross rachel joey rachel joey phoebe joey monica joey chandler Input icm codeforces 1 codeforces technex Output icm codeforces icm technex Note In first example, the killer starts with ross and rachel. * After day 1, ross is killed and joey appears. * After day 2, rachel is killed and phoebe appears. * After day 3, phoebe is killed and monica appears. * After day 4, monica is killed and chandler appears.
instruction
0
86,184
14
172,368
Tags: brute force, implementation, strings Correct Solution: ``` potential_victim_1, potential_victim_2 = input().split() print(potential_victim_1, potential_victim_2) n = int(input()) for i in range(n): victim, next_potential_victim = input().split() if potential_victim_1 == victim: print(potential_victim_2, next_potential_victim) potential_victim_1 = next_potential_victim else: print(potential_victim_1, next_potential_victim) potential_victim_2 = next_potential_victim ```
output
1
86,184
14
172,369
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two potential victims on his first day, selects one of these two, kills selected victim and replaces him with a new person. He repeats this procedure each day. This way, each day he has two potential victims to choose from. Sherlock knows the initial two potential victims. Also, he knows the murder that happened on a particular day and the new person who replaced this victim. You need to help him get all the pairs of potential victims at each day so that Sherlock can observe some pattern. Input First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer n (1 ≀ n ≀ 1000), the number of days. Next n lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second being the one who replaced that person. The input format is consistent, that is, a person murdered is guaranteed to be from the two potential victims at that time. Also, all the names are guaranteed to be distinct and consists of lowercase English letters. Output Output n + 1 lines, the i-th line should contain the two persons from which the killer selects for the i-th murder. The (n + 1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order. Examples Input ross rachel 4 ross joey rachel phoebe phoebe monica monica chandler Output ross rachel joey rachel joey phoebe joey monica joey chandler Input icm codeforces 1 codeforces technex Output icm codeforces icm technex Note In first example, the killer starts with ross and rachel. * After day 1, ross is killed and joey appears. * After day 2, rachel is killed and phoebe appears. * After day 3, phoebe is killed and monica appears. * After day 4, monica is killed and chandler appears. Submitted Solution: ``` a, b = input().split() n = int(input()) print(a, b) for _ in range(n): old, new = input().split() if old == a: a = new else: b = new print(a, b) ```
instruction
0
86,185
14
172,370
Yes
output
1
86,185
14
172,371
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two potential victims on his first day, selects one of these two, kills selected victim and replaces him with a new person. He repeats this procedure each day. This way, each day he has two potential victims to choose from. Sherlock knows the initial two potential victims. Also, he knows the murder that happened on a particular day and the new person who replaced this victim. You need to help him get all the pairs of potential victims at each day so that Sherlock can observe some pattern. Input First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer n (1 ≀ n ≀ 1000), the number of days. Next n lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second being the one who replaced that person. The input format is consistent, that is, a person murdered is guaranteed to be from the two potential victims at that time. Also, all the names are guaranteed to be distinct and consists of lowercase English letters. Output Output n + 1 lines, the i-th line should contain the two persons from which the killer selects for the i-th murder. The (n + 1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order. Examples Input ross rachel 4 ross joey rachel phoebe phoebe monica monica chandler Output ross rachel joey rachel joey phoebe joey monica joey chandler Input icm codeforces 1 codeforces technex Output icm codeforces icm technex Note In first example, the killer starts with ross and rachel. * After day 1, ross is killed and joey appears. * After day 2, rachel is killed and phoebe appears. * After day 3, phoebe is killed and monica appears. * After day 4, monica is killed and chandler appears. Submitted Solution: ``` ans=[list(input().split())] n=int(input()) for _ in range(n): x,y=input().split() xo,yo=ans[-1][0],ans[-1][1] if xo==x: ans+=[[y,yo]] else: ans+=[[xo,y]] for i in range(n+1): ans[i]=' '.join(ans[i]) print('\n'.join(ans)) ```
instruction
0
86,186
14
172,372
Yes
output
1
86,186
14
172,373
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two potential victims on his first day, selects one of these two, kills selected victim and replaces him with a new person. He repeats this procedure each day. This way, each day he has two potential victims to choose from. Sherlock knows the initial two potential victims. Also, he knows the murder that happened on a particular day and the new person who replaced this victim. You need to help him get all the pairs of potential victims at each day so that Sherlock can observe some pattern. Input First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer n (1 ≀ n ≀ 1000), the number of days. Next n lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second being the one who replaced that person. The input format is consistent, that is, a person murdered is guaranteed to be from the two potential victims at that time. Also, all the names are guaranteed to be distinct and consists of lowercase English letters. Output Output n + 1 lines, the i-th line should contain the two persons from which the killer selects for the i-th murder. The (n + 1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order. Examples Input ross rachel 4 ross joey rachel phoebe phoebe monica monica chandler Output ross rachel joey rachel joey phoebe joey monica joey chandler Input icm codeforces 1 codeforces technex Output icm codeforces icm technex Note In first example, the killer starts with ross and rachel. * After day 1, ross is killed and joey appears. * After day 2, rachel is killed and phoebe appears. * After day 3, phoebe is killed and monica appears. * After day 4, monica is killed and chandler appears. Submitted Solution: ``` s1, s2 = list(map(str, input().split())) l = [] l += [s1, s2] n = int(input()) for i in range(n): s3, s4 = list(map(str, input().split())) if s1 == s3: s1 = s4 else: s2 = s4 l += [s1, s2] for i in range(2 * n + 2): if i % 2 == 0: print(l[i], l[i + 1]) ```
instruction
0
86,187
14
172,374
Yes
output
1
86,187
14
172,375
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two potential victims on his first day, selects one of these two, kills selected victim and replaces him with a new person. He repeats this procedure each day. This way, each day he has two potential victims to choose from. Sherlock knows the initial two potential victims. Also, he knows the murder that happened on a particular day and the new person who replaced this victim. You need to help him get all the pairs of potential victims at each day so that Sherlock can observe some pattern. Input First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer n (1 ≀ n ≀ 1000), the number of days. Next n lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second being the one who replaced that person. The input format is consistent, that is, a person murdered is guaranteed to be from the two potential victims at that time. Also, all the names are guaranteed to be distinct and consists of lowercase English letters. Output Output n + 1 lines, the i-th line should contain the two persons from which the killer selects for the i-th murder. The (n + 1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order. Examples Input ross rachel 4 ross joey rachel phoebe phoebe monica monica chandler Output ross rachel joey rachel joey phoebe joey monica joey chandler Input icm codeforces 1 codeforces technex Output icm codeforces icm technex Note In first example, the killer starts with ross and rachel. * After day 1, ross is killed and joey appears. * After day 2, rachel is killed and phoebe appears. * After day 3, phoebe is killed and monica appears. * After day 4, monica is killed and chandler appears. Submitted Solution: ``` t,v = input().split(' ') n=int(input()) i=0 l = [] l1= [] l1.append(t) l1.append(v) l.append(l1) while(i<n): k1,k2 = input().split(' ') l1=[] if(t==k1): l1.append(k2) l1.append(v) l.append(l1) t=v v=k2 if(v==k1): l1.append(k2) l1.append(t) l.append(l1) t=t v=k2 i=i+1 for i in l: print(i[0],i[1]) ```
instruction
0
86,188
14
172,376
Yes
output
1
86,188
14
172,377
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two potential victims on his first day, selects one of these two, kills selected victim and replaces him with a new person. He repeats this procedure each day. This way, each day he has two potential victims to choose from. Sherlock knows the initial two potential victims. Also, he knows the murder that happened on a particular day and the new person who replaced this victim. You need to help him get all the pairs of potential victims at each day so that Sherlock can observe some pattern. Input First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer n (1 ≀ n ≀ 1000), the number of days. Next n lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second being the one who replaced that person. The input format is consistent, that is, a person murdered is guaranteed to be from the two potential victims at that time. Also, all the names are guaranteed to be distinct and consists of lowercase English letters. Output Output n + 1 lines, the i-th line should contain the two persons from which the killer selects for the i-th murder. The (n + 1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order. Examples Input ross rachel 4 ross joey rachel phoebe phoebe monica monica chandler Output ross rachel joey rachel joey phoebe joey monica joey chandler Input icm codeforces 1 codeforces technex Output icm codeforces icm technex Note In first example, the killer starts with ross and rachel. * After day 1, ross is killed and joey appears. * After day 2, rachel is killed and phoebe appears. * After day 3, phoebe is killed and monica appears. * After day 4, monica is killed and chandler appears. Submitted Solution: ``` s = input() n = int(input()) print(s) for i in range(n): n1, n2 = input().split() if n1 in s: s = s.replace(n1, n2) else: s = s.replace(n2, n1) print(s) ```
instruction
0
86,189
14
172,378
No
output
1
86,189
14
172,379
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two potential victims on his first day, selects one of these two, kills selected victim and replaces him with a new person. He repeats this procedure each day. This way, each day he has two potential victims to choose from. Sherlock knows the initial two potential victims. Also, he knows the murder that happened on a particular day and the new person who replaced this victim. You need to help him get all the pairs of potential victims at each day so that Sherlock can observe some pattern. Input First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer n (1 ≀ n ≀ 1000), the number of days. Next n lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second being the one who replaced that person. The input format is consistent, that is, a person murdered is guaranteed to be from the two potential victims at that time. Also, all the names are guaranteed to be distinct and consists of lowercase English letters. Output Output n + 1 lines, the i-th line should contain the two persons from which the killer selects for the i-th murder. The (n + 1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order. Examples Input ross rachel 4 ross joey rachel phoebe phoebe monica monica chandler Output ross rachel joey rachel joey phoebe joey monica joey chandler Input icm codeforces 1 codeforces technex Output icm codeforces icm technex Note In first example, the killer starts with ross and rachel. * After day 1, ross is killed and joey appears. * After day 2, rachel is killed and phoebe appears. * After day 3, phoebe is killed and monica appears. * After day 4, monica is killed and chandler appears. Submitted Solution: ``` s=input() l=[s] n=int(input()) for i in range(n): x,y=map(str,input().split()) if(x in s): s=s.replace(x,y) l.append(s) for i in l: print(i) ```
instruction
0
86,190
14
172,380
No
output
1
86,190
14
172,381
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two potential victims on his first day, selects one of these two, kills selected victim and replaces him with a new person. He repeats this procedure each day. This way, each day he has two potential victims to choose from. Sherlock knows the initial two potential victims. Also, he knows the murder that happened on a particular day and the new person who replaced this victim. You need to help him get all the pairs of potential victims at each day so that Sherlock can observe some pattern. Input First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer n (1 ≀ n ≀ 1000), the number of days. Next n lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second being the one who replaced that person. The input format is consistent, that is, a person murdered is guaranteed to be from the two potential victims at that time. Also, all the names are guaranteed to be distinct and consists of lowercase English letters. Output Output n + 1 lines, the i-th line should contain the two persons from which the killer selects for the i-th murder. The (n + 1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order. Examples Input ross rachel 4 ross joey rachel phoebe phoebe monica monica chandler Output ross rachel joey rachel joey phoebe joey monica joey chandler Input icm codeforces 1 codeforces technex Output icm codeforces icm technex Note In first example, the killer starts with ross and rachel. * After day 1, ross is killed and joey appears. * After day 2, rachel is killed and phoebe appears. * After day 3, phoebe is killed and monica appears. * After day 4, monica is killed and chandler appears. Submitted Solution: ``` a=input().split() n=int(input()) print(*a) for _ in range(n): b=input().split() a.remove(b[0]) a.append(b[1]) print(*b) ```
instruction
0
86,191
14
172,382
No
output
1
86,191
14
172,383
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two potential victims on his first day, selects one of these two, kills selected victim and replaces him with a new person. He repeats this procedure each day. This way, each day he has two potential victims to choose from. Sherlock knows the initial two potential victims. Also, he knows the murder that happened on a particular day and the new person who replaced this victim. You need to help him get all the pairs of potential victims at each day so that Sherlock can observe some pattern. Input First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer n (1 ≀ n ≀ 1000), the number of days. Next n lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second being the one who replaced that person. The input format is consistent, that is, a person murdered is guaranteed to be from the two potential victims at that time. Also, all the names are guaranteed to be distinct and consists of lowercase English letters. Output Output n + 1 lines, the i-th line should contain the two persons from which the killer selects for the i-th murder. The (n + 1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order. Examples Input ross rachel 4 ross joey rachel phoebe phoebe monica monica chandler Output ross rachel joey rachel joey phoebe joey monica joey chandler Input icm codeforces 1 codeforces technex Output icm codeforces icm technex Note In first example, the killer starts with ross and rachel. * After day 1, ross is killed and joey appears. * After day 2, rachel is killed and phoebe appears. * After day 3, phoebe is killed and monica appears. * After day 4, monica is killed and chandler appears. Submitted Solution: ``` p=list(input().split(" ")) n=int(input().strip()) final=[] for i in range(n): p1=list(input().split()) final.append(p1) print(p) for i in final: p.remove(i[0]) p.append(i[1]) print(p) ```
instruction
0
86,192
14
172,384
No
output
1
86,192
14
172,385
Provide tags and a correct Python 3 solution for this coding contest problem. Luba thinks about watering her garden. The garden can be represented as a segment of length k. Luba has got n buckets, the i-th bucket allows her to water some continuous subsegment of garden of length exactly ai each hour. Luba can't water any parts of the garden that were already watered, also she can't water the ground outside the garden. Luba has to choose one of the buckets in order to water the garden as fast as possible (as mentioned above, each hour she will water some continuous subsegment of length ai if she chooses the i-th bucket). Help her to determine the minimum number of hours she has to spend watering the garden. It is guaranteed that Luba can always choose a bucket so it is possible water the garden. See the examples for better understanding. Input The first line of input contains two integer numbers n and k (1 ≀ n, k ≀ 100) β€” the number of buckets and the length of the garden, respectively. The second line of input contains n integer numbers ai (1 ≀ ai ≀ 100) β€” the length of the segment that can be watered by the i-th bucket in one hour. It is guaranteed that there is at least one bucket such that it is possible to water the garden in integer number of hours using only this bucket. Output Print one integer number β€” the minimum number of hours required to water the garden. Examples Input 3 6 2 3 5 Output 2 Input 6 7 1 2 3 4 5 6 Output 7 Note In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden. In the second test we can choose only the bucket that allows us to water the segment of length 1.
instruction
0
86,247
14
172,494
Tags: implementation Correct Solution: ``` n,k=list(map(int,input().split())) t=list(map(int,input().split())) s=[] for i in range(len(t)): if k%t[i]==0: p=k//t[i] s.append(p) print(min(s)) ```
output
1
86,247
14
172,495
Provide tags and a correct Python 3 solution for this coding contest problem. Luba thinks about watering her garden. The garden can be represented as a segment of length k. Luba has got n buckets, the i-th bucket allows her to water some continuous subsegment of garden of length exactly ai each hour. Luba can't water any parts of the garden that were already watered, also she can't water the ground outside the garden. Luba has to choose one of the buckets in order to water the garden as fast as possible (as mentioned above, each hour she will water some continuous subsegment of length ai if she chooses the i-th bucket). Help her to determine the minimum number of hours she has to spend watering the garden. It is guaranteed that Luba can always choose a bucket so it is possible water the garden. See the examples for better understanding. Input The first line of input contains two integer numbers n and k (1 ≀ n, k ≀ 100) β€” the number of buckets and the length of the garden, respectively. The second line of input contains n integer numbers ai (1 ≀ ai ≀ 100) β€” the length of the segment that can be watered by the i-th bucket in one hour. It is guaranteed that there is at least one bucket such that it is possible to water the garden in integer number of hours using only this bucket. Output Print one integer number β€” the minimum number of hours required to water the garden. Examples Input 3 6 2 3 5 Output 2 Input 6 7 1 2 3 4 5 6 Output 7 Note In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden. In the second test we can choose only the bucket that allows us to water the segment of length 1.
instruction
0
86,249
14
172,498
Tags: implementation Correct Solution: ``` N,K = map(int,input().split()) src = list(map(int,input().split())) for a in reversed(sorted(src)): if a > K: continue if K%a == 0: print(K//a) exit() ```
output
1
86,249
14
172,499
Provide tags and a correct Python 3 solution for this coding contest problem. Luba thinks about watering her garden. The garden can be represented as a segment of length k. Luba has got n buckets, the i-th bucket allows her to water some continuous subsegment of garden of length exactly ai each hour. Luba can't water any parts of the garden that were already watered, also she can't water the ground outside the garden. Luba has to choose one of the buckets in order to water the garden as fast as possible (as mentioned above, each hour she will water some continuous subsegment of length ai if she chooses the i-th bucket). Help her to determine the minimum number of hours she has to spend watering the garden. It is guaranteed that Luba can always choose a bucket so it is possible water the garden. See the examples for better understanding. Input The first line of input contains two integer numbers n and k (1 ≀ n, k ≀ 100) β€” the number of buckets and the length of the garden, respectively. The second line of input contains n integer numbers ai (1 ≀ ai ≀ 100) β€” the length of the segment that can be watered by the i-th bucket in one hour. It is guaranteed that there is at least one bucket such that it is possible to water the garden in integer number of hours using only this bucket. Output Print one integer number β€” the minimum number of hours required to water the garden. Examples Input 3 6 2 3 5 Output 2 Input 6 7 1 2 3 4 5 6 Output 7 Note In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden. In the second test we can choose only the bucket that allows us to water the segment of length 1.
instruction
0
86,250
14
172,500
Tags: implementation Correct Solution: ``` n,k=tuple(map(int,input().split())) a=list(map(int,input().split())) a.sort() a.reverse() for i in a: if k%i==0: print(k//i) break ```
output
1
86,250
14
172,501
Provide tags and a correct Python 3 solution for this coding contest problem. Luba thinks about watering her garden. The garden can be represented as a segment of length k. Luba has got n buckets, the i-th bucket allows her to water some continuous subsegment of garden of length exactly ai each hour. Luba can't water any parts of the garden that were already watered, also she can't water the ground outside the garden. Luba has to choose one of the buckets in order to water the garden as fast as possible (as mentioned above, each hour she will water some continuous subsegment of length ai if she chooses the i-th bucket). Help her to determine the minimum number of hours she has to spend watering the garden. It is guaranteed that Luba can always choose a bucket so it is possible water the garden. See the examples for better understanding. Input The first line of input contains two integer numbers n and k (1 ≀ n, k ≀ 100) β€” the number of buckets and the length of the garden, respectively. The second line of input contains n integer numbers ai (1 ≀ ai ≀ 100) β€” the length of the segment that can be watered by the i-th bucket in one hour. It is guaranteed that there is at least one bucket such that it is possible to water the garden in integer number of hours using only this bucket. Output Print one integer number β€” the minimum number of hours required to water the garden. Examples Input 3 6 2 3 5 Output 2 Input 6 7 1 2 3 4 5 6 Output 7 Note In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden. In the second test we can choose only the bucket that allows us to water the segment of length 1.
instruction
0
86,251
14
172,502
Tags: implementation Correct Solution: ``` n,k = map(int, input().split()) b = list(map(int,input().split())) a = [] for i in range(n): if (k/b[i]).is_integer(): a.append(k/b[i]) a = sorted(a) print(int(a[0])) ```
output
1
86,251
14
172,503