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.
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't.
The mouse is in a bit of a hurry, though, so once she enters the cake from its northwest corner (the top left cell in the input data), she will only go east (right) or south (down), until she reaches the southeast corner (the bottom right cell). She will eat every berry in the squares she passes through, but not in the other squares.
The mouse tries to choose her path so as to maximize the number of berries consumed. However, her haste and hunger might be clouding her judgement, leading her to suboptimal decisions...
Input
The first line of input contains two integers H and W (1 β€ H, W β€ 5), separated by a space, β the height and the width of the cake.
The next H lines contain a string of W characters each, representing the squares of the cake in that row: '.' represents an empty square, and '*' represents a square with a berry.
Output
Output the number of berries the mouse will eat following her strategy.
Examples
Input
4 3
*..
.*.
..*
...
Output
3
Input
4 4
.*..
*...
...*
..*.
Output
2
Input
3 4
..**
*...
....
Output
1
Input
5 5
..*..
.....
**...
**...
**...
Output
1
Submitted Solution:
```
#Code by Sounak, IIESTS
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
#sys.setrecursionlimit(300000)
#threading.stack_size(10**8)
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")
#-------------------------------------------------------------------------
#mod = 9223372036854775807
class SegmentTree:
def __init__(self, data, default=0, func=lambda a, b: max(a,b)):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
class SegmentTree1:
def __init__(self, data, default=10**6, func=lambda a, b: min(a,b)):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (2 * _size)
self.data[_size:_size + self._len] = data
for i in reversed(range(_size)):
self.data[i] = func(self.data[i + i], self.data[i + i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
if start == stop:
return self.__getitem__(start)
stop += 1
start += self._size
stop += self._size
res = self._default
while start < stop:
if start & 1:
res = self._func(res, self.data[start])
start += 1
if stop & 1:
stop -= 1
res = self._func(res, self.data[stop])
start >>= 1
stop >>= 1
return res
def __repr__(self):
return "SegmentTree({0})".format(self.data)
MOD=10**9+7
class Factorial:
def __init__(self, MOD):
self.MOD = MOD
self.factorials = [1, 1]
self.invModulos = [0, 1]
self.invFactorial_ = [1, 1]
def calc(self, n):
if n <= -1:
print("Invalid argument to calculate n!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.factorials):
return self.factorials[n]
nextArr = [0] * (n + 1 - len(self.factorials))
initialI = len(self.factorials)
prev = self.factorials[-1]
m = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = prev * i % m
self.factorials += nextArr
return self.factorials[n]
def inv(self, n):
if n <= -1:
print("Invalid argument to calculate n^(-1)")
print("n must be non-negative value. But the argument was " + str(n))
exit()
p = self.MOD
pi = n % p
if pi < len(self.invModulos):
return self.invModulos[pi]
nextArr = [0] * (n + 1 - len(self.invModulos))
initialI = len(self.invModulos)
for i in range(initialI, min(p, n + 1)):
next = -self.invModulos[p % i] * (p // i) % p
self.invModulos.append(next)
return self.invModulos[pi]
def invFactorial(self, n):
if n <= -1:
print("Invalid argument to calculate (n^(-1))!")
print("n must be non-negative value. But the argument was " + str(n))
exit()
if n < len(self.invFactorial_):
return self.invFactorial_[n]
self.inv(n) # To make sure already calculated n^-1
nextArr = [0] * (n + 1 - len(self.invFactorial_))
initialI = len(self.invFactorial_)
prev = self.invFactorial_[-1]
p = self.MOD
for i in range(initialI, n + 1):
prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p
self.invFactorial_ += nextArr
return self.invFactorial_[n]
class Combination:
def __init__(self, MOD):
self.MOD = MOD
self.factorial = Factorial(MOD)
def ncr(self, n, k):
if k < 0 or n < k:
return 0
k = min(k, n - k)
f = self.factorial
return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod=10**9+7
omod=998244353
#-------------------------------------------------------------------------
prime = [True for i in range(10)]
pp=[0]*10
def SieveOfEratosthenes(n=10):
p = 2
c=0
while (p * p <= n):
if (prime[p] == True):
c+=1
for i in range(p, n+1, p):
pp[i]+=1
prime[i] = False
p += 1
#---------------------------------Binary Search------------------------------------------
def binarySearch(arr, n, key):
left = 0
right = n-1
mid = 0
res=0
while (left <= right):
mid = (right + left)//2
if (arr[mid][0] > key):
right = mid-1
else:
res=mid
left = mid + 1
return res
#---------------------------------running code------------------------------------------
n,m=map(int,input().split())
a=[]
for i in range (n):
a.append(list(input()))
dp=[[[0,0] for j in range (m)]for i in range (n)] #right,bottom
for i in range (n-1,-1,-1):
for j in range (m-1,-1,-1):
if j==m-1:
dp[i][j][0]=1000
else:
if a[i][j+1]=='*':
dp[i][j][0]=1
else:
dp[i][j][0]=min(dp[i][j+1])+1
if i==n-1:
dp[i][j][1]=1000
else:
if a[i+1][j]=='*':
dp[i][j][1]=1
else:
dp[i][j][1]=min(dp[i+1][j])+1
res=0
'''
for i in dp:
print(i)
'''
x,y=0,0
while x<n and y<m:
if a[x][y]=='*':
res+=1
#print(x,y)
m1=min(dp[x][y])
if m1==dp[x][y][0]:
y+=1
else:
x+=1
print(res)
``` | instruction | 0 | 52,463 | 9 | 104,926 |
Yes | output | 1 | 52,463 | 9 | 104,927 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't.
The mouse is in a bit of a hurry, though, so once she enters the cake from its northwest corner (the top left cell in the input data), she will only go east (right) or south (down), until she reaches the southeast corner (the bottom right cell). She will eat every berry in the squares she passes through, but not in the other squares.
The mouse tries to choose her path so as to maximize the number of berries consumed. However, her haste and hunger might be clouding her judgement, leading her to suboptimal decisions...
Input
The first line of input contains two integers H and W (1 β€ H, W β€ 5), separated by a space, β the height and the width of the cake.
The next H lines contain a string of W characters each, representing the squares of the cake in that row: '.' represents an empty square, and '*' represents a square with a berry.
Output
Output the number of berries the mouse will eat following her strategy.
Examples
Input
4 3
*..
.*.
..*
...
Output
3
Input
4 4
.*..
*...
...*
..*.
Output
2
Input
3 4
..**
*...
....
Output
1
Input
5 5
..*..
.....
**...
**...
**...
Output
1
Submitted Solution:
```
n, m = map(int, input().split())
a = [input() for i in range(n)]
count = 0
i = 0
j = 0
for k in range(n + m - 1):
if a[i][j] == '*':
count += 1
look_down = -1
look_right = -1
for q in range(i + 1, n):
if a[q][j] == '*':
look_down = q
for q in range(j + 1, m):
if a[i][q] == '*':
look_right = q
if look_down == -1 and look_right == -1 and j != m - 1:
j += 1
elif look_down == -1 and j != m - 1:
j += 1
elif look_right == -1 and i != n - 1:
i += 1
elif look_down - i >= look_right - j and j != m - 1:
j += 1
else:
i += 1
print(count)
``` | instruction | 0 | 52,464 | 9 | 104,928 |
Yes | output | 1 | 52,464 | 9 | 104,929 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't.
The mouse is in a bit of a hurry, though, so once she enters the cake from its northwest corner (the top left cell in the input data), she will only go east (right) or south (down), until she reaches the southeast corner (the bottom right cell). She will eat every berry in the squares she passes through, but not in the other squares.
The mouse tries to choose her path so as to maximize the number of berries consumed. However, her haste and hunger might be clouding her judgement, leading her to suboptimal decisions...
Input
The first line of input contains two integers H and W (1 β€ H, W β€ 5), separated by a space, β the height and the width of the cake.
The next H lines contain a string of W characters each, representing the squares of the cake in that row: '.' represents an empty square, and '*' represents a square with a berry.
Output
Output the number of berries the mouse will eat following her strategy.
Examples
Input
4 3
*..
.*.
..*
...
Output
3
Input
4 4
.*..
*...
...*
..*.
Output
2
Input
3 4
..**
*...
....
Output
1
Input
5 5
..*..
.....
**...
**...
**...
Output
1
Submitted Solution:
```
h, w = map(int, input().split())
m = []
for i in range(h):
m += [list(input())]
x, y = 0, 0
r = 0
if m[x][y] == '*': r += 1
while x < h - 1 or y < w - 1:
if y < w - 1 and m[x][y + 1] == '*':
r += 1
y += 1
elif x < h - 1 and m[x + 1][y] == '*':
r += 1
x += 1
elif y < w - 1:
y += 1
else:
x += 1
print(r)
``` | instruction | 0 | 52,465 | 9 | 104,930 |
Yes | output | 1 | 52,465 | 9 | 104,931 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't.
The mouse is in a bit of a hurry, though, so once she enters the cake from its northwest corner (the top left cell in the input data), she will only go east (right) or south (down), until she reaches the southeast corner (the bottom right cell). She will eat every berry in the squares she passes through, but not in the other squares.
The mouse tries to choose her path so as to maximize the number of berries consumed. However, her haste and hunger might be clouding her judgement, leading her to suboptimal decisions...
Input
The first line of input contains two integers H and W (1 β€ H, W β€ 5), separated by a space, β the height and the width of the cake.
The next H lines contain a string of W characters each, representing the squares of the cake in that row: '.' represents an empty square, and '*' represents a square with a berry.
Output
Output the number of berries the mouse will eat following her strategy.
Examples
Input
4 3
*..
.*.
..*
...
Output
3
Input
4 4
.*..
*...
...*
..*.
Output
2
Input
3 4
..**
*...
....
Output
1
Input
5 5
..*..
.....
**...
**...
**...
Output
1
Submitted Solution:
```
H, W = map(int, input().split())
cake = [[False] * W for i in range(H)]
for i in range(H):
s = input()
for j in range(W):
if s[j] == '*':
cake[i][j] = True
x, y = 0, 0
ans = 0
while x < H and y < W:
if cake[x][y]:
ans += 1
if y < W - 1 and cake[x][y+1]:
y += 1
continue
if x < H - 1 and cake[x+1][y]:
x += 1
continue
if y < W - 1:
y += 1
continue
elif x < H - 1:
x += 1
continue
if x == H - 1 and y == W - 1:
break
print(ans)
``` | instruction | 0 | 52,466 | 9 | 104,932 |
Yes | output | 1 | 52,466 | 9 | 104,933 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't.
The mouse is in a bit of a hurry, though, so once she enters the cake from its northwest corner (the top left cell in the input data), she will only go east (right) or south (down), until she reaches the southeast corner (the bottom right cell). She will eat every berry in the squares she passes through, but not in the other squares.
The mouse tries to choose her path so as to maximize the number of berries consumed. However, her haste and hunger might be clouding her judgement, leading her to suboptimal decisions...
Input
The first line of input contains two integers H and W (1 β€ H, W β€ 5), separated by a space, β the height and the width of the cake.
The next H lines contain a string of W characters each, representing the squares of the cake in that row: '.' represents an empty square, and '*' represents a square with a berry.
Output
Output the number of berries the mouse will eat following her strategy.
Examples
Input
4 3
*..
.*.
..*
...
Output
3
Input
4 4
.*..
*...
...*
..*.
Output
2
Input
3 4
..**
*...
....
Output
1
Input
5 5
..*..
.....
**...
**...
**...
Output
1
Submitted Solution:
```
from itertools import permutations
h, w = map(int, input().split())
s = [input() for _ in range(h)]
ans = 0
a = []
for i in range(h - 1):
a.append(1)
for i in range(w - 1):
a.append(0)
for v in permutations(a, h + w - 2):
nowi, nowj = 0, 0
tmp = 0
prev = 0
if s[nowi][nowj] == '*':
tmp += 1
prev = 1
f = 1
for i in range(h + w - 2):
if v[i] == 1:
nowi += 1
else:
nowj += 1
if s[nowi][nowj] == '*' and prev:
f = 0
break
if s[nowi][nowj] == '*':
prev = 1
tmp += 1
else:
prev = 0
if f:
ans = max(ans, tmp)
print(ans)
``` | instruction | 0 | 52,467 | 9 | 104,934 |
No | output | 1 | 52,467 | 9 | 104,935 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't.
The mouse is in a bit of a hurry, though, so once she enters the cake from its northwest corner (the top left cell in the input data), she will only go east (right) or south (down), until she reaches the southeast corner (the bottom right cell). She will eat every berry in the squares she passes through, but not in the other squares.
The mouse tries to choose her path so as to maximize the number of berries consumed. However, her haste and hunger might be clouding her judgement, leading her to suboptimal decisions...
Input
The first line of input contains two integers H and W (1 β€ H, W β€ 5), separated by a space, β the height and the width of the cake.
The next H lines contain a string of W characters each, representing the squares of the cake in that row: '.' represents an empty square, and '*' represents a square with a berry.
Output
Output the number of berries the mouse will eat following her strategy.
Examples
Input
4 3
*..
.*.
..*
...
Output
3
Input
4 4
.*..
*...
...*
..*.
Output
2
Input
3 4
..**
*...
....
Output
1
Input
5 5
..*..
.....
**...
**...
**...
Output
1
Submitted Solution:
```
m,n=map(int,input().split())
A=[input()for _ in range(m)]
S=A[0][0]=='*'
i,j=0,0
while i<m-1 or j<n-1:
if j==n-1or i<m-1and A[i+1][j]=='*':i+=1
else:j+=1
S+=int(A[i][j]=='*')
print(S)
``` | instruction | 0 | 52,468 | 9 | 104,936 |
No | output | 1 | 52,468 | 9 | 104,937 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't.
The mouse is in a bit of a hurry, though, so once she enters the cake from its northwest corner (the top left cell in the input data), she will only go east (right) or south (down), until she reaches the southeast corner (the bottom right cell). She will eat every berry in the squares she passes through, but not in the other squares.
The mouse tries to choose her path so as to maximize the number of berries consumed. However, her haste and hunger might be clouding her judgement, leading her to suboptimal decisions...
Input
The first line of input contains two integers H and W (1 β€ H, W β€ 5), separated by a space, β the height and the width of the cake.
The next H lines contain a string of W characters each, representing the squares of the cake in that row: '.' represents an empty square, and '*' represents a square with a berry.
Output
Output the number of berries the mouse will eat following her strategy.
Examples
Input
4 3
*..
.*.
..*
...
Output
3
Input
4 4
.*..
*...
...*
..*.
Output
2
Input
3 4
..**
*...
....
Output
1
Input
5 5
..*..
.....
**...
**...
**...
Output
1
Submitted Solution:
```
temp = [int(s) for s in input().split(" ")]
H = temp[0]
W = temp[1]
S = 0
T = -1
for i in range(H):
test = input()
for j in range(W):
if test[j] == '*':
if (T == -1) or (j == T-1) or (j == T+1):
T = j
S += 1
break
print(S)
``` | instruction | 0 | 52,469 | 9 | 104,938 |
No | output | 1 | 52,469 | 9 | 104,939 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A mouse encountered a nice big cake and decided to take a walk across it, eating the berries on top of the cake on its way. The cake is rectangular, neatly divided into squares; some of the squares have a berry in them, and some don't.
The mouse is in a bit of a hurry, though, so once she enters the cake from its northwest corner (the top left cell in the input data), she will only go east (right) or south (down), until she reaches the southeast corner (the bottom right cell). She will eat every berry in the squares she passes through, but not in the other squares.
The mouse tries to choose her path so as to maximize the number of berries consumed. However, her haste and hunger might be clouding her judgement, leading her to suboptimal decisions...
Input
The first line of input contains two integers H and W (1 β€ H, W β€ 5), separated by a space, β the height and the width of the cake.
The next H lines contain a string of W characters each, representing the squares of the cake in that row: '.' represents an empty square, and '*' represents a square with a berry.
Output
Output the number of berries the mouse will eat following her strategy.
Examples
Input
4 3
*..
.*.
..*
...
Output
3
Input
4 4
.*..
*...
...*
..*.
Output
2
Input
3 4
..**
*...
....
Output
1
Input
5 5
..*..
.....
**...
**...
**...
Output
1
Submitted Solution:
```
h,w = map(int, input().split())
g = []
for i in range(h):
gi = input()
g.append(gi)
ans = 0
x,y = 0,0
while x < w-1 or y < h-1:
if g[y][x] == '*':
ans += 1
xdist,ydist = -1,-1
if x < w-1:
xi = x+1
while g[y][xi] == '.':
if xi >= w-1:
break
xi+=1
if g[y][xi] == '*':
xdist = xi-x
if y < h-1:
yi = y+1
while g[yi][x] == '.':
if yi >= h-1:
break
yi+=1
if g[yi][x] == '*':
ydist = yi-y
if ydist != -1 and (xdist == -1 or ydist < xdist):
y += ydist
elif xdist != -1:
x += xdist
elif x < w-1:
x += 1
else:
y += 1
print(ans)
``` | instruction | 0 | 52,470 | 9 | 104,940 |
No | output | 1 | 52,470 | 9 | 104,941 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You may have heard of the pie rule before. It states that if two people wish to fairly share a slice of pie, one person should cut the slice in half, and the other person should choose who gets which slice. Alice and Bob have many slices of pie, and rather than cutting the slices in half, each individual slice will be eaten by just one person.
The way Alice and Bob decide who eats each slice is as follows. First, the order in which the pies are to be handed out is decided. There is a special token called the "decider" token, initially held by Bob. Until all the pie is handed out, whoever has the decider token will give the next slice of pie to one of the participants, and the decider token to the other participant. They continue until no slices of pie are left.
All of the slices are of excellent quality, so each participant obviously wants to maximize the total amount of pie they get to eat. Assuming both players make their decisions optimally, how much pie will each participant receive?
Input
Input will begin with an integer N (1 β€ N β€ 50), the number of slices of pie.
Following this is a line with N integers indicating the sizes of the slices (each between 1 and 100000, inclusive), in the order in which they must be handed out.
Output
Print two integers. First, the sum of the sizes of slices eaten by Alice, then the sum of the sizes of the slices eaten by Bob, assuming both players make their decisions optimally.
Examples
Input
3
141 592 653
Output
653 733
Input
5
10 21 10 21 10
Output
31 41
Note
In the first example, Bob takes the size 141 slice for himself and gives the decider token to Alice. Then Alice gives the size 592 slice to Bob and keeps the decider token for herself, so that she can then give the size 653 slice to herself. | instruction | 0 | 52,757 | 9 | 105,514 |
Tags: dp, games
Correct Solution:
```
import os
import sys
from io import BytesIO, IOBase
import math
from queue import Queue
import itertools
import bisect
import heapq
#sys.setrecursionlimit(100000)
#^^^TAKE CARE FOR MEMORY LIMIT^^^
def main():
pass
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")
def binary(n):
return (bin(n).replace("0b", ""))
def decimal(s):
return (int(s, 2))
def pow2(n):
p = 0
while (n > 1):
n //= 2
p += 1
return (p)
def primeFactors(n):
l = []
while n % 2 == 0:
l.append(2)
n = n / 2
for i in range(3, int(math.sqrt(n)) + 1, 2):
while n % i == 0:
l.append(i)
n = n / i
if n > 2:
l.append(int(n))
return (l)
def isPrime(n):
if (n == 1):
return (False)
else:
root = int(n ** 0.5)
root += 1
for i in range(2, root):
if (n % i == 0):
return (False)
return (True)
def maxPrimeFactors(n):
maxPrime = -1
while n % 2 == 0:
maxPrime = 2
n >>= 1
for i in range(3, int(math.sqrt(n)) + 1, 2):
while n % i == 0:
maxPrime = i
n = n / i
if n > 2:
maxPrime = n
return int(maxPrime)
def countcon(s, i):
c = 0
ch = s[i]
for i in range(i, len(s)):
if (s[i] == ch):
c += 1
else:
break
return (c)
def lis(arr):
n = len(arr)
lis = [1] * n
for i in range(1, n):
for j in range(0, i):
if arr[i] > arr[j] and lis[i] < lis[j] + 1:
lis[i] = lis[j] + 1
maximum = 0
for i in range(n):
maximum = max(maximum, lis[i])
return maximum
def isSubSequence(str1, str2):
m = len(str1)
n = len(str2)
j = 0
i = 0
while j < m and i < n:
if str1[j] == str2[i]:
j = j + 1
i = i + 1
return j == m
def maxfac(n):
root = int(n ** 0.5)
for i in range(2, root + 1):
if (n % i == 0):
return (n // i)
return (n)
def p2(n):
c=0
while(n%2==0):
n//=2
c+=1
return c
def seive(n):
primes=[True]*(n+1)
primes[1]=primes[0]=False
for i in range(2,n+1):
if(primes[i]):
for j in range(i+i,n+1,i):
primes[j]=False
p=[]
for i in range(0,n+1):
if(primes[i]):
p.append(i)
return(p)
def ncr(n, r, p):
num = den = 1
for i in range(r):
num = (num * (n - i)) % p
den = (den * (i + 1)) % p
return (num * pow(den,
p - 2, p)) % p
def denofactinverse(n,m):
fac=1
for i in range(1,n+1):
fac=(fac*i)%m
return (pow(fac,m-2,m))
def numofact(n,m):
fac=1
for i in range(1,n+1):
fac=(fac*i)%m
return(fac)
def sod(n):
s=0
while(n>0):
s+=n%10
n//=10
return s
n=int(input())
l=list(map(int,input().split()))
dp=[[0]*n for i in range(0,2)]
dp[1][-1]=l[-1]
#dp[0][-1]=0
for i in range(n-2,-1,-1):
dp[1][i]=max(l[i]+dp[0][i+1],dp[1][i+1])
dp[0][i]=min(l[i]+dp[0][i+1],dp[1][i+1])
bob=max(dp[1][0],dp[0][0])
print(sum(l)-bob,bob)
``` | output | 1 | 52,757 | 9 | 105,515 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You may have heard of the pie rule before. It states that if two people wish to fairly share a slice of pie, one person should cut the slice in half, and the other person should choose who gets which slice. Alice and Bob have many slices of pie, and rather than cutting the slices in half, each individual slice will be eaten by just one person.
The way Alice and Bob decide who eats each slice is as follows. First, the order in which the pies are to be handed out is decided. There is a special token called the "decider" token, initially held by Bob. Until all the pie is handed out, whoever has the decider token will give the next slice of pie to one of the participants, and the decider token to the other participant. They continue until no slices of pie are left.
All of the slices are of excellent quality, so each participant obviously wants to maximize the total amount of pie they get to eat. Assuming both players make their decisions optimally, how much pie will each participant receive?
Input
Input will begin with an integer N (1 β€ N β€ 50), the number of slices of pie.
Following this is a line with N integers indicating the sizes of the slices (each between 1 and 100000, inclusive), in the order in which they must be handed out.
Output
Print two integers. First, the sum of the sizes of slices eaten by Alice, then the sum of the sizes of the slices eaten by Bob, assuming both players make their decisions optimally.
Examples
Input
3
141 592 653
Output
653 733
Input
5
10 21 10 21 10
Output
31 41
Note
In the first example, Bob takes the size 141 slice for himself and gives the decider token to Alice. Then Alice gives the size 592 slice to Bob and keeps the decider token for herself, so that she can then give the size 653 slice to herself. | instruction | 0 | 52,758 | 9 | 105,516 |
Tags: dp, games
Correct Solution:
```
n = int(input())
slices = list(map(int, input().split()))[::-1]
#print(slices)
a, b = 0, 0
for c in slices:
if b > a + c:
a += c
else:
b, a = a + c, b
#print(a, b)
print(a, b)
``` | output | 1 | 52,758 | 9 | 105,517 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You may have heard of the pie rule before. It states that if two people wish to fairly share a slice of pie, one person should cut the slice in half, and the other person should choose who gets which slice. Alice and Bob have many slices of pie, and rather than cutting the slices in half, each individual slice will be eaten by just one person.
The way Alice and Bob decide who eats each slice is as follows. First, the order in which the pies are to be handed out is decided. There is a special token called the "decider" token, initially held by Bob. Until all the pie is handed out, whoever has the decider token will give the next slice of pie to one of the participants, and the decider token to the other participant. They continue until no slices of pie are left.
All of the slices are of excellent quality, so each participant obviously wants to maximize the total amount of pie they get to eat. Assuming both players make their decisions optimally, how much pie will each participant receive?
Input
Input will begin with an integer N (1 β€ N β€ 50), the number of slices of pie.
Following this is a line with N integers indicating the sizes of the slices (each between 1 and 100000, inclusive), in the order in which they must be handed out.
Output
Print two integers. First, the sum of the sizes of slices eaten by Alice, then the sum of the sizes of the slices eaten by Bob, assuming both players make their decisions optimally.
Examples
Input
3
141 592 653
Output
653 733
Input
5
10 21 10 21 10
Output
31 41
Note
In the first example, Bob takes the size 141 slice for himself and gives the decider token to Alice. Then Alice gives the size 592 slice to Bob and keeps the decider token for herself, so that she can then give the size 653 slice to herself. | instruction | 0 | 52,759 | 9 | 105,518 |
Tags: dp, games
Correct Solution:
```
n=int(input())
x=list(map(int,input().split()))
ma,count=0,0
for i in range(n-1,-1,-1):
ma=max(ma,x[i]+count-ma)
count+=x[i]
print(count-ma,ma)
``` | output | 1 | 52,759 | 9 | 105,519 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You may have heard of the pie rule before. It states that if two people wish to fairly share a slice of pie, one person should cut the slice in half, and the other person should choose who gets which slice. Alice and Bob have many slices of pie, and rather than cutting the slices in half, each individual slice will be eaten by just one person.
The way Alice and Bob decide who eats each slice is as follows. First, the order in which the pies are to be handed out is decided. There is a special token called the "decider" token, initially held by Bob. Until all the pie is handed out, whoever has the decider token will give the next slice of pie to one of the participants, and the decider token to the other participant. They continue until no slices of pie are left.
All of the slices are of excellent quality, so each participant obviously wants to maximize the total amount of pie they get to eat. Assuming both players make their decisions optimally, how much pie will each participant receive?
Input
Input will begin with an integer N (1 β€ N β€ 50), the number of slices of pie.
Following this is a line with N integers indicating the sizes of the slices (each between 1 and 100000, inclusive), in the order in which they must be handed out.
Output
Print two integers. First, the sum of the sizes of slices eaten by Alice, then the sum of the sizes of the slices eaten by Bob, assuming both players make their decisions optimally.
Examples
Input
3
141 592 653
Output
653 733
Input
5
10 21 10 21 10
Output
31 41
Note
In the first example, Bob takes the size 141 slice for himself and gives the decider token to Alice. Then Alice gives the size 592 slice to Bob and keeps the decider token for herself, so that she can then give the size 653 slice to herself. | instruction | 0 | 52,760 | 9 | 105,520 |
Tags: dp, games
Correct Solution:
```
n = int(input())
pieces = list(map(int, input().split()))
reversed_pieces = list(reversed(pieces))
TOTAL = []
current_total = 0
for piece in reversed_pieces:
current_total += piece
TOTAL.append(current_total)
HAS_TOKEN = 0
NO_TOKEN = 1
dp_alice = [[0] * n, [0] * n]
dp_bob = [[0] * n, [0] * n]
dp_alice[HAS_TOKEN][0] = dp_bob[HAS_TOKEN][0] = reversed_pieces[0]
dp_alice[NO_TOKEN][0] = dp_bob[NO_TOKEN][0] = 0
for i in range(1, n):
dp_alice[HAS_TOKEN][i] = max(dp_alice[HAS_TOKEN][i-1], dp_alice[NO_TOKEN][i-1] + reversed_pieces[i])
dp_bob[HAS_TOKEN][i] = max(dp_bob[HAS_TOKEN][i-1], dp_bob[NO_TOKEN][i-1] + reversed_pieces[i])
dp_alice[NO_TOKEN][i] = TOTAL[i] - dp_bob[HAS_TOKEN][i]
dp_bob[NO_TOKEN][i] = TOTAL[i] - dp_alice[HAS_TOKEN][i]
print(dp_alice[NO_TOKEN][-1], dp_bob[HAS_TOKEN][-1])
``` | output | 1 | 52,760 | 9 | 105,521 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You may have heard of the pie rule before. It states that if two people wish to fairly share a slice of pie, one person should cut the slice in half, and the other person should choose who gets which slice. Alice and Bob have many slices of pie, and rather than cutting the slices in half, each individual slice will be eaten by just one person.
The way Alice and Bob decide who eats each slice is as follows. First, the order in which the pies are to be handed out is decided. There is a special token called the "decider" token, initially held by Bob. Until all the pie is handed out, whoever has the decider token will give the next slice of pie to one of the participants, and the decider token to the other participant. They continue until no slices of pie are left.
All of the slices are of excellent quality, so each participant obviously wants to maximize the total amount of pie they get to eat. Assuming both players make their decisions optimally, how much pie will each participant receive?
Input
Input will begin with an integer N (1 β€ N β€ 50), the number of slices of pie.
Following this is a line with N integers indicating the sizes of the slices (each between 1 and 100000, inclusive), in the order in which they must be handed out.
Output
Print two integers. First, the sum of the sizes of slices eaten by Alice, then the sum of the sizes of the slices eaten by Bob, assuming both players make their decisions optimally.
Examples
Input
3
141 592 653
Output
653 733
Input
5
10 21 10 21 10
Output
31 41
Note
In the first example, Bob takes the size 141 slice for himself and gives the decider token to Alice. Then Alice gives the size 592 slice to Bob and keeps the decider token for herself, so that she can then give the size 653 slice to herself. | instruction | 0 | 52,761 | 9 | 105,522 |
Tags: dp, games
Correct Solution:
```
n = int(input())
pie = list(map(int, input().split()))
a = b = 0
for i in reversed(pie):
if a >= b:
b += i
else:
a += i
print(str(min([a,b])) + " " + str(max([a,b])))
``` | output | 1 | 52,761 | 9 | 105,523 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You may have heard of the pie rule before. It states that if two people wish to fairly share a slice of pie, one person should cut the slice in half, and the other person should choose who gets which slice. Alice and Bob have many slices of pie, and rather than cutting the slices in half, each individual slice will be eaten by just one person.
The way Alice and Bob decide who eats each slice is as follows. First, the order in which the pies are to be handed out is decided. There is a special token called the "decider" token, initially held by Bob. Until all the pie is handed out, whoever has the decider token will give the next slice of pie to one of the participants, and the decider token to the other participant. They continue until no slices of pie are left.
All of the slices are of excellent quality, so each participant obviously wants to maximize the total amount of pie they get to eat. Assuming both players make their decisions optimally, how much pie will each participant receive?
Input
Input will begin with an integer N (1 β€ N β€ 50), the number of slices of pie.
Following this is a line with N integers indicating the sizes of the slices (each between 1 and 100000, inclusive), in the order in which they must be handed out.
Output
Print two integers. First, the sum of the sizes of slices eaten by Alice, then the sum of the sizes of the slices eaten by Bob, assuming both players make their decisions optimally.
Examples
Input
3
141 592 653
Output
653 733
Input
5
10 21 10 21 10
Output
31 41
Note
In the first example, Bob takes the size 141 slice for himself and gives the decider token to Alice. Then Alice gives the size 592 slice to Bob and keeps the decider token for herself, so that she can then give the size 653 slice to herself. | instruction | 0 | 52,762 | 9 | 105,524 |
Tags: dp, games
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
def max_revenue(i, a):
if i == len(a)-1:
return a[-1], 0
before = max_revenue(i+1, a)
take = a[i] + before[1], before[0]
give = before[0], a[i] + before[1]
if take[0] > give[0]:
return take
else:
return give
r = max_revenue(0, a)
print(r[1], r[0])
``` | output | 1 | 52,762 | 9 | 105,525 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You may have heard of the pie rule before. It states that if two people wish to fairly share a slice of pie, one person should cut the slice in half, and the other person should choose who gets which slice. Alice and Bob have many slices of pie, and rather than cutting the slices in half, each individual slice will be eaten by just one person.
The way Alice and Bob decide who eats each slice is as follows. First, the order in which the pies are to be handed out is decided. There is a special token called the "decider" token, initially held by Bob. Until all the pie is handed out, whoever has the decider token will give the next slice of pie to one of the participants, and the decider token to the other participant. They continue until no slices of pie are left.
All of the slices are of excellent quality, so each participant obviously wants to maximize the total amount of pie they get to eat. Assuming both players make their decisions optimally, how much pie will each participant receive?
Input
Input will begin with an integer N (1 β€ N β€ 50), the number of slices of pie.
Following this is a line with N integers indicating the sizes of the slices (each between 1 and 100000, inclusive), in the order in which they must be handed out.
Output
Print two integers. First, the sum of the sizes of slices eaten by Alice, then the sum of the sizes of the slices eaten by Bob, assuming both players make their decisions optimally.
Examples
Input
3
141 592 653
Output
653 733
Input
5
10 21 10 21 10
Output
31 41
Note
In the first example, Bob takes the size 141 slice for himself and gives the decider token to Alice. Then Alice gives the size 592 slice to Bob and keeps the decider token for herself, so that she can then give the size 653 slice to herself. | instruction | 0 | 52,763 | 9 | 105,526 |
Tags: dp, games
Correct Solution:
```
N = int(input())
A = list(map(int, input().split()))
s = [0]*(N+1)
dp = [0]*(N+1)
for i in range(N-1, -1, -1):
dp[i] = max(A[i] + s[i+1] - dp[i+1], dp[i+1])
s[i] = s[i+1] + A[i]
print(s[0] - dp[0], dp[0])
``` | output | 1 | 52,763 | 9 | 105,527 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You may have heard of the pie rule before. It states that if two people wish to fairly share a slice of pie, one person should cut the slice in half, and the other person should choose who gets which slice. Alice and Bob have many slices of pie, and rather than cutting the slices in half, each individual slice will be eaten by just one person.
The way Alice and Bob decide who eats each slice is as follows. First, the order in which the pies are to be handed out is decided. There is a special token called the "decider" token, initially held by Bob. Until all the pie is handed out, whoever has the decider token will give the next slice of pie to one of the participants, and the decider token to the other participant. They continue until no slices of pie are left.
All of the slices are of excellent quality, so each participant obviously wants to maximize the total amount of pie they get to eat. Assuming both players make their decisions optimally, how much pie will each participant receive?
Input
Input will begin with an integer N (1 β€ N β€ 50), the number of slices of pie.
Following this is a line with N integers indicating the sizes of the slices (each between 1 and 100000, inclusive), in the order in which they must be handed out.
Output
Print two integers. First, the sum of the sizes of slices eaten by Alice, then the sum of the sizes of the slices eaten by Bob, assuming both players make their decisions optimally.
Examples
Input
3
141 592 653
Output
653 733
Input
5
10 21 10 21 10
Output
31 41
Note
In the first example, Bob takes the size 141 slice for himself and gives the decider token to Alice. Then Alice gives the size 592 slice to Bob and keeps the decider token for herself, so that she can then give the size 653 slice to herself. | instruction | 0 | 52,764 | 9 | 105,528 |
Tags: dp, games
Correct Solution:
```
n = int(input())
p = [int(x) for x in input().split(" ")]
a = b = 0
p.reverse()
for pie in p:
if b > a + pie:
a += pie
else:
a , b = b, a + pie
print(a, b)
# for c in p:
# if b > a + c:
# a += c
# else:
# b, a = a + c, b
# while t:
# for i in reversed(range(len(p))):
# count = 0
# if p[i] >= sum(p[:i]):
# b.append(p[i])
# for j in range(i):
# a.append(p[j])
# p = p[i+1:]
# break
# else:
# count += 1
# if count == len(p):
# b.append(p[0])
# p = p[1:]
# break
#
# if p == []:
# break
# for i in reversed(range(len(p))):
# count = 0
# if p[i] >= sum(p[:i]):
# a.append(p[i])
# for j in range(i):
# b.append(p[j])
# p = p[i+1:]
# break
# else:
# count += 1
# if count == len(p):
# a.append(p[0])
# p = p[1:]
# break
# if p == []:
# break
``` | output | 1 | 52,764 | 9 | 105,529 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You may have heard of the pie rule before. It states that if two people wish to fairly share a slice of pie, one person should cut the slice in half, and the other person should choose who gets which slice. Alice and Bob have many slices of pie, and rather than cutting the slices in half, each individual slice will be eaten by just one person.
The way Alice and Bob decide who eats each slice is as follows. First, the order in which the pies are to be handed out is decided. There is a special token called the "decider" token, initially held by Bob. Until all the pie is handed out, whoever has the decider token will give the next slice of pie to one of the participants, and the decider token to the other participant. They continue until no slices of pie are left.
All of the slices are of excellent quality, so each participant obviously wants to maximize the total amount of pie they get to eat. Assuming both players make their decisions optimally, how much pie will each participant receive?
Input
Input will begin with an integer N (1 β€ N β€ 50), the number of slices of pie.
Following this is a line with N integers indicating the sizes of the slices (each between 1 and 100000, inclusive), in the order in which they must be handed out.
Output
Print two integers. First, the sum of the sizes of slices eaten by Alice, then the sum of the sizes of the slices eaten by Bob, assuming both players make their decisions optimally.
Examples
Input
3
141 592 653
Output
653 733
Input
5
10 21 10 21 10
Output
31 41
Note
In the first example, Bob takes the size 141 slice for himself and gives the decider token to Alice. Then Alice gives the size 592 slice to Bob and keeps the decider token for herself, so that she can then give the size 653 slice to herself.
Submitted Solution:
```
n=int(input())
arr=list(map(int,input().split()))
decider = [0]*n
decider[-1]=arr[-1]
sum=arr[n-1]
for i in range(n-2,-1,-1):
sum+=arr[i]
decider[i]=max(decider[i+1],sum-decider[i+1])
print (sum-decider[0],decider[0])
``` | instruction | 0 | 52,765 | 9 | 105,530 |
Yes | output | 1 | 52,765 | 9 | 105,531 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You may have heard of the pie rule before. It states that if two people wish to fairly share a slice of pie, one person should cut the slice in half, and the other person should choose who gets which slice. Alice and Bob have many slices of pie, and rather than cutting the slices in half, each individual slice will be eaten by just one person.
The way Alice and Bob decide who eats each slice is as follows. First, the order in which the pies are to be handed out is decided. There is a special token called the "decider" token, initially held by Bob. Until all the pie is handed out, whoever has the decider token will give the next slice of pie to one of the participants, and the decider token to the other participant. They continue until no slices of pie are left.
All of the slices are of excellent quality, so each participant obviously wants to maximize the total amount of pie they get to eat. Assuming both players make their decisions optimally, how much pie will each participant receive?
Input
Input will begin with an integer N (1 β€ N β€ 50), the number of slices of pie.
Following this is a line with N integers indicating the sizes of the slices (each between 1 and 100000, inclusive), in the order in which they must be handed out.
Output
Print two integers. First, the sum of the sizes of slices eaten by Alice, then the sum of the sizes of the slices eaten by Bob, assuming both players make their decisions optimally.
Examples
Input
3
141 592 653
Output
653 733
Input
5
10 21 10 21 10
Output
31 41
Note
In the first example, Bob takes the size 141 slice for himself and gives the decider token to Alice. Then Alice gives the size 592 slice to Bob and keeps the decider token for herself, so that she can then give the size 653 slice to herself.
Submitted Solution:
```
n = int(input())
a = list(map(int, input().split()))
a = a[::-1]
d = 0
for i in range(len(a)):
d = max(0 + d, a[i] + (sum(a[:i]) - d))
print(sum(a)-d, d)
``` | instruction | 0 | 52,766 | 9 | 105,532 |
Yes | output | 1 | 52,766 | 9 | 105,533 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You may have heard of the pie rule before. It states that if two people wish to fairly share a slice of pie, one person should cut the slice in half, and the other person should choose who gets which slice. Alice and Bob have many slices of pie, and rather than cutting the slices in half, each individual slice will be eaten by just one person.
The way Alice and Bob decide who eats each slice is as follows. First, the order in which the pies are to be handed out is decided. There is a special token called the "decider" token, initially held by Bob. Until all the pie is handed out, whoever has the decider token will give the next slice of pie to one of the participants, and the decider token to the other participant. They continue until no slices of pie are left.
All of the slices are of excellent quality, so each participant obviously wants to maximize the total amount of pie they get to eat. Assuming both players make their decisions optimally, how much pie will each participant receive?
Input
Input will begin with an integer N (1 β€ N β€ 50), the number of slices of pie.
Following this is a line with N integers indicating the sizes of the slices (each between 1 and 100000, inclusive), in the order in which they must be handed out.
Output
Print two integers. First, the sum of the sizes of slices eaten by Alice, then the sum of the sizes of the slices eaten by Bob, assuming both players make their decisions optimally.
Examples
Input
3
141 592 653
Output
653 733
Input
5
10 21 10 21 10
Output
31 41
Note
In the first example, Bob takes the size 141 slice for himself and gives the decider token to Alice. Then Alice gives the size 592 slice to Bob and keeps the decider token for herself, so that she can then give the size 653 slice to herself.
Submitted Solution:
```
n=int(input())
a=list(map(int,input().split()))[::-1]
if n!=1:
summax,summin=max(a[0],a[1]),min(a[0],a[1])
else:
summin=0;summax=a[0]
for i in range(2,n):
if summax<summin + a[i]:
summax,summin=summin + a[i],summax
else:
summin=summin+a[i]
print(summin,summax)
``` | instruction | 0 | 52,767 | 9 | 105,534 |
Yes | output | 1 | 52,767 | 9 | 105,535 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You may have heard of the pie rule before. It states that if two people wish to fairly share a slice of pie, one person should cut the slice in half, and the other person should choose who gets which slice. Alice and Bob have many slices of pie, and rather than cutting the slices in half, each individual slice will be eaten by just one person.
The way Alice and Bob decide who eats each slice is as follows. First, the order in which the pies are to be handed out is decided. There is a special token called the "decider" token, initially held by Bob. Until all the pie is handed out, whoever has the decider token will give the next slice of pie to one of the participants, and the decider token to the other participant. They continue until no slices of pie are left.
All of the slices are of excellent quality, so each participant obviously wants to maximize the total amount of pie they get to eat. Assuming both players make their decisions optimally, how much pie will each participant receive?
Input
Input will begin with an integer N (1 β€ N β€ 50), the number of slices of pie.
Following this is a line with N integers indicating the sizes of the slices (each between 1 and 100000, inclusive), in the order in which they must be handed out.
Output
Print two integers. First, the sum of the sizes of slices eaten by Alice, then the sum of the sizes of the slices eaten by Bob, assuming both players make their decisions optimally.
Examples
Input
3
141 592 653
Output
653 733
Input
5
10 21 10 21 10
Output
31 41
Note
In the first example, Bob takes the size 141 slice for himself and gives the decider token to Alice. Then Alice gives the size 592 slice to Bob and keeps the decider token for herself, so that she can then give the size 653 slice to herself.
Submitted Solution:
```
input();a=b=0
for i,x in enumerate(list(map(int,input().split()))[::-1]):
if b>a+x:a+=x
else:a,b=b,a+x
print(a,b)
``` | instruction | 0 | 52,768 | 9 | 105,536 |
Yes | output | 1 | 52,768 | 9 | 105,537 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You may have heard of the pie rule before. It states that if two people wish to fairly share a slice of pie, one person should cut the slice in half, and the other person should choose who gets which slice. Alice and Bob have many slices of pie, and rather than cutting the slices in half, each individual slice will be eaten by just one person.
The way Alice and Bob decide who eats each slice is as follows. First, the order in which the pies are to be handed out is decided. There is a special token called the "decider" token, initially held by Bob. Until all the pie is handed out, whoever has the decider token will give the next slice of pie to one of the participants, and the decider token to the other participant. They continue until no slices of pie are left.
All of the slices are of excellent quality, so each participant obviously wants to maximize the total amount of pie they get to eat. Assuming both players make their decisions optimally, how much pie will each participant receive?
Input
Input will begin with an integer N (1 β€ N β€ 50), the number of slices of pie.
Following this is a line with N integers indicating the sizes of the slices (each between 1 and 100000, inclusive), in the order in which they must be handed out.
Output
Print two integers. First, the sum of the sizes of slices eaten by Alice, then the sum of the sizes of the slices eaten by Bob, assuming both players make their decisions optimally.
Examples
Input
3
141 592 653
Output
653 733
Input
5
10 21 10 21 10
Output
31 41
Note
In the first example, Bob takes the size 141 slice for himself and gives the decider token to Alice. Then Alice gives the size 592 slice to Bob and keeps the decider token for herself, so that she can then give the size 653 slice to herself.
Submitted Solution:
```
'''
codeforces.com/problemset/problem/859/C
author: latesum
'''
n = int(input())
v = list(map(int,input().split()))
v.reverse()
ans = [0, 0]
for i in range(n):
if ans[1] + v[i] > ans[0]:
t = ans[1] + v[i]
ans[1] = ans[0]
ans[0] = t
else:
ans[1] += v[i]
print(ans[n&1], ans[1-(n&1)])
``` | instruction | 0 | 52,769 | 9 | 105,538 |
No | output | 1 | 52,769 | 9 | 105,539 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You may have heard of the pie rule before. It states that if two people wish to fairly share a slice of pie, one person should cut the slice in half, and the other person should choose who gets which slice. Alice and Bob have many slices of pie, and rather than cutting the slices in half, each individual slice will be eaten by just one person.
The way Alice and Bob decide who eats each slice is as follows. First, the order in which the pies are to be handed out is decided. There is a special token called the "decider" token, initially held by Bob. Until all the pie is handed out, whoever has the decider token will give the next slice of pie to one of the participants, and the decider token to the other participant. They continue until no slices of pie are left.
All of the slices are of excellent quality, so each participant obviously wants to maximize the total amount of pie they get to eat. Assuming both players make their decisions optimally, how much pie will each participant receive?
Input
Input will begin with an integer N (1 β€ N β€ 50), the number of slices of pie.
Following this is a line with N integers indicating the sizes of the slices (each between 1 and 100000, inclusive), in the order in which they must be handed out.
Output
Print two integers. First, the sum of the sizes of slices eaten by Alice, then the sum of the sizes of the slices eaten by Bob, assuming both players make their decisions optimally.
Examples
Input
3
141 592 653
Output
653 733
Input
5
10 21 10 21 10
Output
31 41
Note
In the first example, Bob takes the size 141 slice for himself and gives the decider token to Alice. Then Alice gives the size 592 slice to Bob and keeps the decider token for herself, so that she can then give the size 653 slice to herself.
Submitted Solution:
```
num = int(input())
Bob = True
pieces = [int(i) for i in input().split()]
bobn = 0
alicen = 0
for i in range(num-2):
if pieces[i] > pieces[i + 1] or (pieces[i] < pieces[i + 1] and pieces[i + 1] > pieces[i + 2]):
Bob = not Bob
if Bob:
bobn += pieces[i]
else:
alicen += pieces[i]
else:
if Bob:
alicen += pieces[i]
else:
bobn += pieces[i]
if Bob:
bobn += max(pieces[num - 1],pieces[num - 2])
alicen += min(pieces[num - 1],pieces[num - 2])
else:
alicen += max(pieces[num - 1],pieces[num - 2])
bobn += min(pieces[num - 1],pieces[num - 2])
print(bobn,alicen)
``` | instruction | 0 | 52,770 | 9 | 105,540 |
No | output | 1 | 52,770 | 9 | 105,541 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You may have heard of the pie rule before. It states that if two people wish to fairly share a slice of pie, one person should cut the slice in half, and the other person should choose who gets which slice. Alice and Bob have many slices of pie, and rather than cutting the slices in half, each individual slice will be eaten by just one person.
The way Alice and Bob decide who eats each slice is as follows. First, the order in which the pies are to be handed out is decided. There is a special token called the "decider" token, initially held by Bob. Until all the pie is handed out, whoever has the decider token will give the next slice of pie to one of the participants, and the decider token to the other participant. They continue until no slices of pie are left.
All of the slices are of excellent quality, so each participant obviously wants to maximize the total amount of pie they get to eat. Assuming both players make their decisions optimally, how much pie will each participant receive?
Input
Input will begin with an integer N (1 β€ N β€ 50), the number of slices of pie.
Following this is a line with N integers indicating the sizes of the slices (each between 1 and 100000, inclusive), in the order in which they must be handed out.
Output
Print two integers. First, the sum of the sizes of slices eaten by Alice, then the sum of the sizes of the slices eaten by Bob, assuming both players make their decisions optimally.
Examples
Input
3
141 592 653
Output
653 733
Input
5
10 21 10 21 10
Output
31 41
Note
In the first example, Bob takes the size 141 slice for himself and gives the decider token to Alice. Then Alice gives the size 592 slice to Bob and keeps the decider token for herself, so that she can then give the size 653 slice to herself.
Submitted Solution:
```
n = int(input())
A = [int(i) for i in input().split()]
if n == 1:
print(0, A[0])
exit()
if n == 2:
print(min(A), max(A))
exit()
o1, o2 = 0, 0
turn = 1
while len(A) > 1:
if turn:
i = 0
summa = 0
while summa < A[i] and i != len(A) - 1:
summa += A[i]
i += 1
o2 += summa
o1 += A[i]
A = A[i + 1:]
turn = 0
else:
i = 0
summa = 0
while summa < A[i] and i != len(A) - 1:
summa += A[i]
i += 1
o1 += summa
o2 += A[i]
A = A[i + 1:]
turn = 1
if len(A) == 1:
if turn:
o1 += A[0]
else:
o2 += A[0]
print(min(o1, o2),max(o1, o2))
``` | instruction | 0 | 52,771 | 9 | 105,542 |
No | output | 1 | 52,771 | 9 | 105,543 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You may have heard of the pie rule before. It states that if two people wish to fairly share a slice of pie, one person should cut the slice in half, and the other person should choose who gets which slice. Alice and Bob have many slices of pie, and rather than cutting the slices in half, each individual slice will be eaten by just one person.
The way Alice and Bob decide who eats each slice is as follows. First, the order in which the pies are to be handed out is decided. There is a special token called the "decider" token, initially held by Bob. Until all the pie is handed out, whoever has the decider token will give the next slice of pie to one of the participants, and the decider token to the other participant. They continue until no slices of pie are left.
All of the slices are of excellent quality, so each participant obviously wants to maximize the total amount of pie they get to eat. Assuming both players make their decisions optimally, how much pie will each participant receive?
Input
Input will begin with an integer N (1 β€ N β€ 50), the number of slices of pie.
Following this is a line with N integers indicating the sizes of the slices (each between 1 and 100000, inclusive), in the order in which they must be handed out.
Output
Print two integers. First, the sum of the sizes of slices eaten by Alice, then the sum of the sizes of the slices eaten by Bob, assuming both players make their decisions optimally.
Examples
Input
3
141 592 653
Output
653 733
Input
5
10 21 10 21 10
Output
31 41
Note
In the first example, Bob takes the size 141 slice for himself and gives the decider token to Alice. Then Alice gives the size 592 slice to Bob and keeps the decider token for herself, so that she can then give the size 653 slice to herself.
Submitted Solution:
```
n = int(input())
pies = list(reversed(list(map(int, input().split()))))
current = 1
distribution = {1:[0], -1:[0]}
while pies:
if pies[-1] > sum(pies[:-1]):
distribution[current].append(pies.pop())
distribution[-current] += pies
pies = []
else:
distribution[current].append(pies.pop())
current *= -1
#print(distribution, pies)
print(sum(distribution[-1]), sum(distribution[1]))
``` | instruction | 0 | 52,772 | 9 | 105,544 |
No | output | 1 | 52,772 | 9 | 105,545 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pinkie Pie has bought a bag of patty-cakes with different fillings! But it appeared that not all patty-cakes differ from one another with filling. In other words, the bag contains some patty-cakes with the same filling.
Pinkie Pie eats the patty-cakes one-by-one. She likes having fun so she decided not to simply eat the patty-cakes but to try not to eat the patty-cakes with the same filling way too often. To achieve this she wants the minimum distance between the eaten with the same filling to be the largest possible. Herein Pinkie Pie called the distance between two patty-cakes the number of eaten patty-cakes strictly between them.
Pinkie Pie can eat the patty-cakes in any order. She is impatient about eating all the patty-cakes up so she asks you to help her to count the greatest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating!
Pinkie Pie is going to buy more bags of patty-cakes so she asks you to solve this problem for several bags!
Input
The first line contains a single integer T (1 β€ T β€ 100): the number of bags for which you need to solve the problem.
The first line of each bag description contains a single integer n (2 β€ n β€ 10^5): the number of patty-cakes in it. The second line of the bag description contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n): the information of patty-cakes' fillings: same fillings are defined as same integers, different fillings are defined as different integers. It is guaranteed that each bag contains at least two patty-cakes with the same filling.
It is guaranteed that the sum of n over all bags does not exceed 10^5.
Output
For each bag print in separate line one single integer: the largest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating for that bag.
Example
Input
4
7
1 7 1 6 4 4 6
8
1 1 4 6 4 6 4 7
3
3 3 3
6
2 5 2 3 1 4
Output
3
2
0
4
Note
For the first bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): 1, 6, 4, 7, 1, 6, 4 (in this way, the minimum distance is equal to 3).
For the second bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): 1, 4, 6, 7, 4, 1, 6, 4 (in this way, the minimum distance is equal to 2). | instruction | 0 | 53,255 | 9 | 106,510 |
Tags: constructive algorithms, greedy, math, sortings
Correct Solution:
```
for _ in range(int(input())):
n=int(input())
l=[int(x) for x in input().split()]
r=[0 for i in range(n+1)]
for i in l:
r[i]+=1
r.sort()
m=r[-1]
h=r.count(m)
print((n-h)//(m-1)-1)
``` | output | 1 | 53,255 | 9 | 106,511 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pinkie Pie has bought a bag of patty-cakes with different fillings! But it appeared that not all patty-cakes differ from one another with filling. In other words, the bag contains some patty-cakes with the same filling.
Pinkie Pie eats the patty-cakes one-by-one. She likes having fun so she decided not to simply eat the patty-cakes but to try not to eat the patty-cakes with the same filling way too often. To achieve this she wants the minimum distance between the eaten with the same filling to be the largest possible. Herein Pinkie Pie called the distance between two patty-cakes the number of eaten patty-cakes strictly between them.
Pinkie Pie can eat the patty-cakes in any order. She is impatient about eating all the patty-cakes up so she asks you to help her to count the greatest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating!
Pinkie Pie is going to buy more bags of patty-cakes so she asks you to solve this problem for several bags!
Input
The first line contains a single integer T (1 β€ T β€ 100): the number of bags for which you need to solve the problem.
The first line of each bag description contains a single integer n (2 β€ n β€ 10^5): the number of patty-cakes in it. The second line of the bag description contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n): the information of patty-cakes' fillings: same fillings are defined as same integers, different fillings are defined as different integers. It is guaranteed that each bag contains at least two patty-cakes with the same filling.
It is guaranteed that the sum of n over all bags does not exceed 10^5.
Output
For each bag print in separate line one single integer: the largest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating for that bag.
Example
Input
4
7
1 7 1 6 4 4 6
8
1 1 4 6 4 6 4 7
3
3 3 3
6
2 5 2 3 1 4
Output
3
2
0
4
Note
For the first bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): 1, 6, 4, 7, 1, 6, 4 (in this way, the minimum distance is equal to 3).
For the second bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): 1, 4, 6, 7, 4, 1, 6, 4 (in this way, the minimum distance is equal to 2). | instruction | 0 | 53,256 | 9 | 106,512 |
Tags: constructive algorithms, greedy, math, sortings
Correct Solution:
```
# n=10, have 3 6's
# 6____6___6 -> min distance is 3
# n=10, have 3 6's, 3 4's
# 46__46__46 -> min distance is 3
# n=10, have 3 6's, 3 4's, 3 2's
# 246246_246 -> min distance is 2
# answer = n/(largest_count) or n/(largest_count) - 1 ?
# let x = answer
# let c = largest_count = 5
# let f = frequency of largest_count = 4
# 1_______1_______1_______1_______1___
# x (f-1)
# 1234____1234____1234____1234____1234
#
# n >= (x+1)(c-1)+f
#
# x+1 <= (n-f)/(c-1)
for _ in range(int(input())):
n = int(input())
fillings = list(map(int,input().split()))
l = [0]*100000
for i in range(n):
l[fillings[i] - 1] += 1 # is this correct btw
c = max(l)
f = l.count(c)
print((n-f)//(c-1)-1)
# find the number that appears most frequently then put other numbers evenly between them?
``` | output | 1 | 53,256 | 9 | 106,513 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pinkie Pie has bought a bag of patty-cakes with different fillings! But it appeared that not all patty-cakes differ from one another with filling. In other words, the bag contains some patty-cakes with the same filling.
Pinkie Pie eats the patty-cakes one-by-one. She likes having fun so she decided not to simply eat the patty-cakes but to try not to eat the patty-cakes with the same filling way too often. To achieve this she wants the minimum distance between the eaten with the same filling to be the largest possible. Herein Pinkie Pie called the distance between two patty-cakes the number of eaten patty-cakes strictly between them.
Pinkie Pie can eat the patty-cakes in any order. She is impatient about eating all the patty-cakes up so she asks you to help her to count the greatest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating!
Pinkie Pie is going to buy more bags of patty-cakes so she asks you to solve this problem for several bags!
Input
The first line contains a single integer T (1 β€ T β€ 100): the number of bags for which you need to solve the problem.
The first line of each bag description contains a single integer n (2 β€ n β€ 10^5): the number of patty-cakes in it. The second line of the bag description contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n): the information of patty-cakes' fillings: same fillings are defined as same integers, different fillings are defined as different integers. It is guaranteed that each bag contains at least two patty-cakes with the same filling.
It is guaranteed that the sum of n over all bags does not exceed 10^5.
Output
For each bag print in separate line one single integer: the largest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating for that bag.
Example
Input
4
7
1 7 1 6 4 4 6
8
1 1 4 6 4 6 4 7
3
3 3 3
6
2 5 2 3 1 4
Output
3
2
0
4
Note
For the first bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): 1, 6, 4, 7, 1, 6, 4 (in this way, the minimum distance is equal to 3).
For the second bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): 1, 4, 6, 7, 4, 1, 6, 4 (in this way, the minimum distance is equal to 2). | instruction | 0 | 53,257 | 9 | 106,514 |
Tags: constructive algorithms, greedy, math, sortings
Correct Solution:
```
T = int(input())
ans = []
for i in range(T):
n = int(input())
a = list(map(int, input().split()))
c = [0] * (n + 1)
max1 = 0
c_max = 0
for j in a:
c[j] += 1
for j in c:
if j > max1:
max1 = j
c_max = 1
elif j == max1:
c_max += 1
ans.append((n - max1 * c_max) // (max1 - 1) + c_max - 1)
for i in ans:
print(i)
``` | output | 1 | 53,257 | 9 | 106,515 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pinkie Pie has bought a bag of patty-cakes with different fillings! But it appeared that not all patty-cakes differ from one another with filling. In other words, the bag contains some patty-cakes with the same filling.
Pinkie Pie eats the patty-cakes one-by-one. She likes having fun so she decided not to simply eat the patty-cakes but to try not to eat the patty-cakes with the same filling way too often. To achieve this she wants the minimum distance between the eaten with the same filling to be the largest possible. Herein Pinkie Pie called the distance between two patty-cakes the number of eaten patty-cakes strictly between them.
Pinkie Pie can eat the patty-cakes in any order. She is impatient about eating all the patty-cakes up so she asks you to help her to count the greatest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating!
Pinkie Pie is going to buy more bags of patty-cakes so she asks you to solve this problem for several bags!
Input
The first line contains a single integer T (1 β€ T β€ 100): the number of bags for which you need to solve the problem.
The first line of each bag description contains a single integer n (2 β€ n β€ 10^5): the number of patty-cakes in it. The second line of the bag description contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n): the information of patty-cakes' fillings: same fillings are defined as same integers, different fillings are defined as different integers. It is guaranteed that each bag contains at least two patty-cakes with the same filling.
It is guaranteed that the sum of n over all bags does not exceed 10^5.
Output
For each bag print in separate line one single integer: the largest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating for that bag.
Example
Input
4
7
1 7 1 6 4 4 6
8
1 1 4 6 4 6 4 7
3
3 3 3
6
2 5 2 3 1 4
Output
3
2
0
4
Note
For the first bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): 1, 6, 4, 7, 1, 6, 4 (in this way, the minimum distance is equal to 3).
For the second bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): 1, 4, 6, 7, 4, 1, 6, 4 (in this way, the minimum distance is equal to 2). | instruction | 0 | 53,258 | 9 | 106,516 |
Tags: constructive algorithms, greedy, math, sortings
Correct Solution:
```
import sys
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))
from collections import Counter as cc
t,=I()
for _ in range(t):
n,=I()
l=I()
an=0
d=cc(l)
ma=max(d.values())
ct=list(d.values()).count(ma)
rm=n-ct*ma
an+=(ct-1+rm//(ma-1) if ma!=1 else n)
print(an)
``` | output | 1 | 53,258 | 9 | 106,517 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pinkie Pie has bought a bag of patty-cakes with different fillings! But it appeared that not all patty-cakes differ from one another with filling. In other words, the bag contains some patty-cakes with the same filling.
Pinkie Pie eats the patty-cakes one-by-one. She likes having fun so she decided not to simply eat the patty-cakes but to try not to eat the patty-cakes with the same filling way too often. To achieve this she wants the minimum distance between the eaten with the same filling to be the largest possible. Herein Pinkie Pie called the distance between two patty-cakes the number of eaten patty-cakes strictly between them.
Pinkie Pie can eat the patty-cakes in any order. She is impatient about eating all the patty-cakes up so she asks you to help her to count the greatest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating!
Pinkie Pie is going to buy more bags of patty-cakes so she asks you to solve this problem for several bags!
Input
The first line contains a single integer T (1 β€ T β€ 100): the number of bags for which you need to solve the problem.
The first line of each bag description contains a single integer n (2 β€ n β€ 10^5): the number of patty-cakes in it. The second line of the bag description contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n): the information of patty-cakes' fillings: same fillings are defined as same integers, different fillings are defined as different integers. It is guaranteed that each bag contains at least two patty-cakes with the same filling.
It is guaranteed that the sum of n over all bags does not exceed 10^5.
Output
For each bag print in separate line one single integer: the largest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating for that bag.
Example
Input
4
7
1 7 1 6 4 4 6
8
1 1 4 6 4 6 4 7
3
3 3 3
6
2 5 2 3 1 4
Output
3
2
0
4
Note
For the first bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): 1, 6, 4, 7, 1, 6, 4 (in this way, the minimum distance is equal to 3).
For the second bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): 1, 4, 6, 7, 4, 1, 6, 4 (in this way, the minimum distance is equal to 2). | instruction | 0 | 53,259 | 9 | 106,518 |
Tags: constructive algorithms, greedy, math, sortings
Correct Solution:
```
import heapq
T = int(input())
for test in range(T):
n = int(input())
l = dict()
for v in map(int, input().split()):
if v not in l:
l[v] = 0
l[v] += 1
lo = 0 #Impossible
hi = n #Possible
while hi - lo > 1:
test = (lo + hi) // 2
so_far = []
ll = dict(l)
q = []
works = True
for v in l:
heapq.heappush(q, -ll[v])
for i in range(n):
if i >= test:
v = so_far[i-test]
if v:
heapq.heappush(q, -v)
if q:
nex = -heapq.heappop(q)
so_far.append(nex - 1)
else:
works = False
break
if works:
lo = test
else:
hi = test
print(lo - 1)
``` | output | 1 | 53,259 | 9 | 106,519 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pinkie Pie has bought a bag of patty-cakes with different fillings! But it appeared that not all patty-cakes differ from one another with filling. In other words, the bag contains some patty-cakes with the same filling.
Pinkie Pie eats the patty-cakes one-by-one. She likes having fun so she decided not to simply eat the patty-cakes but to try not to eat the patty-cakes with the same filling way too often. To achieve this she wants the minimum distance between the eaten with the same filling to be the largest possible. Herein Pinkie Pie called the distance between two patty-cakes the number of eaten patty-cakes strictly between them.
Pinkie Pie can eat the patty-cakes in any order. She is impatient about eating all the patty-cakes up so she asks you to help her to count the greatest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating!
Pinkie Pie is going to buy more bags of patty-cakes so she asks you to solve this problem for several bags!
Input
The first line contains a single integer T (1 β€ T β€ 100): the number of bags for which you need to solve the problem.
The first line of each bag description contains a single integer n (2 β€ n β€ 10^5): the number of patty-cakes in it. The second line of the bag description contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n): the information of patty-cakes' fillings: same fillings are defined as same integers, different fillings are defined as different integers. It is guaranteed that each bag contains at least two patty-cakes with the same filling.
It is guaranteed that the sum of n over all bags does not exceed 10^5.
Output
For each bag print in separate line one single integer: the largest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating for that bag.
Example
Input
4
7
1 7 1 6 4 4 6
8
1 1 4 6 4 6 4 7
3
3 3 3
6
2 5 2 3 1 4
Output
3
2
0
4
Note
For the first bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): 1, 6, 4, 7, 1, 6, 4 (in this way, the minimum distance is equal to 3).
For the second bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): 1, 4, 6, 7, 4, 1, 6, 4 (in this way, the minimum distance is equal to 2). | instruction | 0 | 53,260 | 9 | 106,520 |
Tags: constructive algorithms, greedy, math, sortings
Correct Solution:
```
from collections import defaultdict
t = int(input())
while t:
t -= 1
n = int(input())
lst = list(map(int, input().split()))
dic = defaultdict(int)
for i in lst:
dic[i] += 1
max_ele = 0
counter = 0
for i in dic.values():
if max_ele < i:
counter = 1
max_ele = i
elif max_ele == i:
counter += 1
res = counter - 1
if n - (max_ele * counter) != 0:
res += (n - (max_ele * counter)) // (max_ele - 1)
print(res)
``` | output | 1 | 53,260 | 9 | 106,521 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pinkie Pie has bought a bag of patty-cakes with different fillings! But it appeared that not all patty-cakes differ from one another with filling. In other words, the bag contains some patty-cakes with the same filling.
Pinkie Pie eats the patty-cakes one-by-one. She likes having fun so she decided not to simply eat the patty-cakes but to try not to eat the patty-cakes with the same filling way too often. To achieve this she wants the minimum distance between the eaten with the same filling to be the largest possible. Herein Pinkie Pie called the distance between two patty-cakes the number of eaten patty-cakes strictly between them.
Pinkie Pie can eat the patty-cakes in any order. She is impatient about eating all the patty-cakes up so she asks you to help her to count the greatest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating!
Pinkie Pie is going to buy more bags of patty-cakes so she asks you to solve this problem for several bags!
Input
The first line contains a single integer T (1 β€ T β€ 100): the number of bags for which you need to solve the problem.
The first line of each bag description contains a single integer n (2 β€ n β€ 10^5): the number of patty-cakes in it. The second line of the bag description contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n): the information of patty-cakes' fillings: same fillings are defined as same integers, different fillings are defined as different integers. It is guaranteed that each bag contains at least two patty-cakes with the same filling.
It is guaranteed that the sum of n over all bags does not exceed 10^5.
Output
For each bag print in separate line one single integer: the largest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating for that bag.
Example
Input
4
7
1 7 1 6 4 4 6
8
1 1 4 6 4 6 4 7
3
3 3 3
6
2 5 2 3 1 4
Output
3
2
0
4
Note
For the first bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): 1, 6, 4, 7, 1, 6, 4 (in this way, the minimum distance is equal to 3).
For the second bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): 1, 4, 6, 7, 4, 1, 6, 4 (in this way, the minimum distance is equal to 2). | instruction | 0 | 53,261 | 9 | 106,522 |
Tags: constructive algorithms, greedy, math, sortings
Correct Solution:
```
for i in ' '*int(input()):
n=int(input())
L=list(map(int,input().split()))
L.sort()
pt=0
M=[]
ct=0
while pt<n-1:
pt+=1
ct+=1
if L[pt]!=L[pt-1]:
M.append(ct)
ct=0
ct+=1
M.append(ct)
M.sort()
mx=max(M)
count=0
mxcount=0
for i in M:
if i==mx:mxcount+=1
else:count+=i
ans=mxcount+(count//(mx-1))-1
print(ans)
``` | output | 1 | 53,261 | 9 | 106,523 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Pinkie Pie has bought a bag of patty-cakes with different fillings! But it appeared that not all patty-cakes differ from one another with filling. In other words, the bag contains some patty-cakes with the same filling.
Pinkie Pie eats the patty-cakes one-by-one. She likes having fun so she decided not to simply eat the patty-cakes but to try not to eat the patty-cakes with the same filling way too often. To achieve this she wants the minimum distance between the eaten with the same filling to be the largest possible. Herein Pinkie Pie called the distance between two patty-cakes the number of eaten patty-cakes strictly between them.
Pinkie Pie can eat the patty-cakes in any order. She is impatient about eating all the patty-cakes up so she asks you to help her to count the greatest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating!
Pinkie Pie is going to buy more bags of patty-cakes so she asks you to solve this problem for several bags!
Input
The first line contains a single integer T (1 β€ T β€ 100): the number of bags for which you need to solve the problem.
The first line of each bag description contains a single integer n (2 β€ n β€ 10^5): the number of patty-cakes in it. The second line of the bag description contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n): the information of patty-cakes' fillings: same fillings are defined as same integers, different fillings are defined as different integers. It is guaranteed that each bag contains at least two patty-cakes with the same filling.
It is guaranteed that the sum of n over all bags does not exceed 10^5.
Output
For each bag print in separate line one single integer: the largest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating for that bag.
Example
Input
4
7
1 7 1 6 4 4 6
8
1 1 4 6 4 6 4 7
3
3 3 3
6
2 5 2 3 1 4
Output
3
2
0
4
Note
For the first bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): 1, 6, 4, 7, 1, 6, 4 (in this way, the minimum distance is equal to 3).
For the second bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): 1, 4, 6, 7, 4, 1, 6, 4 (in this way, the minimum distance is equal to 2). | instruction | 0 | 53,262 | 9 | 106,524 |
Tags: constructive algorithms, greedy, math, sortings
Correct Solution:
```
from collections import Counter
for _ in range(int(input())):
n = int(input())
mc = [x[1] for x in Counter(map(int, input().split())).most_common()]
e = mc[0]
q = 0
for c in mc:
if c != e:
break
q += 1
print((n - q) // (e - 1) - 1)
``` | output | 1 | 53,262 | 9 | 106,525 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pinkie Pie has bought a bag of patty-cakes with different fillings! But it appeared that not all patty-cakes differ from one another with filling. In other words, the bag contains some patty-cakes with the same filling.
Pinkie Pie eats the patty-cakes one-by-one. She likes having fun so she decided not to simply eat the patty-cakes but to try not to eat the patty-cakes with the same filling way too often. To achieve this she wants the minimum distance between the eaten with the same filling to be the largest possible. Herein Pinkie Pie called the distance between two patty-cakes the number of eaten patty-cakes strictly between them.
Pinkie Pie can eat the patty-cakes in any order. She is impatient about eating all the patty-cakes up so she asks you to help her to count the greatest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating!
Pinkie Pie is going to buy more bags of patty-cakes so she asks you to solve this problem for several bags!
Input
The first line contains a single integer T (1 β€ T β€ 100): the number of bags for which you need to solve the problem.
The first line of each bag description contains a single integer n (2 β€ n β€ 10^5): the number of patty-cakes in it. The second line of the bag description contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n): the information of patty-cakes' fillings: same fillings are defined as same integers, different fillings are defined as different integers. It is guaranteed that each bag contains at least two patty-cakes with the same filling.
It is guaranteed that the sum of n over all bags does not exceed 10^5.
Output
For each bag print in separate line one single integer: the largest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating for that bag.
Example
Input
4
7
1 7 1 6 4 4 6
8
1 1 4 6 4 6 4 7
3
3 3 3
6
2 5 2 3 1 4
Output
3
2
0
4
Note
For the first bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): 1, 6, 4, 7, 1, 6, 4 (in this way, the minimum distance is equal to 3).
For the second bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): 1, 4, 6, 7, 4, 1, 6, 4 (in this way, the minimum distance is equal to 2).
Submitted Solution:
```
import sys, os, io
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(sys.stdin.readline())
def ria(): return list(map(int, sys.stdin.readline().split()))
def ws(s): sys.stdout.write(s + '\n')
def wi(n): sys.stdout.write(str(n) + '\n')
def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math,datetime,functools,itertools,operator,bisect,fractions,statistics
from collections import deque,defaultdict,OrderedDict,Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify ,_heapify_max,_heappop_max,nsmallest,nlargest
def main():
# mod=1000000007
# InverseofNumber(mod)
# InverseofFactorial(mod)
# factorial(mod)
starttime=datetime.datetime.now()
if(os.path.exists('input.txt')):
sys.stdin = open("input.txt","r")
sys.stdout = open("output.txt","w")
tc=ri()
for _ in range(tc):
n=ri()
a=ria()
d=Counter(a)
k=0
for i in d:
k=max(k,d[i])
maxfreq=0
for i in d:
if d[i]==k:
maxfreq+=1
print((n-maxfreq)//(k-1)-1)
#<--Solving Area Ends
endtime=datetime.datetime.now()
time=(endtime-starttime).total_seconds()*1000
if(os.path.exists('input.txt')):
print("Time:",time,"ms")
class FastReader(io.IOBase):
newlines = 0
def __init__(self, fd, chunk_size=1024 * 8):
self._fd = fd
self._chunk_size = chunk_size
self.buffer = io.BytesIO()
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
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, size=-1):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
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()
class FastWriter(io.IOBase):
def __init__(self, fd):
self._fd = fd
self.buffer = io.BytesIO()
self.write = self.buffer.write
def flush(self):
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class FastStdin(io.IOBase):
def __init__(self, fd=0):
self.buffer = FastReader(fd)
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
class FastStdout(io.IOBase):
def __init__(self, fd=1):
self.buffer = FastWriter(fd)
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.flush = self.buffer.flush
if __name__ == '__main__':
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()
``` | instruction | 0 | 53,263 | 9 | 106,526 |
Yes | output | 1 | 53,263 | 9 | 106,527 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pinkie Pie has bought a bag of patty-cakes with different fillings! But it appeared that not all patty-cakes differ from one another with filling. In other words, the bag contains some patty-cakes with the same filling.
Pinkie Pie eats the patty-cakes one-by-one. She likes having fun so she decided not to simply eat the patty-cakes but to try not to eat the patty-cakes with the same filling way too often. To achieve this she wants the minimum distance between the eaten with the same filling to be the largest possible. Herein Pinkie Pie called the distance between two patty-cakes the number of eaten patty-cakes strictly between them.
Pinkie Pie can eat the patty-cakes in any order. She is impatient about eating all the patty-cakes up so she asks you to help her to count the greatest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating!
Pinkie Pie is going to buy more bags of patty-cakes so she asks you to solve this problem for several bags!
Input
The first line contains a single integer T (1 β€ T β€ 100): the number of bags for which you need to solve the problem.
The first line of each bag description contains a single integer n (2 β€ n β€ 10^5): the number of patty-cakes in it. The second line of the bag description contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n): the information of patty-cakes' fillings: same fillings are defined as same integers, different fillings are defined as different integers. It is guaranteed that each bag contains at least two patty-cakes with the same filling.
It is guaranteed that the sum of n over all bags does not exceed 10^5.
Output
For each bag print in separate line one single integer: the largest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating for that bag.
Example
Input
4
7
1 7 1 6 4 4 6
8
1 1 4 6 4 6 4 7
3
3 3 3
6
2 5 2 3 1 4
Output
3
2
0
4
Note
For the first bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): 1, 6, 4, 7, 1, 6, 4 (in this way, the minimum distance is equal to 3).
For the second bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): 1, 4, 6, 7, 4, 1, 6, 4 (in this way, the minimum distance is equal to 2).
Submitted Solution:
```
for _ in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
b={}
for i in a:
if i in b:
b[i]+=1
else:
b[i]=1
c=sorted(b.items(),key=lambda x:x[1],reverse=True)
u,v=c[0]
p=1
for i in range(1,len(c)):
s,t=c[i]
if t==v:
p+=1
else:
break
n-=p
n=n//(v-1)
print(n-1)
``` | instruction | 0 | 53,264 | 9 | 106,528 |
Yes | output | 1 | 53,264 | 9 | 106,529 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pinkie Pie has bought a bag of patty-cakes with different fillings! But it appeared that not all patty-cakes differ from one another with filling. In other words, the bag contains some patty-cakes with the same filling.
Pinkie Pie eats the patty-cakes one-by-one. She likes having fun so she decided not to simply eat the patty-cakes but to try not to eat the patty-cakes with the same filling way too often. To achieve this she wants the minimum distance between the eaten with the same filling to be the largest possible. Herein Pinkie Pie called the distance between two patty-cakes the number of eaten patty-cakes strictly between them.
Pinkie Pie can eat the patty-cakes in any order. She is impatient about eating all the patty-cakes up so she asks you to help her to count the greatest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating!
Pinkie Pie is going to buy more bags of patty-cakes so she asks you to solve this problem for several bags!
Input
The first line contains a single integer T (1 β€ T β€ 100): the number of bags for which you need to solve the problem.
The first line of each bag description contains a single integer n (2 β€ n β€ 10^5): the number of patty-cakes in it. The second line of the bag description contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n): the information of patty-cakes' fillings: same fillings are defined as same integers, different fillings are defined as different integers. It is guaranteed that each bag contains at least two patty-cakes with the same filling.
It is guaranteed that the sum of n over all bags does not exceed 10^5.
Output
For each bag print in separate line one single integer: the largest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating for that bag.
Example
Input
4
7
1 7 1 6 4 4 6
8
1 1 4 6 4 6 4 7
3
3 3 3
6
2 5 2 3 1 4
Output
3
2
0
4
Note
For the first bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): 1, 6, 4, 7, 1, 6, 4 (in this way, the minimum distance is equal to 3).
For the second bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): 1, 4, 6, 7, 4, 1, 6, 4 (in this way, the minimum distance is equal to 2).
Submitted Solution:
```
"""
Satwik_Tiwari ;) .
7th AUGUST , 2020 - FRIDAY
"""
#===============================================================================================
#importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter # Counter(list) return a dict with {key: count}
from itertools import combinations as comb # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
#If the element is already present in the list,
# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect
#If the element is already present in the list,
# the right most position where element has to be inserted is returned
#==============================================================================================
#fast I/O region
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")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
# inp = lambda: sys.stdin.readline().rstrip("\r\n")
#===============================================================================================
### START ITERATE RECURSION ###
from types import GeneratorType
def iterative(f, stack=[]):
def wrapped_func(*args, **kwargs):
if stack: return f(*args, **kwargs)
to = f(*args, **kwargs)
while True:
if type(to) is GeneratorType:
stack.append(to)
to = next(to)
continue
stack.pop()
if not stack: break
to = stack[-1].send(to)
return to
return wrapped_func
#### END ITERATE RECURSION ####
#===============================================================================================
#some shortcuts
mod = 1000000007
def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def out(var): sys.stdout.write(str(var)) #for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
# def graph(vertex): return [[] for i in range(0,vertex+1)]
def zerolist(n): return [0]*n
def nextline(): out("\n") #as stdout.write always print sring.
def testcase(t):
for p in range(t):
solve()
def printlist(a) :
for p in range(0,len(a)):
out(str(a[p]) + ' ')
def lcm(a,b): return (a*b)//gcd(a,b)
def power(a,b):
ans = 1
while(b>0):
if(b%2==1):
ans*=a
a*=a
b//=2
return ans
def ncr(n,r): return factorial(n)//(factorial(r)*factorial(max(n-r,1)))
def isPrime(n) :
if (n <= 1) : return False
if (n <= 3) : return True
if (n % 2 == 0 or n % 3 == 0) : return False
i = 5
while(i * i <= n) :
if (n % i == 0 or n % (i + 2) == 0) :
return False
i = i + 6
return True
#===============================================================================================
# code here ;))
def chck(ans,help,mx,n):
if(1 + (mx-1)*(ans+1) + help - 1<=n):
return True
else:
return False
def solve():
n = int(inp())
a = lis()
cnt = [0]*(10**5+1)
for i in range(n):
cnt[a[i]]+=1
mx = max(cnt)
help = cnt.count(mx)
l = 0
h = n-2
ans = 0
while(l<=h):
mid = (l+h)//2
if(chck(mid,help,mx,n)):
l = mid+1
ans = max(ans,mid)
else:
h = mid-1
# print(l,h,'==')
print(ans)
# testcase(1)
testcase(int(inp()))
``` | instruction | 0 | 53,265 | 9 | 106,530 |
Yes | output | 1 | 53,265 | 9 | 106,531 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pinkie Pie has bought a bag of patty-cakes with different fillings! But it appeared that not all patty-cakes differ from one another with filling. In other words, the bag contains some patty-cakes with the same filling.
Pinkie Pie eats the patty-cakes one-by-one. She likes having fun so she decided not to simply eat the patty-cakes but to try not to eat the patty-cakes with the same filling way too often. To achieve this she wants the minimum distance between the eaten with the same filling to be the largest possible. Herein Pinkie Pie called the distance between two patty-cakes the number of eaten patty-cakes strictly between them.
Pinkie Pie can eat the patty-cakes in any order. She is impatient about eating all the patty-cakes up so she asks you to help her to count the greatest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating!
Pinkie Pie is going to buy more bags of patty-cakes so she asks you to solve this problem for several bags!
Input
The first line contains a single integer T (1 β€ T β€ 100): the number of bags for which you need to solve the problem.
The first line of each bag description contains a single integer n (2 β€ n β€ 10^5): the number of patty-cakes in it. The second line of the bag description contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n): the information of patty-cakes' fillings: same fillings are defined as same integers, different fillings are defined as different integers. It is guaranteed that each bag contains at least two patty-cakes with the same filling.
It is guaranteed that the sum of n over all bags does not exceed 10^5.
Output
For each bag print in separate line one single integer: the largest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating for that bag.
Example
Input
4
7
1 7 1 6 4 4 6
8
1 1 4 6 4 6 4 7
3
3 3 3
6
2 5 2 3 1 4
Output
3
2
0
4
Note
For the first bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): 1, 6, 4, 7, 1, 6, 4 (in this way, the minimum distance is equal to 3).
For the second bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): 1, 4, 6, 7, 4, 1, 6, 4 (in this way, the minimum distance is equal to 2).
Submitted Solution:
```
from math import *
from collections import *
from random import *
from decimal import Decimal
from heapq import *
from bisect import *
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**5)
def lis():
return list(map(int,input().split()))
def ma():
return map(int,input().split())
def inp():
return int(input())
def st1():
return input().rstrip('\n')
t=inp()
while(t):
t-=1
n=inp()
a=lis()
f=Counter(a)
z=max(f.values())
#print(z)
co1=0
for i in f.keys():
if(f[i]==z):
co1+=1
print((n-co1)//(z-1) - 1)
``` | instruction | 0 | 53,266 | 9 | 106,532 |
Yes | output | 1 | 53,266 | 9 | 106,533 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pinkie Pie has bought a bag of patty-cakes with different fillings! But it appeared that not all patty-cakes differ from one another with filling. In other words, the bag contains some patty-cakes with the same filling.
Pinkie Pie eats the patty-cakes one-by-one. She likes having fun so she decided not to simply eat the patty-cakes but to try not to eat the patty-cakes with the same filling way too often. To achieve this she wants the minimum distance between the eaten with the same filling to be the largest possible. Herein Pinkie Pie called the distance between two patty-cakes the number of eaten patty-cakes strictly between them.
Pinkie Pie can eat the patty-cakes in any order. She is impatient about eating all the patty-cakes up so she asks you to help her to count the greatest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating!
Pinkie Pie is going to buy more bags of patty-cakes so she asks you to solve this problem for several bags!
Input
The first line contains a single integer T (1 β€ T β€ 100): the number of bags for which you need to solve the problem.
The first line of each bag description contains a single integer n (2 β€ n β€ 10^5): the number of patty-cakes in it. The second line of the bag description contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n): the information of patty-cakes' fillings: same fillings are defined as same integers, different fillings are defined as different integers. It is guaranteed that each bag contains at least two patty-cakes with the same filling.
It is guaranteed that the sum of n over all bags does not exceed 10^5.
Output
For each bag print in separate line one single integer: the largest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating for that bag.
Example
Input
4
7
1 7 1 6 4 4 6
8
1 1 4 6 4 6 4 7
3
3 3 3
6
2 5 2 3 1 4
Output
3
2
0
4
Note
For the first bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): 1, 6, 4, 7, 1, 6, 4 (in this way, the minimum distance is equal to 3).
For the second bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): 1, 4, 6, 7, 4, 1, 6, 4 (in this way, the minimum distance is equal to 2).
Submitted Solution:
```
from sys import stdin
input = stdin.readline
n = 0
cnt = []
def f(m):
vis = [0] * (2 * n + 1)
j = 0
for i in cnt:
tmp = i
while j < n and vis[j]:
j += 1
k = j
while k < n and not vis[k] and tmp:
vis[k] = 1
tmp -= 1
k += m
if tmp:
return True
return False
for _ in range(int(input())):
n = int(input())
*a, = map(int, input().split())
cnt = [0] * (n + 1)
for i in a:
cnt[i] += 1
cnt.sort(reverse=True)
print(cnt)
l, r = 0, n - 1
while l < r:
m = l + r >> 1
if f(m):
r = m
else:
l = m + 1
if f(l):
l -= 1
print(l - 1)
``` | instruction | 0 | 53,267 | 9 | 106,534 |
No | output | 1 | 53,267 | 9 | 106,535 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pinkie Pie has bought a bag of patty-cakes with different fillings! But it appeared that not all patty-cakes differ from one another with filling. In other words, the bag contains some patty-cakes with the same filling.
Pinkie Pie eats the patty-cakes one-by-one. She likes having fun so she decided not to simply eat the patty-cakes but to try not to eat the patty-cakes with the same filling way too often. To achieve this she wants the minimum distance between the eaten with the same filling to be the largest possible. Herein Pinkie Pie called the distance between two patty-cakes the number of eaten patty-cakes strictly between them.
Pinkie Pie can eat the patty-cakes in any order. She is impatient about eating all the patty-cakes up so she asks you to help her to count the greatest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating!
Pinkie Pie is going to buy more bags of patty-cakes so she asks you to solve this problem for several bags!
Input
The first line contains a single integer T (1 β€ T β€ 100): the number of bags for which you need to solve the problem.
The first line of each bag description contains a single integer n (2 β€ n β€ 10^5): the number of patty-cakes in it. The second line of the bag description contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n): the information of patty-cakes' fillings: same fillings are defined as same integers, different fillings are defined as different integers. It is guaranteed that each bag contains at least two patty-cakes with the same filling.
It is guaranteed that the sum of n over all bags does not exceed 10^5.
Output
For each bag print in separate line one single integer: the largest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating for that bag.
Example
Input
4
7
1 7 1 6 4 4 6
8
1 1 4 6 4 6 4 7
3
3 3 3
6
2 5 2 3 1 4
Output
3
2
0
4
Note
For the first bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): 1, 6, 4, 7, 1, 6, 4 (in this way, the minimum distance is equal to 3).
For the second bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): 1, 4, 6, 7, 4, 1, 6, 4 (in this way, the minimum distance is equal to 2).
Submitted Solution:
```
from sys import stdin
input = stdin.readline
for _ in range(int(input())):
n = int(input())
a = [int(x) for x in input().split()]
d = dict()
for x in a:
if x in d.keys():
d[x] += 1
else:
d[x] = 1
m = max(d.values())
cnt1, cnt2, cnt3 = 0, 0, 0
for x in d.values():
if m == x:
cnt1 += 1
elif m - 1 == x:
cnt2 += 1
elif m - 2 == x:
cnt3 += 1
if 2 * m == n:
print(1)
continue
if n % 2 and 2 * m == n + 1:
print(1)
continue
if n % 2 and 2 * m + 1 == n:
print(1)
continue
if 2 * m > n:
print(0)
continue
print(cnt1 + cnt2 - 1)
``` | instruction | 0 | 53,268 | 9 | 106,536 |
No | output | 1 | 53,268 | 9 | 106,537 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pinkie Pie has bought a bag of patty-cakes with different fillings! But it appeared that not all patty-cakes differ from one another with filling. In other words, the bag contains some patty-cakes with the same filling.
Pinkie Pie eats the patty-cakes one-by-one. She likes having fun so she decided not to simply eat the patty-cakes but to try not to eat the patty-cakes with the same filling way too often. To achieve this she wants the minimum distance between the eaten with the same filling to be the largest possible. Herein Pinkie Pie called the distance between two patty-cakes the number of eaten patty-cakes strictly between them.
Pinkie Pie can eat the patty-cakes in any order. She is impatient about eating all the patty-cakes up so she asks you to help her to count the greatest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating!
Pinkie Pie is going to buy more bags of patty-cakes so she asks you to solve this problem for several bags!
Input
The first line contains a single integer T (1 β€ T β€ 100): the number of bags for which you need to solve the problem.
The first line of each bag description contains a single integer n (2 β€ n β€ 10^5): the number of patty-cakes in it. The second line of the bag description contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n): the information of patty-cakes' fillings: same fillings are defined as same integers, different fillings are defined as different integers. It is guaranteed that each bag contains at least two patty-cakes with the same filling.
It is guaranteed that the sum of n over all bags does not exceed 10^5.
Output
For each bag print in separate line one single integer: the largest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating for that bag.
Example
Input
4
7
1 7 1 6 4 4 6
8
1 1 4 6 4 6 4 7
3
3 3 3
6
2 5 2 3 1 4
Output
3
2
0
4
Note
For the first bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): 1, 6, 4, 7, 1, 6, 4 (in this way, the minimum distance is equal to 3).
For the second bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): 1, 4, 6, 7, 4, 1, 6, 4 (in this way, the minimum distance is equal to 2).
Submitted Solution:
```
for _ in range(int(input())):
n = int(input())
ar = list(map(int,input().split()))
d = {}
for i in range(n):
if ar[i] in d:
d[ar[i]]+= 1
else:
d[ar[i]]=1
mx = []
for key, value in d.items():
mx.append((value,key))
mx.sort()
r = mx.pop()
ans = [0 for i in range(r[0])]
mx.reverse()
e = 0
for i in range(len(mx)):
if mx[i][0]< n-1:
for j in range(mx[i][0]):
ans[(j + e)%n]+=1
else:
for j in range(mx[i][0]):
ans[j]+= 1
ans.pop()
print(min(ans))
``` | instruction | 0 | 53,269 | 9 | 106,538 |
No | output | 1 | 53,269 | 9 | 106,539 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Pinkie Pie has bought a bag of patty-cakes with different fillings! But it appeared that not all patty-cakes differ from one another with filling. In other words, the bag contains some patty-cakes with the same filling.
Pinkie Pie eats the patty-cakes one-by-one. She likes having fun so she decided not to simply eat the patty-cakes but to try not to eat the patty-cakes with the same filling way too often. To achieve this she wants the minimum distance between the eaten with the same filling to be the largest possible. Herein Pinkie Pie called the distance between two patty-cakes the number of eaten patty-cakes strictly between them.
Pinkie Pie can eat the patty-cakes in any order. She is impatient about eating all the patty-cakes up so she asks you to help her to count the greatest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating!
Pinkie Pie is going to buy more bags of patty-cakes so she asks you to solve this problem for several bags!
Input
The first line contains a single integer T (1 β€ T β€ 100): the number of bags for which you need to solve the problem.
The first line of each bag description contains a single integer n (2 β€ n β€ 10^5): the number of patty-cakes in it. The second line of the bag description contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ n): the information of patty-cakes' fillings: same fillings are defined as same integers, different fillings are defined as different integers. It is guaranteed that each bag contains at least two patty-cakes with the same filling.
It is guaranteed that the sum of n over all bags does not exceed 10^5.
Output
For each bag print in separate line one single integer: the largest minimum distance between the eaten patty-cakes with the same filling amongst all possible orders of eating for that bag.
Example
Input
4
7
1 7 1 6 4 4 6
8
1 1 4 6 4 6 4 7
3
3 3 3
6
2 5 2 3 1 4
Output
3
2
0
4
Note
For the first bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): 1, 6, 4, 7, 1, 6, 4 (in this way, the minimum distance is equal to 3).
For the second bag Pinkie Pie can eat the patty-cakes in the following order (by fillings): 1, 4, 6, 7, 4, 1, 6, 4 (in this way, the minimum distance is equal to 2).
Submitted Solution:
```
import sys
input = sys.stdin.readline
for _ in range(int(input())):
n = int(input())
a = sorted([int(i) for i in input().split()])
num = [0 for i in range(n)]
act_num = 0
num[0] = 1
for i in range(1, n):
if a[i] == a[i-1]: num[act_num] += 1
else:
act_num += 1
num[act_num] = 1
candies = sorted(num[:act_num+1], reverse = True)
ans = 0
gaps = candies[0]-1
free = gaps
for i in candies[1:]:
if i < free: free -= i
elif i == free:
ans += 1
free = gaps
else:
free = gaps - (i - free)
ans += 1
print(ans)
``` | instruction | 0 | 53,270 | 9 | 106,540 |
No | output | 1 | 53,270 | 9 | 106,541 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius r and center at the origin. Pizza consists of the main part β circle of radius r - d with center at the origin, and crust around the main part of the width d. Pieces of sausage are also circles. The radius of the i -th piece of the sausage is ri, and the center is given as a pair (xi, yi).
Gleb asks you to help determine the number of pieces of sausage caught on the crust. A piece of sausage got on the crust, if it completely lies on the crust.
Input
First string contains two integer numbers r and d (0 β€ d < r β€ 500) β the radius of pizza and the width of crust.
Next line contains one integer number n β the number of pieces of sausage (1 β€ n β€ 105).
Each of next n lines contains three integer numbers xi, yi and ri ( - 500 β€ xi, yi β€ 500, 0 β€ ri β€ 500), where xi and yi are coordinates of the center of i-th peace of sausage, ri β radius of i-th peace of sausage.
Output
Output the number of pieces of sausage that lay on the crust.
Examples
Input
8 4
7
7 8 1
-7 3 2
0 2 1
0 -2 2
-3 -3 1
0 6 2
5 3 1
Output
2
Input
10 8
4
0 0 9
0 0 10
1 0 1
1 0 2
Output
0
Note
Below is a picture explaining the first example. Circles of green color denote pieces of sausage lying on the crust.
<image> | instruction | 0 | 53,571 | 9 | 107,142 |
Tags: geometry
Correct Solution:
```
import math
from sys import stdin, stdout
def main():
x = stdin.readline().split()
r = int(x[0])
d = int(x[1])
r -= d
n = int(stdin.readline())
ans = 0
for i in range(n):
x = stdin.readline().split()
a = int(x[0])
b = int(x[1])
ri = int(x[2])
D = math.sqrt((a*a) + (b*b))
if D-ri >= r and d >= 2*ri and D+ri <= r+d:
ans += 1
print(ans)
if __name__ == '__main__':
main()
``` | output | 1 | 53,571 | 9 | 107,143 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius r and center at the origin. Pizza consists of the main part β circle of radius r - d with center at the origin, and crust around the main part of the width d. Pieces of sausage are also circles. The radius of the i -th piece of the sausage is ri, and the center is given as a pair (xi, yi).
Gleb asks you to help determine the number of pieces of sausage caught on the crust. A piece of sausage got on the crust, if it completely lies on the crust.
Input
First string contains two integer numbers r and d (0 β€ d < r β€ 500) β the radius of pizza and the width of crust.
Next line contains one integer number n β the number of pieces of sausage (1 β€ n β€ 105).
Each of next n lines contains three integer numbers xi, yi and ri ( - 500 β€ xi, yi β€ 500, 0 β€ ri β€ 500), where xi and yi are coordinates of the center of i-th peace of sausage, ri β radius of i-th peace of sausage.
Output
Output the number of pieces of sausage that lay on the crust.
Examples
Input
8 4
7
7 8 1
-7 3 2
0 2 1
0 -2 2
-3 -3 1
0 6 2
5 3 1
Output
2
Input
10 8
4
0 0 9
0 0 10
1 0 1
1 0 2
Output
0
Note
Below is a picture explaining the first example. Circles of green color denote pieces of sausage lying on the crust.
<image> | instruction | 0 | 53,572 | 9 | 107,144 |
Tags: geometry
Correct Solution:
```
r,d=map(int,input().split())
n=int(input())
ans=0
for i in range(n):
x,y,z=map(int,input().split())
rr=0.7
rr=(x**2+y**2)**(1/2.0)
if (rr-z)>=r-d and rr+z<=r:
ans=ans+1
print(ans)
``` | output | 1 | 53,572 | 9 | 107,145 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius r and center at the origin. Pizza consists of the main part β circle of radius r - d with center at the origin, and crust around the main part of the width d. Pieces of sausage are also circles. The radius of the i -th piece of the sausage is ri, and the center is given as a pair (xi, yi).
Gleb asks you to help determine the number of pieces of sausage caught on the crust. A piece of sausage got on the crust, if it completely lies on the crust.
Input
First string contains two integer numbers r and d (0 β€ d < r β€ 500) β the radius of pizza and the width of crust.
Next line contains one integer number n β the number of pieces of sausage (1 β€ n β€ 105).
Each of next n lines contains three integer numbers xi, yi and ri ( - 500 β€ xi, yi β€ 500, 0 β€ ri β€ 500), where xi and yi are coordinates of the center of i-th peace of sausage, ri β radius of i-th peace of sausage.
Output
Output the number of pieces of sausage that lay on the crust.
Examples
Input
8 4
7
7 8 1
-7 3 2
0 2 1
0 -2 2
-3 -3 1
0 6 2
5 3 1
Output
2
Input
10 8
4
0 0 9
0 0 10
1 0 1
1 0 2
Output
0
Note
Below is a picture explaining the first example. Circles of green color denote pieces of sausage lying on the crust.
<image> | instruction | 0 | 53,573 | 9 | 107,146 |
Tags: geometry
Correct Solution:
```
ls=list(map(int,input().split()))
r=ls[0]
d=ls[1]
n=int(input())
ans=0
for i in range(n):
l=list(map(int,input().split()))
x=l[0]
y=l[1]
rd=l[2]
ds=(((abs(x)**2)+(abs(y)**2))**0.5)
if ds-rd>=r-d and ds+rd<=r:
ans+=1
print(ans)
``` | output | 1 | 53,573 | 9 | 107,147 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius r and center at the origin. Pizza consists of the main part β circle of radius r - d with center at the origin, and crust around the main part of the width d. Pieces of sausage are also circles. The radius of the i -th piece of the sausage is ri, and the center is given as a pair (xi, yi).
Gleb asks you to help determine the number of pieces of sausage caught on the crust. A piece of sausage got on the crust, if it completely lies on the crust.
Input
First string contains two integer numbers r and d (0 β€ d < r β€ 500) β the radius of pizza and the width of crust.
Next line contains one integer number n β the number of pieces of sausage (1 β€ n β€ 105).
Each of next n lines contains three integer numbers xi, yi and ri ( - 500 β€ xi, yi β€ 500, 0 β€ ri β€ 500), where xi and yi are coordinates of the center of i-th peace of sausage, ri β radius of i-th peace of sausage.
Output
Output the number of pieces of sausage that lay on the crust.
Examples
Input
8 4
7
7 8 1
-7 3 2
0 2 1
0 -2 2
-3 -3 1
0 6 2
5 3 1
Output
2
Input
10 8
4
0 0 9
0 0 10
1 0 1
1 0 2
Output
0
Note
Below is a picture explaining the first example. Circles of green color denote pieces of sausage lying on the crust.
<image> | instruction | 0 | 53,574 | 9 | 107,148 |
Tags: geometry
Correct Solution:
```
import math
def main():
R, D = map(int, input().split())
N = int(input())
XYR = tuple(tuple(map(int, input().split())) for _ in range(N))
ans = 0
for x, y, r in XYR:
l = math.hypot(x, y)
if l + r <= R and l - r >= R - D:
ans += 1
print(ans)
main()
``` | output | 1 | 53,574 | 9 | 107,149 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius r and center at the origin. Pizza consists of the main part β circle of radius r - d with center at the origin, and crust around the main part of the width d. Pieces of sausage are also circles. The radius of the i -th piece of the sausage is ri, and the center is given as a pair (xi, yi).
Gleb asks you to help determine the number of pieces of sausage caught on the crust. A piece of sausage got on the crust, if it completely lies on the crust.
Input
First string contains two integer numbers r and d (0 β€ d < r β€ 500) β the radius of pizza and the width of crust.
Next line contains one integer number n β the number of pieces of sausage (1 β€ n β€ 105).
Each of next n lines contains three integer numbers xi, yi and ri ( - 500 β€ xi, yi β€ 500, 0 β€ ri β€ 500), where xi and yi are coordinates of the center of i-th peace of sausage, ri β radius of i-th peace of sausage.
Output
Output the number of pieces of sausage that lay on the crust.
Examples
Input
8 4
7
7 8 1
-7 3 2
0 2 1
0 -2 2
-3 -3 1
0 6 2
5 3 1
Output
2
Input
10 8
4
0 0 9
0 0 10
1 0 1
1 0 2
Output
0
Note
Below is a picture explaining the first example. Circles of green color denote pieces of sausage lying on the crust.
<image> | instruction | 0 | 53,575 | 9 | 107,150 |
Tags: geometry
Correct Solution:
```
r, d = map(int, input().split())
n = int(input())
circles = [list(map(int, input().split())) for i in range(n)]
t = 0
for i in range(n):
x, y, rr = circles[i]
if (x * x + y * y) ** 0.5 - rr >= r - d and (x * x + y * y) ** 0.5 + rr <= r:
t += 1
print(t)
``` | output | 1 | 53,575 | 9 | 107,151 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius r and center at the origin. Pizza consists of the main part β circle of radius r - d with center at the origin, and crust around the main part of the width d. Pieces of sausage are also circles. The radius of the i -th piece of the sausage is ri, and the center is given as a pair (xi, yi).
Gleb asks you to help determine the number of pieces of sausage caught on the crust. A piece of sausage got on the crust, if it completely lies on the crust.
Input
First string contains two integer numbers r and d (0 β€ d < r β€ 500) β the radius of pizza and the width of crust.
Next line contains one integer number n β the number of pieces of sausage (1 β€ n β€ 105).
Each of next n lines contains three integer numbers xi, yi and ri ( - 500 β€ xi, yi β€ 500, 0 β€ ri β€ 500), where xi and yi are coordinates of the center of i-th peace of sausage, ri β radius of i-th peace of sausage.
Output
Output the number of pieces of sausage that lay on the crust.
Examples
Input
8 4
7
7 8 1
-7 3 2
0 2 1
0 -2 2
-3 -3 1
0 6 2
5 3 1
Output
2
Input
10 8
4
0 0 9
0 0 10
1 0 1
1 0 2
Output
0
Note
Below is a picture explaining the first example. Circles of green color denote pieces of sausage lying on the crust.
<image> | instruction | 0 | 53,576 | 9 | 107,152 |
Tags: geometry
Correct Solution:
```
R=lambda:list(map(int,input().split()))
r,d=R()
def ok():
x,y,z=R()
return 1 if (r-d+z)**2<=x*x+y*y<=(r-z)**2 else 0
print(sum(ok() for i in range(int(input()))))
``` | output | 1 | 53,576 | 9 | 107,153 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius r and center at the origin. Pizza consists of the main part β circle of radius r - d with center at the origin, and crust around the main part of the width d. Pieces of sausage are also circles. The radius of the i -th piece of the sausage is ri, and the center is given as a pair (xi, yi).
Gleb asks you to help determine the number of pieces of sausage caught on the crust. A piece of sausage got on the crust, if it completely lies on the crust.
Input
First string contains two integer numbers r and d (0 β€ d < r β€ 500) β the radius of pizza and the width of crust.
Next line contains one integer number n β the number of pieces of sausage (1 β€ n β€ 105).
Each of next n lines contains three integer numbers xi, yi and ri ( - 500 β€ xi, yi β€ 500, 0 β€ ri β€ 500), where xi and yi are coordinates of the center of i-th peace of sausage, ri β radius of i-th peace of sausage.
Output
Output the number of pieces of sausage that lay on the crust.
Examples
Input
8 4
7
7 8 1
-7 3 2
0 2 1
0 -2 2
-3 -3 1
0 6 2
5 3 1
Output
2
Input
10 8
4
0 0 9
0 0 10
1 0 1
1 0 2
Output
0
Note
Below is a picture explaining the first example. Circles of green color denote pieces of sausage lying on the crust.
<image> | instruction | 0 | 53,577 | 9 | 107,154 |
Tags: geometry
Correct Solution:
```
r,d = map(int,input().split())
r1 = r-d
r2=r
n = int(input())
k = 0
for i in range(n):
x,y,ri = map(int,input().split())
if (x*x+y*y>=(r1+ri)**2)and(x*x+y*y<=(r2-ri)**2):
k+=1
print(k)
``` | output | 1 | 53,577 | 9 | 107,155 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius r and center at the origin. Pizza consists of the main part β circle of radius r - d with center at the origin, and crust around the main part of the width d. Pieces of sausage are also circles. The radius of the i -th piece of the sausage is ri, and the center is given as a pair (xi, yi).
Gleb asks you to help determine the number of pieces of sausage caught on the crust. A piece of sausage got on the crust, if it completely lies on the crust.
Input
First string contains two integer numbers r and d (0 β€ d < r β€ 500) β the radius of pizza and the width of crust.
Next line contains one integer number n β the number of pieces of sausage (1 β€ n β€ 105).
Each of next n lines contains three integer numbers xi, yi and ri ( - 500 β€ xi, yi β€ 500, 0 β€ ri β€ 500), where xi and yi are coordinates of the center of i-th peace of sausage, ri β radius of i-th peace of sausage.
Output
Output the number of pieces of sausage that lay on the crust.
Examples
Input
8 4
7
7 8 1
-7 3 2
0 2 1
0 -2 2
-3 -3 1
0 6 2
5 3 1
Output
2
Input
10 8
4
0 0 9
0 0 10
1 0 1
1 0 2
Output
0
Note
Below is a picture explaining the first example. Circles of green color denote pieces of sausage lying on the crust.
<image> | instruction | 0 | 53,578 | 9 | 107,156 |
Tags: geometry
Correct Solution:
```
import math
r,d = [int(x) for x in input().split()]
small_r = r-d
large_r = r
count = 0
for _ in range(int(input())):
#count = 0
x, y, ra = [int(x) for x in input().split()]
dist1 = math.sqrt(x*x + y*y)
inside1 = ((dist1- small_r) < 0)
inside2 = ((dist1 - large_r) <= 0)
if(not inside1 and inside2):
if(ra<=(dist1 - small_r)):
if(ra<= abs(dist1 - large_r)):
count += 1
print(count)
``` | output | 1 | 53,578 | 9 | 107,157 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius r and center at the origin. Pizza consists of the main part β circle of radius r - d with center at the origin, and crust around the main part of the width d. Pieces of sausage are also circles. The radius of the i -th piece of the sausage is ri, and the center is given as a pair (xi, yi).
Gleb asks you to help determine the number of pieces of sausage caught on the crust. A piece of sausage got on the crust, if it completely lies on the crust.
Input
First string contains two integer numbers r and d (0 β€ d < r β€ 500) β the radius of pizza and the width of crust.
Next line contains one integer number n β the number of pieces of sausage (1 β€ n β€ 105).
Each of next n lines contains three integer numbers xi, yi and ri ( - 500 β€ xi, yi β€ 500, 0 β€ ri β€ 500), where xi and yi are coordinates of the center of i-th peace of sausage, ri β radius of i-th peace of sausage.
Output
Output the number of pieces of sausage that lay on the crust.
Examples
Input
8 4
7
7 8 1
-7 3 2
0 2 1
0 -2 2
-3 -3 1
0 6 2
5 3 1
Output
2
Input
10 8
4
0 0 9
0 0 10
1 0 1
1 0 2
Output
0
Note
Below is a picture explaining the first example. Circles of green color denote pieces of sausage lying on the crust.
<image>
Submitted Solution:
```
from __future__ import print_function, division
from sys import stdin
r, d = map(int, stdin.readline().split())
n = int(stdin.readline())
ans = 0
for i in range(n):
x, y, dr = map(int, stdin.readline().split())
if x ** 2 + y**2 < (r - d + dr) ** 2:
continue
if x ** 2 + y ** 2 > (r - dr) ** 2:
continue
ans += 1
print(ans)
``` | instruction | 0 | 53,579 | 9 | 107,158 |
Yes | output | 1 | 53,579 | 9 | 107,159 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius r and center at the origin. Pizza consists of the main part β circle of radius r - d with center at the origin, and crust around the main part of the width d. Pieces of sausage are also circles. The radius of the i -th piece of the sausage is ri, and the center is given as a pair (xi, yi).
Gleb asks you to help determine the number of pieces of sausage caught on the crust. A piece of sausage got on the crust, if it completely lies on the crust.
Input
First string contains two integer numbers r and d (0 β€ d < r β€ 500) β the radius of pizza and the width of crust.
Next line contains one integer number n β the number of pieces of sausage (1 β€ n β€ 105).
Each of next n lines contains three integer numbers xi, yi and ri ( - 500 β€ xi, yi β€ 500, 0 β€ ri β€ 500), where xi and yi are coordinates of the center of i-th peace of sausage, ri β radius of i-th peace of sausage.
Output
Output the number of pieces of sausage that lay on the crust.
Examples
Input
8 4
7
7 8 1
-7 3 2
0 2 1
0 -2 2
-3 -3 1
0 6 2
5 3 1
Output
2
Input
10 8
4
0 0 9
0 0 10
1 0 1
1 0 2
Output
0
Note
Below is a picture explaining the first example. Circles of green color denote pieces of sausage lying on the crust.
<image>
Submitted Solution:
```
r,d = map(int,input().split())
kott = r - d
n = int(input())
ans = 0
for i in range(n):
x,y,r1 = map(int,input().split())
k = (y ** 2 + x ** 2) ** 0.5
if min(r - k,k - kott) >= r1:
ans += 1
print(ans)
``` | instruction | 0 | 53,580 | 9 | 107,160 |
Yes | output | 1 | 53,580 | 9 | 107,161 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.