message stringlengths 2 65.1k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 0 108k | cluster float64 14 14 | __index_level_0__ int64 0 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself.
<image>
Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight.
Now, she is going to pick three gems.
Xenia loves colorful things, so she will pick exactly one gem of each color.
Xenia loves balance, so she will try to pick gems with little difference in weight.
Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her?
Input
The first line contains a single integer t (1β€ t β€ 100) β the number of test cases. Then t test cases follow.
The first line of each test case contains three integers n_r,n_g,n_b (1β€ n_r,n_g,n_bβ€ 10^5) β the number of red gems, green gems and blue gems respectively.
The second line of each test case contains n_r integers r_1,r_2,β¦,r_{n_r} (1β€ r_i β€ 10^9) β r_i is the weight of the i-th red gem.
The third line of each test case contains n_g integers g_1,g_2,β¦,g_{n_g} (1β€ g_i β€ 10^9) β g_i is the weight of the i-th green gem.
The fourth line of each test case contains n_b integers b_1,b_2,β¦,b_{n_b} (1β€ b_i β€ 10^9) β b_i is the weight of the i-th blue gem.
It is guaranteed that β n_r β€ 10^5, β n_g β€ 10^5, β n_b β€ 10^5 (the sum for all test cases).
Output
For each test case, print a line contains one integer β the minimum value which Xenia wants to find.
Example
Input
5
2 2 3
7 8
6 3
3 1 4
1 1 1
1
1
1000000000
2 2 2
1 2
5 4
6 7
2 2 2
1 2
3 4
6 7
3 4 1
3 2 1
7 3 3 4
6
Output
14
1999999996000000002
24
24
14
Note
In the first test case, Xenia has the following gems:
<image>
If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14. | instruction | 0 | 73,478 | 14 | 146,956 |
Tags: binary search, greedy, math, sortings, two pointers
Correct Solution:
```
# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------- fast io --------------------
from bisect import bisect_left as bis
def dist(p1,p2,p3):
a1=(p1-p2)
a2=(p1-p3)
a3=(p2-p3)
return (a1*a1 +a2*a2 +a3*a3)
def mindist(red,green,blue):
r=len(red);g=len(green);b=len(blue)
minsofar=dist(red[0],green[0],blue[0])
for s in range(r):
#4 cases
p1=red[s]
#case 1(00)
o1=min(bis(green,p1),g-1);o2=min(bis(blue,p1),b-1)
c1ind1=o1;c1ind2=o2
if c1ind1>0 and green[c1ind1]>p1:
c1ind1-=1
if c1ind2>0 and blue[c1ind2]>p1:
c1ind2-=1
c1p2=green[c1ind1];c1p3=blue[c1ind2];d1=dist(p1,c1p2,c1p3);minsofar=min(minsofar,d1)
#case 2(10)
c2ind1=o1;c2ind2=o2
if c2ind2>0 and blue[c2ind2]>p1:
c2ind2-=1
c2p2=green[c2ind1];c2p3=blue[c2ind2];d2=dist(p1,c2p2,c2p3);minsofar=min(minsofar,d2)
#case 3(01)
c3ind1=o1;c3ind2=o2
if c3ind1>0 and green[c3ind1]>p1:
c3ind1-=1
c3p2=green[c3ind1];c3p3=blue[c3ind2];d3=dist(p1,c3p2,c3p3);minsofar=min(minsofar,d3)
#case 4(11)
c4ind1=o1;c4ind2=o2
c4p2=green[c4ind1];c4p3=blue[c4ind2];d4=dist(p1,c4p2,c4p3);minsofar=min(minsofar,d4)
return minsofar
for j in range(int(input())):
r,g,b=map(int,input().split())
red=sorted(map(int,input().split()))
green=sorted(map(int,input().split()))
blue=sorted(map(int,input().split()))
minr=mindist(red,green,blue);ming=mindist(green,red,blue);minb=mindist(blue,red,green)
print(min(minr,ming,minb))
``` | output | 1 | 73,478 | 14 | 146,957 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself.
<image>
Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight.
Now, she is going to pick three gems.
Xenia loves colorful things, so she will pick exactly one gem of each color.
Xenia loves balance, so she will try to pick gems with little difference in weight.
Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her?
Input
The first line contains a single integer t (1β€ t β€ 100) β the number of test cases. Then t test cases follow.
The first line of each test case contains three integers n_r,n_g,n_b (1β€ n_r,n_g,n_bβ€ 10^5) β the number of red gems, green gems and blue gems respectively.
The second line of each test case contains n_r integers r_1,r_2,β¦,r_{n_r} (1β€ r_i β€ 10^9) β r_i is the weight of the i-th red gem.
The third line of each test case contains n_g integers g_1,g_2,β¦,g_{n_g} (1β€ g_i β€ 10^9) β g_i is the weight of the i-th green gem.
The fourth line of each test case contains n_b integers b_1,b_2,β¦,b_{n_b} (1β€ b_i β€ 10^9) β b_i is the weight of the i-th blue gem.
It is guaranteed that β n_r β€ 10^5, β n_g β€ 10^5, β n_b β€ 10^5 (the sum for all test cases).
Output
For each test case, print a line contains one integer β the minimum value which Xenia wants to find.
Example
Input
5
2 2 3
7 8
6 3
3 1 4
1 1 1
1
1
1000000000
2 2 2
1 2
5 4
6 7
2 2 2
1 2
3 4
6 7
3 4 1
3 2 1
7 3 3 4
6
Output
14
1999999996000000002
24
24
14
Note
In the first test case, Xenia has the following gems:
<image>
If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14. | instruction | 0 | 73,479 | 14 | 146,958 |
Tags: binary search, greedy, math, sortings, two pointers
Correct Solution:
```
def cal(x, y, z):
return (x-y)*(x-y) + (y-z)*(y-z) + (z-x)*(z-x)
def lb(val, arr):
if (val >= arr[len(arr) - 1]):
return arr[len(arr) - 1]
if (val <= arr[0]):
return arr[0]
l = 0
r = len(arr)
while (r - l > 1):
mid = (r+l)//2
if (arr[mid] == val):
return arr[mid]
if (arr[mid] < val):
l = mid
if (arr[mid] > val):
r = mid
l2 = l+1
if (abs(arr[l2] - val) < abs(arr[l] - val)):
return arr[l2]
return arr[l]
def solve():
t = int(input())
while (t > 0):
mn = 3 * 10**18
nr, ng, nb = map(int, input().split())
rs = sorted(list(map(int, input().split())))
gs = sorted(list(map(int, input().split())))
bs = sorted(list(map(int, input().split())))
for r in rs:
g = lb(r, gs)
b = lb(r, bs)
mn = min(mn, cal(r, g, b))
for g in gs:
r = lb(g, rs)
b = lb(g, bs)
mn = min(mn, cal(r, g, b))
for b in bs:
r = lb(b, rs)
g = lb(b, gs)
mn = min(mn, cal(r, g, b))
print(mn)
t -= 1
solve()
``` | output | 1 | 73,479 | 14 | 146,959 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself.
<image>
Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight.
Now, she is going to pick three gems.
Xenia loves colorful things, so she will pick exactly one gem of each color.
Xenia loves balance, so she will try to pick gems with little difference in weight.
Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her?
Input
The first line contains a single integer t (1β€ t β€ 100) β the number of test cases. Then t test cases follow.
The first line of each test case contains three integers n_r,n_g,n_b (1β€ n_r,n_g,n_bβ€ 10^5) β the number of red gems, green gems and blue gems respectively.
The second line of each test case contains n_r integers r_1,r_2,β¦,r_{n_r} (1β€ r_i β€ 10^9) β r_i is the weight of the i-th red gem.
The third line of each test case contains n_g integers g_1,g_2,β¦,g_{n_g} (1β€ g_i β€ 10^9) β g_i is the weight of the i-th green gem.
The fourth line of each test case contains n_b integers b_1,b_2,β¦,b_{n_b} (1β€ b_i β€ 10^9) β b_i is the weight of the i-th blue gem.
It is guaranteed that β n_r β€ 10^5, β n_g β€ 10^5, β n_b β€ 10^5 (the sum for all test cases).
Output
For each test case, print a line contains one integer β the minimum value which Xenia wants to find.
Example
Input
5
2 2 3
7 8
6 3
3 1 4
1 1 1
1
1
1000000000
2 2 2
1 2
5 4
6 7
2 2 2
1 2
3 4
6 7
3 4 1
3 2 1
7 3 3 4
6
Output
14
1999999996000000002
24
24
14
Note
In the first test case, Xenia has the following gems:
<image>
If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14. | instruction | 0 | 73,480 | 14 | 146,960 |
Tags: binary search, greedy, math, sortings, two pointers
Correct Solution:
```
'''Solution
'''
def val(gems):
g1, g2, g3 = gems
v = (g1 - g2)**2 + (g2 - g3)**2 + (g3 - g1)**2
return v
def binarysearch(lwr, upr, lst, target, dxn):
if upr == lwr:
return lst[lwr]
elif upr - lwr == 1 and dxn == 1:
if lst[upr] <= target:
return lst[upr]
else:
return lst[lwr]
elif upr - lwr == 1 and dxn == -1:
if lst[lwr] >= target:
return lst[lwr]
else:
return lst[upr]
else:
middle = (lwr + upr) // 2
if lst[middle] > target:
return binarysearch(lwr, middle, lst, target, dxn)
elif lst[middle] < target:
return binarysearch(middle, upr, lst, target, dxn)
else:
return target
'''routine
'''
T = int(input())
for test in range(T):
gemsno = list(map(int, input().split()))
gemlists = [list(map(int, input().split())) for col in range(3)]
for n in range(3):
gemlists[n].sort()
# print(gemlists)
perms = [[0,1,2],[0,2,1],[1,0,2],[1,2,0],[2,0,1],[2,1,0]]
dist = 10**20
for perm in perms:
refno = perm[0]
upw = perm[1]
dwn = perm[2]
refgems = gemlists[refno]
upwgems = gemlists[upw]
dwngems = gemlists[dwn]
# print(refgems,upwgems,dwngems)
dwnl, upwl = len(dwngems), len(upwgems)
for refgem in refgems:
if upwgems[-1] < refgem:
gu = upwgems[-1]
else:
gu = binarysearch(0, upwl-1, upwgems, refgem, 1)
if dwngems[0] > refgem:
gd = dwngems[0]
else:
gd = binarysearch(0, dwnl-1, dwngems, refgem, -1)
gems = [refgem, gu, gd]
v = val(gems)
# print(gems)
dist = min(dist, v)
print(dist)
``` | output | 1 | 73,480 | 14 | 146,961 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself.
<image>
Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a weight.
Now, she is going to pick three gems.
Xenia loves colorful things, so she will pick exactly one gem of each color.
Xenia loves balance, so she will try to pick gems with little difference in weight.
Specifically, supposing the weights of the picked gems are x, y and z, Xenia wants to find the minimum value of (x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her?
Input
The first line contains a single integer t (1β€ t β€ 100) β the number of test cases. Then t test cases follow.
The first line of each test case contains three integers n_r,n_g,n_b (1β€ n_r,n_g,n_bβ€ 10^5) β the number of red gems, green gems and blue gems respectively.
The second line of each test case contains n_r integers r_1,r_2,β¦,r_{n_r} (1β€ r_i β€ 10^9) β r_i is the weight of the i-th red gem.
The third line of each test case contains n_g integers g_1,g_2,β¦,g_{n_g} (1β€ g_i β€ 10^9) β g_i is the weight of the i-th green gem.
The fourth line of each test case contains n_b integers b_1,b_2,β¦,b_{n_b} (1β€ b_i β€ 10^9) β b_i is the weight of the i-th blue gem.
It is guaranteed that β n_r β€ 10^5, β n_g β€ 10^5, β n_b β€ 10^5 (the sum for all test cases).
Output
For each test case, print a line contains one integer β the minimum value which Xenia wants to find.
Example
Input
5
2 2 3
7 8
6 3
3 1 4
1 1 1
1
1
1000000000
2 2 2
1 2
5 4
6 7
2 2 2
1 2
3 4
6 7
3 4 1
3 2 1
7 3 3 4
6
Output
14
1999999996000000002
24
24
14
Note
In the first test case, Xenia has the following gems:
<image>
If she picks the red gem with weight 7, the green gem with weight 6, and the blue gem with weight 4, she will achieve the most balanced selection with (x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14. | instruction | 0 | 73,481 | 14 | 146,962 |
Tags: binary search, greedy, math, sortings, two pointers
Correct Solution:
```
# -*- coding: utf-8 -*-
import sys
from bisect import bisect_left
def input(): return sys.stdin.buffer.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7
for _ in range(INT()):
N1, N2, N3 = MAP()
R = LIST()
G = LIST()
B = LIST()
RGB = [[]] * 3
RGB[0] = sorted(set(R))
RGB[1] = sorted(set(G))
RGB[2] = sorted(set(B))
N = [0] * 3
for i in range(3):
N[i] = len(RGB[i])
ans = INF
for c in range(3):
for i in range(N[c%3]):
x = RGB[c%3][i]
idxy = bisect_left(RGB[(c+1)%3], x)
idxz = bisect_left(RGB[(c+2)%3], x)
for j in range(max(idxy-1, 0), min(idxy+1, N[(c+1)%3])):
for k in range(max(idxz-1, 0), min(idxz+1, N[(c+2)%3])):
y = RGB[(c+1)%3][j]
z = RGB[(c+2)%3][k]
ans = min(ans, (x-y)**2 + (y-z)**2 + (z-x)**2)
print(ans)
``` | output | 1 | 73,481 | 14 | 146,963 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together.
Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of width wi pixels and height hi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W Γ H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.
As is usually the case, the friends made n photos β the j-th (1 β€ j β€ n) photo had everybody except for the j-th friend as he was the photographer.
Print the minimum size of each made photo in pixels.
Input
The first line contains integer n (2 β€ n β€ 200 000) β the number of friends.
Then n lines follow: the i-th line contains information about the i-th friend. The line contains a pair of integers wi, hi (1 β€ wi β€ 10, 1 β€ hi β€ 1000) β the width and height in pixels of the corresponding rectangle.
Output
Print n space-separated numbers b1, b2, ..., bn, where bi β the total number of pixels on the minimum photo containing all friends expect for the i-th one.
Examples
Input
3
1 10
5 5
10 1
Output
75 110 60
Input
3
2 1
1 2
2 1
Output
6 4 6 | instruction | 0 | 73,706 | 14 | 147,412 |
Tags: *special, data structures, dp, implementation
Correct Solution:
```
import math as mt
import sys,string
input=sys.stdin.readline
#print=sys.stdout.write
import random
from collections import deque,defaultdict
L=lambda : list(map(int,input().split()))
Ls=lambda : list(input().split())
M=lambda : map(int,input().split())
I=lambda :int(input())
n=I()
W=0
d=defaultdict(int)
fmax=0
smax=0
H=[]
l=[]
for i in range(n):
a,b=M()
l.append([a,b])
W+=a
if(b>=fmax):
smax=max(smax,fmax)
fmax=b
elif(b>smax):
smax=b
for i in range(n):
if(l[i][1]==fmax):
p=smax
else:
p=fmax
print((W-l[i][0])*p,end=" ")
``` | output | 1 | 73,706 | 14 | 147,413 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together.
Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of width wi pixels and height hi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W Γ H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.
As is usually the case, the friends made n photos β the j-th (1 β€ j β€ n) photo had everybody except for the j-th friend as he was the photographer.
Print the minimum size of each made photo in pixels.
Input
The first line contains integer n (2 β€ n β€ 200 000) β the number of friends.
Then n lines follow: the i-th line contains information about the i-th friend. The line contains a pair of integers wi, hi (1 β€ wi β€ 10, 1 β€ hi β€ 1000) β the width and height in pixels of the corresponding rectangle.
Output
Print n space-separated numbers b1, b2, ..., bn, where bi β the total number of pixels on the minimum photo containing all friends expect for the i-th one.
Examples
Input
3
1 10
5 5
10 1
Output
75 110 60
Input
3
2 1
1 2
2 1
Output
6 4 6 | instruction | 0 | 73,707 | 14 | 147,414 |
Tags: *special, data structures, dp, implementation
Correct Solution:
```
s = 0
L = []
M = []
for i in range(int(input())) :
w , l = map(int , input().split())
L.append((w , l))
s += w
M.append(l)
M.sort(reverse = True)
for i in L :
if i[1] != M[0] :
print((s - i[0]) * M[0] , end =" ")
else :
print((s-i[0]) * M[1] , end = " ")
``` | output | 1 | 73,707 | 14 | 147,415 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together.
Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of width wi pixels and height hi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W Γ H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.
As is usually the case, the friends made n photos β the j-th (1 β€ j β€ n) photo had everybody except for the j-th friend as he was the photographer.
Print the minimum size of each made photo in pixels.
Input
The first line contains integer n (2 β€ n β€ 200 000) β the number of friends.
Then n lines follow: the i-th line contains information about the i-th friend. The line contains a pair of integers wi, hi (1 β€ wi β€ 10, 1 β€ hi β€ 1000) β the width and height in pixels of the corresponding rectangle.
Output
Print n space-separated numbers b1, b2, ..., bn, where bi β the total number of pixels on the minimum photo containing all friends expect for the i-th one.
Examples
Input
3
1 10
5 5
10 1
Output
75 110 60
Input
3
2 1
1 2
2 1
Output
6 4 6 | instruction | 0 | 73,708 | 14 | 147,416 |
Tags: *special, data structures, dp, implementation
Correct Solution:
```
n = int(input())
W, H, H2 = 0, 0, 0
data = []
for i in range(n):
wi, hi = map(int, input().split())
W += wi
H = max(H, hi)
data.append((wi, hi))
help = []
for i in range(n):
help.append([data[i][1], True])
for i in range(n):
if help[i][0] == H:
help[i][1] = False
break
for i in range(n):
if help[i][1]:
H2 = max(H2, help[i][0])
for i in range(n):
if data[i][1] == H:
print((W - data[i][0]) * H2, end=" ")
else:
print((W - data[i][0]) * H, end=" ")
``` | output | 1 | 73,708 | 14 | 147,417 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together.
Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of width wi pixels and height hi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W Γ H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.
As is usually the case, the friends made n photos β the j-th (1 β€ j β€ n) photo had everybody except for the j-th friend as he was the photographer.
Print the minimum size of each made photo in pixels.
Input
The first line contains integer n (2 β€ n β€ 200 000) β the number of friends.
Then n lines follow: the i-th line contains information about the i-th friend. The line contains a pair of integers wi, hi (1 β€ wi β€ 10, 1 β€ hi β€ 1000) β the width and height in pixels of the corresponding rectangle.
Output
Print n space-separated numbers b1, b2, ..., bn, where bi β the total number of pixels on the minimum photo containing all friends expect for the i-th one.
Examples
Input
3
1 10
5 5
10 1
Output
75 110 60
Input
3
2 1
1 2
2 1
Output
6 4 6 | instruction | 0 | 73,709 | 14 | 147,418 |
Tags: *special, data structures, dp, implementation
Correct Solution:
```
st=int(input())
summa=0
q=[]
w=[]
ish=[]
for i in range(st):
z,x=map(int,input().split())
q.append(z)
w.append(x)
ish.append(x)
summa=sum(q)
w.sort()
for i in range(st):
qw=w[st-1]
if ish[i]==qw:
qw=w[st-2]
print((summa-q[i])*qw,end=' ')
``` | output | 1 | 73,709 | 14 | 147,419 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together.
Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of width wi pixels and height hi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W Γ H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.
As is usually the case, the friends made n photos β the j-th (1 β€ j β€ n) photo had everybody except for the j-th friend as he was the photographer.
Print the minimum size of each made photo in pixels.
Input
The first line contains integer n (2 β€ n β€ 200 000) β the number of friends.
Then n lines follow: the i-th line contains information about the i-th friend. The line contains a pair of integers wi, hi (1 β€ wi β€ 10, 1 β€ hi β€ 1000) β the width and height in pixels of the corresponding rectangle.
Output
Print n space-separated numbers b1, b2, ..., bn, where bi β the total number of pixels on the minimum photo containing all friends expect for the i-th one.
Examples
Input
3
1 10
5 5
10 1
Output
75 110 60
Input
3
2 1
1 2
2 1
Output
6 4 6 | instruction | 0 | 73,710 | 14 | 147,420 |
Tags: *special, data structures, dp, implementation
Correct Solution:
```
n = int(input())
w,h = [], []
h1,h2, s = 0, 0, 0
for _ in range(n):
a,b = list(map(int,input().split()))
w.append(a)
h.append(b)
s += a
if b > h1:
h2 = h1
h1 = b
elif b > h2:
h2 = b
for i in range(n):
if h[i] != h1:
print((s-w[i])*h1,end=' ')
else:
print((s-w[i])*h2,end=' ')
``` | output | 1 | 73,710 | 14 | 147,421 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together.
Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of width wi pixels and height hi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W Γ H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.
As is usually the case, the friends made n photos β the j-th (1 β€ j β€ n) photo had everybody except for the j-th friend as he was the photographer.
Print the minimum size of each made photo in pixels.
Input
The first line contains integer n (2 β€ n β€ 200 000) β the number of friends.
Then n lines follow: the i-th line contains information about the i-th friend. The line contains a pair of integers wi, hi (1 β€ wi β€ 10, 1 β€ hi β€ 1000) β the width and height in pixels of the corresponding rectangle.
Output
Print n space-separated numbers b1, b2, ..., bn, where bi β the total number of pixels on the minimum photo containing all friends expect for the i-th one.
Examples
Input
3
1 10
5 5
10 1
Output
75 110 60
Input
3
2 1
1 2
2 1
Output
6 4 6 | instruction | 0 | 73,711 | 14 | 147,422 |
Tags: *special, data structures, dp, implementation
Correct Solution:
```
n = int(input())
h0 = int(-1)
h1 = int(-1)
arr = []
sw = int(0)
cnt = int(0)
for _ in range(n):
w, h = map(int, input().split())
arr.append([w, h])
sw += w
if h0 < h:
cnt = 0
h0 = h
elif h0 == h:
cnt += 1
for x in arr:
if x[1] != h0 and x[1] > h1:
h1 = x[1]
if cnt > 0:
h1 = h0
for i in range(len(arr)):
if arr[i][1] == h0:
print((sw - arr[i][0]) * h1, end = ' ')
else:
print((sw - arr[i][0]) * h0, end = ' ')
``` | output | 1 | 73,711 | 14 | 147,423 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together.
Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of width wi pixels and height hi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W Γ H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.
As is usually the case, the friends made n photos β the j-th (1 β€ j β€ n) photo had everybody except for the j-th friend as he was the photographer.
Print the minimum size of each made photo in pixels.
Input
The first line contains integer n (2 β€ n β€ 200 000) β the number of friends.
Then n lines follow: the i-th line contains information about the i-th friend. The line contains a pair of integers wi, hi (1 β€ wi β€ 10, 1 β€ hi β€ 1000) β the width and height in pixels of the corresponding rectangle.
Output
Print n space-separated numbers b1, b2, ..., bn, where bi β the total number of pixels on the minimum photo containing all friends expect for the i-th one.
Examples
Input
3
1 10
5 5
10 1
Output
75 110 60
Input
3
2 1
1 2
2 1
Output
6 4 6 | instruction | 0 | 73,712 | 14 | 147,424 |
Tags: *special, data structures, dp, implementation
Correct Solution:
```
n = int(input())
def solve(n):
w = []
h = []
for i in range(n):
inp = input().split()
w.append(int(inp[0]))
h.append(int(inp[-1]))
res = []
sm = sum(w)
h_mx = sorted(enumerate(h), reverse=True, key=lambda x: x[-1])
for i in range(n):
w_ = sm - w[i]
if i == h_mx[0][0]:
h_ = h_mx[1][1]
else:
h_ = h_mx[0][1]
res.append(str(w_*h_))
return ' '.join(res)
print(solve(n))
``` | output | 1 | 73,712 | 14 | 147,425 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together.
Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of width wi pixels and height hi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W Γ H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.
As is usually the case, the friends made n photos β the j-th (1 β€ j β€ n) photo had everybody except for the j-th friend as he was the photographer.
Print the minimum size of each made photo in pixels.
Input
The first line contains integer n (2 β€ n β€ 200 000) β the number of friends.
Then n lines follow: the i-th line contains information about the i-th friend. The line contains a pair of integers wi, hi (1 β€ wi β€ 10, 1 β€ hi β€ 1000) β the width and height in pixels of the corresponding rectangle.
Output
Print n space-separated numbers b1, b2, ..., bn, where bi β the total number of pixels on the minimum photo containing all friends expect for the i-th one.
Examples
Input
3
1 10
5 5
10 1
Output
75 110 60
Input
3
2 1
1 2
2 1
Output
6 4 6 | instruction | 0 | 73,713 | 14 | 147,426 |
Tags: *special, data structures, dp, implementation
Correct Solution:
```
s=0
L=[]
M=[]
for i in range(int(input())):
w,l=[int(x) for x in input().split()];L.append((w,l));s+=w;M.append(l)
M.sort();M=M[::-1]
for i in L:
if i[1]==M[0]:print(M[1]*(s-i[0]))
else:print(M[0]*(s-i[0]))
``` | output | 1 | 73,713 | 14 | 147,427 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together.
Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of width wi pixels and height hi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W Γ H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.
As is usually the case, the friends made n photos β the j-th (1 β€ j β€ n) photo had everybody except for the j-th friend as he was the photographer.
Print the minimum size of each made photo in pixels.
Input
The first line contains integer n (2 β€ n β€ 200 000) β the number of friends.
Then n lines follow: the i-th line contains information about the i-th friend. The line contains a pair of integers wi, hi (1 β€ wi β€ 10, 1 β€ hi β€ 1000) β the width and height in pixels of the corresponding rectangle.
Output
Print n space-separated numbers b1, b2, ..., bn, where bi β the total number of pixels on the minimum photo containing all friends expect for the i-th one.
Examples
Input
3
1 10
5 5
10 1
Output
75 110 60
Input
3
2 1
1 2
2 1
Output
6 4 6
Submitted Solution:
```
z,zz=input,lambda:list(map(int,z().split()))
fast=lambda:stdin.readline().strip()
zzz=lambda:[int(i) for i in fast().split()]
szz,graph,mod,szzz=lambda:sorted(zz()),{},10**9+7,lambda:sorted(zzz())
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac
def lcd(xnum1,xnum2):return (xnum1*xnum2//gcd(xnum1,xnum2))
def prime(x):
p=ceil(x**.5)+1
for i in range(2,p):
if (x%i==0 and x!=2) or x==0:return 0
return 1
def dfs(u,visit,graph):
visit[u]=1
for i in graph[u]:
if not visit[i]:
dfs(i,visit,graph)
###########################---Test-Case---#################################
"""
If you Know me , Then you probably don't know me !
"""
###########################---START-CODING---##############################
num=int(z())
lst1=[]
lst2=[]
s1,s2=0,0
c=0
for i in range(num):
x,y=zzz()
s1+=x
s2+=y
lst1.append(x)
lst2.append(y)
lst3=sorted(lst2)
for i,j in zip(lst1,lst2):
w=s1-i
h=lst3[-1]
if h==j:
h=lst3[-2]
print(h*w)
``` | instruction | 0 | 73,714 | 14 | 147,428 |
Yes | output | 1 | 73,714 | 14 | 147,429 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together.
Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of width wi pixels and height hi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W Γ H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.
As is usually the case, the friends made n photos β the j-th (1 β€ j β€ n) photo had everybody except for the j-th friend as he was the photographer.
Print the minimum size of each made photo in pixels.
Input
The first line contains integer n (2 β€ n β€ 200 000) β the number of friends.
Then n lines follow: the i-th line contains information about the i-th friend. The line contains a pair of integers wi, hi (1 β€ wi β€ 10, 1 β€ hi β€ 1000) β the width and height in pixels of the corresponding rectangle.
Output
Print n space-separated numbers b1, b2, ..., bn, where bi β the total number of pixels on the minimum photo containing all friends expect for the i-th one.
Examples
Input
3
1 10
5 5
10 1
Output
75 110 60
Input
3
2 1
1 2
2 1
Output
6 4 6
Submitted Solution:
```
#!/usr/bin/env python
from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
#complete the main function with number of test cases to complete
def main():
n=int(input())
W,H=[],[]
tw,mh1,mh2=0,0,0
for x in range(n):
a,b=map(int,input().split())
W.append(a)
H.append(b)
tw+=a
if b>mh1:
mh2=max(mh1,mh2)
mh1=b
elif b>mh2:
mh2=b
ans=[]
for x in range(n):
if H[x]!=mh1:
ans.append((tw-W[x])*mh1)
else:
ans.append((tw-W[x])*mh2)
print(*ans)
# region fastio
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)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
main()
``` | instruction | 0 | 73,715 | 14 | 147,430 |
Yes | output | 1 | 73,715 | 14 | 147,431 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together.
Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of width wi pixels and height hi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W Γ H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.
As is usually the case, the friends made n photos β the j-th (1 β€ j β€ n) photo had everybody except for the j-th friend as he was the photographer.
Print the minimum size of each made photo in pixels.
Input
The first line contains integer n (2 β€ n β€ 200 000) β the number of friends.
Then n lines follow: the i-th line contains information about the i-th friend. The line contains a pair of integers wi, hi (1 β€ wi β€ 10, 1 β€ hi β€ 1000) β the width and height in pixels of the corresponding rectangle.
Output
Print n space-separated numbers b1, b2, ..., bn, where bi β the total number of pixels on the minimum photo containing all friends expect for the i-th one.
Examples
Input
3
1 10
5 5
10 1
Output
75 110 60
Input
3
2 1
1 2
2 1
Output
6 4 6
Submitted Solution:
```
import math
I = lambda: int(input())
tup = lambda: map(int, input().split())
lst = lambda: list(map(int, input().split()))
def solve():
n=I()
width=[]
height=[]
for i in range(n):
w,h=tup()
width.append(w)
height.append(h)
total_width = sum(width)
answer =[]
h1,h2=0,0 # max1 and max2 of height
for i in range(n):
if height[i]>h1:
h2=h1
h1=height[i]
elif height[i]>h2:
h2=height[i]
for i in range(n):
wid = total_width - width[i]
if height[i] != h1:
answer.append(wid*h1)
else:
answer.append(wid*h2)
print(*answer)
# ---------------------------------------------------------------------------------
t = 1
#t = I()
while t:
solve()
t -= 1
``` | instruction | 0 | 73,716 | 14 | 147,432 |
Yes | output | 1 | 73,716 | 14 | 147,433 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together.
Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of width wi pixels and height hi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W Γ H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.
As is usually the case, the friends made n photos β the j-th (1 β€ j β€ n) photo had everybody except for the j-th friend as he was the photographer.
Print the minimum size of each made photo in pixels.
Input
The first line contains integer n (2 β€ n β€ 200 000) β the number of friends.
Then n lines follow: the i-th line contains information about the i-th friend. The line contains a pair of integers wi, hi (1 β€ wi β€ 10, 1 β€ hi β€ 1000) β the width and height in pixels of the corresponding rectangle.
Output
Print n space-separated numbers b1, b2, ..., bn, where bi β the total number of pixels on the minimum photo containing all friends expect for the i-th one.
Examples
Input
3
1 10
5 5
10 1
Output
75 110 60
Input
3
2 1
1 2
2 1
Output
6 4 6
Submitted Solution:
```
n = int(input().rstrip())
w = [0] * n
h = [0] * n
for i in range(n):
w[i], h[i] = [int(j) for j in input().split()]
suma = sum(w)
max1 = max(h)
max2 = 0
if h.count(max1) != 1: max2 = max1
else:
for i in range(n):
if h[i] != max1:
max2 = max(max2, h[i])
for i in range(n):
if h[i] == max1:
print((suma - w[i])* (max2))
else:
print((suma - w[i])* (max1))
``` | instruction | 0 | 73,717 | 14 | 147,434 |
Yes | output | 1 | 73,717 | 14 | 147,435 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together.
Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of width wi pixels and height hi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W Γ H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.
As is usually the case, the friends made n photos β the j-th (1 β€ j β€ n) photo had everybody except for the j-th friend as he was the photographer.
Print the minimum size of each made photo in pixels.
Input
The first line contains integer n (2 β€ n β€ 200 000) β the number of friends.
Then n lines follow: the i-th line contains information about the i-th friend. The line contains a pair of integers wi, hi (1 β€ wi β€ 10, 1 β€ hi β€ 1000) β the width and height in pixels of the corresponding rectangle.
Output
Print n space-separated numbers b1, b2, ..., bn, where bi β the total number of pixels on the minimum photo containing all friends expect for the i-th one.
Examples
Input
3
1 10
5 5
10 1
Output
75 110 60
Input
3
2 1
1 2
2 1
Output
6 4 6
Submitted Solution:
```
n = int(input())
w_sum = 0
h_max = -float('inf')
h_sub_max = -float('inf')
w = [0] * n
h = [0] * n
for i in range(n):
w[i], h[i] = map(int, input().split())
w_sum += w[i]
if h_max <= h[i]:
h_sub_max = h_max
h_max = h[i]
elif h_sub_max < h[i]:
h_sub_max = h[i]
print(h_max, h_sub_max)
for i in range(n):
if h[i] == h_max:
print((w_sum - w[i]) * h_sub_max, end=' ')
else:
print((w_sum - w[i]) * h_max, end=' ')
print()
``` | instruction | 0 | 73,718 | 14 | 147,436 |
No | output | 1 | 73,718 | 14 | 147,437 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together.
Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of width wi pixels and height hi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W Γ H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.
As is usually the case, the friends made n photos β the j-th (1 β€ j β€ n) photo had everybody except for the j-th friend as he was the photographer.
Print the minimum size of each made photo in pixels.
Input
The first line contains integer n (2 β€ n β€ 200 000) β the number of friends.
Then n lines follow: the i-th line contains information about the i-th friend. The line contains a pair of integers wi, hi (1 β€ wi β€ 10, 1 β€ hi β€ 1000) β the width and height in pixels of the corresponding rectangle.
Output
Print n space-separated numbers b1, b2, ..., bn, where bi β the total number of pixels on the minimum photo containing all friends expect for the i-th one.
Examples
Input
3
1 10
5 5
10 1
Output
75 110 60
Input
3
2 1
1 2
2 1
Output
6 4 6
Submitted Solution:
```
in_t = "2\n1 1\n1 2"
count = int(in_t[:in_t.find('\n')])
width = [int(i.split(' ')[0]) for i in in_t[in_t.find('\n')+1:].split('\n')]
height = [int(i.split(' ')[1]) for i in in_t[in_t.find('\n')+1:].split('\n')]
result = []
curr = 0
while count:
temp_w, temp_h, temp_w[curr], temp_h[curr] = width[:], height[:], 0, 0
sum_width = sum(temp_w)
max_height = max([i for i in temp_h])
result.append(sum_width * max_height)
curr += 1
count -= 1
print(result)
``` | instruction | 0 | 73,719 | 14 | 147,438 |
No | output | 1 | 73,719 | 14 | 147,439 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together.
Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of width wi pixels and height hi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W Γ H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.
As is usually the case, the friends made n photos β the j-th (1 β€ j β€ n) photo had everybody except for the j-th friend as he was the photographer.
Print the minimum size of each made photo in pixels.
Input
The first line contains integer n (2 β€ n β€ 200 000) β the number of friends.
Then n lines follow: the i-th line contains information about the i-th friend. The line contains a pair of integers wi, hi (1 β€ wi β€ 10, 1 β€ hi β€ 1000) β the width and height in pixels of the corresponding rectangle.
Output
Print n space-separated numbers b1, b2, ..., bn, where bi β the total number of pixels on the minimum photo containing all friends expect for the i-th one.
Examples
Input
3
1 10
5 5
10 1
Output
75 110 60
Input
3
2 1
1 2
2 1
Output
6 4 6
Submitted Solution:
```
totalW =0
d = { 0 : [0, 0, 0] }
w=[]
h=[]
for item in range(int(input())):
currentW, currentH = map(int, input().split())
w.append(currentW)
h.append(currentH)
totalW+=currentW
if currentH > d[0][0]:
temp = [currentH, 1, 0 ]#currentH - d[0][2]]
d[0] = temp
elif currentH == d[0]:
d[0][1] = d[0][1] + 1
elif d[0][0] - currentH > d[0][2]:
d[0][2] = d[0][0] - currentH
result=[]
for i,item in enumerate(w):
if d[0][1] >= 2 or h[i] != d[0][0]:
h_mult = d[0][0]
else:
h_mult = d[0][0] - d[0][2]
result.append(str((totalW - item) * h_mult))
print(" ".join(result))
``` | instruction | 0 | 73,720 | 14 | 147,440 |
No | output | 1 | 73,720 | 14 | 147,441 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together.
Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them occupies the rectangle of width wi pixels and height hi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W Γ H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.
As is usually the case, the friends made n photos β the j-th (1 β€ j β€ n) photo had everybody except for the j-th friend as he was the photographer.
Print the minimum size of each made photo in pixels.
Input
The first line contains integer n (2 β€ n β€ 200 000) β the number of friends.
Then n lines follow: the i-th line contains information about the i-th friend. The line contains a pair of integers wi, hi (1 β€ wi β€ 10, 1 β€ hi β€ 1000) β the width and height in pixels of the corresponding rectangle.
Output
Print n space-separated numbers b1, b2, ..., bn, where bi β the total number of pixels on the minimum photo containing all friends expect for the i-th one.
Examples
Input
3
1 10
5 5
10 1
Output
75 110 60
Input
3
2 1
1 2
2 1
Output
6 4 6
Submitted Solution:
```
n = int(input())
a,b,ans = [],[],[]
s = 0
for i in range(n) :
w,h = map(int,input().split(' '))
a.append(w)
b.append(h)
s +=w+h
for i in range(n) :
c = b[i]
b.remove(c)
t = max(b)
b= b[:i]+[c]+b[i:]
ans.append(str((s-a[i])*t))
print(' '.join(ans))
``` | instruction | 0 | 73,721 | 14 | 147,442 |
No | output | 1 | 73,721 | 14 | 147,443 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to n as the pattern. The digits will form a rhombus. The largest digit n should be located in the centre. The digits should decrease as they approach the edges. For example, for n = 5 the handkerchief pattern should look like that:
Β Β Β Β Β Β Β Β Β Β 0
Β Β Β Β Β Β Β Β 0Β 1Β 0
Β Β Β Β Β Β 0Β 1Β 2Β 1Β 0
Β Β Β Β 0Β 1Β 2Β 3Β 2Β 1Β 0
Β Β 0Β 1Β 2Β 3Β 4Β 3Β 2Β 1Β 0
0Β 1Β 2Β 3Β 4Β 5Β 4Β 3Β 2Β 1Β 0
Β Β 0Β 1Β 2Β 3Β 4Β 3Β 2Β 1Β 0
Β Β Β Β 0Β 1Β 2Β 3Β 2Β 1Β 0
Β Β Β Β Β Β 0Β 1Β 2Β 1Β 0
Β Β Β Β Β Β Β Β 0Β 1Β 0
Β Β Β Β Β Β Β Β Β Β 0
Your task is to determine the way the handkerchief will look like by the given n.
Input
The first line contains the single integer n (2 β€ n β€ 9).
Output
Print a picture for the given n. You should strictly observe the number of spaces before the first digit on each line. Every two adjacent digits in the same line should be separated by exactly one space. There should be no spaces after the last digit at the end of each line.
Examples
Input
2
Output
0
0 1 0
0 1 2 1 0
0 1 0
0
Input
3
Output
0
0 1 0
0 1 2 1 0
0 1 2 3 2 1 0
0 1 2 1 0
0 1 0
0 | instruction | 0 | 74,239 | 14 | 148,478 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n =int(input())
loop = n+1
for i in range(1,loop+1):
firstloop = n-i+1
for j in range(firstloop):
print(" ",end=' ')
secondloop = i
value = 0
for j in range(secondloop-1):
print(value,end=' ')
value+=1
if(i==1):
print(value)
value+=1
else:
print(value,end=' ')
value+=1
thirdloop = i-1
value = value-2
for j in range(thirdloop-1):
print(value,end=' ')
value-=1
if(i!=1):
print(value)
value-=1
loop = n
for i in range(loop,0,-1):
firstloop = n-i+1
for j in range(firstloop):
print(" ",end=' ')
secondloop = i
value = 0
for j in range(secondloop-1):
print(value,end=' ')
value+=1
if(i==1):
print(value)
value+=1
else:
print(value,end=' ')
value+=1
thirdloop = i-1
value = value-2
for j in range(thirdloop-1):
print(value,end=' ')
value-=1
if(i!=1):
print(value)
value-=1
``` | output | 1 | 74,239 | 14 | 148,479 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to n as the pattern. The digits will form a rhombus. The largest digit n should be located in the centre. The digits should decrease as they approach the edges. For example, for n = 5 the handkerchief pattern should look like that:
Β Β Β Β Β Β Β Β Β Β 0
Β Β Β Β Β Β Β Β 0Β 1Β 0
Β Β Β Β Β Β 0Β 1Β 2Β 1Β 0
Β Β Β Β 0Β 1Β 2Β 3Β 2Β 1Β 0
Β Β 0Β 1Β 2Β 3Β 4Β 3Β 2Β 1Β 0
0Β 1Β 2Β 3Β 4Β 5Β 4Β 3Β 2Β 1Β 0
Β Β 0Β 1Β 2Β 3Β 4Β 3Β 2Β 1Β 0
Β Β Β Β 0Β 1Β 2Β 3Β 2Β 1Β 0
Β Β Β Β Β Β 0Β 1Β 2Β 1Β 0
Β Β Β Β Β Β Β Β 0Β 1Β 0
Β Β Β Β Β Β Β Β Β Β 0
Your task is to determine the way the handkerchief will look like by the given n.
Input
The first line contains the single integer n (2 β€ n β€ 9).
Output
Print a picture for the given n. You should strictly observe the number of spaces before the first digit on each line. Every two adjacent digits in the same line should be separated by exactly one space. There should be no spaces after the last digit at the end of each line.
Examples
Input
2
Output
0
0 1 0
0 1 2 1 0
0 1 0
0
Input
3
Output
0
0 1 0
0 1 2 1 0
0 1 2 3 2 1 0
0 1 2 1 0
0 1 0
0 | instruction | 0 | 74,240 | 14 | 148,480 |
Tags: constructive algorithms, implementation
Correct Solution:
```
'''input
2
'''
n = int(input())
for x in range(n+1):
y = list(range(x)) + [x] + list(range(x))[::-1]
y = " ".join(str(z) for z in y)
print(" " * 2*(n-x) + y)
for i in range(n-1,-1,-1):
j = list(range(i)) + [i] + list(range(i))[::-1]
j = " ".join(str(k) for k in j)
print(" " * 2*(n-i) + j)
``` | output | 1 | 74,240 | 14 | 148,481 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to n as the pattern. The digits will form a rhombus. The largest digit n should be located in the centre. The digits should decrease as they approach the edges. For example, for n = 5 the handkerchief pattern should look like that:
Β Β Β Β Β Β Β Β Β Β 0
Β Β Β Β Β Β Β Β 0Β 1Β 0
Β Β Β Β Β Β 0Β 1Β 2Β 1Β 0
Β Β Β Β 0Β 1Β 2Β 3Β 2Β 1Β 0
Β Β 0Β 1Β 2Β 3Β 4Β 3Β 2Β 1Β 0
0Β 1Β 2Β 3Β 4Β 5Β 4Β 3Β 2Β 1Β 0
Β Β 0Β 1Β 2Β 3Β 4Β 3Β 2Β 1Β 0
Β Β Β Β 0Β 1Β 2Β 3Β 2Β 1Β 0
Β Β Β Β Β Β 0Β 1Β 2Β 1Β 0
Β Β Β Β Β Β Β Β 0Β 1Β 0
Β Β Β Β Β Β Β Β Β Β 0
Your task is to determine the way the handkerchief will look like by the given n.
Input
The first line contains the single integer n (2 β€ n β€ 9).
Output
Print a picture for the given n. You should strictly observe the number of spaces before the first digit on each line. Every two adjacent digits in the same line should be separated by exactly one space. There should be no spaces after the last digit at the end of each line.
Examples
Input
2
Output
0
0 1 0
0 1 2 1 0
0 1 0
0
Input
3
Output
0
0 1 0
0 1 2 1 0
0 1 2 3 2 1 0
0 1 2 1 0
0 1 0
0 | instruction | 0 | 74,241 | 14 | 148,482 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n = int(input())
s = []
for i in range(n + 1):
s.append(' ' * 2 * (n - i) + ' '.join(str(j) for j in range(i + 1)) + ' ' * min(i, 1) + ' '.join(str(i - j - 1) for j in range(i)))
for i in range(n + 1):
print(s[i])
for i in range(n):
print(s[n - i - 1])
``` | output | 1 | 74,241 | 14 | 148,483 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to n as the pattern. The digits will form a rhombus. The largest digit n should be located in the centre. The digits should decrease as they approach the edges. For example, for n = 5 the handkerchief pattern should look like that:
Β Β Β Β Β Β Β Β Β Β 0
Β Β Β Β Β Β Β Β 0Β 1Β 0
Β Β Β Β Β Β 0Β 1Β 2Β 1Β 0
Β Β Β Β 0Β 1Β 2Β 3Β 2Β 1Β 0
Β Β 0Β 1Β 2Β 3Β 4Β 3Β 2Β 1Β 0
0Β 1Β 2Β 3Β 4Β 5Β 4Β 3Β 2Β 1Β 0
Β Β 0Β 1Β 2Β 3Β 4Β 3Β 2Β 1Β 0
Β Β Β Β 0Β 1Β 2Β 3Β 2Β 1Β 0
Β Β Β Β Β Β 0Β 1Β 2Β 1Β 0
Β Β Β Β Β Β Β Β 0Β 1Β 0
Β Β Β Β Β Β Β Β Β Β 0
Your task is to determine the way the handkerchief will look like by the given n.
Input
The first line contains the single integer n (2 β€ n β€ 9).
Output
Print a picture for the given n. You should strictly observe the number of spaces before the first digit on each line. Every two adjacent digits in the same line should be separated by exactly one space. There should be no spaces after the last digit at the end of each line.
Examples
Input
2
Output
0
0 1 0
0 1 2 1 0
0 1 0
0
Input
3
Output
0
0 1 0
0 1 2 1 0
0 1 2 3 2 1 0
0 1 2 1 0
0 1 0
0 | instruction | 0 | 74,242 | 14 | 148,484 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n = int(input())
k=(n*2)-1
o=[]
z=[]
q=-1
for i in range(0,n+1):
for j in range(0,i):
o.append(j)
for w in range(i-2,-1,-1):
o.append(w)
if len(o)>0:
if k>0:
print(k*" ",*o)
k-=2
o=[]
else:
print(*o)
for p in range(n+1,0,-1):
for m in range(0,p):
z.append(m)
for w in range(p-2,-1,-1):
z.append(w)
if q==-1:
print(*z)
q+=2
z=[]
else:
print(q*" ",*z)
q+=2
z=[]
``` | output | 1 | 74,242 | 14 | 148,485 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to n as the pattern. The digits will form a rhombus. The largest digit n should be located in the centre. The digits should decrease as they approach the edges. For example, for n = 5 the handkerchief pattern should look like that:
Β Β Β Β Β Β Β Β Β Β 0
Β Β Β Β Β Β Β Β 0Β 1Β 0
Β Β Β Β Β Β 0Β 1Β 2Β 1Β 0
Β Β Β Β 0Β 1Β 2Β 3Β 2Β 1Β 0
Β Β 0Β 1Β 2Β 3Β 4Β 3Β 2Β 1Β 0
0Β 1Β 2Β 3Β 4Β 5Β 4Β 3Β 2Β 1Β 0
Β Β 0Β 1Β 2Β 3Β 4Β 3Β 2Β 1Β 0
Β Β Β Β 0Β 1Β 2Β 3Β 2Β 1Β 0
Β Β Β Β Β Β 0Β 1Β 2Β 1Β 0
Β Β Β Β Β Β Β Β 0Β 1Β 0
Β Β Β Β Β Β Β Β Β Β 0
Your task is to determine the way the handkerchief will look like by the given n.
Input
The first line contains the single integer n (2 β€ n β€ 9).
Output
Print a picture for the given n. You should strictly observe the number of spaces before the first digit on each line. Every two adjacent digits in the same line should be separated by exactly one space. There should be no spaces after the last digit at the end of each line.
Examples
Input
2
Output
0
0 1 0
0 1 2 1 0
0 1 0
0
Input
3
Output
0
0 1 0
0 1 2 1 0
0 1 2 3 2 1 0
0 1 2 1 0
0 1 0
0 | instruction | 0 | 74,243 | 14 | 148,486 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n = int(input())
for i in range(n + n + 1):
result = ''
for j in range(n + n + 1):
if i <= n:
if j >= n - i and j <= n:
if j == 0:
result += str(abs(n - j - i))
else:
if n - j - i == 0:
result += str(abs(n - j - i))
else:
result += ' ' + str(abs(n - j - i))
elif j <= n + i and j >= n :
result += ' ' + str(abs(n - j + i))
else:
if j > n:
result += ''
else:
result += ' '
else:
w = 2*n - i
if j >= n - w and j <= n :
if n - j - w == 0:
result += str(abs(n - j - w))
else:
result += ' ' + str(abs(n - j - w))
elif j <= n + w and j >= n:
result += ' ' + str(abs(n - j + w))
else:
if j > n:
result += ''
else:
result += ' '
print(result)
``` | output | 1 | 74,243 | 14 | 148,487 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to n as the pattern. The digits will form a rhombus. The largest digit n should be located in the centre. The digits should decrease as they approach the edges. For example, for n = 5 the handkerchief pattern should look like that:
Β Β Β Β Β Β Β Β Β Β 0
Β Β Β Β Β Β Β Β 0Β 1Β 0
Β Β Β Β Β Β 0Β 1Β 2Β 1Β 0
Β Β Β Β 0Β 1Β 2Β 3Β 2Β 1Β 0
Β Β 0Β 1Β 2Β 3Β 4Β 3Β 2Β 1Β 0
0Β 1Β 2Β 3Β 4Β 5Β 4Β 3Β 2Β 1Β 0
Β Β 0Β 1Β 2Β 3Β 4Β 3Β 2Β 1Β 0
Β Β Β Β 0Β 1Β 2Β 3Β 2Β 1Β 0
Β Β Β Β Β Β 0Β 1Β 2Β 1Β 0
Β Β Β Β Β Β Β Β 0Β 1Β 0
Β Β Β Β Β Β Β Β Β Β 0
Your task is to determine the way the handkerchief will look like by the given n.
Input
The first line contains the single integer n (2 β€ n β€ 9).
Output
Print a picture for the given n. You should strictly observe the number of spaces before the first digit on each line. Every two adjacent digits in the same line should be separated by exactly one space. There should be no spaces after the last digit at the end of each line.
Examples
Input
2
Output
0
0 1 0
0 1 2 1 0
0 1 0
0
Input
3
Output
0
0 1 0
0 1 2 1 0
0 1 2 3 2 1 0
0 1 2 1 0
0 1 0
0 | instruction | 0 | 74,244 | 14 | 148,488 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n=int(input())
for i in range(n):
s=[]
for j in range(i):
s.append(str(j))
s = s + [str(i)] + s[::-1]
print(' '.join(s).center(4*n+1).rstrip())
s=[]
for i in range(n):
s.append(i)
s = s + [str(i+1)]+s[::-1]
print(' '.join([str(i) for i in s]))
for i in range(n-1,-1,-1):
s=[]
for j in range(i):
s.append(str(j))
s = s + [str(i)] + s[::-1]
print(' '.join(s).center(4*n+1).rstrip())
``` | output | 1 | 74,244 | 14 | 148,489 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to n as the pattern. The digits will form a rhombus. The largest digit n should be located in the centre. The digits should decrease as they approach the edges. For example, for n = 5 the handkerchief pattern should look like that:
Β Β Β Β Β Β Β Β Β Β 0
Β Β Β Β Β Β Β Β 0Β 1Β 0
Β Β Β Β Β Β 0Β 1Β 2Β 1Β 0
Β Β Β Β 0Β 1Β 2Β 3Β 2Β 1Β 0
Β Β 0Β 1Β 2Β 3Β 4Β 3Β 2Β 1Β 0
0Β 1Β 2Β 3Β 4Β 5Β 4Β 3Β 2Β 1Β 0
Β Β 0Β 1Β 2Β 3Β 4Β 3Β 2Β 1Β 0
Β Β Β Β 0Β 1Β 2Β 3Β 2Β 1Β 0
Β Β Β Β Β Β 0Β 1Β 2Β 1Β 0
Β Β Β Β Β Β Β Β 0Β 1Β 0
Β Β Β Β Β Β Β Β Β Β 0
Your task is to determine the way the handkerchief will look like by the given n.
Input
The first line contains the single integer n (2 β€ n β€ 9).
Output
Print a picture for the given n. You should strictly observe the number of spaces before the first digit on each line. Every two adjacent digits in the same line should be separated by exactly one space. There should be no spaces after the last digit at the end of each line.
Examples
Input
2
Output
0
0 1 0
0 1 2 1 0
0 1 0
0
Input
3
Output
0
0 1 0
0 1 2 1 0
0 1 2 3 2 1 0
0 1 2 1 0
0 1 0
0 | instruction | 0 | 74,245 | 14 | 148,490 |
Tags: constructive algorithms, implementation
Correct Solution:
```
n = int(input())
arr = [[0]]
rev = []
for i in range(1,n+1):
tmp = [0]
for j in range(1,i+1):
tmp.append(j)
for j in range(i-1,0,-1):
tmp.append(j)
tmp.append(0)
if i != n:
rev.append(tmp)
arr.append(tmp)
rev = rev[::-1]
rev.append([0])
tmp = n
for i in range(n+1):
for j in range(tmp):
print(" ",end = " ")
print(*arr[i])
tmp -= 1
tmp = 1
for i in range(n):
for j in range(tmp):
print(" ",end = " ")
print(*rev[i])
tmp += 1
``` | output | 1 | 74,245 | 14 | 148,491 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to n as the pattern. The digits will form a rhombus. The largest digit n should be located in the centre. The digits should decrease as they approach the edges. For example, for n = 5 the handkerchief pattern should look like that:
Β Β Β Β Β Β Β Β Β Β 0
Β Β Β Β Β Β Β Β 0Β 1Β 0
Β Β Β Β Β Β 0Β 1Β 2Β 1Β 0
Β Β Β Β 0Β 1Β 2Β 3Β 2Β 1Β 0
Β Β 0Β 1Β 2Β 3Β 4Β 3Β 2Β 1Β 0
0Β 1Β 2Β 3Β 4Β 5Β 4Β 3Β 2Β 1Β 0
Β Β 0Β 1Β 2Β 3Β 4Β 3Β 2Β 1Β 0
Β Β Β Β 0Β 1Β 2Β 3Β 2Β 1Β 0
Β Β Β Β Β Β 0Β 1Β 2Β 1Β 0
Β Β Β Β Β Β Β Β 0Β 1Β 0
Β Β Β Β Β Β Β Β Β Β 0
Your task is to determine the way the handkerchief will look like by the given n.
Input
The first line contains the single integer n (2 β€ n β€ 9).
Output
Print a picture for the given n. You should strictly observe the number of spaces before the first digit on each line. Every two adjacent digits in the same line should be separated by exactly one space. There should be no spaces after the last digit at the end of each line.
Examples
Input
2
Output
0
0 1 0
0 1 2 1 0
0 1 0
0
Input
3
Output
0
0 1 0
0 1 2 1 0
0 1 2 3 2 1 0
0 1 2 1 0
0 1 0
0 | instruction | 0 | 74,246 | 14 | 148,492 |
Tags: constructive algorithms, implementation
Correct Solution:
```
a = int(input())
for itema in range(a):
print(" " * 2 * (a - itema) + " ".join([str(item) for item in range(itema+1)] + [str(item) for item in range(itema)][::-1]))
print(" ".join([str(item) for item in range(a+1)] + [str(item) for item in range(a)][::-1]))
for itema in range(a):
print(" " * 2 *(itema+1) + " ".join([str(item) for item in range(a-(itema+1))] + [str(item) for item in range(a-(itema))][::-1]))
``` | output | 1 | 74,246 | 14 | 148,493 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do n chores. Each chore is characterized by a single parameter β its complexity. The complexity of the i-th chore equals hi.
As Petya is older, he wants to take the chores with complexity larger than some value x (hi > x) to leave to Vasya the chores with complexity less than or equal to x (hi β€ x). The brothers have already decided that Petya will do exactly a chores and Vasya will do exactly b chores (a + b = n).
In how many ways can they choose an integer x so that Petya got exactly a chores and Vasya got exactly b chores?
Input
The first input line contains three integers n, a and b (2 β€ n β€ 2000; a, b β₯ 1; a + b = n) β the total number of chores, the number of Petya's chores and the number of Vasya's chores.
The next line contains a sequence of integers h1, h2, ..., hn (1 β€ hi β€ 109), hi is the complexity of the i-th chore. The numbers in the given sequence are not necessarily different.
All numbers on the lines are separated by single spaces.
Output
Print the required number of ways to choose an integer value of x. If there are no such ways, print 0.
Examples
Input
5 2 3
6 2 3 100 1
Output
3
Input
7 3 4
1 1 9 1 1 1 1
Output
0
Note
In the first sample the possible values of x are 3, 4 or 5.
In the second sample it is impossible to find such x, that Petya got 3 chores and Vasya got 4. | instruction | 0 | 74,450 | 14 | 148,900 |
Tags: sortings
Correct Solution:
```
input1 = list(map(int,input().split()))
numberOfChores = input1[0]
numberOfPetyaChores = input1[1]
numberOfVasyaChores = input1[2]
choresComplexities = list(map(int, input().split()))
choresComplexities.sort()
numberOfWayToChooseN = choresComplexities[numberOfVasyaChores] - choresComplexities[numberOfVasyaChores - 1]
print(numberOfWayToChooseN)
``` | output | 1 | 74,450 | 14 | 148,901 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do n chores. Each chore is characterized by a single parameter β its complexity. The complexity of the i-th chore equals hi.
As Petya is older, he wants to take the chores with complexity larger than some value x (hi > x) to leave to Vasya the chores with complexity less than or equal to x (hi β€ x). The brothers have already decided that Petya will do exactly a chores and Vasya will do exactly b chores (a + b = n).
In how many ways can they choose an integer x so that Petya got exactly a chores and Vasya got exactly b chores?
Input
The first input line contains three integers n, a and b (2 β€ n β€ 2000; a, b β₯ 1; a + b = n) β the total number of chores, the number of Petya's chores and the number of Vasya's chores.
The next line contains a sequence of integers h1, h2, ..., hn (1 β€ hi β€ 109), hi is the complexity of the i-th chore. The numbers in the given sequence are not necessarily different.
All numbers on the lines are separated by single spaces.
Output
Print the required number of ways to choose an integer value of x. If there are no such ways, print 0.
Examples
Input
5 2 3
6 2 3 100 1
Output
3
Input
7 3 4
1 1 9 1 1 1 1
Output
0
Note
In the first sample the possible values of x are 3, 4 or 5.
In the second sample it is impossible to find such x, that Petya got 3 chores and Vasya got 4. | instruction | 0 | 74,451 | 14 | 148,902 |
Tags: sortings
Correct Solution:
```
n,a,b=list(map(int, input().split()))
h = list(map(int, input().split()))
h.sort()
print(h[0-a]-h[b-1])
``` | output | 1 | 74,451 | 14 | 148,903 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do n chores. Each chore is characterized by a single parameter β its complexity. The complexity of the i-th chore equals hi.
As Petya is older, he wants to take the chores with complexity larger than some value x (hi > x) to leave to Vasya the chores with complexity less than or equal to x (hi β€ x). The brothers have already decided that Petya will do exactly a chores and Vasya will do exactly b chores (a + b = n).
In how many ways can they choose an integer x so that Petya got exactly a chores and Vasya got exactly b chores?
Input
The first input line contains three integers n, a and b (2 β€ n β€ 2000; a, b β₯ 1; a + b = n) β the total number of chores, the number of Petya's chores and the number of Vasya's chores.
The next line contains a sequence of integers h1, h2, ..., hn (1 β€ hi β€ 109), hi is the complexity of the i-th chore. The numbers in the given sequence are not necessarily different.
All numbers on the lines are separated by single spaces.
Output
Print the required number of ways to choose an integer value of x. If there are no such ways, print 0.
Examples
Input
5 2 3
6 2 3 100 1
Output
3
Input
7 3 4
1 1 9 1 1 1 1
Output
0
Note
In the first sample the possible values of x are 3, 4 or 5.
In the second sample it is impossible to find such x, that Petya got 3 chores and Vasya got 4. | instruction | 0 | 74,452 | 14 | 148,904 |
Tags: sortings
Correct Solution:
```
n, a, b = map(int,input().split())
h = list(map(int,input().split()))
h.sort()
c = h[b] - h[b - 1]
print(c)
``` | output | 1 | 74,452 | 14 | 148,905 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do n chores. Each chore is characterized by a single parameter β its complexity. The complexity of the i-th chore equals hi.
As Petya is older, he wants to take the chores with complexity larger than some value x (hi > x) to leave to Vasya the chores with complexity less than or equal to x (hi β€ x). The brothers have already decided that Petya will do exactly a chores and Vasya will do exactly b chores (a + b = n).
In how many ways can they choose an integer x so that Petya got exactly a chores and Vasya got exactly b chores?
Input
The first input line contains three integers n, a and b (2 β€ n β€ 2000; a, b β₯ 1; a + b = n) β the total number of chores, the number of Petya's chores and the number of Vasya's chores.
The next line contains a sequence of integers h1, h2, ..., hn (1 β€ hi β€ 109), hi is the complexity of the i-th chore. The numbers in the given sequence are not necessarily different.
All numbers on the lines are separated by single spaces.
Output
Print the required number of ways to choose an integer value of x. If there are no such ways, print 0.
Examples
Input
5 2 3
6 2 3 100 1
Output
3
Input
7 3 4
1 1 9 1 1 1 1
Output
0
Note
In the first sample the possible values of x are 3, 4 or 5.
In the second sample it is impossible to find such x, that Petya got 3 chores and Vasya got 4. | instruction | 0 | 74,453 | 14 | 148,906 |
Tags: sortings
Correct Solution:
```
n,a,b = tuple(map(int, input().strip().split()))
h = list(map(int, input().strip().split()))
def insertionsort(lst):
for i in range(1,len(lst)):
val = lst[i]
for j in range(0, i):
if lst[j] < val:
tmp = lst[j]
lst[j] = val
val = tmp
lst[i] = val
return lst
h = insertionsort(h)
print(abs(h[a-1]-h[a]))
``` | output | 1 | 74,453 | 14 | 148,907 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do n chores. Each chore is characterized by a single parameter β its complexity. The complexity of the i-th chore equals hi.
As Petya is older, he wants to take the chores with complexity larger than some value x (hi > x) to leave to Vasya the chores with complexity less than or equal to x (hi β€ x). The brothers have already decided that Petya will do exactly a chores and Vasya will do exactly b chores (a + b = n).
In how many ways can they choose an integer x so that Petya got exactly a chores and Vasya got exactly b chores?
Input
The first input line contains three integers n, a and b (2 β€ n β€ 2000; a, b β₯ 1; a + b = n) β the total number of chores, the number of Petya's chores and the number of Vasya's chores.
The next line contains a sequence of integers h1, h2, ..., hn (1 β€ hi β€ 109), hi is the complexity of the i-th chore. The numbers in the given sequence are not necessarily different.
All numbers on the lines are separated by single spaces.
Output
Print the required number of ways to choose an integer value of x. If there are no such ways, print 0.
Examples
Input
5 2 3
6 2 3 100 1
Output
3
Input
7 3 4
1 1 9 1 1 1 1
Output
0
Note
In the first sample the possible values of x are 3, 4 or 5.
In the second sample it is impossible to find such x, that Petya got 3 chores and Vasya got 4. | instruction | 0 | 74,454 | 14 | 148,908 |
Tags: sortings
Correct Solution:
```
n,a,b = map(int, input().split())
h = list(map(int, input().split()))
h.sort(reverse=True)
ans = h[a-1] - h[a]
print(ans)
``` | output | 1 | 74,454 | 14 | 148,909 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do n chores. Each chore is characterized by a single parameter β its complexity. The complexity of the i-th chore equals hi.
As Petya is older, he wants to take the chores with complexity larger than some value x (hi > x) to leave to Vasya the chores with complexity less than or equal to x (hi β€ x). The brothers have already decided that Petya will do exactly a chores and Vasya will do exactly b chores (a + b = n).
In how many ways can they choose an integer x so that Petya got exactly a chores and Vasya got exactly b chores?
Input
The first input line contains three integers n, a and b (2 β€ n β€ 2000; a, b β₯ 1; a + b = n) β the total number of chores, the number of Petya's chores and the number of Vasya's chores.
The next line contains a sequence of integers h1, h2, ..., hn (1 β€ hi β€ 109), hi is the complexity of the i-th chore. The numbers in the given sequence are not necessarily different.
All numbers on the lines are separated by single spaces.
Output
Print the required number of ways to choose an integer value of x. If there are no such ways, print 0.
Examples
Input
5 2 3
6 2 3 100 1
Output
3
Input
7 3 4
1 1 9 1 1 1 1
Output
0
Note
In the first sample the possible values of x are 3, 4 or 5.
In the second sample it is impossible to find such x, that Petya got 3 chores and Vasya got 4. | instruction | 0 | 74,455 | 14 | 148,910 |
Tags: sortings
Correct Solution:
```
# Codeforces: 169A - Chores
n, a, b = map(int, input().split())
h = list(map(int, input().split()))
h.sort()
ans = h[b] - h[b - 1]
print(ans)
``` | output | 1 | 74,455 | 14 | 148,911 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do n chores. Each chore is characterized by a single parameter β its complexity. The complexity of the i-th chore equals hi.
As Petya is older, he wants to take the chores with complexity larger than some value x (hi > x) to leave to Vasya the chores with complexity less than or equal to x (hi β€ x). The brothers have already decided that Petya will do exactly a chores and Vasya will do exactly b chores (a + b = n).
In how many ways can they choose an integer x so that Petya got exactly a chores and Vasya got exactly b chores?
Input
The first input line contains three integers n, a and b (2 β€ n β€ 2000; a, b β₯ 1; a + b = n) β the total number of chores, the number of Petya's chores and the number of Vasya's chores.
The next line contains a sequence of integers h1, h2, ..., hn (1 β€ hi β€ 109), hi is the complexity of the i-th chore. The numbers in the given sequence are not necessarily different.
All numbers on the lines are separated by single spaces.
Output
Print the required number of ways to choose an integer value of x. If there are no such ways, print 0.
Examples
Input
5 2 3
6 2 3 100 1
Output
3
Input
7 3 4
1 1 9 1 1 1 1
Output
0
Note
In the first sample the possible values of x are 3, 4 or 5.
In the second sample it is impossible to find such x, that Petya got 3 chores and Vasya got 4. | instruction | 0 | 74,456 | 14 | 148,912 |
Tags: sortings
Correct Solution:
```
a=list(map(int, input().split()))
b=list(map(int, input().split()))
h=sorted(b,reverse=True)
print(h[a[1]-1]-h[a[1]])
``` | output | 1 | 74,456 | 14 | 148,913 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do n chores. Each chore is characterized by a single parameter β its complexity. The complexity of the i-th chore equals hi.
As Petya is older, he wants to take the chores with complexity larger than some value x (hi > x) to leave to Vasya the chores with complexity less than or equal to x (hi β€ x). The brothers have already decided that Petya will do exactly a chores and Vasya will do exactly b chores (a + b = n).
In how many ways can they choose an integer x so that Petya got exactly a chores and Vasya got exactly b chores?
Input
The first input line contains three integers n, a and b (2 β€ n β€ 2000; a, b β₯ 1; a + b = n) β the total number of chores, the number of Petya's chores and the number of Vasya's chores.
The next line contains a sequence of integers h1, h2, ..., hn (1 β€ hi β€ 109), hi is the complexity of the i-th chore. The numbers in the given sequence are not necessarily different.
All numbers on the lines are separated by single spaces.
Output
Print the required number of ways to choose an integer value of x. If there are no such ways, print 0.
Examples
Input
5 2 3
6 2 3 100 1
Output
3
Input
7 3 4
1 1 9 1 1 1 1
Output
0
Note
In the first sample the possible values of x are 3, 4 or 5.
In the second sample it is impossible to find such x, that Petya got 3 chores and Vasya got 4. | instruction | 0 | 74,457 | 14 | 148,914 |
Tags: sortings
Correct Solution:
```
a,b,c=map(int,input().split())
d=list(map(int,input().split()))
d.sort(reverse=True)
print(d[b-1]-d[b])
``` | output | 1 | 74,457 | 14 | 148,915 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do n chores. Each chore is characterized by a single parameter β its complexity. The complexity of the i-th chore equals hi.
As Petya is older, he wants to take the chores with complexity larger than some value x (hi > x) to leave to Vasya the chores with complexity less than or equal to x (hi β€ x). The brothers have already decided that Petya will do exactly a chores and Vasya will do exactly b chores (a + b = n).
In how many ways can they choose an integer x so that Petya got exactly a chores and Vasya got exactly b chores?
Input
The first input line contains three integers n, a and b (2 β€ n β€ 2000; a, b β₯ 1; a + b = n) β the total number of chores, the number of Petya's chores and the number of Vasya's chores.
The next line contains a sequence of integers h1, h2, ..., hn (1 β€ hi β€ 109), hi is the complexity of the i-th chore. The numbers in the given sequence are not necessarily different.
All numbers on the lines are separated by single spaces.
Output
Print the required number of ways to choose an integer value of x. If there are no such ways, print 0.
Examples
Input
5 2 3
6 2 3 100 1
Output
3
Input
7 3 4
1 1 9 1 1 1 1
Output
0
Note
In the first sample the possible values of x are 3, 4 or 5.
In the second sample it is impossible to find such x, that Petya got 3 chores and Vasya got 4.
Submitted Solution:
```
# Problem from Codeforces
# http://codeforces.com/problemset/problem/169/A
n, a, b = map(int, input().split())
h = list(map(int, input().split()))
h.sort()
print(h[b] - h[b - 1])
``` | instruction | 0 | 74,458 | 14 | 148,916 |
Yes | output | 1 | 74,458 | 14 | 148,917 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do n chores. Each chore is characterized by a single parameter β its complexity. The complexity of the i-th chore equals hi.
As Petya is older, he wants to take the chores with complexity larger than some value x (hi > x) to leave to Vasya the chores with complexity less than or equal to x (hi β€ x). The brothers have already decided that Petya will do exactly a chores and Vasya will do exactly b chores (a + b = n).
In how many ways can they choose an integer x so that Petya got exactly a chores and Vasya got exactly b chores?
Input
The first input line contains three integers n, a and b (2 β€ n β€ 2000; a, b β₯ 1; a + b = n) β the total number of chores, the number of Petya's chores and the number of Vasya's chores.
The next line contains a sequence of integers h1, h2, ..., hn (1 β€ hi β€ 109), hi is the complexity of the i-th chore. The numbers in the given sequence are not necessarily different.
All numbers on the lines are separated by single spaces.
Output
Print the required number of ways to choose an integer value of x. If there are no such ways, print 0.
Examples
Input
5 2 3
6 2 3 100 1
Output
3
Input
7 3 4
1 1 9 1 1 1 1
Output
0
Note
In the first sample the possible values of x are 3, 4 or 5.
In the second sample it is impossible to find such x, that Petya got 3 chores and Vasya got 4.
Submitted Solution:
```
s = list(map(int,input().split()))
e = list(map(int,input().split()))
q = 0
p = 0
e.sort(reverse = True)
for i in range(0,s[1]):
p = e[i]
q = e[i+1]
p -= q
if (e.count(min(e))>=len(e)-(s[1]-1)) and (len(e)!=2):
print('0')
else:
print(p)
``` | instruction | 0 | 74,459 | 14 | 148,918 |
Yes | output | 1 | 74,459 | 14 | 148,919 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do n chores. Each chore is characterized by a single parameter β its complexity. The complexity of the i-th chore equals hi.
As Petya is older, he wants to take the chores with complexity larger than some value x (hi > x) to leave to Vasya the chores with complexity less than or equal to x (hi β€ x). The brothers have already decided that Petya will do exactly a chores and Vasya will do exactly b chores (a + b = n).
In how many ways can they choose an integer x so that Petya got exactly a chores and Vasya got exactly b chores?
Input
The first input line contains three integers n, a and b (2 β€ n β€ 2000; a, b β₯ 1; a + b = n) β the total number of chores, the number of Petya's chores and the number of Vasya's chores.
The next line contains a sequence of integers h1, h2, ..., hn (1 β€ hi β€ 109), hi is the complexity of the i-th chore. The numbers in the given sequence are not necessarily different.
All numbers on the lines are separated by single spaces.
Output
Print the required number of ways to choose an integer value of x. If there are no such ways, print 0.
Examples
Input
5 2 3
6 2 3 100 1
Output
3
Input
7 3 4
1 1 9 1 1 1 1
Output
0
Note
In the first sample the possible values of x are 3, 4 or 5.
In the second sample it is impossible to find such x, that Petya got 3 chores and Vasya got 4.
Submitted Solution:
```
def inp(): return map(int, input().split())
n,a,b = inp()
h = list(inp())
h.sort()
print(h[b] - h[b-1])
``` | instruction | 0 | 74,460 | 14 | 148,920 |
Yes | output | 1 | 74,460 | 14 | 148,921 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do n chores. Each chore is characterized by a single parameter β its complexity. The complexity of the i-th chore equals hi.
As Petya is older, he wants to take the chores with complexity larger than some value x (hi > x) to leave to Vasya the chores with complexity less than or equal to x (hi β€ x). The brothers have already decided that Petya will do exactly a chores and Vasya will do exactly b chores (a + b = n).
In how many ways can they choose an integer x so that Petya got exactly a chores and Vasya got exactly b chores?
Input
The first input line contains three integers n, a and b (2 β€ n β€ 2000; a, b β₯ 1; a + b = n) β the total number of chores, the number of Petya's chores and the number of Vasya's chores.
The next line contains a sequence of integers h1, h2, ..., hn (1 β€ hi β€ 109), hi is the complexity of the i-th chore. The numbers in the given sequence are not necessarily different.
All numbers on the lines are separated by single spaces.
Output
Print the required number of ways to choose an integer value of x. If there are no such ways, print 0.
Examples
Input
5 2 3
6 2 3 100 1
Output
3
Input
7 3 4
1 1 9 1 1 1 1
Output
0
Note
In the first sample the possible values of x are 3, 4 or 5.
In the second sample it is impossible to find such x, that Petya got 3 chores and Vasya got 4.
Submitted Solution:
```
n, a, b = map(int, input().split())
arr = sorted(list(map(int, input().split())))
print(arr[b] - arr[b - 1])
``` | instruction | 0 | 74,461 | 14 | 148,922 |
Yes | output | 1 | 74,461 | 14 | 148,923 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do n chores. Each chore is characterized by a single parameter β its complexity. The complexity of the i-th chore equals hi.
As Petya is older, he wants to take the chores with complexity larger than some value x (hi > x) to leave to Vasya the chores with complexity less than or equal to x (hi β€ x). The brothers have already decided that Petya will do exactly a chores and Vasya will do exactly b chores (a + b = n).
In how many ways can they choose an integer x so that Petya got exactly a chores and Vasya got exactly b chores?
Input
The first input line contains three integers n, a and b (2 β€ n β€ 2000; a, b β₯ 1; a + b = n) β the total number of chores, the number of Petya's chores and the number of Vasya's chores.
The next line contains a sequence of integers h1, h2, ..., hn (1 β€ hi β€ 109), hi is the complexity of the i-th chore. The numbers in the given sequence are not necessarily different.
All numbers on the lines are separated by single spaces.
Output
Print the required number of ways to choose an integer value of x. If there are no such ways, print 0.
Examples
Input
5 2 3
6 2 3 100 1
Output
3
Input
7 3 4
1 1 9 1 1 1 1
Output
0
Note
In the first sample the possible values of x are 3, 4 or 5.
In the second sample it is impossible to find such x, that Petya got 3 chores and Vasya got 4.
Submitted Solution:
```
s = list(map(int,input().split()))
e = list(map(int,input().split()))
q = 0
p = 0
e.sort(reverse = True)
for i in range(0,s[1]):
p = e[i]
q = e[i+1]
p -= q
if (e.count(min(e))>=len(e)-s[1]-1) and (len(e)!=2):
print('0')
else:
print(p)
``` | instruction | 0 | 74,462 | 14 | 148,924 |
No | output | 1 | 74,462 | 14 | 148,925 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do n chores. Each chore is characterized by a single parameter β its complexity. The complexity of the i-th chore equals hi.
As Petya is older, he wants to take the chores with complexity larger than some value x (hi > x) to leave to Vasya the chores with complexity less than or equal to x (hi β€ x). The brothers have already decided that Petya will do exactly a chores and Vasya will do exactly b chores (a + b = n).
In how many ways can they choose an integer x so that Petya got exactly a chores and Vasya got exactly b chores?
Input
The first input line contains three integers n, a and b (2 β€ n β€ 2000; a, b β₯ 1; a + b = n) β the total number of chores, the number of Petya's chores and the number of Vasya's chores.
The next line contains a sequence of integers h1, h2, ..., hn (1 β€ hi β€ 109), hi is the complexity of the i-th chore. The numbers in the given sequence are not necessarily different.
All numbers on the lines are separated by single spaces.
Output
Print the required number of ways to choose an integer value of x. If there are no such ways, print 0.
Examples
Input
5 2 3
6 2 3 100 1
Output
3
Input
7 3 4
1 1 9 1 1 1 1
Output
0
Note
In the first sample the possible values of x are 3, 4 or 5.
In the second sample it is impossible to find such x, that Petya got 3 chores and Vasya got 4.
Submitted Solution:
```
# Problem: A. Chores
# Contest: Codeforces - VK Cup 2012 Round 2 (Unofficial Div. 2 Edition)
# URL: https://codeforces.com/problemset/problem/169/A
# Memory Limit: 256 MB
# Time Limit: 2000 ms
# Powered by CP Editor (https://github.com/cpeditor/cpeditor)
n,a,b=input().split()
a=int(a)
n=int(n)
b=int(b)
l=list(map(int,input().split()))
l.sort()
if l[b]==l[b-1]:
print(0)
else:
print((l[b-1]+l[b])//2)
``` | instruction | 0 | 74,463 | 14 | 148,926 |
No | output | 1 | 74,463 | 14 | 148,927 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do n chores. Each chore is characterized by a single parameter β its complexity. The complexity of the i-th chore equals hi.
As Petya is older, he wants to take the chores with complexity larger than some value x (hi > x) to leave to Vasya the chores with complexity less than or equal to x (hi β€ x). The brothers have already decided that Petya will do exactly a chores and Vasya will do exactly b chores (a + b = n).
In how many ways can they choose an integer x so that Petya got exactly a chores and Vasya got exactly b chores?
Input
The first input line contains three integers n, a and b (2 β€ n β€ 2000; a, b β₯ 1; a + b = n) β the total number of chores, the number of Petya's chores and the number of Vasya's chores.
The next line contains a sequence of integers h1, h2, ..., hn (1 β€ hi β€ 109), hi is the complexity of the i-th chore. The numbers in the given sequence are not necessarily different.
All numbers on the lines are separated by single spaces.
Output
Print the required number of ways to choose an integer value of x. If there are no such ways, print 0.
Examples
Input
5 2 3
6 2 3 100 1
Output
3
Input
7 3 4
1 1 9 1 1 1 1
Output
0
Note
In the first sample the possible values of x are 3, 4 or 5.
In the second sample it is impossible to find such x, that Petya got 3 chores and Vasya got 4.
Submitted Solution:
```
n,a,b=map(int,input().split())
s=list(map(int,input().split()))
s.sort()
if s[b-1]<s[b]:
print(s[b-1],end="")
else:
print(0,end="")
``` | instruction | 0 | 74,464 | 14 | 148,928 |
No | output | 1 | 74,464 | 14 | 148,929 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do n chores. Each chore is characterized by a single parameter β its complexity. The complexity of the i-th chore equals hi.
As Petya is older, he wants to take the chores with complexity larger than some value x (hi > x) to leave to Vasya the chores with complexity less than or equal to x (hi β€ x). The brothers have already decided that Petya will do exactly a chores and Vasya will do exactly b chores (a + b = n).
In how many ways can they choose an integer x so that Petya got exactly a chores and Vasya got exactly b chores?
Input
The first input line contains three integers n, a and b (2 β€ n β€ 2000; a, b β₯ 1; a + b = n) β the total number of chores, the number of Petya's chores and the number of Vasya's chores.
The next line contains a sequence of integers h1, h2, ..., hn (1 β€ hi β€ 109), hi is the complexity of the i-th chore. The numbers in the given sequence are not necessarily different.
All numbers on the lines are separated by single spaces.
Output
Print the required number of ways to choose an integer value of x. If there are no such ways, print 0.
Examples
Input
5 2 3
6 2 3 100 1
Output
3
Input
7 3 4
1 1 9 1 1 1 1
Output
0
Note
In the first sample the possible values of x are 3, 4 or 5.
In the second sample it is impossible to find such x, that Petya got 3 chores and Vasya got 4.
Submitted Solution:
```
nab = list(map(int, input().split()))
n = nab[0]
a = nab[1]
b = nab[2]
nums = list(map(int, input().split()))
nums.sort()
if b - 2 >= 2:
print(nums[b - 1] - nums[b - 2])
else:
print(nums[b - 1])
``` | instruction | 0 | 74,465 | 14 | 148,930 |
No | output | 1 | 74,465 | 14 | 148,931 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Maxim has opened his own restaurant! The restaurant has got a huge table, the table's length is p meters.
Maxim has got a dinner party tonight, n guests will come to him. Let's index the guests of Maxim's restaurant from 1 to n. Maxim knows the sizes of all guests that are going to come to him. The i-th guest's size (ai) represents the number of meters the guest is going to take up if he sits at the restaurant table.
Long before the dinner, the guests line up in a queue in front of the restaurant in some order. Then Maxim lets the guests in, one by one. Maxim stops letting the guests in when there is no place at the restaurant table for another guest in the queue. There is no place at the restaurant table for another guest in the queue, if the sum of sizes of all guests in the restaurant plus the size of this guest from the queue is larger than p. In this case, not to offend the guest who has no place at the table, Maxim doesn't let any other guest in the restaurant, even if one of the following guests in the queue would have fit in at the table.
Maxim is now wondering, what is the average number of visitors who have come to the restaurant for all possible n! orders of guests in the queue. Help Maxim, calculate this number.
Input
The first line contains integer n (1 β€ n β€ 50) β the number of guests in the restaurant. The next line contains integers a1, a2, ..., an (1 β€ ai β€ 50) β the guests' sizes in meters. The third line contains integer p (1 β€ p β€ 50) β the table's length in meters.
The numbers in the lines are separated by single spaces.
Output
In a single line print a real number β the answer to the problem. The answer will be considered correct, if the absolute or relative error doesn't exceed 10 - 4.
Examples
Input
3
1 2 3
3
Output
1.3333333333
Note
In the first sample the people will come in the following orders:
* (1, 2, 3) β there will be two people in the restaurant;
* (1, 3, 2) β there will be one person in the restaurant;
* (2, 1, 3) β there will be two people in the restaurant;
* (2, 3, 1) β there will be one person in the restaurant;
* (3, 1, 2) β there will be one person in the restaurant;
* (3, 2, 1) β there will be one person in the restaurant.
In total we get (2 + 1 + 2 + 1 + 1 + 1) / 6 = 8 / 6 = 1.(3). | instruction | 0 | 74,466 | 14 | 148,932 |
Tags: dp, math, probabilities
Correct Solution:
```
n=int(input())
b=list(map(int,input().split()))
p=int(input())
dp=[[0 for j in range(51)] for i in range(51)]
dp[0][0]=1
fac=[1]
for i in range(1,51):
fac.append(fac[-1]*i)
for i in range(n):
k=i+1
while(k>=1):
for s in range(b[i],p+1):
dp[k][s]+=dp[k-1][s-b[i]]
k+=-1
ans=0
for i in range(1,n+1):
for j in range(1,p+1):
ans=(ans+(dp[i][j]*fac[i]*fac[n-i]))
print(ans/fac[n])
``` | output | 1 | 74,466 | 14 | 148,933 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Maxim has opened his own restaurant! The restaurant has got a huge table, the table's length is p meters.
Maxim has got a dinner party tonight, n guests will come to him. Let's index the guests of Maxim's restaurant from 1 to n. Maxim knows the sizes of all guests that are going to come to him. The i-th guest's size (ai) represents the number of meters the guest is going to take up if he sits at the restaurant table.
Long before the dinner, the guests line up in a queue in front of the restaurant in some order. Then Maxim lets the guests in, one by one. Maxim stops letting the guests in when there is no place at the restaurant table for another guest in the queue. There is no place at the restaurant table for another guest in the queue, if the sum of sizes of all guests in the restaurant plus the size of this guest from the queue is larger than p. In this case, not to offend the guest who has no place at the table, Maxim doesn't let any other guest in the restaurant, even if one of the following guests in the queue would have fit in at the table.
Maxim is now wondering, what is the average number of visitors who have come to the restaurant for all possible n! orders of guests in the queue. Help Maxim, calculate this number.
Input
The first line contains integer n (1 β€ n β€ 50) β the number of guests in the restaurant. The next line contains integers a1, a2, ..., an (1 β€ ai β€ 50) β the guests' sizes in meters. The third line contains integer p (1 β€ p β€ 50) β the table's length in meters.
The numbers in the lines are separated by single spaces.
Output
In a single line print a real number β the answer to the problem. The answer will be considered correct, if the absolute or relative error doesn't exceed 10 - 4.
Examples
Input
3
1 2 3
3
Output
1.3333333333
Note
In the first sample the people will come in the following orders:
* (1, 2, 3) β there will be two people in the restaurant;
* (1, 3, 2) β there will be one person in the restaurant;
* (2, 1, 3) β there will be two people in the restaurant;
* (2, 3, 1) β there will be one person in the restaurant;
* (3, 1, 2) β there will be one person in the restaurant;
* (3, 2, 1) β there will be one person in the restaurant.
In total we get (2 + 1 + 2 + 1 + 1 + 1) / 6 = 8 / 6 = 1.(3). | instruction | 0 | 74,467 | 14 | 148,934 |
Tags: dp, math, probabilities
Correct Solution:
```
n = input()
n = int(n)
arr = [0] * n
fact = [0] * 51
a = input().split()
p = input()
p = int(p)
for i in range(n):
arr[i] = int(a[i])
if n == 1:
if arr[0] <= p:
print(1)
else:
print(0)
exit(0)
def pre():
fact[0] = 1
for i in range(1, 51):
fact[i] = fact[i - 1] * i
def get(arr, min_sum, max_sum):
ways = [[0 for i in range(max_sum + 1)] for i in range(len(arr) + 1)]
ways[0][0] = 1
for i in range(len(arr)):
for j in range(i, -1, -1):
for k in range(max_sum, -1, -1):
if k + arr[i] <= max_sum:
ways[j + 1][k + arr[i]] += ways[j][k]
ans = 0
counted = 0
for i in range(0, len(arr) + 1):
for j in range(min_sum, max_sum + 1):
ans += fact[i] * fact[n - i - 1] * ways[i][j] * i
counted += fact[i] * fact[n - i - 1] * ways[i][j]
return ans, counted
pre()
tot = 0
count = 0
sm = 0
for i in range(n):
sm += arr[i]
arr1 = [0] * (n - 1)
got = 0
for j in range(n):
if j == i:
continue
arr1[got] = arr[j]
got += 1
how_many = get(arr1, max(0, p - arr[i] + 1), p)
tot += how_many[0]
count += how_many[1]
def get_div(a, b): #a / b
res = a // b
a %= b
for i in range(1, 10):
a = int(a)
a *= 10
x = a // b
x1 = x
res += pow(10, -i) * x1
a -= x * b
return res
if sm <= p:
print(n)
else:
print(get_div(tot, fact[n]))
``` | output | 1 | 74,467 | 14 | 148,935 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Maxim has opened his own restaurant! The restaurant has got a huge table, the table's length is p meters.
Maxim has got a dinner party tonight, n guests will come to him. Let's index the guests of Maxim's restaurant from 1 to n. Maxim knows the sizes of all guests that are going to come to him. The i-th guest's size (ai) represents the number of meters the guest is going to take up if he sits at the restaurant table.
Long before the dinner, the guests line up in a queue in front of the restaurant in some order. Then Maxim lets the guests in, one by one. Maxim stops letting the guests in when there is no place at the restaurant table for another guest in the queue. There is no place at the restaurant table for another guest in the queue, if the sum of sizes of all guests in the restaurant plus the size of this guest from the queue is larger than p. In this case, not to offend the guest who has no place at the table, Maxim doesn't let any other guest in the restaurant, even if one of the following guests in the queue would have fit in at the table.
Maxim is now wondering, what is the average number of visitors who have come to the restaurant for all possible n! orders of guests in the queue. Help Maxim, calculate this number.
Input
The first line contains integer n (1 β€ n β€ 50) β the number of guests in the restaurant. The next line contains integers a1, a2, ..., an (1 β€ ai β€ 50) β the guests' sizes in meters. The third line contains integer p (1 β€ p β€ 50) β the table's length in meters.
The numbers in the lines are separated by single spaces.
Output
In a single line print a real number β the answer to the problem. The answer will be considered correct, if the absolute or relative error doesn't exceed 10 - 4.
Examples
Input
3
1 2 3
3
Output
1.3333333333
Note
In the first sample the people will come in the following orders:
* (1, 2, 3) β there will be two people in the restaurant;
* (1, 3, 2) β there will be one person in the restaurant;
* (2, 1, 3) β there will be two people in the restaurant;
* (2, 3, 1) β there will be one person in the restaurant;
* (3, 1, 2) β there will be one person in the restaurant;
* (3, 2, 1) β there will be one person in the restaurant.
In total we get (2 + 1 + 2 + 1 + 1 + 1) / 6 = 8 / 6 = 1.(3). | instruction | 0 | 74,468 | 14 | 148,936 |
Tags: dp, math, probabilities
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
p = int(input())
fact = [1]
for i in range(1, 51):
fact.append(fact[-1]*i)
if sum(a) <= p:
print(n)
else:
dp = [[0]*56 for _ in range(56)]
dp[0][0] = 1
for i in range(n):
for j in range(n, -1, -1):
for k in range(p):
if a[i]+k <= p:
dp[j+1][a[i]+k] += dp[j][k]
tot = sum( dp[i][j] * fact[i]*fact[n-i]
for j in range(1, p+1)
for i in range(1, n+1) )
print(f'{tot/fact[n]:.9f}')
``` | output | 1 | 74,468 | 14 | 148,937 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Maxim has opened his own restaurant! The restaurant has got a huge table, the table's length is p meters.
Maxim has got a dinner party tonight, n guests will come to him. Let's index the guests of Maxim's restaurant from 1 to n. Maxim knows the sizes of all guests that are going to come to him. The i-th guest's size (ai) represents the number of meters the guest is going to take up if he sits at the restaurant table.
Long before the dinner, the guests line up in a queue in front of the restaurant in some order. Then Maxim lets the guests in, one by one. Maxim stops letting the guests in when there is no place at the restaurant table for another guest in the queue. There is no place at the restaurant table for another guest in the queue, if the sum of sizes of all guests in the restaurant plus the size of this guest from the queue is larger than p. In this case, not to offend the guest who has no place at the table, Maxim doesn't let any other guest in the restaurant, even if one of the following guests in the queue would have fit in at the table.
Maxim is now wondering, what is the average number of visitors who have come to the restaurant for all possible n! orders of guests in the queue. Help Maxim, calculate this number.
Input
The first line contains integer n (1 β€ n β€ 50) β the number of guests in the restaurant. The next line contains integers a1, a2, ..., an (1 β€ ai β€ 50) β the guests' sizes in meters. The third line contains integer p (1 β€ p β€ 50) β the table's length in meters.
The numbers in the lines are separated by single spaces.
Output
In a single line print a real number β the answer to the problem. The answer will be considered correct, if the absolute or relative error doesn't exceed 10 - 4.
Examples
Input
3
1 2 3
3
Output
1.3333333333
Note
In the first sample the people will come in the following orders:
* (1, 2, 3) β there will be two people in the restaurant;
* (1, 3, 2) β there will be one person in the restaurant;
* (2, 1, 3) β there will be two people in the restaurant;
* (2, 3, 1) β there will be one person in the restaurant;
* (3, 1, 2) β there will be one person in the restaurant;
* (3, 2, 1) β there will be one person in the restaurant.
In total we get (2 + 1 + 2 + 1 + 1 + 1) / 6 = 8 / 6 = 1.(3). | instruction | 0 | 74,469 | 14 | 148,938 |
Tags: dp, math, probabilities
Correct Solution:
```
import math
n = int(input())
a = [int(x) for x in input().split()]
p = int(input())
sum=0;
for x in range(n):
sum+=a[x]
if(sum<=p):
print(n)
else:
ans=0
for i in range(n):
dp = [[[0 for z in range(55)] for y in range(55)] for x in range(55)]
dp[-1][0][0]=1
for j in range(n):
if(j==i):
for k in range(n):
for z in range(p+1):
dp[j][k][z]=dp[j-1][k][z]
continue
for k in range(n):
for z in range(p+1):
if(z+a[j]<=p):
dp[j][k+1][z+a[j]]+=dp[j-1][k][z]
dp[j][k][z]+=dp[j-1][k][z]
for k in range(n):
for z in range(p+1):
if(z+a[i]>p):
ans+=k*dp[n-1][k][z]*math.factorial(k)*math.factorial(n-k-1)
print(ans/math.factorial(n))
``` | output | 1 | 74,469 | 14 | 148,939 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Maxim has opened his own restaurant! The restaurant has got a huge table, the table's length is p meters.
Maxim has got a dinner party tonight, n guests will come to him. Let's index the guests of Maxim's restaurant from 1 to n. Maxim knows the sizes of all guests that are going to come to him. The i-th guest's size (ai) represents the number of meters the guest is going to take up if he sits at the restaurant table.
Long before the dinner, the guests line up in a queue in front of the restaurant in some order. Then Maxim lets the guests in, one by one. Maxim stops letting the guests in when there is no place at the restaurant table for another guest in the queue. There is no place at the restaurant table for another guest in the queue, if the sum of sizes of all guests in the restaurant plus the size of this guest from the queue is larger than p. In this case, not to offend the guest who has no place at the table, Maxim doesn't let any other guest in the restaurant, even if one of the following guests in the queue would have fit in at the table.
Maxim is now wondering, what is the average number of visitors who have come to the restaurant for all possible n! orders of guests in the queue. Help Maxim, calculate this number.
Input
The first line contains integer n (1 β€ n β€ 50) β the number of guests in the restaurant. The next line contains integers a1, a2, ..., an (1 β€ ai β€ 50) β the guests' sizes in meters. The third line contains integer p (1 β€ p β€ 50) β the table's length in meters.
The numbers in the lines are separated by single spaces.
Output
In a single line print a real number β the answer to the problem. The answer will be considered correct, if the absolute or relative error doesn't exceed 10 - 4.
Examples
Input
3
1 2 3
3
Output
1.3333333333
Note
In the first sample the people will come in the following orders:
* (1, 2, 3) β there will be two people in the restaurant;
* (1, 3, 2) β there will be one person in the restaurant;
* (2, 1, 3) β there will be two people in the restaurant;
* (2, 3, 1) β there will be one person in the restaurant;
* (3, 1, 2) β there will be one person in the restaurant;
* (3, 2, 1) β there will be one person in the restaurant.
In total we get (2 + 1 + 2 + 1 + 1 + 1) / 6 = 8 / 6 = 1.(3). | instruction | 0 | 74,470 | 14 | 148,940 |
Tags: dp, math, probabilities
Correct Solution:
```
from pprint import pprint
n = int(input())
a = list(map(int, input().split()))
p = int(input())
fact = [1]
for i in range(1, 51):
fact.append(fact[-1]*i)
if sum(a) <= p:
print(n)
else:
dp = [[0]*56 for _ in range(56)]
dp[0][0] = 1
for i in range(n):
for j in range(n, -1, -1):
for k in range(p):
if a[i]+k <= p:
dp[a[i]+k][j+1] += dp[k][j]
tot = sum( dp[j][i] * fact[i]*fact[n-i]
for i in range(1, n+1)
for j in range(1, p+1) )
print(f'{tot/fact[n]:.9f}')
``` | output | 1 | 74,470 | 14 | 148,941 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Maxim has opened his own restaurant! The restaurant has got a huge table, the table's length is p meters.
Maxim has got a dinner party tonight, n guests will come to him. Let's index the guests of Maxim's restaurant from 1 to n. Maxim knows the sizes of all guests that are going to come to him. The i-th guest's size (ai) represents the number of meters the guest is going to take up if he sits at the restaurant table.
Long before the dinner, the guests line up in a queue in front of the restaurant in some order. Then Maxim lets the guests in, one by one. Maxim stops letting the guests in when there is no place at the restaurant table for another guest in the queue. There is no place at the restaurant table for another guest in the queue, if the sum of sizes of all guests in the restaurant plus the size of this guest from the queue is larger than p. In this case, not to offend the guest who has no place at the table, Maxim doesn't let any other guest in the restaurant, even if one of the following guests in the queue would have fit in at the table.
Maxim is now wondering, what is the average number of visitors who have come to the restaurant for all possible n! orders of guests in the queue. Help Maxim, calculate this number.
Input
The first line contains integer n (1 β€ n β€ 50) β the number of guests in the restaurant. The next line contains integers a1, a2, ..., an (1 β€ ai β€ 50) β the guests' sizes in meters. The third line contains integer p (1 β€ p β€ 50) β the table's length in meters.
The numbers in the lines are separated by single spaces.
Output
In a single line print a real number β the answer to the problem. The answer will be considered correct, if the absolute or relative error doesn't exceed 10 - 4.
Examples
Input
3
1 2 3
3
Output
1.3333333333
Note
In the first sample the people will come in the following orders:
* (1, 2, 3) β there will be two people in the restaurant;
* (1, 3, 2) β there will be one person in the restaurant;
* (2, 1, 3) β there will be two people in the restaurant;
* (2, 3, 1) β there will be one person in the restaurant;
* (3, 1, 2) β there will be one person in the restaurant;
* (3, 2, 1) β there will be one person in the restaurant.
In total we get (2 + 1 + 2 + 1 + 1 + 1) / 6 = 8 / 6 = 1.(3). | instruction | 0 | 74,471 | 14 | 148,942 |
Tags: dp, math, probabilities
Correct Solution:
```
n=int(input())
arr=list(map(int,input().split()))
p=int(input())
dp=[[[0 for k in range(n+1)] for i in range(p+1)] for i in range(n+1)]
for j in range(p+1):
for k in range(n+1):
dp[0][j][k]=1
for i in range(1,n+1):
for j in range(p+1):
for k in range(1,n+1):
if j>=arr[k-1]:
dp[i][j][k]=dp[i][j][k-1]+i*dp[i-1][j-arr[k-1]][k-1]
else:
dp[i][j][k]=dp[i][j][k-1]
fact=n
ans=0
for i in range(1,n+1):
ans+=dp[i][p][n]/fact
fact*=(n-i)
print(ans)
``` | output | 1 | 74,471 | 14 | 148,943 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.