message stringlengths 2 44.5k | message_type stringclasses 2
values | message_id int64 0 1 | conversation_id int64 276 109k | cluster float64 23 23 | __index_level_0__ int64 552 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n segments on a coordinate axis OX. The i-th segment has borders [l_i; r_i]. All points x, for which l_i β€ x β€ r_i holds, belong to the i-th segment.
Your task is to choose the maximum by size (the number of segments) subset of the given set of segments such that each pair of segments in this subset either non-intersecting or one of them lies inside the other one.
Two segments [l_i; r_i] and [l_j; r_j] are non-intersecting if they have no common points. For example, segments [1; 2] and [3; 4], [1; 3] and [5; 5] are non-intersecting, while segments [1; 2] and [2; 3], [1; 2] and [2; 2] are intersecting.
The segment [l_i; r_i] lies inside the segment [l_j; r_j] if l_j β€ l_i and r_i β€ r_j. For example, segments [2; 2], [2, 3], [3; 4] and [2; 4] lie inside the segment [2; 4], while [2; 5] and [1; 4] are not.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 1000) β the number of test cases. Then t test cases follow.
The first line of the test case contains one integer n (1 β€ n β€ 3000) β the number of segments. The next n lines describe segments. The i-th segment is given as two integers l_i and r_i (1 β€ l_i β€ r_i β€ 2 β
10^5), where l_i is the left border of the i-th segment and r_i is the right border of the i-th segment.
Additional constraint on the input: there are no duplicates in the list of segments.
It is guaranteed that the sum of n does not exceed 3000 (β n β€ 3000).
Output
For each test case, print the answer: the maximum possible size of the subset of the given set of segments such that each pair of segments in this subset either non-intersecting or one of them lies inside the other one.
Example
Input
4
4
1 5
2 4
2 3
3 4
5
1 5
2 3
2 5
3 5
2 2
3
1 3
2 4
2 3
7
1 10
2 8
2 5
3 4
4 4
6 8
7 7
Output
3
4
2
7 | instruction | 0 | 54,958 | 23 | 109,916 |
Tags: data structures, dp, graphs, sortings
Correct Solution:
```
# θ§£θͺ¬AC
mod = 1000000007
eps = 10**-9
def main():
import sys
input = sys.stdin.buffer.readline
for _ in range(int(input())):
M = int(input())
LR_raw = []
val = set()
for _ in range(M):
l, r = map(int, input().split())
LR_raw.append((l, r))
val.add(l)
val.add(r)
val = sorted(list(val))
val2idx = {x: i for i, x in enumerate(val)}
LR = []
N = len(val)
segment = [set() for _ in range(N)]
for l_, r_ in LR_raw:
l = val2idx[l_]
r = val2idx[r_]
LR.append((l, r))
segment[l].add(r)
dp = [[0] * N for _ in range(N)]
for d in range(1, N+1):
for l in range(N):
r = l + d - 1
if r < N:
if l+1 <= r:
dp[l][r] = dp[l+1][r]
for rr in segment[l]:
if rr >= r:
continue
dp[l][r] = max(dp[l][r], dp[l][rr] + dp[rr+1][r])
if r in segment[l]:
dp[l][r] += 1
print(dp[0][-1])
if __name__ == '__main__':
main()
``` | output | 1 | 54,958 | 23 | 109,917 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n segments on a coordinate axis OX. The i-th segment has borders [l_i; r_i]. All points x, for which l_i β€ x β€ r_i holds, belong to the i-th segment.
Your task is to choose the maximum by size (the number of segments) subset of the given set of segments such that each pair of segments in this subset either non-intersecting or one of them lies inside the other one.
Two segments [l_i; r_i] and [l_j; r_j] are non-intersecting if they have no common points. For example, segments [1; 2] and [3; 4], [1; 3] and [5; 5] are non-intersecting, while segments [1; 2] and [2; 3], [1; 2] and [2; 2] are intersecting.
The segment [l_i; r_i] lies inside the segment [l_j; r_j] if l_j β€ l_i and r_i β€ r_j. For example, segments [2; 2], [2, 3], [3; 4] and [2; 4] lie inside the segment [2; 4], while [2; 5] and [1; 4] are not.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 1000) β the number of test cases. Then t test cases follow.
The first line of the test case contains one integer n (1 β€ n β€ 3000) β the number of segments. The next n lines describe segments. The i-th segment is given as two integers l_i and r_i (1 β€ l_i β€ r_i β€ 2 β
10^5), where l_i is the left border of the i-th segment and r_i is the right border of the i-th segment.
Additional constraint on the input: there are no duplicates in the list of segments.
It is guaranteed that the sum of n does not exceed 3000 (β n β€ 3000).
Output
For each test case, print the answer: the maximum possible size of the subset of the given set of segments such that each pair of segments in this subset either non-intersecting or one of them lies inside the other one.
Example
Input
4
4
1 5
2 4
2 3
3 4
5
1 5
2 3
2 5
3 5
2 2
3
1 3
2 4
2 3
7
1 10
2 8
2 5
3 4
4 4
6 8
7 7
Output
3
4
2
7 | instruction | 0 | 54,959 | 23 | 109,918 |
Tags: data structures, dp, graphs, sortings
Correct Solution:
```
from operator import itemgetter
import bisect
import sys
input = sys.stdin.buffer.readline
def topological_sort(graph: list) -> list:
n = len(graph)
degree = [0] * n
for g in graph:
for next_pos in g:
degree[next_pos] += 1
ans = [i for i in range(n) if degree[i] == 0]
q = ans[:]
while q:
pos = q.pop()
for next_pos in graph[pos]:
degree[next_pos] -= 1
if degree[next_pos] == 0:
q.append(next_pos)
ans.append(next_pos)
return ans
def solve_dp(ds):
n = len(ds)
dp = [0] * (len(ds) + 1)
ls = [l for l, r in ds]
rs = [r for l, r in ds]
for i in range(n):
l, r = ds[i]
ind = bisect.bisect_left(rs, l)
dp[i + 1] = max(dp[ind] + vals[to_ind[(l, r)]], dp[i])
return max(dp)
t = int(input())
for _ in range(t):
n = int(input())
dists = [list(map(int, input().split())) for i in range(n)]
dists.sort(key=itemgetter(1))
to_ind = {(l, r): i for i, (l, r) in enumerate(dists)}
graph = [[] for i in range(n)]
for i in range(n):
li, ri = dists[i]
for j in range(n):
if i == j:
continue
lj, rj = dists[j]
if li <= lj <= rj <= ri:
graph[i].append(j)
tp_sort = topological_sort(graph)
vals = [0] * n
for v in tp_sort[::-1]:
ds = []
for nxt_v in graph[v]:
ds.append(dists[nxt_v])
vals[v] = solve_dp(ds) + 1
print(solve_dp(dists))
``` | output | 1 | 54,959 | 23 | 109,919 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n segments on a coordinate axis OX. The i-th segment has borders [l_i; r_i]. All points x, for which l_i β€ x β€ r_i holds, belong to the i-th segment.
Your task is to choose the maximum by size (the number of segments) subset of the given set of segments such that each pair of segments in this subset either non-intersecting or one of them lies inside the other one.
Two segments [l_i; r_i] and [l_j; r_j] are non-intersecting if they have no common points. For example, segments [1; 2] and [3; 4], [1; 3] and [5; 5] are non-intersecting, while segments [1; 2] and [2; 3], [1; 2] and [2; 2] are intersecting.
The segment [l_i; r_i] lies inside the segment [l_j; r_j] if l_j β€ l_i and r_i β€ r_j. For example, segments [2; 2], [2, 3], [3; 4] and [2; 4] lie inside the segment [2; 4], while [2; 5] and [1; 4] are not.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 1000) β the number of test cases. Then t test cases follow.
The first line of the test case contains one integer n (1 β€ n β€ 3000) β the number of segments. The next n lines describe segments. The i-th segment is given as two integers l_i and r_i (1 β€ l_i β€ r_i β€ 2 β
10^5), where l_i is the left border of the i-th segment and r_i is the right border of the i-th segment.
Additional constraint on the input: there are no duplicates in the list of segments.
It is guaranteed that the sum of n does not exceed 3000 (β n β€ 3000).
Output
For each test case, print the answer: the maximum possible size of the subset of the given set of segments such that each pair of segments in this subset either non-intersecting or one of them lies inside the other one.
Example
Input
4
4
1 5
2 4
2 3
3 4
5
1 5
2 3
2 5
3 5
2 2
3
1 3
2 4
2 3
7
1 10
2 8
2 5
3 4
4 4
6 8
7 7
Output
3
4
2
7 | instruction | 0 | 54,960 | 23 | 109,920 |
Tags: data structures, dp, graphs, sortings
Correct Solution:
```
from collections import deque
t=1
for _ in range(int(input())):
n=int(input())
val=set([0,2*10**5+1])
seg=[(0,2*10**5+1)]
for i in range(n):
l,r=map(int,input().split())
val.add(l)
val.add(r)
seg.append((l,r))
val=list(val)
val.sort()
comp={i:e+1 for e,i in enumerate(val)}
for i in range(n+1):
l,r=seg[i]
seg[i]=(comp[l],comp[r])
deg=[0]*(n+1)
out=[[] for i in range(n+1)]
for i in range(n+1):
for j in range(i+1,n+1):
l,r=seg[i];L,R=seg[j]
if L<=l and r<=R:out[j].append(i);deg[i]+=1
elif l<=L and R<=r:out[i].append(j);deg[j]+=1
ans=[0]
deq=deque(ans)
while deq:
v=deq.popleft()
for nv in out[v]:
deg[nv]-=1
if deg[nv]==0:deq.append(nv);ans.append(nv)
dp=[0]*(n+1)
def solve(v):
query=[[] for i in range(2*n+3)]
for nv in out[v]:l,r=seg[nv];query[r].append((l,dp[nv]))
subdp=[0]*(2*n+3)
for i in range(1,2*n+3):
res=subdp[i-1]
for l,val in query[i]:test=subdp[l-1]+val;res=max(test,res)
subdp[i]=res
dp[v]=subdp[-1]+1
for v in ans[::-1]:solve(v)
print(dp[0]-1)
``` | output | 1 | 54,960 | 23 | 109,921 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n segments on a coordinate axis OX. The i-th segment has borders [l_i; r_i]. All points x, for which l_i β€ x β€ r_i holds, belong to the i-th segment.
Your task is to choose the maximum by size (the number of segments) subset of the given set of segments such that each pair of segments in this subset either non-intersecting or one of them lies inside the other one.
Two segments [l_i; r_i] and [l_j; r_j] are non-intersecting if they have no common points. For example, segments [1; 2] and [3; 4], [1; 3] and [5; 5] are non-intersecting, while segments [1; 2] and [2; 3], [1; 2] and [2; 2] are intersecting.
The segment [l_i; r_i] lies inside the segment [l_j; r_j] if l_j β€ l_i and r_i β€ r_j. For example, segments [2; 2], [2, 3], [3; 4] and [2; 4] lie inside the segment [2; 4], while [2; 5] and [1; 4] are not.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 1000) β the number of test cases. Then t test cases follow.
The first line of the test case contains one integer n (1 β€ n β€ 3000) β the number of segments. The next n lines describe segments. The i-th segment is given as two integers l_i and r_i (1 β€ l_i β€ r_i β€ 2 β
10^5), where l_i is the left border of the i-th segment and r_i is the right border of the i-th segment.
Additional constraint on the input: there are no duplicates in the list of segments.
It is guaranteed that the sum of n does not exceed 3000 (β n β€ 3000).
Output
For each test case, print the answer: the maximum possible size of the subset of the given set of segments such that each pair of segments in this subset either non-intersecting or one of them lies inside the other one.
Example
Input
4
4
1 5
2 4
2 3
3 4
5
1 5
2 3
2 5
3 5
2 2
3
1 3
2 4
2 3
7
1 10
2 8
2 5
3 4
4 4
6 8
7 7
Output
3
4
2
7 | instruction | 0 | 54,961 | 23 | 109,922 |
Tags: data structures, dp, graphs, sortings
Correct Solution:
```
import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(sys.stdin.readline())
def ria(): return list(map(int, sys.stdin.readline().split()))
def ws(s): sys.stdout.write(s); sys.stdout.write('\n')
def wi(n): sys.stdout.write(str(n)); sys.stdout.write('\n')
def wia(a, sep=' '): sys.stdout.write(sep.join([str(x) for x in a])); sys.stdout.write('\n')
def solve(n, segs):
vals = set()
for l, r in segs:
vals.add(l)
vals.add(r)
vals = sorted(list(vals))
d = {x: i for i, x in enumerate(vals)}
m = len(vals)
c_segs = []
r_segs = [[] for _ in range(m)]
for l, r in segs:
ll = d[l]
rr = d[r]
c_segs.append((ll, rr))
r_segs[ll].append(rr)
dp = [[0] * m for _ in range(m)]
for ln in range(1, m + 1):
for l in range(m):
r = l + ln - 1
if r >= m: continue
if l + 1 <= r:
dp[l][r] = dp[l + 1][r]
for rr in r_segs[l]:
if rr >= r:
continue
dp[l][r] = max(dp[l][r], dp[l][rr] + dp[rr + 1][r])
if r in r_segs[l]:
dp[l][r] += 1
return dp[0][-1]
def main():
for _ in range(ri()):
n = ri()
segs = []
for i in range(n):
l, r = ria()
segs.append((l, r))
wi(solve(n, segs))
if __name__ == '__main__':
main()
``` | output | 1 | 54,961 | 23 | 109,923 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n segments on a coordinate axis OX. The i-th segment has borders [l_i; r_i]. All points x, for which l_i β€ x β€ r_i holds, belong to the i-th segment.
Your task is to choose the maximum by size (the number of segments) subset of the given set of segments such that each pair of segments in this subset either non-intersecting or one of them lies inside the other one.
Two segments [l_i; r_i] and [l_j; r_j] are non-intersecting if they have no common points. For example, segments [1; 2] and [3; 4], [1; 3] and [5; 5] are non-intersecting, while segments [1; 2] and [2; 3], [1; 2] and [2; 2] are intersecting.
The segment [l_i; r_i] lies inside the segment [l_j; r_j] if l_j β€ l_i and r_i β€ r_j. For example, segments [2; 2], [2, 3], [3; 4] and [2; 4] lie inside the segment [2; 4], while [2; 5] and [1; 4] are not.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 1000) β the number of test cases. Then t test cases follow.
The first line of the test case contains one integer n (1 β€ n β€ 3000) β the number of segments. The next n lines describe segments. The i-th segment is given as two integers l_i and r_i (1 β€ l_i β€ r_i β€ 2 β
10^5), where l_i is the left border of the i-th segment and r_i is the right border of the i-th segment.
Additional constraint on the input: there are no duplicates in the list of segments.
It is guaranteed that the sum of n does not exceed 3000 (β n β€ 3000).
Output
For each test case, print the answer: the maximum possible size of the subset of the given set of segments such that each pair of segments in this subset either non-intersecting or one of them lies inside the other one.
Example
Input
4
4
1 5
2 4
2 3
3 4
5
1 5
2 3
2 5
3 5
2 2
3
1 3
2 4
2 3
7
1 10
2 8
2 5
3 4
4 4
6 8
7 7
Output
3
4
2
7 | instruction | 0 | 54,962 | 23 | 109,924 |
Tags: data structures, dp, graphs, sortings
Correct Solution:
```
# Fast IO (only use in integer input)
# import os,io
# input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
t = int(input())
for _ in range(t):
n = int(input())
pointList = []
pointOrderDict = {}
interval = [] # (l,r) tuple
intervalOrder = [] # interval list compressed as an order
for _ in range(n):
l,r = map(int,input().split())
pointList.append(l)
pointList.append(r)
interval.append((l,r))
pointList.sort()
cnt = 0
for i in range(2 * n):
if i == 0 or pointList[i] != pointList[i-1]:
pointOrderDict[pointList[i]] = cnt
cnt += 1
for elem in interval:
intervalOrder.append((pointOrderDict[elem[0]],pointOrderDict[elem[1]]))
intervalList = []
dp = []
for i in range(cnt):
dp.append([])
intervalList.append([])
for j in range(cnt):
dp[i].append(-1)
for elem in intervalOrder:
intervalList[elem[0]].append(elem[1])
for i in range(cnt): # r - l
for j in range(cnt - i): # l
ans1 = 0 # is there [l,r]
ans2 = 0 # max of [l+1,r] and [l,nr] + [nr + 1,r]
if i != 0:
ans2 = dp[j + 1][i + j]
for elem in intervalList[j]:
if elem == i + j:
ans1 += 1
elif elem < i + j and ans2 < dp[j][elem] + dp[elem + 1][i + j]:
ans2 = dp[j][elem] + dp[elem + 1][i + j]
dp[j][i+j] = ans1 + ans2
print(dp[0][cnt - 1])
``` | output | 1 | 54,962 | 23 | 109,925 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n segments on a coordinate axis OX. The i-th segment has borders [l_i; r_i]. All points x, for which l_i β€ x β€ r_i holds, belong to the i-th segment.
Your task is to choose the maximum by size (the number of segments) subset of the given set of segments such that each pair of segments in this subset either non-intersecting or one of them lies inside the other one.
Two segments [l_i; r_i] and [l_j; r_j] are non-intersecting if they have no common points. For example, segments [1; 2] and [3; 4], [1; 3] and [5; 5] are non-intersecting, while segments [1; 2] and [2; 3], [1; 2] and [2; 2] are intersecting.
The segment [l_i; r_i] lies inside the segment [l_j; r_j] if l_j β€ l_i and r_i β€ r_j. For example, segments [2; 2], [2, 3], [3; 4] and [2; 4] lie inside the segment [2; 4], while [2; 5] and [1; 4] are not.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 1000) β the number of test cases. Then t test cases follow.
The first line of the test case contains one integer n (1 β€ n β€ 3000) β the number of segments. The next n lines describe segments. The i-th segment is given as two integers l_i and r_i (1 β€ l_i β€ r_i β€ 2 β
10^5), where l_i is the left border of the i-th segment and r_i is the right border of the i-th segment.
Additional constraint on the input: there are no duplicates in the list of segments.
It is guaranteed that the sum of n does not exceed 3000 (β n β€ 3000).
Output
For each test case, print the answer: the maximum possible size of the subset of the given set of segments such that each pair of segments in this subset either non-intersecting or one of them lies inside the other one.
Example
Input
4
4
1 5
2 4
2 3
3 4
5
1 5
2 3
2 5
3 5
2 2
3
1 3
2 4
2 3
7
1 10
2 8
2 5
3 4
4 4
6 8
7 7
Output
3
4
2
7 | instruction | 0 | 54,963 | 23 | 109,926 |
Tags: data structures, dp, graphs, sortings
Correct Solution:
```
from collections import deque
for _ in range(int(input())):
n=int(input());val=set([0,2*10**5+1]);seg=[(0,2*10**5+1)]
for i in range(n):l,r=map(int,input().split());val.add(l);val.add(r);seg.append((l,r))
val=sorted(list(val));comp={i:e+1 for e,i in enumerate(val)};deg=[0]*(n+1);out=[[] for i in range(n+1)]
for i in range(n+1):l,r=seg[i];seg[i]=(comp[l],comp[r])
for i in range(n+1):
for j in range(i+1,n+1):
l,r=seg[i];L,R=seg[j]
if L<=l and r<=R:out[j].append(i);deg[i]+=1
elif l<=L and R<=r:out[i].append(j);deg[j]+=1
ans=[0];deq=deque(ans);dp=[0]*(n+1)
while deq:
v=deq.popleft()
for nv in out[v]:
deg[nv]-=1
if deg[nv]==0:deq.append(nv);ans.append(nv)
def solve(v):
query=[[] for i in range(2*n+3)];subdp=[0]*(2*n+3)
for nv in out[v]:l,r=seg[nv];query[r].append((l,dp[nv]))
for i in range(1,2*n+3):
res=subdp[i-1]
for l,val in query[i]:test=subdp[l-1]+val;res=max(test,res)
subdp[i]=res
dp[v]=subdp[-1]+1
for v in ans[::-1]:solve(v)
print(dp[0]-1)
``` | output | 1 | 54,963 | 23 | 109,927 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given n segments on a coordinate axis OX. The i-th segment has borders [l_i; r_i]. All points x, for which l_i β€ x β€ r_i holds, belong to the i-th segment.
Your task is to choose the maximum by size (the number of segments) subset of the given set of segments such that each pair of segments in this subset either non-intersecting or one of them lies inside the other one.
Two segments [l_i; r_i] and [l_j; r_j] are non-intersecting if they have no common points. For example, segments [1; 2] and [3; 4], [1; 3] and [5; 5] are non-intersecting, while segments [1; 2] and [2; 3], [1; 2] and [2; 2] are intersecting.
The segment [l_i; r_i] lies inside the segment [l_j; r_j] if l_j β€ l_i and r_i β€ r_j. For example, segments [2; 2], [2, 3], [3; 4] and [2; 4] lie inside the segment [2; 4], while [2; 5] and [1; 4] are not.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 1000) β the number of test cases. Then t test cases follow.
The first line of the test case contains one integer n (1 β€ n β€ 3000) β the number of segments. The next n lines describe segments. The i-th segment is given as two integers l_i and r_i (1 β€ l_i β€ r_i β€ 2 β
10^5), where l_i is the left border of the i-th segment and r_i is the right border of the i-th segment.
Additional constraint on the input: there are no duplicates in the list of segments.
It is guaranteed that the sum of n does not exceed 3000 (β n β€ 3000).
Output
For each test case, print the answer: the maximum possible size of the subset of the given set of segments such that each pair of segments in this subset either non-intersecting or one of them lies inside the other one.
Example
Input
4
4
1 5
2 4
2 3
3 4
5
1 5
2 3
2 5
3 5
2 2
3
1 3
2 4
2 3
7
1 10
2 8
2 5
3 4
4 4
6 8
7 7
Output
3
4
2
7 | instruction | 0 | 54,964 | 23 | 109,928 |
Tags: data structures, dp, graphs, sortings
Correct Solution:
```
import sys
from collections import deque
t=1
for _ in range(int(input())):
n=int(input())
val=set([0,2*10**5+1])
seg=[(0,2*10**5+1)]
for i in range(n):
l,r=map(int,input().split())
val.add(l)
val.add(r)
seg.append((l,r))
val=list(val)
val.sort()
comp={i:e+1 for e,i in enumerate(val)}
for i in range(n+1):
l,r=seg[i]
seg[i]=(comp[l],comp[r])
deg=[0]*(n+1)
out=[[] for i in range(n+1)]
for i in range(n+1):
for j in range(i+1,n+1):
l,r=seg[i]
L,R=seg[j]
if L<=l and r<=R:
out[j].append(i)
deg[i]+=1
elif l<=L and R<=r:
out[i].append(j)
deg[j]+=1
ans=[0]
deq=deque(ans)
while deq:
v=deq.popleft()
for nv in out[v]:
deg[nv]-=1
if deg[nv]==0:
deq.append(nv)
ans.append(nv)
dp=[0]*(n+1)
def solve(v):
query=[[] for i in range(2*n+3)]
for nv in out[v]:l,r=seg[nv];query[r].append((l,dp[nv]))
subdp=[0]*(2*n+3)
for i in range(1,2*n+3):
res=subdp[i-1]
for l,val in query[i]:test=subdp[l-1]+val;res=max(test,res)
subdp[i]=res
dp[v]=subdp[-1]+1
for v in ans[::-1]:solve(v)
print(dp[0]-1)
``` | output | 1 | 54,964 | 23 | 109,929 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n segments on a coordinate axis OX. The i-th segment has borders [l_i; r_i]. All points x, for which l_i β€ x β€ r_i holds, belong to the i-th segment.
Your task is to choose the maximum by size (the number of segments) subset of the given set of segments such that each pair of segments in this subset either non-intersecting or one of them lies inside the other one.
Two segments [l_i; r_i] and [l_j; r_j] are non-intersecting if they have no common points. For example, segments [1; 2] and [3; 4], [1; 3] and [5; 5] are non-intersecting, while segments [1; 2] and [2; 3], [1; 2] and [2; 2] are intersecting.
The segment [l_i; r_i] lies inside the segment [l_j; r_j] if l_j β€ l_i and r_i β€ r_j. For example, segments [2; 2], [2, 3], [3; 4] and [2; 4] lie inside the segment [2; 4], while [2; 5] and [1; 4] are not.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 1000) β the number of test cases. Then t test cases follow.
The first line of the test case contains one integer n (1 β€ n β€ 3000) β the number of segments. The next n lines describe segments. The i-th segment is given as two integers l_i and r_i (1 β€ l_i β€ r_i β€ 2 β
10^5), where l_i is the left border of the i-th segment and r_i is the right border of the i-th segment.
Additional constraint on the input: there are no duplicates in the list of segments.
It is guaranteed that the sum of n does not exceed 3000 (β n β€ 3000).
Output
For each test case, print the answer: the maximum possible size of the subset of the given set of segments such that each pair of segments in this subset either non-intersecting or one of them lies inside the other one.
Example
Input
4
4
1 5
2 4
2 3
3 4
5
1 5
2 3
2 5
3 5
2 2
3
1 3
2 4
2 3
7
1 10
2 8
2 5
3 4
4 4
6 8
7 7
Output
3
4
2
7
Submitted Solution:
```
import sys
from collections import deque
input=sys.stdin.readline
t=1
t=int(input())
for _ in range(t):
n=int(input())
val=set([0,2*10**5+1])
seg=[(0,2*10**5+1)]
for i in range(n):
l,r=map(int,input().split())
val.add(l)
val.add(r)
seg.append((l,r))
val=list(val)
val.sort()
comp={i:e+1 for e,i in enumerate(val)}
for i in range(n+1):
l,r=seg[i]
seg[i]=(comp[l],comp[r])
deg=[0]*(n+1)
out=[[] for i in range(n+1)]
for i in range(n+1):
for j in range(i+1,n+1):
l,r=seg[i]
L,R=seg[j]
if L<=l and r<=R:
out[j].append(i)
deg[i]+=1
elif l<=L and R<=r:
out[i].append(j)
deg[j]+=1
ans=[0]
deq=deque(ans)
while deq:
v=deq.popleft()
for nv in out[v]:
deg[nv]-=1
if deg[nv]==0:
deq.append(nv)
ans.append(nv)
dp=[0]*(n+1)
def solve(v):
query=[[] for i in range(2*n+3)]
for nv in out[v]:
l,r=seg[nv]
query[r].append((l,dp[nv]))
subdp=[0]*(2*n+3)
for i in range(1,2*n+3):
res=subdp[i-1]
for l,val in query[i]:
test=subdp[l-1]+val
res=max(test,res)
subdp[i]=res
dp[v]=subdp[-1]+1
for v in ans[::-1]:
solve(v)
print(dp[0]-1)
``` | instruction | 0 | 54,965 | 23 | 109,930 |
Yes | output | 1 | 54,965 | 23 | 109,931 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n segments on a coordinate axis OX. The i-th segment has borders [l_i; r_i]. All points x, for which l_i β€ x β€ r_i holds, belong to the i-th segment.
Your task is to choose the maximum by size (the number of segments) subset of the given set of segments such that each pair of segments in this subset either non-intersecting or one of them lies inside the other one.
Two segments [l_i; r_i] and [l_j; r_j] are non-intersecting if they have no common points. For example, segments [1; 2] and [3; 4], [1; 3] and [5; 5] are non-intersecting, while segments [1; 2] and [2; 3], [1; 2] and [2; 2] are intersecting.
The segment [l_i; r_i] lies inside the segment [l_j; r_j] if l_j β€ l_i and r_i β€ r_j. For example, segments [2; 2], [2, 3], [3; 4] and [2; 4] lie inside the segment [2; 4], while [2; 5] and [1; 4] are not.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 1000) β the number of test cases. Then t test cases follow.
The first line of the test case contains one integer n (1 β€ n β€ 3000) β the number of segments. The next n lines describe segments. The i-th segment is given as two integers l_i and r_i (1 β€ l_i β€ r_i β€ 2 β
10^5), where l_i is the left border of the i-th segment and r_i is the right border of the i-th segment.
Additional constraint on the input: there are no duplicates in the list of segments.
It is guaranteed that the sum of n does not exceed 3000 (β n β€ 3000).
Output
For each test case, print the answer: the maximum possible size of the subset of the given set of segments such that each pair of segments in this subset either non-intersecting or one of them lies inside the other one.
Example
Input
4
4
1 5
2 4
2 3
3 4
5
1 5
2 3
2 5
3 5
2 2
3
1 3
2 4
2 3
7
1 10
2 8
2 5
3 4
4 4
6 8
7 7
Output
3
4
2
7
Submitted Solution:
```
import sys
input = sys.stdin.buffer.readline
def solve():
n = int(input())
LR = [tuple(map(int,input().split())) for i in range(n)]
s = set()
for l,r in LR:
s.add(l)
s.add(r)
dic = {x:i for i,x in enumerate(sorted(list(s)))}
le = len(s)
seg = [[] for i in range(le)]
for l,r in LR:
seg[dic[r]].append(dic[l])
dp = [[len(seg[0])]]
for i in range(1,le):
dp.append(dp[-1]+[0])
for l in sorted(seg[i],reverse=True):
dp[i][l] += 1
for j in range(l):
dp[i][j] = max(dp[i][j],dp[i][l]+dp[l-1][j])
return dp[-1][0]
t = int(input())
for _ in range(t):
ans = solve()
print(ans)
``` | instruction | 0 | 54,966 | 23 | 109,932 |
Yes | output | 1 | 54,966 | 23 | 109,933 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n segments on a coordinate axis OX. The i-th segment has borders [l_i; r_i]. All points x, for which l_i β€ x β€ r_i holds, belong to the i-th segment.
Your task is to choose the maximum by size (the number of segments) subset of the given set of segments such that each pair of segments in this subset either non-intersecting or one of them lies inside the other one.
Two segments [l_i; r_i] and [l_j; r_j] are non-intersecting if they have no common points. For example, segments [1; 2] and [3; 4], [1; 3] and [5; 5] are non-intersecting, while segments [1; 2] and [2; 3], [1; 2] and [2; 2] are intersecting.
The segment [l_i; r_i] lies inside the segment [l_j; r_j] if l_j β€ l_i and r_i β€ r_j. For example, segments [2; 2], [2, 3], [3; 4] and [2; 4] lie inside the segment [2; 4], while [2; 5] and [1; 4] are not.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 1000) β the number of test cases. Then t test cases follow.
The first line of the test case contains one integer n (1 β€ n β€ 3000) β the number of segments. The next n lines describe segments. The i-th segment is given as two integers l_i and r_i (1 β€ l_i β€ r_i β€ 2 β
10^5), where l_i is the left border of the i-th segment and r_i is the right border of the i-th segment.
Additional constraint on the input: there are no duplicates in the list of segments.
It is guaranteed that the sum of n does not exceed 3000 (β n β€ 3000).
Output
For each test case, print the answer: the maximum possible size of the subset of the given set of segments such that each pair of segments in this subset either non-intersecting or one of them lies inside the other one.
Example
Input
4
4
1 5
2 4
2 3
3 4
5
1 5
2 3
2 5
3 5
2 2
3
1 3
2 4
2 3
7
1 10
2 8
2 5
3 4
4 4
6 8
7 7
Output
3
4
2
7
Submitted Solution:
```
from bisect import bisect_left as lower
import sys
input = sys.stdin.buffer.readline
def put():
return map(int, input().split())
def func(size,seg):
dp = [[0]*size for i in range(size)]
for k in range(1, size+1):
for l in range(size):
r = l+k-1
if r<size:
if l+1<=r:
dp[l][r] = dp[l+1][r]
same = 0
for i in seg[l]:
if i==r:
same=1
if i<r:
dp[l][r] = max(dp[l][r], dp[l][i]+ dp[i+1][r])
dp[l][r]+=same
return dp[0][-1]
def solve():
t = int(input())
for _ in range(t):
n = int(input())
l,r,m = [],[],set()
for i in range(n):
x,y = put()
l.append(x);r.append(y)
m.add(x);m.add(y)
m = sorted(m)
size = len(m)
seg = [[] for i in range(size)]
for i in range(n):
l[i] = lower(m, l[i])
r[i] = lower(m, r[i])
seg[l[i]].append(r[i])
print(func(size, seg))
solve()
``` | instruction | 0 | 54,967 | 23 | 109,934 |
Yes | output | 1 | 54,967 | 23 | 109,935 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n segments on a coordinate axis OX. The i-th segment has borders [l_i; r_i]. All points x, for which l_i β€ x β€ r_i holds, belong to the i-th segment.
Your task is to choose the maximum by size (the number of segments) subset of the given set of segments such that each pair of segments in this subset either non-intersecting or one of them lies inside the other one.
Two segments [l_i; r_i] and [l_j; r_j] are non-intersecting if they have no common points. For example, segments [1; 2] and [3; 4], [1; 3] and [5; 5] are non-intersecting, while segments [1; 2] and [2; 3], [1; 2] and [2; 2] are intersecting.
The segment [l_i; r_i] lies inside the segment [l_j; r_j] if l_j β€ l_i and r_i β€ r_j. For example, segments [2; 2], [2, 3], [3; 4] and [2; 4] lie inside the segment [2; 4], while [2; 5] and [1; 4] are not.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 1000) β the number of test cases. Then t test cases follow.
The first line of the test case contains one integer n (1 β€ n β€ 3000) β the number of segments. The next n lines describe segments. The i-th segment is given as two integers l_i and r_i (1 β€ l_i β€ r_i β€ 2 β
10^5), where l_i is the left border of the i-th segment and r_i is the right border of the i-th segment.
Additional constraint on the input: there are no duplicates in the list of segments.
It is guaranteed that the sum of n does not exceed 3000 (β n β€ 3000).
Output
For each test case, print the answer: the maximum possible size of the subset of the given set of segments such that each pair of segments in this subset either non-intersecting or one of them lies inside the other one.
Example
Input
4
4
1 5
2 4
2 3
3 4
5
1 5
2 3
2 5
3 5
2 2
3
1 3
2 4
2 3
7
1 10
2 8
2 5
3 4
4 4
6 8
7 7
Output
3
4
2
7
Submitted Solution:
```
def solve():
n = int(input())
LR = [tuple(map(int,input().split())) for i in range(n)]
s = set()
for l,r in LR:
s.add(l)
s.add(r)
dic = {x:i for i,x in enumerate(sorted(list(s)))}
le = len(s)
seg = [[] for i in range(le)]
for l,r in LR:
seg[dic[r]].append(dic[l])
dp = [[len(seg[0])]]
for i in range(1,le):
dp.append(dp[-1]+[0])
for l in sorted(seg[i],reverse=True):
dp[i][l] += 1
for j in range(l):
dp[i][j] = max(dp[i][j],dp[i][l]+dp[l-1][j])
return dp[-1][0]
t = int(input())
for _ in range(t):
ans = solve()
print(ans)
``` | instruction | 0 | 54,968 | 23 | 109,936 |
Yes | output | 1 | 54,968 | 23 | 109,937 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n segments on a coordinate axis OX. The i-th segment has borders [l_i; r_i]. All points x, for which l_i β€ x β€ r_i holds, belong to the i-th segment.
Your task is to choose the maximum by size (the number of segments) subset of the given set of segments such that each pair of segments in this subset either non-intersecting or one of them lies inside the other one.
Two segments [l_i; r_i] and [l_j; r_j] are non-intersecting if they have no common points. For example, segments [1; 2] and [3; 4], [1; 3] and [5; 5] are non-intersecting, while segments [1; 2] and [2; 3], [1; 2] and [2; 2] are intersecting.
The segment [l_i; r_i] lies inside the segment [l_j; r_j] if l_j β€ l_i and r_i β€ r_j. For example, segments [2; 2], [2, 3], [3; 4] and [2; 4] lie inside the segment [2; 4], while [2; 5] and [1; 4] are not.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 1000) β the number of test cases. Then t test cases follow.
The first line of the test case contains one integer n (1 β€ n β€ 3000) β the number of segments. The next n lines describe segments. The i-th segment is given as two integers l_i and r_i (1 β€ l_i β€ r_i β€ 2 β
10^5), where l_i is the left border of the i-th segment and r_i is the right border of the i-th segment.
Additional constraint on the input: there are no duplicates in the list of segments.
It is guaranteed that the sum of n does not exceed 3000 (β n β€ 3000).
Output
For each test case, print the answer: the maximum possible size of the subset of the given set of segments such that each pair of segments in this subset either non-intersecting or one of them lies inside the other one.
Example
Input
4
4
1 5
2 4
2 3
3 4
5
1 5
2 3
2 5
3 5
2 2
3
1 3
2 4
2 3
7
1 10
2 8
2 5
3 4
4 4
6 8
7 7
Output
3
4
2
7
Submitted Solution:
```
from itertools import chain, combinations
def powerset(iterable):
"powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
s = list(iterable)
return list(chain.from_iterable(combinations(s, r) for r in range(1, len(s)+1)))
def generatepairs(source):
result = []
for p1 in range(len(source)):
for p2 in range(p1+1,len(source)):
result.append([source[p1],source[p2]])
return result
def nonintersect(pair):
pair_1_points = list(range(pair[0][0],pair[0][1]+1))
pair_2_points = list(range(pair[1][0],pair[0][1]+1))
if(len(set(pair_1_points) & set(pair_2_points))>1):
return False
else:
return True
def lie_inside(pair):
if(pair[0][0]<=pair[1][0] and pair[1][1]<=pair[0][1]):
return True
elif(pair[1][0]<=pair[0][0] and pair[0][1]<=pair[1][1]):
return True
else:
return False
for x in range(0, int(input())):
segments = []
for y in range(0, int(input())):
segments.append([int(z) for z in input().split(" ")])
max_length = -1
all_subsets = powerset(segments)
for subset in all_subsets:
works = True
pairs = generatepairs(subset)
for pair in pairs:
if(not(nonintersect(pair) or lie_inside(pair))):
works = False
break
if(works):
if(len(subset)>max_length):
max_length = len(subset)
print(max_length)
``` | instruction | 0 | 54,969 | 23 | 109,938 |
No | output | 1 | 54,969 | 23 | 109,939 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n segments on a coordinate axis OX. The i-th segment has borders [l_i; r_i]. All points x, for which l_i β€ x β€ r_i holds, belong to the i-th segment.
Your task is to choose the maximum by size (the number of segments) subset of the given set of segments such that each pair of segments in this subset either non-intersecting or one of them lies inside the other one.
Two segments [l_i; r_i] and [l_j; r_j] are non-intersecting if they have no common points. For example, segments [1; 2] and [3; 4], [1; 3] and [5; 5] are non-intersecting, while segments [1; 2] and [2; 3], [1; 2] and [2; 2] are intersecting.
The segment [l_i; r_i] lies inside the segment [l_j; r_j] if l_j β€ l_i and r_i β€ r_j. For example, segments [2; 2], [2, 3], [3; 4] and [2; 4] lie inside the segment [2; 4], while [2; 5] and [1; 4] are not.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 1000) β the number of test cases. Then t test cases follow.
The first line of the test case contains one integer n (1 β€ n β€ 3000) β the number of segments. The next n lines describe segments. The i-th segment is given as two integers l_i and r_i (1 β€ l_i β€ r_i β€ 2 β
10^5), where l_i is the left border of the i-th segment and r_i is the right border of the i-th segment.
Additional constraint on the input: there are no duplicates in the list of segments.
It is guaranteed that the sum of n does not exceed 3000 (β n β€ 3000).
Output
For each test case, print the answer: the maximum possible size of the subset of the given set of segments such that each pair of segments in this subset either non-intersecting or one of them lies inside the other one.
Example
Input
4
4
1 5
2 4
2 3
3 4
5
1 5
2 3
2 5
3 5
2 2
3
1 3
2 4
2 3
7
1 10
2 8
2 5
3 4
4 4
6 8
7 7
Output
3
4
2
7
Submitted Solution:
```
from collections import defaultdict
from bisect import bisect_left as lower
import sys,threading
input = sys.stdin.readline
dp = [[ 0]*3005 for _ in range(3005)]
vis= [[-1]*3005 for _ in range(3005)]
def put():
return map(int, input().split())
def func(x,y,seg,t):
if x>y: return 0
if vis[x][y]==t:
return dp[x][y]
vis[x][y]=t
dp[x][y] = func(x+1, y, seg, t)
x_to_y = 0
if x in seg:
for z in seg[x]:
if z==y: x_to_y = 1
if z<=y:
dp[x][y] = max(dp[x][y], func(x,z,seg,t)+func(z+1,y,seg,t))
dp[x][y] += x_to_y
return dp[x][y]
def solve():
t = int(input())
for _ in range(t):
n = int(input())
l,r,m = [],[],[]
seg = defaultdict()
for i in range(n):
x,y = put()
l.append(x);r.append(y)
m.append(x);m.append(y)
m = sorted(set(m))
for i in range(n):
l[i] = lower(m, l[i])
r[i] = lower(m, r[i])
if l[i] not in seg:
seg[l[i]] = []
seg[l[i]].append(r[i])
print(func(0, len(m)-1, seg, _))
max_recur_size = 10**5*2 + 1000
max_stack_size = max_recur_size*500
sys.setrecursionlimit(max_recur_size)
threading.stack_size(max_stack_size)
thread = threading.Thread(target=solve)
thread.start()
``` | instruction | 0 | 54,970 | 23 | 109,940 |
No | output | 1 | 54,970 | 23 | 109,941 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n segments on a coordinate axis OX. The i-th segment has borders [l_i; r_i]. All points x, for which l_i β€ x β€ r_i holds, belong to the i-th segment.
Your task is to choose the maximum by size (the number of segments) subset of the given set of segments such that each pair of segments in this subset either non-intersecting or one of them lies inside the other one.
Two segments [l_i; r_i] and [l_j; r_j] are non-intersecting if they have no common points. For example, segments [1; 2] and [3; 4], [1; 3] and [5; 5] are non-intersecting, while segments [1; 2] and [2; 3], [1; 2] and [2; 2] are intersecting.
The segment [l_i; r_i] lies inside the segment [l_j; r_j] if l_j β€ l_i and r_i β€ r_j. For example, segments [2; 2], [2, 3], [3; 4] and [2; 4] lie inside the segment [2; 4], while [2; 5] and [1; 4] are not.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 1000) β the number of test cases. Then t test cases follow.
The first line of the test case contains one integer n (1 β€ n β€ 3000) β the number of segments. The next n lines describe segments. The i-th segment is given as two integers l_i and r_i (1 β€ l_i β€ r_i β€ 2 β
10^5), where l_i is the left border of the i-th segment and r_i is the right border of the i-th segment.
Additional constraint on the input: there are no duplicates in the list of segments.
It is guaranteed that the sum of n does not exceed 3000 (β n β€ 3000).
Output
For each test case, print the answer: the maximum possible size of the subset of the given set of segments such that each pair of segments in this subset either non-intersecting or one of them lies inside the other one.
Example
Input
4
4
1 5
2 4
2 3
3 4
5
1 5
2 3
2 5
3 5
2 2
3
1 3
2 4
2 3
7
1 10
2 8
2 5
3 4
4 4
6 8
7 7
Output
3
4
2
7
Submitted Solution:
```
t = int(input())
for i in range(t):
num = int(input())
l = []
for j in range(num):
li = list(map(int,input().split()))
l.append(li)
m = []
for j in l:
n = 0
for x in l:
if j[0] <= x[0] and j[1] >= x[1]:
n += 1
elif j[0] >= x[0] and j[1] <= x[1]:
n += 1
elif j[1] < x[0] or x[1] < j[0]:
n += 1
m.append(n)
print(min(m))
``` | instruction | 0 | 54,971 | 23 | 109,942 |
No | output | 1 | 54,971 | 23 | 109,943 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given n segments on a coordinate axis OX. The i-th segment has borders [l_i; r_i]. All points x, for which l_i β€ x β€ r_i holds, belong to the i-th segment.
Your task is to choose the maximum by size (the number of segments) subset of the given set of segments such that each pair of segments in this subset either non-intersecting or one of them lies inside the other one.
Two segments [l_i; r_i] and [l_j; r_j] are non-intersecting if they have no common points. For example, segments [1; 2] and [3; 4], [1; 3] and [5; 5] are non-intersecting, while segments [1; 2] and [2; 3], [1; 2] and [2; 2] are intersecting.
The segment [l_i; r_i] lies inside the segment [l_j; r_j] if l_j β€ l_i and r_i β€ r_j. For example, segments [2; 2], [2, 3], [3; 4] and [2; 4] lie inside the segment [2; 4], while [2; 5] and [1; 4] are not.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 1000) β the number of test cases. Then t test cases follow.
The first line of the test case contains one integer n (1 β€ n β€ 3000) β the number of segments. The next n lines describe segments. The i-th segment is given as two integers l_i and r_i (1 β€ l_i β€ r_i β€ 2 β
10^5), where l_i is the left border of the i-th segment and r_i is the right border of the i-th segment.
Additional constraint on the input: there are no duplicates in the list of segments.
It is guaranteed that the sum of n does not exceed 3000 (β n β€ 3000).
Output
For each test case, print the answer: the maximum possible size of the subset of the given set of segments such that each pair of segments in this subset either non-intersecting or one of them lies inside the other one.
Example
Input
4
4
1 5
2 4
2 3
3 4
5
1 5
2 3
2 5
3 5
2 2
3
1 3
2 4
2 3
7
1 10
2 8
2 5
3 4
4 4
6 8
7 7
Output
3
4
2
7
Submitted Solution:
```
t = int(input())
for T in range(t):
n = int(input())
coords = [[int(i) for i in input().split()] for q in range(n)]
coords.sort()
nonPairs = {i : [] for i in range(n)}
for a in range(n - 1):
b = a + 1
while coords[a][0] == coords[b][0]:
b += 1
if b == n:
break
while b < n:
if coords[b][0] > coords[a][1]:
break
else:
if coords[b][1] > coords[a][1]:
nonPairs[a].append(b)
nonPairs[b].append(a)
b += 1
notChecked = set(range(n))
size = 0
while notChecked:
current = notChecked.pop()
notChecked.add(current)
size += 1
queue = nonPairs[current]
visited = [current] + nonPairs[current]
while queue:
c = queue.pop(0)
for nei in nonPairs[c]:
if nei not in visited:
queue.append(nei)
visited.append(nei)
for qe in visited:
notChecked.remove(qe)
print(size)
``` | instruction | 0 | 54,972 | 23 | 109,944 |
No | output | 1 | 54,972 | 23 | 109,945 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Monocarp wants to draw four line segments on a sheet of paper. He wants the i-th segment to have its length equal to a_i (1 β€ i β€ 4). These segments can intersect with each other, and each segment should be either horizontal or vertical.
Monocarp wants to draw the segments in such a way that they enclose a rectangular space, and the area of that rectangular space should be maximum possible.
For example, if Monocarp wants to draw four segments with lengths 1, 2, 3 and 4, he can do it the following way:
<image> Here, Monocarp has drawn segments AB (with length 1), CD (with length 2), BC (with length 3) and EF (with length 4). He got a rectangle ABCF with area equal to 3 that is enclosed by the segments.
Calculate the maximum area of a rectangle Monocarp can enclose with four segments.
Input
The first line contains one integer t (1 β€ t β€ 3 β
10^4) β the number of test cases.
Each test case consists of a single line containing four integers a_1, a_2, a_3, a_4 (1 β€ a_i β€ 10^4) β the lengths of the segments Monocarp wants to draw.
Output
For each test case, print one integer β the maximum area of a rectangle Monocarp can enclose with four segments (it can be shown that the answer is always an integer).
Example
Input
4
1 2 3 4
5 5 5 5
3 1 4 1
100 20 20 100
Output
3
25
3
2000
Note
The first test case of the example is described in the statement.
For the second test case, Monocarp can draw the segments AB, BC, CD and DA as follows:
<image> Here, Monocarp has drawn segments AB (with length 5), BC (with length 5), CD (with length 5) and DA (with length 5). He got a rectangle ABCD with area equal to 25 that is enclosed by the segments. | instruction | 0 | 54,981 | 23 | 109,962 |
Tags: greedy
Correct Solution:
```
for _ in range(int(input())):
l=list(map(int,input().split()))
l1=[]
for i in range(4):
l1=l1+[max(l)]
l.remove(l1[i])
print(l1[1]*l1[3])
``` | output | 1 | 54,981 | 23 | 109,963 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Monocarp wants to draw four line segments on a sheet of paper. He wants the i-th segment to have its length equal to a_i (1 β€ i β€ 4). These segments can intersect with each other, and each segment should be either horizontal or vertical.
Monocarp wants to draw the segments in such a way that they enclose a rectangular space, and the area of that rectangular space should be maximum possible.
For example, if Monocarp wants to draw four segments with lengths 1, 2, 3 and 4, he can do it the following way:
<image> Here, Monocarp has drawn segments AB (with length 1), CD (with length 2), BC (with length 3) and EF (with length 4). He got a rectangle ABCF with area equal to 3 that is enclosed by the segments.
Calculate the maximum area of a rectangle Monocarp can enclose with four segments.
Input
The first line contains one integer t (1 β€ t β€ 3 β
10^4) β the number of test cases.
Each test case consists of a single line containing four integers a_1, a_2, a_3, a_4 (1 β€ a_i β€ 10^4) β the lengths of the segments Monocarp wants to draw.
Output
For each test case, print one integer β the maximum area of a rectangle Monocarp can enclose with four segments (it can be shown that the answer is always an integer).
Example
Input
4
1 2 3 4
5 5 5 5
3 1 4 1
100 20 20 100
Output
3
25
3
2000
Note
The first test case of the example is described in the statement.
For the second test case, Monocarp can draw the segments AB, BC, CD and DA as follows:
<image> Here, Monocarp has drawn segments AB (with length 5), BC (with length 5), CD (with length 5) and DA (with length 5). He got a rectangle ABCD with area equal to 25 that is enclosed by the segments. | instruction | 0 | 54,982 | 23 | 109,964 |
Tags: greedy
Correct Solution:
```
for _ in range(int(input())):
x=list(map(int,input().split()))
y1=min(x)
y2=max(x)
x.remove(y1)
x.remove(y2)
y3=max(x)
y4=min(x)
print(abs(min(y1,y4)*min(y2,y3)))
``` | output | 1 | 54,982 | 23 | 109,965 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Monocarp wants to draw four line segments on a sheet of paper. He wants the i-th segment to have its length equal to a_i (1 β€ i β€ 4). These segments can intersect with each other, and each segment should be either horizontal or vertical.
Monocarp wants to draw the segments in such a way that they enclose a rectangular space, and the area of that rectangular space should be maximum possible.
For example, if Monocarp wants to draw four segments with lengths 1, 2, 3 and 4, he can do it the following way:
<image> Here, Monocarp has drawn segments AB (with length 1), CD (with length 2), BC (with length 3) and EF (with length 4). He got a rectangle ABCF with area equal to 3 that is enclosed by the segments.
Calculate the maximum area of a rectangle Monocarp can enclose with four segments.
Input
The first line contains one integer t (1 β€ t β€ 3 β
10^4) β the number of test cases.
Each test case consists of a single line containing four integers a_1, a_2, a_3, a_4 (1 β€ a_i β€ 10^4) β the lengths of the segments Monocarp wants to draw.
Output
For each test case, print one integer β the maximum area of a rectangle Monocarp can enclose with four segments (it can be shown that the answer is always an integer).
Example
Input
4
1 2 3 4
5 5 5 5
3 1 4 1
100 20 20 100
Output
3
25
3
2000
Note
The first test case of the example is described in the statement.
For the second test case, Monocarp can draw the segments AB, BC, CD and DA as follows:
<image> Here, Monocarp has drawn segments AB (with length 5), BC (with length 5), CD (with length 5) and DA (with length 5). He got a rectangle ABCD with area equal to 25 that is enclosed by the segments. | instruction | 0 | 54,983 | 23 | 109,966 |
Tags: greedy
Correct Solution:
```
t = int(input())
for _ in range(t):
a, b, c, d = map(int, input().split())
print(max(min(a, b) * min(c, d), min(a, c) * min(b, d), min(a, d) * min(b, c)))
``` | output | 1 | 54,983 | 23 | 109,967 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Monocarp wants to draw four line segments on a sheet of paper. He wants the i-th segment to have its length equal to a_i (1 β€ i β€ 4). These segments can intersect with each other, and each segment should be either horizontal or vertical.
Monocarp wants to draw the segments in such a way that they enclose a rectangular space, and the area of that rectangular space should be maximum possible.
For example, if Monocarp wants to draw four segments with lengths 1, 2, 3 and 4, he can do it the following way:
<image> Here, Monocarp has drawn segments AB (with length 1), CD (with length 2), BC (with length 3) and EF (with length 4). He got a rectangle ABCF with area equal to 3 that is enclosed by the segments.
Calculate the maximum area of a rectangle Monocarp can enclose with four segments.
Input
The first line contains one integer t (1 β€ t β€ 3 β
10^4) β the number of test cases.
Each test case consists of a single line containing four integers a_1, a_2, a_3, a_4 (1 β€ a_i β€ 10^4) β the lengths of the segments Monocarp wants to draw.
Output
For each test case, print one integer β the maximum area of a rectangle Monocarp can enclose with four segments (it can be shown that the answer is always an integer).
Example
Input
4
1 2 3 4
5 5 5 5
3 1 4 1
100 20 20 100
Output
3
25
3
2000
Note
The first test case of the example is described in the statement.
For the second test case, Monocarp can draw the segments AB, BC, CD and DA as follows:
<image> Here, Monocarp has drawn segments AB (with length 5), BC (with length 5), CD (with length 5) and DA (with length 5). He got a rectangle ABCD with area equal to 25 that is enclosed by the segments. | instruction | 0 | 54,984 | 23 | 109,968 |
Tags: greedy
Correct Solution:
```
for _ in range(int(input())):
a1,a2,a3,a4=map(int,input().split())
c=[[a1,a2],[a1,a3],[a1,a4]]
maxi=-1
maxi=max(maxi,min(a1,a2)*min(a3,a4))
maxi=max(maxi,min(a1,a3)*min(a2,a4))
maxi=max(maxi,min(a1,a4)*min(a2,a3))
print(maxi)
``` | output | 1 | 54,984 | 23 | 109,969 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Monocarp wants to draw four line segments on a sheet of paper. He wants the i-th segment to have its length equal to a_i (1 β€ i β€ 4). These segments can intersect with each other, and each segment should be either horizontal or vertical.
Monocarp wants to draw the segments in such a way that they enclose a rectangular space, and the area of that rectangular space should be maximum possible.
For example, if Monocarp wants to draw four segments with lengths 1, 2, 3 and 4, he can do it the following way:
<image> Here, Monocarp has drawn segments AB (with length 1), CD (with length 2), BC (with length 3) and EF (with length 4). He got a rectangle ABCF with area equal to 3 that is enclosed by the segments.
Calculate the maximum area of a rectangle Monocarp can enclose with four segments.
Input
The first line contains one integer t (1 β€ t β€ 3 β
10^4) β the number of test cases.
Each test case consists of a single line containing four integers a_1, a_2, a_3, a_4 (1 β€ a_i β€ 10^4) β the lengths of the segments Monocarp wants to draw.
Output
For each test case, print one integer β the maximum area of a rectangle Monocarp can enclose with four segments (it can be shown that the answer is always an integer).
Example
Input
4
1 2 3 4
5 5 5 5
3 1 4 1
100 20 20 100
Output
3
25
3
2000
Note
The first test case of the example is described in the statement.
For the second test case, Monocarp can draw the segments AB, BC, CD and DA as follows:
<image> Here, Monocarp has drawn segments AB (with length 5), BC (with length 5), CD (with length 5) and DA (with length 5). He got a rectangle ABCD with area equal to 25 that is enclosed by the segments. | instruction | 0 | 54,985 | 23 | 109,970 |
Tags: greedy
Correct Solution:
```
import sys
zz=1
sys.setrecursionlimit(10**5)
if zz:
input=sys.stdin.readline
else:
sys.stdin=open('input.txt', 'r')
sys.stdout=open('all.txt','w')
di=[[-1,0],[1,0],[0,1],[0,-1]]
def fori(n):
return [fi() for i in range(n)]
def inc(d,c,x=1):
d[c]=d[c]+x if c in d else x
def ii():
return input().rstrip()
def li():
return [int(xx) for xx in input().split()]
def fli():
return [float(x) for x in input().split()]
def comp(a,b):
if(a>b):
return 2
return 2 if a==b else 0
def gi():
return [xx for xx in input().split()]
def gtc(tc,ans):
print("Case #"+str(tc)+":",ans)
def cil(n,m):
return n//m+int(n%m>0)
def fi():
return int(input())
def pro(a):
return reduce(lambda a,b:a*b,a)
def swap(a,i,j):
a[i],a[j]=a[j],a[i]
def si():
return list(input().rstrip())
def mi():
return map(int,input().split())
def gh():
sys.stdout.flush()
def isvalid(i,j,n,m):
return 0<=i<n and 0<=j<m
def bo(i):
return ord(i)-ord('a')
def graph(n,m):
for i in range(m):
x,y=mi()
a[x].append(y)
a[y].append(x)
t=fi()
uu=t
while t>0:
t-=1
a=li()
a.sort()
print(a[0]*a[2])
``` | output | 1 | 54,985 | 23 | 109,971 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Monocarp wants to draw four line segments on a sheet of paper. He wants the i-th segment to have its length equal to a_i (1 β€ i β€ 4). These segments can intersect with each other, and each segment should be either horizontal or vertical.
Monocarp wants to draw the segments in such a way that they enclose a rectangular space, and the area of that rectangular space should be maximum possible.
For example, if Monocarp wants to draw four segments with lengths 1, 2, 3 and 4, he can do it the following way:
<image> Here, Monocarp has drawn segments AB (with length 1), CD (with length 2), BC (with length 3) and EF (with length 4). He got a rectangle ABCF with area equal to 3 that is enclosed by the segments.
Calculate the maximum area of a rectangle Monocarp can enclose with four segments.
Input
The first line contains one integer t (1 β€ t β€ 3 β
10^4) β the number of test cases.
Each test case consists of a single line containing four integers a_1, a_2, a_3, a_4 (1 β€ a_i β€ 10^4) β the lengths of the segments Monocarp wants to draw.
Output
For each test case, print one integer β the maximum area of a rectangle Monocarp can enclose with four segments (it can be shown that the answer is always an integer).
Example
Input
4
1 2 3 4
5 5 5 5
3 1 4 1
100 20 20 100
Output
3
25
3
2000
Note
The first test case of the example is described in the statement.
For the second test case, Monocarp can draw the segments AB, BC, CD and DA as follows:
<image> Here, Monocarp has drawn segments AB (with length 5), BC (with length 5), CD (with length 5) and DA (with length 5). He got a rectangle ABCD with area equal to 25 that is enclosed by the segments. | instruction | 0 | 54,986 | 23 | 109,972 |
Tags: greedy
Correct Solution:
```
for _ in range(int(input())):
li = list(map(int, input().split()))
li.sort()
print(li[0]*li[-2])
``` | output | 1 | 54,986 | 23 | 109,973 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Monocarp wants to draw four line segments on a sheet of paper. He wants the i-th segment to have its length equal to a_i (1 β€ i β€ 4). These segments can intersect with each other, and each segment should be either horizontal or vertical.
Monocarp wants to draw the segments in such a way that they enclose a rectangular space, and the area of that rectangular space should be maximum possible.
For example, if Monocarp wants to draw four segments with lengths 1, 2, 3 and 4, he can do it the following way:
<image> Here, Monocarp has drawn segments AB (with length 1), CD (with length 2), BC (with length 3) and EF (with length 4). He got a rectangle ABCF with area equal to 3 that is enclosed by the segments.
Calculate the maximum area of a rectangle Monocarp can enclose with four segments.
Input
The first line contains one integer t (1 β€ t β€ 3 β
10^4) β the number of test cases.
Each test case consists of a single line containing four integers a_1, a_2, a_3, a_4 (1 β€ a_i β€ 10^4) β the lengths of the segments Monocarp wants to draw.
Output
For each test case, print one integer β the maximum area of a rectangle Monocarp can enclose with four segments (it can be shown that the answer is always an integer).
Example
Input
4
1 2 3 4
5 5 5 5
3 1 4 1
100 20 20 100
Output
3
25
3
2000
Note
The first test case of the example is described in the statement.
For the second test case, Monocarp can draw the segments AB, BC, CD and DA as follows:
<image> Here, Monocarp has drawn segments AB (with length 5), BC (with length 5), CD (with length 5) and DA (with length 5). He got a rectangle ABCD with area equal to 25 that is enclosed by the segments. | instruction | 0 | 54,987 | 23 | 109,974 |
Tags: greedy
Correct Solution:
```
n = int(input())
for i in range(n):
lista= [int(x) for x in input().split() ]
lista.sort()
print(min(lista[0],lista[1])*min(lista[2],lista[3]))
``` | output | 1 | 54,987 | 23 | 109,975 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Monocarp wants to draw four line segments on a sheet of paper. He wants the i-th segment to have its length equal to a_i (1 β€ i β€ 4). These segments can intersect with each other, and each segment should be either horizontal or vertical.
Monocarp wants to draw the segments in such a way that they enclose a rectangular space, and the area of that rectangular space should be maximum possible.
For example, if Monocarp wants to draw four segments with lengths 1, 2, 3 and 4, he can do it the following way:
<image> Here, Monocarp has drawn segments AB (with length 1), CD (with length 2), BC (with length 3) and EF (with length 4). He got a rectangle ABCF with area equal to 3 that is enclosed by the segments.
Calculate the maximum area of a rectangle Monocarp can enclose with four segments.
Input
The first line contains one integer t (1 β€ t β€ 3 β
10^4) β the number of test cases.
Each test case consists of a single line containing four integers a_1, a_2, a_3, a_4 (1 β€ a_i β€ 10^4) β the lengths of the segments Monocarp wants to draw.
Output
For each test case, print one integer β the maximum area of a rectangle Monocarp can enclose with four segments (it can be shown that the answer is always an integer).
Example
Input
4
1 2 3 4
5 5 5 5
3 1 4 1
100 20 20 100
Output
3
25
3
2000
Note
The first test case of the example is described in the statement.
For the second test case, Monocarp can draw the segments AB, BC, CD and DA as follows:
<image> Here, Monocarp has drawn segments AB (with length 5), BC (with length 5), CD (with length 5) and DA (with length 5). He got a rectangle ABCD with area equal to 25 that is enclosed by the segments. | instruction | 0 | 54,988 | 23 | 109,976 |
Tags: greedy
Correct Solution:
```
try:
for i in range(int(input())):
a = [int(i) for i in input().split()]
a.sort()
print(a[0]*a[2])
except:
pass
``` | output | 1 | 54,988 | 23 | 109,977 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Monocarp wants to draw four line segments on a sheet of paper. He wants the i-th segment to have its length equal to a_i (1 β€ i β€ 4). These segments can intersect with each other, and each segment should be either horizontal or vertical.
Monocarp wants to draw the segments in such a way that they enclose a rectangular space, and the area of that rectangular space should be maximum possible.
For example, if Monocarp wants to draw four segments with lengths 1, 2, 3 and 4, he can do it the following way:
<image> Here, Monocarp has drawn segments AB (with length 1), CD (with length 2), BC (with length 3) and EF (with length 4). He got a rectangle ABCF with area equal to 3 that is enclosed by the segments.
Calculate the maximum area of a rectangle Monocarp can enclose with four segments.
Input
The first line contains one integer t (1 β€ t β€ 3 β
10^4) β the number of test cases.
Each test case consists of a single line containing four integers a_1, a_2, a_3, a_4 (1 β€ a_i β€ 10^4) β the lengths of the segments Monocarp wants to draw.
Output
For each test case, print one integer β the maximum area of a rectangle Monocarp can enclose with four segments (it can be shown that the answer is always an integer).
Example
Input
4
1 2 3 4
5 5 5 5
3 1 4 1
100 20 20 100
Output
3
25
3
2000
Note
The first test case of the example is described in the statement.
For the second test case, Monocarp can draw the segments AB, BC, CD and DA as follows:
<image> Here, Monocarp has drawn segments AB (with length 5), BC (with length 5), CD (with length 5) and DA (with length 5). He got a rectangle ABCD with area equal to 25 that is enclosed by the segments.
Submitted Solution:
```
# konnichiwa ! korewa boku no template desu # varun kedia
import math
import random
# input methods
def int_input():
return(int(input()))
def list_input():
return([int(x) for x in input().split()])
# end
# main program
#-------------------------------------------------------------------------------------
def program_structure():
pass
a = list_input()
a.sort()
return a[0]*a[-2]
#-------------------------------------------------------------------------------------
# main function for starting the program.
if __name__ == '__main__':
testcases = 1
testcases=int(input())
for i in range(testcases):
ans = program_structure()
if ans==None: # if nothing is returned, skip
continue # this happens when i print multiple answers for a testcase
elif type(ans)==list:
print(*ans) # if list, print while spreading
else:
print(ans) # prints answer for this testcase
``` | instruction | 0 | 54,989 | 23 | 109,978 |
Yes | output | 1 | 54,989 | 23 | 109,979 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Monocarp wants to draw four line segments on a sheet of paper. He wants the i-th segment to have its length equal to a_i (1 β€ i β€ 4). These segments can intersect with each other, and each segment should be either horizontal or vertical.
Monocarp wants to draw the segments in such a way that they enclose a rectangular space, and the area of that rectangular space should be maximum possible.
For example, if Monocarp wants to draw four segments with lengths 1, 2, 3 and 4, he can do it the following way:
<image> Here, Monocarp has drawn segments AB (with length 1), CD (with length 2), BC (with length 3) and EF (with length 4). He got a rectangle ABCF with area equal to 3 that is enclosed by the segments.
Calculate the maximum area of a rectangle Monocarp can enclose with four segments.
Input
The first line contains one integer t (1 β€ t β€ 3 β
10^4) β the number of test cases.
Each test case consists of a single line containing four integers a_1, a_2, a_3, a_4 (1 β€ a_i β€ 10^4) β the lengths of the segments Monocarp wants to draw.
Output
For each test case, print one integer β the maximum area of a rectangle Monocarp can enclose with four segments (it can be shown that the answer is always an integer).
Example
Input
4
1 2 3 4
5 5 5 5
3 1 4 1
100 20 20 100
Output
3
25
3
2000
Note
The first test case of the example is described in the statement.
For the second test case, Monocarp can draw the segments AB, BC, CD and DA as follows:
<image> Here, Monocarp has drawn segments AB (with length 5), BC (with length 5), CD (with length 5) and DA (with length 5). He got a rectangle ABCD with area equal to 25 that is enclosed by the segments.
Submitted Solution:
```
t=int(input())
for i in range(t):
arr=[int(x) for x in input().split()]
arr.sort()
print(arr[0]*arr[2])
``` | instruction | 0 | 54,990 | 23 | 109,980 |
Yes | output | 1 | 54,990 | 23 | 109,981 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Monocarp wants to draw four line segments on a sheet of paper. He wants the i-th segment to have its length equal to a_i (1 β€ i β€ 4). These segments can intersect with each other, and each segment should be either horizontal or vertical.
Monocarp wants to draw the segments in such a way that they enclose a rectangular space, and the area of that rectangular space should be maximum possible.
For example, if Monocarp wants to draw four segments with lengths 1, 2, 3 and 4, he can do it the following way:
<image> Here, Monocarp has drawn segments AB (with length 1), CD (with length 2), BC (with length 3) and EF (with length 4). He got a rectangle ABCF with area equal to 3 that is enclosed by the segments.
Calculate the maximum area of a rectangle Monocarp can enclose with four segments.
Input
The first line contains one integer t (1 β€ t β€ 3 β
10^4) β the number of test cases.
Each test case consists of a single line containing four integers a_1, a_2, a_3, a_4 (1 β€ a_i β€ 10^4) β the lengths of the segments Monocarp wants to draw.
Output
For each test case, print one integer β the maximum area of a rectangle Monocarp can enclose with four segments (it can be shown that the answer is always an integer).
Example
Input
4
1 2 3 4
5 5 5 5
3 1 4 1
100 20 20 100
Output
3
25
3
2000
Note
The first test case of the example is described in the statement.
For the second test case, Monocarp can draw the segments AB, BC, CD and DA as follows:
<image> Here, Monocarp has drawn segments AB (with length 5), BC (with length 5), CD (with length 5) and DA (with length 5). He got a rectangle ABCD with area equal to 25 that is enclosed by the segments.
Submitted Solution:
```
t=int(input())
for o in range(t):
a=list(map(int,input().split()))
b=sorted(a)
p=min(b[0],b[1])
q=min(b[2],b[3])
print(p*q)
``` | instruction | 0 | 54,991 | 23 | 109,982 |
Yes | output | 1 | 54,991 | 23 | 109,983 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Monocarp wants to draw four line segments on a sheet of paper. He wants the i-th segment to have its length equal to a_i (1 β€ i β€ 4). These segments can intersect with each other, and each segment should be either horizontal or vertical.
Monocarp wants to draw the segments in such a way that they enclose a rectangular space, and the area of that rectangular space should be maximum possible.
For example, if Monocarp wants to draw four segments with lengths 1, 2, 3 and 4, he can do it the following way:
<image> Here, Monocarp has drawn segments AB (with length 1), CD (with length 2), BC (with length 3) and EF (with length 4). He got a rectangle ABCF with area equal to 3 that is enclosed by the segments.
Calculate the maximum area of a rectangle Monocarp can enclose with four segments.
Input
The first line contains one integer t (1 β€ t β€ 3 β
10^4) β the number of test cases.
Each test case consists of a single line containing four integers a_1, a_2, a_3, a_4 (1 β€ a_i β€ 10^4) β the lengths of the segments Monocarp wants to draw.
Output
For each test case, print one integer β the maximum area of a rectangle Monocarp can enclose with four segments (it can be shown that the answer is always an integer).
Example
Input
4
1 2 3 4
5 5 5 5
3 1 4 1
100 20 20 100
Output
3
25
3
2000
Note
The first test case of the example is described in the statement.
For the second test case, Monocarp can draw the segments AB, BC, CD and DA as follows:
<image> Here, Monocarp has drawn segments AB (with length 5), BC (with length 5), CD (with length 5) and DA (with length 5). He got a rectangle ABCD with area equal to 25 that is enclosed by the segments.
Submitted Solution:
```
x=int(input())
for i in range(x):
m=list(map(int,input().split()))[:4]
m.sort()
print(m[0]*m[2])
``` | instruction | 0 | 54,992 | 23 | 109,984 |
Yes | output | 1 | 54,992 | 23 | 109,985 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Monocarp wants to draw four line segments on a sheet of paper. He wants the i-th segment to have its length equal to a_i (1 β€ i β€ 4). These segments can intersect with each other, and each segment should be either horizontal or vertical.
Monocarp wants to draw the segments in such a way that they enclose a rectangular space, and the area of that rectangular space should be maximum possible.
For example, if Monocarp wants to draw four segments with lengths 1, 2, 3 and 4, he can do it the following way:
<image> Here, Monocarp has drawn segments AB (with length 1), CD (with length 2), BC (with length 3) and EF (with length 4). He got a rectangle ABCF with area equal to 3 that is enclosed by the segments.
Calculate the maximum area of a rectangle Monocarp can enclose with four segments.
Input
The first line contains one integer t (1 β€ t β€ 3 β
10^4) β the number of test cases.
Each test case consists of a single line containing four integers a_1, a_2, a_3, a_4 (1 β€ a_i β€ 10^4) β the lengths of the segments Monocarp wants to draw.
Output
For each test case, print one integer β the maximum area of a rectangle Monocarp can enclose with four segments (it can be shown that the answer is always an integer).
Example
Input
4
1 2 3 4
5 5 5 5
3 1 4 1
100 20 20 100
Output
3
25
3
2000
Note
The first test case of the example is described in the statement.
For the second test case, Monocarp can draw the segments AB, BC, CD and DA as follows:
<image> Here, Monocarp has drawn segments AB (with length 5), BC (with length 5), CD (with length 5) and DA (with length 5). He got a rectangle ABCD with area equal to 25 that is enclosed by the segments.
Submitted Solution:
```
from itertools import groupby
for _ in range(int(input())):
a = list(set([ int(x) for x in input().split() ]))
if len(a) == 1:
print(a[0] * a[0])
elif len(a) == 2:
print(a[0] * a[1])
elif len(a) == 3:
a.remove(max(a))
print(min(a) * max(a))
else:
a.remove(max(a))
print(min(a) * max(a))
``` | instruction | 0 | 54,993 | 23 | 109,986 |
No | output | 1 | 54,993 | 23 | 109,987 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Monocarp wants to draw four line segments on a sheet of paper. He wants the i-th segment to have its length equal to a_i (1 β€ i β€ 4). These segments can intersect with each other, and each segment should be either horizontal or vertical.
Monocarp wants to draw the segments in such a way that they enclose a rectangular space, and the area of that rectangular space should be maximum possible.
For example, if Monocarp wants to draw four segments with lengths 1, 2, 3 and 4, he can do it the following way:
<image> Here, Monocarp has drawn segments AB (with length 1), CD (with length 2), BC (with length 3) and EF (with length 4). He got a rectangle ABCF with area equal to 3 that is enclosed by the segments.
Calculate the maximum area of a rectangle Monocarp can enclose with four segments.
Input
The first line contains one integer t (1 β€ t β€ 3 β
10^4) β the number of test cases.
Each test case consists of a single line containing four integers a_1, a_2, a_3, a_4 (1 β€ a_i β€ 10^4) β the lengths of the segments Monocarp wants to draw.
Output
For each test case, print one integer β the maximum area of a rectangle Monocarp can enclose with four segments (it can be shown that the answer is always an integer).
Example
Input
4
1 2 3 4
5 5 5 5
3 1 4 1
100 20 20 100
Output
3
25
3
2000
Note
The first test case of the example is described in the statement.
For the second test case, Monocarp can draw the segments AB, BC, CD and DA as follows:
<image> Here, Monocarp has drawn segments AB (with length 5), BC (with length 5), CD (with length 5) and DA (with length 5). He got a rectangle ABCD with area equal to 25 that is enclosed by the segments.
Submitted Solution:
```
for _ in range(int(input())):
r = [int(i) for i in input().split()]
r.sort()
print(r)
print(r[0]*r[2])
``` | instruction | 0 | 54,994 | 23 | 109,988 |
No | output | 1 | 54,994 | 23 | 109,989 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Monocarp wants to draw four line segments on a sheet of paper. He wants the i-th segment to have its length equal to a_i (1 β€ i β€ 4). These segments can intersect with each other, and each segment should be either horizontal or vertical.
Monocarp wants to draw the segments in such a way that they enclose a rectangular space, and the area of that rectangular space should be maximum possible.
For example, if Monocarp wants to draw four segments with lengths 1, 2, 3 and 4, he can do it the following way:
<image> Here, Monocarp has drawn segments AB (with length 1), CD (with length 2), BC (with length 3) and EF (with length 4). He got a rectangle ABCF with area equal to 3 that is enclosed by the segments.
Calculate the maximum area of a rectangle Monocarp can enclose with four segments.
Input
The first line contains one integer t (1 β€ t β€ 3 β
10^4) β the number of test cases.
Each test case consists of a single line containing four integers a_1, a_2, a_3, a_4 (1 β€ a_i β€ 10^4) β the lengths of the segments Monocarp wants to draw.
Output
For each test case, print one integer β the maximum area of a rectangle Monocarp can enclose with four segments (it can be shown that the answer is always an integer).
Example
Input
4
1 2 3 4
5 5 5 5
3 1 4 1
100 20 20 100
Output
3
25
3
2000
Note
The first test case of the example is described in the statement.
For the second test case, Monocarp can draw the segments AB, BC, CD and DA as follows:
<image> Here, Monocarp has drawn segments AB (with length 5), BC (with length 5), CD (with length 5) and DA (with length 5). He got a rectangle ABCD with area equal to 25 that is enclosed by the segments.
Submitted Solution:
```
from __future__ import division, print_function
import bisect
import math
import heapq
import itertools
import sys
from collections import deque
from atexit import register
from collections import Counter
from functools import reduce
if sys.version_info[0] < 3:
from io import BytesIO as stream
else:
from io import StringIO as stream
def sync_with_stdio(sync=True):
"""Set whether the standard Python streams are allowed to buffer their I/O.
Args:
sync (bool, optional): The new synchronization setting.
"""
global input, flush
if sync:
flush = sys.stdout.flush
else:
sys.stdin = stream(sys.stdin.read())
input = lambda: sys.stdin.readline().rstrip('\r\n')
sys.stdout = stream()
register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))
for _ in range(int(input())):
a = list(map(int, input().split()))
a.sort()
b = list(set(a))
if len(b) == 1:
print(a[0] * a[0])
else:
print(b[0] * b[1])
``` | instruction | 0 | 54,995 | 23 | 109,990 |
No | output | 1 | 54,995 | 23 | 109,991 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Monocarp wants to draw four line segments on a sheet of paper. He wants the i-th segment to have its length equal to a_i (1 β€ i β€ 4). These segments can intersect with each other, and each segment should be either horizontal or vertical.
Monocarp wants to draw the segments in such a way that they enclose a rectangular space, and the area of that rectangular space should be maximum possible.
For example, if Monocarp wants to draw four segments with lengths 1, 2, 3 and 4, he can do it the following way:
<image> Here, Monocarp has drawn segments AB (with length 1), CD (with length 2), BC (with length 3) and EF (with length 4). He got a rectangle ABCF with area equal to 3 that is enclosed by the segments.
Calculate the maximum area of a rectangle Monocarp can enclose with four segments.
Input
The first line contains one integer t (1 β€ t β€ 3 β
10^4) β the number of test cases.
Each test case consists of a single line containing four integers a_1, a_2, a_3, a_4 (1 β€ a_i β€ 10^4) β the lengths of the segments Monocarp wants to draw.
Output
For each test case, print one integer β the maximum area of a rectangle Monocarp can enclose with four segments (it can be shown that the answer is always an integer).
Example
Input
4
1 2 3 4
5 5 5 5
3 1 4 1
100 20 20 100
Output
3
25
3
2000
Note
The first test case of the example is described in the statement.
For the second test case, Monocarp can draw the segments AB, BC, CD and DA as follows:
<image> Here, Monocarp has drawn segments AB (with length 5), BC (with length 5), CD (with length 5) and DA (with length 5). He got a rectangle ABCD with area equal to 25 that is enclosed by the segments.
Submitted Solution:
```
def process(n):
n.sort()
return int(n[0])*int(n[2])
t = int(input())
for i in range(t):
inp = input().split()
print(process(inp))
``` | instruction | 0 | 54,996 | 23 | 109,992 |
No | output | 1 | 54,996 | 23 | 109,993 |
Provide tags and a correct Python 3 solution for this coding contest problem.
After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned pool written on a paper, until his friend came along and erased some of the vertices.
Now Wilbur is wondering, if the remaining n vertices of the initial rectangle give enough information to restore the area of the planned swimming pool.
Input
The first line of the input contains a single integer n (1 β€ n β€ 4) β the number of vertices that were not erased by Wilbur's friend.
Each of the following n lines contains two integers xi and yi ( - 1000 β€ xi, yi β€ 1000) βthe coordinates of the i-th vertex that remains. Vertices are given in an arbitrary order.
It's guaranteed that these points are distinct vertices of some rectangle, that has positive area and which sides are parallel to the coordinate axes.
Output
Print the area of the initial rectangle if it could be uniquely determined by the points remaining. Otherwise, print - 1.
Examples
Input
2
0 0
1 1
Output
1
Input
1
1 1
Output
-1
Note
In the first sample, two opposite corners of the initial rectangle are given, and that gives enough information to say that the rectangle is actually a unit square.
In the second sample there is only one vertex left and this is definitely not enough to uniquely define the area. | instruction | 0 | 55,206 | 23 | 110,412 |
Tags: geometry, implementation
Correct Solution:
```
n = int(input())
a = {}
b = {}
for i in range(n):
t1, t2 = map(int, input().split())
a[t1] = t1
b[t2] = t2
if (len(a) < 2 or len(b) < 2):
print(-1)
else:
r1 = 0
flag = 0
for i in a:
if (flag == 1):
r1 -= i
else:
r1 += i
flag = 1
r2 = 0
flag = 0
for i in b:
if (flag == 1):
r2 -= i
else:
r2 += i
flag = 1
r = r1 * r2
if (r < 0):
r *= -1
print(r)
``` | output | 1 | 55,206 | 23 | 110,413 |
Provide tags and a correct Python 3 solution for this coding contest problem.
After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned pool written on a paper, until his friend came along and erased some of the vertices.
Now Wilbur is wondering, if the remaining n vertices of the initial rectangle give enough information to restore the area of the planned swimming pool.
Input
The first line of the input contains a single integer n (1 β€ n β€ 4) β the number of vertices that were not erased by Wilbur's friend.
Each of the following n lines contains two integers xi and yi ( - 1000 β€ xi, yi β€ 1000) βthe coordinates of the i-th vertex that remains. Vertices are given in an arbitrary order.
It's guaranteed that these points are distinct vertices of some rectangle, that has positive area and which sides are parallel to the coordinate axes.
Output
Print the area of the initial rectangle if it could be uniquely determined by the points remaining. Otherwise, print - 1.
Examples
Input
2
0 0
1 1
Output
1
Input
1
1 1
Output
-1
Note
In the first sample, two opposite corners of the initial rectangle are given, and that gives enough information to say that the rectangle is actually a unit square.
In the second sample there is only one vertex left and this is definitely not enough to uniquely define the area. | instruction | 0 | 55,207 | 23 | 110,414 |
Tags: geometry, implementation
Correct Solution:
```
n = int(input())
points = [[int(x) for x in input().split()] for _ in range(n)]
if n <= 1:
print(-1)
exit()
dx = [1e9, -1e9]
dy = [1e9, -1e9]
for x, y in points:
dx[0] = min(dx[0], x)
dx[1] = max(dx[1], x)
dy[0] = min(dy[0], y)
dy[1] = max(dy[1], y)
area = (dx[1] - dx[0]) * (dy[1] - dy[0])
if area:
print(area)
else:
print(-1)
``` | output | 1 | 55,207 | 23 | 110,415 |
Provide tags and a correct Python 3 solution for this coding contest problem.
After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned pool written on a paper, until his friend came along and erased some of the vertices.
Now Wilbur is wondering, if the remaining n vertices of the initial rectangle give enough information to restore the area of the planned swimming pool.
Input
The first line of the input contains a single integer n (1 β€ n β€ 4) β the number of vertices that were not erased by Wilbur's friend.
Each of the following n lines contains two integers xi and yi ( - 1000 β€ xi, yi β€ 1000) βthe coordinates of the i-th vertex that remains. Vertices are given in an arbitrary order.
It's guaranteed that these points are distinct vertices of some rectangle, that has positive area and which sides are parallel to the coordinate axes.
Output
Print the area of the initial rectangle if it could be uniquely determined by the points remaining. Otherwise, print - 1.
Examples
Input
2
0 0
1 1
Output
1
Input
1
1 1
Output
-1
Note
In the first sample, two opposite corners of the initial rectangle are given, and that gives enough information to say that the rectangle is actually a unit square.
In the second sample there is only one vertex left and this is definitely not enough to uniquely define the area. | instruction | 0 | 55,208 | 23 | 110,416 |
Tags: geometry, implementation
Correct Solution:
```
n=int(input())
if n==1:
x1,y1 = map(int, input().strip().split(' '))
print(-1)
elif n==2:
x1,y1 = map(int, input().strip().split(' '))
x2,y2 = map(int, input().strip().split(' '))
if x1==x2 or y1==y2:
print(-1)
else:
print(abs(x1-x2)*abs(y1-y2))
elif n==3:
x1,y1 = map(int, input().strip().split(' '))
x2,y2 = map(int, input().strip().split(' '))
x3,y3 = map(int, input().strip().split(' '))
if x1!=x2 and y1!=y2:
print(abs(x1-x2)*abs(y1-y2))
elif x1!=x3 and y1!=y3:
print(abs(x1-x3)*abs(y1-y3))
else:
print(abs(x2-x3)*abs(y2-y3))
else:
x1,y1 = map(int, input().strip().split(' '))
x2,y2 = map(int, input().strip().split(' '))
x3,y3 = map(int, input().strip().split(' '))
x4,y4 = map(int, input().strip().split(' '))
if x1!=x2 and y1!=y2:
print(abs(x1-x2)*abs(y1-y2))
elif x1!=x3 and y1!=y3:
print(abs(x1-x3)*abs(y1-y3))
else:
print(abs(x1-x4)*abs(y1-y4))
#lst = list(map(int, input().strip().split(' ')))
``` | output | 1 | 55,208 | 23 | 110,417 |
Provide tags and a correct Python 3 solution for this coding contest problem.
After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned pool written on a paper, until his friend came along and erased some of the vertices.
Now Wilbur is wondering, if the remaining n vertices of the initial rectangle give enough information to restore the area of the planned swimming pool.
Input
The first line of the input contains a single integer n (1 β€ n β€ 4) β the number of vertices that were not erased by Wilbur's friend.
Each of the following n lines contains two integers xi and yi ( - 1000 β€ xi, yi β€ 1000) βthe coordinates of the i-th vertex that remains. Vertices are given in an arbitrary order.
It's guaranteed that these points are distinct vertices of some rectangle, that has positive area and which sides are parallel to the coordinate axes.
Output
Print the area of the initial rectangle if it could be uniquely determined by the points remaining. Otherwise, print - 1.
Examples
Input
2
0 0
1 1
Output
1
Input
1
1 1
Output
-1
Note
In the first sample, two opposite corners of the initial rectangle are given, and that gives enough information to say that the rectangle is actually a unit square.
In the second sample there is only one vertex left and this is definitely not enough to uniquely define the area. | instruction | 0 | 55,209 | 23 | 110,418 |
Tags: geometry, implementation
Correct Solution:
```
n = int(input())
if n>2:
a = []
for i in range(n):
x, y = map(int, input().split())
a.append([x,y])
for j in range(n-1):
for k in range(j+1,n):
if a[j][0]!=a[k][0] and a[j][1]!=a[k][1]:
print(abs(a[j][0]-a[k][0])*abs(a[j][1]-a[k][1]))
exit()
if n==2:
x1, y1 = map(int, input().split())
x2, y2 = map(int, input().split())
if x1==x2 or y1 ==y2:
print(-1)
else:
print(abs(x1-x2)*abs(y1-y2))
else:
x,y = map(int,input().split())
print(-1)
``` | output | 1 | 55,209 | 23 | 110,419 |
Provide tags and a correct Python 3 solution for this coding contest problem.
After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned pool written on a paper, until his friend came along and erased some of the vertices.
Now Wilbur is wondering, if the remaining n vertices of the initial rectangle give enough information to restore the area of the planned swimming pool.
Input
The first line of the input contains a single integer n (1 β€ n β€ 4) β the number of vertices that were not erased by Wilbur's friend.
Each of the following n lines contains two integers xi and yi ( - 1000 β€ xi, yi β€ 1000) βthe coordinates of the i-th vertex that remains. Vertices are given in an arbitrary order.
It's guaranteed that these points are distinct vertices of some rectangle, that has positive area and which sides are parallel to the coordinate axes.
Output
Print the area of the initial rectangle if it could be uniquely determined by the points remaining. Otherwise, print - 1.
Examples
Input
2
0 0
1 1
Output
1
Input
1
1 1
Output
-1
Note
In the first sample, two opposite corners of the initial rectangle are given, and that gives enough information to say that the rectangle is actually a unit square.
In the second sample there is only one vertex left and this is definitely not enough to uniquely define the area. | instruction | 0 | 55,210 | 23 | 110,420 |
Tags: geometry, implementation
Correct Solution:
```
v = int(input())
def pl3(v):
point = []
for i in range(v):
point.append(input().split())
for k in point:
for j in point:
if k[0] != j[0] and k[1] != j[1]:
return abs((int(k[0])-int(j[0]))*(int(k[1])-int(j[1])))
break
return -1
if v == 1:
print('-1')
else:
print(pl3(v))
``` | output | 1 | 55,210 | 23 | 110,421 |
Provide tags and a correct Python 3 solution for this coding contest problem.
After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned pool written on a paper, until his friend came along and erased some of the vertices.
Now Wilbur is wondering, if the remaining n vertices of the initial rectangle give enough information to restore the area of the planned swimming pool.
Input
The first line of the input contains a single integer n (1 β€ n β€ 4) β the number of vertices that were not erased by Wilbur's friend.
Each of the following n lines contains two integers xi and yi ( - 1000 β€ xi, yi β€ 1000) βthe coordinates of the i-th vertex that remains. Vertices are given in an arbitrary order.
It's guaranteed that these points are distinct vertices of some rectangle, that has positive area and which sides are parallel to the coordinate axes.
Output
Print the area of the initial rectangle if it could be uniquely determined by the points remaining. Otherwise, print - 1.
Examples
Input
2
0 0
1 1
Output
1
Input
1
1 1
Output
-1
Note
In the first sample, two opposite corners of the initial rectangle are given, and that gives enough information to say that the rectangle is actually a unit square.
In the second sample there is only one vertex left and this is definitely not enough to uniquely define the area. | instruction | 0 | 55,211 | 23 | 110,422 |
Tags: geometry, implementation
Correct Solution:
```
n=int(input())
a=[]
for i in range(n):
b= list(map(int, input().split()))
a.append(b)
if n==1:print(-1)
elif n==2:
if a[0][0]!=a[1][0] and a[0][1]!=a[1][1]:
print(abs(a[0][0]-a[1][0])*abs(a[0][1]-a[1][1]))
else:print(-1)
elif n==3:
x1,x2,x3,y1,y2,y3=a[0][0],a[1][0],a[2][0],a[0][1],a[1][1],a[2][1]
if x1-x2!=0 and y1-y2!=0:print(abs(x1-x2)*abs(y1-y2))
elif x1-x3!=0 and y1-y3!=0:print(abs(x1-x3)*abs(y1-y3))
else:print(abs(x3-x2)*abs(y3-y2))
else:
x1,x2,x3,x4,y1,y2,y3,y4=a[0][0],a[1][0],a[2][0],a[3][0],a[0][1],a[1][1],a[2][1],a[3][1]
if x1-x2!=0 and y1-y2!=0:print(abs(x1-x2)*abs(y1-y2))
elif x1-x3!=0 and y1-y3!=0:print(abs(x1-x3)*abs(y1-y3))
else:print(abs(x1-x4)*abs(y1-y4))
``` | output | 1 | 55,211 | 23 | 110,423 |
Provide tags and a correct Python 3 solution for this coding contest problem.
After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned pool written on a paper, until his friend came along and erased some of the vertices.
Now Wilbur is wondering, if the remaining n vertices of the initial rectangle give enough information to restore the area of the planned swimming pool.
Input
The first line of the input contains a single integer n (1 β€ n β€ 4) β the number of vertices that were not erased by Wilbur's friend.
Each of the following n lines contains two integers xi and yi ( - 1000 β€ xi, yi β€ 1000) βthe coordinates of the i-th vertex that remains. Vertices are given in an arbitrary order.
It's guaranteed that these points are distinct vertices of some rectangle, that has positive area and which sides are parallel to the coordinate axes.
Output
Print the area of the initial rectangle if it could be uniquely determined by the points remaining. Otherwise, print - 1.
Examples
Input
2
0 0
1 1
Output
1
Input
1
1 1
Output
-1
Note
In the first sample, two opposite corners of the initial rectangle are given, and that gives enough information to say that the rectangle is actually a unit square.
In the second sample there is only one vertex left and this is definitely not enough to uniquely define the area. | instruction | 0 | 55,212 | 23 | 110,424 |
Tags: geometry, implementation
Correct Solution:
```
n = int(input())
p = [0] * n
for i in range(n):
p[i] = tuple(map(int, input().split()))
if n == 4:
for i in range(1, 4):
if p[0][0] != p[i][0] and p[0][1] != p[i][1]:
res = abs(p[0][0] - p[i][0]) * abs(p[0][1] - p[i][1])
elif n == 3:
for i in range(1, 3):
if p[0][0] != p[i][0] and p[0][1] != p[i][1]:
res = abs(p[0][0] - p[i][0]) * abs(p[0][1] - p[i][1])
for i in [0, 2]:
if p[1][0] != p[i][0] and p[1][1] != p[i][1]:
res = abs(p[1][0] - p[i][0]) * abs(p[1][1] - p[i][1])
elif n == 2:
if p[0][0] != p[1][0] and p[0][1] != p[1][1]:
res = abs(p[0][0] - p[1][0]) * abs(p[0][1] - p[1][1])
else: res = -1
else:
res = -1
print(res)
``` | output | 1 | 55,212 | 23 | 110,425 |
Provide tags and a correct Python 3 solution for this coding contest problem.
After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned pool written on a paper, until his friend came along and erased some of the vertices.
Now Wilbur is wondering, if the remaining n vertices of the initial rectangle give enough information to restore the area of the planned swimming pool.
Input
The first line of the input contains a single integer n (1 β€ n β€ 4) β the number of vertices that were not erased by Wilbur's friend.
Each of the following n lines contains two integers xi and yi ( - 1000 β€ xi, yi β€ 1000) βthe coordinates of the i-th vertex that remains. Vertices are given in an arbitrary order.
It's guaranteed that these points are distinct vertices of some rectangle, that has positive area and which sides are parallel to the coordinate axes.
Output
Print the area of the initial rectangle if it could be uniquely determined by the points remaining. Otherwise, print - 1.
Examples
Input
2
0 0
1 1
Output
1
Input
1
1 1
Output
-1
Note
In the first sample, two opposite corners of the initial rectangle are given, and that gives enough information to say that the rectangle is actually a unit square.
In the second sample there is only one vertex left and this is definitely not enough to uniquely define the area. | instruction | 0 | 55,213 | 23 | 110,426 |
Tags: geometry, implementation
Correct Solution:
```
# print("Input n")
n = int(input())
a = [[0 for i in range(2)] for j in range(n)]
for i in range(n):
# print("Input the next pair of vertices")
x,y = [int(t) for t in input().split()]
a[i][0] = x
a[i][1] = y
if n == 1:
print(-1)
elif n == 2: # Can do it if they form a diagonal
if a[0][0] == a[1][0] or a[0][1] == a[1][1]:
print(-1)
else:
print(abs(a[0][0] - a[1][0]) * abs(a[0][1] - a[1][1]))
else: # n == 3 or n == 4
# Find the two that are on a diag--then same logic as before
# Just compute three and take the positive one
one = abs(a[0][0] - a[1][0]) * abs(a[0][1] - a[1][1])
two = abs(a[0][0] - a[2][0]) * abs(a[0][1] - a[2][1])
three = abs(a[1][0] - a[2][0]) * abs(a[1][1] - a[2][1])
print(max(one, two, three))
``` | output | 1 | 55,213 | 23 | 110,427 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned pool written on a paper, until his friend came along and erased some of the vertices.
Now Wilbur is wondering, if the remaining n vertices of the initial rectangle give enough information to restore the area of the planned swimming pool.
Input
The first line of the input contains a single integer n (1 β€ n β€ 4) β the number of vertices that were not erased by Wilbur's friend.
Each of the following n lines contains two integers xi and yi ( - 1000 β€ xi, yi β€ 1000) βthe coordinates of the i-th vertex that remains. Vertices are given in an arbitrary order.
It's guaranteed that these points are distinct vertices of some rectangle, that has positive area and which sides are parallel to the coordinate axes.
Output
Print the area of the initial rectangle if it could be uniquely determined by the points remaining. Otherwise, print - 1.
Examples
Input
2
0 0
1 1
Output
1
Input
1
1 1
Output
-1
Note
In the first sample, two opposite corners of the initial rectangle are given, and that gives enough information to say that the rectangle is actually a unit square.
In the second sample there is only one vertex left and this is definitely not enough to uniquely define the area.
Submitted Solution:
```
#!/usr/bin/python3.5
n=int(input())
if n==1:
print(-1)
quit()
if n==2:
a,b=[int(x) for x in input().split()]
c,d=[int(x) for x in input().split()]
if a!=c and b!=d:
print(abs(a-c)*abs(b-d))
quit()
else:
print(-1)
quit()
if n==3:
a,b=[int(x) for x in input().split()]
c,d=[int(x) for x in input().split()]
e,f=[int(x) for x in input().split()]
k=[abs(a-c),abs(a-e)]
l=[abs(b-d),abs(b-f)]
print(max(k)*max(l))
quit()
a,b=[int(x) for x in input().split()]
c,d=[int(x) for x in input().split()]
e,f=[int(x) for x in input().split()]
g,h=[int(x) for x in input().split()]
k=[abs(a-c),abs(a-e)]
l=[abs(b-d),abs(b-f)]
print(max(k)*max(l))
``` | instruction | 0 | 55,214 | 23 | 110,428 |
Yes | output | 1 | 55,214 | 23 | 110,429 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned pool written on a paper, until his friend came along and erased some of the vertices.
Now Wilbur is wondering, if the remaining n vertices of the initial rectangle give enough information to restore the area of the planned swimming pool.
Input
The first line of the input contains a single integer n (1 β€ n β€ 4) β the number of vertices that were not erased by Wilbur's friend.
Each of the following n lines contains two integers xi and yi ( - 1000 β€ xi, yi β€ 1000) βthe coordinates of the i-th vertex that remains. Vertices are given in an arbitrary order.
It's guaranteed that these points are distinct vertices of some rectangle, that has positive area and which sides are parallel to the coordinate axes.
Output
Print the area of the initial rectangle if it could be uniquely determined by the points remaining. Otherwise, print - 1.
Examples
Input
2
0 0
1 1
Output
1
Input
1
1 1
Output
-1
Note
In the first sample, two opposite corners of the initial rectangle are given, and that gives enough information to say that the rectangle is actually a unit square.
In the second sample there is only one vertex left and this is definitely not enough to uniquely define the area.
Submitted Solution:
```
n = int(input())
read = lambda : map(int,input().split())
x1,y1 = read()
x2=x1
y2=y1
for _ in range(n-1):
x,y = read()
x1 = min(x1,x)
x2 = max(x2,x)
y1 = min(y1,y)
y2 = max(y2,y)
if x1==x2 or y1==y2:
print(-1)
else:
print((x2-x1)*(y2-y1))
``` | instruction | 0 | 55,215 | 23 | 110,430 |
Yes | output | 1 | 55,215 | 23 | 110,431 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned pool written on a paper, until his friend came along and erased some of the vertices.
Now Wilbur is wondering, if the remaining n vertices of the initial rectangle give enough information to restore the area of the planned swimming pool.
Input
The first line of the input contains a single integer n (1 β€ n β€ 4) β the number of vertices that were not erased by Wilbur's friend.
Each of the following n lines contains two integers xi and yi ( - 1000 β€ xi, yi β€ 1000) βthe coordinates of the i-th vertex that remains. Vertices are given in an arbitrary order.
It's guaranteed that these points are distinct vertices of some rectangle, that has positive area and which sides are parallel to the coordinate axes.
Output
Print the area of the initial rectangle if it could be uniquely determined by the points remaining. Otherwise, print - 1.
Examples
Input
2
0 0
1 1
Output
1
Input
1
1 1
Output
-1
Note
In the first sample, two opposite corners of the initial rectangle are given, and that gives enough information to say that the rectangle is actually a unit square.
In the second sample there is only one vertex left and this is definitely not enough to uniquely define the area.
Submitted Solution:
```
n = int(input())
a = [[0] * 2 for i in range(n)]
for i in range(n):
a[i][0], a[i][1] = map(int, input().split())
if n < 2:
print(-1)
elif n == 2:
if a[0][0] == a[1][0] or a[0][1] == a[1][1]:
print(-1)
else:
print(abs(a[0][0] - a[1][0]) * abs(a[0][1] - a[1][1]))
else:
if a[0][0] == a[1][0] or a[0][1] == a[1][1]:
if a[0][0] == a[2][0] or a[0][1] == a[2][1]:
print(abs(a[2][0] - a[1][0]) * abs(a[2][1] - a[1][1]))
else:
print(abs(a[2][0] - a[0][0]) * abs(a[2][1] - a[0][1]))
else:
print(abs(a[0][0] - a[1][0]) * abs(a[0][1] - a[1][1]))
``` | instruction | 0 | 55,216 | 23 | 110,432 |
Yes | output | 1 | 55,216 | 23 | 110,433 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned pool written on a paper, until his friend came along and erased some of the vertices.
Now Wilbur is wondering, if the remaining n vertices of the initial rectangle give enough information to restore the area of the planned swimming pool.
Input
The first line of the input contains a single integer n (1 β€ n β€ 4) β the number of vertices that were not erased by Wilbur's friend.
Each of the following n lines contains two integers xi and yi ( - 1000 β€ xi, yi β€ 1000) βthe coordinates of the i-th vertex that remains. Vertices are given in an arbitrary order.
It's guaranteed that these points are distinct vertices of some rectangle, that has positive area and which sides are parallel to the coordinate axes.
Output
Print the area of the initial rectangle if it could be uniquely determined by the points remaining. Otherwise, print - 1.
Examples
Input
2
0 0
1 1
Output
1
Input
1
1 1
Output
-1
Note
In the first sample, two opposite corners of the initial rectangle are given, and that gives enough information to say that the rectangle is actually a unit square.
In the second sample there is only one vertex left and this is definitely not enough to uniquely define the area.
Submitted Solution:
```
n = int(input())
xs = set()
ys = set()
for i in range(n):
x, y = map(int, input().split())
xs.add(x)
ys.add(y)
if len(xs) == 2 and len(ys) == 2:
x1, x2 = xs
y1, y2 = ys
print(abs((x1 - x2)*(y1 - y2)))
else:
print(-1)
``` | instruction | 0 | 55,217 | 23 | 110,434 |
Yes | output | 1 | 55,217 | 23 | 110,435 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned pool written on a paper, until his friend came along and erased some of the vertices.
Now Wilbur is wondering, if the remaining n vertices of the initial rectangle give enough information to restore the area of the planned swimming pool.
Input
The first line of the input contains a single integer n (1 β€ n β€ 4) β the number of vertices that were not erased by Wilbur's friend.
Each of the following n lines contains two integers xi and yi ( - 1000 β€ xi, yi β€ 1000) βthe coordinates of the i-th vertex that remains. Vertices are given in an arbitrary order.
It's guaranteed that these points are distinct vertices of some rectangle, that has positive area and which sides are parallel to the coordinate axes.
Output
Print the area of the initial rectangle if it could be uniquely determined by the points remaining. Otherwise, print - 1.
Examples
Input
2
0 0
1 1
Output
1
Input
1
1 1
Output
-1
Note
In the first sample, two opposite corners of the initial rectangle are given, and that gives enough information to say that the rectangle is actually a unit square.
In the second sample there is only one vertex left and this is definitely not enough to uniquely define the area.
Submitted Solution:
```
n = int(input())
lst_x = []
lst_y = []
output = -1
for _ in range(n):
x,y = map(int, input().split())
if x not in lst_x and y not in lst_y:
lst_x.append(x)
lst_y.append(y)
if len(lst_x) == 2:
output = abs(lst_x[0] - lst_x[1]) * abs(lst_y[0] - lst_y[1])
print(output)
``` | instruction | 0 | 55,218 | 23 | 110,436 |
No | output | 1 | 55,218 | 23 | 110,437 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned pool written on a paper, until his friend came along and erased some of the vertices.
Now Wilbur is wondering, if the remaining n vertices of the initial rectangle give enough information to restore the area of the planned swimming pool.
Input
The first line of the input contains a single integer n (1 β€ n β€ 4) β the number of vertices that were not erased by Wilbur's friend.
Each of the following n lines contains two integers xi and yi ( - 1000 β€ xi, yi β€ 1000) βthe coordinates of the i-th vertex that remains. Vertices are given in an arbitrary order.
It's guaranteed that these points are distinct vertices of some rectangle, that has positive area and which sides are parallel to the coordinate axes.
Output
Print the area of the initial rectangle if it could be uniquely determined by the points remaining. Otherwise, print - 1.
Examples
Input
2
0 0
1 1
Output
1
Input
1
1 1
Output
-1
Note
In the first sample, two opposite corners of the initial rectangle are given, and that gives enough information to say that the rectangle is actually a unit square.
In the second sample there is only one vertex left and this is definitely not enough to uniquely define the area.
Submitted Solution:
```
n=int(input())
mas=[]
if (n>1) and (n<5):
for i in range(n):
mas.append(input().split(" "))
for i in range(len(mas)):
for j in range(2):
mas[i][j]=int(mas[i][j])
s=[]
mas1=[]
for i in sorted(mas):
mas1.append(i)
print(mas1)
if abs((mas1[0][0])-(mas1[-1][0]))*abs((mas1[0][1])-mas1[-1][1])!=0:
print(abs((mas1[0][0])-(mas1[-1][0]))*abs((mas1[0][1])-mas1[-1][1]))
elif n==3 and abs((mas1[0][0])-(mas1[-1][0]))*abs((mas1[0][1])-mas1[-1][1])==0:
print(abs((mas1[0][0])-(mas1[-1][0]))*abs((mas1[0][1])-mas1[-2][1]))
else:
print(-1)
else:
print(-1)
``` | instruction | 0 | 55,219 | 23 | 110,438 |
No | output | 1 | 55,219 | 23 | 110,439 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned pool written on a paper, until his friend came along and erased some of the vertices.
Now Wilbur is wondering, if the remaining n vertices of the initial rectangle give enough information to restore the area of the planned swimming pool.
Input
The first line of the input contains a single integer n (1 β€ n β€ 4) β the number of vertices that were not erased by Wilbur's friend.
Each of the following n lines contains two integers xi and yi ( - 1000 β€ xi, yi β€ 1000) βthe coordinates of the i-th vertex that remains. Vertices are given in an arbitrary order.
It's guaranteed that these points are distinct vertices of some rectangle, that has positive area and which sides are parallel to the coordinate axes.
Output
Print the area of the initial rectangle if it could be uniquely determined by the points remaining. Otherwise, print - 1.
Examples
Input
2
0 0
1 1
Output
1
Input
1
1 1
Output
-1
Note
In the first sample, two opposite corners of the initial rectangle are given, and that gives enough information to say that the rectangle is actually a unit square.
In the second sample there is only one vertex left and this is definitely not enough to uniquely define the area.
Submitted Solution:
```
n=int(input())
r=[]
for j in range(n):
(q,w)=(int(i) for i in input().split())
r.append([q,w])
def sq(a,b):
return abs((a[1]-b[1])*(a[0]-b[0]))
if n==1:
print('-1')
else:
if n==2:
if r[0][0]!=r[1][0] and r[0][1]!=r[1][1]:
print(sq(r[1],r[0]))
else:
print('-1')
else:
max(sq(r[1],r[0]),sq(r[2],r[1]),sq(r[2],r[0]))
``` | instruction | 0 | 55,220 | 23 | 110,440 |
No | output | 1 | 55,220 | 23 | 110,441 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned pool written on a paper, until his friend came along and erased some of the vertices.
Now Wilbur is wondering, if the remaining n vertices of the initial rectangle give enough information to restore the area of the planned swimming pool.
Input
The first line of the input contains a single integer n (1 β€ n β€ 4) β the number of vertices that were not erased by Wilbur's friend.
Each of the following n lines contains two integers xi and yi ( - 1000 β€ xi, yi β€ 1000) βthe coordinates of the i-th vertex that remains. Vertices are given in an arbitrary order.
It's guaranteed that these points are distinct vertices of some rectangle, that has positive area and which sides are parallel to the coordinate axes.
Output
Print the area of the initial rectangle if it could be uniquely determined by the points remaining. Otherwise, print - 1.
Examples
Input
2
0 0
1 1
Output
1
Input
1
1 1
Output
-1
Note
In the first sample, two opposite corners of the initial rectangle are given, and that gives enough information to say that the rectangle is actually a unit square.
In the second sample there is only one vertex left and this is definitely not enough to uniquely define the area.
Submitted Solution:
```
a=int(input())
if a in [3,4]:
print('1')
elif a == 2:
b=input().split()
c=input().split()
if b[0]!=c[0] and b[1]!=c[1]:
print('1')
else:
print('-1')
else:
print('-1')
``` | instruction | 0 | 55,221 | 23 | 110,442 |
No | output | 1 | 55,221 | 23 | 110,443 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya likes to draw. He drew N red and M blue points on the plane in such a way that no three points lie on the same line. Now he wonders what is the number of distinct triangles with vertices in red points which do not contain any blue point inside.
Input
The first line contains two non-negative integer numbers N and M (0 β€ N β€ 500, 0 β€ M β€ 500) β the number of red and blue points respectively. The following N lines contain two integer numbers each β coordinates of red points. The following M lines contain two integer numbers each β coordinates of blue points. All coordinates do not exceed 109 by absolute value.
Output
Output one integer β the number of distinct triangles with vertices in red points which do not contain any blue point inside.
Examples
Input
4 1
0 0
10 0
10 10
5 4
2 1
Output
2
Input
5 5
5 10
6 1
8 6
-6 -7
7 -1
5 -1
10 -4
-10 -8
-10 5
-2 -8
Output
7
Submitted Solution:
```
import itertools
def area(x1, y1, x2, y2, x3, y3):
return abs((x1 * (y2 - y3) + x2 * (y3 - y1)
+ x3 * (y1 - y2)) / 2.0)
# A function to check whether point P(x, y)
# lies inside the triangle formed by
# A(x1, y1), B(x2, y2) and C(x3, y3)
def isInside(x1, y1, x2, y2, x3, y3, x, y):
# Calculate area of triangle ABC
A = area (x1, y1, x2, y2, x3, y3)
# Calculate area of triangle PBC
A1 = area (x, y, x2, y2, x3, y3)
# Calculate area of triangle PAC
A2 = area (x1, y1, x, y, x3, y3)
# Calculate area of triangle PAB
A3 = area (x1, y1, x2, y2, x, y)
# Check if sum of A1, A2 and A3
# is same as A
if(A == A1 + A2 + A3):
return True
else:
return False
def intri(r,b):
x1=r[0][0]
x2=r[1][0]
x3=r[2][0]
y1=r[0][1]
y2=r[1][1]
y3=r[2][1]
x=b[0]
y=b[1]
if isInside(x1,y1,x2,y2,x3,y3,x,y) is True:
return True
else:
return False
n,m=list(map(int,input().split()))
nl=[]
ml=[]
for i in range(n):
nl.append(list(map(int,input().split())))
#print(nl)
for i in range(m):
ml.append(list(map(int,input().split())))
#print(ml)
com=list(itertools.combinations(nl,3))
#print(com)
count=0
for z in ml:
for r in com:
if intri(r,z) is False:
count+=1
print(count)
``` | instruction | 0 | 55,778 | 23 | 111,556 |
No | output | 1 | 55,778 | 23 | 111,557 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Little Petya likes to draw. He drew N red and M blue points on the plane in such a way that no three points lie on the same line. Now he wonders what is the number of distinct triangles with vertices in red points which do not contain any blue point inside.
Input
The first line contains two non-negative integer numbers N and M (0 β€ N β€ 500, 0 β€ M β€ 500) β the number of red and blue points respectively. The following N lines contain two integer numbers each β coordinates of red points. The following M lines contain two integer numbers each β coordinates of blue points. All coordinates do not exceed 109 by absolute value.
Output
Output one integer β the number of distinct triangles with vertices in red points which do not contain any blue point inside.
Examples
Input
4 1
0 0
10 0
10 10
5 4
2 1
Output
2
Input
5 5
5 10
6 1
8 6
-6 -7
7 -1
5 -1
10 -4
-10 -8
-10 5
-2 -8
Output
7
Submitted Solution:
```
import itertools
def area(x1, y1, x2, y2, x3, y3):
return abs((x1 * (y2 - y3) + x2 * (y3 - y1)
+ x3 * (y1 - y2)) / 2.0)
# A function to check whether point P(x, y)
# lies inside the triangle formed by
# A(x1, y1), B(x2, y2) and C(x3, y3)
def isInside(x1, y1, x2, y2, x3, y3, x, y):
# Calculate area of triangle ABC
A = area (x1, y1, x2, y2, x3, y3)
# Calculate area of triangle PBC
A1 = area (x, y, x2, y2, x3, y3)
# Calculate area of triangle PAC
A2 = area (x1, y1, x, y, x3, y3)
# Calculate area of triangle PAB
A3 = area (x1, y1, x2, y2, x, y)
# Check if sum of A1, A2 and A3
# is same as A
if(A == A1 + A2 + A3):
return True
else:
return False
def intri(r,b):
x1=r[0][0]
x2=r[1][0]
x3=r[2][0]
y1=r[0][1]
y2=r[1][1]
y3=r[2][1]
x=b[0]
y=b[1]
if isInside(x1,y1,x2,y2,x3,y3,x,y) is True:
return True
else:
return False
n,m=list(map(int,input().split()))
nl=[]
ml=[]
for i in range(n):
nl.append(list(map(int,input().split())))
print(nl)
for i in range(m):
ml.append(list(map(int,input().split())))
print(ml)
com=list(itertools.combinations(nl,3))
print(com)
count=0
for z in ml:
for r in com:
if intri(r,z) is False:
count+=1
print(count)
``` | instruction | 0 | 55,779 | 23 | 111,558 |
No | output | 1 | 55,779 | 23 | 111,559 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasily the bear has a favorite rectangle, it has one vertex at point (0, 0), and the opposite vertex at point (x, y). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate axes.
Vasya also loves triangles, if the triangles have one vertex at point B = (0, 0). That's why today he asks you to find two points A = (x1, y1) and C = (x2, y2), such that the following conditions hold:
* the coordinates of points: x1, x2, y1, y2 are integers. Besides, the following inequation holds: x1 < x2;
* the triangle formed by point A, B and C is rectangular and isosceles (<image> is right);
* all points of the favorite rectangle are located inside or on the border of triangle ABC;
* the area of triangle ABC is as small as possible.
Help the bear, find the required points. It is not so hard to proof that these points are unique.
Input
The first line contains two integers x, y ( - 109 β€ x, y β€ 109, x β 0, y β 0).
Output
Print in the single line four integers x1, y1, x2, y2 β the coordinates of the required points.
Examples
Input
10 5
Output
0 15 15 0
Input
-10 5
Output
-15 0 0 15
Note
<image>
Figure to the first sample | instruction | 0 | 55,916 | 23 | 111,832 |
Tags: implementation, math
Correct Solution:
```
x,y=map(int,input().split())
sum1=abs(x)+abs(y)
if(y>0):
if(x<0):
print(-1*(sum1),0,0,sum1)
else:
print(0,sum1,sum1,0)
else:
if(x<0):
print(-1*(sum1),0,0,-1*(sum1))
else:
print(0,-1*(sum1),sum1,0)
``` | output | 1 | 55,916 | 23 | 111,833 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.