message
stringlengths
2
30.5k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
237
109k
cluster
float64
10
10
__index_level_0__
int64
474
217k
Provide tags and a correct Python 3 solution for this coding contest problem. Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online. The store contains k items. n customers have already used the above service. Each user paid for m items. Let aij denote the j-th item in the i-th person's order. Due to the space limitations all the items are arranged in one single row. When Ayush receives the i-th order he will find one by one all the items aij (1 ≀ j ≀ m) in the row. Let pos(x) denote the position of the item x in the row at the moment of its collection. Then Ayush takes time equal to pos(ai1) + pos(ai2) + ... + pos(aim) for the i-th customer. When Ayush accesses the x-th element he keeps a new stock in the front of the row and takes away the x-th element. Thus the values are updating. Your task is to calculate the total time it takes for Ayush to process all the orders. You can assume that the market has endless stock. Input The first line contains three integers n, m and k (1 ≀ n, k ≀ 100, 1 ≀ m ≀ k) β€” the number of users, the number of items each user wants to buy and the total number of items at the market. The next line contains k distinct integers pl (1 ≀ pl ≀ k) denoting the initial positions of the items in the store. The items are numbered with integers from 1 to k. Each of the next n lines contains m distinct integers aij (1 ≀ aij ≀ k) β€” the order of the i-th person. Output Print the only integer t β€” the total time needed for Ayush to process all the orders. Example Input 2 2 5 3 4 1 2 5 1 5 3 1 Output 14 Note Customer 1 wants the items 1 and 5. pos(1) = 3, so the new positions are: [1, 3, 4, 2, 5]. pos(5) = 5, so the new positions are: [5, 1, 3, 4, 2]. Time taken for the first customer is 3 + 5 = 8. Customer 2 wants the items 3 and 1. pos(3) = 3, so the new positions are: [3, 5, 1, 4, 2]. pos(1) = 3, so the new positions are: [1, 3, 5, 4, 2]. Time taken for the second customer is 3 + 3 = 6. Total time is 8 + 6 = 14. Formally pos(x) is the index of x in the current row.
instruction
0
49,290
10
98,580
Tags: brute force Correct Solution: ``` n, m, k = map(int, input().split()) queue = list(map(int, input().split())) mass = [] for i in range(n): mass += list(map(int, input().split())) count = 0 for elem in mass: c = queue.index(elem) count += c + 1 queue.pop(c) queue.insert(0, elem) print(count) ```
output
1
49,290
10
98,581
Provide tags and a correct Python 3 solution for this coding contest problem. Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online. The store contains k items. n customers have already used the above service. Each user paid for m items. Let aij denote the j-th item in the i-th person's order. Due to the space limitations all the items are arranged in one single row. When Ayush receives the i-th order he will find one by one all the items aij (1 ≀ j ≀ m) in the row. Let pos(x) denote the position of the item x in the row at the moment of its collection. Then Ayush takes time equal to pos(ai1) + pos(ai2) + ... + pos(aim) for the i-th customer. When Ayush accesses the x-th element he keeps a new stock in the front of the row and takes away the x-th element. Thus the values are updating. Your task is to calculate the total time it takes for Ayush to process all the orders. You can assume that the market has endless stock. Input The first line contains three integers n, m and k (1 ≀ n, k ≀ 100, 1 ≀ m ≀ k) β€” the number of users, the number of items each user wants to buy and the total number of items at the market. The next line contains k distinct integers pl (1 ≀ pl ≀ k) denoting the initial positions of the items in the store. The items are numbered with integers from 1 to k. Each of the next n lines contains m distinct integers aij (1 ≀ aij ≀ k) β€” the order of the i-th person. Output Print the only integer t β€” the total time needed for Ayush to process all the orders. Example Input 2 2 5 3 4 1 2 5 1 5 3 1 Output 14 Note Customer 1 wants the items 1 and 5. pos(1) = 3, so the new positions are: [1, 3, 4, 2, 5]. pos(5) = 5, so the new positions are: [5, 1, 3, 4, 2]. Time taken for the first customer is 3 + 5 = 8. Customer 2 wants the items 3 and 1. pos(3) = 3, so the new positions are: [3, 5, 1, 4, 2]. pos(1) = 3, so the new positions are: [1, 3, 5, 4, 2]. Time taken for the second customer is 3 + 3 = 6. Total time is 8 + 6 = 14. Formally pos(x) is the index of x in the current row.
instruction
0
49,291
10
98,582
Tags: brute force Correct Solution: ``` # -*- coding: utf-8 -*- """ Created on Wed Apr 20 21:02:31 2016 @author: Kirill """ n, m, k = map(int, input().split()) order = list(map(int, input().split())) items = [] for i in range(n): items.append(list(map(int, input().split()))) ans = 0 for i in range(n): for j in range(m): item = order.index(items[i][j]) ans += item + 1 order.insert(0, order.pop(item)) print(ans) ```
output
1
49,291
10
98,583
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online. The store contains k items. n customers have already used the above service. Each user paid for m items. Let aij denote the j-th item in the i-th person's order. Due to the space limitations all the items are arranged in one single row. When Ayush receives the i-th order he will find one by one all the items aij (1 ≀ j ≀ m) in the row. Let pos(x) denote the position of the item x in the row at the moment of its collection. Then Ayush takes time equal to pos(ai1) + pos(ai2) + ... + pos(aim) for the i-th customer. When Ayush accesses the x-th element he keeps a new stock in the front of the row and takes away the x-th element. Thus the values are updating. Your task is to calculate the total time it takes for Ayush to process all the orders. You can assume that the market has endless stock. Input The first line contains three integers n, m and k (1 ≀ n, k ≀ 100, 1 ≀ m ≀ k) β€” the number of users, the number of items each user wants to buy and the total number of items at the market. The next line contains k distinct integers pl (1 ≀ pl ≀ k) denoting the initial positions of the items in the store. The items are numbered with integers from 1 to k. Each of the next n lines contains m distinct integers aij (1 ≀ aij ≀ k) β€” the order of the i-th person. Output Print the only integer t β€” the total time needed for Ayush to process all the orders. Example Input 2 2 5 3 4 1 2 5 1 5 3 1 Output 14 Note Customer 1 wants the items 1 and 5. pos(1) = 3, so the new positions are: [1, 3, 4, 2, 5]. pos(5) = 5, so the new positions are: [5, 1, 3, 4, 2]. Time taken for the first customer is 3 + 5 = 8. Customer 2 wants the items 3 and 1. pos(3) = 3, so the new positions are: [3, 5, 1, 4, 2]. pos(1) = 3, so the new positions are: [1, 3, 5, 4, 2]. Time taken for the second customer is 3 + 3 = 6. Total time is 8 + 6 = 14. Formally pos(x) is the index of x in the current row. Submitted Solution: ``` n, m, k = map(int, input().split()) a = list(map(int, input().split())) ans = 0 for i in range(n): orders = map(int, input().split()) for order in orders: ans += a.index(order) + 1 a.remove(order) a.insert(0, order) print(ans) ```
instruction
0
49,292
10
98,584
Yes
output
1
49,292
10
98,585
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online. The store contains k items. n customers have already used the above service. Each user paid for m items. Let aij denote the j-th item in the i-th person's order. Due to the space limitations all the items are arranged in one single row. When Ayush receives the i-th order he will find one by one all the items aij (1 ≀ j ≀ m) in the row. Let pos(x) denote the position of the item x in the row at the moment of its collection. Then Ayush takes time equal to pos(ai1) + pos(ai2) + ... + pos(aim) for the i-th customer. When Ayush accesses the x-th element he keeps a new stock in the front of the row and takes away the x-th element. Thus the values are updating. Your task is to calculate the total time it takes for Ayush to process all the orders. You can assume that the market has endless stock. Input The first line contains three integers n, m and k (1 ≀ n, k ≀ 100, 1 ≀ m ≀ k) β€” the number of users, the number of items each user wants to buy and the total number of items at the market. The next line contains k distinct integers pl (1 ≀ pl ≀ k) denoting the initial positions of the items in the store. The items are numbered with integers from 1 to k. Each of the next n lines contains m distinct integers aij (1 ≀ aij ≀ k) β€” the order of the i-th person. Output Print the only integer t β€” the total time needed for Ayush to process all the orders. Example Input 2 2 5 3 4 1 2 5 1 5 3 1 Output 14 Note Customer 1 wants the items 1 and 5. pos(1) = 3, so the new positions are: [1, 3, 4, 2, 5]. pos(5) = 5, so the new positions are: [5, 1, 3, 4, 2]. Time taken for the first customer is 3 + 5 = 8. Customer 2 wants the items 3 and 1. pos(3) = 3, so the new positions are: [3, 5, 1, 4, 2]. pos(1) = 3, so the new positions are: [1, 3, 5, 4, 2]. Time taken for the second customer is 3 + 3 = 6. Total time is 8 + 6 = 14. Formally pos(x) is the index of x in the current row. Submitted Solution: ``` n, m, k = map(int, input().split()) l = list(map(int, input().split())) ans = 0 for i in range(n): t = list(map(int, input().split())) for j in range(m): ans += l.index(t[j]) + 1 l.remove(t[j]) l.insert(0, t[j]) print (ans) ```
instruction
0
49,293
10
98,586
Yes
output
1
49,293
10
98,587
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online. The store contains k items. n customers have already used the above service. Each user paid for m items. Let aij denote the j-th item in the i-th person's order. Due to the space limitations all the items are arranged in one single row. When Ayush receives the i-th order he will find one by one all the items aij (1 ≀ j ≀ m) in the row. Let pos(x) denote the position of the item x in the row at the moment of its collection. Then Ayush takes time equal to pos(ai1) + pos(ai2) + ... + pos(aim) for the i-th customer. When Ayush accesses the x-th element he keeps a new stock in the front of the row and takes away the x-th element. Thus the values are updating. Your task is to calculate the total time it takes for Ayush to process all the orders. You can assume that the market has endless stock. Input The first line contains three integers n, m and k (1 ≀ n, k ≀ 100, 1 ≀ m ≀ k) β€” the number of users, the number of items each user wants to buy and the total number of items at the market. The next line contains k distinct integers pl (1 ≀ pl ≀ k) denoting the initial positions of the items in the store. The items are numbered with integers from 1 to k. Each of the next n lines contains m distinct integers aij (1 ≀ aij ≀ k) β€” the order of the i-th person. Output Print the only integer t β€” the total time needed for Ayush to process all the orders. Example Input 2 2 5 3 4 1 2 5 1 5 3 1 Output 14 Note Customer 1 wants the items 1 and 5. pos(1) = 3, so the new positions are: [1, 3, 4, 2, 5]. pos(5) = 5, so the new positions are: [5, 1, 3, 4, 2]. Time taken for the first customer is 3 + 5 = 8. Customer 2 wants the items 3 and 1. pos(3) = 3, so the new positions are: [3, 5, 1, 4, 2]. pos(1) = 3, so the new positions are: [1, 3, 5, 4, 2]. Time taken for the second customer is 3 + 3 = 6. Total time is 8 + 6 = 14. Formally pos(x) is the index of x in the current row. Submitted Solution: ``` n, m, k = map(int, input().split()) A = list(map(int, input().split())) time = 0 for a in range(n): B = list(map(int, input().split())) for i in B: K = [i] time += (A.index(i) + 1) for a in A: if a != i: K.append(a) A = K print(time) ```
instruction
0
49,294
10
98,588
Yes
output
1
49,294
10
98,589
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online. The store contains k items. n customers have already used the above service. Each user paid for m items. Let aij denote the j-th item in the i-th person's order. Due to the space limitations all the items are arranged in one single row. When Ayush receives the i-th order he will find one by one all the items aij (1 ≀ j ≀ m) in the row. Let pos(x) denote the position of the item x in the row at the moment of its collection. Then Ayush takes time equal to pos(ai1) + pos(ai2) + ... + pos(aim) for the i-th customer. When Ayush accesses the x-th element he keeps a new stock in the front of the row and takes away the x-th element. Thus the values are updating. Your task is to calculate the total time it takes for Ayush to process all the orders. You can assume that the market has endless stock. Input The first line contains three integers n, m and k (1 ≀ n, k ≀ 100, 1 ≀ m ≀ k) β€” the number of users, the number of items each user wants to buy and the total number of items at the market. The next line contains k distinct integers pl (1 ≀ pl ≀ k) denoting the initial positions of the items in the store. The items are numbered with integers from 1 to k. Each of the next n lines contains m distinct integers aij (1 ≀ aij ≀ k) β€” the order of the i-th person. Output Print the only integer t β€” the total time needed for Ayush to process all the orders. Example Input 2 2 5 3 4 1 2 5 1 5 3 1 Output 14 Note Customer 1 wants the items 1 and 5. pos(1) = 3, so the new positions are: [1, 3, 4, 2, 5]. pos(5) = 5, so the new positions are: [5, 1, 3, 4, 2]. Time taken for the first customer is 3 + 5 = 8. Customer 2 wants the items 3 and 1. pos(3) = 3, so the new positions are: [3, 5, 1, 4, 2]. pos(1) = 3, so the new positions are: [1, 3, 5, 4, 2]. Time taken for the second customer is 3 + 3 = 6. Total time is 8 + 6 = 14. Formally pos(x) is the index of x in the current row. Submitted Solution: ``` import io, sys, atexit, os import math as ma from sys import exit from decimal import Decimal as dec from itertools import permutations from itertools import combinations def li (): return list (map (int, input ().split ())) def num (): return map (int, input ().split ()) def nu (): return int (input ()) def find_gcd ( x, y ): while (y): x, y = y, x % y return x def lcm ( x, y ): gg = find_gcd (x, y) return (x * y // gg) def printDivisors ( n ): # Note that this loop runs till square root i = 1 cc=0 while i <= ma.sqrt (n): if (n % i == 0): # If divisors are equal, print only one if (n / i == i): cc+=1 else: # Otherwise print both cc+=2 i = i + 1 return cc mm = 1000000007 yp = 0 def solve (): t = 1 for tt in range (t): n,m,k=num() a=li() ff=a ss=0 for i in range(n): b=li() for j in range(m): for ll in range(k): if(b[j]==ff[ll]): ss+=ll+1 ff=[b[j]]+ff[0:ll]+ff[ll+1:] break print(ss) if __name__ == "__main__": solve () ```
instruction
0
49,295
10
98,590
Yes
output
1
49,295
10
98,591
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online. The store contains k items. n customers have already used the above service. Each user paid for m items. Let aij denote the j-th item in the i-th person's order. Due to the space limitations all the items are arranged in one single row. When Ayush receives the i-th order he will find one by one all the items aij (1 ≀ j ≀ m) in the row. Let pos(x) denote the position of the item x in the row at the moment of its collection. Then Ayush takes time equal to pos(ai1) + pos(ai2) + ... + pos(aim) for the i-th customer. When Ayush accesses the x-th element he keeps a new stock in the front of the row and takes away the x-th element. Thus the values are updating. Your task is to calculate the total time it takes for Ayush to process all the orders. You can assume that the market has endless stock. Input The first line contains three integers n, m and k (1 ≀ n, k ≀ 100, 1 ≀ m ≀ k) β€” the number of users, the number of items each user wants to buy and the total number of items at the market. The next line contains k distinct integers pl (1 ≀ pl ≀ k) denoting the initial positions of the items in the store. The items are numbered with integers from 1 to k. Each of the next n lines contains m distinct integers aij (1 ≀ aij ≀ k) β€” the order of the i-th person. Output Print the only integer t β€” the total time needed for Ayush to process all the orders. Example Input 2 2 5 3 4 1 2 5 1 5 3 1 Output 14 Note Customer 1 wants the items 1 and 5. pos(1) = 3, so the new positions are: [1, 3, 4, 2, 5]. pos(5) = 5, so the new positions are: [5, 1, 3, 4, 2]. Time taken for the first customer is 3 + 5 = 8. Customer 2 wants the items 3 and 1. pos(3) = 3, so the new positions are: [3, 5, 1, 4, 2]. pos(1) = 3, so the new positions are: [1, 3, 5, 4, 2]. Time taken for the second customer is 3 + 3 = 6. Total time is 8 + 6 = 14. Formally pos(x) is the index of x in the current row. Submitted Solution: ``` R = lambda : map(int, input().split()) n, m, k = R() val = list(R()) res = 0 for i in range(n): pos = list(R()) for p in pos: res += val[p - 1] val = [p] + [_ for _ in val if _ != p] #print(*val) print(res) ```
instruction
0
49,296
10
98,592
No
output
1
49,296
10
98,593
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online. The store contains k items. n customers have already used the above service. Each user paid for m items. Let aij denote the j-th item in the i-th person's order. Due to the space limitations all the items are arranged in one single row. When Ayush receives the i-th order he will find one by one all the items aij (1 ≀ j ≀ m) in the row. Let pos(x) denote the position of the item x in the row at the moment of its collection. Then Ayush takes time equal to pos(ai1) + pos(ai2) + ... + pos(aim) for the i-th customer. When Ayush accesses the x-th element he keeps a new stock in the front of the row and takes away the x-th element. Thus the values are updating. Your task is to calculate the total time it takes for Ayush to process all the orders. You can assume that the market has endless stock. Input The first line contains three integers n, m and k (1 ≀ n, k ≀ 100, 1 ≀ m ≀ k) β€” the number of users, the number of items each user wants to buy and the total number of items at the market. The next line contains k distinct integers pl (1 ≀ pl ≀ k) denoting the initial positions of the items in the store. The items are numbered with integers from 1 to k. Each of the next n lines contains m distinct integers aij (1 ≀ aij ≀ k) β€” the order of the i-th person. Output Print the only integer t β€” the total time needed for Ayush to process all the orders. Example Input 2 2 5 3 4 1 2 5 1 5 3 1 Output 14 Note Customer 1 wants the items 1 and 5. pos(1) = 3, so the new positions are: [1, 3, 4, 2, 5]. pos(5) = 5, so the new positions are: [5, 1, 3, 4, 2]. Time taken for the first customer is 3 + 5 = 8. Customer 2 wants the items 3 and 1. pos(3) = 3, so the new positions are: [3, 5, 1, 4, 2]. pos(1) = 3, so the new positions are: [1, 3, 5, 4, 2]. Time taken for the second customer is 3 + 3 = 6. Total time is 8 + 6 = 14. Formally pos(x) is the index of x in the current row. Submitted Solution: ``` #!/usr/bin/python3 n, m, k = map(int, input().split()) positionOf = [x-1 for x in map(int, input().split())] sol = 0 for i in range(n): v = [x-1 for x in map(int, input().split())] for x in v: sol += positionOf[x] + 1 for y in range(k): if positionOf[y] < positionOf[x]: positionOf[y] += 1 positionOf[x] = 0 print(sol) ```
instruction
0
49,297
10
98,594
No
output
1
49,297
10
98,595
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online. The store contains k items. n customers have already used the above service. Each user paid for m items. Let aij denote the j-th item in the i-th person's order. Due to the space limitations all the items are arranged in one single row. When Ayush receives the i-th order he will find one by one all the items aij (1 ≀ j ≀ m) in the row. Let pos(x) denote the position of the item x in the row at the moment of its collection. Then Ayush takes time equal to pos(ai1) + pos(ai2) + ... + pos(aim) for the i-th customer. When Ayush accesses the x-th element he keeps a new stock in the front of the row and takes away the x-th element. Thus the values are updating. Your task is to calculate the total time it takes for Ayush to process all the orders. You can assume that the market has endless stock. Input The first line contains three integers n, m and k (1 ≀ n, k ≀ 100, 1 ≀ m ≀ k) β€” the number of users, the number of items each user wants to buy and the total number of items at the market. The next line contains k distinct integers pl (1 ≀ pl ≀ k) denoting the initial positions of the items in the store. The items are numbered with integers from 1 to k. Each of the next n lines contains m distinct integers aij (1 ≀ aij ≀ k) β€” the order of the i-th person. Output Print the only integer t β€” the total time needed for Ayush to process all the orders. Example Input 2 2 5 3 4 1 2 5 1 5 3 1 Output 14 Note Customer 1 wants the items 1 and 5. pos(1) = 3, so the new positions are: [1, 3, 4, 2, 5]. pos(5) = 5, so the new positions are: [5, 1, 3, 4, 2]. Time taken for the first customer is 3 + 5 = 8. Customer 2 wants the items 3 and 1. pos(3) = 3, so the new positions are: [3, 5, 1, 4, 2]. pos(1) = 3, so the new positions are: [1, 3, 5, 4, 2]. Time taken for the second customer is 3 + 3 = 6. Total time is 8 + 6 = 14. Formally pos(x) is the index of x in the current row. Submitted Solution: ``` import io, sys, atexit, os import math as ma from sys import exit from decimal import Decimal as dec from itertools import permutations from itertools import combinations def li (): return list (map (int, input ().split ())) def num (): return map (int, input ().split ()) def nu (): return int (input ()) def find_gcd ( x, y ): while (y): x, y = y, x % y return x def lcm ( x, y ): gg = find_gcd (x, y) return (x * y // gg) def printDivisors ( n ): # Note that this loop runs till square root i = 1 cc=0 while i <= ma.sqrt (n): if (n % i == 0): # If divisors are equal, print only one if (n / i == i): cc+=1 else: # Otherwise print both cc+=2 i = i + 1 return cc mm = 1000000007 yp = 0 def solve (): t = 1 for tt in range (t): n,m,k=num() a=li() ff=[0]*k for i in range(k): ff[a[i]-1]=i ss=0 for i in range(n): b=li() for j in range(m): for ll in range(k): if(b[j]-1==ff[ll]): ss+=ll+1 ff=[b[j]-1]+ff[0:ll]+ff[ll+1:] break print(ss) if __name__ == "__main__": solve () ```
instruction
0
49,298
10
98,596
No
output
1
49,298
10
98,597
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online. The store contains k items. n customers have already used the above service. Each user paid for m items. Let aij denote the j-th item in the i-th person's order. Due to the space limitations all the items are arranged in one single row. When Ayush receives the i-th order he will find one by one all the items aij (1 ≀ j ≀ m) in the row. Let pos(x) denote the position of the item x in the row at the moment of its collection. Then Ayush takes time equal to pos(ai1) + pos(ai2) + ... + pos(aim) for the i-th customer. When Ayush accesses the x-th element he keeps a new stock in the front of the row and takes away the x-th element. Thus the values are updating. Your task is to calculate the total time it takes for Ayush to process all the orders. You can assume that the market has endless stock. Input The first line contains three integers n, m and k (1 ≀ n, k ≀ 100, 1 ≀ m ≀ k) β€” the number of users, the number of items each user wants to buy and the total number of items at the market. The next line contains k distinct integers pl (1 ≀ pl ≀ k) denoting the initial positions of the items in the store. The items are numbered with integers from 1 to k. Each of the next n lines contains m distinct integers aij (1 ≀ aij ≀ k) β€” the order of the i-th person. Output Print the only integer t β€” the total time needed for Ayush to process all the orders. Example Input 2 2 5 3 4 1 2 5 1 5 3 1 Output 14 Note Customer 1 wants the items 1 and 5. pos(1) = 3, so the new positions are: [1, 3, 4, 2, 5]. pos(5) = 5, so the new positions are: [5, 1, 3, 4, 2]. Time taken for the first customer is 3 + 5 = 8. Customer 2 wants the items 3 and 1. pos(3) = 3, so the new positions are: [3, 5, 1, 4, 2]. pos(1) = 3, so the new positions are: [1, 3, 5, 4, 2]. Time taken for the second customer is 3 + 3 = 6. Total time is 8 + 6 = 14. Formally pos(x) is the index of x in the current row. Submitted Solution: ``` # -*- coding: utf-8 -*- """ Created on Wed Apr 20 21:02:31 2016 @author: Kirill """ n, m, k = map(int, input('input n m k:\n').split()) order = list(map(int, input().split())) items = [] for i in range(n): items.append(list(map(int, input().split()))) ans = 0 for i in range(n): for j in range(m): ans += order.index(items[i][j]) + 1 order.insert(0, order.pop(items[i][j] - 1)) print(ans) ```
instruction
0
49,299
10
98,598
No
output
1
49,299
10
98,599
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. The good times at Heidi's library are over. Marmots finally got their internet connections and stopped coming to the library altogether. Not only that, but the bookstore has begun charging extortionate prices for some books. Namely, whereas in the previous versions each book could be bought for 1 CHF, now the price of book i is ci CHF. Input The first line of input will contain two integers n and k (<image>). The second line will contain n integers a1, a2, ..., an (1 ≀ ai ≀ n) – the sequence of book requests. The third line contains n integers c1, c2, ..., cn (0 ≀ ci ≀ 106) – the costs of the books. Output On a single line print the minimum cost of buying books at the store so as to satisfy all requests. Examples Input 4 80 1 2 2 1 1 1 1 1 Output 2 Input 4 1 1 2 2 1 1 1 1 1 Output 3 Input 4 2 1 2 3 1 1 1 1 1 Output 3 Input 7 2 1 2 3 1 1 1 2 1 10 1 0 0 0 0 Output 13 Note The first three sample cases are repeated, but the fourth one is new. In the fourth test case, when buying book 3, Heidi should discard either book 1 or 2. Even though book 2 will be requested later than book 1, she should keep it, because it is so expensive to buy again. Submitted Solution: ``` print(2) ```
instruction
0
49,351
10
98,702
No
output
1
49,351
10
98,703
Provide a correct Python 3 solution for this coding contest problem. Find the price of a product before tax such that, when the consumption tax rate is 8 percent and 10 percent, the amount of consumption tax levied on it is A yen and B yen, respectively. (Yen is the currency of Japan.) Here, the price before tax must be a positive integer, and the amount of consumption tax is rounded down to the nearest integer. If multiple prices satisfy the condition, print the lowest such price; if no price satisfies the condition, print `-1`. Constraints * 1 \leq A \leq B \leq 100 * A and B are integers. Input Input is given from Standard Input in the following format: A B Output If there is a price that satisfies the condition, print an integer representing the lowest such price; otherwise, print `-1`. Examples Input 2 2 Output 25 Input 8 10 Output 100 Input 19 99 Output -1
instruction
0
49,413
10
98,826
"Correct Solution: ``` a, b = map(int, input().split()) for i in range(1, 1010): if int(i * 0.08) == a and int(i * 0.1) == b: print(i); exit() print(-1) ```
output
1
49,413
10
98,827
Provide a correct Python 3 solution for this coding contest problem. Find the price of a product before tax such that, when the consumption tax rate is 8 percent and 10 percent, the amount of consumption tax levied on it is A yen and B yen, respectively. (Yen is the currency of Japan.) Here, the price before tax must be a positive integer, and the amount of consumption tax is rounded down to the nearest integer. If multiple prices satisfy the condition, print the lowest such price; if no price satisfies the condition, print `-1`. Constraints * 1 \leq A \leq B \leq 100 * A and B are integers. Input Input is given from Standard Input in the following format: A B Output If there is a price that satisfies the condition, print an integer representing the lowest such price; otherwise, print `-1`. Examples Input 2 2 Output 25 Input 8 10 Output 100 Input 19 99 Output -1
instruction
0
49,414
10
98,828
"Correct Solution: ``` A,B=map(int,input().split()) for i in range(10000): if (i*0.08)//1==A and (i*0.1)//1==B: print(i) exit() print(-1) ```
output
1
49,414
10
98,829
Provide a correct Python 3 solution for this coding contest problem. Find the price of a product before tax such that, when the consumption tax rate is 8 percent and 10 percent, the amount of consumption tax levied on it is A yen and B yen, respectively. (Yen is the currency of Japan.) Here, the price before tax must be a positive integer, and the amount of consumption tax is rounded down to the nearest integer. If multiple prices satisfy the condition, print the lowest such price; if no price satisfies the condition, print `-1`. Constraints * 1 \leq A \leq B \leq 100 * A and B are integers. Input Input is given from Standard Input in the following format: A B Output If there is a price that satisfies the condition, print an integer representing the lowest such price; otherwise, print `-1`. Examples Input 2 2 Output 25 Input 8 10 Output 100 Input 19 99 Output -1
instruction
0
49,415
10
98,830
"Correct Solution: ``` a, b = map(int, input().split()) for i in range(1001): if int(i * 0.08) == a and int(i * 0.1) == b: print(i) break else: print(-1) ```
output
1
49,415
10
98,831
Provide a correct Python 3 solution for this coding contest problem. Find the price of a product before tax such that, when the consumption tax rate is 8 percent and 10 percent, the amount of consumption tax levied on it is A yen and B yen, respectively. (Yen is the currency of Japan.) Here, the price before tax must be a positive integer, and the amount of consumption tax is rounded down to the nearest integer. If multiple prices satisfy the condition, print the lowest such price; if no price satisfies the condition, print `-1`. Constraints * 1 \leq A \leq B \leq 100 * A and B are integers. Input Input is given from Standard Input in the following format: A B Output If there is a price that satisfies the condition, print an integer representing the lowest such price; otherwise, print `-1`. Examples Input 2 2 Output 25 Input 8 10 Output 100 Input 19 99 Output -1
instruction
0
49,416
10
98,832
"Correct Solution: ``` A, B =map(int, input().split()) r = -1 for i in range(1001): if i *8//100==A and i *10//100==B: r = i break print(r) ```
output
1
49,416
10
98,833
Provide a correct Python 3 solution for this coding contest problem. Find the price of a product before tax such that, when the consumption tax rate is 8 percent and 10 percent, the amount of consumption tax levied on it is A yen and B yen, respectively. (Yen is the currency of Japan.) Here, the price before tax must be a positive integer, and the amount of consumption tax is rounded down to the nearest integer. If multiple prices satisfy the condition, print the lowest such price; if no price satisfies the condition, print `-1`. Constraints * 1 \leq A \leq B \leq 100 * A and B are integers. Input Input is given from Standard Input in the following format: A B Output If there is a price that satisfies the condition, print an integer representing the lowest such price; otherwise, print `-1`. Examples Input 2 2 Output 25 Input 8 10 Output 100 Input 19 99 Output -1
instruction
0
49,417
10
98,834
"Correct Solution: ``` A,B=map(int,input().split()) ans=-1 for i in range(1500): if int(i*0.08)==A and int(i*0.1)==B: ans=i break print(ans) ```
output
1
49,417
10
98,835
Provide a correct Python 3 solution for this coding contest problem. Find the price of a product before tax such that, when the consumption tax rate is 8 percent and 10 percent, the amount of consumption tax levied on it is A yen and B yen, respectively. (Yen is the currency of Japan.) Here, the price before tax must be a positive integer, and the amount of consumption tax is rounded down to the nearest integer. If multiple prices satisfy the condition, print the lowest such price; if no price satisfies the condition, print `-1`. Constraints * 1 \leq A \leq B \leq 100 * A and B are integers. Input Input is given from Standard Input in the following format: A B Output If there is a price that satisfies the condition, print an integer representing the lowest such price; otherwise, print `-1`. Examples Input 2 2 Output 25 Input 8 10 Output 100 Input 19 99 Output -1
instruction
0
49,418
10
98,836
"Correct Solution: ``` a,b=map(int,input().split()) for x in range(10000): if int(x*0.08)==a and int(x*0.1)==b: print(x) exit() print(-1) ```
output
1
49,418
10
98,837
Provide a correct Python 3 solution for this coding contest problem. Find the price of a product before tax such that, when the consumption tax rate is 8 percent and 10 percent, the amount of consumption tax levied on it is A yen and B yen, respectively. (Yen is the currency of Japan.) Here, the price before tax must be a positive integer, and the amount of consumption tax is rounded down to the nearest integer. If multiple prices satisfy the condition, print the lowest such price; if no price satisfies the condition, print `-1`. Constraints * 1 \leq A \leq B \leq 100 * A and B are integers. Input Input is given from Standard Input in the following format: A B Output If there is a price that satisfies the condition, print an integer representing the lowest such price; otherwise, print `-1`. Examples Input 2 2 Output 25 Input 8 10 Output 100 Input 19 99 Output -1
instruction
0
49,419
10
98,838
"Correct Solution: ``` a,b=map(int,input().split());print(([i for i in range(10**6)if a==i//12.5and b==i//10]+[-1])[0]) ```
output
1
49,419
10
98,839
Provide a correct Python 3 solution for this coding contest problem. Find the price of a product before tax such that, when the consumption tax rate is 8 percent and 10 percent, the amount of consumption tax levied on it is A yen and B yen, respectively. (Yen is the currency of Japan.) Here, the price before tax must be a positive integer, and the amount of consumption tax is rounded down to the nearest integer. If multiple prices satisfy the condition, print the lowest such price; if no price satisfies the condition, print `-1`. Constraints * 1 \leq A \leq B \leq 100 * A and B are integers. Input Input is given from Standard Input in the following format: A B Output If there is a price that satisfies the condition, print an integer representing the lowest such price; otherwise, print `-1`. Examples Input 2 2 Output 25 Input 8 10 Output 100 Input 19 99 Output -1
instruction
0
49,420
10
98,840
"Correct Solution: ``` A,B=map(int,input().split()) for i in range(10001): if (i*8)//100==A and (i*10)//100==B: print(i) exit() print(-1) ```
output
1
49,420
10
98,841
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Find the price of a product before tax such that, when the consumption tax rate is 8 percent and 10 percent, the amount of consumption tax levied on it is A yen and B yen, respectively. (Yen is the currency of Japan.) Here, the price before tax must be a positive integer, and the amount of consumption tax is rounded down to the nearest integer. If multiple prices satisfy the condition, print the lowest such price; if no price satisfies the condition, print `-1`. Constraints * 1 \leq A \leq B \leq 100 * A and B are integers. Input Input is given from Standard Input in the following format: A B Output If there is a price that satisfies the condition, print an integer representing the lowest such price; otherwise, print `-1`. Examples Input 2 2 Output 25 Input 8 10 Output 100 Input 19 99 Output -1 Submitted Solution: ``` a,b=map(int,input().split());l=max(0--a*25//2,b*10);print([-1,l][l<min(-~a*25//2,-~b*10)]) ```
instruction
0
49,421
10
98,842
Yes
output
1
49,421
10
98,843
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Find the price of a product before tax such that, when the consumption tax rate is 8 percent and 10 percent, the amount of consumption tax levied on it is A yen and B yen, respectively. (Yen is the currency of Japan.) Here, the price before tax must be a positive integer, and the amount of consumption tax is rounded down to the nearest integer. If multiple prices satisfy the condition, print the lowest such price; if no price satisfies the condition, print `-1`. Constraints * 1 \leq A \leq B \leq 100 * A and B are integers. Input Input is given from Standard Input in the following format: A B Output If there is a price that satisfies the condition, print an integer representing the lowest such price; otherwise, print `-1`. Examples Input 2 2 Output 25 Input 8 10 Output 100 Input 19 99 Output -1 Submitted Solution: ``` a,b=map(int,input().split()) ans=-1 for i in range(1010): if(a==int(i*0.08) and b==int(i*0.1)): ans=i break print(ans) ```
instruction
0
49,422
10
98,844
Yes
output
1
49,422
10
98,845
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Find the price of a product before tax such that, when the consumption tax rate is 8 percent and 10 percent, the amount of consumption tax levied on it is A yen and B yen, respectively. (Yen is the currency of Japan.) Here, the price before tax must be a positive integer, and the amount of consumption tax is rounded down to the nearest integer. If multiple prices satisfy the condition, print the lowest such price; if no price satisfies the condition, print `-1`. Constraints * 1 \leq A \leq B \leq 100 * A and B are integers. Input Input is given from Standard Input in the following format: A B Output If there is a price that satisfies the condition, print an integer representing the lowest such price; otherwise, print `-1`. Examples Input 2 2 Output 25 Input 8 10 Output 100 Input 19 99 Output -1 Submitted Solution: ``` a,b=map(int,input().split()) for x in range(1,2000): if int(x*0.08)==a and int(x*0.1)==b: print(x) exit(0) print(-1) ```
instruction
0
49,423
10
98,846
Yes
output
1
49,423
10
98,847
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Find the price of a product before tax such that, when the consumption tax rate is 8 percent and 10 percent, the amount of consumption tax levied on it is A yen and B yen, respectively. (Yen is the currency of Japan.) Here, the price before tax must be a positive integer, and the amount of consumption tax is rounded down to the nearest integer. If multiple prices satisfy the condition, print the lowest such price; if no price satisfies the condition, print `-1`. Constraints * 1 \leq A \leq B \leq 100 * A and B are integers. Input Input is given from Standard Input in the following format: A B Output If there is a price that satisfies the condition, print an integer representing the lowest such price; otherwise, print `-1`. Examples Input 2 2 Output 25 Input 8 10 Output 100 Input 19 99 Output -1 Submitted Solution: ``` a,b=map(int,input().split()) ans=-1 for i in range(15000): if a==int(i*0.08) and b==int(i*0.1): ans=i break print(ans) ```
instruction
0
49,424
10
98,848
Yes
output
1
49,424
10
98,849
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Find the price of a product before tax such that, when the consumption tax rate is 8 percent and 10 percent, the amount of consumption tax levied on it is A yen and B yen, respectively. (Yen is the currency of Japan.) Here, the price before tax must be a positive integer, and the amount of consumption tax is rounded down to the nearest integer. If multiple prices satisfy the condition, print the lowest such price; if no price satisfies the condition, print `-1`. Constraints * 1 \leq A \leq B \leq 100 * A and B are integers. Input Input is given from Standard Input in the following format: A B Output If there is a price that satisfies the condition, print an integer representing the lowest such price; otherwise, print `-1`. Examples Input 2 2 Output 25 Input 8 10 Output 100 Input 19 99 Output -1 Submitted Solution: ``` import math A,B=map(int,input().split()) eight=[] i=0 ten=[] for a in range(1,1001): if math.floor(a*0.08)==A: eight.append(a) if math.floor(a*0.1)==B: ten.append(a) for a in eight: if a in ten: print(a) i=1 break if i=0: print("-1") ```
instruction
0
49,425
10
98,850
No
output
1
49,425
10
98,851
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Find the price of a product before tax such that, when the consumption tax rate is 8 percent and 10 percent, the amount of consumption tax levied on it is A yen and B yen, respectively. (Yen is the currency of Japan.) Here, the price before tax must be a positive integer, and the amount of consumption tax is rounded down to the nearest integer. If multiple prices satisfy the condition, print the lowest such price; if no price satisfies the condition, print `-1`. Constraints * 1 \leq A \leq B \leq 100 * A and B are integers. Input Input is given from Standard Input in the following format: A B Output If there is a price that satisfies the condition, print an integer representing the lowest such price; otherwise, print `-1`. Examples Input 2 2 Output 25 Input 8 10 Output 100 Input 19 99 Output -1 Submitted Solution: ``` import math a,b=list(map(int,input().split())) ans=-1 for i in range(math.floor(a*100/8)+1,math.floor((a+1)*100/8)+1): if math.floor(i*10/100)==b: ans=i break print(ans) ```
instruction
0
49,426
10
98,852
No
output
1
49,426
10
98,853
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Find the price of a product before tax such that, when the consumption tax rate is 8 percent and 10 percent, the amount of consumption tax levied on it is A yen and B yen, respectively. (Yen is the currency of Japan.) Here, the price before tax must be a positive integer, and the amount of consumption tax is rounded down to the nearest integer. If multiple prices satisfy the condition, print the lowest such price; if no price satisfies the condition, print `-1`. Constraints * 1 \leq A \leq B \leq 100 * A and B are integers. Input Input is given from Standard Input in the following format: A B Output If there is a price that satisfies the condition, print an integer representing the lowest such price; otherwise, print `-1`. Examples Input 2 2 Output 25 Input 8 10 Output 100 Input 19 99 Output -1 Submitted Solution: ``` import math def main(): A,B = map(int, input().split()) # η¨ŽηŽ‡rate%でtaxがA円とγͺγ‚‹η¨ŽζŠœγδΎ‘ζ Όxは、ceil(a*100/rate)<=x<ceil((a+1)*100/rate)γ‚’ζΊ€γŸγ™ min1 = math.ceil(A*100/8) max1 = math.ceil((A+1)*100/8)-1 min2 = math.ceil(B*100/10) max2 = math.ceil((B+1)*100/10)-1 ans = max(min1,min2) if not max1<min2 or max2<min1 else -1 print(ans) main() ```
instruction
0
49,427
10
98,854
No
output
1
49,427
10
98,855
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Find the price of a product before tax such that, when the consumption tax rate is 8 percent and 10 percent, the amount of consumption tax levied on it is A yen and B yen, respectively. (Yen is the currency of Japan.) Here, the price before tax must be a positive integer, and the amount of consumption tax is rounded down to the nearest integer. If multiple prices satisfy the condition, print the lowest such price; if no price satisfies the condition, print `-1`. Constraints * 1 \leq A \leq B \leq 100 * A and B are integers. Input Input is given from Standard Input in the following format: A B Output If there is a price that satisfies the condition, print an integer representing the lowest such price; otherwise, print `-1`. Examples Input 2 2 Output 25 Input 8 10 Output 100 Input 19 99 Output -1 Submitted Solution: ``` import math a,b=map(int,input().split()) f=-1 for i in range(1000): if math.floor(i*0.08)==a and math.floor(i*0.1)==b: f=i break print(f) ```
instruction
0
49,428
10
98,856
No
output
1
49,428
10
98,857
Provide tags and a correct Python 3 solution for this coding contest problem. Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis! The computers bought for the room were different. Some of them had only USB ports, some β€” only PS/2 ports, and some had both options. You have found a price list of a certain computer shop. In it, for m mouses it is specified the cost and the type of the port that is required to plug the mouse in (USB or PS/2). Each mouse from the list can be bought at most once. You want to buy some set of mouses from the given price list in such a way so that you maximize the number of computers equipped with mouses (it is not guaranteed that you will be able to equip all of the computers), and in case of equality of this value you want to minimize the total cost of mouses you will buy. Input The first line contains three integers a, b and c (0 ≀ a, b, c ≀ 105) β€” the number of computers that only have USB ports, the number of computers, that only have PS/2 ports, and the number of computers, that have both options, respectively. The next line contains one integer m (0 ≀ m ≀ 3Β·105) β€” the number of mouses in the price list. The next m lines each describe another mouse. The i-th line contains first integer vali (1 ≀ vali ≀ 109) β€” the cost of the i-th mouse, then the type of port (USB or PS/2) that is required to plug the mouse in. Output Output two integers separated by space β€” the number of equipped computers and the total cost of the mouses you will buy. Example Input 2 1 1 4 5 USB 6 PS/2 3 PS/2 7 PS/2 Output 3 14 Note In the first example you can buy the first three mouses. This way you will equip one of the computers that has only a USB port with a USB mouse, and the two PS/2 mouses you will plug into the computer with PS/2 port and the computer with both ports.
instruction
0
50,124
10
100,248
Tags: greedy, implementation, sortings, two pointers Correct Solution: ``` import math import re a, b, c = map(int, input().split()) q = 0 res = 0 val = int(input()) usb = [] ps2 = [] for i in range(val): x, y = input().split() if y == 'USB': usb.append(int(x)) else: ps2.append(int(x)) usb = sorted(usb) ps2 = sorted(ps2) res += sum(usb[:min(len(usb), a)]) q += min(len(usb), a) del(usb[:min(len(usb), a)]) res += sum(ps2[:min(len(ps2), b)]) q += min(len(ps2), b) del(ps2[:min(len(ps2), b)]) usb = sorted(usb + ps2) res += sum(usb[:min(len(usb), c)]) q += min(len(usb), c) print(str(q) + ' ' + str(res)) ```
output
1
50,124
10
100,249
Provide tags and a correct Python 3 solution for this coding contest problem. Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis! The computers bought for the room were different. Some of them had only USB ports, some β€” only PS/2 ports, and some had both options. You have found a price list of a certain computer shop. In it, for m mouses it is specified the cost and the type of the port that is required to plug the mouse in (USB or PS/2). Each mouse from the list can be bought at most once. You want to buy some set of mouses from the given price list in such a way so that you maximize the number of computers equipped with mouses (it is not guaranteed that you will be able to equip all of the computers), and in case of equality of this value you want to minimize the total cost of mouses you will buy. Input The first line contains three integers a, b and c (0 ≀ a, b, c ≀ 105) β€” the number of computers that only have USB ports, the number of computers, that only have PS/2 ports, and the number of computers, that have both options, respectively. The next line contains one integer m (0 ≀ m ≀ 3Β·105) β€” the number of mouses in the price list. The next m lines each describe another mouse. The i-th line contains first integer vali (1 ≀ vali ≀ 109) β€” the cost of the i-th mouse, then the type of port (USB or PS/2) that is required to plug the mouse in. Output Output two integers separated by space β€” the number of equipped computers and the total cost of the mouses you will buy. Example Input 2 1 1 4 5 USB 6 PS/2 3 PS/2 7 PS/2 Output 3 14 Note In the first example you can buy the first three mouses. This way you will equip one of the computers that has only a USB port with a USB mouse, and the two PS/2 mouses you will plug into the computer with PS/2 port and the computer with both ports.
instruction
0
50,125
10
100,250
Tags: greedy, implementation, sortings, two pointers Correct Solution: ``` from sys import stdin as fin a, b, c = input().split() a = int(a) b = int(b) c = int(c) n = int(input()) mouses = [] for i in range(0, n): l, r = fin.readline().strip().split() mouses.append((int(l), r)) mouses.sort() money_count = 0 comp_count = 0 for t in mouses: if t[1] == 'USB' and a + c or t[1] == 'PS/2' and b + c : money_count += t[0] comp_count += 1 if t[1] == 'USB': if a : a -= 1 elif c : c -= 1 if t[1] == 'PS/2': if b : b -= 1 elif c : c -= 1 print(comp_count, money_count) ```
output
1
50,125
10
100,251
Provide tags and a correct Python 3 solution for this coding contest problem. Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis! The computers bought for the room were different. Some of them had only USB ports, some β€” only PS/2 ports, and some had both options. You have found a price list of a certain computer shop. In it, for m mouses it is specified the cost and the type of the port that is required to plug the mouse in (USB or PS/2). Each mouse from the list can be bought at most once. You want to buy some set of mouses from the given price list in such a way so that you maximize the number of computers equipped with mouses (it is not guaranteed that you will be able to equip all of the computers), and in case of equality of this value you want to minimize the total cost of mouses you will buy. Input The first line contains three integers a, b and c (0 ≀ a, b, c ≀ 105) β€” the number of computers that only have USB ports, the number of computers, that only have PS/2 ports, and the number of computers, that have both options, respectively. The next line contains one integer m (0 ≀ m ≀ 3Β·105) β€” the number of mouses in the price list. The next m lines each describe another mouse. The i-th line contains first integer vali (1 ≀ vali ≀ 109) β€” the cost of the i-th mouse, then the type of port (USB or PS/2) that is required to plug the mouse in. Output Output two integers separated by space β€” the number of equipped computers and the total cost of the mouses you will buy. Example Input 2 1 1 4 5 USB 6 PS/2 3 PS/2 7 PS/2 Output 3 14 Note In the first example you can buy the first three mouses. This way you will equip one of the computers that has only a USB port with a USB mouse, and the two PS/2 mouses you will plug into the computer with PS/2 port and the computer with both ports.
instruction
0
50,126
10
100,252
Tags: greedy, implementation, sortings, two pointers Correct Solution: ``` #!/usr/local/bin/python3.4 from collections import * import pdb usb, ps_2 , both = map(int, input().split()) sales_usb = deque() sales_ps_2 = deque() for _ in range(int(input())): value, type_ = input().split() value = int(value) if type_ == "USB": sales_usb.append(value) else: sales_ps_2.append(value) def remove_both(usb,ps,both): total = 0 sold = 0 while both != 0: if (len(usb)!=0 and len(ps)!=0): if ( usb[0] >= ps[0] ): total+= ps.popleft() sold+=1 both-=1 elif ( usb[0] < ps[0] ): total+= usb.popleft() sold+=1 both-=1 elif len(usb)==0 and len(ps)!=0: temp_total,temp_sold,_ = remove_single(ps,both) total+=temp_total sold+=temp_sold both=0 elif len(ps)==0 and len(usb)!=0: temp_total,temp_sold,_ = remove_single(usb,both) total+=temp_total sold+=temp_sold both=0 else: both=0 return total,sold def remove_single(slist,number): total = 0 sold = 0 while number!=0 and len(slist)>0: total+=slist.popleft() sold+=1 number-=1 return total,sold,slist sum_all=0 sold=0 sales_usb = sorted(sales_usb) sales_ps_2 = sorted(sales_ps_2) # print (sales_usb,sales_ps_2) t_sum_all, t_sold, sales_ps_2 = remove_single(deque(sales_ps_2),ps_2) sum_all+=t_sum_all sold+=t_sold t_sum_all, t_sold, sales_usb = remove_single(deque(sales_usb),usb) sold+=t_sold sum_all+=t_sum_all t_sum_all, t_sold = remove_both(deque(sales_usb),deque(sales_ps_2),both) sum_all+=t_sum_all sold+=t_sold print (sold, sum_all) ```
output
1
50,126
10
100,253
Provide tags and a correct Python 3 solution for this coding contest problem. Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis! The computers bought for the room were different. Some of them had only USB ports, some β€” only PS/2 ports, and some had both options. You have found a price list of a certain computer shop. In it, for m mouses it is specified the cost and the type of the port that is required to plug the mouse in (USB or PS/2). Each mouse from the list can be bought at most once. You want to buy some set of mouses from the given price list in such a way so that you maximize the number of computers equipped with mouses (it is not guaranteed that you will be able to equip all of the computers), and in case of equality of this value you want to minimize the total cost of mouses you will buy. Input The first line contains three integers a, b and c (0 ≀ a, b, c ≀ 105) β€” the number of computers that only have USB ports, the number of computers, that only have PS/2 ports, and the number of computers, that have both options, respectively. The next line contains one integer m (0 ≀ m ≀ 3Β·105) β€” the number of mouses in the price list. The next m lines each describe another mouse. The i-th line contains first integer vali (1 ≀ vali ≀ 109) β€” the cost of the i-th mouse, then the type of port (USB or PS/2) that is required to plug the mouse in. Output Output two integers separated by space β€” the number of equipped computers and the total cost of the mouses you will buy. Example Input 2 1 1 4 5 USB 6 PS/2 3 PS/2 7 PS/2 Output 3 14 Note In the first example you can buy the first three mouses. This way you will equip one of the computers that has only a USB port with a USB mouse, and the two PS/2 mouses you will plug into the computer with PS/2 port and the computer with both ports.
instruction
0
50,127
10
100,254
Tags: greedy, implementation, sortings, two pointers Correct Solution: ``` def list_from_input(): return list(map(int, input().split())) class Mouse: def __init__(self, price, type): self.type = type self.price = price @classmethod def from_input(cls): mouse_data = input().split() price = int(mouse_data[0]) type = mouse_data[1][0] return Mouse(price, type) def main(): usb_pc, ps_pc, both_pc = list_from_input() mouses_count = int(input()) mouses = [] for i in range(mouses_count): mouses.append(Mouse.from_input()) mouses.sort(key=lambda mouse: mouse.price) purchase_amount = 0 pc_with_mouses = 0 for mouse in mouses: if mouse.type is 'U' and usb_pc > 0: usb_pc -= 1 purchase_amount += mouse.price pc_with_mouses += 1 elif mouse.type is 'P' and ps_pc > 0: ps_pc -= 1 purchase_amount += mouse.price pc_with_mouses += 1 elif both_pc > 0: both_pc -= 1 purchase_amount += mouse.price pc_with_mouses += 1 print(pc_with_mouses, purchase_amount) main() ```
output
1
50,127
10
100,255
Provide tags and a correct Python 3 solution for this coding contest problem. Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis! The computers bought for the room were different. Some of them had only USB ports, some β€” only PS/2 ports, and some had both options. You have found a price list of a certain computer shop. In it, for m mouses it is specified the cost and the type of the port that is required to plug the mouse in (USB or PS/2). Each mouse from the list can be bought at most once. You want to buy some set of mouses from the given price list in such a way so that you maximize the number of computers equipped with mouses (it is not guaranteed that you will be able to equip all of the computers), and in case of equality of this value you want to minimize the total cost of mouses you will buy. Input The first line contains three integers a, b and c (0 ≀ a, b, c ≀ 105) β€” the number of computers that only have USB ports, the number of computers, that only have PS/2 ports, and the number of computers, that have both options, respectively. The next line contains one integer m (0 ≀ m ≀ 3Β·105) β€” the number of mouses in the price list. The next m lines each describe another mouse. The i-th line contains first integer vali (1 ≀ vali ≀ 109) β€” the cost of the i-th mouse, then the type of port (USB or PS/2) that is required to plug the mouse in. Output Output two integers separated by space β€” the number of equipped computers and the total cost of the mouses you will buy. Example Input 2 1 1 4 5 USB 6 PS/2 3 PS/2 7 PS/2 Output 3 14 Note In the first example you can buy the first three mouses. This way you will equip one of the computers that has only a USB port with a USB mouse, and the two PS/2 mouses you will plug into the computer with PS/2 port and the computer with both ports.
instruction
0
50,128
10
100,256
Tags: greedy, implementation, sortings, two pointers Correct Solution: ``` from collections import deque a, b, c = list(map(int, input().split())) m = int(input()) usb_cost = [] ps_cost = [] for i in range(m): cost, t = input().split() cost = int(cost) if t == 'USB': usb_cost.append(cost) else: ps_cost.append(cost) usb_cost.sort(reverse = True) ps_cost.sort(reverse = True) # print(usb_cost) # print(ps_cost) ans = 0 ans_sum = 0 for i in range(min(a, len(usb_cost))): ans_sum += usb_cost.pop() ans += 1 for i in range(min(b, len(ps_cost))): ans_sum += ps_cost.pop() ans += 1 all_types = sorted(usb_cost + ps_cost, reverse = True) for i in range(min(c, len(all_types))): ans_sum += all_types.pop() ans += 1 print(ans, ans_sum) ```
output
1
50,128
10
100,257
Provide tags and a correct Python 3 solution for this coding contest problem. Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis! The computers bought for the room were different. Some of them had only USB ports, some β€” only PS/2 ports, and some had both options. You have found a price list of a certain computer shop. In it, for m mouses it is specified the cost and the type of the port that is required to plug the mouse in (USB or PS/2). Each mouse from the list can be bought at most once. You want to buy some set of mouses from the given price list in such a way so that you maximize the number of computers equipped with mouses (it is not guaranteed that you will be able to equip all of the computers), and in case of equality of this value you want to minimize the total cost of mouses you will buy. Input The first line contains three integers a, b and c (0 ≀ a, b, c ≀ 105) β€” the number of computers that only have USB ports, the number of computers, that only have PS/2 ports, and the number of computers, that have both options, respectively. The next line contains one integer m (0 ≀ m ≀ 3Β·105) β€” the number of mouses in the price list. The next m lines each describe another mouse. The i-th line contains first integer vali (1 ≀ vali ≀ 109) β€” the cost of the i-th mouse, then the type of port (USB or PS/2) that is required to plug the mouse in. Output Output two integers separated by space β€” the number of equipped computers and the total cost of the mouses you will buy. Example Input 2 1 1 4 5 USB 6 PS/2 3 PS/2 7 PS/2 Output 3 14 Note In the first example you can buy the first three mouses. This way you will equip one of the computers that has only a USB port with a USB mouse, and the two PS/2 mouses you will plug into the computer with PS/2 port and the computer with both ports.
instruction
0
50,129
10
100,258
Tags: greedy, implementation, sortings, two pointers Correct Solution: ``` a,b,c=map(int,input().split()) m=int(input()) d={'USB':[], 'PS/2':[]} for _ in range(m): v,t=input().split() d[t].append(int(v)) d['PS/2'].sort() d['USB'].sort() eq=cst=f1=f2=0 nusb=len(d['USB']) nps2=len(d['PS/2']) while a>0 and f1<nusb: a-=1 eq+=1 cst+=d['USB'][f1] f1+=1 while b>0 and f2<nps2: b-=1 eq+=1 cst+=d['PS/2'][f2] f2+=1 while c>0 and (f1<nusb or f2<nps2): c-=1 eq+=1 if f1==nusb: cst+=d['PS/2'][f2] f2+=1 continue elif f2==nps2: cst+=d['USB'][f1] f1+=1 continue if d['PS/2'][f2]<d['USB'][f1]: cst+=d['PS/2'][f2] f2+=1 else: cst+=d['USB'][f1] f1+=1 print(eq,cst) ```
output
1
50,129
10
100,259
Provide tags and a correct Python 3 solution for this coding contest problem. Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis! The computers bought for the room were different. Some of them had only USB ports, some β€” only PS/2 ports, and some had both options. You have found a price list of a certain computer shop. In it, for m mouses it is specified the cost and the type of the port that is required to plug the mouse in (USB or PS/2). Each mouse from the list can be bought at most once. You want to buy some set of mouses from the given price list in such a way so that you maximize the number of computers equipped with mouses (it is not guaranteed that you will be able to equip all of the computers), and in case of equality of this value you want to minimize the total cost of mouses you will buy. Input The first line contains three integers a, b and c (0 ≀ a, b, c ≀ 105) β€” the number of computers that only have USB ports, the number of computers, that only have PS/2 ports, and the number of computers, that have both options, respectively. The next line contains one integer m (0 ≀ m ≀ 3Β·105) β€” the number of mouses in the price list. The next m lines each describe another mouse. The i-th line contains first integer vali (1 ≀ vali ≀ 109) β€” the cost of the i-th mouse, then the type of port (USB or PS/2) that is required to plug the mouse in. Output Output two integers separated by space β€” the number of equipped computers and the total cost of the mouses you will buy. Example Input 2 1 1 4 5 USB 6 PS/2 3 PS/2 7 PS/2 Output 3 14 Note In the first example you can buy the first three mouses. This way you will equip one of the computers that has only a USB port with a USB mouse, and the two PS/2 mouses you will plug into the computer with PS/2 port and the computer with both ports.
instruction
0
50,130
10
100,260
Tags: greedy, implementation, sortings, two pointers Correct Solution: ``` u, p, b = map(int,input().split()) t = int(input()) usb = [] ps2 = [] for i in range(t): val = input().split() if val[1] == 'USB': usb.append(int(val[0])) else: ps2.append(int(val[0])) c = 0 s = 0 usb.sort(reverse=True) ps2.sort(reverse=True) leu = len(usb) lep = len(ps2) j = 0 for i in range(leu): if j>=u: break s += usb.pop() j += 1 c += 1 k = 0 for i in range(lep): if k>=p: break s += ps2.pop() k += 1 c += 1 for i in range(b): if len(usb)>0 and len(ps2)>0: if usb[-1]<ps2[-1]: s += usb.pop() c += 1 else: s += ps2.pop() c += 1 elif len(usb)>0: s += usb.pop() c += 1 elif len(ps2)>0: s += ps2.pop() c += 1 else: break print(c, s) ```
output
1
50,130
10
100,261
Provide tags and a correct Python 3 solution for this coding contest problem. Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis! The computers bought for the room were different. Some of them had only USB ports, some β€” only PS/2 ports, and some had both options. You have found a price list of a certain computer shop. In it, for m mouses it is specified the cost and the type of the port that is required to plug the mouse in (USB or PS/2). Each mouse from the list can be bought at most once. You want to buy some set of mouses from the given price list in such a way so that you maximize the number of computers equipped with mouses (it is not guaranteed that you will be able to equip all of the computers), and in case of equality of this value you want to minimize the total cost of mouses you will buy. Input The first line contains three integers a, b and c (0 ≀ a, b, c ≀ 105) β€” the number of computers that only have USB ports, the number of computers, that only have PS/2 ports, and the number of computers, that have both options, respectively. The next line contains one integer m (0 ≀ m ≀ 3Β·105) β€” the number of mouses in the price list. The next m lines each describe another mouse. The i-th line contains first integer vali (1 ≀ vali ≀ 109) β€” the cost of the i-th mouse, then the type of port (USB or PS/2) that is required to plug the mouse in. Output Output two integers separated by space β€” the number of equipped computers and the total cost of the mouses you will buy. Example Input 2 1 1 4 5 USB 6 PS/2 3 PS/2 7 PS/2 Output 3 14 Note In the first example you can buy the first three mouses. This way you will equip one of the computers that has only a USB port with a USB mouse, and the two PS/2 mouses you will plug into the computer with PS/2 port and the computer with both ports.
instruction
0
50,131
10
100,262
Tags: greedy, implementation, sortings, two pointers Correct Solution: ``` a,b,c = input().split() a,b,c = int(a), int(b), int(c) usb = 'USB' ps2 = 'PS/2' u = [] ps = [] n = int(input()) while n >0: cost, s = input().split() if s == usb: u.append(int(cost)) elif s == ps2: ps.append(int(cost)) n -= 1 u.sort() ps.sort() cost, count = 0, 0 a_curr, ps_curr = 0, 0 a_count, ps_count = len(u), len(ps) cost += sum(u[0:min(a_count,a)]) a_curr = min(a_count,a) count = a_curr cost += sum(ps[0:min(ps_count, b)]) ps_curr = min(ps_count, b) count += ps_curr new_arr = u[a_curr:] + ps[ps_curr:] count += min(c,len(new_arr)) new_arr.sort() cost += sum(new_arr[:c]) print(count, cost, sep = ' ') ```
output
1
50,131
10
100,263
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis! The computers bought for the room were different. Some of them had only USB ports, some β€” only PS/2 ports, and some had both options. You have found a price list of a certain computer shop. In it, for m mouses it is specified the cost and the type of the port that is required to plug the mouse in (USB or PS/2). Each mouse from the list can be bought at most once. You want to buy some set of mouses from the given price list in such a way so that you maximize the number of computers equipped with mouses (it is not guaranteed that you will be able to equip all of the computers), and in case of equality of this value you want to minimize the total cost of mouses you will buy. Input The first line contains three integers a, b and c (0 ≀ a, b, c ≀ 105) β€” the number of computers that only have USB ports, the number of computers, that only have PS/2 ports, and the number of computers, that have both options, respectively. The next line contains one integer m (0 ≀ m ≀ 3Β·105) β€” the number of mouses in the price list. The next m lines each describe another mouse. The i-th line contains first integer vali (1 ≀ vali ≀ 109) β€” the cost of the i-th mouse, then the type of port (USB or PS/2) that is required to plug the mouse in. Output Output two integers separated by space β€” the number of equipped computers and the total cost of the mouses you will buy. Example Input 2 1 1 4 5 USB 6 PS/2 3 PS/2 7 PS/2 Output 3 14 Note In the first example you can buy the first three mouses. This way you will equip one of the computers that has only a USB port with a USB mouse, and the two PS/2 mouses you will plug into the computer with PS/2 port and the computer with both ports. Submitted Solution: ``` import sys input = sys.stdin.readline ''' ''' num_usb, num_ps, num_both = map(int, input().split()) m = int(input()) usb = [] ps = [] for _ in range(m): c, con = input().rstrip().split() c = int(c) if con == "USB": usb.append(c) else: ps.append(c) usb.sort(reverse=True) ps.sort(reverse=True) cost = 0 count = 0 while num_usb and usb: num_usb -= 1 cost += usb.pop() count += 1 while num_ps and ps: num_ps -= 1 cost += ps.pop() count += 1 usb.extend(ps) both = usb both.sort(reverse=True) while num_both and usb: num_both -= 1 cost += both.pop() count += 1 print(count, cost) ```
instruction
0
50,132
10
100,264
Yes
output
1
50,132
10
100,265
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis! The computers bought for the room were different. Some of them had only USB ports, some β€” only PS/2 ports, and some had both options. You have found a price list of a certain computer shop. In it, for m mouses it is specified the cost and the type of the port that is required to plug the mouse in (USB or PS/2). Each mouse from the list can be bought at most once. You want to buy some set of mouses from the given price list in such a way so that you maximize the number of computers equipped with mouses (it is not guaranteed that you will be able to equip all of the computers), and in case of equality of this value you want to minimize the total cost of mouses you will buy. Input The first line contains three integers a, b and c (0 ≀ a, b, c ≀ 105) β€” the number of computers that only have USB ports, the number of computers, that only have PS/2 ports, and the number of computers, that have both options, respectively. The next line contains one integer m (0 ≀ m ≀ 3Β·105) β€” the number of mouses in the price list. The next m lines each describe another mouse. The i-th line contains first integer vali (1 ≀ vali ≀ 109) β€” the cost of the i-th mouse, then the type of port (USB or PS/2) that is required to plug the mouse in. Output Output two integers separated by space β€” the number of equipped computers and the total cost of the mouses you will buy. Example Input 2 1 1 4 5 USB 6 PS/2 3 PS/2 7 PS/2 Output 3 14 Note In the first example you can buy the first three mouses. This way you will equip one of the computers that has only a USB port with a USB mouse, and the two PS/2 mouses you will plug into the computer with PS/2 port and the computer with both ports. Submitted Solution: ``` a,b,c=map(int,input().split()) m=int(input()) usb,ps2=[],[] for i in range(m): s=input().split() if s[1]=="USB": usb.append(int(s[0])) else: ps2.append(int(s[0])) usb.sort(); ps2.sort(); kusb,kps2=min(a,len(usb)),min(b,len(ps2)) kans=kusb+kps2 sans=sum(usb[:kusb])+sum(ps2[:kps2]) other=usb[kusb:]+ps2[kps2:] other.sort() kother=min(c,len(other)) kans+=kother sans+=sum(other[:kother]) print(str(kans)+' '+str(sans)) ```
instruction
0
50,133
10
100,266
Yes
output
1
50,133
10
100,267
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis! The computers bought for the room were different. Some of them had only USB ports, some β€” only PS/2 ports, and some had both options. You have found a price list of a certain computer shop. In it, for m mouses it is specified the cost and the type of the port that is required to plug the mouse in (USB or PS/2). Each mouse from the list can be bought at most once. You want to buy some set of mouses from the given price list in such a way so that you maximize the number of computers equipped with mouses (it is not guaranteed that you will be able to equip all of the computers), and in case of equality of this value you want to minimize the total cost of mouses you will buy. Input The first line contains three integers a, b and c (0 ≀ a, b, c ≀ 105) β€” the number of computers that only have USB ports, the number of computers, that only have PS/2 ports, and the number of computers, that have both options, respectively. The next line contains one integer m (0 ≀ m ≀ 3Β·105) β€” the number of mouses in the price list. The next m lines each describe another mouse. The i-th line contains first integer vali (1 ≀ vali ≀ 109) β€” the cost of the i-th mouse, then the type of port (USB or PS/2) that is required to plug the mouse in. Output Output two integers separated by space β€” the number of equipped computers and the total cost of the mouses you will buy. Example Input 2 1 1 4 5 USB 6 PS/2 3 PS/2 7 PS/2 Output 3 14 Note In the first example you can buy the first three mouses. This way you will equip one of the computers that has only a USB port with a USB mouse, and the two PS/2 mouses you will plug into the computer with PS/2 port and the computer with both ports. Submitted Solution: ``` a,b,c=map(int,input().split()) m=int(input()) usb=[] ps=[] count=0 for _ in range(m): x,y=input().split() if y=="USB": usb.append(int(x)) else: ps.append(int(x)) usb.sort() ps.sort() ans=0 usbc=0 psc=0 if a>len(usb): ans+=sum(usb) usbc=len(usb) count+=len(usb) else: for i in range(a): ans+=usb[i] usbc=i count+=1 if a>0: usbc+=1 if b>len(ps): ans+=sum(ps) psc=len(ps) count+=len(ps) else: for i in range(b): ans+=ps[i] psc=i count+=1 if b>0: psc+=1 cc=c if len(usb)-1>=usbc and len(ps)-1>=psc: while usbc<=len(usb)-1 and psc<=len(ps)-1 and cc>0: if usb[usbc]<ps[psc]: ans+=usb[usbc] usbc+=1 cc-=1 count+=1 else: ans+=ps[psc] psc+=1 cc-=1 count+=1 #print(usbc,psc) if cc>0 and usbc<=len(usb)-1: while cc>0 and usbc<=len(usb)-1: cc-=1 ans+=usb[usbc] usbc+=1 count+=1 if cc>0 and psc<=len(ps)-1: while cc>0 and psc<=len(ps)-1: cc-=1 ans+=ps[psc] psc+=1 count+=1 print(count,ans) ```
instruction
0
50,134
10
100,268
Yes
output
1
50,134
10
100,269
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis! The computers bought for the room were different. Some of them had only USB ports, some β€” only PS/2 ports, and some had both options. You have found a price list of a certain computer shop. In it, for m mouses it is specified the cost and the type of the port that is required to plug the mouse in (USB or PS/2). Each mouse from the list can be bought at most once. You want to buy some set of mouses from the given price list in such a way so that you maximize the number of computers equipped with mouses (it is not guaranteed that you will be able to equip all of the computers), and in case of equality of this value you want to minimize the total cost of mouses you will buy. Input The first line contains three integers a, b and c (0 ≀ a, b, c ≀ 105) β€” the number of computers that only have USB ports, the number of computers, that only have PS/2 ports, and the number of computers, that have both options, respectively. The next line contains one integer m (0 ≀ m ≀ 3Β·105) β€” the number of mouses in the price list. The next m lines each describe another mouse. The i-th line contains first integer vali (1 ≀ vali ≀ 109) β€” the cost of the i-th mouse, then the type of port (USB or PS/2) that is required to plug the mouse in. Output Output two integers separated by space β€” the number of equipped computers and the total cost of the mouses you will buy. Example Input 2 1 1 4 5 USB 6 PS/2 3 PS/2 7 PS/2 Output 3 14 Note In the first example you can buy the first three mouses. This way you will equip one of the computers that has only a USB port with a USB mouse, and the two PS/2 mouses you will plug into the computer with PS/2 port and the computer with both ports. Submitted Solution: ``` a, b, c = [int(i) for i in input().split()] #usb = a #ps = b #both = c n = int(input()) A = [] ps = [] usb = [] for i in range(n): s = input().split() s[0] = int(s[0]) if s[1] == "USB": usb.append(s[0]) else: ps.append(s[0]) #s[0], s[1] = s[1], s[0] # A.append(s) #A.sort() ps.sort() usb.sort() usbptr = 0 psptr = 0 totalnum = 0 totalcost = 0 for i in range(a): if usbptr < len(usb): totalcost += usb[usbptr] usbptr+=1 totalnum+=1 elif usbptr == len(usb): break for i in range(b): if psptr < len(ps): totalcost += ps[psptr] psptr+=1 totalnum+=1 elif psptr == len(ps): break for i in range(c): if usbptr < len(usb) and psptr < len(ps): if usb[usbptr] < ps[psptr]: totalcost += usb[usbptr] usbptr+=1 totalnum+=1 else: totalcost += ps[psptr] psptr+=1 totalnum+=1 elif usbptr==len(usb) and psptr<len(ps): totalcost += ps[psptr] psptr+=1 totalnum+=1 elif usbptr<len(usb) and psptr == len(ps): totalcost += usb[usbptr] usbptr+=1 totalnum+=1 else: break print(totalnum, totalcost) ```
instruction
0
50,135
10
100,270
Yes
output
1
50,135
10
100,271
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis! The computers bought for the room were different. Some of them had only USB ports, some β€” only PS/2 ports, and some had both options. You have found a price list of a certain computer shop. In it, for m mouses it is specified the cost and the type of the port that is required to plug the mouse in (USB or PS/2). Each mouse from the list can be bought at most once. You want to buy some set of mouses from the given price list in such a way so that you maximize the number of computers equipped with mouses (it is not guaranteed that you will be able to equip all of the computers), and in case of equality of this value you want to minimize the total cost of mouses you will buy. Input The first line contains three integers a, b and c (0 ≀ a, b, c ≀ 105) β€” the number of computers that only have USB ports, the number of computers, that only have PS/2 ports, and the number of computers, that have both options, respectively. The next line contains one integer m (0 ≀ m ≀ 3Β·105) β€” the number of mouses in the price list. The next m lines each describe another mouse. The i-th line contains first integer vali (1 ≀ vali ≀ 109) β€” the cost of the i-th mouse, then the type of port (USB or PS/2) that is required to plug the mouse in. Output Output two integers separated by space β€” the number of equipped computers and the total cost of the mouses you will buy. Example Input 2 1 1 4 5 USB 6 PS/2 3 PS/2 7 PS/2 Output 3 14 Note In the first example you can buy the first three mouses. This way you will equip one of the computers that has only a USB port with a USB mouse, and the two PS/2 mouses you will plug into the computer with PS/2 port and the computer with both ports. Submitted Solution: ``` a,b,c=map(int,input().split()) m=int(input()) usb=[] ps2=[] cost=0 for i in range(m): z=list(input().split()) if z[1]=='USB': usb.append(int(z[0])) else: ps2.append(int(z[0])) usb=sorted(usb) ps2=sorted(ps2) while (len(usb)>0 and len(ps2)>0) and (a>0 or b>0 or c>0): if usb[0]>ps2[0]: if b>0 or c>0: cost+=ps2[0] if b>0: b-=1 else: c-=1 ps2.pop(0) elif (a>0): cost+=usb[0] a-=1 usb.pop(0) else: if a>0 or c>0: cost+=usb[0] if a>0: a-=1 else: c-=1 usb.pop(0) elif b>0: cost+=ps2[0] b-=1 ps2.pop(0) while len(usb)>0 and a>0: cost+=usb[0] a-=1 usb.pop(0) while len(ps2)>0 and b>0: cost+=ps2[0] b-=1 ps2.pop(0) while len(usb)>0 and c>0: cost+=usb[0] c-=1 usb.pop(0) while len(ps2)>0 and c>0: cost+=ps2[0] c-=1 ps2.pop(0) print((m-a-b-c),cost) ```
instruction
0
50,136
10
100,272
No
output
1
50,136
10
100,273
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis! The computers bought for the room were different. Some of them had only USB ports, some β€” only PS/2 ports, and some had both options. You have found a price list of a certain computer shop. In it, for m mouses it is specified the cost and the type of the port that is required to plug the mouse in (USB or PS/2). Each mouse from the list can be bought at most once. You want to buy some set of mouses from the given price list in such a way so that you maximize the number of computers equipped with mouses (it is not guaranteed that you will be able to equip all of the computers), and in case of equality of this value you want to minimize the total cost of mouses you will buy. Input The first line contains three integers a, b and c (0 ≀ a, b, c ≀ 105) β€” the number of computers that only have USB ports, the number of computers, that only have PS/2 ports, and the number of computers, that have both options, respectively. The next line contains one integer m (0 ≀ m ≀ 3Β·105) β€” the number of mouses in the price list. The next m lines each describe another mouse. The i-th line contains first integer vali (1 ≀ vali ≀ 109) β€” the cost of the i-th mouse, then the type of port (USB or PS/2) that is required to plug the mouse in. Output Output two integers separated by space β€” the number of equipped computers and the total cost of the mouses you will buy. Example Input 2 1 1 4 5 USB 6 PS/2 3 PS/2 7 PS/2 Output 3 14 Note In the first example you can buy the first three mouses. This way you will equip one of the computers that has only a USB port with a USB mouse, and the two PS/2 mouses you will plug into the computer with PS/2 port and the computer with both ports. Submitted Solution: ``` a,b,c=map(int,input().split()) m=int(input()) l=[] for i in range(m): q=input().split() l.append(q) l[i][0]=int(q[0]) l=sorted(l) n=a+b+c s=0 if n>m: for i in range(m): s+=l[i][0] print(n, s) exit() ka=0 kb=0 kc=0 for i in range(n): if l[i][1]=="PS/2" and kb<b: s+=l[i][0] kb+=1 continue elif l[i][1]=="PS/2" and kc<c: s+=l[i][0] kc+=1 continue if l[i][1]=="USB" and ka<a: s+=l[i][0] ka+=1 elif l[i][1]=="USB" and kc<c: s+=l[i][0] kc+=1 print(ka+kb+kc, s) ```
instruction
0
50,137
10
100,274
No
output
1
50,137
10
100,275
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis! The computers bought for the room were different. Some of them had only USB ports, some β€” only PS/2 ports, and some had both options. You have found a price list of a certain computer shop. In it, for m mouses it is specified the cost and the type of the port that is required to plug the mouse in (USB or PS/2). Each mouse from the list can be bought at most once. You want to buy some set of mouses from the given price list in such a way so that you maximize the number of computers equipped with mouses (it is not guaranteed that you will be able to equip all of the computers), and in case of equality of this value you want to minimize the total cost of mouses you will buy. Input The first line contains three integers a, b and c (0 ≀ a, b, c ≀ 105) β€” the number of computers that only have USB ports, the number of computers, that only have PS/2 ports, and the number of computers, that have both options, respectively. The next line contains one integer m (0 ≀ m ≀ 3Β·105) β€” the number of mouses in the price list. The next m lines each describe another mouse. The i-th line contains first integer vali (1 ≀ vali ≀ 109) β€” the cost of the i-th mouse, then the type of port (USB or PS/2) that is required to plug the mouse in. Output Output two integers separated by space β€” the number of equipped computers and the total cost of the mouses you will buy. Example Input 2 1 1 4 5 USB 6 PS/2 3 PS/2 7 PS/2 Output 3 14 Note In the first example you can buy the first three mouses. This way you will equip one of the computers that has only a USB port with a USB mouse, and the two PS/2 mouses you will plug into the computer with PS/2 port and the computer with both ports. Submitted Solution: ``` def mergesort(): usbps = [] i = 0 j = 0 while i > len(usb) and j > len(ps): if usb[i] <= ps[j]: usbps.append(usb[i]) i += 1 else: usbps.append(ps[j]) j += 1 usbps += usb[i:] + ps[j:] return usbps a, b, c = map(int, input().split()) m = int(input()) ans1 = 0 ans2 = 0 usb = [] ps = [] for i in range(m): l = list(input().split()) if l[1] == 'USB': usb.append(int(l[0])) else: ps.append(int(l[0])) cntusb = len(usb) cntps = len(ps) usb.sort() ps.sort() if cntusb > a: cntusb -= a ans1 += a ans2 += sum(usb[:a]) usb = usb[a:] else: ans1 += cntusb cntusb = 0 ans2 += sum(usb) usb = [] if cntps > b: cntps -= b ans1 += b ans2 += sum(ps[:b]) ps = ps[b:] else: ans1 += b cntps = 0 ans2 += sum(ps) ps = [] every = mergesort() if cntusb + cntps > c: ans1 += c ans2 += sum(every[:c]) else: ans1 += c - cntusb - cntps ans2 += sum(every) print(ans1, ans2) ```
instruction
0
50,138
10
100,276
No
output
1
50,138
10
100,277
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis! The computers bought for the room were different. Some of them had only USB ports, some β€” only PS/2 ports, and some had both options. You have found a price list of a certain computer shop. In it, for m mouses it is specified the cost and the type of the port that is required to plug the mouse in (USB or PS/2). Each mouse from the list can be bought at most once. You want to buy some set of mouses from the given price list in such a way so that you maximize the number of computers equipped with mouses (it is not guaranteed that you will be able to equip all of the computers), and in case of equality of this value you want to minimize the total cost of mouses you will buy. Input The first line contains three integers a, b and c (0 ≀ a, b, c ≀ 105) β€” the number of computers that only have USB ports, the number of computers, that only have PS/2 ports, and the number of computers, that have both options, respectively. The next line contains one integer m (0 ≀ m ≀ 3Β·105) β€” the number of mouses in the price list. The next m lines each describe another mouse. The i-th line contains first integer vali (1 ≀ vali ≀ 109) β€” the cost of the i-th mouse, then the type of port (USB or PS/2) that is required to plug the mouse in. Output Output two integers separated by space β€” the number of equipped computers and the total cost of the mouses you will buy. Example Input 2 1 1 4 5 USB 6 PS/2 3 PS/2 7 PS/2 Output 3 14 Note In the first example you can buy the first three mouses. This way you will equip one of the computers that has only a USB port with a USB mouse, and the two PS/2 mouses you will plug into the computer with PS/2 port and the computer with both ports. Submitted Solution: ``` a,b,k=map(int, input().split()) A=[] B=[] for _ in range(int(input())): s=input() if s[len(s)-1]=='2': B.append(int(s[0])) else: A.append(int(s[0])) B.sort() A.sort() c=0 ans=0 T=[] if len(A)<=a: c+=len(A) ans+=sum(A) else: c+=a ans+=sum(A[0:a]) T+=A[a:len(A)] if len(B)<=b: c+=len(B) ans+=sum(B) else: c+=b ans+=sum(B[0:b]) T+=B[b:len(B)] T.sort() if len(T)<=k: c+=len(T) ans+=sum(T) else: c+=k ans+=sum(T[0:k]) print(c,ans) ```
instruction
0
50,139
10
100,278
No
output
1
50,139
10
100,279
Provide a correct Python 3 solution for this coding contest problem. There are N gems. The value of the i-th gem is V_i. You will choose some of these gems, possibly all or none, and get them. However, you need to pay a cost of C_i to get the i-th gem. Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid. Find the maximum possible value of X-Y. Constraints * All values in input are integers. * 1 \leq N \leq 20 * 1 \leq C_i, V_i \leq 50 Input Input is given from Standard Input in the following format: N V_1 V_2 ... V_N C_1 C_2 ... C_N Output Print the maximum possible value of X-Y. Examples Input 3 10 2 5 6 3 4 Output 5 Input 4 13 21 6 19 11 30 6 15 Output 6 Input 1 1 50 Output 0
instruction
0
50,313
10
100,626
"Correct Solution: ``` n=int(input()) aa=list(map(int,input().split())) bb=list(map(int,input().split())) ans=0 for a,b in zip(aa,bb): if a-b>0: ans+=a-b print(ans) ```
output
1
50,313
10
100,627
Provide a correct Python 3 solution for this coding contest problem. There are N gems. The value of the i-th gem is V_i. You will choose some of these gems, possibly all or none, and get them. However, you need to pay a cost of C_i to get the i-th gem. Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid. Find the maximum possible value of X-Y. Constraints * All values in input are integers. * 1 \leq N \leq 20 * 1 \leq C_i, V_i \leq 50 Input Input is given from Standard Input in the following format: N V_1 V_2 ... V_N C_1 C_2 ... C_N Output Print the maximum possible value of X-Y. Examples Input 3 10 2 5 6 3 4 Output 5 Input 4 13 21 6 19 11 30 6 15 Output 6 Input 1 1 50 Output 0
instruction
0
50,314
10
100,628
"Correct Solution: ``` n=int(input()) v=list(map(int,input().split())) c=list(map(int,input().split())) d=0 for a,b in zip(v,c): if a-b>0: d+=a-b print(d) ```
output
1
50,314
10
100,629
Provide a correct Python 3 solution for this coding contest problem. There are N gems. The value of the i-th gem is V_i. You will choose some of these gems, possibly all or none, and get them. However, you need to pay a cost of C_i to get the i-th gem. Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid. Find the maximum possible value of X-Y. Constraints * All values in input are integers. * 1 \leq N \leq 20 * 1 \leq C_i, V_i \leq 50 Input Input is given from Standard Input in the following format: N V_1 V_2 ... V_N C_1 C_2 ... C_N Output Print the maximum possible value of X-Y. Examples Input 3 10 2 5 6 3 4 Output 5 Input 4 13 21 6 19 11 30 6 15 Output 6 Input 1 1 50 Output 0
instruction
0
50,315
10
100,630
"Correct Solution: ``` n=int(input()) v=list(map(int,input().split())) c=list(map(int,input().split())) sum=0 for i in range(n): sum+=max(v[i]-c[i],0) print(sum) ```
output
1
50,315
10
100,631
Provide a correct Python 3 solution for this coding contest problem. There are N gems. The value of the i-th gem is V_i. You will choose some of these gems, possibly all or none, and get them. However, you need to pay a cost of C_i to get the i-th gem. Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid. Find the maximum possible value of X-Y. Constraints * All values in input are integers. * 1 \leq N \leq 20 * 1 \leq C_i, V_i \leq 50 Input Input is given from Standard Input in the following format: N V_1 V_2 ... V_N C_1 C_2 ... C_N Output Print the maximum possible value of X-Y. Examples Input 3 10 2 5 6 3 4 Output 5 Input 4 13 21 6 19 11 30 6 15 Output 6 Input 1 1 50 Output 0
instruction
0
50,316
10
100,632
"Correct Solution: ``` N=int(input()) V=input().split(" ") C=input().split(" ") ans=0 for i in range(N): ans+=max(0, int(V[i])-int(C[i])) print(int(ans)) ```
output
1
50,316
10
100,633
Provide a correct Python 3 solution for this coding contest problem. There are N gems. The value of the i-th gem is V_i. You will choose some of these gems, possibly all or none, and get them. However, you need to pay a cost of C_i to get the i-th gem. Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid. Find the maximum possible value of X-Y. Constraints * All values in input are integers. * 1 \leq N \leq 20 * 1 \leq C_i, V_i \leq 50 Input Input is given from Standard Input in the following format: N V_1 V_2 ... V_N C_1 C_2 ... C_N Output Print the maximum possible value of X-Y. Examples Input 3 10 2 5 6 3 4 Output 5 Input 4 13 21 6 19 11 30 6 15 Output 6 Input 1 1 50 Output 0
instruction
0
50,317
10
100,634
"Correct Solution: ``` N = int(input()) V = list(map(int,input().split())) C = list(map(int,input().split())) ans = 0 for i,j in zip(V,C): ans += max(0,i-j) print(ans) ```
output
1
50,317
10
100,635
Provide a correct Python 3 solution for this coding contest problem. There are N gems. The value of the i-th gem is V_i. You will choose some of these gems, possibly all or none, and get them. However, you need to pay a cost of C_i to get the i-th gem. Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid. Find the maximum possible value of X-Y. Constraints * All values in input are integers. * 1 \leq N \leq 20 * 1 \leq C_i, V_i \leq 50 Input Input is given from Standard Input in the following format: N V_1 V_2 ... V_N C_1 C_2 ... C_N Output Print the maximum possible value of X-Y. Examples Input 3 10 2 5 6 3 4 Output 5 Input 4 13 21 6 19 11 30 6 15 Output 6 Input 1 1 50 Output 0
instruction
0
50,318
10
100,636
"Correct Solution: ``` N = int(input()) V = list(map(int, input().split())) C = list(map(int, input().split())) print(sum([max(v-c, 0) for v, c in zip(V, C)])) ```
output
1
50,318
10
100,637
Provide a correct Python 3 solution for this coding contest problem. There are N gems. The value of the i-th gem is V_i. You will choose some of these gems, possibly all or none, and get them. However, you need to pay a cost of C_i to get the i-th gem. Let X be the sum of the values of the gems obtained, and Y be the sum of the costs paid. Find the maximum possible value of X-Y. Constraints * All values in input are integers. * 1 \leq N \leq 20 * 1 \leq C_i, V_i \leq 50 Input Input is given from Standard Input in the following format: N V_1 V_2 ... V_N C_1 C_2 ... C_N Output Print the maximum possible value of X-Y. Examples Input 3 10 2 5 6 3 4 Output 5 Input 4 13 21 6 19 11 30 6 15 Output 6 Input 1 1 50 Output 0
instruction
0
50,319
10
100,638
"Correct Solution: ``` N = input() VS = [int(i) for i in input().split()] CS = [int(i) for i in input().split()] print(sum([a - b for a, b in zip(VS, CS) if a - b > 0])) ```
output
1
50,319
10
100,639