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 |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
At the pancake shop you work for, pancake dough is lined up in a row on an elongated iron plate and baked. Pancakes can be completed by turning them over with a spatula several times. How many times you turn it over to complete it depends on the pancake.
Since the spatula is large, two adjacent pancakes will be turned over at the same time. At this time, the positions of these two sheets do not switch. However, not only can you flip both ends together with the pancake next to you, but you can also flip just one. After turning over all the pancakes more than the required number of times, remove them all at once from the iron plate and you're done.
I don't want to flip the pancakes too much, as turning them over more than necessary will make them harder. So you wanted to find a way to minimize the total number of times each pancake was flipped over by the time it was all finished.
When each pancake is given the number of pancakes on the iron plate and how many times it must be turned over before it is completed, the number of times each pancake is turned over before it is completed (manipulate the spatula). Create a program that calculates the minimum sum of (not the number of times).
Input
The input is given in the following format.
N
p1 p2 ... pN
The number of pancakes N (3 β€ N β€ 5000) is given on the first line. The second line gives the number of flips pi (0 β€ pi β€ 3) required to complete each pancake.
Output
Output the minimum value of the total number of times each pancake is turned inside out on one line until all are completed.
Examples
Input
3
1 2 1
Output
4
Input
3
0 3 0
Output
6
Submitted Solution:
```
'''aizu 0340
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0340
'''
# encoding: 'utf-8'
def main():
input()
hill = [int(x) for x in input().split()]
count = 0
while any([x > 0 for x in hill]):
hill, c = step(hill)
count += c
# print(count, hill)
print(count)
def step(hill):
c = 0
highest = max(hill)
i = hill.index(highest)
if 0 < i < len(hill)-1:
if hill[i] % 2 == hill[i-1] % 2:
hill[i-1] -= 1
elif hill[i] % 2 == hill[i+1] % 2:
hill[i+1] -= 1
else:
if hill[i-1] > hill[i+1]:
hill[i-1] -= 1
else:
hill[i+1] -= 1
hill[i] -= 1
c += 2
elif i == 0:
if hill[1] > 0:
hill[1] -= 1
c += 1
hill[0] -= 1
c += 1
elif i == len(hill) - 1:
if hill[-2] > 0:
hill[-2] -= 1
c += 1
hill[-1] -= 1
c += 1
else:
raise Exception("unreachable")
return (hill, c)
if __name__ == '__main__':
main()
``` | instruction | 0 | 47,871 | 9 | 95,742 |
No | output | 1 | 47,871 | 9 | 95,743 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
At the pancake shop you work for, pancake dough is lined up in a row on an elongated iron plate and baked. Pancakes can be completed by turning them over with a spatula several times. How many times you turn it over to complete it depends on the pancake.
Since the spatula is large, two adjacent pancakes will be turned over at the same time. At this time, the positions of these two sheets do not switch. However, not only can you flip both ends together with the pancake next to you, but you can also flip just one. After turning over all the pancakes more than the required number of times, remove them all at once from the iron plate and you're done.
I don't want to flip the pancakes too much, as turning them over more than necessary will make them harder. So you wanted to find a way to minimize the total number of times each pancake was flipped over by the time it was all finished.
When each pancake is given the number of pancakes on the iron plate and how many times it must be turned over before it is completed, the number of times each pancake is turned over before it is completed (manipulate the spatula). Create a program that calculates the minimum sum of (not the number of times).
Input
The input is given in the following format.
N
p1 p2 ... pN
The number of pancakes N (3 β€ N β€ 5000) is given on the first line. The second line gives the number of flips pi (0 β€ pi β€ 3) required to complete each pancake.
Output
Output the minimum value of the total number of times each pancake is turned inside out on one line until all are completed.
Examples
Input
3
1 2 1
Output
4
Input
3
0 3 0
Output
6
Submitted Solution:
```
'''aizu 0340
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0340
'''
# encoding: 'utf-8'
def main():
length = int(input())
hill = [int(x) for x in input().split()]
count = 0
while any([x > 0 for x in hill]):
hill, c = step(hill)
count += c
# print(count, hill)
print(count)
def step(hill):
c = 0
highest = max(hill)
for (i, _) in ((i,x) for (i, x) in enumerate(hill) if x == highest):
if 0 < i < len(hill)-1:
if hill[i-1] > hill[i+1]:
hill[i-1] -= 1
else:
hill[i+1] -= 1
hill[i] -= 1
c += 2
elif i == 0:
if hill[1] > 0:
hill[1] -= 1
c += 1
hill[0] -= 1
c += 1
elif i == len(hill) - 1:
if hill[-2] > 0:
hill[-2] -= 1
c += 1
hill[-1] -= 1
c += 1
else:
raise Exception("unreachable")
return (hill, c)
if __name__ == '__main__':
main()
``` | instruction | 0 | 47,872 | 9 | 95,744 |
No | output | 1 | 47,872 | 9 | 95,745 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In 2N - 1 boxes there are apples and oranges. Your task is to choose N boxes so, that they will contain not less than half of all the apples and not less than half of all the oranges.
Input
The first input line contains one number T β amount of tests. The description of each test starts with a natural number N β amount of boxes. Each of the following 2N - 1 lines contains numbers ai and oi β amount of apples and oranges in the i-th box (0 β€ ai, oi β€ 109). The sum of N in all the tests in the input doesn't exceed 105. All the input numbers are integer.
Output
For each test output two lines. In the first line output YES, if it's possible to choose N boxes, or NO otherwise. If the answer is positive output in the second line N numbers β indexes of the chosen boxes. Boxes are numbered from 1 in the input order. Otherwise leave the second line empty. Separate the numbers with one space.
Examples
Input
2
2
10 15
5 7
20 18
1
0 0
Output
YES
1 3
YES
1 | instruction | 0 | 48,201 | 9 | 96,402 |
Tags: constructive algorithms, sortings
Correct Solution:
```
t = int(input())
while t:
t = t-1
boxes = []
n = int(input())
num_box = (2*n)-1
for i in range(num_box):
pair = input().split()
apples = int(pair[0])
oranges = int(pair[1])
boxes.append((apples, oranges, i+1))
print("YES")
boxes.sort(reverse=True)
orange_boxes = list(zip(*boxes))[1]
total_oranges = sum(orange_boxes)
half_sum1 = sum(orange_boxes[::2])
half_sum2 = sum(orange_boxes[1::2])
index_list = list(list(zip(*boxes))[2])
index_list1 = index_list[::2]
index_list2 = index_list[1::2]
index_list2.append(index_list1[0])
if half_sum1 >= half_sum2:
print(*index_list1, sep=' ')
else:
print(*index_list2, sep=' ')
``` | output | 1 | 48,201 | 9 | 96,403 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In 2N - 1 boxes there are apples and oranges. Your task is to choose N boxes so, that they will contain not less than half of all the apples and not less than half of all the oranges.
Input
The first input line contains one number T β amount of tests. The description of each test starts with a natural number N β amount of boxes. Each of the following 2N - 1 lines contains numbers ai and oi β amount of apples and oranges in the i-th box (0 β€ ai, oi β€ 109). The sum of N in all the tests in the input doesn't exceed 105. All the input numbers are integer.
Output
For each test output two lines. In the first line output YES, if it's possible to choose N boxes, or NO otherwise. If the answer is positive output in the second line N numbers β indexes of the chosen boxes. Boxes are numbered from 1 in the input order. Otherwise leave the second line empty. Separate the numbers with one space.
Examples
Input
2
2
10 15
5 7
20 18
1
0 0
Output
YES
1 3
YES
1 | instruction | 0 | 48,202 | 9 | 96,404 |
Tags: constructive algorithms, sortings
Correct Solution:
```
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
##########################################################
#for _ in range(int(input())):
def primes(n):
sieve = [True] * n
for i in range(3, int(n ** 0.5) + 1, 2):
if sieve[i]:
sieve[i * i::2 * i] = [False] * ((n - i * i - 1) // (2 * i) + 1)
return [2] + [i for i in range(3, n, 2) if sieve[i]]
def binomial_coefficient(n, k):
if 0 <= k <= n:
ntok = 1
ktok = 1
for t in range(1, min(k, n - k) + 1):
ntok *= n
ktok *= t
n -= 1
return ntok // ktok
else:
return 0
def powerOfK(k, max):
if k == 1:
return [1]
if k == -1:
return [-1, 1]
result = []
n = 1
while n <= max:
result.append(n)
n *= k
return result
def prefixSum(arr):
for i in range(1, len(arr)):
arr[i] = arr[i] + arr[i - 1]
return arr
def divisors(n):
i = 1
result = []
while i * i <= n:
if n % i == 0:
if n / i == i:
result.append(i)
else:
result.append(i)
result.append(n / i)
i += 1
return result
def kadane(a, size):
max_so_far = 0
max_ending_here = 0
for i in range(0, size):
max_ending_here = max_ending_here + a[i]
if (max_so_far < max_ending_here):
max_so_far = max_ending_here
if max_ending_here < 0:
max_ending_here = 0
return max_so_far
# @lru_cache(maxsize=None)
def digitsSum(n):
if n == 0:
return 0
r = 0
while n > 0:
r += n % 10
n //= 10
return r
def print_grid(grid):
for line in grid:
print("".join(line))
# n=int(input())
# n,k=map(int,input().split())
# arr=list(map(int,input().split()))
#ls=list(map(int,input().split()))
#for i in range(m):
# for _ in range(int(input())):
from collections import Counter
#from fractions import Fraction
#n = int(input())
# for _ in range(int(input())):
# import math
import sys
# from collections import deque
# n=int(input())
import math
from math import gcd
for _ in range(int(input())):
n = int(input())
b=[]
t=0
for i in range(2*n-1):
u,v=map(int,input().split())
b.append((u,v,i+1))
t+=v
b=sorted(b,key=lambda x:x[0])
eo=b[::2]
oo=b[1::2]+[b[-1]]
e_or=sum([e[1] for e in eo])
o_or=sum([e[1] for e in oo])
var=t//2
if t%2!=0:
var+=1
if e_or>=var:
ind=[i[2] for i in eo]
print("YES")
print(*ind)
elif o_or>=var:
ind = [i[2] for i in oo]
print("YES")
print(*ind)
else:
print("NO")
'''for i in range(2,int(n**0.5)+1):
if n%i==0:
print(n//i,-(n//i))
break
else:
print(1, n-1)'''
``` | output | 1 | 48,202 | 9 | 96,405 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In 2N - 1 boxes there are apples and oranges. Your task is to choose N boxes so, that they will contain not less than half of all the apples and not less than half of all the oranges.
Input
The first input line contains one number T β amount of tests. The description of each test starts with a natural number N β amount of boxes. Each of the following 2N - 1 lines contains numbers ai and oi β amount of apples and oranges in the i-th box (0 β€ ai, oi β€ 109). The sum of N in all the tests in the input doesn't exceed 105. All the input numbers are integer.
Output
For each test output two lines. In the first line output YES, if it's possible to choose N boxes, or NO otherwise. If the answer is positive output in the second line N numbers β indexes of the chosen boxes. Boxes are numbered from 1 in the input order. Otherwise leave the second line empty. Separate the numbers with one space.
Examples
Input
2
2
10 15
5 7
20 18
1
0 0
Output
YES
1 3
YES
1 | instruction | 0 | 48,203 | 9 | 96,406 |
Tags: constructive algorithms, sortings
Correct Solution:
```
import sys
input = sys.stdin.readline
t = int(input())
for cs in range(t):
n = int(input())
arr = []
for i in range(2 * n - 1):
a, b = map(int, input().split())
arr.append((a, b, i))
arr.sort()
res = []
for i in range(0, len(arr), 2):
if i + 1 < len(arr):
if arr[i][1] > arr[i + 1][1]:
res.append(arr[i][2] + 1)
else:
res.append(arr[i + 1][2] + 1)
else:
res.append(arr[i][2] + 1)
print('YES')
print(' '.join(map(str, res)))
``` | output | 1 | 48,203 | 9 | 96,407 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In 2N - 1 boxes there are apples and oranges. Your task is to choose N boxes so, that they will contain not less than half of all the apples and not less than half of all the oranges.
Input
The first input line contains one number T β amount of tests. The description of each test starts with a natural number N β amount of boxes. Each of the following 2N - 1 lines contains numbers ai and oi β amount of apples and oranges in the i-th box (0 β€ ai, oi β€ 109). The sum of N in all the tests in the input doesn't exceed 105. All the input numbers are integer.
Output
For each test output two lines. In the first line output YES, if it's possible to choose N boxes, or NO otherwise. If the answer is positive output in the second line N numbers β indexes of the chosen boxes. Boxes are numbered from 1 in the input order. Otherwise leave the second line empty. Separate the numbers with one space.
Examples
Input
2
2
10 15
5 7
20 18
1
0 0
Output
YES
1 3
YES
1 | instruction | 0 | 48,204 | 9 | 96,408 |
Tags: constructive algorithms, sortings
Correct Solution:
```
import os,io
from sys import stdout
import collections
# import random
import math
from operator import itemgetter
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
from collections import Counter
# from decimal import Decimal
# import heapq
# from functools import lru_cache
# import sys
# sys.setrecursionlimit(10**6)
# from functools import lru_cache
# @lru_cache(maxsize=None)
def primes(n):
sieve = [True] * n
for i in range(3,int(n**0.5)+1,2):
if sieve[i]:
sieve[i*i::2*i]=[False]*((n-i*i-1)//(2*i)+1)
return [2] + [i for i in range(3,n,2) if sieve[i]]
def binomial_coefficient(n, k):
if 0 <= k <= n:
ntok = 1
ktok = 1
for t in range(1, min(k, n - k) + 1):
ntok *= n
ktok *= t
n -= 1
return ntok // ktok
else:
return 0
def powerOfK(k, max):
if k == 1:
return [1]
if k == -1:
return [-1, 1]
result = []
n = 1
while n <= max:
result.append(n)
n *= k
return result
def prefixSum(arr):
for i in range(1, len(arr)):
arr[i] = arr[i] + arr[i-1]
return arr
def divisors(n):
i = 1
result = []
while i*i <= n:
if n%i == 0:
if n/i == i:
result.append(i)
else:
result.append(i)
result.append(n/i)
i+=1
return result
def kadane(a,size):
max_so_far = 0
max_ending_here = 0
for i in range(0, size):
max_ending_here = max_ending_here + a[i]
if (max_so_far < max_ending_here):
max_so_far = max_ending_here
if max_ending_here < 0:
max_ending_here = 0
return max_so_far
# @lru_cache(maxsize=None)
def digitsSum(n):
if n == 0:
return 0
r = 0
while n > 0:
r += n % 10
n //= 10
return r
def print_grid(grid):
for line in grid:
print("".join(line))
# INPUTS --------------------------
# s = input().decode('utf-8').strip()
# n = int(input())
# l = list(map(int, input().split()))
# t = int(input())
# for _ in range(t):
# for _ in range(t):
t = int(input())
for _ in range(t):
n = int(input())
boxes = []
i = 0
for _ in range(2*n-1):
boxes.append(list(map(int, input().split()))+[i+1])
i+=1
boxes = sorted(boxes, key=itemgetter(1))
even = boxes[::2]
odd = boxes[1::2] + [boxes[-1]]
apples = sum([e[0] for e in boxes])
halfapple = apples // 2
if apples % 2 == 1:
halfapple += 1
aeven = sum([e[0] for e in even])
aodd = sum([e[0] for e in odd])
if aeven >= halfapple:
print('YES')
res = []
for e in even:
res.append(e[2])
print(" ".join([str(e) for e in sorted(res)]))
elif aodd >= halfapple:
print('YES')
res = []
for e in odd:
res.append(e[2])
print(" ".join([str(e) for e in sorted(res)]))
else:
print('NO')
``` | output | 1 | 48,204 | 9 | 96,409 |
Provide tags and a correct Python 3 solution for this coding contest problem.
In 2N - 1 boxes there are apples and oranges. Your task is to choose N boxes so, that they will contain not less than half of all the apples and not less than half of all the oranges.
Input
The first input line contains one number T β amount of tests. The description of each test starts with a natural number N β amount of boxes. Each of the following 2N - 1 lines contains numbers ai and oi β amount of apples and oranges in the i-th box (0 β€ ai, oi β€ 109). The sum of N in all the tests in the input doesn't exceed 105. All the input numbers are integer.
Output
For each test output two lines. In the first line output YES, if it's possible to choose N boxes, or NO otherwise. If the answer is positive output in the second line N numbers β indexes of the chosen boxes. Boxes are numbered from 1 in the input order. Otherwise leave the second line empty. Separate the numbers with one space.
Examples
Input
2
2
10 15
5 7
20 18
1
0 0
Output
YES
1 3
YES
1 | instruction | 0 | 48,205 | 9 | 96,410 |
Tags: constructive algorithms, sortings
Correct Solution:
```
t=int(input())
for _ in range(t):
n=int(input())
nums=[]
for i in range(2*n-1):
a,b=map(int,input().split())
nums.append([b,a,i+1])
nums=sorted(nums)[::-1]
vals=[nums[0][2]]
i=1
while(i+1<len(nums)):
c=i
if(nums[i][1]<nums[i+1][1]):
c=i+1
vals.append(nums[c][2])
i+=2
print("YES")
print(*vals)
``` | output | 1 | 48,205 | 9 | 96,411 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In 2N - 1 boxes there are apples and oranges. Your task is to choose N boxes so, that they will contain not less than half of all the apples and not less than half of all the oranges.
Input
The first input line contains one number T β amount of tests. The description of each test starts with a natural number N β amount of boxes. Each of the following 2N - 1 lines contains numbers ai and oi β amount of apples and oranges in the i-th box (0 β€ ai, oi β€ 109). The sum of N in all the tests in the input doesn't exceed 105. All the input numbers are integer.
Output
For each test output two lines. In the first line output YES, if it's possible to choose N boxes, or NO otherwise. If the answer is positive output in the second line N numbers β indexes of the chosen boxes. Boxes are numbered from 1 in the input order. Otherwise leave the second line empty. Separate the numbers with one space.
Examples
Input
2
2
10 15
5 7
20 18
1
0 0
Output
YES
1 3
YES
1
Submitted Solution:
```
import os,io
from sys import stdout
import collections
# import random
import math
from operator import itemgetter
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
from collections import Counter
# from decimal import Decimal
# import heapq
# from functools import lru_cache
# import sys
# sys.setrecursionlimit(10**6)
# from functools import lru_cache
# @lru_cache(maxsize=None)
def primes(n):
sieve = [True] * n
for i in range(3,int(n**0.5)+1,2):
if sieve[i]:
sieve[i*i::2*i]=[False]*((n-i*i-1)//(2*i)+1)
return [2] + [i for i in range(3,n,2) if sieve[i]]
def binomial_coefficient(n, k):
if 0 <= k <= n:
ntok = 1
ktok = 1
for t in range(1, min(k, n - k) + 1):
ntok *= n
ktok *= t
n -= 1
return ntok // ktok
else:
return 0
def powerOfK(k, max):
if k == 1:
return [1]
if k == -1:
return [-1, 1]
result = []
n = 1
while n <= max:
result.append(n)
n *= k
return result
def prefixSum(arr):
for i in range(1, len(arr)):
arr[i] = arr[i] + arr[i-1]
return arr
def divisors(n):
i = 1
result = []
while i*i <= n:
if n%i == 0:
if n/i == i:
result.append(i)
else:
result.append(i)
result.append(n/i)
i+=1
return result
def kadane(a,size):
max_so_far = 0
max_ending_here = 0
for i in range(0, size):
max_ending_here = max_ending_here + a[i]
if (max_so_far < max_ending_here):
max_so_far = max_ending_here
if max_ending_here < 0:
max_ending_here = 0
return max_so_far
# @lru_cache(maxsize=None)
def digitsSum(n):
if n == 0:
return 0
r = 0
while n > 0:
r += n % 10
n //= 10
return r
def print_grid(grid):
for line in grid:
print("".join(line))
# INPUTS --------------------------
# s = input().decode('utf-8').strip()
# n = int(input())
# l = list(map(int, input().split()))
# t = int(input())
# for _ in range(t):
# for _ in range(t):
t = int(input())
for _ in range(t):
n = int(input())
boxes = []
i = 0
for _ in range(2*n-1):
boxes.append(list(map(int, input().split()))+[i+1])
i+=1
boxes = sorted(boxes, key=itemgetter(1))
even = boxes[::2]
odd = boxes[1::2]
apples = sum([e[1] for e in boxes])
halfapple = apples // 2
if apples % 2 == 1:
halfapple += 1
aeven = sum([e[1] for e in even])
aodd = sum([e[1] for e in odd])
if aeven >= halfapple:
print('YES')
res = []
for e in even:
res.append(e[2])
print(" ".join([str(e) for e in sorted(res)]))
elif aodd >= halfapple:
print('YES')
res = []
for e in odd:
res.append(e[2])
res.append(even[-1][2])
print(" ".join([str(e) for e in sorted(res)]))
else:
print('NO')
``` | instruction | 0 | 48,206 | 9 | 96,412 |
No | output | 1 | 48,206 | 9 | 96,413 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In 2N - 1 boxes there are apples and oranges. Your task is to choose N boxes so, that they will contain not less than half of all the apples and not less than half of all the oranges.
Input
The first input line contains one number T β amount of tests. The description of each test starts with a natural number N β amount of boxes. Each of the following 2N - 1 lines contains numbers ai and oi β amount of apples and oranges in the i-th box (0 β€ ai, oi β€ 109). The sum of N in all the tests in the input doesn't exceed 105. All the input numbers are integer.
Output
For each test output two lines. In the first line output YES, if it's possible to choose N boxes, or NO otherwise. If the answer is positive output in the second line N numbers β indexes of the chosen boxes. Boxes are numbered from 1 in the input order. Otherwise leave the second line empty. Separate the numbers with one space.
Examples
Input
2
2
10 15
5 7
20 18
1
0 0
Output
YES
1 3
YES
1
Submitted Solution:
```
t=int(input())
for z in range(t):
n=int(input())
s1=0
s2=0
l1=[]
l2=[]
l3=[]
for i in range(2*n-1):
a,b=map(int,input().split())
s1+=a/2
s2+=b/2
l1.append(a)
l2.append(b)
l3.append(((a+b)*a*b,i))
l4=l3[:]
l4.sort()
l4.reverse()
d1=0
d2=0
for i in range(n):
d1+=l1[l4[i][1]]
d2+=l2[l4[i][1]]
if d1<s1 or d2<s2:
print("NO")
else:
print("YES")
for i in range(n):
print(l4[i][1]+1,end=" ")
print()
``` | instruction | 0 | 48,207 | 9 | 96,414 |
No | output | 1 | 48,207 | 9 | 96,415 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In 2N - 1 boxes there are apples and oranges. Your task is to choose N boxes so, that they will contain not less than half of all the apples and not less than half of all the oranges.
Input
The first input line contains one number T β amount of tests. The description of each test starts with a natural number N β amount of boxes. Each of the following 2N - 1 lines contains numbers ai and oi β amount of apples and oranges in the i-th box (0 β€ ai, oi β€ 109). The sum of N in all the tests in the input doesn't exceed 105. All the input numbers are integer.
Output
For each test output two lines. In the first line output YES, if it's possible to choose N boxes, or NO otherwise. If the answer is positive output in the second line N numbers β indexes of the chosen boxes. Boxes are numbered from 1 in the input order. Otherwise leave the second line empty. Separate the numbers with one space.
Examples
Input
2
2
10 15
5 7
20 18
1
0 0
Output
YES
1 3
YES
1
Submitted Solution:
```
t=int(input())
for i in range(t):
n=int(input())
app=[];ora=[];apps=ors=0
for j in range(2*n-1):
a,o=map(int,input().split())
apps+=a;ors+=o
app.append([a,o,j+1]);ora.append([o,j+1])
app.sort(reverse=True);ora.sort(reverse=True)
apps=-(-apps//2);ors=-(-ors//2)
s=set()
for j in range(n):
s.add(app[j][2])
apps-=app[j][0];ors-=app[j][1]
if apps<=0:
break
for j in range(2*n-1):
if len(s)==n:break
if ora[j][1] not in s:
s.add(ora[j][1])
ors-=ora[j][0]
if ors<=0 and apps<=0 and len(s)==n:
print('YES')
print(*list(s))
else:
print('NO')
``` | instruction | 0 | 48,208 | 9 | 96,416 |
No | output | 1 | 48,208 | 9 | 96,417 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
In 2N - 1 boxes there are apples and oranges. Your task is to choose N boxes so, that they will contain not less than half of all the apples and not less than half of all the oranges.
Input
The first input line contains one number T β amount of tests. The description of each test starts with a natural number N β amount of boxes. Each of the following 2N - 1 lines contains numbers ai and oi β amount of apples and oranges in the i-th box (0 β€ ai, oi β€ 109). The sum of N in all the tests in the input doesn't exceed 105. All the input numbers are integer.
Output
For each test output two lines. In the first line output YES, if it's possible to choose N boxes, or NO otherwise. If the answer is positive output in the second line N numbers β indexes of the chosen boxes. Boxes are numbered from 1 in the input order. Otherwise leave the second line empty. Separate the numbers with one space.
Examples
Input
2
2
10 15
5 7
20 18
1
0 0
Output
YES
1 3
YES
1
Submitted Solution:
```
t = int(input())
boxes = []
while t:
t = t-1
n = int(input())
num_box = (2*n)-1
for i in range(num_box):
pair = input().split()
apples = int(pair[0])
oranges = int(pair[1])
boxes.append((apples, oranges, i+1))
print("YES")
boxes.sort(reverse=True)
orange_boxes = list(zip(*boxes))[1]
total_oranges = sum(orange_boxes)
half_sum1 = sum(orange_boxes[::2])
half_sum2 = sum(orange_boxes[1::2])
index_list = list(list(zip(*boxes))[2])
index_list1 = index_list[::2]
index_list2 = index_list[1::2]
index_list2.append(index_list1[0])
if half_sum1 >= half_sum2:
print(*index_list1, sep=' ')
else:
print(*index_list2, sep=' ')
``` | instruction | 0 | 48,209 | 9 | 96,418 |
No | output | 1 | 48,209 | 9 | 96,419 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Gerald has n younger brothers and their number happens to be even. One day he bought n2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer k from 1 to n2 he has exactly one bag with k candies.
Help him give n bags of candies to each brother so that all brothers got the same number of candies.
Input
The single line contains a single integer n (n is even, 2 β€ n β€ 100) β the number of Gerald's brothers.
Output
Let's assume that Gerald indexes his brothers with numbers from 1 to n. You need to print n lines, on the i-th line print n integers β the numbers of candies in the bags for the i-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to n2. You can print the numbers in the lines in any order.
It is guaranteed that the solution exists at the given limits.
Examples
Input
2
Output
1 4
2 3
Note
The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother. | instruction | 0 | 49,144 | 9 | 98,288 |
Tags: implementation
Correct Solution:
```
N=int(input()) # is always even 2<N<100
candies=[x+1 for x in range(N**2)]
sumof_candies_per_person=sum(candies)/N
candies=list(reversed(sorted(candies)))
bags_per_person=[]
for i in range(N):
bags_per_person.append(candies[0:N//2]+candies[-N//2:])
del candies[0:N//2]
del candies[-N//2:]
for bags in bags_per_person:
for bag in bags:
print(bag, end=" ")
print("")
``` | output | 1 | 49,144 | 9 | 98,289 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Gerald has n younger brothers and their number happens to be even. One day he bought n2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer k from 1 to n2 he has exactly one bag with k candies.
Help him give n bags of candies to each brother so that all brothers got the same number of candies.
Input
The single line contains a single integer n (n is even, 2 β€ n β€ 100) β the number of Gerald's brothers.
Output
Let's assume that Gerald indexes his brothers with numbers from 1 to n. You need to print n lines, on the i-th line print n integers β the numbers of candies in the bags for the i-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to n2. You can print the numbers in the lines in any order.
It is guaranteed that the solution exists at the given limits.
Examples
Input
2
Output
1 4
2 3
Note
The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother. | instruction | 0 | 49,145 | 9 | 98,290 |
Tags: implementation
Correct Solution:
```
n = int(input())
sqN = n**2
for i in range (n):
for j in range(i * int(n / 2) + 1, (i + 1) * int(n / 2) + 1):
print(j, sqN - j + 1, end = ' ')
print()
``` | output | 1 | 49,145 | 9 | 98,291 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Gerald has n younger brothers and their number happens to be even. One day he bought n2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer k from 1 to n2 he has exactly one bag with k candies.
Help him give n bags of candies to each brother so that all brothers got the same number of candies.
Input
The single line contains a single integer n (n is even, 2 β€ n β€ 100) β the number of Gerald's brothers.
Output
Let's assume that Gerald indexes his brothers with numbers from 1 to n. You need to print n lines, on the i-th line print n integers β the numbers of candies in the bags for the i-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to n2. You can print the numbers in the lines in any order.
It is guaranteed that the solution exists at the given limits.
Examples
Input
2
Output
1 4
2 3
Note
The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother. | instruction | 0 | 49,146 | 9 | 98,292 |
Tags: implementation
Correct Solution:
```
loop = int(input())
usage = []
for i in range(1, loop**2+1):
usage.append(str(i))
k = 0
d = len(usage)-1
for i in range(loop):
finals = ""
for j in range(int(loop/2)):
finals+=usage[k]
finals+=" "
k+=1
for j in range(int(loop/2)):
finals+=usage[d]
finals+=" "
d-=1
print(finals)
``` | output | 1 | 49,146 | 9 | 98,293 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Gerald has n younger brothers and their number happens to be even. One day he bought n2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer k from 1 to n2 he has exactly one bag with k candies.
Help him give n bags of candies to each brother so that all brothers got the same number of candies.
Input
The single line contains a single integer n (n is even, 2 β€ n β€ 100) β the number of Gerald's brothers.
Output
Let's assume that Gerald indexes his brothers with numbers from 1 to n. You need to print n lines, on the i-th line print n integers β the numbers of candies in the bags for the i-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to n2. You can print the numbers in the lines in any order.
It is guaranteed that the solution exists at the given limits.
Examples
Input
2
Output
1 4
2 3
Note
The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother. | instruction | 0 | 49,147 | 9 | 98,294 |
Tags: implementation
Correct Solution:
```
def main():
n = int(input())
results = [[0 for _ in range(n)] for __ in range(n)]
number = 1
for col in range(n):
starting_row = number // n
for row in range(starting_row, n):
results[row][col] = number
number += 1
for row in range(starting_row):
results[row][col] = number
number += 1
for row in results:
print(' '.join([str(value) for value in row]))
if __name__ == '__main__':
main()
``` | output | 1 | 49,147 | 9 | 98,295 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Gerald has n younger brothers and their number happens to be even. One day he bought n2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer k from 1 to n2 he has exactly one bag with k candies.
Help him give n bags of candies to each brother so that all brothers got the same number of candies.
Input
The single line contains a single integer n (n is even, 2 β€ n β€ 100) β the number of Gerald's brothers.
Output
Let's assume that Gerald indexes his brothers with numbers from 1 to n. You need to print n lines, on the i-th line print n integers β the numbers of candies in the bags for the i-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to n2. You can print the numbers in the lines in any order.
It is guaranteed that the solution exists at the given limits.
Examples
Input
2
Output
1 4
2 3
Note
The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother. | instruction | 0 | 49,148 | 9 | 98,296 |
Tags: implementation
Correct Solution:
```
# import sys
# sys.stdin=open("input.in",'r')
# sys.stdout=open("out.out",'w')
n=int(input())
for i in range((n*n)//2):
if ((i+1)*2)%n!=0:
print(i+1,n*n-i,end=" ")
else:
print(i+1,n*n-i)
``` | output | 1 | 49,148 | 9 | 98,297 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Gerald has n younger brothers and their number happens to be even. One day he bought n2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer k from 1 to n2 he has exactly one bag with k candies.
Help him give n bags of candies to each brother so that all brothers got the same number of candies.
Input
The single line contains a single integer n (n is even, 2 β€ n β€ 100) β the number of Gerald's brothers.
Output
Let's assume that Gerald indexes his brothers with numbers from 1 to n. You need to print n lines, on the i-th line print n integers β the numbers of candies in the bags for the i-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to n2. You can print the numbers in the lines in any order.
It is guaranteed that the solution exists at the given limits.
Examples
Input
2
Output
1 4
2 3
Note
The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother. | instruction | 0 | 49,149 | 9 | 98,298 |
Tags: implementation
Correct Solution:
```
a=int(input())
b=a*a
k=0
n=1
m=a**2
z=0
for i in range(a):
p=[]
while k<m:
p.append(n)
n=n+1
k=k+1
if k==a//2:
k=0
break
while k<m:
p.append(m-z)
z=z+1
k=k+1
if k==a//2:
k=0
break
s=str(p[0])
for i in range(1,len(p)):
s=s+" "+str(p[i])
print(s)
``` | output | 1 | 49,149 | 9 | 98,299 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Gerald has n younger brothers and their number happens to be even. One day he bought n2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer k from 1 to n2 he has exactly one bag with k candies.
Help him give n bags of candies to each brother so that all brothers got the same number of candies.
Input
The single line contains a single integer n (n is even, 2 β€ n β€ 100) β the number of Gerald's brothers.
Output
Let's assume that Gerald indexes his brothers with numbers from 1 to n. You need to print n lines, on the i-th line print n integers β the numbers of candies in the bags for the i-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to n2. You can print the numbers in the lines in any order.
It is guaranteed that the solution exists at the given limits.
Examples
Input
2
Output
1 4
2 3
Note
The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother. | instruction | 0 | 49,150 | 9 | 98,300 |
Tags: implementation
Correct Solution:
```
import sys
input = sys.stdin.readline
from operator import mul
from functools import reduce
############ ---- Input Functions ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(map(int,input().split()))
########### ----- MAIN FUNCTION ---- ##########
def main():
n=inp()
list1 = []
for i in range(n*n//2):
list1.append(i+1)
list1.append(n*n-i)
cnt=0
for i in range(n):
for j in range(n):
print(list1[i*n+j],end=" ")
print()
if __name__ == "__main__":
main()
``` | output | 1 | 49,150 | 9 | 98,301 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Gerald has n younger brothers and their number happens to be even. One day he bought n2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer k from 1 to n2 he has exactly one bag with k candies.
Help him give n bags of candies to each brother so that all brothers got the same number of candies.
Input
The single line contains a single integer n (n is even, 2 β€ n β€ 100) β the number of Gerald's brothers.
Output
Let's assume that Gerald indexes his brothers with numbers from 1 to n. You need to print n lines, on the i-th line print n integers β the numbers of candies in the bags for the i-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to n2. You can print the numbers in the lines in any order.
It is guaranteed that the solution exists at the given limits.
Examples
Input
2
Output
1 4
2 3
Note
The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother. | instruction | 0 | 49,151 | 9 | 98,302 |
Tags: implementation
Correct Solution:
```
n = int(input())
for i in range(n):
for j in range(n):
if j < n/2:
ind = (i+1) + j*n
else:
ind = (n-i) + j*n
print(ind, end=' ')
print()
``` | output | 1 | 49,151 | 9 | 98,303 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Gerald has n younger brothers and their number happens to be even. One day he bought n2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer k from 1 to n2 he has exactly one bag with k candies.
Help him give n bags of candies to each brother so that all brothers got the same number of candies.
Input
The single line contains a single integer n (n is even, 2 β€ n β€ 100) β the number of Gerald's brothers.
Output
Let's assume that Gerald indexes his brothers with numbers from 1 to n. You need to print n lines, on the i-th line print n integers β the numbers of candies in the bags for the i-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to n2. You can print the numbers in the lines in any order.
It is guaranteed that the solution exists at the given limits.
Examples
Input
2
Output
1 4
2 3
Note
The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother.
Submitted Solution:
```
# https://codeforces.com/contest/334/problem/A
def single_integer():
return int(input())
def multi_integer():
return map(int, input().split())
def string():
return input()
def multi_string():
return input().split()
n = single_integer()
t = n ** 2
ans = list()
for i in range(t):
ans.append((i + 1, t - i))
i = 0
while i < t // 2:
for k in range(i, i + n // 2):
print(*ans[k], end=" ")
i += n //2
print()
``` | instruction | 0 | 49,152 | 9 | 98,304 |
Yes | output | 1 | 49,152 | 9 | 98,305 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Gerald has n younger brothers and their number happens to be even. One day he bought n2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer k from 1 to n2 he has exactly one bag with k candies.
Help him give n bags of candies to each brother so that all brothers got the same number of candies.
Input
The single line contains a single integer n (n is even, 2 β€ n β€ 100) β the number of Gerald's brothers.
Output
Let's assume that Gerald indexes his brothers with numbers from 1 to n. You need to print n lines, on the i-th line print n integers β the numbers of candies in the bags for the i-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to n2. You can print the numbers in the lines in any order.
It is guaranteed that the solution exists at the given limits.
Examples
Input
2
Output
1 4
2 3
Note
The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother.
Submitted Solution:
```
a=int(input())
k=a**2
half=int(a/2)
sweets=[x for x in range(1,k+1)]
for x in range(a):
print(*sweets[:half],*sweets[-half:])
sweets[:half]=[]
sweets[-half:]=[]
``` | instruction | 0 | 49,153 | 9 | 98,306 |
Yes | output | 1 | 49,153 | 9 | 98,307 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Gerald has n younger brothers and their number happens to be even. One day he bought n2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer k from 1 to n2 he has exactly one bag with k candies.
Help him give n bags of candies to each brother so that all brothers got the same number of candies.
Input
The single line contains a single integer n (n is even, 2 β€ n β€ 100) β the number of Gerald's brothers.
Output
Let's assume that Gerald indexes his brothers with numbers from 1 to n. You need to print n lines, on the i-th line print n integers β the numbers of candies in the bags for the i-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to n2. You can print the numbers in the lines in any order.
It is guaranteed that the solution exists at the given limits.
Examples
Input
2
Output
1 4
2 3
Note
The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother.
Submitted Solution:
```
n = int(input())
for i in range(int(n**2/2)):
print(i+1, n**2 - i)
``` | instruction | 0 | 49,154 | 9 | 98,308 |
Yes | output | 1 | 49,154 | 9 | 98,309 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Gerald has n younger brothers and their number happens to be even. One day he bought n2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer k from 1 to n2 he has exactly one bag with k candies.
Help him give n bags of candies to each brother so that all brothers got the same number of candies.
Input
The single line contains a single integer n (n is even, 2 β€ n β€ 100) β the number of Gerald's brothers.
Output
Let's assume that Gerald indexes his brothers with numbers from 1 to n. You need to print n lines, on the i-th line print n integers β the numbers of candies in the bags for the i-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to n2. You can print the numbers in the lines in any order.
It is guaranteed that the solution exists at the given limits.
Examples
Input
2
Output
1 4
2 3
Note
The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother.
Submitted Solution:
```
n = int(input())
j, k = n*n, 1
for i in range(n):
for t in range(n//2):
print(k, j, end = ' ')
k += 1
j -= 1
print()
``` | instruction | 0 | 49,155 | 9 | 98,310 |
Yes | output | 1 | 49,155 | 9 | 98,311 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Gerald has n younger brothers and their number happens to be even. One day he bought n2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer k from 1 to n2 he has exactly one bag with k candies.
Help him give n bags of candies to each brother so that all brothers got the same number of candies.
Input
The single line contains a single integer n (n is even, 2 β€ n β€ 100) β the number of Gerald's brothers.
Output
Let's assume that Gerald indexes his brothers with numbers from 1 to n. You need to print n lines, on the i-th line print n integers β the numbers of candies in the bags for the i-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to n2. You can print the numbers in the lines in any order.
It is guaranteed that the solution exists at the given limits.
Examples
Input
2
Output
1 4
2 3
Note
The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother.
Submitted Solution:
```
n = int(input())
m = n**2 + 1
t = n//2
for i in range(t):
x = t*n + 1
for j in range(x, x + t):
print(j, m - j, end=' ')
print()
``` | instruction | 0 | 49,156 | 9 | 98,312 |
No | output | 1 | 49,156 | 9 | 98,313 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Gerald has n younger brothers and their number happens to be even. One day he bought n2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer k from 1 to n2 he has exactly one bag with k candies.
Help him give n bags of candies to each brother so that all brothers got the same number of candies.
Input
The single line contains a single integer n (n is even, 2 β€ n β€ 100) β the number of Gerald's brothers.
Output
Let's assume that Gerald indexes his brothers with numbers from 1 to n. You need to print n lines, on the i-th line print n integers β the numbers of candies in the bags for the i-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to n2. You can print the numbers in the lines in any order.
It is guaranteed that the solution exists at the given limits.
Examples
Input
2
Output
1 4
2 3
Note
The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother.
Submitted Solution:
```
from itertools import combinations
n = int(input())
k = ((n**2)*(n**2 + 1))//2
c = [i for i in range(1,n**2+1)]
ans = []
for i in combinations(c,n):
if sum(i)==(k//n):
print(" ".join(map(str,i)))
``` | instruction | 0 | 49,157 | 9 | 98,314 |
No | output | 1 | 49,157 | 9 | 98,315 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Gerald has n younger brothers and their number happens to be even. One day he bought n2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer k from 1 to n2 he has exactly one bag with k candies.
Help him give n bags of candies to each brother so that all brothers got the same number of candies.
Input
The single line contains a single integer n (n is even, 2 β€ n β€ 100) β the number of Gerald's brothers.
Output
Let's assume that Gerald indexes his brothers with numbers from 1 to n. You need to print n lines, on the i-th line print n integers β the numbers of candies in the bags for the i-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to n2. You can print the numbers in the lines in any order.
It is guaranteed that the solution exists at the given limits.
Examples
Input
2
Output
1 4
2 3
Note
The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother.
Submitted Solution:
```
n=int(input())
for i in range(1,n+1):
print(i,n*n-i+1)
``` | instruction | 0 | 49,158 | 9 | 98,316 |
No | output | 1 | 49,158 | 9 | 98,317 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Gerald has n younger brothers and their number happens to be even. One day he bought n2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer k from 1 to n2 he has exactly one bag with k candies.
Help him give n bags of candies to each brother so that all brothers got the same number of candies.
Input
The single line contains a single integer n (n is even, 2 β€ n β€ 100) β the number of Gerald's brothers.
Output
Let's assume that Gerald indexes his brothers with numbers from 1 to n. You need to print n lines, on the i-th line print n integers β the numbers of candies in the bags for the i-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to n2. You can print the numbers in the lines in any order.
It is guaranteed that the solution exists at the given limits.
Examples
Input
2
Output
1 4
2 3
Note
The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother.
Submitted Solution:
```
n = int(input())
n2=n**2
for i in range(1,n*2+1,2):
for j in range(n//2):
print(i+j,n2-j,end=' ')
n2-=2
print(end='\n')
``` | instruction | 0 | 49,159 | 9 | 98,318 |
No | output | 1 | 49,159 | 9 | 98,319 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jzzhu has a big rectangular chocolate bar that consists of n Γ m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements:
* each cut should be straight (horizontal or vertical);
* each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut);
* each cut should go inside the whole chocolate bar, and all cuts must be distinct.
The picture below shows a possible way to cut a 5 Γ 6 chocolate for 5 times.
<image>
Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it.
Input
A single line contains three integers n, m, k (1 β€ n, m β€ 109; 1 β€ k β€ 2Β·109).
Output
Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1.
Examples
Input
3 4 1
Output
6
Input
6 4 2
Output
8
Input
2 3 4
Output
-1
Note
In the first sample, Jzzhu can cut the chocolate following the picture below:
<image>
In the second sample the optimal division looks like this:
<image>
In the third sample, it's impossible to cut a 2 Γ 3 chocolate 4 times. | instruction | 0 | 49,189 | 9 | 98,378 |
Tags: greedy, math
Correct Solution:
```
import math,sys,bisect,heapq
from collections import defaultdict,Counter,deque
from itertools import groupby,accumulate
#sys.setrecursionlimit(200000000)
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda: map(int,input().split())
alele = lambda: list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
MOD = 1000000000 + 7
def Y(c): print(["NO","YES"][c])
def y(c): print(["no","yes"][c])
def Yy(c): print(["No","Yes"][c])
def printDivisors(n) :
A=[]
i = 1
while i <= math.sqrt(n):
if (n % i == 0) :
if (n / i == i) :
A.append(i)
else :
A.append(i)
A.append(n//i)
i = i + 1
return A
n,m,k= ilele()
z = n-1 + m-1
if k > z:
print(-1)
elif k == z:
print(1)
else:
mini = -1
A = printDivisors(n)
B = printDivisors(m)
#print(A,B)
for i in A:
l = i
b = k - ((n // l) - 1)
if b <= 0:
mini = max(mini,l*m)
else:
if b <= m-1:
r = max(1,m//(b+1))
mini = max(mini,l*r)
#print(mini)
for i in B:
r = i
b = k - ((m // r) - 1)
#print(i,b)
if b <= 0:
mini = max(mini,r*n)
else:
if b <= n-1:
l = max(1,n//(b+1))
mini = max(mini,l*r)
print(mini)
``` | output | 1 | 49,189 | 9 | 98,379 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jzzhu has a big rectangular chocolate bar that consists of n Γ m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements:
* each cut should be straight (horizontal or vertical);
* each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut);
* each cut should go inside the whole chocolate bar, and all cuts must be distinct.
The picture below shows a possible way to cut a 5 Γ 6 chocolate for 5 times.
<image>
Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it.
Input
A single line contains three integers n, m, k (1 β€ n, m β€ 109; 1 β€ k β€ 2Β·109).
Output
Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1.
Examples
Input
3 4 1
Output
6
Input
6 4 2
Output
8
Input
2 3 4
Output
-1
Note
In the first sample, Jzzhu can cut the chocolate following the picture below:
<image>
In the second sample the optimal division looks like this:
<image>
In the third sample, it's impossible to cut a 2 Γ 3 chocolate 4 times. | instruction | 0 | 49,190 | 9 | 98,380 |
Tags: greedy, math
Correct Solution:
```
def main():
n, m, k = [int(i) for i in input().split()]
if k > n + m - 2:
print(-1)
return
if k > n - 1:
result1 = m // (k + 2 - n)
else:
result1 = n // (k + 1) * m
if k > m - 1:
result2 = n // (k + 2 - m)
else:
result2 = m // (k + 1) * n
print(max(result1, result2))
main()
``` | output | 1 | 49,190 | 9 | 98,381 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jzzhu has a big rectangular chocolate bar that consists of n Γ m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements:
* each cut should be straight (horizontal or vertical);
* each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut);
* each cut should go inside the whole chocolate bar, and all cuts must be distinct.
The picture below shows a possible way to cut a 5 Γ 6 chocolate for 5 times.
<image>
Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it.
Input
A single line contains three integers n, m, k (1 β€ n, m β€ 109; 1 β€ k β€ 2Β·109).
Output
Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1.
Examples
Input
3 4 1
Output
6
Input
6 4 2
Output
8
Input
2 3 4
Output
-1
Note
In the first sample, Jzzhu can cut the chocolate following the picture below:
<image>
In the second sample the optimal division looks like this:
<image>
In the third sample, it's impossible to cut a 2 Γ 3 chocolate 4 times. | instruction | 0 | 49,191 | 9 | 98,382 |
Tags: greedy, math
Correct Solution:
```
#!/usr/bin/env python3
from itertools import *
def read_ints():
return map(int, input().strip().split())
n, m, k = read_ints()
def val(x, k, n, m):
Y = x+1
Z = k-x+1
if Y>0 and Z>0:
return (n//(x+1)) * (m//(k-x+1))
def sym(n, m, k):
x = min(n-1, k)
return val(x, k, n, m)
def test(n, m, k):
if n+m+2<k:
return -1
answers = [
sym(n, m, k),
sym(m, n, k),
]
return max(answers) or -1
print(test(n, m, k))
``` | output | 1 | 49,191 | 9 | 98,383 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jzzhu has a big rectangular chocolate bar that consists of n Γ m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements:
* each cut should be straight (horizontal or vertical);
* each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut);
* each cut should go inside the whole chocolate bar, and all cuts must be distinct.
The picture below shows a possible way to cut a 5 Γ 6 chocolate for 5 times.
<image>
Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it.
Input
A single line contains three integers n, m, k (1 β€ n, m β€ 109; 1 β€ k β€ 2Β·109).
Output
Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1.
Examples
Input
3 4 1
Output
6
Input
6 4 2
Output
8
Input
2 3 4
Output
-1
Note
In the first sample, Jzzhu can cut the chocolate following the picture below:
<image>
In the second sample the optimal division looks like this:
<image>
In the third sample, it's impossible to cut a 2 Γ 3 chocolate 4 times. | instruction | 0 | 49,192 | 9 | 98,384 |
Tags: greedy, math
Correct Solution:
```
a = input().split(' ')
n = int(a[0])
m = int(a[1])
k = int(a[2])
if k>m+n-2:
print(-1)
else:
ans = 1
if k<n:
ans = max(ans, n//(k+1)*m)
if k<m:
ans = max(ans,m//(k+1)*n)
if k>=n:
ans = max( ans,m//(k-(n-1)+1) )
if k>=m:
ans = max( ans,n//(k-(m-1)+1) )
print (ans)
``` | output | 1 | 49,192 | 9 | 98,385 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jzzhu has a big rectangular chocolate bar that consists of n Γ m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements:
* each cut should be straight (horizontal or vertical);
* each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut);
* each cut should go inside the whole chocolate bar, and all cuts must be distinct.
The picture below shows a possible way to cut a 5 Γ 6 chocolate for 5 times.
<image>
Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it.
Input
A single line contains three integers n, m, k (1 β€ n, m β€ 109; 1 β€ k β€ 2Β·109).
Output
Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1.
Examples
Input
3 4 1
Output
6
Input
6 4 2
Output
8
Input
2 3 4
Output
-1
Note
In the first sample, Jzzhu can cut the chocolate following the picture below:
<image>
In the second sample the optimal division looks like this:
<image>
In the third sample, it's impossible to cut a 2 Γ 3 chocolate 4 times. | instruction | 0 | 49,193 | 9 | 98,386 |
Tags: greedy, math
Correct Solution:
```
inputx=input().split(' ')
n=int(inputx[0])
m=int(inputx[1])
k=int(inputx[2])
#assume n<=m
if n+m-2<k:
print(-1)
else:
if n>m:
n, m = m, n
if k<n:
print(max(n*int(m/(k+1)), m*int(n/(k+1))))
elif n<=k and k<m:
print(n*int(m/(k+1)))
else:
#long side, cut m-1 times
#short side, cut k-m times
print(int(n/(k-m+2)))
``` | output | 1 | 49,193 | 9 | 98,387 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jzzhu has a big rectangular chocolate bar that consists of n Γ m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements:
* each cut should be straight (horizontal or vertical);
* each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut);
* each cut should go inside the whole chocolate bar, and all cuts must be distinct.
The picture below shows a possible way to cut a 5 Γ 6 chocolate for 5 times.
<image>
Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it.
Input
A single line contains three integers n, m, k (1 β€ n, m β€ 109; 1 β€ k β€ 2Β·109).
Output
Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1.
Examples
Input
3 4 1
Output
6
Input
6 4 2
Output
8
Input
2 3 4
Output
-1
Note
In the first sample, Jzzhu can cut the chocolate following the picture below:
<image>
In the second sample the optimal division looks like this:
<image>
In the third sample, it's impossible to cut a 2 Γ 3 chocolate 4 times. | instruction | 0 | 49,194 | 9 | 98,388 |
Tags: greedy, math
Correct Solution:
```
n,m,k=map(int,input().split())
if m>n:
n,m=m,n
res=-1
if k<n:
res=m*(n//(k+1))
if k<m:
res=max(res,n*(m//(k+1)))
elif k<=(n-1)+m-1:
res=m//((k+1-n)+1)
print(res)
``` | output | 1 | 49,194 | 9 | 98,389 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jzzhu has a big rectangular chocolate bar that consists of n Γ m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements:
* each cut should be straight (horizontal or vertical);
* each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut);
* each cut should go inside the whole chocolate bar, and all cuts must be distinct.
The picture below shows a possible way to cut a 5 Γ 6 chocolate for 5 times.
<image>
Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it.
Input
A single line contains three integers n, m, k (1 β€ n, m β€ 109; 1 β€ k β€ 2Β·109).
Output
Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1.
Examples
Input
3 4 1
Output
6
Input
6 4 2
Output
8
Input
2 3 4
Output
-1
Note
In the first sample, Jzzhu can cut the chocolate following the picture below:
<image>
In the second sample the optimal division looks like this:
<image>
In the third sample, it's impossible to cut a 2 Γ 3 chocolate 4 times. | instruction | 0 | 49,195 | 9 | 98,390 |
Tags: greedy, math
Correct Solution:
```
n, m, k = map(int, input().split())
if m > n:
n, m = m, n
ans = -1
if k < n:
ans = m * (n // (k + 1))
if k < m:
ans = max(ans, n * (m // (k + 1)))
elif k <= (n - 1) + (m - 1):
ans = m // ((k + 1 - n) + 1)
print(ans)
# Made By Mostafa_Khaled
``` | output | 1 | 49,195 | 9 | 98,391 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Jzzhu has a big rectangular chocolate bar that consists of n Γ m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements:
* each cut should be straight (horizontal or vertical);
* each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut);
* each cut should go inside the whole chocolate bar, and all cuts must be distinct.
The picture below shows a possible way to cut a 5 Γ 6 chocolate for 5 times.
<image>
Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it.
Input
A single line contains three integers n, m, k (1 β€ n, m β€ 109; 1 β€ k β€ 2Β·109).
Output
Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1.
Examples
Input
3 4 1
Output
6
Input
6 4 2
Output
8
Input
2 3 4
Output
-1
Note
In the first sample, Jzzhu can cut the chocolate following the picture below:
<image>
In the second sample the optimal division looks like this:
<image>
In the third sample, it's impossible to cut a 2 Γ 3 chocolate 4 times. | instruction | 0 | 49,196 | 9 | 98,392 |
Tags: greedy, math
Correct Solution:
```
#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import*
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
ALPHA='abcdefghijklmnopqrstuvwxyz'
M=998244353
EPS=1e-6
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]
#-------------------------code---------------------------#
# vsInput()
# equation = x*(cuts+2-x)
# x=possible i.e. cuts+2-x <= numerator
r,c,cuts=value()
max_cuts=r+c-2
if(cuts>max_cuts):
print(-1)
else:
x=min(cuts+2-1,r)
ans1=(r//x)*(c//(cuts+2-x))
r,c=c,r
x=min(cuts+2-1,r)
ans2=(r//x)*(c//(cuts+2-x))
print(max(ans1,ans2))
``` | output | 1 | 49,196 | 9 | 98,393 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Jzzhu has a big rectangular chocolate bar that consists of n Γ m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements:
* each cut should be straight (horizontal or vertical);
* each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut);
* each cut should go inside the whole chocolate bar, and all cuts must be distinct.
The picture below shows a possible way to cut a 5 Γ 6 chocolate for 5 times.
<image>
Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it.
Input
A single line contains three integers n, m, k (1 β€ n, m β€ 109; 1 β€ k β€ 2Β·109).
Output
Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1.
Examples
Input
3 4 1
Output
6
Input
6 4 2
Output
8
Input
2 3 4
Output
-1
Note
In the first sample, Jzzhu can cut the chocolate following the picture below:
<image>
In the second sample the optimal division looks like this:
<image>
In the third sample, it's impossible to cut a 2 Γ 3 chocolate 4 times.
Submitted Solution:
```
n,m,k=map(int,input().split())
if m>n:
n,m=m,n
ans=-1
if k<n:
ans=m*(n//(k+1))
if k<m:
ans=max(ans,n*(m//(k+1)))
elif k<=(n-1)+m-1:
ans=m//((k+1-n)+1)
print(ans)
``` | instruction | 0 | 49,197 | 9 | 98,394 |
Yes | output | 1 | 49,197 | 9 | 98,395 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Jzzhu has a big rectangular chocolate bar that consists of n Γ m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements:
* each cut should be straight (horizontal or vertical);
* each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut);
* each cut should go inside the whole chocolate bar, and all cuts must be distinct.
The picture below shows a possible way to cut a 5 Γ 6 chocolate for 5 times.
<image>
Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it.
Input
A single line contains three integers n, m, k (1 β€ n, m β€ 109; 1 β€ k β€ 2Β·109).
Output
Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1.
Examples
Input
3 4 1
Output
6
Input
6 4 2
Output
8
Input
2 3 4
Output
-1
Note
In the first sample, Jzzhu can cut the chocolate following the picture below:
<image>
In the second sample the optimal division looks like this:
<image>
In the third sample, it's impossible to cut a 2 Γ 3 chocolate 4 times.
Submitted Solution:
```
a = input().split(' ')
n = int(a[0])
m = int(a[1])
k = int(a[2])
if k>m+n-2:
print -1
else:
px = (n*k+n-m)//(n+m)
limit = 100000
ans = 1
for i in range(limit):
x = px+i-limit//2
y = k-x
if x<0 or y<0:
continue
cx = n/(x+1)
cy = m/(y+1)
ans = max(ans,cx*cy)
print (ans)
``` | instruction | 0 | 49,198 | 9 | 98,396 |
No | output | 1 | 49,198 | 9 | 98,397 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Jzzhu has a big rectangular chocolate bar that consists of n Γ m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements:
* each cut should be straight (horizontal or vertical);
* each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut);
* each cut should go inside the whole chocolate bar, and all cuts must be distinct.
The picture below shows a possible way to cut a 5 Γ 6 chocolate for 5 times.
<image>
Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it.
Input
A single line contains three integers n, m, k (1 β€ n, m β€ 109; 1 β€ k β€ 2Β·109).
Output
Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1.
Examples
Input
3 4 1
Output
6
Input
6 4 2
Output
8
Input
2 3 4
Output
-1
Note
In the first sample, Jzzhu can cut the chocolate following the picture below:
<image>
In the second sample the optimal division looks like this:
<image>
In the third sample, it's impossible to cut a 2 Γ 3 chocolate 4 times.
Submitted Solution:
```
sa=input().split(' ')
dx=int(sa[0])
dy=int(sa[1])
cuts=int(sa[2])
##def pieces(cuts, dim1, dim2):
## if dx>=cuts or dy>=cuts:
## return cuts+1
## else:
## b1=dim1-1
## b2=dim2-1
## if b1+b2<cuts:
## return -1
## else:
## sa1=max(b1, b2)
## sa2=cuts-sa1
## return sa1*sa2+sa1+sa2+1
##
def pieces(cuts, dim1, dim2):
#x+y=cuts
#pieces=(x+1)(y+1)
#x<=b1
#y<=b2
b1=dim1-1
b2=dim2-1
if b1+b2<cuts:
return -1
else:
if b1>=cuts or b2>=cuts:
dimen1=cuts
dimen2=0
elif b1<=cuts and b2<=cuts:
dimen1=max(dim1, dim2)
dimen2=cuts-dimen1
else:
dimen1=cuts
dimen2=0
return ((dimen1+1)*(dimen2+1))
if pieces(cuts, dx, dy)==-1:
print(-1)
else:
print(int(dx*dy/pieces(cuts, dy, dx)))
``` | instruction | 0 | 49,199 | 9 | 98,398 |
No | output | 1 | 49,199 | 9 | 98,399 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Jzzhu has a big rectangular chocolate bar that consists of n Γ m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements:
* each cut should be straight (horizontal or vertical);
* each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut);
* each cut should go inside the whole chocolate bar, and all cuts must be distinct.
The picture below shows a possible way to cut a 5 Γ 6 chocolate for 5 times.
<image>
Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it.
Input
A single line contains three integers n, m, k (1 β€ n, m β€ 109; 1 β€ k β€ 2Β·109).
Output
Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1.
Examples
Input
3 4 1
Output
6
Input
6 4 2
Output
8
Input
2 3 4
Output
-1
Note
In the first sample, Jzzhu can cut the chocolate following the picture below:
<image>
In the second sample the optimal division looks like this:
<image>
In the third sample, it's impossible to cut a 2 Γ 3 chocolate 4 times.
Submitted Solution:
```
sa=input().split(' ')
dx=int(sa[0])
dy=int(sa[1])
cuts=int(sa[2])
##def pieces(cuts, dim1, dim2):
## if dx>=cuts or dy>=cuts:
## return cuts+1
## else:
## b1=dim1-1
## b2=dim2-1
## if b1+b2<cuts:
## return -1
## else:
## sa1=max(b1, b2)
## sa2=cuts-sa1
## return sa1*sa2+sa1+sa2+1
##
def pieces(cuts, dim1, dim2):
#x+y=cuts
#pieces=(x+1)(y+1)
#x<=b1
#y<=b2
b1=dim1-1
b2=dim2-1
if b1+b2<cuts:
return -1
else:
if b1<=cuts and b2<=cuts:
dimen1=max(b1, b2)
dimen2=cuts-dimen1
return ((dimen1+1)*(dimen2+1))
else:
dimen1=cuts
dimen2=0
if b1%cuts==0:
return int(dim2/(cuts+1))*dim1
else:
return int(dim1/(cuts+1))*dim2
if pieces(cuts, dx, dy)==-1:
print(-1)
else:
if dx-1>=cuts or dy-1>=cuts:
print(pieces(cuts, dx, dy))
else:
print(int(dx*dy/pieces(cuts, dy, dx)))
``` | instruction | 0 | 49,200 | 9 | 98,400 |
No | output | 1 | 49,200 | 9 | 98,401 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Jzzhu has a big rectangular chocolate bar that consists of n Γ m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements:
* each cut should be straight (horizontal or vertical);
* each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut);
* each cut should go inside the whole chocolate bar, and all cuts must be distinct.
The picture below shows a possible way to cut a 5 Γ 6 chocolate for 5 times.
<image>
Imagine Jzzhu have made k cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly k cuts? The area of a chocolate piece is the number of unit squares in it.
Input
A single line contains three integers n, m, k (1 β€ n, m β€ 109; 1 β€ k β€ 2Β·109).
Output
Output a single integer representing the answer. If it is impossible to cut the big chocolate k times, print -1.
Examples
Input
3 4 1
Output
6
Input
6 4 2
Output
8
Input
2 3 4
Output
-1
Note
In the first sample, Jzzhu can cut the chocolate following the picture below:
<image>
In the second sample the optimal division looks like this:
<image>
In the third sample, it's impossible to cut a 2 Γ 3 chocolate 4 times.
Submitted Solution:
```
#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import*
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
ALPHA='abcdefghijklmnopqrstuvwxyz'
M=998244353
EPS=1e-6
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]
#-------------------------code---------------------------#
# vsInput()
r,c,cuts=value()
max_cuts=r+c-2
if(cuts>max_cuts):
print(-1)
else:
print(r*c//(cuts+2-1))
``` | instruction | 0 | 49,201 | 9 | 98,402 |
No | output | 1 | 49,201 | 9 | 98,403 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasiliy spent his vacation in a sanatorium, came back and found that he completely forgot details of his vacation!
Every day there was a breakfast, a dinner and a supper in a dining room of the sanatorium (of course, in this order). The only thing that Vasiliy has now is a card from the dining room contaning notes how many times he had a breakfast, a dinner and a supper (thus, the card contains three integers). Vasiliy could sometimes have missed some meal, for example, he could have had a breakfast and a supper, but a dinner, or, probably, at some days he haven't been at the dining room at all.
Vasiliy doesn't remember what was the time of the day when he arrived to sanatorium (before breakfast, before dinner, before supper or after supper), and the time when he left it (before breakfast, before dinner, before supper or after supper). So he considers any of these options. After Vasiliy arrived to the sanatorium, he was there all the time until he left. Please note, that it's possible that Vasiliy left the sanatorium on the same day he arrived.
According to the notes in the card, help Vasiliy determine the minimum number of meals in the dining room that he could have missed. We shouldn't count as missed meals on the arrival day before Vasiliy's arrival and meals on the departure day after he left.
Input
The only line contains three integers b, d and s (0 β€ b, d, s β€ 1018, b + d + s β₯ 1) β the number of breakfasts, dinners and suppers which Vasiliy had during his vacation in the sanatorium.
Output
Print single integer β the minimum possible number of meals which Vasiliy could have missed during his vacation.
Examples
Input
3 2 1
Output
1
Input
1 0 0
Output
0
Input
1 1 1
Output
0
Input
1000000000000000000 0 1000000000000000000
Output
999999999999999999
Note
In the first sample, Vasiliy could have missed one supper, for example, in case he have arrived before breakfast, have been in the sanatorium for two days (including the day of arrival) and then have left after breakfast on the third day.
In the second sample, Vasiliy could have arrived before breakfast, have had it, and immediately have left the sanatorium, not missing any meal.
In the third sample, Vasiliy could have been in the sanatorium for one day, not missing any meal.
Submitted Solution:
```
a=list(map(int,input().split()))
q,s=max(a),0
for i in a:
if i<q:s+=q-i-1
print(s)
``` | instruction | 0 | 49,326 | 9 | 98,652 |
Yes | output | 1 | 49,326 | 9 | 98,653 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasiliy spent his vacation in a sanatorium, came back and found that he completely forgot details of his vacation!
Every day there was a breakfast, a dinner and a supper in a dining room of the sanatorium (of course, in this order). The only thing that Vasiliy has now is a card from the dining room contaning notes how many times he had a breakfast, a dinner and a supper (thus, the card contains three integers). Vasiliy could sometimes have missed some meal, for example, he could have had a breakfast and a supper, but a dinner, or, probably, at some days he haven't been at the dining room at all.
Vasiliy doesn't remember what was the time of the day when he arrived to sanatorium (before breakfast, before dinner, before supper or after supper), and the time when he left it (before breakfast, before dinner, before supper or after supper). So he considers any of these options. After Vasiliy arrived to the sanatorium, he was there all the time until he left. Please note, that it's possible that Vasiliy left the sanatorium on the same day he arrived.
According to the notes in the card, help Vasiliy determine the minimum number of meals in the dining room that he could have missed. We shouldn't count as missed meals on the arrival day before Vasiliy's arrival and meals on the departure day after he left.
Input
The only line contains three integers b, d and s (0 β€ b, d, s β€ 1018, b + d + s β₯ 1) β the number of breakfasts, dinners and suppers which Vasiliy had during his vacation in the sanatorium.
Output
Print single integer β the minimum possible number of meals which Vasiliy could have missed during his vacation.
Examples
Input
3 2 1
Output
1
Input
1 0 0
Output
0
Input
1 1 1
Output
0
Input
1000000000000000000 0 1000000000000000000
Output
999999999999999999
Note
In the first sample, Vasiliy could have missed one supper, for example, in case he have arrived before breakfast, have been in the sanatorium for two days (including the day of arrival) and then have left after breakfast on the third day.
In the second sample, Vasiliy could have arrived before breakfast, have had it, and immediately have left the sanatorium, not missing any meal.
In the third sample, Vasiliy could have been in the sanatorium for one day, not missing any meal.
Submitted Solution:
```
from sys import stdin, stdout
def main():
A = list(map(int, stdin.readline().strip().split()))
A[:] = sorted(A, reverse = True)
m = max(A) - 1
c = 0
for i in A[1:]:
c += max(0,m - i)
stdout.write(f'{c}')
if __name__ == '__main__':
main()
``` | instruction | 0 | 49,327 | 9 | 98,654 |
Yes | output | 1 | 49,327 | 9 | 98,655 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasiliy spent his vacation in a sanatorium, came back and found that he completely forgot details of his vacation!
Every day there was a breakfast, a dinner and a supper in a dining room of the sanatorium (of course, in this order). The only thing that Vasiliy has now is a card from the dining room contaning notes how many times he had a breakfast, a dinner and a supper (thus, the card contains three integers). Vasiliy could sometimes have missed some meal, for example, he could have had a breakfast and a supper, but a dinner, or, probably, at some days he haven't been at the dining room at all.
Vasiliy doesn't remember what was the time of the day when he arrived to sanatorium (before breakfast, before dinner, before supper or after supper), and the time when he left it (before breakfast, before dinner, before supper or after supper). So he considers any of these options. After Vasiliy arrived to the sanatorium, he was there all the time until he left. Please note, that it's possible that Vasiliy left the sanatorium on the same day he arrived.
According to the notes in the card, help Vasiliy determine the minimum number of meals in the dining room that he could have missed. We shouldn't count as missed meals on the arrival day before Vasiliy's arrival and meals on the departure day after he left.
Input
The only line contains three integers b, d and s (0 β€ b, d, s β€ 1018, b + d + s β₯ 1) β the number of breakfasts, dinners and suppers which Vasiliy had during his vacation in the sanatorium.
Output
Print single integer β the minimum possible number of meals which Vasiliy could have missed during his vacation.
Examples
Input
3 2 1
Output
1
Input
1 0 0
Output
0
Input
1 1 1
Output
0
Input
1000000000000000000 0 1000000000000000000
Output
999999999999999999
Note
In the first sample, Vasiliy could have missed one supper, for example, in case he have arrived before breakfast, have been in the sanatorium for two days (including the day of arrival) and then have left after breakfast on the third day.
In the second sample, Vasiliy could have arrived before breakfast, have had it, and immediately have left the sanatorium, not missing any meal.
In the third sample, Vasiliy could have been in the sanatorium for one day, not missing any meal.
Submitted Solution:
```
b, d, s = map(int, input().split())
def calc(b, d, s):
return max(b, d, s) * 3 - sum((b,d,s))
res = []
for i in range(3):
for j in range(3):
res.append(calc(b - (j > 0), d - (j > 1) - (i > 1), s - (i > 0)))
print(min(res))
``` | instruction | 0 | 49,328 | 9 | 98,656 |
Yes | output | 1 | 49,328 | 9 | 98,657 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasiliy spent his vacation in a sanatorium, came back and found that he completely forgot details of his vacation!
Every day there was a breakfast, a dinner and a supper in a dining room of the sanatorium (of course, in this order). The only thing that Vasiliy has now is a card from the dining room contaning notes how many times he had a breakfast, a dinner and a supper (thus, the card contains three integers). Vasiliy could sometimes have missed some meal, for example, he could have had a breakfast and a supper, but a dinner, or, probably, at some days he haven't been at the dining room at all.
Vasiliy doesn't remember what was the time of the day when he arrived to sanatorium (before breakfast, before dinner, before supper or after supper), and the time when he left it (before breakfast, before dinner, before supper or after supper). So he considers any of these options. After Vasiliy arrived to the sanatorium, he was there all the time until he left. Please note, that it's possible that Vasiliy left the sanatorium on the same day he arrived.
According to the notes in the card, help Vasiliy determine the minimum number of meals in the dining room that he could have missed. We shouldn't count as missed meals on the arrival day before Vasiliy's arrival and meals on the departure day after he left.
Input
The only line contains three integers b, d and s (0 β€ b, d, s β€ 1018, b + d + s β₯ 1) β the number of breakfasts, dinners and suppers which Vasiliy had during his vacation in the sanatorium.
Output
Print single integer β the minimum possible number of meals which Vasiliy could have missed during his vacation.
Examples
Input
3 2 1
Output
1
Input
1 0 0
Output
0
Input
1 1 1
Output
0
Input
1000000000000000000 0 1000000000000000000
Output
999999999999999999
Note
In the first sample, Vasiliy could have missed one supper, for example, in case he have arrived before breakfast, have been in the sanatorium for two days (including the day of arrival) and then have left after breakfast on the third day.
In the second sample, Vasiliy could have arrived before breakfast, have had it, and immediately have left the sanatorium, not missing any meal.
In the third sample, Vasiliy could have been in the sanatorium for one day, not missing any meal.
Submitted Solution:
```
a=input()
a=a.split()
for i in range(0,3):
a[i]=int(a[i])
a.sort()
if a[0]==a[2]:
print(0)
exit()
print(a[2]-a[0]-1+max(0,a[2]-a[1]-1))
``` | instruction | 0 | 49,329 | 9 | 98,658 |
Yes | output | 1 | 49,329 | 9 | 98,659 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasiliy spent his vacation in a sanatorium, came back and found that he completely forgot details of his vacation!
Every day there was a breakfast, a dinner and a supper in a dining room of the sanatorium (of course, in this order). The only thing that Vasiliy has now is a card from the dining room contaning notes how many times he had a breakfast, a dinner and a supper (thus, the card contains three integers). Vasiliy could sometimes have missed some meal, for example, he could have had a breakfast and a supper, but a dinner, or, probably, at some days he haven't been at the dining room at all.
Vasiliy doesn't remember what was the time of the day when he arrived to sanatorium (before breakfast, before dinner, before supper or after supper), and the time when he left it (before breakfast, before dinner, before supper or after supper). So he considers any of these options. After Vasiliy arrived to the sanatorium, he was there all the time until he left. Please note, that it's possible that Vasiliy left the sanatorium on the same day he arrived.
According to the notes in the card, help Vasiliy determine the minimum number of meals in the dining room that he could have missed. We shouldn't count as missed meals on the arrival day before Vasiliy's arrival and meals on the departure day after he left.
Input
The only line contains three integers b, d and s (0 β€ b, d, s β€ 1018, b + d + s β₯ 1) β the number of breakfasts, dinners and suppers which Vasiliy had during his vacation in the sanatorium.
Output
Print single integer β the minimum possible number of meals which Vasiliy could have missed during his vacation.
Examples
Input
3 2 1
Output
1
Input
1 0 0
Output
0
Input
1 1 1
Output
0
Input
1000000000000000000 0 1000000000000000000
Output
999999999999999999
Note
In the first sample, Vasiliy could have missed one supper, for example, in case he have arrived before breakfast, have been in the sanatorium for two days (including the day of arrival) and then have left after breakfast on the third day.
In the second sample, Vasiliy could have arrived before breakfast, have had it, and immediately have left the sanatorium, not missing any meal.
In the third sample, Vasiliy could have been in the sanatorium for one day, not missing any meal.
Submitted Solution:
```
t = list(map(int,input().split()))
a= max(t)
b= min(t)
if a-b<=1:
print(0)
else:
print(a-b-1)
``` | instruction | 0 | 49,330 | 9 | 98,660 |
No | output | 1 | 49,330 | 9 | 98,661 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasiliy spent his vacation in a sanatorium, came back and found that he completely forgot details of his vacation!
Every day there was a breakfast, a dinner and a supper in a dining room of the sanatorium (of course, in this order). The only thing that Vasiliy has now is a card from the dining room contaning notes how many times he had a breakfast, a dinner and a supper (thus, the card contains three integers). Vasiliy could sometimes have missed some meal, for example, he could have had a breakfast and a supper, but a dinner, or, probably, at some days he haven't been at the dining room at all.
Vasiliy doesn't remember what was the time of the day when he arrived to sanatorium (before breakfast, before dinner, before supper or after supper), and the time when he left it (before breakfast, before dinner, before supper or after supper). So he considers any of these options. After Vasiliy arrived to the sanatorium, he was there all the time until he left. Please note, that it's possible that Vasiliy left the sanatorium on the same day he arrived.
According to the notes in the card, help Vasiliy determine the minimum number of meals in the dining room that he could have missed. We shouldn't count as missed meals on the arrival day before Vasiliy's arrival and meals on the departure day after he left.
Input
The only line contains three integers b, d and s (0 β€ b, d, s β€ 1018, b + d + s β₯ 1) β the number of breakfasts, dinners and suppers which Vasiliy had during his vacation in the sanatorium.
Output
Print single integer β the minimum possible number of meals which Vasiliy could have missed during his vacation.
Examples
Input
3 2 1
Output
1
Input
1 0 0
Output
0
Input
1 1 1
Output
0
Input
1000000000000000000 0 1000000000000000000
Output
999999999999999999
Note
In the first sample, Vasiliy could have missed one supper, for example, in case he have arrived before breakfast, have been in the sanatorium for two days (including the day of arrival) and then have left after breakfast on the third day.
In the second sample, Vasiliy could have arrived before breakfast, have had it, and immediately have left the sanatorium, not missing any meal.
In the third sample, Vasiliy could have been in the sanatorium for one day, not missing any meal.
Submitted Solution:
```
b, d, s = input().split()
b, d, s = int(b), int(d), int(s)
arr = [b, d, s]
res = []
res.append(sum([b, d, s]))
res.append(sum([b, d, s + 1]))
res.append(sum([b, d + 1, s + 1]))
res.append(sum([b + 1, d, s]))
res.append(sum([b + 1, d, s + 1]))
res.append(sum([b + 1, d + 1, s]))
print(3 * max([b, d, s]) - max(res))
``` | instruction | 0 | 49,331 | 9 | 98,662 |
No | output | 1 | 49,331 | 9 | 98,663 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasiliy spent his vacation in a sanatorium, came back and found that he completely forgot details of his vacation!
Every day there was a breakfast, a dinner and a supper in a dining room of the sanatorium (of course, in this order). The only thing that Vasiliy has now is a card from the dining room contaning notes how many times he had a breakfast, a dinner and a supper (thus, the card contains three integers). Vasiliy could sometimes have missed some meal, for example, he could have had a breakfast and a supper, but a dinner, or, probably, at some days he haven't been at the dining room at all.
Vasiliy doesn't remember what was the time of the day when he arrived to sanatorium (before breakfast, before dinner, before supper or after supper), and the time when he left it (before breakfast, before dinner, before supper or after supper). So he considers any of these options. After Vasiliy arrived to the sanatorium, he was there all the time until he left. Please note, that it's possible that Vasiliy left the sanatorium on the same day he arrived.
According to the notes in the card, help Vasiliy determine the minimum number of meals in the dining room that he could have missed. We shouldn't count as missed meals on the arrival day before Vasiliy's arrival and meals on the departure day after he left.
Input
The only line contains three integers b, d and s (0 β€ b, d, s β€ 1018, b + d + s β₯ 1) β the number of breakfasts, dinners and suppers which Vasiliy had during his vacation in the sanatorium.
Output
Print single integer β the minimum possible number of meals which Vasiliy could have missed during his vacation.
Examples
Input
3 2 1
Output
1
Input
1 0 0
Output
0
Input
1 1 1
Output
0
Input
1000000000000000000 0 1000000000000000000
Output
999999999999999999
Note
In the first sample, Vasiliy could have missed one supper, for example, in case he have arrived before breakfast, have been in the sanatorium for two days (including the day of arrival) and then have left after breakfast on the third day.
In the second sample, Vasiliy could have arrived before breakfast, have had it, and immediately have left the sanatorium, not missing any meal.
In the third sample, Vasiliy could have been in the sanatorium for one day, not missing any meal.
Submitted Solution:
```
read = lambda: map(int, input().split())
b, d, s = read()
A = (0, 0, 0), (1, 0, 0), (1, 1, 0)
B = (0, 0, 0), (0, 0, 1), (0, 1, 1)
ans = float('inf')
if sorted((b, d, s)) in ((0, 0, 1), (0, 1, 1), (1, 1, 1)):
print(0)
exit()
for x1, y1, z1 in A:
for x2, y2, z2 in B:
x, y, z = x1 + x2, y1 + y2, z1 + z2
if x + y + z > b + d + s or b < x or d < y or s < z: continue
k = max(b - x, d - y, s - z)
cur = max(k + x - b, k + y - d, k + z - s)
ans = min(ans, cur)
print(ans)
``` | instruction | 0 | 49,332 | 9 | 98,664 |
No | output | 1 | 49,332 | 9 | 98,665 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasiliy spent his vacation in a sanatorium, came back and found that he completely forgot details of his vacation!
Every day there was a breakfast, a dinner and a supper in a dining room of the sanatorium (of course, in this order). The only thing that Vasiliy has now is a card from the dining room contaning notes how many times he had a breakfast, a dinner and a supper (thus, the card contains three integers). Vasiliy could sometimes have missed some meal, for example, he could have had a breakfast and a supper, but a dinner, or, probably, at some days he haven't been at the dining room at all.
Vasiliy doesn't remember what was the time of the day when he arrived to sanatorium (before breakfast, before dinner, before supper or after supper), and the time when he left it (before breakfast, before dinner, before supper or after supper). So he considers any of these options. After Vasiliy arrived to the sanatorium, he was there all the time until he left. Please note, that it's possible that Vasiliy left the sanatorium on the same day he arrived.
According to the notes in the card, help Vasiliy determine the minimum number of meals in the dining room that he could have missed. We shouldn't count as missed meals on the arrival day before Vasiliy's arrival and meals on the departure day after he left.
Input
The only line contains three integers b, d and s (0 β€ b, d, s β€ 1018, b + d + s β₯ 1) β the number of breakfasts, dinners and suppers which Vasiliy had during his vacation in the sanatorium.
Output
Print single integer β the minimum possible number of meals which Vasiliy could have missed during his vacation.
Examples
Input
3 2 1
Output
1
Input
1 0 0
Output
0
Input
1 1 1
Output
0
Input
1000000000000000000 0 1000000000000000000
Output
999999999999999999
Note
In the first sample, Vasiliy could have missed one supper, for example, in case he have arrived before breakfast, have been in the sanatorium for two days (including the day of arrival) and then have left after breakfast on the third day.
In the second sample, Vasiliy could have arrived before breakfast, have had it, and immediately have left the sanatorium, not missing any meal.
In the third sample, Vasiliy could have been in the sanatorium for one day, not missing any meal.
Submitted Solution:
```
b, l, d = [int(i) for i in input().split()]
min_val = min([b, l, d])
b, l, d = b-min_val, l-min_val, d-min_val
if l==b and l>d:
l -= 1
b -= 1
elif b>l and b>=d:
b -= 1
if l==d and l>b:
l -= 1
d -= 1
elif d>l and d>=b:
d -= 1
a = [b, l, d]
a = [i if i>=0 else 0 for i in a]
# print(a)
ans = (3*max(a)) - sum(a)
print(ans)
``` | instruction | 0 | 49,333 | 9 | 98,666 |
No | output | 1 | 49,333 | 9 | 98,667 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arkady wants to have a dinner. He has just returned from a shop where he has bought a semifinished cutlet. He only needs to fry it. The cutlet should be fried for 2n seconds, in particular, it should be fried for n seconds on one side and n seconds on the other side. Arkady has already got a frying pan and turn on fire, but understood that maybe he won't be able to flip the cutlet exactly after n seconds after the beginning of cooking.
Arkady is too busy with sorting sticker packs in his favorite messenger and can flip the cutlet only in some periods of time. Namely, there are k periods of time in which he can do it, the i-th of them is an interval of time from li seconds after he starts cooking till ri seconds, inclusive. Arkady decided that it's not required to flip the cutlet exactly in the middle of cooking, instead, he will flip it several times in such a way that the cutlet will be fried exactly n seconds on one side and n seconds on the other side in total.
Help Arkady and find out if it's possible for him to cook the cutlet, if he is able to flip the cutlet only in given periods of time; and if yes, find the minimum number of flips he needs to cook the cutlet.
Input
The first line contains two integers n and k (1 β€ n β€ 100 000, 1 β€ k β€ 100) β the number of seconds the cutlet should be cooked on each side and number of periods of time in which Arkady can flip it.
The next k lines contain descriptions of these intervals. Each line contains two integers li and ri (0 β€ li β€ ri β€ 2Β·n), meaning that Arkady can flip the cutlet in any moment starting from li seconds after the beginning of cooking and finishing at ri seconds after beginning of cooking. In particular, if li = ri then Arkady can flip the cutlet only in the moment li = ri. It's guaranteed that li > ri - 1 for all 2 β€ i β€ k.
Output
Output "Hungry" if Arkady won't be able to fry the cutlet for exactly n seconds on one side and exactly n seconds on the other side.
Otherwise, output "Full" in the first line, and the minimum number of times he should flip the cutlet in the second line.
Examples
Input
10 2
3 5
11 13
Output
Full
2
Input
10 3
3 5
9 10
11 13
Output
Full
1
Input
20 1
3 19
Output
Hungry
Note
In the first example Arkady should flip the cutlet in time moment 3 seconds after he starts cooking and in time moment 13 seconds after he starts cooking.
In the second example, Arkady can flip the cutlet at 10 seconds after he starts cooking.
Submitted Solution:
```
import sys, math
#f = open('input/input_0', 'r')
f = sys.stdin
class BIT:
def __init__(self, data_size, init_val=0):
self.data_size = data_size
i = 0
while ((1 << i) < data_size):
i += 1
self.tree_size = (1 << (i+1))
self.base = (1 << i)
self.b = [init_val] * self.tree_size
def update(self, p, val, func):
p = self.base + p
while (p > 0):
self.b[p] = func(self.b[p], val)
p = p >> 1
def update_section(self, l, r, val, func):
l = self.base + l
r = self.base + r
while (l <= r):
if (l == r):
self.b[l] = func(self.b[l], val)
break
if ((l&1) == 1):
self.b[l] = func(self.b[l], val)
l += 1
if ((r&1) == 0):
self.b[r] = func(self.b[r], val)
r -= 1
l = l >> 1
r = r >> 1
def get_one(self, p, start_val, func):
p = self.base + p
val = start_val
while (p > 0):
val = func(self.b[p], val)
p = p >> 1
return val
def get_section(self, l, r, start_val, func):
l = self.base + l
r = self.base + r
val = start_val
while (l <= r):
if (l == r):
val = func(self.b[l], val)
break
if ((l&1) == 1):
val = func(self.b[l], val)
l += 1
if ((r&1) == 0):
val = func(self.b[r], val)
r -= 1
l = l >> 1
r = r >> 1
return val
def get(self, p):
return self.b[self.base + p]
N, K = map(int, f.readline().split())
MAX_VAL = 10000000
on_bit = BIT(N, MAX_VAL)
off_bit = BIT(N, MAX_VAL)
def just_set(val_in_bit, new_val):
return new_val
def smaller(val_in_bit, new_val):
return min(val_in_bit, new_val)
on_bit.update(0, 0, just_set)
off_bit.update(0, 0, just_set)
last = 0
for i in range(K):
l, r = map(int, f.readline().split())
new_on_bit = BIT(N, MAX_VAL)
new_off_bit = BIT(N, MAX_VAL)
for j in range(N):
on_val = MAX_VAL
if j >= (r-last):
on_val = min(on_val, on_bit.get(j-(r-last)))
start = max(0, j-(r-l))
end = j
on_val = min(on_val, off_bit.get_section(start, end, MAX_VAL, smaller) + 1)
if on_val < MAX_VAL:
new_on_bit.update(j, on_val, just_set)
off_val = off_bit.get(j)
if j-(l-last) >= 0:
start = max(j-(r-last), 0)
end = j-(l-last)
off_val = min(off_val, on_bit.get_section(start, end, MAX_VAL, smaller) + 1)
if off_val < MAX_VAL:
new_off_bit.update(j, off_val, just_set)
on_bit = new_on_bit
off_bit = new_off_bit
last = r
result = min(on_bit.get(N - (2*N - last)), off_bit.get(N))
if result == MAX_VAL:
print("Hungry")
else:
print("Full")
print(result)
``` | instruction | 0 | 49,363 | 9 | 98,726 |
No | output | 1 | 49,363 | 9 | 98,727 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arkady wants to have a dinner. He has just returned from a shop where he has bought a semifinished cutlet. He only needs to fry it. The cutlet should be fried for 2n seconds, in particular, it should be fried for n seconds on one side and n seconds on the other side. Arkady has already got a frying pan and turn on fire, but understood that maybe he won't be able to flip the cutlet exactly after n seconds after the beginning of cooking.
Arkady is too busy with sorting sticker packs in his favorite messenger and can flip the cutlet only in some periods of time. Namely, there are k periods of time in which he can do it, the i-th of them is an interval of time from li seconds after he starts cooking till ri seconds, inclusive. Arkady decided that it's not required to flip the cutlet exactly in the middle of cooking, instead, he will flip it several times in such a way that the cutlet will be fried exactly n seconds on one side and n seconds on the other side in total.
Help Arkady and find out if it's possible for him to cook the cutlet, if he is able to flip the cutlet only in given periods of time; and if yes, find the minimum number of flips he needs to cook the cutlet.
Input
The first line contains two integers n and k (1 β€ n β€ 100 000, 1 β€ k β€ 100) β the number of seconds the cutlet should be cooked on each side and number of periods of time in which Arkady can flip it.
The next k lines contain descriptions of these intervals. Each line contains two integers li and ri (0 β€ li β€ ri β€ 2Β·n), meaning that Arkady can flip the cutlet in any moment starting from li seconds after the beginning of cooking and finishing at ri seconds after beginning of cooking. In particular, if li = ri then Arkady can flip the cutlet only in the moment li = ri. It's guaranteed that li > ri - 1 for all 2 β€ i β€ k.
Output
Output "Hungry" if Arkady won't be able to fry the cutlet for exactly n seconds on one side and exactly n seconds on the other side.
Otherwise, output "Full" in the first line, and the minimum number of times he should flip the cutlet in the second line.
Examples
Input
10 2
3 5
11 13
Output
Full
2
Input
10 3
3 5
9 10
11 13
Output
Full
1
Input
20 1
3 19
Output
Hungry
Note
In the first example Arkady should flip the cutlet in time moment 3 seconds after he starts cooking and in time moment 13 seconds after he starts cooking.
In the second example, Arkady can flip the cutlet at 10 seconds after he starts cooking.
Submitted Solution:
```
R=lambda:map(int,input().split())
n, k = R()
old_right = 0
a = []
for i in range(k):
l, r = R()
a.append(l - old_right)
a.append(r - l)
old_right = r
a.append(2*n - old_right)
sums =[[0,0,0]]
for i in range(len(a)):
new = []
for x in sums:
if x[2] % 2 == 0:
new += [[x[0] + a[i], x[1], x[2]]]
new +=[ [x[0] , x[1] + a[i], x[2] + 1]]
else:
new += [[x[0] + a[i], x[1], x[2] + 1]]
new += [[x[0] , x[1] + a[i], x[2]]]
sums = new
best = float('inf')
flag = False
for i in range(len(sums)):
if sums[i][0] == n and sums[i][2] < best:
best = sums[i][2]
flag = True
if flag:
print("Full")
print(best)
else:
print("Hungry")
``` | instruction | 0 | 49,364 | 9 | 98,728 |
No | output | 1 | 49,364 | 9 | 98,729 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.