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 |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
I conducted an exit poll of the shopping amount at a department store. Create a program that takes the shopping amount data as input, calculates the average shopping amount per person, and outputs it. The number of people surveyed shall be 100,000 or less, and the shopping amount per person shall not exceed 1 million yen.
Input
The input is given in the following format:
n
v1
v2
::
vn
The first line gives the number of people surveyed n, and the following n lines give the integer vi representing the purchase amount of the ith person.
Output
Please output the average shopping amount (integer: rounded down to the nearest whole number) on one line.
Example
Input
6
12300
5600
33800
0
26495
52000
Output
21699
Submitted Solution:
```
n = int(input())
sum =0
for _ in range(n):
sum += int(input())
print(sum//n)
``` | instruction | 0 | 103,591 | 10 | 207,182 |
Yes | output | 1 | 103,591 | 10 | 207,183 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
I conducted an exit poll of the shopping amount at a department store. Create a program that takes the shopping amount data as input, calculates the average shopping amount per person, and outputs it. The number of people surveyed shall be 100,000 or less, and the shopping amount per person shall not exceed 1 million yen.
Input
The input is given in the following format:
n
v1
v2
::
vn
The first line gives the number of people surveyed n, and the following n lines give the integer vi representing the purchase amount of the ith person.
Output
Please output the average shopping amount (integer: rounded down to the nearest whole number) on one line.
Example
Input
6
12300
5600
33800
0
26495
52000
Output
21699
Submitted Solution:
```
inputCount = int(input())
prices = [int(input()) for lp in range(inputCount)]
average = sum(prices) // inputCount
print(average)
``` | instruction | 0 | 103,592 | 10 | 207,184 |
Yes | output | 1 | 103,592 | 10 | 207,185 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
I conducted an exit poll of the shopping amount at a department store. Create a program that takes the shopping amount data as input, calculates the average shopping amount per person, and outputs it. The number of people surveyed shall be 100,000 or less, and the shopping amount per person shall not exceed 1 million yen.
Input
The input is given in the following format:
n
v1
v2
::
vn
The first line gives the number of people surveyed n, and the following n lines give the integer vi representing the purchase amount of the ith person.
Output
Please output the average shopping amount (integer: rounded down to the nearest whole number) on one line.
Example
Input
6
12300
5600
33800
0
26495
52000
Output
21699
Submitted Solution:
```
n = int(input())
num = []
for i in range(n):
num.append(int(input()))
print(int(sum(num)/n))
``` | instruction | 0 | 103,593 | 10 | 207,186 |
Yes | output | 1 | 103,593 | 10 | 207,187 |
Provide a correct Python 3 solution for this coding contest problem.
People in Silverland use square coins. Not only they have square shapes but also their values are square numbers. Coins with values of all square numbers up to 289 (= 172), i.e., 1-credit coins, 4-credit coins, 9-credit coins, ..., and 289-credit coins, are available in Silverland.
There are four combinations of coins to pay ten credits:
* ten 1-credit coins,
* one 4-credit coin and six 1-credit coins,
* two 4-credit coins and two 1-credit coins, and
* one 9-credit coin and one 1-credit coin.
Your mission is to count the number of ways to pay a given amount using coins of Silverland.
Input
The input consists of lines each containing an integer meaning an amount to be paid, followed by a line containing a zero. You may assume that all the amounts are positive and less than 300.
Output
For each of the given amount, one line containing a single integer representing the number of combinations of coins should be output. No other characters should appear in the output.
Example
Input
2
10
30
0
Output
1
4
27 | instruction | 0 | 103,612 | 10 | 207,224 |
"Correct Solution:
```
dp=[1]*301
for i in range(2,18):
for j in range(i*i,301):dp[j]+=dp[j-i*i]
while 1:
n=int(input())
if n==0:break
print(dp[n])
``` | output | 1 | 103,612 | 10 | 207,225 |
Provide a correct Python 3 solution for this coding contest problem.
People in Silverland use square coins. Not only they have square shapes but also their values are square numbers. Coins with values of all square numbers up to 289 (= 172), i.e., 1-credit coins, 4-credit coins, 9-credit coins, ..., and 289-credit coins, are available in Silverland.
There are four combinations of coins to pay ten credits:
* ten 1-credit coins,
* one 4-credit coin and six 1-credit coins,
* two 4-credit coins and two 1-credit coins, and
* one 9-credit coin and one 1-credit coin.
Your mission is to count the number of ways to pay a given amount using coins of Silverland.
Input
The input consists of lines each containing an integer meaning an amount to be paid, followed by a line containing a zero. You may assume that all the amounts are positive and less than 300.
Output
For each of the given amount, one line containing a single integer representing the number of combinations of coins should be output. No other characters should appear in the output.
Example
Input
2
10
30
0
Output
1
4
27 | instruction | 0 | 103,613 | 10 | 207,226 |
"Correct Solution:
```
# AOJ 1209: Square Coins
#Python3 2018.7.19 bal4u
dp = [1]*300
for i in range(2, 18):
for j in range(i**2, 300): dp[j] += dp[j-i**2]
while True:
n = int(input())
if n == 0: break
print(dp[n])
``` | output | 1 | 103,613 | 10 | 207,227 |
Provide a correct Python 3 solution for this coding contest problem.
People in Silverland use square coins. Not only they have square shapes but also their values are square numbers. Coins with values of all square numbers up to 289 (= 172), i.e., 1-credit coins, 4-credit coins, 9-credit coins, ..., and 289-credit coins, are available in Silverland.
There are four combinations of coins to pay ten credits:
* ten 1-credit coins,
* one 4-credit coin and six 1-credit coins,
* two 4-credit coins and two 1-credit coins, and
* one 9-credit coin and one 1-credit coin.
Your mission is to count the number of ways to pay a given amount using coins of Silverland.
Input
The input consists of lines each containing an integer meaning an amount to be paid, followed by a line containing a zero. You may assume that all the amounts are positive and less than 300.
Output
For each of the given amount, one line containing a single integer representing the number of combinations of coins should be output. No other characters should appear in the output.
Example
Input
2
10
30
0
Output
1
4
27 | instruction | 0 | 103,614 | 10 | 207,228 |
"Correct Solution:
```
# AOJ 1209: Square Coins
#Python3 2018.7.19 bal4u
N = 18
tbl = [i**2 for i in range(0, N)]
dp = [[0 for j in range(600)] for i in range(N)]
dp[0][0] = 1
for i in range(1, N):
for n in range(300):
dp[i][n] += dp[i-1][n]
for j in range(tbl[i], 300, tbl[i]):
dp[i][n+j] += dp[i-1][n]
while True:
n = int(input())
if n == 0: break
print(dp[N-1][n])
``` | output | 1 | 103,614 | 10 | 207,229 |
Provide a correct Python 3 solution for this coding contest problem.
People in Silverland use square coins. Not only they have square shapes but also their values are square numbers. Coins with values of all square numbers up to 289 (= 172), i.e., 1-credit coins, 4-credit coins, 9-credit coins, ..., and 289-credit coins, are available in Silverland.
There are four combinations of coins to pay ten credits:
* ten 1-credit coins,
* one 4-credit coin and six 1-credit coins,
* two 4-credit coins and two 1-credit coins, and
* one 9-credit coin and one 1-credit coin.
Your mission is to count the number of ways to pay a given amount using coins of Silverland.
Input
The input consists of lines each containing an integer meaning an amount to be paid, followed by a line containing a zero. You may assume that all the amounts are positive and less than 300.
Output
For each of the given amount, one line containing a single integer representing the number of combinations of coins should be output. No other characters should appear in the output.
Example
Input
2
10
30
0
Output
1
4
27 | instruction | 0 | 103,615 | 10 | 207,230 |
"Correct Solution:
```
import sys
readline = sys.stdin.readline
write = sys.stdout.write
dp = [0]*601
dp[0] = 1
V = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289]
for v in V:
for k in range(300, -1, -1):
x = dp[k]
w = v
while k+w <= 300:
dp[k+w] += x
w += v
while 1:
N = int(readline())
if not N:
break
write("%d\n" % dp[N])
``` | output | 1 | 103,615 | 10 | 207,231 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As it has been found out recently, all the Berland's current economical state can be described using a simple table n Γ m in size. n β the number of days in each Berland month, m β the number of months. Thus, a table cell corresponds to a day and a month of the Berland's year. Each cell will contain either 1, or -1, which means the state's gains in a particular month, on a particular day. 1 corresponds to profits, -1 corresponds to losses. It turned out important for successful development to analyze the data on the state of the economy of the previous year, however when the treasurers referred to the archives to retrieve the data, it turned out that the table had been substantially damaged. In some table cells the number values had faded and were impossible to be deciphered. It is known that the number of cells in which the data had been preserved is strictly less than max(n, m). However, there is additional information β the product of the numbers in each line and column equaled -1. Your task is to find out how many different tables may conform to the preserved data. As the answer to the task can be quite large, you have to find it modulo p.
Input
The first line contains integers n and m (1 β€ n, m β€ 1000). The second line contains the integer k (0 β€ k < max(n, m)) β the number of cells in which the data had been preserved. The next k lines contain the data on the state of the table in the preserved cells. Each line is of the form "a b c", where a (1 β€ a β€ n) β the number of the table row, b (1 β€ b β€ m) β the number of the column, c β the value containing in the cell (1 or -1). They are numbered starting from 1. It is guaranteed that no two lines with same a and b values exist. The last line contains an integer p (2 β€ p β€ 109 + 7).
Output
Print the number of different tables that could conform to the preserved data modulo p.
Examples
Input
2 2
0
100
Output
2
Input
2 2
1
1 1 -1
100
Output
1
Submitted Solution:
```
n,m=map(int,input().split())
k=int(input())
A=[[] for i in range(max(n,m))]
for i in range(k):
a,b,c=map(int,input().split())
A[b-1 if n<m else a-1].append(c==-1)
p=int(input())
if n%2!=m%2:
print(0)
exit(0)
r=k
for i in A:
if len(i)>=min(n,m):
if sum(i)%2:
r=-1
else:
print(0)
break
else:
print(pow(2,(n-1)*(m-1)-r,p))
``` | instruction | 0 | 104,013 | 10 | 208,026 |
No | output | 1 | 104,013 | 10 | 208,027 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As it has been found out recently, all the Berland's current economical state can be described using a simple table n Γ m in size. n β the number of days in each Berland month, m β the number of months. Thus, a table cell corresponds to a day and a month of the Berland's year. Each cell will contain either 1, or -1, which means the state's gains in a particular month, on a particular day. 1 corresponds to profits, -1 corresponds to losses. It turned out important for successful development to analyze the data on the state of the economy of the previous year, however when the treasurers referred to the archives to retrieve the data, it turned out that the table had been substantially damaged. In some table cells the number values had faded and were impossible to be deciphered. It is known that the number of cells in which the data had been preserved is strictly less than max(n, m). However, there is additional information β the product of the numbers in each line and column equaled -1. Your task is to find out how many different tables may conform to the preserved data. As the answer to the task can be quite large, you have to find it modulo p.
Input
The first line contains integers n and m (1 β€ n, m β€ 1000). The second line contains the integer k (0 β€ k < max(n, m)) β the number of cells in which the data had been preserved. The next k lines contain the data on the state of the table in the preserved cells. Each line is of the form "a b c", where a (1 β€ a β€ n) β the number of the table row, b (1 β€ b β€ m) β the number of the column, c β the value containing in the cell (1 or -1). They are numbered starting from 1. It is guaranteed that no two lines with same a and b values exist. The last line contains an integer p (2 β€ p β€ 109 + 7).
Output
Print the number of different tables that could conform to the preserved data modulo p.
Examples
Input
2 2
0
100
Output
2
Input
2 2
1
1 1 -1
100
Output
1
Submitted Solution:
```
import itertools
import math
n, m = [int(x) for x in input().split()]
k = int(input())
S = [[] for i in range(max(n,m))]
for i in range(k):
a, b, c = [int(x) for x in input().split()]
if n<m:
S[b-1].append(c==-1)
else:
S[a-1].append(c==-1)
p = int(input())
restrictions = k
for string in S:
if len(string) >= min(n,m):
if sum(string)%2:
restrictions -= 1
else:
print(0)
break
else:
print(pow(2, (n-1)*(m-1) - restrictions, p))
``` | instruction | 0 | 104,014 | 10 | 208,028 |
No | output | 1 | 104,014 | 10 | 208,029 |
Provide a correct Python 3 solution for this coding contest problem.
You have N coins each of which has a value ai. Find the number of combinations that result when you choose K different coins in such a way that the total value of the coins is greater than or equal to L and less than or equal to R.
Constraints
* 1 β€ K β€ N β€ 40
* 1 β€ ai β€ 1016
* 1 β€ L β€ R β€ 1016
* All input values are given in integers
Input
The input is given in the following format.
N K L R
a1 a2 ... aN
Output
Print the number of combinations in a line.
Examples
Input
2 2 1 9
5 1
Output
1
Input
5 2 7 19
3 5 4 2 2
Output
5 | instruction | 0 | 104,390 | 10 | 208,780 |
"Correct Solution:
```
#!python3
from bisect import bisect_left
from collections import defaultdict
from itertools import accumulate
iim = lambda: map(int, input().rstrip().split())
def resolve():
N, K, L, R = iim()
A = list(iim())
n2 = N // 2
def calc(a, b):
d0 = [[] for i in range(K)]
for i in range(a, b):
x = A[i]
for k in range(K-1, 0, -1):
d1 = d0[k-1]
d2 = d0[k]
for v1 in d1:
v1 += x
if v1 > R: continue
d2.append(v1)
d0[0].append(x)
return d0
da = calc(0, n2)
db = calc(n2, N)
for i in range(K-1):
#da[i].sort(reverse=True)
db[i].sort()
ans = 0
for k in range(1, K):
j = K-k-1
d1 = da[k-1]
d2 = db[j]
pos1 = 0
for k1 in d1:
#pos1 = bisect_left(d2, L-k1, pos1)
pos1 = bisect_left(d2, L-k1)
pos2 = bisect_left(d2, R+1-k1, pos1)
#print(k, k1, num1, pos1, pos2)
ans += pos2 - pos1
for dx in [da[-1], db[-1]]:
for val in dx:
if L <= val <= R:
ans += 1
print(ans)
if __name__ == "__main__":
resolve()
``` | output | 1 | 104,390 | 10 | 208,781 |
Provide a correct Python 3 solution for this coding contest problem.
You have N coins each of which has a value ai. Find the number of combinations that result when you choose K different coins in such a way that the total value of the coins is greater than or equal to L and less than or equal to R.
Constraints
* 1 β€ K β€ N β€ 40
* 1 β€ ai β€ 1016
* 1 β€ L β€ R β€ 1016
* All input values are given in integers
Input
The input is given in the following format.
N K L R
a1 a2 ... aN
Output
Print the number of combinations in a line.
Examples
Input
2 2 1 9
5 1
Output
1
Input
5 2 7 19
3 5 4 2 2
Output
5 | instruction | 0 | 104,392 | 10 | 208,784 |
"Correct Solution:
```
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
n,k,l,r = LI()
a = LI()
n1 = n>>1
n2 = n-n1
s1 = [[] for i in range(n1+1)]
s2 = [[] for i in range(n2+1)]
for b in range(1<<n1):
s = 0
j = 0
for i in range(n1):
if not b&(1<<i):
continue
s += a[i]
j += 1
s1[j].append(s)
for b in range(1<<n2):
s = 0
j = 0
for i in range(n2):
if not b&(1<<i):
continue
s += a[i+n1]
j += 1
s2[j].append(s)
for i in range(n2+1):
s2[i].sort()
ans = 0
for i in range(n1+1):
if i > k:
break
j = k-i
if j > n2:
continue
for s in s1[i]:
a,b = bisect.bisect_left(s2[j],l-s),bisect.bisect_right(s2[j],r-s)
ans += b-a
print(ans)
return
#Solve
if __name__ == "__main__":
solve()
``` | output | 1 | 104,392 | 10 | 208,785 |
Provide a correct Python 3 solution for this coding contest problem.
You have N coins each of which has a value ai. Find the number of combinations that result when you choose K different coins in such a way that the total value of the coins is greater than or equal to L and less than or equal to R.
Constraints
* 1 β€ K β€ N β€ 40
* 1 β€ ai β€ 1016
* 1 β€ L β€ R β€ 1016
* All input values are given in integers
Input
The input is given in the following format.
N K L R
a1 a2 ... aN
Output
Print the number of combinations in a line.
Examples
Input
2 2 1 9
5 1
Output
1
Input
5 2 7 19
3 5 4 2 2
Output
5 | instruction | 0 | 104,394 | 10 | 208,788 |
"Correct Solution:
```
# εεε
¨εζ
from bisect import bisect, bisect_left
N, K, L, R = map(int, input().split())
*A, = map(int, input().split())
def enum(A):
n = len(A)
ret = [[] for _ in [0]*(N+1)]
for i in range(1 << n):
sun = 0
cnt = 0
for j, a in enumerate(A):
if i >> j & 1:
sun += a
cnt += 1
ret[cnt].append(sun)
return [sorted(r) for r in ret]
S1 = enum(A[:N//2])
S2 = enum(A[N//2:])
ans = 0
for k, _S1 in enumerate(S1):
if k == K:
l = bisect_left(_S1, L)
r = bisect(_S1, R)
ans += r-l
continue
if K-k < 0:
break
_S2 = S2[K-k]
for a in _S1:
l = bisect_left(_S2, L-a)
r = bisect(_S2, R-a)
ans += r-l
print(ans)
``` | output | 1 | 104,394 | 10 | 208,789 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have N coins each of which has a value ai. Find the number of combinations that result when you choose K different coins in such a way that the total value of the coins is greater than or equal to L and less than or equal to R.
Constraints
* 1 β€ K β€ N β€ 40
* 1 β€ ai β€ 1016
* 1 β€ L β€ R β€ 1016
* All input values are given in integers
Input
The input is given in the following format.
N K L R
a1 a2 ... aN
Output
Print the number of combinations in a line.
Examples
Input
2 2 1 9
5 1
Output
1
Input
5 2 7 19
3 5 4 2 2
Output
5
Submitted Solution:
```
from bisect import bisect_left as bl
from bisect import bisect_right as br
def makeItems(lst, size):
length = len(lst)
ret = [[] for _ in range(size + 2)]
ret[0] = [0]
for a in lst:
for b in range(size, -1, -1):
add = [a + c for c in ret[b]]
ret[b + 1].extend(add)
return ret
def main():
n, k, l, r = map(int, input().split())
aList = list(map(int, input().split()))
aLeft = aList[:n // 2]
aRight = aList[n // 2:]
leftItems = makeItems(aLeft, k)
rightItems = makeItems(aRight, k)
for lst in rightItems:
lst.sort()
ans = 0
for i, lst in enumerate(leftItems):
if i > k:continue
for item in lst:
minLimit = l - item
maxLimit = r - item
left = bl(rightItems[k - i], minLimit)
right = br(rightItems[k - i], maxLimit)
ans += right - left
print(ans)
main()
``` | instruction | 0 | 104,400 | 10 | 208,800 |
Yes | output | 1 | 104,400 | 10 | 208,801 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.
Sasha and Masha are about to buy some coconuts which are sold at price z chizhiks per coconut. Sasha has x chizhiks, Masha has y chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.
The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.
Consider the following example. Suppose Sasha has 5 chizhiks, Masha has 4 chizhiks, and the price for one coconut be 3 chizhiks. If the girls don't exchange with chizhiks, they will buy 1 + 1 = 2 coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have 6 chizhiks, Masha will have 3 chizhiks, and the girls will buy 2 + 1 = 3 coconuts.
It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Input
The first line contains three integers x, y and z (0 β€ x, y β€ 10^{18}, 1 β€ z β€ 10^{18}) β the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
Output
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
Examples
Input
5 4 3
Output
3 1
Input
6 8 2
Output
7 0
Note
The first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy 3 + 4 = 7 coconuts. | instruction | 0 | 104,487 | 10 | 208,974 |
Tags: greedy, math
Correct Solution:
```
x,y,z=map(int,input().split())
print((x+y)//z,end=" ")
a=x%z
b=y%z
if a+b>=z:
print(z-max(a,b))
else:
print("0")
``` | output | 1 | 104,487 | 10 | 208,975 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.
Sasha and Masha are about to buy some coconuts which are sold at price z chizhiks per coconut. Sasha has x chizhiks, Masha has y chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.
The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.
Consider the following example. Suppose Sasha has 5 chizhiks, Masha has 4 chizhiks, and the price for one coconut be 3 chizhiks. If the girls don't exchange with chizhiks, they will buy 1 + 1 = 2 coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have 6 chizhiks, Masha will have 3 chizhiks, and the girls will buy 2 + 1 = 3 coconuts.
It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Input
The first line contains three integers x, y and z (0 β€ x, y β€ 10^{18}, 1 β€ z β€ 10^{18}) β the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
Output
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
Examples
Input
5 4 3
Output
3 1
Input
6 8 2
Output
7 0
Note
The first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy 3 + 4 = 7 coconuts. | instruction | 0 | 104,488 | 10 | 208,976 |
Tags: greedy, math
Correct Solution:
```
x, y, z = [int(i) for i in input().split()]
ans = 0
al = (x + y) // z
if x // z + y // z == al:
print(al, 0)
else:
print(al, min(z - (x % z), z - (y % z)))
``` | output | 1 | 104,488 | 10 | 208,977 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.
Sasha and Masha are about to buy some coconuts which are sold at price z chizhiks per coconut. Sasha has x chizhiks, Masha has y chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.
The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.
Consider the following example. Suppose Sasha has 5 chizhiks, Masha has 4 chizhiks, and the price for one coconut be 3 chizhiks. If the girls don't exchange with chizhiks, they will buy 1 + 1 = 2 coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have 6 chizhiks, Masha will have 3 chizhiks, and the girls will buy 2 + 1 = 3 coconuts.
It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Input
The first line contains three integers x, y and z (0 β€ x, y β€ 10^{18}, 1 β€ z β€ 10^{18}) β the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
Output
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
Examples
Input
5 4 3
Output
3 1
Input
6 8 2
Output
7 0
Note
The first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy 3 + 4 = 7 coconuts. | instruction | 0 | 104,489 | 10 | 208,978 |
Tags: greedy, math
Correct Solution:
```
n,m,k = map(int,input().split())
a = n%k
if a:
a = k-a
b = m%k
if b:
b = k-b
if ((n+a)//k + (m-a)//k) > ((n-b)//k + (m+b)//k):
if ((n+a)//k + (m-a)//k) == (n//k + m//k):
print(((n+a)//k + (m-a)//k),0)
else:
print(((n+a)//k + (m-a)//k),a)
elif ((n+a)//k + (m-a)//k) == ((n-b)//k + (m+b)//k):
if (n+a)//k + (m-a)//k == (n//k + m//k):
print((n//k + m//k),0)
elif a>b:
print(((n-b)//k + (m+b)//k),b)
else:
print(((n-b)//k + (m+b)//k),a)
else:
if (n//k + m//k) == ((n-b)//k + (m+b)//k):
print(((n-b)//k + (m+b)//k),0)
else:
print(((n-b)//k + (m+b)//k),b)
``` | output | 1 | 104,489 | 10 | 208,979 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.
Sasha and Masha are about to buy some coconuts which are sold at price z chizhiks per coconut. Sasha has x chizhiks, Masha has y chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.
The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.
Consider the following example. Suppose Sasha has 5 chizhiks, Masha has 4 chizhiks, and the price for one coconut be 3 chizhiks. If the girls don't exchange with chizhiks, they will buy 1 + 1 = 2 coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have 6 chizhiks, Masha will have 3 chizhiks, and the girls will buy 2 + 1 = 3 coconuts.
It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Input
The first line contains three integers x, y and z (0 β€ x, y β€ 10^{18}, 1 β€ z β€ 10^{18}) β the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
Output
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
Examples
Input
5 4 3
Output
3 1
Input
6 8 2
Output
7 0
Note
The first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy 3 + 4 = 7 coconuts. | instruction | 0 | 104,490 | 10 | 208,980 |
Tags: greedy, math
Correct Solution:
```
Input=lambda:map(int,input().split())
x,y,z = Input()
print((x+y)//z,end = " ")
Coconut = x//z
x%=z
Coconut += y//z
y%=z
r = (x+y)//z
Coconut+=r
if r == 0:
print(0)
else:
print(min(x,y)-((x+y)%z))
'''
openvpn
vpnbook
sEN6DC9
'''
``` | output | 1 | 104,490 | 10 | 208,981 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.
Sasha and Masha are about to buy some coconuts which are sold at price z chizhiks per coconut. Sasha has x chizhiks, Masha has y chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.
The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.
Consider the following example. Suppose Sasha has 5 chizhiks, Masha has 4 chizhiks, and the price for one coconut be 3 chizhiks. If the girls don't exchange with chizhiks, they will buy 1 + 1 = 2 coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have 6 chizhiks, Masha will have 3 chizhiks, and the girls will buy 2 + 1 = 3 coconuts.
It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Input
The first line contains three integers x, y and z (0 β€ x, y β€ 10^{18}, 1 β€ z β€ 10^{18}) β the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
Output
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
Examples
Input
5 4 3
Output
3 1
Input
6 8 2
Output
7 0
Note
The first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy 3 + 4 = 7 coconuts. | instruction | 0 | 104,491 | 10 | 208,982 |
Tags: greedy, math
Correct Solution:
```
x,y,z = map(int , input().split())
temp = (x+y)//z
a = z-(x%z)
b = z-(y%z)
if temp == x//z + y//z :
print("{} 0".format(temp))
else:
temp2 = min(a,b)
print("{} {}".format(temp , temp2))
``` | output | 1 | 104,491 | 10 | 208,983 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.
Sasha and Masha are about to buy some coconuts which are sold at price z chizhiks per coconut. Sasha has x chizhiks, Masha has y chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.
The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.
Consider the following example. Suppose Sasha has 5 chizhiks, Masha has 4 chizhiks, and the price for one coconut be 3 chizhiks. If the girls don't exchange with chizhiks, they will buy 1 + 1 = 2 coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have 6 chizhiks, Masha will have 3 chizhiks, and the girls will buy 2 + 1 = 3 coconuts.
It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Input
The first line contains three integers x, y and z (0 β€ x, y β€ 10^{18}, 1 β€ z β€ 10^{18}) β the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
Output
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
Examples
Input
5 4 3
Output
3 1
Input
6 8 2
Output
7 0
Note
The first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy 3 + 4 = 7 coconuts. | instruction | 0 | 104,492 | 10 | 208,984 |
Tags: greedy, math
Correct Solution:
```
x, y, z = list(map(int,input().split()))
# no_of_coconuts = (x//z) + (y//z)
no_of_coconuts = (x+y) // z
x_money_left = x % z
y_money_left = y % z
minimum = min(x_money_left,y_money_left)
maximum = max(x_money_left,y_money_left)
coconut = (maximum + minimum) //z
if coconut == 0:
print(no_of_coconuts, 0)
else:
coconut_price = (coconut * z) - maximum
print(no_of_coconuts, coconut_price)
``` | output | 1 | 104,492 | 10 | 208,985 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.
Sasha and Masha are about to buy some coconuts which are sold at price z chizhiks per coconut. Sasha has x chizhiks, Masha has y chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.
The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.
Consider the following example. Suppose Sasha has 5 chizhiks, Masha has 4 chizhiks, and the price for one coconut be 3 chizhiks. If the girls don't exchange with chizhiks, they will buy 1 + 1 = 2 coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have 6 chizhiks, Masha will have 3 chizhiks, and the girls will buy 2 + 1 = 3 coconuts.
It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Input
The first line contains three integers x, y and z (0 β€ x, y β€ 10^{18}, 1 β€ z β€ 10^{18}) β the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
Output
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
Examples
Input
5 4 3
Output
3 1
Input
6 8 2
Output
7 0
Note
The first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy 3 + 4 = 7 coconuts. | instruction | 0 | 104,493 | 10 | 208,986 |
Tags: greedy, math
Correct Solution:
```
# Chunga-Changa
# from collections import Counter
x, y, z = list(map(int, input().split()))
max_coc = (x + y) // z
if (x // z) + (y // z) == max_coc:
give = 0
else:
r1 = x % z
r2 = y % z
give = min(r1, r2, z - r1, z - r2)
print(max_coc, give)
``` | output | 1 | 104,493 | 10 | 208,987 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.
Sasha and Masha are about to buy some coconuts which are sold at price z chizhiks per coconut. Sasha has x chizhiks, Masha has y chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.
The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.
Consider the following example. Suppose Sasha has 5 chizhiks, Masha has 4 chizhiks, and the price for one coconut be 3 chizhiks. If the girls don't exchange with chizhiks, they will buy 1 + 1 = 2 coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have 6 chizhiks, Masha will have 3 chizhiks, and the girls will buy 2 + 1 = 3 coconuts.
It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Input
The first line contains three integers x, y and z (0 β€ x, y β€ 10^{18}, 1 β€ z β€ 10^{18}) β the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
Output
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
Examples
Input
5 4 3
Output
3 1
Input
6 8 2
Output
7 0
Note
The first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy 3 + 4 = 7 coconuts. | instruction | 0 | 104,494 | 10 | 208,988 |
Tags: greedy, math
Correct Solution:
```
x,y,z = list(map(int,input().split()))
if x%z+y%z<z: #Π΅ΡΠ»ΠΈ Π·Π° ΠΎΡΡΠ°ΡΠΊΠΈ ΠΌΠΎΠΆΠ½ΠΎ ΠΊΡΠΏΠΈΡΡ ΠΊΠΎΠΊΠΎΡ
print(x//z+y//z,0)
else:
if x%z>=y%z:print(x//z+y//z+1,z-x%z)
else:print(x//z+y//z+1,z-y%z)
``` | output | 1 | 104,494 | 10 | 208,989 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.
Sasha and Masha are about to buy some coconuts which are sold at price z chizhiks per coconut. Sasha has x chizhiks, Masha has y chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.
The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.
Consider the following example. Suppose Sasha has 5 chizhiks, Masha has 4 chizhiks, and the price for one coconut be 3 chizhiks. If the girls don't exchange with chizhiks, they will buy 1 + 1 = 2 coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have 6 chizhiks, Masha will have 3 chizhiks, and the girls will buy 2 + 1 = 3 coconuts.
It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Input
The first line contains three integers x, y and z (0 β€ x, y β€ 10^{18}, 1 β€ z β€ 10^{18}) β the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
Output
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
Examples
Input
5 4 3
Output
3 1
Input
6 8 2
Output
7 0
Note
The first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy 3 + 4 = 7 coconuts.
Submitted Solution:
```
x, y, z = [int(i) for i in input().split()]
m = (x + y) // z
if x // z + y // z == m:
print(m, 0)
else:
print(m, min(z - x % z, z - y % z))
``` | instruction | 0 | 104,495 | 10 | 208,990 |
Yes | output | 1 | 104,495 | 10 | 208,991 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.
Sasha and Masha are about to buy some coconuts which are sold at price z chizhiks per coconut. Sasha has x chizhiks, Masha has y chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.
The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.
Consider the following example. Suppose Sasha has 5 chizhiks, Masha has 4 chizhiks, and the price for one coconut be 3 chizhiks. If the girls don't exchange with chizhiks, they will buy 1 + 1 = 2 coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have 6 chizhiks, Masha will have 3 chizhiks, and the girls will buy 2 + 1 = 3 coconuts.
It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Input
The first line contains three integers x, y and z (0 β€ x, y β€ 10^{18}, 1 β€ z β€ 10^{18}) β the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
Output
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
Examples
Input
5 4 3
Output
3 1
Input
6 8 2
Output
7 0
Note
The first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy 3 + 4 = 7 coconuts.
Submitted Solution:
```
X, Y, Z = map(int, input().split())
a = (X+Y)//Z
n = X//Z + Y//Z
if a == n:
b = 0
else:
b = min(Z-X%Z, Z-Y%Z)
print(a,b)
``` | instruction | 0 | 104,496 | 10 | 208,992 |
Yes | output | 1 | 104,496 | 10 | 208,993 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.
Sasha and Masha are about to buy some coconuts which are sold at price z chizhiks per coconut. Sasha has x chizhiks, Masha has y chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.
The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.
Consider the following example. Suppose Sasha has 5 chizhiks, Masha has 4 chizhiks, and the price for one coconut be 3 chizhiks. If the girls don't exchange with chizhiks, they will buy 1 + 1 = 2 coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have 6 chizhiks, Masha will have 3 chizhiks, and the girls will buy 2 + 1 = 3 coconuts.
It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Input
The first line contains three integers x, y and z (0 β€ x, y β€ 10^{18}, 1 β€ z β€ 10^{18}) β the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
Output
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
Examples
Input
5 4 3
Output
3 1
Input
6 8 2
Output
7 0
Note
The first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy 3 + 4 = 7 coconuts.
Submitted Solution:
```
x, y, z = [int(i) for i in input().split()]
totalCoco = (x+y)//z
sashaCoco = x//z
mashaCoco = y//z
if sashaCoco + mashaCoco == totalCoco:
print(totalCoco, 0)
else:
print(totalCoco, z-max(x % z, y % z))
``` | instruction | 0 | 104,497 | 10 | 208,994 |
Yes | output | 1 | 104,497 | 10 | 208,995 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.
Sasha and Masha are about to buy some coconuts which are sold at price z chizhiks per coconut. Sasha has x chizhiks, Masha has y chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.
The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.
Consider the following example. Suppose Sasha has 5 chizhiks, Masha has 4 chizhiks, and the price for one coconut be 3 chizhiks. If the girls don't exchange with chizhiks, they will buy 1 + 1 = 2 coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have 6 chizhiks, Masha will have 3 chizhiks, and the girls will buy 2 + 1 = 3 coconuts.
It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Input
The first line contains three integers x, y and z (0 β€ x, y β€ 10^{18}, 1 β€ z β€ 10^{18}) β the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
Output
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
Examples
Input
5 4 3
Output
3 1
Input
6 8 2
Output
7 0
Note
The first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy 3 + 4 = 7 coconuts.
Submitted Solution:
```
x,y,z = map(int,input().split());
re1 = x%z;
re2 = y%z;
no = x//z + y//z;
if(re1+re2<z):
print(str(no)+" 0");
else:
if(re1>=re2):
res = z - re1;
no=no+1;
print(str(no)+" "+str(res));
else:
res = z - re2;
no=no+1;
print(str(no)+" "+str(res));
``` | instruction | 0 | 104,498 | 10 | 208,996 |
Yes | output | 1 | 104,498 | 10 | 208,997 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.
Sasha and Masha are about to buy some coconuts which are sold at price z chizhiks per coconut. Sasha has x chizhiks, Masha has y chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.
The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.
Consider the following example. Suppose Sasha has 5 chizhiks, Masha has 4 chizhiks, and the price for one coconut be 3 chizhiks. If the girls don't exchange with chizhiks, they will buy 1 + 1 = 2 coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have 6 chizhiks, Masha will have 3 chizhiks, and the girls will buy 2 + 1 = 3 coconuts.
It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Input
The first line contains three integers x, y and z (0 β€ x, y β€ 10^{18}, 1 β€ z β€ 10^{18}) β the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
Output
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
Examples
Input
5 4 3
Output
3 1
Input
6 8 2
Output
7 0
Note
The first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy 3 + 4 = 7 coconuts.
Submitted Solution:
```
x,y,z=(int(x) for x in input().split())
coconut=int(x/z)+int(y/z)
sasha_rem=x%z
masha_rem=y%z
rem_coconut=int((sasha_rem+masha_rem)/z)
if rem_coconut!=0:
coconut+=rem_coconut
sasha_rem=z-sasha_rem
masha_rem=z-masha_rem
if sasha_rem>masha_rem:
print(coconut,masha_rem)
else:
print(coconut,sasha_rem)
else:
print(coconut, 0)
``` | instruction | 0 | 104,499 | 10 | 208,998 |
No | output | 1 | 104,499 | 10 | 208,999 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.
Sasha and Masha are about to buy some coconuts which are sold at price z chizhiks per coconut. Sasha has x chizhiks, Masha has y chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.
The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.
Consider the following example. Suppose Sasha has 5 chizhiks, Masha has 4 chizhiks, and the price for one coconut be 3 chizhiks. If the girls don't exchange with chizhiks, they will buy 1 + 1 = 2 coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have 6 chizhiks, Masha will have 3 chizhiks, and the girls will buy 2 + 1 = 3 coconuts.
It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Input
The first line contains three integers x, y and z (0 β€ x, y β€ 10^{18}, 1 β€ z β€ 10^{18}) β the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
Output
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
Examples
Input
5 4 3
Output
3 1
Input
6 8 2
Output
7 0
Note
The first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy 3 + 4 = 7 coconuts.
Submitted Solution:
```
inputs = input().split(' ')
x = int(inputs[0])
y = int(inputs[1])
z = int(inputs[2])
exchange = 0
coconuts = 0
small = min(x, y)
if x + y % z == 0:
coconuts = x + y // z
exchange = small % z;
else:
coconuts = (x + y) // z
exchange = small % z
print (coconuts, exchange)
``` | instruction | 0 | 104,500 | 10 | 209,000 |
No | output | 1 | 104,500 | 10 | 209,001 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.
Sasha and Masha are about to buy some coconuts which are sold at price z chizhiks per coconut. Sasha has x chizhiks, Masha has y chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.
The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.
Consider the following example. Suppose Sasha has 5 chizhiks, Masha has 4 chizhiks, and the price for one coconut be 3 chizhiks. If the girls don't exchange with chizhiks, they will buy 1 + 1 = 2 coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have 6 chizhiks, Masha will have 3 chizhiks, and the girls will buy 2 + 1 = 3 coconuts.
It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Input
The first line contains three integers x, y and z (0 β€ x, y β€ 10^{18}, 1 β€ z β€ 10^{18}) β the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
Output
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
Examples
Input
5 4 3
Output
3 1
Input
6 8 2
Output
7 0
Note
The first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy 3 + 4 = 7 coconuts.
Submitted Solution:
```
x, y, z = [int(x) for x in input().split(' ')]
x1 = x // z
y1 = y // z
z1 = (x + y) // z
if x1 + y1 == z1:
print(z1, 0)
else:
print(z1, min(max(x, z) % min(x, z), max(y, z) % min(y, z)))
``` | instruction | 0 | 104,501 | 10 | 209,002 |
No | output | 1 | 104,501 | 10 | 209,003 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.
Sasha and Masha are about to buy some coconuts which are sold at price z chizhiks per coconut. Sasha has x chizhiks, Masha has y chizhiks. Each girl will buy as many coconuts as she can using only her money. This way each girl will buy an integer non-negative number of coconuts.
The girls discussed their plans and found that the total number of coconuts they buy can increase (or decrease) if one of them gives several chizhiks to the other girl. The chizhiks can't be split in parts, so the girls can only exchange with integer number of chizhiks.
Consider the following example. Suppose Sasha has 5 chizhiks, Masha has 4 chizhiks, and the price for one coconut be 3 chizhiks. If the girls don't exchange with chizhiks, they will buy 1 + 1 = 2 coconuts. However, if, for example, Masha gives Sasha one chizhik, then Sasha will have 6 chizhiks, Masha will have 3 chizhiks, and the girls will buy 2 + 1 = 3 coconuts.
It is not that easy to live on the island now, so Sasha and Mash want to exchange with chizhiks in such a way that they will buy the maximum possible number of coconuts. Nobody wants to have a debt, so among all possible ways to buy the maximum possible number of coconuts find such a way that minimizes the number of chizhiks one girl gives to the other (it is not important who will be the person giving the chizhiks).
Input
The first line contains three integers x, y and z (0 β€ x, y β€ 10^{18}, 1 β€ z β€ 10^{18}) β the number of chizhics Sasha has, the number of chizhics Masha has and the price of a coconut.
Output
Print two integers: the maximum possible number of coconuts the girls can buy and the minimum number of chizhiks one girl has to give to the other.
Examples
Input
5 4 3
Output
3 1
Input
6 8 2
Output
7 0
Note
The first example is described in the statement. In the second example the optimal solution is to dot exchange any chizhiks. The girls will buy 3 + 4 = 7 coconuts.
Submitted Solution:
```
z,c,a=list(map(int,input().split()))
if z%a>c%a:print((z+c%a+c-c%a)//a,c%a,end=' ')
elif c%a>z%a:print((c+z%a+z-z%a)//a,z%a,end=' ')
elif z%a==c%a:print((z+c)//a,0,end=' ')
``` | instruction | 0 | 104,502 | 10 | 209,004 |
No | output | 1 | 104,502 | 10 | 209,005 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Berland shop sells n kinds of juices. Each juice has its price c_i. Each juice includes some set of vitamins in it. There are three types of vitamins: vitamin "A", vitamin "B" and vitamin "C". Each juice can contain one, two or all three types of vitamins in it.
Petya knows that he needs all three types of vitamins to stay healthy. What is the minimum total price of juices that Petya has to buy to obtain all three vitamins? Petya obtains some vitamin if he buys at least one juice containing it and drinks it.
Input
The first line contains a single integer n (1 β€ n β€ 1 000) β the number of juices.
Each of the next n lines contains an integer c_i (1 β€ c_i β€ 100 000) and a string s_i β the price of the i-th juice and the vitamins it contains. String s_i contains from 1 to 3 characters, and the only possible characters are "A", "B" and "C". It is guaranteed that each letter appears no more than once in each string s_i. The order of letters in strings s_i is arbitrary.
Output
Print -1 if there is no way to obtain all three vitamins. Otherwise print the minimum total price of juices that Petya has to buy to obtain all three vitamins.
Examples
Input
4
5 C
6 B
16 BAC
4 A
Output
15
Input
2
10 AB
15 BA
Output
-1
Input
5
10 A
9 BC
11 CA
4 A
5 B
Output
13
Input
6
100 A
355 BCA
150 BC
160 AC
180 B
190 CA
Output
250
Input
2
5 BA
11 CB
Output
16
Note
In the first example Petya buys the first, the second and the fourth juice. He spends 5 + 6 + 4 = 15 and obtains all three vitamins. He can also buy just the third juice and obtain three vitamins, but its cost is 16, which isn't optimal.
In the second example Petya can't obtain all three vitamins, as no juice contains vitamin "C". | instruction | 0 | 105,254 | 10 | 210,508 |
Tags: bitmasks, brute force, dp, implementation
Correct Solution:
```
n=int(input())
d={"A":10000000,"B":1000000000,"C":1000000000,"AB":1000000000,"BC":1000000000,"AC":10000000000,"ABC":10000000000}
for i in range(n):
a1,a2=map(str,input().strip().split())
l1=list(a2)
l1.sort()
a2="".join(l1)
a1=int(a1)
d[a2]=min(a1,d[a2])
o=min(d["A"]+d["B"]+d["C"],d["A"]+d["BC"],d["B"]+d["AC"],d["C"]+d["AB"],d["AB"]+d["BC"],d["AC"]+d["AB"],d["AC"]+d["BC"],d["ABC"])
if (o>300000):
print (-1)
else:
print (o)
``` | output | 1 | 105,254 | 10 | 210,509 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Berland shop sells n kinds of juices. Each juice has its price c_i. Each juice includes some set of vitamins in it. There are three types of vitamins: vitamin "A", vitamin "B" and vitamin "C". Each juice can contain one, two or all three types of vitamins in it.
Petya knows that he needs all three types of vitamins to stay healthy. What is the minimum total price of juices that Petya has to buy to obtain all three vitamins? Petya obtains some vitamin if he buys at least one juice containing it and drinks it.
Input
The first line contains a single integer n (1 β€ n β€ 1 000) β the number of juices.
Each of the next n lines contains an integer c_i (1 β€ c_i β€ 100 000) and a string s_i β the price of the i-th juice and the vitamins it contains. String s_i contains from 1 to 3 characters, and the only possible characters are "A", "B" and "C". It is guaranteed that each letter appears no more than once in each string s_i. The order of letters in strings s_i is arbitrary.
Output
Print -1 if there is no way to obtain all three vitamins. Otherwise print the minimum total price of juices that Petya has to buy to obtain all three vitamins.
Examples
Input
4
5 C
6 B
16 BAC
4 A
Output
15
Input
2
10 AB
15 BA
Output
-1
Input
5
10 A
9 BC
11 CA
4 A
5 B
Output
13
Input
6
100 A
355 BCA
150 BC
160 AC
180 B
190 CA
Output
250
Input
2
5 BA
11 CB
Output
16
Note
In the first example Petya buys the first, the second and the fourth juice. He spends 5 + 6 + 4 = 15 and obtains all three vitamins. He can also buy just the third juice and obtain three vitamins, but its cost is 16, which isn't optimal.
In the second example Petya can't obtain all three vitamins, as no juice contains vitamin "C". | instruction | 0 | 105,255 | 10 | 210,510 |
Tags: bitmasks, brute force, dp, implementation
Correct Solution:
```
# inpt=input()
# l=inpt.split(" ")
# a=int(l[0])
# b=int(l[1])
# x=int(l[2])
# y=int(l[3])
# def prime(x,y):
# for i in range(2,max(x,y)):
# while x%i==0 and y%i==0:
# x= x/i
# y= y/i
# return [x,y]
# print (int(min(a/int(prime(x,y)[0]), b/int(prime(x,y)[1]))))
n=int(input())
l=[]
min_a=100001
min_b=100001
min_c=100001
min_abc=100001
def find(x,y):
for i in x:
if i==y:
return True
for i in range(n):
juice=input()
l.append(juice.split())
for i in range(n):
if l[i][1]=="A":
if int(l[i][0])<min_a:
min_a=int(l[i][0])
elif l[i][1]=="B":
if int(l[i][0])<min_b:
min_b=int(l[i][0])
elif l[i][1]=="C":
if int(l[i][0])<min_c:
min_c=int(l[i][0])
min1=300001
bad=True
for d in range(n):
for c in range(n):
all=l[d][1] + l[c][1]
# print (all)
if find(all, "A")==True and find(all,"B")==True and find(all,"C")==True:
# print ("yaay")
bad=False
if min1> int(l[d][0])+ int(l[c][0]):
min1=int(l[d][0])+ int(l[c][0])
if min_a!=100001 and min_b!=100001 and min_c!=100001:
price=min_a + min_b + min_c
else:
price=-1
for i in range(n):
if find(l[i][1],"A")==True and find(l[i][1],"B")==True and find(l[i][1],"C")==True:
if int(l[i][0])<min_abc:
min_abc=int(l[i][0])
if min_abc!=100001 and bad==False and price!= -1:
print(min(price,min_abc,min1))
elif min_abc!=100001 and bad==False:
print(min(min_abc,min1))
elif bad==False and price!= -1:
print(min(price,min1))
elif min_abc!=100001 and price!= -1:
print(min(price,min_abc))
elif min_abc!=100001 :
print(min_abc)
elif bad==False :
print(min1)
elif price!= -1:
print(price)
else:
print("-1")
``` | output | 1 | 105,255 | 10 | 210,511 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Berland shop sells n kinds of juices. Each juice has its price c_i. Each juice includes some set of vitamins in it. There are three types of vitamins: vitamin "A", vitamin "B" and vitamin "C". Each juice can contain one, two or all three types of vitamins in it.
Petya knows that he needs all three types of vitamins to stay healthy. What is the minimum total price of juices that Petya has to buy to obtain all three vitamins? Petya obtains some vitamin if he buys at least one juice containing it and drinks it.
Input
The first line contains a single integer n (1 β€ n β€ 1 000) β the number of juices.
Each of the next n lines contains an integer c_i (1 β€ c_i β€ 100 000) and a string s_i β the price of the i-th juice and the vitamins it contains. String s_i contains from 1 to 3 characters, and the only possible characters are "A", "B" and "C". It is guaranteed that each letter appears no more than once in each string s_i. The order of letters in strings s_i is arbitrary.
Output
Print -1 if there is no way to obtain all three vitamins. Otherwise print the minimum total price of juices that Petya has to buy to obtain all three vitamins.
Examples
Input
4
5 C
6 B
16 BAC
4 A
Output
15
Input
2
10 AB
15 BA
Output
-1
Input
5
10 A
9 BC
11 CA
4 A
5 B
Output
13
Input
6
100 A
355 BCA
150 BC
160 AC
180 B
190 CA
Output
250
Input
2
5 BA
11 CB
Output
16
Note
In the first example Petya buys the first, the second and the fourth juice. He spends 5 + 6 + 4 = 15 and obtains all three vitamins. He can also buy just the third juice and obtain three vitamins, but its cost is 16, which isn't optimal.
In the second example Petya can't obtain all three vitamins, as no juice contains vitamin "C". | instruction | 0 | 105,256 | 10 | 210,512 |
Tags: bitmasks, brute force, dp, implementation
Correct Solution:
```
from sys import stdin
input=lambda : stdin.readline()
from math import ceil,sqrt,gcd
a=[]
b=[]
c=[]
ab=[]
bc=[]
ac=[]
abc=[]
for i in range(int(input())):
n,s=input().split()
if {'A'}==set(list(s)):
a.append(int(n))
elif {'B'}==set(list(s)):
b.append(int(n))
elif {'C'}==set(list(s)):
c.append(int(n))
elif {'B','C'}==set(list(s)):
bc.append(int(n))
elif {'A','B'}==set(list(s)):
ab.append(int(n))
elif {'A','C'}==set(list(s)):
ac.append(int(n))
elif {'A','B','C'}==set(list(s)):
abc.append(int(n))
abc.sort()
bc.sort()
ac.sort()
ab.sort()
c.sort()
a.sort()
b.sort()
m=1000000000000000000
if len(a)>0 and len(b)>0 and len(c)>0:
m=min(m,a[0]+b[0]+c[0])
if len(ab)>0 and len(c)>0:
m=min(m,ab[0]+c[0])
if len(bc)>0 and len(a)>0:
m=min(m,bc[0]+a[0])
if len(ac)>0 and len(b)>0:
m=min(m,ac[0]+b[0])
if len(abc)>0:
m=min(abc[0],m)
if len(ab)>0 and len(bc)>0:
m=min(m,ab[0]+bc[0])
if len(ab)>0 and len(ac)>0:
m=min(m,ab[0]+ac[0])
if len(ac)>0 and len(bc)>0:
m=min(m,ac[0]+bc[0])
if m==1000000000000000000:
print(-1)
else:
print(m)
# print(a,b,c)
``` | output | 1 | 105,256 | 10 | 210,513 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Berland shop sells n kinds of juices. Each juice has its price c_i. Each juice includes some set of vitamins in it. There are three types of vitamins: vitamin "A", vitamin "B" and vitamin "C". Each juice can contain one, two or all three types of vitamins in it.
Petya knows that he needs all three types of vitamins to stay healthy. What is the minimum total price of juices that Petya has to buy to obtain all three vitamins? Petya obtains some vitamin if he buys at least one juice containing it and drinks it.
Input
The first line contains a single integer n (1 β€ n β€ 1 000) β the number of juices.
Each of the next n lines contains an integer c_i (1 β€ c_i β€ 100 000) and a string s_i β the price of the i-th juice and the vitamins it contains. String s_i contains from 1 to 3 characters, and the only possible characters are "A", "B" and "C". It is guaranteed that each letter appears no more than once in each string s_i. The order of letters in strings s_i is arbitrary.
Output
Print -1 if there is no way to obtain all three vitamins. Otherwise print the minimum total price of juices that Petya has to buy to obtain all three vitamins.
Examples
Input
4
5 C
6 B
16 BAC
4 A
Output
15
Input
2
10 AB
15 BA
Output
-1
Input
5
10 A
9 BC
11 CA
4 A
5 B
Output
13
Input
6
100 A
355 BCA
150 BC
160 AC
180 B
190 CA
Output
250
Input
2
5 BA
11 CB
Output
16
Note
In the first example Petya buys the first, the second and the fourth juice. He spends 5 + 6 + 4 = 15 and obtains all three vitamins. He can also buy just the third juice and obtain three vitamins, but its cost is 16, which isn't optimal.
In the second example Petya can't obtain all three vitamins, as no juice contains vitamin "C". | instruction | 0 | 105,257 | 10 | 210,514 |
Tags: bitmasks, brute force, dp, implementation
Correct Solution:
```
def dp(a):
d={}
for i in a:
x=i[1]
l="".join(sorted(list(set(x))))
d[l]=min(d.get(l,float("inf")),i[0])
for j in set(x):
d[j]=min(d.get(j,float("inf")),i[0])
ans=[]
for word in d.keys():
t=d[word]
for l in "ABC":
if l not in word:
t+=d.get(l,float("inf"))
ans.append(t)
rr=min(ans)
if rr==float("inf"):
return -1
return rr
blanck=[]
for i in range(int(input())):
a,b=map(str,input().strip().split())
blanck.append((int(a),b))
print(dp(blanck))
``` | output | 1 | 105,257 | 10 | 210,515 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Berland shop sells n kinds of juices. Each juice has its price c_i. Each juice includes some set of vitamins in it. There are three types of vitamins: vitamin "A", vitamin "B" and vitamin "C". Each juice can contain one, two or all three types of vitamins in it.
Petya knows that he needs all three types of vitamins to stay healthy. What is the minimum total price of juices that Petya has to buy to obtain all three vitamins? Petya obtains some vitamin if he buys at least one juice containing it and drinks it.
Input
The first line contains a single integer n (1 β€ n β€ 1 000) β the number of juices.
Each of the next n lines contains an integer c_i (1 β€ c_i β€ 100 000) and a string s_i β the price of the i-th juice and the vitamins it contains. String s_i contains from 1 to 3 characters, and the only possible characters are "A", "B" and "C". It is guaranteed that each letter appears no more than once in each string s_i. The order of letters in strings s_i is arbitrary.
Output
Print -1 if there is no way to obtain all three vitamins. Otherwise print the minimum total price of juices that Petya has to buy to obtain all three vitamins.
Examples
Input
4
5 C
6 B
16 BAC
4 A
Output
15
Input
2
10 AB
15 BA
Output
-1
Input
5
10 A
9 BC
11 CA
4 A
5 B
Output
13
Input
6
100 A
355 BCA
150 BC
160 AC
180 B
190 CA
Output
250
Input
2
5 BA
11 CB
Output
16
Note
In the first example Petya buys the first, the second and the fourth juice. He spends 5 + 6 + 4 = 15 and obtains all three vitamins. He can also buy just the third juice and obtain three vitamins, but its cost is 16, which isn't optimal.
In the second example Petya can't obtain all three vitamins, as no juice contains vitamin "C". | instruction | 0 | 105,258 | 10 | 210,516 |
Tags: bitmasks, brute force, dp, implementation
Correct Solution:
```
A = [10**10]*7
n = int(input())
for i in range(n):
price, vito = input().split()
price = int(price)
if "A" in vito and "B" in vito and "C" in vito:
if price < A[6]:
A[6] = price
elif "B" in vito and "C" in vito:
if price < A[5]:
A[5] = price
elif "A" in vito and "B" in vito:
if price < A[4]:
A[4] = price
elif "A" in vito and "C" in vito:
if price < A[3]:
A[3] = price
elif "C" in vito:
if price < A[2]:
A[2] = price
elif "B" in vito:
if price < A[1]:
A[1] = price
else:
if price < A[0]:
A[0] = price
A[6] = min(A[6], A[5]+A[0], A[4]+A[2], A[3]+A[1], A[0]+A[1]+A[2], A[3]+A[5], A[3]+A[4], A[4]+A[5])
if A[6] == 10**10:
print(-1)
else:
print(A[6])
``` | output | 1 | 105,258 | 10 | 210,517 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Berland shop sells n kinds of juices. Each juice has its price c_i. Each juice includes some set of vitamins in it. There are three types of vitamins: vitamin "A", vitamin "B" and vitamin "C". Each juice can contain one, two or all three types of vitamins in it.
Petya knows that he needs all three types of vitamins to stay healthy. What is the minimum total price of juices that Petya has to buy to obtain all three vitamins? Petya obtains some vitamin if he buys at least one juice containing it and drinks it.
Input
The first line contains a single integer n (1 β€ n β€ 1 000) β the number of juices.
Each of the next n lines contains an integer c_i (1 β€ c_i β€ 100 000) and a string s_i β the price of the i-th juice and the vitamins it contains. String s_i contains from 1 to 3 characters, and the only possible characters are "A", "B" and "C". It is guaranteed that each letter appears no more than once in each string s_i. The order of letters in strings s_i is arbitrary.
Output
Print -1 if there is no way to obtain all three vitamins. Otherwise print the minimum total price of juices that Petya has to buy to obtain all three vitamins.
Examples
Input
4
5 C
6 B
16 BAC
4 A
Output
15
Input
2
10 AB
15 BA
Output
-1
Input
5
10 A
9 BC
11 CA
4 A
5 B
Output
13
Input
6
100 A
355 BCA
150 BC
160 AC
180 B
190 CA
Output
250
Input
2
5 BA
11 CB
Output
16
Note
In the first example Petya buys the first, the second and the fourth juice. He spends 5 + 6 + 4 = 15 and obtains all three vitamins. He can also buy just the third juice and obtain three vitamins, but its cost is 16, which isn't optimal.
In the second example Petya can't obtain all three vitamins, as no juice contains vitamin "C". | instruction | 0 | 105,259 | 10 | 210,518 |
Tags: bitmasks, brute force, dp, implementation
Correct Solution:
```
n=int(input())
v=[0]+[10**9]*7
for _ in range(n):
c,s=input().split()
c=int(c)
s=sum(1<<(ord(x)-ord('A')) for x in s)
for i in range(8):
v[i|s]=min(v[i|s], v[i]+c)
if v[7]==10**9: v[7]=-1
print(v[7])
``` | output | 1 | 105,259 | 10 | 210,519 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Berland shop sells n kinds of juices. Each juice has its price c_i. Each juice includes some set of vitamins in it. There are three types of vitamins: vitamin "A", vitamin "B" and vitamin "C". Each juice can contain one, two or all three types of vitamins in it.
Petya knows that he needs all three types of vitamins to stay healthy. What is the minimum total price of juices that Petya has to buy to obtain all three vitamins? Petya obtains some vitamin if he buys at least one juice containing it and drinks it.
Input
The first line contains a single integer n (1 β€ n β€ 1 000) β the number of juices.
Each of the next n lines contains an integer c_i (1 β€ c_i β€ 100 000) and a string s_i β the price of the i-th juice and the vitamins it contains. String s_i contains from 1 to 3 characters, and the only possible characters are "A", "B" and "C". It is guaranteed that each letter appears no more than once in each string s_i. The order of letters in strings s_i is arbitrary.
Output
Print -1 if there is no way to obtain all three vitamins. Otherwise print the minimum total price of juices that Petya has to buy to obtain all three vitamins.
Examples
Input
4
5 C
6 B
16 BAC
4 A
Output
15
Input
2
10 AB
15 BA
Output
-1
Input
5
10 A
9 BC
11 CA
4 A
5 B
Output
13
Input
6
100 A
355 BCA
150 BC
160 AC
180 B
190 CA
Output
250
Input
2
5 BA
11 CB
Output
16
Note
In the first example Petya buys the first, the second and the fourth juice. He spends 5 + 6 + 4 = 15 and obtains all three vitamins. He can also buy just the third juice and obtain three vitamins, but its cost is 16, which isn't optimal.
In the second example Petya can't obtain all three vitamins, as no juice contains vitamin "C". | instruction | 0 | 105,260 | 10 | 210,520 |
Tags: bitmasks, brute force, dp, implementation
Correct Solution:
```
import math
n = int(input())
a = [math.inf]
b = [math.inf]
c = [math.inf]
ab = [math.inf]
bc = [math.inf]
ac = [math.inf]
abc = [math.inf]
for i in range(n):
p,q = input().split()
if q is 'A':
a.append(int(p))
elif q is 'B':
b.append(int(p))
elif q is 'C':
c.append(int(p))
elif q in ['AB', 'BA']:
ab.append(int(p))
elif q in ['AC', 'CA']:
ac.append(int(p))
elif q in ['BC', 'CB']:
bc.append(int(p))
else:
abc.append(int(p))
amin = min(a)
bmin = min(b)
cmin = min(c)
abmin = min(ab)
acmin = min(ac)
bcmin = min(bc)
abcmin = min(abc)
abmin = min(abmin,amin+bmin)
bcmin = min(bcmin,bmin+cmin)
acmin = min(acmin,amin+cmin)
abcmin = min(amin+bmin+cmin,amin+bcmin,bmin+acmin,
cmin+abmin,abmin+bcmin,abmin+acmin,bcmin+acmin,abcmin)
print(-1 if abcmin == math.inf else abcmin)
``` | output | 1 | 105,260 | 10 | 210,521 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Berland shop sells n kinds of juices. Each juice has its price c_i. Each juice includes some set of vitamins in it. There are three types of vitamins: vitamin "A", vitamin "B" and vitamin "C". Each juice can contain one, two or all three types of vitamins in it.
Petya knows that he needs all three types of vitamins to stay healthy. What is the minimum total price of juices that Petya has to buy to obtain all three vitamins? Petya obtains some vitamin if he buys at least one juice containing it and drinks it.
Input
The first line contains a single integer n (1 β€ n β€ 1 000) β the number of juices.
Each of the next n lines contains an integer c_i (1 β€ c_i β€ 100 000) and a string s_i β the price of the i-th juice and the vitamins it contains. String s_i contains from 1 to 3 characters, and the only possible characters are "A", "B" and "C". It is guaranteed that each letter appears no more than once in each string s_i. The order of letters in strings s_i is arbitrary.
Output
Print -1 if there is no way to obtain all three vitamins. Otherwise print the minimum total price of juices that Petya has to buy to obtain all three vitamins.
Examples
Input
4
5 C
6 B
16 BAC
4 A
Output
15
Input
2
10 AB
15 BA
Output
-1
Input
5
10 A
9 BC
11 CA
4 A
5 B
Output
13
Input
6
100 A
355 BCA
150 BC
160 AC
180 B
190 CA
Output
250
Input
2
5 BA
11 CB
Output
16
Note
In the first example Petya buys the first, the second and the fourth juice. He spends 5 + 6 + 4 = 15 and obtains all three vitamins. He can also buy just the third juice and obtain three vitamins, but its cost is 16, which isn't optimal.
In the second example Petya can't obtain all three vitamins, as no juice contains vitamin "C". | instruction | 0 | 105,261 | 10 | 210,522 |
Tags: bitmasks, brute force, dp, implementation
Correct Solution:
```
n = int(input())
vitamins_prices = {}
all_vitamins = ['A', 'B', 'C', 'AB', 'AC', 'BC', 'ABC']
ord_a = ord('A')
ord_c = ord('C')
for i in range(n):
current_price, current_vitamins = input().split()
current_price = int(current_price)
current_vitamins_set = set(current_vitamins)
for vit in all_vitamins:
vit_set = set(vit)
if current_vitamins_set < vit_set:
continue
elif current_vitamins_set == vit_set:
vitamins_prices[vit] = min(vitamins_prices.get(vit, current_price), current_price)
elif vit not in vitamins_prices:
continue
mixed = ''.join(sorted(vit_set | current_vitamins_set))
vit_price = vitamins_prices.get(vit, current_price)
mixed_price = vitamins_prices.get(mixed, vit_price + current_price)
vitamins_prices[mixed] = min(mixed_price, vit_price + current_price)
print(vitamins_prices.get('ABC', -1))
``` | output | 1 | 105,261 | 10 | 210,523 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Berland shop sells n kinds of juices. Each juice has its price c_i. Each juice includes some set of vitamins in it. There are three types of vitamins: vitamin "A", vitamin "B" and vitamin "C". Each juice can contain one, two or all three types of vitamins in it.
Petya knows that he needs all three types of vitamins to stay healthy. What is the minimum total price of juices that Petya has to buy to obtain all three vitamins? Petya obtains some vitamin if he buys at least one juice containing it and drinks it.
Input
The first line contains a single integer n (1 β€ n β€ 1 000) β the number of juices.
Each of the next n lines contains an integer c_i (1 β€ c_i β€ 100 000) and a string s_i β the price of the i-th juice and the vitamins it contains. String s_i contains from 1 to 3 characters, and the only possible characters are "A", "B" and "C". It is guaranteed that each letter appears no more than once in each string s_i. The order of letters in strings s_i is arbitrary.
Output
Print -1 if there is no way to obtain all three vitamins. Otherwise print the minimum total price of juices that Petya has to buy to obtain all three vitamins.
Examples
Input
4
5 C
6 B
16 BAC
4 A
Output
15
Input
2
10 AB
15 BA
Output
-1
Input
5
10 A
9 BC
11 CA
4 A
5 B
Output
13
Input
6
100 A
355 BCA
150 BC
160 AC
180 B
190 CA
Output
250
Input
2
5 BA
11 CB
Output
16
Note
In the first example Petya buys the first, the second and the fourth juice. He spends 5 + 6 + 4 = 15 and obtains all three vitamins. He can also buy just the third juice and obtain three vitamins, but its cost is 16, which isn't optimal.
In the second example Petya can't obtain all three vitamins, as no juice contains vitamin "C".
Submitted Solution:
```
n = int(input())
a,b,c,ab,bc,ac,abc = 10**10,10**10,10**10,10**10,10**10,10**10,10**10
for _ in range(n):
val,word = list(map(str,input().split()))
val = int(val)
if word=='A':
a = min(a,val)
elif word=='B':
b = min(b,val)
elif word=='C':
c = min(c,val)
elif word in ['AB','BA']:
ab = min(ab,val)
elif word in ['BC','CB']:
bc = min(bc,val)
elif word in ['AC','CA']:
ac = min(ac,val)
else:
abc = min(abc,val)
ans = 10**10
ans = min(ans,a+b+c,ab+bc,bc+ac,a+abc,b+abc,c+abc,ab+abc,bc+abc,ac+abc,a+bc,b+ac,c+ab,ac+ab,abc)
if ans==10**10:
print(-1)
else:
print(ans)
``` | instruction | 0 | 105,262 | 10 | 210,524 |
Yes | output | 1 | 105,262 | 10 | 210,525 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Berland shop sells n kinds of juices. Each juice has its price c_i. Each juice includes some set of vitamins in it. There are three types of vitamins: vitamin "A", vitamin "B" and vitamin "C". Each juice can contain one, two or all three types of vitamins in it.
Petya knows that he needs all three types of vitamins to stay healthy. What is the minimum total price of juices that Petya has to buy to obtain all three vitamins? Petya obtains some vitamin if he buys at least one juice containing it and drinks it.
Input
The first line contains a single integer n (1 β€ n β€ 1 000) β the number of juices.
Each of the next n lines contains an integer c_i (1 β€ c_i β€ 100 000) and a string s_i β the price of the i-th juice and the vitamins it contains. String s_i contains from 1 to 3 characters, and the only possible characters are "A", "B" and "C". It is guaranteed that each letter appears no more than once in each string s_i. The order of letters in strings s_i is arbitrary.
Output
Print -1 if there is no way to obtain all three vitamins. Otherwise print the minimum total price of juices that Petya has to buy to obtain all three vitamins.
Examples
Input
4
5 C
6 B
16 BAC
4 A
Output
15
Input
2
10 AB
15 BA
Output
-1
Input
5
10 A
9 BC
11 CA
4 A
5 B
Output
13
Input
6
100 A
355 BCA
150 BC
160 AC
180 B
190 CA
Output
250
Input
2
5 BA
11 CB
Output
16
Note
In the first example Petya buys the first, the second and the fourth juice. He spends 5 + 6 + 4 = 15 and obtains all three vitamins. He can also buy just the third juice and obtain three vitamins, but its cost is 16, which isn't optimal.
In the second example Petya can't obtain all three vitamins, as no juice contains vitamin "C".
Submitted Solution:
```
n=int(input())
dic={'A': 'A', 'B': 'B', 'C': 'C', 'AB': 'AB', 'BA': 'AB', 'AC': 'AC',
'CA': 'AC', 'BC': 'BC', 'CB': 'BC', 'ABC': 'ABC',
'ACB': 'ABC', 'BAC': 'ABC', 'BCA': 'ABC', 'CAB': 'ABC', 'CBA': 'ABC'}
fun={'A': [], 'B': [], 'C': [], 'AB': [], 'AC': [], 'BC': [], 'ABC': []}
for _ in range(n):
s=input().split()
fun[dic[s[1]]].append(int(s[0]))
ans=[]
if len(fun['ABC'])>0:
ans.append(min(fun['ABC']))
if len(fun['AB'])>0 and len(fun['BC'])>0:
ans.append(min(fun['AB'])+min(fun['BC']))
if len(fun['AB'])>0 and len(fun['AC'])>0:
ans.append(min(fun['AB'])+min(fun['AC']))
if len(fun['AC'])>0 and len(fun['BC'])>0:
ans.append(min(fun['AC'])+min(fun['BC']))
if len(fun['A'])>0 and len(fun['B'])>0 and len(fun['C'])>0:
ans.append(min(fun['A'])+min(fun['B'])+min(fun['C']))
if len(fun['A'])>0 and len(fun['BC'])>0:
ans.append(min(fun['A'])+min(fun['BC']))
if len(fun['B'])>0 and len(fun['AC'])>0:
ans.append(min(fun['B'])+min(fun['AC']))
if len(fun['C'])>0 and len(fun['AB'])>0:
ans.append(min(fun['C'])+min(fun['AB']))
try:
print(min(ans))
except:
print(-1)
``` | instruction | 0 | 105,263 | 10 | 210,526 |
Yes | output | 1 | 105,263 | 10 | 210,527 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Berland shop sells n kinds of juices. Each juice has its price c_i. Each juice includes some set of vitamins in it. There are three types of vitamins: vitamin "A", vitamin "B" and vitamin "C". Each juice can contain one, two or all three types of vitamins in it.
Petya knows that he needs all three types of vitamins to stay healthy. What is the minimum total price of juices that Petya has to buy to obtain all three vitamins? Petya obtains some vitamin if he buys at least one juice containing it and drinks it.
Input
The first line contains a single integer n (1 β€ n β€ 1 000) β the number of juices.
Each of the next n lines contains an integer c_i (1 β€ c_i β€ 100 000) and a string s_i β the price of the i-th juice and the vitamins it contains. String s_i contains from 1 to 3 characters, and the only possible characters are "A", "B" and "C". It is guaranteed that each letter appears no more than once in each string s_i. The order of letters in strings s_i is arbitrary.
Output
Print -1 if there is no way to obtain all three vitamins. Otherwise print the minimum total price of juices that Petya has to buy to obtain all three vitamins.
Examples
Input
4
5 C
6 B
16 BAC
4 A
Output
15
Input
2
10 AB
15 BA
Output
-1
Input
5
10 A
9 BC
11 CA
4 A
5 B
Output
13
Input
6
100 A
355 BCA
150 BC
160 AC
180 B
190 CA
Output
250
Input
2
5 BA
11 CB
Output
16
Note
In the first example Petya buys the first, the second and the fourth juice. He spends 5 + 6 + 4 = 15 and obtains all three vitamins. He can also buy just the third juice and obtain three vitamins, but its cost is 16, which isn't optimal.
In the second example Petya can't obtain all three vitamins, as no juice contains vitamin "C".
Submitted Solution:
```
import math as mt
import sys,string,bisect
input=sys.stdin.readline
from collections import deque,defaultdict
L=lambda : list(map(int,input().split()))
Ls=lambda : list(input().split())
M=lambda : map(int,input().split())
I=lambda :int(input())
n=I()
x=defaultdict(lambda: 10000000)
for i in range(n):
c,d=input().strip().split()
c=int(c)
d=tuple(sorted(list(d)))
x[d]=min(x[d],c)
a=min(x[('A',)]+x[('B',)]+x[('C',)],x[("A","B")]+x[("B","C")],x[('A','B')]+x[('A','C')],x[("A","C")]+x[("B","C")],x[("A",)]+x[("B","C")],x[("B",)]+x[("A","C")],x[("A","B")]+x[("C",)],x[("A","B","C")])
if(a>=10000000):
print(-1)
else:
print(a)
``` | instruction | 0 | 105,264 | 10 | 210,528 |
Yes | output | 1 | 105,264 | 10 | 210,529 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Berland shop sells n kinds of juices. Each juice has its price c_i. Each juice includes some set of vitamins in it. There are three types of vitamins: vitamin "A", vitamin "B" and vitamin "C". Each juice can contain one, two or all three types of vitamins in it.
Petya knows that he needs all three types of vitamins to stay healthy. What is the minimum total price of juices that Petya has to buy to obtain all three vitamins? Petya obtains some vitamin if he buys at least one juice containing it and drinks it.
Input
The first line contains a single integer n (1 β€ n β€ 1 000) β the number of juices.
Each of the next n lines contains an integer c_i (1 β€ c_i β€ 100 000) and a string s_i β the price of the i-th juice and the vitamins it contains. String s_i contains from 1 to 3 characters, and the only possible characters are "A", "B" and "C". It is guaranteed that each letter appears no more than once in each string s_i. The order of letters in strings s_i is arbitrary.
Output
Print -1 if there is no way to obtain all three vitamins. Otherwise print the minimum total price of juices that Petya has to buy to obtain all three vitamins.
Examples
Input
4
5 C
6 B
16 BAC
4 A
Output
15
Input
2
10 AB
15 BA
Output
-1
Input
5
10 A
9 BC
11 CA
4 A
5 B
Output
13
Input
6
100 A
355 BCA
150 BC
160 AC
180 B
190 CA
Output
250
Input
2
5 BA
11 CB
Output
16
Note
In the first example Petya buys the first, the second and the fourth juice. He spends 5 + 6 + 4 = 15 and obtains all three vitamins. He can also buy just the third juice and obtain three vitamins, but its cost is 16, which isn't optimal.
In the second example Petya can't obtain all three vitamins, as no juice contains vitamin "C".
Submitted Solution:
```
n = int(input())
s = []
for i in range(n):
a, b = map(str, input().split())
a = int(a)
s.append((a, b))
ans = float('inf')
mina = ans
minb = mina
minc = minb
for i in s:
if('A' in i[1] and mina > i[0]):
mina = i[0]
if('B' in i[1] and minb > i[0]):
minb = i[0]
if('C' in i[1] and minc > i[0]):
minc = i[0]
ans = mina + minb + minc
for i in s:
if(len(i[1]) == 2):
if('A' in i[1] and 'B' in i[1] and minc + i[0] < ans):
ans = minc + i[0]
if('A' in i[1] and 'C' in i[1] and minb + i[0] < ans):
ans = minb + i[0]
if('C' in i[1] and 'B' in i[1] and mina + i[0] < ans):
ans = mina + i[0]
elif(len(i[1]) == 3):
ans = min(ans, i[0])
if(ans == float('inf')):
print(-1)
else:
print(ans)
``` | instruction | 0 | 105,265 | 10 | 210,530 |
Yes | output | 1 | 105,265 | 10 | 210,531 |
Evaluate the correctness of the submitted Python 2 solution to the coding contest problem. Provide a "Yes" or "No" response.
Berland shop sells n kinds of juices. Each juice has its price c_i. Each juice includes some set of vitamins in it. There are three types of vitamins: vitamin "A", vitamin "B" and vitamin "C". Each juice can contain one, two or all three types of vitamins in it.
Petya knows that he needs all three types of vitamins to stay healthy. What is the minimum total price of juices that Petya has to buy to obtain all three vitamins? Petya obtains some vitamin if he buys at least one juice containing it and drinks it.
Input
The first line contains a single integer n (1 β€ n β€ 1 000) β the number of juices.
Each of the next n lines contains an integer c_i (1 β€ c_i β€ 100 000) and a string s_i β the price of the i-th juice and the vitamins it contains. String s_i contains from 1 to 3 characters, and the only possible characters are "A", "B" and "C". It is guaranteed that each letter appears no more than once in each string s_i. The order of letters in strings s_i is arbitrary.
Output
Print -1 if there is no way to obtain all three vitamins. Otherwise print the minimum total price of juices that Petya has to buy to obtain all three vitamins.
Examples
Input
4
5 C
6 B
16 BAC
4 A
Output
15
Input
2
10 AB
15 BA
Output
-1
Input
5
10 A
9 BC
11 CA
4 A
5 B
Output
13
Input
6
100 A
355 BCA
150 BC
160 AC
180 B
190 CA
Output
250
Input
2
5 BA
11 CB
Output
16
Note
In the first example Petya buys the first, the second and the fourth juice. He spends 5 + 6 + 4 = 15 and obtains all three vitamins. He can also buy just the third juice and obtain three vitamins, but its cost is 16, which isn't optimal.
In the second example Petya can't obtain all three vitamins, as no juice contains vitamin "C".
Submitted Solution:
```
#Run code in language PyPy2
#change input() in Python 3 become raw_input() like python2 then submit
#Add this code prefix of your code
import atexit
import io
import sys
buff = io.BytesIO()
sys.stdout = buff
@atexit.register
def write():
sys.__stdout__.write(buff.getvalue())
# code
r = raw_input
n = int(r())
X =[10**9]*7
for i in range(0,n):
A = r().split()
x = int(A[0])
y = str(A[1])
#A x 0
if('B' not in y and 'C' not in y):
if(X[0] > x):
X[0] = x
#B x 1
if('A' not in y and 'C' not in y):
if(X[1] > x):
X[1] = x
#C x 2
if('A' not in y and 'B' not in y):
if(X[2] > x):
X[2] = x
#AB x 3
if('C' not in y and 'A' in y and 'B' in y):
if(X[3] > x):
X[3] = x
#BC x 4
if('A' not in y and 'B' in y and 'C' in y):
if(X[4] > x):
X[4] = x
#AC x 5
if('B' not in y and 'A' in y and 'C' in y):
if(X[5] > x):
X[5] = x
#ABC x 6
if('A' in y and 'B' in y and 'C' in y):
if(X[6] > x):
X[6] = x
ans = 10**9
#A B C
if(ans > X[0]+X[1]+X[2]):
ans = X[0]+X[1]+X[2]
#A BC
if(ans > X[0]+X[4]):
ans = X[0]+X[4]
#B AC
if(ans > X[1]+X[5]):
ans = X[1]+X[5]
#C AB
if(ans > X[2]+X[3]):
ans = X[2]+X[3]
#ABC
if(ans > X[6]):
ans = X[6]
#AB BC
if(ans > X[3]+X[4]):
ans = X[3]+X[4]
#BC AC
if(ans > X[4]+X[5]):
ans = X[4]+X[5]
#AC BA
if(ans > X[3]+X[5]):
ans = X[3]+X[5]
if(ans == 10**9):
print(-1)
else:
print(ans)
``` | instruction | 0 | 105,266 | 10 | 210,532 |
Yes | output | 1 | 105,266 | 10 | 210,533 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Berland shop sells n kinds of juices. Each juice has its price c_i. Each juice includes some set of vitamins in it. There are three types of vitamins: vitamin "A", vitamin "B" and vitamin "C". Each juice can contain one, two or all three types of vitamins in it.
Petya knows that he needs all three types of vitamins to stay healthy. What is the minimum total price of juices that Petya has to buy to obtain all three vitamins? Petya obtains some vitamin if he buys at least one juice containing it and drinks it.
Input
The first line contains a single integer n (1 β€ n β€ 1 000) β the number of juices.
Each of the next n lines contains an integer c_i (1 β€ c_i β€ 100 000) and a string s_i β the price of the i-th juice and the vitamins it contains. String s_i contains from 1 to 3 characters, and the only possible characters are "A", "B" and "C". It is guaranteed that each letter appears no more than once in each string s_i. The order of letters in strings s_i is arbitrary.
Output
Print -1 if there is no way to obtain all three vitamins. Otherwise print the minimum total price of juices that Petya has to buy to obtain all three vitamins.
Examples
Input
4
5 C
6 B
16 BAC
4 A
Output
15
Input
2
10 AB
15 BA
Output
-1
Input
5
10 A
9 BC
11 CA
4 A
5 B
Output
13
Input
6
100 A
355 BCA
150 BC
160 AC
180 B
190 CA
Output
250
Input
2
5 BA
11 CB
Output
16
Note
In the first example Petya buys the first, the second and the fourth juice. He spends 5 + 6 + 4 = 15 and obtains all three vitamins. He can also buy just the third juice and obtain three vitamins, but its cost is 16, which isn't optimal.
In the second example Petya can't obtain all three vitamins, as no juice contains vitamin "C".
Submitted Solution:
```
dict1 = {}
d = []
for _ in range(int(input())):
arr1 = [i for i in input().split()]
g = sorted(arr1[1])
s = ""
for i in g:
s = s+i
if dict1.get(s)==None:
dict1[s] = int(arr1[0])
d.append(s)
else:
if dict1[s]>int(arr1[0]):
dict1[s] = int(arr1[0])
count1 = 0
count2 = 0
count3 = 0
count4 = 0
count5 = 0
op = []
count = 100000
if dict1.get("A")!=None and dict1.get("B")!=None and dict1.get("C")!=None :
count1 +=dict1["A"]+dict1["B"]+dict1["C"]
if count1<count and count1>0:
count = count1
for i in d:
if i.count("A")>0 and i.count("B")>0 and i.count("C")>0:
count2 = dict1[i]
if count2<count:
count = count2
else:
for j in d:
s = i+j
if s.count("A")>0 and s.count("B")>0 and s.count("C")>0:
count2 = dict1[i]+dict1[j]
if count>count2:
count = count2
if count==100000:
print(-1)
else:
print(count)
``` | instruction | 0 | 105,267 | 10 | 210,534 |
No | output | 1 | 105,267 | 10 | 210,535 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Berland shop sells n kinds of juices. Each juice has its price c_i. Each juice includes some set of vitamins in it. There are three types of vitamins: vitamin "A", vitamin "B" and vitamin "C". Each juice can contain one, two or all three types of vitamins in it.
Petya knows that he needs all three types of vitamins to stay healthy. What is the minimum total price of juices that Petya has to buy to obtain all three vitamins? Petya obtains some vitamin if he buys at least one juice containing it and drinks it.
Input
The first line contains a single integer n (1 β€ n β€ 1 000) β the number of juices.
Each of the next n lines contains an integer c_i (1 β€ c_i β€ 100 000) and a string s_i β the price of the i-th juice and the vitamins it contains. String s_i contains from 1 to 3 characters, and the only possible characters are "A", "B" and "C". It is guaranteed that each letter appears no more than once in each string s_i. The order of letters in strings s_i is arbitrary.
Output
Print -1 if there is no way to obtain all three vitamins. Otherwise print the minimum total price of juices that Petya has to buy to obtain all three vitamins.
Examples
Input
4
5 C
6 B
16 BAC
4 A
Output
15
Input
2
10 AB
15 BA
Output
-1
Input
5
10 A
9 BC
11 CA
4 A
5 B
Output
13
Input
6
100 A
355 BCA
150 BC
160 AC
180 B
190 CA
Output
250
Input
2
5 BA
11 CB
Output
16
Note
In the first example Petya buys the first, the second and the fourth juice. He spends 5 + 6 + 4 = 15 and obtains all three vitamins. He can also buy just the third juice and obtain three vitamins, but its cost is 16, which isn't optimal.
In the second example Petya can't obtain all three vitamins, as no juice contains vitamin "C".
Submitted Solution:
```
from collections import Counter
from itertools import permutations
nu=int(input())
d={}
for i in range(nu) :
n,s=map(str,input().split())
n=int(n)
if s in d :
k=s
k=list(k)
k.sort()
k="".join(k)
d[k]=min(d[k],n)
else :
k=s
k=list(k)
k.sort()
k="".join(k)
d[k]=n
#print(d);
j={};
c=0;cost=[];s=0;
j[1]=0;j[2]=0;j[3]=0;
for i in d :
if len(i) == 1 :
c+=1
s=s+d[i]
elif len(i)==3 :
cost.append(d[i])
else :
if i.startswith("A") and i.endswith("B"):
j[1]=d[i]
elif i.startswith("A") and i.endswith("C"):
j[2]=d[i]
else :
j[3]=d[i]
if j[1]!=0 and j[2]!=0 :
print("a")
cost.append(j[1]+j[2])
elif j[2]!=0 and j[3]!=0 :
cost.append(j[3]+j[2])
print("b")
elif j[1]!=0 and j[3]!=0 :
cost.append(j[1]+j[3])
print("c")
if c==3 :
cost.append(s)
if len(cost)==0 :
exit(print("-1"))
print(min(cost))
``` | instruction | 0 | 105,268 | 10 | 210,536 |
No | output | 1 | 105,268 | 10 | 210,537 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Berland shop sells n kinds of juices. Each juice has its price c_i. Each juice includes some set of vitamins in it. There are three types of vitamins: vitamin "A", vitamin "B" and vitamin "C". Each juice can contain one, two or all three types of vitamins in it.
Petya knows that he needs all three types of vitamins to stay healthy. What is the minimum total price of juices that Petya has to buy to obtain all three vitamins? Petya obtains some vitamin if he buys at least one juice containing it and drinks it.
Input
The first line contains a single integer n (1 β€ n β€ 1 000) β the number of juices.
Each of the next n lines contains an integer c_i (1 β€ c_i β€ 100 000) and a string s_i β the price of the i-th juice and the vitamins it contains. String s_i contains from 1 to 3 characters, and the only possible characters are "A", "B" and "C". It is guaranteed that each letter appears no more than once in each string s_i. The order of letters in strings s_i is arbitrary.
Output
Print -1 if there is no way to obtain all three vitamins. Otherwise print the minimum total price of juices that Petya has to buy to obtain all three vitamins.
Examples
Input
4
5 C
6 B
16 BAC
4 A
Output
15
Input
2
10 AB
15 BA
Output
-1
Input
5
10 A
9 BC
11 CA
4 A
5 B
Output
13
Input
6
100 A
355 BCA
150 BC
160 AC
180 B
190 CA
Output
250
Input
2
5 BA
11 CB
Output
16
Note
In the first example Petya buys the first, the second and the fourth juice. He spends 5 + 6 + 4 = 15 and obtains all three vitamins. He can also buy just the third juice and obtain three vitamins, but its cost is 16, which isn't optimal.
In the second example Petya can't obtain all three vitamins, as no juice contains vitamin "C".
Submitted Solution:
```
#warmup
tmp = float('inf')
d = {'A':tmp,'B':tmp,'C':tmp,'AB':tmp,'AC':tmp,'BC':tmp,'ABC':tmp}
seen = {'A':0, 'B':0, 'C':0}
for i in range(int(input())):
c,s = map(str,input().split())
t = ''.join(sorted(s))
d[t] = min(int(c), d[t])
for j in s:
seen[j] = 1
if sum(seen.values()) != 3:
print(-1)
else:
print(min([ d['ABC'], d['A']+d['B']+d['C'],d['A']+d['BC'],d['B']+d['AC'],d['C']+d['AB'] ]))
``` | instruction | 0 | 105,269 | 10 | 210,538 |
No | output | 1 | 105,269 | 10 | 210,539 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Berland shop sells n kinds of juices. Each juice has its price c_i. Each juice includes some set of vitamins in it. There are three types of vitamins: vitamin "A", vitamin "B" and vitamin "C". Each juice can contain one, two or all three types of vitamins in it.
Petya knows that he needs all three types of vitamins to stay healthy. What is the minimum total price of juices that Petya has to buy to obtain all three vitamins? Petya obtains some vitamin if he buys at least one juice containing it and drinks it.
Input
The first line contains a single integer n (1 β€ n β€ 1 000) β the number of juices.
Each of the next n lines contains an integer c_i (1 β€ c_i β€ 100 000) and a string s_i β the price of the i-th juice and the vitamins it contains. String s_i contains from 1 to 3 characters, and the only possible characters are "A", "B" and "C". It is guaranteed that each letter appears no more than once in each string s_i. The order of letters in strings s_i is arbitrary.
Output
Print -1 if there is no way to obtain all three vitamins. Otherwise print the minimum total price of juices that Petya has to buy to obtain all three vitamins.
Examples
Input
4
5 C
6 B
16 BAC
4 A
Output
15
Input
2
10 AB
15 BA
Output
-1
Input
5
10 A
9 BC
11 CA
4 A
5 B
Output
13
Input
6
100 A
355 BCA
150 BC
160 AC
180 B
190 CA
Output
250
Input
2
5 BA
11 CB
Output
16
Note
In the first example Petya buys the first, the second and the fourth juice. He spends 5 + 6 + 4 = 15 and obtains all three vitamins. He can also buy just the third juice and obtain three vitamins, but its cost is 16, which isn't optimal.
In the second example Petya can't obtain all three vitamins, as no juice contains vitamin "C".
Submitted Solution:
```
from sys import stdin, stdout
import math,sys,heapq
from itertools import permutations, combinations
from collections import defaultdict,deque,OrderedDict
from os import path
import random
import bisect as bi
def yes():print('YES')
def no():print('NO')
if (path.exists('input.txt')):
#------------------Sublime--------------------------------------#
sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w');
def I():return (int(input()))
def In():return(map(int,input().split()))
else:
#------------------PYPY FAst I/o--------------------------------#
def I():return (int(stdin.readline()))
def In():return(map(int,stdin.readline().split()))
#sys.setrecursionlimit(1500)
def dict(a):
d={}
for x in a:
if d.get(x,-1)!=-1:
d[x]+=1
else:
d[x]=1
return d
def find_gt(a, x):
'Find leftmost value greater than x'
i = bi.bisect_left(a, x)
if i != len(a):
return i
else:
return -1
def main():
try:
n=I()
d={'A':Max,'B':Max,'C':Max,'AB':Max,'AC':Max,'BC':Max,'ABC':Max}
for x in range(n):
l=input().split(' ')
temp=list(l[1])
temp.sort()
temp=''.join(temp)
d[temp]=min(d[temp],int(l[0]))
#print(d)
ans=Max
ans=min(ans,d['A']+d['B']+d['C'])
ans=min(ans,d['A']+d['BC'])
ans=min(ans,d['B']+d['AC'])
ans=min(ans,d['C']+d['BC'])
ans=min(ans,d['AB']+d['BC'])
ans=min(ans,d['AC']+d['BC'])
ans=min(ans,d['AB']+d['AC'])
ans=min(ans,d['ABC'])
if ans>=Max:
print(-1)
else:
print(ans)
except:
pass
M = 998244353
P = 1000000007
Max=100000000
if __name__ == '__main__':
#for _ in range(I()):main()
for _ in range(1):main()
``` | instruction | 0 | 105,270 | 10 | 210,540 |
No | output | 1 | 105,270 | 10 | 210,541 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a special offer in Vasya's favourite supermarket: if the customer buys a chocolate bars, he or she may take b additional bars for free. This special offer can be used any number of times.
Vasya currently has s roubles, and he wants to get as many chocolate bars for free. Each chocolate bar costs c roubles. Help Vasya to calculate the maximum possible number of chocolate bars he can get!
Input
The first line contains one integer t (1 β€ t β€ 100) β the number of testcases.
Each of the next t lines contains four integers s, a, b, c~(1 β€ s, a, b, c β€ 10^9) β the number of roubles Vasya has, the number of chocolate bars you have to buy to use the special offer, the number of bars you get for free, and the cost of one bar, respectively.
Output
Print t lines. i-th line should contain the maximum possible number of chocolate bars Vasya can get in i-th test.
Example
Input
2
10 3 1 1
1000000000 1 1000000000 1
Output
13
1000000001000000000
Note
In the first test of the example Vasya can buy 9 bars, get 3 for free, buy another bar, and so he will get 13 bars.
In the second test Vasya buys 1000000000 bars and gets 1000000000000000000 for free. So he has 1000000001000000000 bars. | instruction | 0 | 105,271 | 10 | 210,542 |
Tags: implementation, math
Correct Solution:
```
t=int(input())
for case in range(t):
n,a,b,c=map(int,input().split())
print(n//c//a*b+n//c)
``` | output | 1 | 105,271 | 10 | 210,543 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a special offer in Vasya's favourite supermarket: if the customer buys a chocolate bars, he or she may take b additional bars for free. This special offer can be used any number of times.
Vasya currently has s roubles, and he wants to get as many chocolate bars for free. Each chocolate bar costs c roubles. Help Vasya to calculate the maximum possible number of chocolate bars he can get!
Input
The first line contains one integer t (1 β€ t β€ 100) β the number of testcases.
Each of the next t lines contains four integers s, a, b, c~(1 β€ s, a, b, c β€ 10^9) β the number of roubles Vasya has, the number of chocolate bars you have to buy to use the special offer, the number of bars you get for free, and the cost of one bar, respectively.
Output
Print t lines. i-th line should contain the maximum possible number of chocolate bars Vasya can get in i-th test.
Example
Input
2
10 3 1 1
1000000000 1 1000000000 1
Output
13
1000000001000000000
Note
In the first test of the example Vasya can buy 9 bars, get 3 for free, buy another bar, and so he will get 13 bars.
In the second test Vasya buys 1000000000 bars and gets 1000000000000000000 for free. So he has 1000000001000000000 bars. | instruction | 0 | 105,272 | 10 | 210,544 |
Tags: implementation, math
Correct Solution:
```
t=int(input())
for i in range(0,t):
s,a,b,c=input().split()
s=int(s)
a=int(a)
b=int(b)
c=int(c)
br=s//c
f=br//a
fr=f*b
print(br+fr)
``` | output | 1 | 105,272 | 10 | 210,545 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a special offer in Vasya's favourite supermarket: if the customer buys a chocolate bars, he or she may take b additional bars for free. This special offer can be used any number of times.
Vasya currently has s roubles, and he wants to get as many chocolate bars for free. Each chocolate bar costs c roubles. Help Vasya to calculate the maximum possible number of chocolate bars he can get!
Input
The first line contains one integer t (1 β€ t β€ 100) β the number of testcases.
Each of the next t lines contains four integers s, a, b, c~(1 β€ s, a, b, c β€ 10^9) β the number of roubles Vasya has, the number of chocolate bars you have to buy to use the special offer, the number of bars you get for free, and the cost of one bar, respectively.
Output
Print t lines. i-th line should contain the maximum possible number of chocolate bars Vasya can get in i-th test.
Example
Input
2
10 3 1 1
1000000000 1 1000000000 1
Output
13
1000000001000000000
Note
In the first test of the example Vasya can buy 9 bars, get 3 for free, buy another bar, and so he will get 13 bars.
In the second test Vasya buys 1000000000 bars and gets 1000000000000000000 for free. So he has 1000000001000000000 bars. | instruction | 0 | 105,273 | 10 | 210,546 |
Tags: implementation, math
Correct Solution:
```
t = int(input())
for i in range(t):
s,a, b , c= list(map(int,input().split()))
print((s//(a*c))*(a+b)+(s%(a*c))//c)
``` | output | 1 | 105,273 | 10 | 210,547 |
Provide tags and a correct Python 3 solution for this coding contest problem.
There is a special offer in Vasya's favourite supermarket: if the customer buys a chocolate bars, he or she may take b additional bars for free. This special offer can be used any number of times.
Vasya currently has s roubles, and he wants to get as many chocolate bars for free. Each chocolate bar costs c roubles. Help Vasya to calculate the maximum possible number of chocolate bars he can get!
Input
The first line contains one integer t (1 β€ t β€ 100) β the number of testcases.
Each of the next t lines contains four integers s, a, b, c~(1 β€ s, a, b, c β€ 10^9) β the number of roubles Vasya has, the number of chocolate bars you have to buy to use the special offer, the number of bars you get for free, and the cost of one bar, respectively.
Output
Print t lines. i-th line should contain the maximum possible number of chocolate bars Vasya can get in i-th test.
Example
Input
2
10 3 1 1
1000000000 1 1000000000 1
Output
13
1000000001000000000
Note
In the first test of the example Vasya can buy 9 bars, get 3 for free, buy another bar, and so he will get 13 bars.
In the second test Vasya buys 1000000000 bars and gets 1000000000000000000 for free. So he has 1000000001000000000 bars. | instruction | 0 | 105,274 | 10 | 210,548 |
Tags: implementation, math
Correct Solution:
```
t = int(input())
while t > 0:
s, a, b, c = map(int, input().split())
buy_bars = s // c
free = (buy_bars // a) * b
print(buy_bars + free)
t -= 1
``` | output | 1 | 105,274 | 10 | 210,549 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.