message stringlengths 2 22.7k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 145 109k | cluster float64 9 9 | __index_level_0__ int64 290 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
As you know, every birthday party has a cake! This time, Babaei is going to prepare the very special birthday party's cake.
Simple cake is a cylinder of some radius and height. The volume of the simple cake is equal to the volume of corresponding cylinder. Babaei has n simple cakes and he is going to make a special cake placing some cylinders on each other.
However, there are some additional culinary restrictions. The cakes are numbered in such a way that the cake number i can be placed only on the table or on some cake number j where j < i. Moreover, in order to impress friends Babaei will put the cake i on top of the cake j only if the volume of the cake i is strictly greater than the volume of the cake j.
Babaei wants to prepare a birthday cake that has a maximum possible total volume. Help him find this value.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of simple cakes Babaei has.
Each of the following n lines contains two integers ri and hi (1 ≤ ri, hi ≤ 10 000), giving the radius and height of the i-th cake.
Output
Print the maximum volume of the cake that Babaei can make. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>.
Examples
Input
2
100 30
40 10
Output
942477.796077000
Input
4
1 1
9 7
1 4
10 7
Output
3983.539484752
Note
In first sample, the optimal way is to choose the cake number 1.
In second sample, the way to get the maximum volume is to use cakes with indices 1, 2 and 4. | instruction | 0 | 9,507 | 9 | 19,014 |
Tags: data structures, dp
Correct Solution:
```
# [https://codeforces.com/contest/629/submission/32426374]
import math
n = int(input())
p = [0] * n
for i in range(n):
(r, h) = map(int, input().split())
p[i] = r**2 * h
k = {v: j for j, v in enumerate(sorted(set(p)))}
d = [0] * (len(k) + 1)
for v in p:
j = k[v]
i = j + 1
q = 0
while j > 0:
q = max(d[j], q)
j -= j & -j
q += v
while i < len(d):
d[i] = max(d[i], q)
i += i & -i
print(max(d) * math.pi)
``` | output | 1 | 9,507 | 9 | 19,015 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As you know, every birthday party has a cake! This time, Babaei is going to prepare the very special birthday party's cake.
Simple cake is a cylinder of some radius and height. The volume of the simple cake is equal to the volume of corresponding cylinder. Babaei has n simple cakes and he is going to make a special cake placing some cylinders on each other.
However, there are some additional culinary restrictions. The cakes are numbered in such a way that the cake number i can be placed only on the table or on some cake number j where j < i. Moreover, in order to impress friends Babaei will put the cake i on top of the cake j only if the volume of the cake i is strictly greater than the volume of the cake j.
Babaei wants to prepare a birthday cake that has a maximum possible total volume. Help him find this value.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of simple cakes Babaei has.
Each of the following n lines contains two integers ri and hi (1 ≤ ri, hi ≤ 10 000), giving the radius and height of the i-th cake.
Output
Print the maximum volume of the cake that Babaei can make. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>.
Examples
Input
2
100 30
40 10
Output
942477.796077000
Input
4
1 1
9 7
1 4
10 7
Output
3983.539484752
Note
In first sample, the optimal way is to choose the cake number 1.
In second sample, the way to get the maximum volume is to use cakes with indices 1, 2 and 4. | instruction | 0 | 9,508 | 9 | 19,016 |
Tags: data structures, dp
Correct Solution:
```
from math import pi
n = int(input())
secuencia = [None] * n
maximo_to = -1
for num in range(n):
r, h = (int(x) for x in input().strip().split())
secuencia[num] = [r * r * h, num + 1]
secuencia.reverse()
secuencia.sort(key=lambda x: x[0])
actual = 0
bit = [0] * (n + 1)
def max_x(x, l):
suma = 0
while x != 0:
suma = max(suma, l[x])
x -= (x & -x)
return suma
def update_x(x, l, max_n, val):
while x <= max_n:
if val > l[x]:
l[x] = val
else:
return
x += (x & -x)
for e in range(n):
maximo = secuencia[e][0] + max_x(secuencia[e][1] - 1, bit)
update_x(secuencia[e][1], bit, n, maximo)
if maximo > maximo_to:
maximo_to = maximo
print(maximo_to * pi)
``` | output | 1 | 9,508 | 9 | 19,017 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As you know, every birthday party has a cake! This time, Babaei is going to prepare the very special birthday party's cake.
Simple cake is a cylinder of some radius and height. The volume of the simple cake is equal to the volume of corresponding cylinder. Babaei has n simple cakes and he is going to make a special cake placing some cylinders on each other.
However, there are some additional culinary restrictions. The cakes are numbered in such a way that the cake number i can be placed only on the table or on some cake number j where j < i. Moreover, in order to impress friends Babaei will put the cake i on top of the cake j only if the volume of the cake i is strictly greater than the volume of the cake j.
Babaei wants to prepare a birthday cake that has a maximum possible total volume. Help him find this value.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of simple cakes Babaei has.
Each of the following n lines contains two integers ri and hi (1 ≤ ri, hi ≤ 10 000), giving the radius and height of the i-th cake.
Output
Print the maximum volume of the cake that Babaei can make. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>.
Examples
Input
2
100 30
40 10
Output
942477.796077000
Input
4
1 1
9 7
1 4
10 7
Output
3983.539484752
Note
In first sample, the optimal way is to choose the cake number 1.
In second sample, the way to get the maximum volume is to use cakes with indices 1, 2 and 4. | instruction | 0 | 9,509 | 9 | 19,018 |
Tags: data structures, dp
Correct Solution:
```
from sys import *
t = list(map(int, stdin.read().split()))
p = [t[i + 1] * t[i] ** 2 for i in range(1, len(t), 2)]
k = {v: j for j, v in enumerate(sorted(set(p)))}
d = [0] * (len(k) + 1)
for v in p:
j = k[v]
i = j + 1
q = 0
while j > 0:
q = max(d[j], q)
j -= j & -j
q += v
while i < len(d):
d[i] = max(d[i], q)
i += i & -i
print(max(d) * 3.14159265)
``` | output | 1 | 9,509 | 9 | 19,019 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As you know, every birthday party has a cake! This time, Babaei is going to prepare the very special birthday party's cake.
Simple cake is a cylinder of some radius and height. The volume of the simple cake is equal to the volume of corresponding cylinder. Babaei has n simple cakes and he is going to make a special cake placing some cylinders on each other.
However, there are some additional culinary restrictions. The cakes are numbered in such a way that the cake number i can be placed only on the table or on some cake number j where j < i. Moreover, in order to impress friends Babaei will put the cake i on top of the cake j only if the volume of the cake i is strictly greater than the volume of the cake j.
Babaei wants to prepare a birthday cake that has a maximum possible total volume. Help him find this value.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of simple cakes Babaei has.
Each of the following n lines contains two integers ri and hi (1 ≤ ri, hi ≤ 10 000), giving the radius and height of the i-th cake.
Output
Print the maximum volume of the cake that Babaei can make. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>.
Examples
Input
2
100 30
40 10
Output
942477.796077000
Input
4
1 1
9 7
1 4
10 7
Output
3983.539484752
Note
In first sample, the optimal way is to choose the cake number 1.
In second sample, the way to get the maximum volume is to use cakes with indices 1, 2 and 4. | instruction | 0 | 9,510 | 9 | 19,020 |
Tags: data structures, dp
Correct Solution:
```
def add(i, q):
while i < len(d):
d[i] = max(d[i], q)
i += i & -i
def get(i):
q = 0
while i > 0:
q = max(d[i], q)
i -= i & -i
return q
from sys import *
t = list(map(int, stdin.read().split()))
p = [t[i] * t[i] * t[i + 1] for i in range(1, len(t), 2)]
k = {v: j for j, v in enumerate(sorted(set(p)))}
d = [0] * (len(k) + 1)
for v in p:
j = k[v]
add(j + 1, get(j) + v)
print(get(len(k)) * 3.14159265)
``` | output | 1 | 9,510 | 9 | 19,021 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As you know, every birthday party has a cake! This time, Babaei is going to prepare the very special birthday party's cake.
Simple cake is a cylinder of some radius and height. The volume of the simple cake is equal to the volume of corresponding cylinder. Babaei has n simple cakes and he is going to make a special cake placing some cylinders on each other.
However, there are some additional culinary restrictions. The cakes are numbered in such a way that the cake number i can be placed only on the table or on some cake number j where j < i. Moreover, in order to impress friends Babaei will put the cake i on top of the cake j only if the volume of the cake i is strictly greater than the volume of the cake j.
Babaei wants to prepare a birthday cake that has a maximum possible total volume. Help him find this value.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of simple cakes Babaei has.
Each of the following n lines contains two integers ri and hi (1 ≤ ri, hi ≤ 10 000), giving the radius and height of the i-th cake.
Output
Print the maximum volume of the cake that Babaei can make. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>.
Examples
Input
2
100 30
40 10
Output
942477.796077000
Input
4
1 1
9 7
1 4
10 7
Output
3983.539484752
Note
In first sample, the optimal way is to choose the cake number 1.
In second sample, the way to get the maximum volume is to use cakes with indices 1, 2 and 4. | instruction | 0 | 9,511 | 9 | 19,022 |
Tags: data structures, dp
Correct Solution:
```
import math
from functools import reduce
class SegmentTree():
def __init__(self, L, function = lambda x,y: x+y):
self.function = function
N = self.size = len(L)
M = 1 << N.bit_length()
self.margin = 2*M - N
self.L = [None for i in range(self.margin)] + L
for i in range(M-1, 0, -1):
x, y = self.L[i<<1], self.L[i<<1|1]
self.L[i] = None if x is None or y is None else function(x, y)
def modify(self, pos, value):
p = pos + self.margin
self.L[p] = value
while p > 1:
x, y = self.L[p], self.L[p^1]
if p&1: x, y = y, x
self.L[p>>1] = None if x is None or y is None else self.function(x, y)
p>>=1
def query(self, left, right):
l, r = left + self.margin, right + self.margin
stack = []
void = True
while l < r:
if l&1:
if void:
result = self.L[l]
void = False
else:
result = self.function(result, self.L[l])
l+=1
if r&1:
r-=1
stack.append(self.L[r])
l>>=1
r>>=1
init = stack.pop() if void else result
return reduce(self.function, reversed(stack), init)
n = int(input())
pies, index, first_equal = [0]*n, [0]*n, [0]*n
for i in range(n):
r, h = [int(x) for x in input().split()]
pies[i] = r*r*h
s_pies = list(sorted(enumerate(pies), key = lambda p: p[1]))
for i in range(n): index[s_pies[i][0]] = i
for i in range(1, n):
first_equal[s_pies[i][0]] = i if s_pies[i][1] != s_pies[i-1][1] else first_equal[s_pies[i-1][0]]
towers = SegmentTree([0]*(n+1), max)
for j, pie in enumerate(pies):
i, k = index[j], first_equal[j]
q = towers.query(0, k+1)
towers.modify(i+1, q + pie)
print(math.pi * towers.query(0, n+1))
``` | output | 1 | 9,511 | 9 | 19,023 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As you know, every birthday party has a cake! This time, Babaei is going to prepare the very special birthday party's cake.
Simple cake is a cylinder of some radius and height. The volume of the simple cake is equal to the volume of corresponding cylinder. Babaei has n simple cakes and he is going to make a special cake placing some cylinders on each other.
However, there are some additional culinary restrictions. The cakes are numbered in such a way that the cake number i can be placed only on the table or on some cake number j where j < i. Moreover, in order to impress friends Babaei will put the cake i on top of the cake j only if the volume of the cake i is strictly greater than the volume of the cake j.
Babaei wants to prepare a birthday cake that has a maximum possible total volume. Help him find this value.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of simple cakes Babaei has.
Each of the following n lines contains two integers ri and hi (1 ≤ ri, hi ≤ 10 000), giving the radius and height of the i-th cake.
Output
Print the maximum volume of the cake that Babaei can make. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>.
Examples
Input
2
100 30
40 10
Output
942477.796077000
Input
4
1 1
9 7
1 4
10 7
Output
3983.539484752
Note
In first sample, the optimal way is to choose the cake number 1.
In second sample, the way to get the maximum volume is to use cakes with indices 1, 2 and 4. | instruction | 0 | 9,512 | 9 | 19,024 |
Tags: data structures, dp
Correct Solution:
```
from math import *
from bisect import *
def update(bit, size, idx, amount):
while idx <= size:
if bit[idx] < amount:
bit[idx] = amount
idx += idx & -idx
def read(bit, idx):
rst = 0
while idx >= 1:
if bit[idx] > rst:
rst = bit[idx]
idx -= idx & -idx
return rst
n = int(input())
arr = [map(int, input().split()) for _ in range(n)]
arr = [r*r*h for r, h in arr]
arr2 = sorted(list(set(arr)))
n2 = len(arr2)
bit = [0] * (n2 + 1)
for v in arr:
idx = bisect(arr2, v)
update(bit, n2, idx, read(bit, idx-1) + v)
print(pi*max(bit))
``` | output | 1 | 9,512 | 9 | 19,025 |
Provide tags and a correct Python 3 solution for this coding contest problem.
As you know, every birthday party has a cake! This time, Babaei is going to prepare the very special birthday party's cake.
Simple cake is a cylinder of some radius and height. The volume of the simple cake is equal to the volume of corresponding cylinder. Babaei has n simple cakes and he is going to make a special cake placing some cylinders on each other.
However, there are some additional culinary restrictions. The cakes are numbered in such a way that the cake number i can be placed only on the table or on some cake number j where j < i. Moreover, in order to impress friends Babaei will put the cake i on top of the cake j only if the volume of the cake i is strictly greater than the volume of the cake j.
Babaei wants to prepare a birthday cake that has a maximum possible total volume. Help him find this value.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of simple cakes Babaei has.
Each of the following n lines contains two integers ri and hi (1 ≤ ri, hi ≤ 10 000), giving the radius and height of the i-th cake.
Output
Print the maximum volume of the cake that Babaei can make. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>.
Examples
Input
2
100 30
40 10
Output
942477.796077000
Input
4
1 1
9 7
1 4
10 7
Output
3983.539484752
Note
In first sample, the optimal way is to choose the cake number 1.
In second sample, the way to get the maximum volume is to use cakes with indices 1, 2 and 4. | instruction | 0 | 9,513 | 9 | 19,026 |
Tags: data structures, dp
Correct Solution:
```
from math import *
from bisect import *
def update(bit, size, idx, amount):
while idx <= size:
if bit[idx] < amount:
bit[idx] = amount
idx += idx & -idx
def read(bit, idx):
rst = 0
while idx >= 1:
if bit[idx] > rst:
rst = bit[idx]
idx -= idx & -idx
return rst
n = int(input())
arr = [map(int, input().split()) for _ in range(n)]
arr = [pi*(r*r*h) for r, h in arr]
arr2 = sorted(list(set(arr)))
n2 = len(arr2)
bit = [0.0] * (n2 + 1)
for v in arr:
idx = bisect(arr2, v)
update(bit, n2, idx, read(bit, idx-1) + v)
print(max(bit))
``` | output | 1 | 9,513 | 9 | 19,027 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As you know, every birthday party has a cake! This time, Babaei is going to prepare the very special birthday party's cake.
Simple cake is a cylinder of some radius and height. The volume of the simple cake is equal to the volume of corresponding cylinder. Babaei has n simple cakes and he is going to make a special cake placing some cylinders on each other.
However, there are some additional culinary restrictions. The cakes are numbered in such a way that the cake number i can be placed only on the table or on some cake number j where j < i. Moreover, in order to impress friends Babaei will put the cake i on top of the cake j only if the volume of the cake i is strictly greater than the volume of the cake j.
Babaei wants to prepare a birthday cake that has a maximum possible total volume. Help him find this value.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of simple cakes Babaei has.
Each of the following n lines contains two integers ri and hi (1 ≤ ri, hi ≤ 10 000), giving the radius and height of the i-th cake.
Output
Print the maximum volume of the cake that Babaei can make. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>.
Examples
Input
2
100 30
40 10
Output
942477.796077000
Input
4
1 1
9 7
1 4
10 7
Output
3983.539484752
Note
In first sample, the optimal way is to choose the cake number 1.
In second sample, the way to get the maximum volume is to use cakes with indices 1, 2 and 4.
Submitted Solution:
```
def setmax(a, i, v):
while i < len(a):
a[i] = max(a[i], v)
i |= i + 1
def getmax(a, i):
r = 0
while i > 0:
r = max(r, a[i-1])
i &= i - 1
return r
def his(l):
maxbit = [0] * len(l)
rank = [0] * len(l)
for i, j in enumerate(sorted(range(len(l)), key=lambda i: l[i])):
rank[j] = i
for i, x in enumerate(l):
r = rank[i]
s = getmax(maxbit, r)
setmax(maxbit, r, x + s)
return getmax(maxbit, len(l))
import math
n=int(input())
lis=list()
for _ in range(n):
a,b=map(int,input().split())
lis.append(math.pi*a*a*b)
print(his(lis))
``` | instruction | 0 | 9,514 | 9 | 19,028 |
No | output | 1 | 9,514 | 9 | 19,029 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As you know, every birthday party has a cake! This time, Babaei is going to prepare the very special birthday party's cake.
Simple cake is a cylinder of some radius and height. The volume of the simple cake is equal to the volume of corresponding cylinder. Babaei has n simple cakes and he is going to make a special cake placing some cylinders on each other.
However, there are some additional culinary restrictions. The cakes are numbered in such a way that the cake number i can be placed only on the table or on some cake number j where j < i. Moreover, in order to impress friends Babaei will put the cake i on top of the cake j only if the volume of the cake i is strictly greater than the volume of the cake j.
Babaei wants to prepare a birthday cake that has a maximum possible total volume. Help him find this value.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of simple cakes Babaei has.
Each of the following n lines contains two integers ri and hi (1 ≤ ri, hi ≤ 10 000), giving the radius and height of the i-th cake.
Output
Print the maximum volume of the cake that Babaei can make. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>.
Examples
Input
2
100 30
40 10
Output
942477.796077000
Input
4
1 1
9 7
1 4
10 7
Output
3983.539484752
Note
In first sample, the optimal way is to choose the cake number 1.
In second sample, the way to get the maximum volume is to use cakes with indices 1, 2 and 4.
Submitted Solution:
```
from math import *
from bisect import *
def update(bit, size, idx, amount):
while idx <= size:
if bit[idx] < amount:
bit[idx] = amount
idx += idx & -idx
def read(bit, idx):
rst = 0
while idx >= 1:
if bit[idx] > rst:
rst = bit[idx]
idx -= idx & -idx
return rst
n = int(input())
arr = [map(int, input().split()) for _ in range(n)]
arr = [pi*r*r*h for r, h in arr]
arr2 = sorted(list(set(arr)))
n2 = len(arr2)
bit = [0.0] * (n2 + 1)
for v in arr:
idx = bisect(arr2, v)
update(bit, n2, idx, read(bit, idx-1) + v)
print(bit[-1])
``` | instruction | 0 | 9,515 | 9 | 19,030 |
No | output | 1 | 9,515 | 9 | 19,031 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As you know, every birthday party has a cake! This time, Babaei is going to prepare the very special birthday party's cake.
Simple cake is a cylinder of some radius and height. The volume of the simple cake is equal to the volume of corresponding cylinder. Babaei has n simple cakes and he is going to make a special cake placing some cylinders on each other.
However, there are some additional culinary restrictions. The cakes are numbered in such a way that the cake number i can be placed only on the table or on some cake number j where j < i. Moreover, in order to impress friends Babaei will put the cake i on top of the cake j only if the volume of the cake i is strictly greater than the volume of the cake j.
Babaei wants to prepare a birthday cake that has a maximum possible total volume. Help him find this value.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of simple cakes Babaei has.
Each of the following n lines contains two integers ri and hi (1 ≤ ri, hi ≤ 10 000), giving the radius and height of the i-th cake.
Output
Print the maximum volume of the cake that Babaei can make. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>.
Examples
Input
2
100 30
40 10
Output
942477.796077000
Input
4
1 1
9 7
1 4
10 7
Output
3983.539484752
Note
In first sample, the optimal way is to choose the cake number 1.
In second sample, the way to get the maximum volume is to use cakes with indices 1, 2 and 4.
Submitted Solution:
```
#adapted his
def his(l):
max1 = [0] * len(l)
r1 = [0] * len(l)
for i, j in enumerate(sorted(range(len(l)), key=lambda i: l[i])):
r1[j] = i
for i, x in enumerate(l):
r = r1[i]
r2 = 0
i2 = r
while i2 > 0:
r2 = max(r2, max1[i2-1])
i2 &= i2 - 1
i2 = r
while i2 < len(max1):
max1[i2] = max(x+r2,max1[i2])
i2|=i2+1
r2 = 0
i2 = len(l)
while i2 > 0:
r2 = max(r2, max1[i2-1])
i2 &= i2-1
return r2
n = int(input())
l = []
for i in range(n):
j,k = map(int, input().split())
l.append(j*j*3.14159265358979*k)
print(his(l))
``` | instruction | 0 | 9,516 | 9 | 19,032 |
No | output | 1 | 9,516 | 9 | 19,033 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
As you know, every birthday party has a cake! This time, Babaei is going to prepare the very special birthday party's cake.
Simple cake is a cylinder of some radius and height. The volume of the simple cake is equal to the volume of corresponding cylinder. Babaei has n simple cakes and he is going to make a special cake placing some cylinders on each other.
However, there are some additional culinary restrictions. The cakes are numbered in such a way that the cake number i can be placed only on the table or on some cake number j where j < i. Moreover, in order to impress friends Babaei will put the cake i on top of the cake j only if the volume of the cake i is strictly greater than the volume of the cake j.
Babaei wants to prepare a birthday cake that has a maximum possible total volume. Help him find this value.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of simple cakes Babaei has.
Each of the following n lines contains two integers ri and hi (1 ≤ ri, hi ≤ 10 000), giving the radius and height of the i-th cake.
Output
Print the maximum volume of the cake that Babaei can make. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.
Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if <image>.
Examples
Input
2
100 30
40 10
Output
942477.796077000
Input
4
1 1
9 7
1 4
10 7
Output
3983.539484752
Note
In first sample, the optimal way is to choose the cake number 1.
In second sample, the way to get the maximum volume is to use cakes with indices 1, 2 and 4.
Submitted Solution:
```
from math import pi
n = int(input())
secuencia = [None] * n
maximo_to = -1
for num in range(n):
r, h = (int(x) for x in input().strip().split())
secuencia[num] = [r * r * h, num + 1, None]
secuencia.sort(key=lambda x: x[0])
actual = 0
est_actual = 0
for num in range(n):
if secuencia[num][0] > actual:
est_actual += 1
secuencia[num][2] = est_actual
bit = [0] * (est_actual + 1)
def max_x(x, l):
suma = 0
while x != 0:
suma = max(suma, l[x])
x -= (x & -x)
return suma
def update_x(x, l, max_n, val):
while x <= max_n:
if val > l[x]:
l[x] = val
else:
return
x += (x & -x)
for e in range(n):
maximo = secuencia[e][0] + max_x(secuencia[e][1] - 1, bit)
update_x(secuencia[e][1], bit, est_actual, maximo)
if maximo > maximo_to:
maximo_to = maximo
print(maximo_to * pi)
``` | instruction | 0 | 9,517 | 9 | 19,034 |
No | output | 1 | 9,517 | 9 | 19,035 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are n days, at the i-th day, Arya finds ai candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her candies. If she don't give him the candies at the same day, they are saved for her and she can give them to him later.
Your task is to find the minimum number of days Arya needs to give Bran k candies before the end of the n-th day. Formally, you need to output the minimum day index to the end of which k candies will be given out (the days are indexed from 1 to n).
Print -1 if she can't give him k candies during n given days.
Input
The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 10000).
The second line contains n integers a1, a2, a3, ..., an (1 ≤ ai ≤ 100).
Output
If it is impossible for Arya to give Bran k candies within n days, print -1.
Otherwise print a single integer — the minimum number of days Arya needs to give Bran k candies before the end of the n-th day.
Examples
Input
2 3
1 2
Output
2
Input
3 17
10 10 10
Output
3
Input
1 9
10
Output
-1
Note
In the first sample, Arya can give Bran 3 candies in 2 days.
In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day.
In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies within 1 day. | instruction | 0 | 9,594 | 9 | 19,188 |
Tags: implementation
Correct Solution:
```
n,k=map(int,input().split())
a=list(map(int,input().split()))
summ=0
for j in range(n):
summ+=a[j]
if n*8>=k and k<=summ:
carramel=0
for i in range(n):
carramel+=a[i]
if carramel>8:
k-=8
carramel-=8
else:
k-=carramel
carramel=0
if k<=0:
days=i+1
print(days)
break
if k>0:
print('-1')
else:
print('-1')
``` | output | 1 | 9,594 | 9 | 19,189 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are n days, at the i-th day, Arya finds ai candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her candies. If she don't give him the candies at the same day, they are saved for her and she can give them to him later.
Your task is to find the minimum number of days Arya needs to give Bran k candies before the end of the n-th day. Formally, you need to output the minimum day index to the end of which k candies will be given out (the days are indexed from 1 to n).
Print -1 if she can't give him k candies during n given days.
Input
The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 10000).
The second line contains n integers a1, a2, a3, ..., an (1 ≤ ai ≤ 100).
Output
If it is impossible for Arya to give Bran k candies within n days, print -1.
Otherwise print a single integer — the minimum number of days Arya needs to give Bran k candies before the end of the n-th day.
Examples
Input
2 3
1 2
Output
2
Input
3 17
10 10 10
Output
3
Input
1 9
10
Output
-1
Note
In the first sample, Arya can give Bran 3 candies in 2 days.
In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day.
In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies within 1 day. | instruction | 0 | 9,595 | 9 | 19,190 |
Tags: implementation
Correct Solution:
```
n, k = map(int, input().split())
l = list(map(int, input().split()))
s = 0
for i in range(n):
s += l[i]
k -= min(s, 8)
s -= min(s, 8)
if k <= 0:
print(i + 1)
exit(0)
print(-1)
``` | output | 1 | 9,595 | 9 | 19,191 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are n days, at the i-th day, Arya finds ai candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her candies. If she don't give him the candies at the same day, they are saved for her and she can give them to him later.
Your task is to find the minimum number of days Arya needs to give Bran k candies before the end of the n-th day. Formally, you need to output the minimum day index to the end of which k candies will be given out (the days are indexed from 1 to n).
Print -1 if she can't give him k candies during n given days.
Input
The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 10000).
The second line contains n integers a1, a2, a3, ..., an (1 ≤ ai ≤ 100).
Output
If it is impossible for Arya to give Bran k candies within n days, print -1.
Otherwise print a single integer — the minimum number of days Arya needs to give Bran k candies before the end of the n-th day.
Examples
Input
2 3
1 2
Output
2
Input
3 17
10 10 10
Output
3
Input
1 9
10
Output
-1
Note
In the first sample, Arya can give Bran 3 candies in 2 days.
In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day.
In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies within 1 day. | instruction | 0 | 9,596 | 9 | 19,192 |
Tags: implementation
Correct Solution:
```
n, k = map(int, input().split())
l = list(map(int, input().split()))
have = 0
for i in range(0, n):
have+=l[i]
x= min(8, have)
k -=x
have-=x
if k<=0:
print(i+1)
exit()
print(-1)
``` | output | 1 | 9,596 | 9 | 19,193 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are n days, at the i-th day, Arya finds ai candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her candies. If she don't give him the candies at the same day, they are saved for her and she can give them to him later.
Your task is to find the minimum number of days Arya needs to give Bran k candies before the end of the n-th day. Formally, you need to output the minimum day index to the end of which k candies will be given out (the days are indexed from 1 to n).
Print -1 if she can't give him k candies during n given days.
Input
The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 10000).
The second line contains n integers a1, a2, a3, ..., an (1 ≤ ai ≤ 100).
Output
If it is impossible for Arya to give Bran k candies within n days, print -1.
Otherwise print a single integer — the minimum number of days Arya needs to give Bran k candies before the end of the n-th day.
Examples
Input
2 3
1 2
Output
2
Input
3 17
10 10 10
Output
3
Input
1 9
10
Output
-1
Note
In the first sample, Arya can give Bran 3 candies in 2 days.
In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day.
In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies within 1 day. | instruction | 0 | 9,597 | 9 | 19,194 |
Tags: implementation
Correct Solution:
```
n,k = list(map(int, input().rstrip().split()))
days = list(map(int, input().rstrip().split()))
r = 0
for i, a in enumerate(days):
if a + r > 8:
r += a - 8
k -= 8
else:
k -= a + r
r = 0;
if k <= 0:
print(i + 1)
break
else:
print(-1)
``` | output | 1 | 9,597 | 9 | 19,195 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are n days, at the i-th day, Arya finds ai candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her candies. If she don't give him the candies at the same day, they are saved for her and she can give them to him later.
Your task is to find the minimum number of days Arya needs to give Bran k candies before the end of the n-th day. Formally, you need to output the minimum day index to the end of which k candies will be given out (the days are indexed from 1 to n).
Print -1 if she can't give him k candies during n given days.
Input
The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 10000).
The second line contains n integers a1, a2, a3, ..., an (1 ≤ ai ≤ 100).
Output
If it is impossible for Arya to give Bran k candies within n days, print -1.
Otherwise print a single integer — the minimum number of days Arya needs to give Bran k candies before the end of the n-th day.
Examples
Input
2 3
1 2
Output
2
Input
3 17
10 10 10
Output
3
Input
1 9
10
Output
-1
Note
In the first sample, Arya can give Bran 3 candies in 2 days.
In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day.
In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies within 1 day. | instruction | 0 | 9,598 | 9 | 19,196 |
Tags: implementation
Correct Solution:
```
import sys
read=lambda:sys.stdin.readline().rstrip()
readi=lambda:int(sys.stdin.readline())
writeln=lambda x:sys.stdout.write(str(x)+"\n")
write=lambda x:sys.stdout.write(x)
N, K = map(int, read().split())
ns = list(map(int, read().split()))
A,B = 0,0
ans = -1
for i in range(N):
A += ns[i]
if A >= 8:
A -= 8
B += 8
else:
B += A
A = 0
if B >= K:
ans = i+1
break
writeln(ans)
``` | output | 1 | 9,598 | 9 | 19,197 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are n days, at the i-th day, Arya finds ai candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her candies. If she don't give him the candies at the same day, they are saved for her and she can give them to him later.
Your task is to find the minimum number of days Arya needs to give Bran k candies before the end of the n-th day. Formally, you need to output the minimum day index to the end of which k candies will be given out (the days are indexed from 1 to n).
Print -1 if she can't give him k candies during n given days.
Input
The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 10000).
The second line contains n integers a1, a2, a3, ..., an (1 ≤ ai ≤ 100).
Output
If it is impossible for Arya to give Bran k candies within n days, print -1.
Otherwise print a single integer — the minimum number of days Arya needs to give Bran k candies before the end of the n-th day.
Examples
Input
2 3
1 2
Output
2
Input
3 17
10 10 10
Output
3
Input
1 9
10
Output
-1
Note
In the first sample, Arya can give Bran 3 candies in 2 days.
In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day.
In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies within 1 day. | instruction | 0 | 9,599 | 9 | 19,198 |
Tags: implementation
Correct Solution:
```
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
count=0
ana,f=0,0
ans=0
for val in a:
if ans>=k:
f=1
break
if val+ana<=8:
ans+=val+ana
ana=0
count+=1
else:
ana=(val+ana)-8
count+=1
ans+=8
if f==1 or ans>=k :
print(count)
else:
print(-1)
``` | output | 1 | 9,599 | 9 | 19,199 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are n days, at the i-th day, Arya finds ai candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her candies. If she don't give him the candies at the same day, they are saved for her and she can give them to him later.
Your task is to find the minimum number of days Arya needs to give Bran k candies before the end of the n-th day. Formally, you need to output the minimum day index to the end of which k candies will be given out (the days are indexed from 1 to n).
Print -1 if she can't give him k candies during n given days.
Input
The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 10000).
The second line contains n integers a1, a2, a3, ..., an (1 ≤ ai ≤ 100).
Output
If it is impossible for Arya to give Bran k candies within n days, print -1.
Otherwise print a single integer — the minimum number of days Arya needs to give Bran k candies before the end of the n-th day.
Examples
Input
2 3
1 2
Output
2
Input
3 17
10 10 10
Output
3
Input
1 9
10
Output
-1
Note
In the first sample, Arya can give Bran 3 candies in 2 days.
In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day.
In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies within 1 day. | instruction | 0 | 9,600 | 9 | 19,200 |
Tags: implementation
Correct Solution:
```
n, k = map(int, input().split())
a = list(map(int, input().split()))
c = d = 0
for i in range(n):
add = min(8, c + a[i])
if add >= 8: c = c + a[i] - add
else: c = 0
d += add
if d >= k:
print(i + 1)
break
else:
print(-1)
``` | output | 1 | 9,600 | 9 | 19,201 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are n days, at the i-th day, Arya finds ai candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her candies. If she don't give him the candies at the same day, they are saved for her and she can give them to him later.
Your task is to find the minimum number of days Arya needs to give Bran k candies before the end of the n-th day. Formally, you need to output the minimum day index to the end of which k candies will be given out (the days are indexed from 1 to n).
Print -1 if she can't give him k candies during n given days.
Input
The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 10000).
The second line contains n integers a1, a2, a3, ..., an (1 ≤ ai ≤ 100).
Output
If it is impossible for Arya to give Bran k candies within n days, print -1.
Otherwise print a single integer — the minimum number of days Arya needs to give Bran k candies before the end of the n-th day.
Examples
Input
2 3
1 2
Output
2
Input
3 17
10 10 10
Output
3
Input
1 9
10
Output
-1
Note
In the first sample, Arya can give Bran 3 candies in 2 days.
In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day.
In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies within 1 day. | instruction | 0 | 9,601 | 9 | 19,202 |
Tags: implementation
Correct Solution:
```
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
x = 0
y = 0
z = 0
b = 0
for i in a:
b += 1
x += i
if x >= 8:
y += 8
else:
y += x
x -= 8
if x<0:
x = 0
if y >= k:
z = i
break
if z == 0:
print(-1)
else:
print(b)
``` | output | 1 | 9,601 | 9 | 19,203 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are n days, at the i-th day, Arya finds ai candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her candies. If she don't give him the candies at the same day, they are saved for her and she can give them to him later.
Your task is to find the minimum number of days Arya needs to give Bran k candies before the end of the n-th day. Formally, you need to output the minimum day index to the end of which k candies will be given out (the days are indexed from 1 to n).
Print -1 if she can't give him k candies during n given days.
Input
The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 10000).
The second line contains n integers a1, a2, a3, ..., an (1 ≤ ai ≤ 100).
Output
If it is impossible for Arya to give Bran k candies within n days, print -1.
Otherwise print a single integer — the minimum number of days Arya needs to give Bran k candies before the end of the n-th day.
Examples
Input
2 3
1 2
Output
2
Input
3 17
10 10 10
Output
3
Input
1 9
10
Output
-1
Note
In the first sample, Arya can give Bran 3 candies in 2 days.
In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day.
In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies within 1 day.
Submitted Solution:
```
n, k = map(int, input().split())
m = list(map(int, input().split()))
arya = 0
sweet = 0
day = 0
ans = -1
for i in m:
day += 1
if i > 8:
sweet += 8
arya += i - 8
else:
if arya + i >= 8:
sweet += 8
arya -= (8 - i)
else:
sweet += i + arya
arya = 0
if sweet >= k:
ans = day
break
print(ans)
``` | instruction | 0 | 9,602 | 9 | 19,204 |
Yes | output | 1 | 9,602 | 9 | 19,205 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are n days, at the i-th day, Arya finds ai candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her candies. If she don't give him the candies at the same day, they are saved for her and she can give them to him later.
Your task is to find the minimum number of days Arya needs to give Bran k candies before the end of the n-th day. Formally, you need to output the minimum day index to the end of which k candies will be given out (the days are indexed from 1 to n).
Print -1 if she can't give him k candies during n given days.
Input
The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 10000).
The second line contains n integers a1, a2, a3, ..., an (1 ≤ ai ≤ 100).
Output
If it is impossible for Arya to give Bran k candies within n days, print -1.
Otherwise print a single integer — the minimum number of days Arya needs to give Bran k candies before the end of the n-th day.
Examples
Input
2 3
1 2
Output
2
Input
3 17
10 10 10
Output
3
Input
1 9
10
Output
-1
Note
In the first sample, Arya can give Bran 3 candies in 2 days.
In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day.
In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies within 1 day.
Submitted Solution:
```
from sys import stdin, stdout
n, k = map(int, stdin.readline().split())
values = list(map(int, stdin.readline().split()))
cnt = 0
sweet = 0
for i in range(n):
cnt += values[i]
v = min(min(cnt, 8), k - sweet)
sweet += v
cnt -= v
if sweet == k:
stdout.write(str(i + 1))
break
else:
stdout.write('-1')
``` | instruction | 0 | 9,603 | 9 | 19,206 |
Yes | output | 1 | 9,603 | 9 | 19,207 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are n days, at the i-th day, Arya finds ai candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her candies. If she don't give him the candies at the same day, they are saved for her and she can give them to him later.
Your task is to find the minimum number of days Arya needs to give Bran k candies before the end of the n-th day. Formally, you need to output the minimum day index to the end of which k candies will be given out (the days are indexed from 1 to n).
Print -1 if she can't give him k candies during n given days.
Input
The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 10000).
The second line contains n integers a1, a2, a3, ..., an (1 ≤ ai ≤ 100).
Output
If it is impossible for Arya to give Bran k candies within n days, print -1.
Otherwise print a single integer — the minimum number of days Arya needs to give Bran k candies before the end of the n-th day.
Examples
Input
2 3
1 2
Output
2
Input
3 17
10 10 10
Output
3
Input
1 9
10
Output
-1
Note
In the first sample, Arya can give Bran 3 candies in 2 days.
In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day.
In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies within 1 day.
Submitted Solution:
```
n,k=map(int,input().split())
l = map(int,input().split())
l=list(l)
if sum(l)<k or 8*n<k:
print(-1)
else:
s=0
t=True
i=0
d=0
while s<k :
try:
if l[i]>=8:
s+=8
d+=l[i]-8
else:
s+=l[i]+min(d,8-l[i])
d-=min(d,8-l[i])
i+=1
except IndexError:
t=False
print(-1)
break
if t:
print(i)
``` | instruction | 0 | 9,604 | 9 | 19,208 |
Yes | output | 1 | 9,604 | 9 | 19,209 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are n days, at the i-th day, Arya finds ai candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her candies. If she don't give him the candies at the same day, they are saved for her and she can give them to him later.
Your task is to find the minimum number of days Arya needs to give Bran k candies before the end of the n-th day. Formally, you need to output the minimum day index to the end of which k candies will be given out (the days are indexed from 1 to n).
Print -1 if she can't give him k candies during n given days.
Input
The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 10000).
The second line contains n integers a1, a2, a3, ..., an (1 ≤ ai ≤ 100).
Output
If it is impossible for Arya to give Bran k candies within n days, print -1.
Otherwise print a single integer — the minimum number of days Arya needs to give Bran k candies before the end of the n-th day.
Examples
Input
2 3
1 2
Output
2
Input
3 17
10 10 10
Output
3
Input
1 9
10
Output
-1
Note
In the first sample, Arya can give Bran 3 candies in 2 days.
In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day.
In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies within 1 day.
Submitted Solution:
```
n , k = map(int,input().split())
a = [int(i) for i in input().split()][:n]
d = 0
e = 0
if k > sum(a):
print(-1)
else:
for item in a:
if item+e >= 8:
k-=8
e += (item-8)
else:
k-=item+e
e = 0
d+=1
if k <= 0:
print(d)
break
if d == n:
print(-1)
break
``` | instruction | 0 | 9,605 | 9 | 19,210 |
Yes | output | 1 | 9,605 | 9 | 19,211 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are n days, at the i-th day, Arya finds ai candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her candies. If she don't give him the candies at the same day, they are saved for her and she can give them to him later.
Your task is to find the minimum number of days Arya needs to give Bran k candies before the end of the n-th day. Formally, you need to output the minimum day index to the end of which k candies will be given out (the days are indexed from 1 to n).
Print -1 if she can't give him k candies during n given days.
Input
The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 10000).
The second line contains n integers a1, a2, a3, ..., an (1 ≤ ai ≤ 100).
Output
If it is impossible for Arya to give Bran k candies within n days, print -1.
Otherwise print a single integer — the minimum number of days Arya needs to give Bran k candies before the end of the n-th day.
Examples
Input
2 3
1 2
Output
2
Input
3 17
10 10 10
Output
3
Input
1 9
10
Output
-1
Note
In the first sample, Arya can give Bran 3 candies in 2 days.
In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day.
In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies within 1 day.
Submitted Solution:
```
x, y = map(int, input().split(" "))
z=input()
a=[]
i=0
while i<x:
a.append(int(z.split(" ")[i]))
i=i+1
if y//x>8 or sum(a)<y or max(a)<8:
print(-1)
else:
j=0
current_sum=0
a.sort(reverse=True)
while j<x:
current_sum=8*(j+1)
if current_sum>=y:
print(j+1)
break
j=j+1
``` | instruction | 0 | 9,606 | 9 | 19,212 |
No | output | 1 | 9,606 | 9 | 19,213 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are n days, at the i-th day, Arya finds ai candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her candies. If she don't give him the candies at the same day, they are saved for her and she can give them to him later.
Your task is to find the minimum number of days Arya needs to give Bran k candies before the end of the n-th day. Formally, you need to output the minimum day index to the end of which k candies will be given out (the days are indexed from 1 to n).
Print -1 if she can't give him k candies during n given days.
Input
The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 10000).
The second line contains n integers a1, a2, a3, ..., an (1 ≤ ai ≤ 100).
Output
If it is impossible for Arya to give Bran k candies within n days, print -1.
Otherwise print a single integer — the minimum number of days Arya needs to give Bran k candies before the end of the n-th day.
Examples
Input
2 3
1 2
Output
2
Input
3 17
10 10 10
Output
3
Input
1 9
10
Output
-1
Note
In the first sample, Arya can give Bran 3 candies in 2 days.
In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day.
In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies within 1 day.
Submitted Solution:
```
x, y = map(int, input().split(" "))
z=input()
a=[]
i=0
while i<x:
a.append(int(z.split(" ")[i]))
i=i+1
if y//x>8:
print(-1)
else:
print(x)
``` | instruction | 0 | 9,607 | 9 | 19,214 |
No | output | 1 | 9,607 | 9 | 19,215 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are n days, at the i-th day, Arya finds ai candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her candies. If she don't give him the candies at the same day, they are saved for her and she can give them to him later.
Your task is to find the minimum number of days Arya needs to give Bran k candies before the end of the n-th day. Formally, you need to output the minimum day index to the end of which k candies will be given out (the days are indexed from 1 to n).
Print -1 if she can't give him k candies during n given days.
Input
The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 10000).
The second line contains n integers a1, a2, a3, ..., an (1 ≤ ai ≤ 100).
Output
If it is impossible for Arya to give Bran k candies within n days, print -1.
Otherwise print a single integer — the minimum number of days Arya needs to give Bran k candies before the end of the n-th day.
Examples
Input
2 3
1 2
Output
2
Input
3 17
10 10 10
Output
3
Input
1 9
10
Output
-1
Note
In the first sample, Arya can give Bran 3 candies in 2 days.
In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day.
In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies within 1 day.
Submitted Solution:
```
nk = list(map(int, input().split()))
a = list(map(int, input().split()))
day = 0
bank = 0
while nk[1] > 0 and day < nk[0]:
day += 1
if a[day - 1] > 8:
bank += a[day - 1] - 8
nk[1] -= 8
else:
nk[1] -= (a[day - 1] + min(bank, 8 - a[day - 1]))
bank -= min(bank, a[day - 1])
if nk[1] > 0:
print(-1)
else:
print(day)
``` | instruction | 0 | 9,608 | 9 | 19,216 |
No | output | 1 | 9,608 | 9 | 19,217 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are n days, at the i-th day, Arya finds ai candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her candies. If she don't give him the candies at the same day, they are saved for her and she can give them to him later.
Your task is to find the minimum number of days Arya needs to give Bran k candies before the end of the n-th day. Formally, you need to output the minimum day index to the end of which k candies will be given out (the days are indexed from 1 to n).
Print -1 if she can't give him k candies during n given days.
Input
The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 10000).
The second line contains n integers a1, a2, a3, ..., an (1 ≤ ai ≤ 100).
Output
If it is impossible for Arya to give Bran k candies within n days, print -1.
Otherwise print a single integer — the minimum number of days Arya needs to give Bran k candies before the end of the n-th day.
Examples
Input
2 3
1 2
Output
2
Input
3 17
10 10 10
Output
3
Input
1 9
10
Output
-1
Note
In the first sample, Arya can give Bran 3 candies in 2 days.
In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day.
In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies within 1 day.
Submitted Solution:
```
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = 0
c = 0
ans = 0
for i in range(n):
a[i] += c
if a[i] > 8:
c += (a[i] - 8)
b += 8
ans += 1
else:
b += a[i]
ans += 1
if b >= k:
print(ans)
break
if b < k and i + 1 == n:
print('-1')
``` | instruction | 0 | 9,609 | 9 | 19,218 |
No | output | 1 | 9,609 | 9 | 19,219 |
Provide a correct Python 3 solution for this coding contest problem.
The cake shop made a lot of roll cakes of various sizes. You have been tasked with arranging this cake in a box.
The roll cake is so soft that it will collapse if another roll cake is on top. Therefore, as shown in Fig. (A), all roll cakes must be arranged so that they touch the bottom of the box. Sorting also changes the required width.
<image>
---
Figure (a)
<image>
Figure (b)
Read the radii r1, r2, ..., rn of n roll cakes and the length of the box, judge whether they fit well in the box, and devise the order of arrangement. ", Create a program that outputs" NA "if it does not fit in any order.
It is assumed that the cross section of the roll cake is a circle and the height of the wall of the box is high enough. However, the radius of the roll cake should be an integer between 3 and 10. In other words, there is no extreme difference in cake radii, and small cakes do not get stuck between large cakes as shown in Figure (b).
Input
The input consists of multiple datasets. Each dataset is given in the following format:
W r1 r2 ... rn
First, the integer W (1 ≤ W ≤ 1,000) representing the length of the box is given. It is then given the integer ri (3 ≤ ri ≤ 10), which represents the radius of each roll cake, separated by blanks. The number of cakes n is 12 or less.
The number of datasets does not exceed 50.
Output
Print OK or NA on one line for each dataset.
Example
Input
30 4 5 6
30 5 5 5
50 3 3 3 10 10
49 3 3 3 10 10
Output
OK
OK
OK
NA | instruction | 0 | 9,785 | 9 | 19,570 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0120
"""
import sys
from sys import stdin
input = stdin.readline
def calc_width(cakes):
# ??±????????????????????????(?????????)????????????????????????????????????????¨??????????
if len(cakes) == 1:
return cakes[0]*2
prev_r = cakes[0]
width = prev_r
for r in cakes[1:]:
h_diff = abs(prev_r - r)
w = ((prev_r + r)**2 - h_diff**2)**0.5
width += w
prev_r = r
width += cakes[-1]
return width
def main(args):
for line in sys.stdin:
data = [int(x) for x in line.strip().split()]
box_size = data[0]
temp = data[1:]
temp.sort()
# ??±??????????????????????????????????????????????????????????????????????????????
min_width = float('inf')
cakes = [temp[0]]
temp = temp[1:]
pick_large = True
while temp:
if pick_large:
pick = temp[-1]
temp = temp[:-1]
pick_large = False
diff_front = abs(pick - cakes[0])
diff_rear = abs(pick - cakes[-1])
if diff_front > diff_rear:
cakes.insert(0, pick)
else:
cakes.append(pick)
else:
pick = temp[0]
temp = temp[1:]
pick_large = True
diff_front = abs(pick - cakes[0])
diff_rear = abs(pick - cakes[-1])
if diff_front > diff_rear:
cakes.insert(0, pick)
else:
cakes.append(pick)
result = calc_width(cakes)
min_width = min(result, min_width)
if min_width <= box_size:
print('OK')
else:
print('NA')
if __name__ == '__main__':
main(sys.argv[1:])
``` | output | 1 | 9,785 | 9 | 19,571 |
Provide a correct Python 3 solution for this coding contest problem.
The cake shop made a lot of roll cakes of various sizes. You have been tasked with arranging this cake in a box.
The roll cake is so soft that it will collapse if another roll cake is on top. Therefore, as shown in Fig. (A), all roll cakes must be arranged so that they touch the bottom of the box. Sorting also changes the required width.
<image>
---
Figure (a)
<image>
Figure (b)
Read the radii r1, r2, ..., rn of n roll cakes and the length of the box, judge whether they fit well in the box, and devise the order of arrangement. ", Create a program that outputs" NA "if it does not fit in any order.
It is assumed that the cross section of the roll cake is a circle and the height of the wall of the box is high enough. However, the radius of the roll cake should be an integer between 3 and 10. In other words, there is no extreme difference in cake radii, and small cakes do not get stuck between large cakes as shown in Figure (b).
Input
The input consists of multiple datasets. Each dataset is given in the following format:
W r1 r2 ... rn
First, the integer W (1 ≤ W ≤ 1,000) representing the length of the box is given. It is then given the integer ri (3 ≤ ri ≤ 10), which represents the radius of each roll cake, separated by blanks. The number of cakes n is 12 or less.
The number of datasets does not exceed 50.
Output
Print OK or NA on one line for each dataset.
Example
Input
30 4 5 6
30 5 5 5
50 3 3 3 10 10
49 3 3 3 10 10
Output
OK
OK
OK
NA | instruction | 0 | 9,786 | 9 | 19,572 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0120
"""
import sys
from sys import stdin
input = stdin.readline
def calc_width(cakes):
# ??±????????????????????????(?????????)????????????????????????????????????????¨??????????
if len(cakes) == 1:
return cakes[0]*2
prev_r = cakes[0]
width = prev_r
for r in cakes[1:]:
h_diff = abs(prev_r - r)
if h_diff == 0:
width += prev_r
width += r
else:
w = ((prev_r + r)**2 - h_diff**2)**0.5
width += w
prev_r = r
width += cakes[-1]
return width
def main(args):
for line in sys.stdin:
data = [int(x) for x in line.strip().split()]
box_size = data[0]
temp = data[1:]
temp.sort()
min_width = float('inf')
cake = []
if len(temp) < 3:
cakes = temp[:]
elif len(temp) == 3:
cakes = [temp[1], temp[2], temp[0]]
else:
cakes = [temp[1] ,temp[-1], temp[0]]
temp = temp[2:-1]
tail = True
small = False
while temp:
if tail:
if small:
cakes.append(temp[0])
temp = temp[1:]
tail = False
else:
cakes.append(temp[-1])
temp = temp[:-1]
tail = False
else:
if small:
cakes.insert(0, temp[0])
temp = temp[1:]
small = False
tail = True
else:
cakes.insert(0, temp[-1])
temp = temp[:-1]
small = True
tail = True
result = calc_width(cakes)
min_width = min(result, min_width)
temp = data[1:]
temp.sort()
cake = []
if len(temp) < 3:
cakes = temp[:]
elif len(temp) == 3:
cakes = [temp[1], temp[0], temp[2]]
else:
cakes = [temp[-2] ,temp[0], temp[-1]]
temp = temp[1:-2]
tail = True
small = True
while temp:
if tail:
if small:
cakes.append(temp[0])
temp = temp[1:]
tail = False
else:
cakes.append(temp[-1])
temp = temp[:-1]
tail = False
else:
if small:
cakes.insert(0, temp[0])
temp = temp[1:]
small = False
tail = True
else:
cakes.insert(0, temp[-1])
temp = temp[:-1]
small = True
tail = True
result = calc_width(cakes)
min_width = min(result, min_width)
if min_width <= box_size:
print('OK')
else:
print('NA')
from itertools import permutations
def main2(args):
data = [3, 3, 3, 10, 10]
p = permutations(data, len(data))
best_fit = float('inf')
for cakes in p:
result = calc_width(cakes)
if result < best_fit:
best_fit = result
print(cakes)
print(result)
if __name__ == '__main__':
main(sys.argv[1:])
``` | output | 1 | 9,786 | 9 | 19,573 |
Provide a correct Python 3 solution for this coding contest problem.
The cake shop made a lot of roll cakes of various sizes. You have been tasked with arranging this cake in a box.
The roll cake is so soft that it will collapse if another roll cake is on top. Therefore, as shown in Fig. (A), all roll cakes must be arranged so that they touch the bottom of the box. Sorting also changes the required width.
<image>
---
Figure (a)
<image>
Figure (b)
Read the radii r1, r2, ..., rn of n roll cakes and the length of the box, judge whether they fit well in the box, and devise the order of arrangement. ", Create a program that outputs" NA "if it does not fit in any order.
It is assumed that the cross section of the roll cake is a circle and the height of the wall of the box is high enough. However, the radius of the roll cake should be an integer between 3 and 10. In other words, there is no extreme difference in cake radii, and small cakes do not get stuck between large cakes as shown in Figure (b).
Input
The input consists of multiple datasets. Each dataset is given in the following format:
W r1 r2 ... rn
First, the integer W (1 ≤ W ≤ 1,000) representing the length of the box is given. It is then given the integer ri (3 ≤ ri ≤ 10), which represents the radius of each roll cake, separated by blanks. The number of cakes n is 12 or less.
The number of datasets does not exceed 50.
Output
Print OK or NA on one line for each dataset.
Example
Input
30 4 5 6
30 5 5 5
50 3 3 3 10 10
49 3 3 3 10 10
Output
OK
OK
OK
NA | instruction | 0 | 9,787 | 9 | 19,574 |
"Correct Solution:
```
INF = 10 ** 20
def get_dist(r1, r2):
return ((r1 + r2) ** 2 - (r1 - r2) ** 2) ** (1 / 2)
def minimum_width(rest, r, dic):
if (rest, r) in dic:
return dic[(rest, r)]
if rest == ():
return r
ret = INF
lenr = len(rest)
for c in rest:
next_rest = list(rest)
next_rest.remove(c)
ret = min(ret, minimum_width(tuple(next_rest), c, dic) + get_dist(r, c))
dic[(rest, r)] = ret
return ret
while True:
try:
lst = list(map(int, input().split()))
w = lst[0]
cakes = lst[1:]
cakes.sort()
lenc = len(cakes)
dic = {}
ans = INF
for i in range(lenc):
ans = min(ans, minimum_width(tuple(cakes[j] for j in range(lenc) if i != j), cakes[i], dic) + cakes[i])
if w >= ans:
print("OK")
else:
print("NA")
except EOFError:
break
``` | output | 1 | 9,787 | 9 | 19,575 |
Provide a correct Python 3 solution for this coding contest problem.
The cake shop made a lot of roll cakes of various sizes. You have been tasked with arranging this cake in a box.
The roll cake is so soft that it will collapse if another roll cake is on top. Therefore, as shown in Fig. (A), all roll cakes must be arranged so that they touch the bottom of the box. Sorting also changes the required width.
<image>
---
Figure (a)
<image>
Figure (b)
Read the radii r1, r2, ..., rn of n roll cakes and the length of the box, judge whether they fit well in the box, and devise the order of arrangement. ", Create a program that outputs" NA "if it does not fit in any order.
It is assumed that the cross section of the roll cake is a circle and the height of the wall of the box is high enough. However, the radius of the roll cake should be an integer between 3 and 10. In other words, there is no extreme difference in cake radii, and small cakes do not get stuck between large cakes as shown in Figure (b).
Input
The input consists of multiple datasets. Each dataset is given in the following format:
W r1 r2 ... rn
First, the integer W (1 ≤ W ≤ 1,000) representing the length of the box is given. It is then given the integer ri (3 ≤ ri ≤ 10), which represents the radius of each roll cake, separated by blanks. The number of cakes n is 12 or less.
The number of datasets does not exceed 50.
Output
Print OK or NA on one line for each dataset.
Example
Input
30 4 5 6
30 5 5 5
50 3 3 3 10 10
49 3 3 3 10 10
Output
OK
OK
OK
NA | instruction | 0 | 9,788 | 9 | 19,576 |
"Correct Solution:
```
#######################################################################################
import sys
from math import sqrt
def rec(state, v):
if state == (1 << N) - 1:
return cakes[v]
if dp[state][v] != -1:
return dp[state][v]
ret = INF
for u in range(N):
if state == 0:
ret = min(ret, rec(1 << u, u) + cakes[u])
elif not (state >> u & 1):
ret = min(ret, rec(state | 1 << u, u) + sqrt(pow(cakes[u] + cakes[v], 2) - pow(cakes[u] - cakes[v], 2)))
dp[state][v] = ret
return ret
testcases = [[int(x) for x in line.split()] for line in sys.stdin.readlines()]
for testcase in testcases:
box, *cakes = testcase
N = len(cakes)
INF = box + 1
dp = [[-1] * N for _ in range(1 << N)]
print('OK' if rec(0, 0) <= box else 'NA')
``` | output | 1 | 9,788 | 9 | 19,577 |
Provide a correct Python 3 solution for this coding contest problem.
The cake shop made a lot of roll cakes of various sizes. You have been tasked with arranging this cake in a box.
The roll cake is so soft that it will collapse if another roll cake is on top. Therefore, as shown in Fig. (A), all roll cakes must be arranged so that they touch the bottom of the box. Sorting also changes the required width.
<image>
---
Figure (a)
<image>
Figure (b)
Read the radii r1, r2, ..., rn of n roll cakes and the length of the box, judge whether they fit well in the box, and devise the order of arrangement. ", Create a program that outputs" NA "if it does not fit in any order.
It is assumed that the cross section of the roll cake is a circle and the height of the wall of the box is high enough. However, the radius of the roll cake should be an integer between 3 and 10. In other words, there is no extreme difference in cake radii, and small cakes do not get stuck between large cakes as shown in Figure (b).
Input
The input consists of multiple datasets. Each dataset is given in the following format:
W r1 r2 ... rn
First, the integer W (1 ≤ W ≤ 1,000) representing the length of the box is given. It is then given the integer ri (3 ≤ ri ≤ 10), which represents the radius of each roll cake, separated by blanks. The number of cakes n is 12 or less.
The number of datasets does not exceed 50.
Output
Print OK or NA on one line for each dataset.
Example
Input
30 4 5 6
30 5 5 5
50 3 3 3 10 10
49 3 3 3 10 10
Output
OK
OK
OK
NA | instruction | 0 | 9,789 | 9 | 19,578 |
"Correct Solution:
```
import sys
from math import sqrt
def rec(state, v):
if state == (1 << N) - 1:
return cakes[v]
if dp[state][v] != -1:
return dp[state][v]
ret = INF
for i in range(N):
if state == 0:
ret = min(ret, rec(1 << i, i) + cakes[i])
elif not (state >> i & 1):
ret = min(ret, rec(state | 1 << i, i) + sqrt(pow(cakes[i] + cakes[v], 2) - pow(cakes[i] - cakes[v], 2)))
dp[state][v] = ret
return ret
testcases = [[int(x) for x in line.split()] for line in sys.stdin.readlines()]
for testcase in testcases:
box, *cakes = testcase
N = len(cakes)
INF = box + 1
dp = [[-1] * N for _ in range(1 << N)]
print('OK' if rec(0, 0) <= box else 'NA')
``` | output | 1 | 9,789 | 9 | 19,579 |
Provide a correct Python 3 solution for this coding contest problem.
The cake shop made a lot of roll cakes of various sizes. You have been tasked with arranging this cake in a box.
The roll cake is so soft that it will collapse if another roll cake is on top. Therefore, as shown in Fig. (A), all roll cakes must be arranged so that they touch the bottom of the box. Sorting also changes the required width.
<image>
---
Figure (a)
<image>
Figure (b)
Read the radii r1, r2, ..., rn of n roll cakes and the length of the box, judge whether they fit well in the box, and devise the order of arrangement. ", Create a program that outputs" NA "if it does not fit in any order.
It is assumed that the cross section of the roll cake is a circle and the height of the wall of the box is high enough. However, the radius of the roll cake should be an integer between 3 and 10. In other words, there is no extreme difference in cake radii, and small cakes do not get stuck between large cakes as shown in Figure (b).
Input
The input consists of multiple datasets. Each dataset is given in the following format:
W r1 r2 ... rn
First, the integer W (1 ≤ W ≤ 1,000) representing the length of the box is given. It is then given the integer ri (3 ≤ ri ≤ 10), which represents the radius of each roll cake, separated by blanks. The number of cakes n is 12 or less.
The number of datasets does not exceed 50.
Output
Print OK or NA on one line for each dataset.
Example
Input
30 4 5 6
30 5 5 5
50 3 3 3 10 10
49 3 3 3 10 10
Output
OK
OK
OK
NA | instruction | 0 | 9,790 | 9 | 19,580 |
"Correct Solution:
```
from collections import deque
def calcwidth(cks):
if len(cks) == 1: return cks[0]*2
width = cks[0] + cks[-1]
for ck1,ck2 in zip(cks[:-1],cks[1:]):
width += ((ck1+ck2)**2-(ck1-ck2)**2)**0.5
return width
while True:
try: W, *rs = list(map(float,input().split()))
except: break
rs = deque(sorted(rs))
dp = [float('inf')]*len(rs)
cs = deque([rs.popleft()])
last_pick_small = -1
# if -1: last pick up is smallest, if 0: last pick up is biggest
while rs:
if last_pick_small: nxt = rs.pop()
else: nxt = rs.popleft()
if abs(nxt-cs[0]) > abs(nxt-cs[-1]): cs.appendleft(nxt)
else: cs.append(nxt)
last_pick_small = -1-last_pick_small
ret = calcwidth(list(cs))
if ret <= W: print('OK')
else: print('NA')
``` | output | 1 | 9,790 | 9 | 19,581 |
Provide a correct Python 3 solution for this coding contest problem.
The cake shop made a lot of roll cakes of various sizes. You have been tasked with arranging this cake in a box.
The roll cake is so soft that it will collapse if another roll cake is on top. Therefore, as shown in Fig. (A), all roll cakes must be arranged so that they touch the bottom of the box. Sorting also changes the required width.
<image>
---
Figure (a)
<image>
Figure (b)
Read the radii r1, r2, ..., rn of n roll cakes and the length of the box, judge whether they fit well in the box, and devise the order of arrangement. ", Create a program that outputs" NA "if it does not fit in any order.
It is assumed that the cross section of the roll cake is a circle and the height of the wall of the box is high enough. However, the radius of the roll cake should be an integer between 3 and 10. In other words, there is no extreme difference in cake radii, and small cakes do not get stuck between large cakes as shown in Figure (b).
Input
The input consists of multiple datasets. Each dataset is given in the following format:
W r1 r2 ... rn
First, the integer W (1 ≤ W ≤ 1,000) representing the length of the box is given. It is then given the integer ri (3 ≤ ri ≤ 10), which represents the radius of each roll cake, separated by blanks. The number of cakes n is 12 or less.
The number of datasets does not exceed 50.
Output
Print OK or NA on one line for each dataset.
Example
Input
30 4 5 6
30 5 5 5
50 3 3 3 10 10
49 3 3 3 10 10
Output
OK
OK
OK
NA | instruction | 0 | 9,791 | 9 | 19,582 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0120
"""
import sys
from sys import stdin
input = stdin.readline
def calc_width(cakes):
# ??±????????????????????????(?????????)????????????????????????????????????????¨??????????
if len(cakes) == 1:
return cakes[0]*2
prev_r = cakes[0]
width = prev_r # ??±?????????(???????????±???????????????)
for r in cakes[1:]: # ???????????±?????????????????????????°´????????¢
h_diff = abs(prev_r - r)
w = ((prev_r + r)**2 - h_diff**2)**0.5
width += w
prev_r = r
width += cakes[-1] # ??±?????????(???????????±???????????????)
return width
def main(args):
for line in sys.stdin:
data = [int(x) for x in line.strip().split()]
box_size = data[0]
temp = data[1:]
temp.sort()
# ??±??????????????????????????????????????????????????????????????????????????????
# ????°??????±??????????????????????????§????????´??¨?°?????????´??????????????????????????¢??????????????£????????±????????¨???????????§????????????????????????
cakes = [temp[0]]
temp = temp[1:]
pick_large = True
pick = 0
while temp:
if pick_large:
pick = temp[-1]
temp = temp[:-1]
pick_large = False
else:
pick = temp[0]
temp = temp[1:]
pick_large = True
diff_front = abs(pick - cakes[0])
diff_rear = abs(pick - cakes[-1])
if diff_front > diff_rear:
cakes.insert(0, pick)
else:
cakes.append(pick)
# ??±????????¨???????¨????????¨????????????±?????\???????¢??????????
result = calc_width(cakes)
if result <= box_size:
print('OK')
else:
print('NA')
if __name__ == '__main__':
main(sys.argv[1:])
``` | output | 1 | 9,791 | 9 | 19,583 |
Provide a correct Python 3 solution for this coding contest problem.
The cake shop made a lot of roll cakes of various sizes. You have been tasked with arranging this cake in a box.
The roll cake is so soft that it will collapse if another roll cake is on top. Therefore, as shown in Fig. (A), all roll cakes must be arranged so that they touch the bottom of the box. Sorting also changes the required width.
<image>
---
Figure (a)
<image>
Figure (b)
Read the radii r1, r2, ..., rn of n roll cakes and the length of the box, judge whether they fit well in the box, and devise the order of arrangement. ", Create a program that outputs" NA "if it does not fit in any order.
It is assumed that the cross section of the roll cake is a circle and the height of the wall of the box is high enough. However, the radius of the roll cake should be an integer between 3 and 10. In other words, there is no extreme difference in cake radii, and small cakes do not get stuck between large cakes as shown in Figure (b).
Input
The input consists of multiple datasets. Each dataset is given in the following format:
W r1 r2 ... rn
First, the integer W (1 ≤ W ≤ 1,000) representing the length of the box is given. It is then given the integer ri (3 ≤ ri ≤ 10), which represents the radius of each roll cake, separated by blanks. The number of cakes n is 12 or less.
The number of datasets does not exceed 50.
Output
Print OK or NA on one line for each dataset.
Example
Input
30 4 5 6
30 5 5 5
50 3 3 3 10 10
49 3 3 3 10 10
Output
OK
OK
OK
NA | instruction | 0 | 9,792 | 9 | 19,584 |
"Correct Solution:
```
import sys
from math import sqrt
def rec(state, v):
if state == (1 << N) - 1:
return cakes[v]
if dp[state][v] != -1:
return dp[state][v]
ret = INF
for u in range(N):
if state == 0:
ret = min(ret, rec(1 << u, u) + cakes[u])
elif not (state >> u & 1):
ret = min(ret, rec(state | 1 << u, u) + sqrt(pow(cakes[u] + cakes[v], 2) - pow(cakes[u] - cakes[v], 2)))
dp[state][v] = ret
return ret
testcases = [[int(x) for x in line.split()] for line in sys.stdin.readlines()]
for testcase in testcases:
box, *cakes = testcase
N = len(cakes)
INF = box + 1
dp = [[-1] * N for _ in range(1 << N)]
print('OK' if rec(0, 0) <= box else 'NA')
``` | output | 1 | 9,792 | 9 | 19,585 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The cake shop made a lot of roll cakes of various sizes. You have been tasked with arranging this cake in a box.
The roll cake is so soft that it will collapse if another roll cake is on top. Therefore, as shown in Fig. (A), all roll cakes must be arranged so that they touch the bottom of the box. Sorting also changes the required width.
<image>
---
Figure (a)
<image>
Figure (b)
Read the radii r1, r2, ..., rn of n roll cakes and the length of the box, judge whether they fit well in the box, and devise the order of arrangement. ", Create a program that outputs" NA "if it does not fit in any order.
It is assumed that the cross section of the roll cake is a circle and the height of the wall of the box is high enough. However, the radius of the roll cake should be an integer between 3 and 10. In other words, there is no extreme difference in cake radii, and small cakes do not get stuck between large cakes as shown in Figure (b).
Input
The input consists of multiple datasets. Each dataset is given in the following format:
W r1 r2 ... rn
First, the integer W (1 ≤ W ≤ 1,000) representing the length of the box is given. It is then given the integer ri (3 ≤ ri ≤ 10), which represents the radius of each roll cake, separated by blanks. The number of cakes n is 12 or less.
The number of datasets does not exceed 50.
Output
Print OK or NA on one line for each dataset.
Example
Input
30 4 5 6
30 5 5 5
50 3 3 3 10 10
49 3 3 3 10 10
Output
OK
OK
OK
NA
Submitted Solution:
```
INF = 10 ** 20
def get_dist(r1, r2):
return ((r1 + r2) ** 2 - (r1 - r2) ** 2) ** (1 / 2)
def minimum_width(rest, r, dic):
if (rest, r) in dic:
return dic[(rest, r)]
if rest == ():
return r
ret = INF
lenr = len(rest)
for c in rest:
next_rest = list(rest)
next_rest.remove(c)
ret = min(ret, minimum_width(tuple(next_rest), c, dic) + get_dist(r, c))
dic[(rest, r)] = ret
return ret
while True:
try:
lst = list(map(int, input().split()))
w = lst[0]
cakes = lst[1:]
cakes.sort()
lenc = len(cakes)
dic = {}
ans = INF
for c in cakes:
tmp = cakes[:]
tmp.remove(c)
ans = min(ans, minimum_width(tuple(tmp), c, dic) + c)
if w >= ans:
print("OK")
else:
print("NA")
except EOFError:
break
``` | instruction | 0 | 9,793 | 9 | 19,586 |
Yes | output | 1 | 9,793 | 9 | 19,587 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The cake shop made a lot of roll cakes of various sizes. You have been tasked with arranging this cake in a box.
The roll cake is so soft that it will collapse if another roll cake is on top. Therefore, as shown in Fig. (A), all roll cakes must be arranged so that they touch the bottom of the box. Sorting also changes the required width.
<image>
---
Figure (a)
<image>
Figure (b)
Read the radii r1, r2, ..., rn of n roll cakes and the length of the box, judge whether they fit well in the box, and devise the order of arrangement. ", Create a program that outputs" NA "if it does not fit in any order.
It is assumed that the cross section of the roll cake is a circle and the height of the wall of the box is high enough. However, the radius of the roll cake should be an integer between 3 and 10. In other words, there is no extreme difference in cake radii, and small cakes do not get stuck between large cakes as shown in Figure (b).
Input
The input consists of multiple datasets. Each dataset is given in the following format:
W r1 r2 ... rn
First, the integer W (1 ≤ W ≤ 1,000) representing the length of the box is given. It is then given the integer ri (3 ≤ ri ≤ 10), which represents the radius of each roll cake, separated by blanks. The number of cakes n is 12 or less.
The number of datasets does not exceed 50.
Output
Print OK or NA on one line for each dataset.
Example
Input
30 4 5 6
30 5 5 5
50 3 3 3 10 10
49 3 3 3 10 10
Output
OK
OK
OK
NA
Submitted Solution:
```
# AOJ 0120 Patisserie
# Python3 2018.6.23 bal4u
INF = 0x7fffffff
R = 100000
d = [[0 for j in range(13)] for i in range(13)] # ロールケーキ円心間の水平距離
for i in range(3, 11):
ii = i*i
for j in range(i, 11):
d[i][j] = d[j][i] = int(2*R * ii**0.5)
ii += i
while 1:
try: r = list(map(int, input().split()))
except: break
W = r.pop(0)
if 2*sum(r) <= W:
print("OK")
continue
n = len(r)
W *= R
dp = [[INF for j in range(1<<n)] for i in range(n)]
for i in range(n): dp[i][1<<i] = r[i]*R
lim = 1<<n
for k in range(lim):
for i in range(n):
if k & (1<<i): continue
for j in range(n):
dp[i][k|(1<<i)] = min(dp[i][k|(1<<i)], dp[j][k] + d[r[i]][r[j]])
w = 240*R
for i in range(n):
dp[i][lim-1] += r[i]*R
if dp[i][lim-1] < w: w = dp[i][lim-1];
print("OK" if w <= W else "NA")
``` | instruction | 0 | 9,794 | 9 | 19,588 |
Yes | output | 1 | 9,794 | 9 | 19,589 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The cake shop made a lot of roll cakes of various sizes. You have been tasked with arranging this cake in a box.
The roll cake is so soft that it will collapse if another roll cake is on top. Therefore, as shown in Fig. (A), all roll cakes must be arranged so that they touch the bottom of the box. Sorting also changes the required width.
<image>
---
Figure (a)
<image>
Figure (b)
Read the radii r1, r2, ..., rn of n roll cakes and the length of the box, judge whether they fit well in the box, and devise the order of arrangement. ", Create a program that outputs" NA "if it does not fit in any order.
It is assumed that the cross section of the roll cake is a circle and the height of the wall of the box is high enough. However, the radius of the roll cake should be an integer between 3 and 10. In other words, there is no extreme difference in cake radii, and small cakes do not get stuck between large cakes as shown in Figure (b).
Input
The input consists of multiple datasets. Each dataset is given in the following format:
W r1 r2 ... rn
First, the integer W (1 ≤ W ≤ 1,000) representing the length of the box is given. It is then given the integer ri (3 ≤ ri ≤ 10), which represents the radius of each roll cake, separated by blanks. The number of cakes n is 12 or less.
The number of datasets does not exceed 50.
Output
Print OK or NA on one line for each dataset.
Example
Input
30 4 5 6
30 5 5 5
50 3 3 3 10 10
49 3 3 3 10 10
Output
OK
OK
OK
NA
Submitted Solution:
```
INF = 10 ** 20
def get_dist(r1, r2):
c = r1 + r2
b = abs(r1 - r2)
return (c ** 2 - b ** 2) ** (1 / 2)
def minimum_width(rest, r, dic):
if (rest, r) in dic:
return dic[(rest, r)]
if rest == ():
return r
ret = INF
lenr = len(rest)
for i, c in enumerate(rest):
ret = min(ret, minimum_width(tuple(rest[j] for j in range(lenr) if i != j), rest[i], dic) + get_dist(r, rest[i]))
dic[(rest, r)] = ret
return ret
while True:
try:
lst = list(map(int, input().split()))
w = lst[0]
cakes = lst[1:]
cakes.sort()
lenc = len(cakes)
dic = {}
ans = INF
for i in range(lenc):
ans = min(ans, minimum_width(tuple(cakes[j] for j in range(lenc) if i != j), cakes[i], dic) + cakes[i])
if w >= ans:
print("OK")
else:
print("NA")
except EOFError:
break
``` | instruction | 0 | 9,795 | 9 | 19,590 |
Yes | output | 1 | 9,795 | 9 | 19,591 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The cake shop made a lot of roll cakes of various sizes. You have been tasked with arranging this cake in a box.
The roll cake is so soft that it will collapse if another roll cake is on top. Therefore, as shown in Fig. (A), all roll cakes must be arranged so that they touch the bottom of the box. Sorting also changes the required width.
<image>
---
Figure (a)
<image>
Figure (b)
Read the radii r1, r2, ..., rn of n roll cakes and the length of the box, judge whether they fit well in the box, and devise the order of arrangement. ", Create a program that outputs" NA "if it does not fit in any order.
It is assumed that the cross section of the roll cake is a circle and the height of the wall of the box is high enough. However, the radius of the roll cake should be an integer between 3 and 10. In other words, there is no extreme difference in cake radii, and small cakes do not get stuck between large cakes as shown in Figure (b).
Input
The input consists of multiple datasets. Each dataset is given in the following format:
W r1 r2 ... rn
First, the integer W (1 ≤ W ≤ 1,000) representing the length of the box is given. It is then given the integer ri (3 ≤ ri ≤ 10), which represents the radius of each roll cake, separated by blanks. The number of cakes n is 12 or less.
The number of datasets does not exceed 50.
Output
Print OK or NA on one line for each dataset.
Example
Input
30 4 5 6
30 5 5 5
50 3 3 3 10 10
49 3 3 3 10 10
Output
OK
OK
OK
NA
Submitted Solution:
```
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0120
"""
import sys
from sys import stdin
input = stdin.readline
def calc_width(cakes):
# ??±????????????????????????(?????????????????????????????????????????????????¨??????????)
if len(cakes) == 1:
return cakes[0]*2
prev_r = cakes[0]
width = prev_r
for r in cakes[1:]:
h_diff = abs(prev_r - r)
if h_diff == 0:
width += prev_r
width += r
else:
w = ((prev_r + r)**2 - h_diff**2)**0.5
width += w
prev_r = r
width += cakes[-1]
return width
def main(args):
for line in sys.stdin:
data = [int(x) for x in line.split()]
box_size = data[0]
temp = data[1:]
temp.sort()
cakes = []
head = True
while temp:
if head:
cakes.append(temp[0])
temp = temp[1:]
head = False
else:
cakes.append(temp[-1])
temp = temp[:-1]
head = True
result = calc_width(cakes)
if result <= box_size:
print('OK')
else:
print('NA')
if __name__ == '__main__':
main(sys.argv[1:])
``` | instruction | 0 | 9,796 | 9 | 19,592 |
No | output | 1 | 9,796 | 9 | 19,593 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The cake shop made a lot of roll cakes of various sizes. You have been tasked with arranging this cake in a box.
The roll cake is so soft that it will collapse if another roll cake is on top. Therefore, as shown in Fig. (A), all roll cakes must be arranged so that they touch the bottom of the box. Sorting also changes the required width.
<image>
---
Figure (a)
<image>
Figure (b)
Read the radii r1, r2, ..., rn of n roll cakes and the length of the box, judge whether they fit well in the box, and devise the order of arrangement. ", Create a program that outputs" NA "if it does not fit in any order.
It is assumed that the cross section of the roll cake is a circle and the height of the wall of the box is high enough. However, the radius of the roll cake should be an integer between 3 and 10. In other words, there is no extreme difference in cake radii, and small cakes do not get stuck between large cakes as shown in Figure (b).
Input
The input consists of multiple datasets. Each dataset is given in the following format:
W r1 r2 ... rn
First, the integer W (1 ≤ W ≤ 1,000) representing the length of the box is given. It is then given the integer ri (3 ≤ ri ≤ 10), which represents the radius of each roll cake, separated by blanks. The number of cakes n is 12 or less.
The number of datasets does not exceed 50.
Output
Print OK or NA on one line for each dataset.
Example
Input
30 4 5 6
30 5 5 5
50 3 3 3 10 10
49 3 3 3 10 10
Output
OK
OK
OK
NA
Submitted Solution:
```
import sys
from math import sqrt
testcases = [[int(x) for x in line.split()] for line in sys.stdin.readlines()]
for testcase in testcases:
box, *cakes = testcase
N = len(cakes)
INF = box + 1
dp = [[INF] * N for _ in range(1 << N)]
dp[(1 << N) - 1][0] = 0
for state in reversed(range(1 << N)):
for v in range(N):
for u in range(N):
if not (state >> u & 1):
dp[state][v] = min(dp[state][v], dp[state | 1 << u][u] + sqrt(pow(cakes[u] + cakes[v], 2) - pow(cakes[u] - cakes[v], 2)))
print(*dp[0])
print('OK' if min(dp[0]) <= box else 'NA')
``` | instruction | 0 | 9,798 | 9 | 19,596 |
No | output | 1 | 9,798 | 9 | 19,597 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The cake shop made a lot of roll cakes of various sizes. You have been tasked with arranging this cake in a box.
The roll cake is so soft that it will collapse if another roll cake is on top. Therefore, as shown in Fig. (A), all roll cakes must be arranged so that they touch the bottom of the box. Sorting also changes the required width.
<image>
---
Figure (a)
<image>
Figure (b)
Read the radii r1, r2, ..., rn of n roll cakes and the length of the box, judge whether they fit well in the box, and devise the order of arrangement. ", Create a program that outputs" NA "if it does not fit in any order.
It is assumed that the cross section of the roll cake is a circle and the height of the wall of the box is high enough. However, the radius of the roll cake should be an integer between 3 and 10. In other words, there is no extreme difference in cake radii, and small cakes do not get stuck between large cakes as shown in Figure (b).
Input
The input consists of multiple datasets. Each dataset is given in the following format:
W r1 r2 ... rn
First, the integer W (1 ≤ W ≤ 1,000) representing the length of the box is given. It is then given the integer ri (3 ≤ ri ≤ 10), which represents the radius of each roll cake, separated by blanks. The number of cakes n is 12 or less.
The number of datasets does not exceed 50.
Output
Print OK or NA on one line for each dataset.
Example
Input
30 4 5 6
30 5 5 5
50 3 3 3 10 10
49 3 3 3 10 10
Output
OK
OK
OK
NA
Submitted Solution:
```
# -*- coding: utf-8 -*-
import sys
import os
import math
for s in sys.stdin:
lst = list(map(int, s.split()))
W = lst[0]
R = lst[1:]
R.sort()
# zigzag
Z = []
while R:
r = R.pop(0)
Z.append(r)
if R:
r = R.pop(-1)
Z.append(r)
#print('Z', Z)
l = 0
n = len(Z)
for i in range(0, n-1):
r0 = Z[i]
r1 = Z[i+1]
x_length = math.sqrt((r0+r1)**2 - (r0-r1) ** 2)
l += x_length
l += Z[0]
l += Z[-1]
#print(l)
if l <= W:
print('OK')
else:
print('NA')
``` | instruction | 0 | 9,799 | 9 | 19,598 |
No | output | 1 | 9,799 | 9 | 19,599 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice and Bob have received three big piles of candies as a gift. Now they want to divide these candies as fair as possible. To do this, Alice takes one pile of candies, then Bob takes one of the other two piles. The last pile is split between Alice and Bob as they want: for example, it is possible that Alice takes the whole pile, and Bob gets nothing from it.
After taking the candies from the piles, if Alice has more candies than Bob, she discards some candies so that the number of candies she has is equal to the number of candies Bob has. Of course, Bob does the same if he has more candies.
Alice and Bob want to have as many candies as possible, and they plan the process of dividing candies accordingly. Please calculate the maximum number of candies Alice can have after this division process (of course, Bob will have the same number of candies).
You have to answer q independent queries.
Let's see the following example: [1, 3, 4]. Then Alice can choose the third pile, Bob can take the second pile, and then the only candy from the first pile goes to Bob — then Alice has 4 candies, and Bob has 4 candies.
Another example is [1, 10, 100]. Then Alice can choose the second pile, Bob can choose the first pile, and candies from the third pile can be divided in such a way that Bob takes 54 candies, and Alice takes 46 candies. Now Bob has 55 candies, and Alice has 56 candies, so she has to discard one candy — and after that, she has 55 candies too.
Input
The first line of the input contains one integer q (1 ≤ q ≤ 1000) — the number of queries. Then q queries follow.
The only line of the query contains three integers a, b and c (1 ≤ a, b, c ≤ 10^{16}) — the number of candies in the first, second and third piles correspondingly.
Output
Print q lines. The i-th line should contain the answer for the i-th query — the maximum number of candies Alice can have after the division, if both Alice and Bob act optimally (of course, Bob will have the same number of candies).
Example
Input
4
1 3 4
1 10 100
10000000000000000 10000000000000000 10000000000000000
23 34 45
Output
4
55
15000000000000000
51 | instruction | 0 | 10,005 | 9 | 20,010 |
Tags: brute force, constructive algorithms, math
Correct Solution:
```
n=int(input())
for i in range(n):
a,b,c=[int(x) for x in input().split()]
if abs(a-b)<=c or abs(b-c)<=a or abs(c-a)<=b:
print((a+b+c)//2)
else:
print(min[a+b,b+c,c+a])
``` | output | 1 | 10,005 | 9 | 20,011 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice and Bob have received three big piles of candies as a gift. Now they want to divide these candies as fair as possible. To do this, Alice takes one pile of candies, then Bob takes one of the other two piles. The last pile is split between Alice and Bob as they want: for example, it is possible that Alice takes the whole pile, and Bob gets nothing from it.
After taking the candies from the piles, if Alice has more candies than Bob, she discards some candies so that the number of candies she has is equal to the number of candies Bob has. Of course, Bob does the same if he has more candies.
Alice and Bob want to have as many candies as possible, and they plan the process of dividing candies accordingly. Please calculate the maximum number of candies Alice can have after this division process (of course, Bob will have the same number of candies).
You have to answer q independent queries.
Let's see the following example: [1, 3, 4]. Then Alice can choose the third pile, Bob can take the second pile, and then the only candy from the first pile goes to Bob — then Alice has 4 candies, and Bob has 4 candies.
Another example is [1, 10, 100]. Then Alice can choose the second pile, Bob can choose the first pile, and candies from the third pile can be divided in such a way that Bob takes 54 candies, and Alice takes 46 candies. Now Bob has 55 candies, and Alice has 56 candies, so she has to discard one candy — and after that, she has 55 candies too.
Input
The first line of the input contains one integer q (1 ≤ q ≤ 1000) — the number of queries. Then q queries follow.
The only line of the query contains three integers a, b and c (1 ≤ a, b, c ≤ 10^{16}) — the number of candies in the first, second and third piles correspondingly.
Output
Print q lines. The i-th line should contain the answer for the i-th query — the maximum number of candies Alice can have after the division, if both Alice and Bob act optimally (of course, Bob will have the same number of candies).
Example
Input
4
1 3 4
1 10 100
10000000000000000 10000000000000000 10000000000000000
23 34 45
Output
4
55
15000000000000000
51 | instruction | 0 | 10,006 | 9 | 20,012 |
Tags: brute force, constructive algorithms, math
Correct Solution:
```
import sys
input = sys.stdin.readline
q=int(input())
for i in range(q):
A=[int(i) for i in input().split()]
print(sum(A)//2)
``` | output | 1 | 10,006 | 9 | 20,013 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice and Bob have received three big piles of candies as a gift. Now they want to divide these candies as fair as possible. To do this, Alice takes one pile of candies, then Bob takes one of the other two piles. The last pile is split between Alice and Bob as they want: for example, it is possible that Alice takes the whole pile, and Bob gets nothing from it.
After taking the candies from the piles, if Alice has more candies than Bob, she discards some candies so that the number of candies she has is equal to the number of candies Bob has. Of course, Bob does the same if he has more candies.
Alice and Bob want to have as many candies as possible, and they plan the process of dividing candies accordingly. Please calculate the maximum number of candies Alice can have after this division process (of course, Bob will have the same number of candies).
You have to answer q independent queries.
Let's see the following example: [1, 3, 4]. Then Alice can choose the third pile, Bob can take the second pile, and then the only candy from the first pile goes to Bob — then Alice has 4 candies, and Bob has 4 candies.
Another example is [1, 10, 100]. Then Alice can choose the second pile, Bob can choose the first pile, and candies from the third pile can be divided in such a way that Bob takes 54 candies, and Alice takes 46 candies. Now Bob has 55 candies, and Alice has 56 candies, so she has to discard one candy — and after that, she has 55 candies too.
Input
The first line of the input contains one integer q (1 ≤ q ≤ 1000) — the number of queries. Then q queries follow.
The only line of the query contains three integers a, b and c (1 ≤ a, b, c ≤ 10^{16}) — the number of candies in the first, second and third piles correspondingly.
Output
Print q lines. The i-th line should contain the answer for the i-th query — the maximum number of candies Alice can have after the division, if both Alice and Bob act optimally (of course, Bob will have the same number of candies).
Example
Input
4
1 3 4
1 10 100
10000000000000000 10000000000000000 10000000000000000
23 34 45
Output
4
55
15000000000000000
51 | instruction | 0 | 10,007 | 9 | 20,014 |
Tags: brute force, constructive algorithms, math
Correct Solution:
```
t=int(input())
for _ in range(0,t):
a,b,c=map(int,input().split())
print ((a+b+c)//2)
``` | output | 1 | 10,007 | 9 | 20,015 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice and Bob have received three big piles of candies as a gift. Now they want to divide these candies as fair as possible. To do this, Alice takes one pile of candies, then Bob takes one of the other two piles. The last pile is split between Alice and Bob as they want: for example, it is possible that Alice takes the whole pile, and Bob gets nothing from it.
After taking the candies from the piles, if Alice has more candies than Bob, she discards some candies so that the number of candies she has is equal to the number of candies Bob has. Of course, Bob does the same if he has more candies.
Alice and Bob want to have as many candies as possible, and they plan the process of dividing candies accordingly. Please calculate the maximum number of candies Alice can have after this division process (of course, Bob will have the same number of candies).
You have to answer q independent queries.
Let's see the following example: [1, 3, 4]. Then Alice can choose the third pile, Bob can take the second pile, and then the only candy from the first pile goes to Bob — then Alice has 4 candies, and Bob has 4 candies.
Another example is [1, 10, 100]. Then Alice can choose the second pile, Bob can choose the first pile, and candies from the third pile can be divided in such a way that Bob takes 54 candies, and Alice takes 46 candies. Now Bob has 55 candies, and Alice has 56 candies, so she has to discard one candy — and after that, she has 55 candies too.
Input
The first line of the input contains one integer q (1 ≤ q ≤ 1000) — the number of queries. Then q queries follow.
The only line of the query contains three integers a, b and c (1 ≤ a, b, c ≤ 10^{16}) — the number of candies in the first, second and third piles correspondingly.
Output
Print q lines. The i-th line should contain the answer for the i-th query — the maximum number of candies Alice can have after the division, if both Alice and Bob act optimally (of course, Bob will have the same number of candies).
Example
Input
4
1 3 4
1 10 100
10000000000000000 10000000000000000 10000000000000000
23 34 45
Output
4
55
15000000000000000
51 | instruction | 0 | 10,008 | 9 | 20,016 |
Tags: brute force, constructive algorithms, math
Correct Solution:
```
q = int(input())
for i in range(q):
s = sum(list(map(int, input().split())))
print(s // 2)
``` | output | 1 | 10,008 | 9 | 20,017 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice and Bob have received three big piles of candies as a gift. Now they want to divide these candies as fair as possible. To do this, Alice takes one pile of candies, then Bob takes one of the other two piles. The last pile is split between Alice and Bob as they want: for example, it is possible that Alice takes the whole pile, and Bob gets nothing from it.
After taking the candies from the piles, if Alice has more candies than Bob, she discards some candies so that the number of candies she has is equal to the number of candies Bob has. Of course, Bob does the same if he has more candies.
Alice and Bob want to have as many candies as possible, and they plan the process of dividing candies accordingly. Please calculate the maximum number of candies Alice can have after this division process (of course, Bob will have the same number of candies).
You have to answer q independent queries.
Let's see the following example: [1, 3, 4]. Then Alice can choose the third pile, Bob can take the second pile, and then the only candy from the first pile goes to Bob — then Alice has 4 candies, and Bob has 4 candies.
Another example is [1, 10, 100]. Then Alice can choose the second pile, Bob can choose the first pile, and candies from the third pile can be divided in such a way that Bob takes 54 candies, and Alice takes 46 candies. Now Bob has 55 candies, and Alice has 56 candies, so she has to discard one candy — and after that, she has 55 candies too.
Input
The first line of the input contains one integer q (1 ≤ q ≤ 1000) — the number of queries. Then q queries follow.
The only line of the query contains three integers a, b and c (1 ≤ a, b, c ≤ 10^{16}) — the number of candies in the first, second and third piles correspondingly.
Output
Print q lines. The i-th line should contain the answer for the i-th query — the maximum number of candies Alice can have after the division, if both Alice and Bob act optimally (of course, Bob will have the same number of candies).
Example
Input
4
1 3 4
1 10 100
10000000000000000 10000000000000000 10000000000000000
23 34 45
Output
4
55
15000000000000000
51 | instruction | 0 | 10,009 | 9 | 20,018 |
Tags: brute force, constructive algorithms, math
Correct Solution:
```
def main():
t = int(input())
for i in range(t):
a,b,c = tuple(map(int, input().split()))
print((a + b + c)//2)
if __name__=='__main__':
main()
``` | output | 1 | 10,009 | 9 | 20,019 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice and Bob have received three big piles of candies as a gift. Now they want to divide these candies as fair as possible. To do this, Alice takes one pile of candies, then Bob takes one of the other two piles. The last pile is split between Alice and Bob as they want: for example, it is possible that Alice takes the whole pile, and Bob gets nothing from it.
After taking the candies from the piles, if Alice has more candies than Bob, she discards some candies so that the number of candies she has is equal to the number of candies Bob has. Of course, Bob does the same if he has more candies.
Alice and Bob want to have as many candies as possible, and they plan the process of dividing candies accordingly. Please calculate the maximum number of candies Alice can have after this division process (of course, Bob will have the same number of candies).
You have to answer q independent queries.
Let's see the following example: [1, 3, 4]. Then Alice can choose the third pile, Bob can take the second pile, and then the only candy from the first pile goes to Bob — then Alice has 4 candies, and Bob has 4 candies.
Another example is [1, 10, 100]. Then Alice can choose the second pile, Bob can choose the first pile, and candies from the third pile can be divided in such a way that Bob takes 54 candies, and Alice takes 46 candies. Now Bob has 55 candies, and Alice has 56 candies, so she has to discard one candy — and after that, she has 55 candies too.
Input
The first line of the input contains one integer q (1 ≤ q ≤ 1000) — the number of queries. Then q queries follow.
The only line of the query contains three integers a, b and c (1 ≤ a, b, c ≤ 10^{16}) — the number of candies in the first, second and third piles correspondingly.
Output
Print q lines. The i-th line should contain the answer for the i-th query — the maximum number of candies Alice can have after the division, if both Alice and Bob act optimally (of course, Bob will have the same number of candies).
Example
Input
4
1 3 4
1 10 100
10000000000000000 10000000000000000 10000000000000000
23 34 45
Output
4
55
15000000000000000
51 | instruction | 0 | 10,010 | 9 | 20,020 |
Tags: brute force, constructive algorithms, math
Correct Solution:
```
for _ in range(int(input())):
a,b,c = list(map(int,input().split()))
if (a+b+c) % 2 == 0:
print((a+b+c)//2)
else:
print((a+b+c-1)//2)
``` | output | 1 | 10,010 | 9 | 20,021 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice and Bob have received three big piles of candies as a gift. Now they want to divide these candies as fair as possible. To do this, Alice takes one pile of candies, then Bob takes one of the other two piles. The last pile is split between Alice and Bob as they want: for example, it is possible that Alice takes the whole pile, and Bob gets nothing from it.
After taking the candies from the piles, if Alice has more candies than Bob, she discards some candies so that the number of candies she has is equal to the number of candies Bob has. Of course, Bob does the same if he has more candies.
Alice and Bob want to have as many candies as possible, and they plan the process of dividing candies accordingly. Please calculate the maximum number of candies Alice can have after this division process (of course, Bob will have the same number of candies).
You have to answer q independent queries.
Let's see the following example: [1, 3, 4]. Then Alice can choose the third pile, Bob can take the second pile, and then the only candy from the first pile goes to Bob — then Alice has 4 candies, and Bob has 4 candies.
Another example is [1, 10, 100]. Then Alice can choose the second pile, Bob can choose the first pile, and candies from the third pile can be divided in such a way that Bob takes 54 candies, and Alice takes 46 candies. Now Bob has 55 candies, and Alice has 56 candies, so she has to discard one candy — and after that, she has 55 candies too.
Input
The first line of the input contains one integer q (1 ≤ q ≤ 1000) — the number of queries. Then q queries follow.
The only line of the query contains three integers a, b and c (1 ≤ a, b, c ≤ 10^{16}) — the number of candies in the first, second and third piles correspondingly.
Output
Print q lines. The i-th line should contain the answer for the i-th query — the maximum number of candies Alice can have after the division, if both Alice and Bob act optimally (of course, Bob will have the same number of candies).
Example
Input
4
1 3 4
1 10 100
10000000000000000 10000000000000000 10000000000000000
23 34 45
Output
4
55
15000000000000000
51 | instruction | 0 | 10,011 | 9 | 20,022 |
Tags: brute force, constructive algorithms, math
Correct Solution:
```
a = int(input())
for i in range(a):
z, x, c = map(int, input().split())
s = z + x + c
s = s // 2
print(s)
``` | output | 1 | 10,011 | 9 | 20,023 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Alice and Bob have received three big piles of candies as a gift. Now they want to divide these candies as fair as possible. To do this, Alice takes one pile of candies, then Bob takes one of the other two piles. The last pile is split between Alice and Bob as they want: for example, it is possible that Alice takes the whole pile, and Bob gets nothing from it.
After taking the candies from the piles, if Alice has more candies than Bob, she discards some candies so that the number of candies she has is equal to the number of candies Bob has. Of course, Bob does the same if he has more candies.
Alice and Bob want to have as many candies as possible, and they plan the process of dividing candies accordingly. Please calculate the maximum number of candies Alice can have after this division process (of course, Bob will have the same number of candies).
You have to answer q independent queries.
Let's see the following example: [1, 3, 4]. Then Alice can choose the third pile, Bob can take the second pile, and then the only candy from the first pile goes to Bob — then Alice has 4 candies, and Bob has 4 candies.
Another example is [1, 10, 100]. Then Alice can choose the second pile, Bob can choose the first pile, and candies from the third pile can be divided in such a way that Bob takes 54 candies, and Alice takes 46 candies. Now Bob has 55 candies, and Alice has 56 candies, so she has to discard one candy — and after that, she has 55 candies too.
Input
The first line of the input contains one integer q (1 ≤ q ≤ 1000) — the number of queries. Then q queries follow.
The only line of the query contains three integers a, b and c (1 ≤ a, b, c ≤ 10^{16}) — the number of candies in the first, second and third piles correspondingly.
Output
Print q lines. The i-th line should contain the answer for the i-th query — the maximum number of candies Alice can have after the division, if both Alice and Bob act optimally (of course, Bob will have the same number of candies).
Example
Input
4
1 3 4
1 10 100
10000000000000000 10000000000000000 10000000000000000
23 34 45
Output
4
55
15000000000000000
51 | instruction | 0 | 10,012 | 9 | 20,024 |
Tags: brute force, constructive algorithms, math
Correct Solution:
```
q = int(input())
for i in range(q):
s = sum([int(x) for x in input().split(" ")])
print(s//2)
``` | output | 1 | 10,012 | 9 | 20,025 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Alice and Bob have received three big piles of candies as a gift. Now they want to divide these candies as fair as possible. To do this, Alice takes one pile of candies, then Bob takes one of the other two piles. The last pile is split between Alice and Bob as they want: for example, it is possible that Alice takes the whole pile, and Bob gets nothing from it.
After taking the candies from the piles, if Alice has more candies than Bob, she discards some candies so that the number of candies she has is equal to the number of candies Bob has. Of course, Bob does the same if he has more candies.
Alice and Bob want to have as many candies as possible, and they plan the process of dividing candies accordingly. Please calculate the maximum number of candies Alice can have after this division process (of course, Bob will have the same number of candies).
You have to answer q independent queries.
Let's see the following example: [1, 3, 4]. Then Alice can choose the third pile, Bob can take the second pile, and then the only candy from the first pile goes to Bob — then Alice has 4 candies, and Bob has 4 candies.
Another example is [1, 10, 100]. Then Alice can choose the second pile, Bob can choose the first pile, and candies from the third pile can be divided in such a way that Bob takes 54 candies, and Alice takes 46 candies. Now Bob has 55 candies, and Alice has 56 candies, so she has to discard one candy — and after that, she has 55 candies too.
Input
The first line of the input contains one integer q (1 ≤ q ≤ 1000) — the number of queries. Then q queries follow.
The only line of the query contains three integers a, b and c (1 ≤ a, b, c ≤ 10^{16}) — the number of candies in the first, second and third piles correspondingly.
Output
Print q lines. The i-th line should contain the answer for the i-th query — the maximum number of candies Alice can have after the division, if both Alice and Bob act optimally (of course, Bob will have the same number of candies).
Example
Input
4
1 3 4
1 10 100
10000000000000000 10000000000000000 10000000000000000
23 34 45
Output
4
55
15000000000000000
51
Submitted Solution:
```
k=int(input())
for i in range(k):
l = map(int, input().split())
print((sum(l) // 2))
``` | instruction | 0 | 10,013 | 9 | 20,026 |
Yes | output | 1 | 10,013 | 9 | 20,027 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.