inputs
stringlengths 50
14k
| targets
stringlengths 4
655k
|
---|---|
Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the input. Then $t$ test cases follow.
Each test case is given in two lines.
The first line contains two integers $a_1$ and $b_1$ ($1 \le a_1, b_1 \le 100$) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length).
The second line contains two integers $a_2$ and $b_2$ ($1 \le a_2, b_2 \le 100$) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length).
-----Output-----
Print $t$ answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower).
-----Example-----
Input
3
2 3
3 1
3 2
1 3
3 3
1 3
Output
Yes
Yes
No
|
import math
for _ in range(int(input())):
a,b=list(map(int,input().split()))
c,d=list(map(int,input().split()))
if min(c,d)+min(a,b)==max(a,b) and max(a,b)==max(c,d):
print("Yes")
else:
print("No")
|
Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the input. Then $t$ test cases follow.
Each test case is given in two lines.
The first line contains two integers $a_1$ and $b_1$ ($1 \le a_1, b_1 \le 100$) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length).
The second line contains two integers $a_2$ and $b_2$ ($1 \le a_2, b_2 \le 100$) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length).
-----Output-----
Print $t$ answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower).
-----Example-----
Input
3
2 3
3 1
3 2
1 3
3 3
1 3
Output
Yes
Yes
No
|
import sys
for t in range(int(sys.stdin.readline())):
a, b = list(map(int, sys.stdin.readline().split()))
x, y = list(map(int, sys.stdin.readline().split()))
a, b = min(a, b), max(a, b)
x, y = min(x, y), max(x, y)
if b == y and b == a + x:
sys.stdout.write("Yes\n")
else:
sys.stdout.write("No\n")
|
Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the input. Then $t$ test cases follow.
Each test case is given in two lines.
The first line contains two integers $a_1$ and $b_1$ ($1 \le a_1, b_1 \le 100$) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length).
The second line contains two integers $a_2$ and $b_2$ ($1 \le a_2, b_2 \le 100$) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length).
-----Output-----
Print $t$ answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower).
-----Example-----
Input
3
2 3
3 1
3 2
1 3
3 3
1 3
Output
Yes
Yes
No
|
import sys,bisect,string,math,time,functools,random
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,ls=None,Directed=False,index=1):
org_inp=[];g=[[] for i in range(V)]
FromStdin=True if ls==None else False
for i in range(E):
if FromStdin:
inp=LI()
org_inp.append(inp)
else:
inp=ls[i]
if len(inp)==2:
a,b=inp;c=1
else:
a,b,c=inp
if index==1:a-=1;b-=1
aa=(a,c);bb=(b,c);g[a].append(bb)
if not Directed:g[b].append(aa)
return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1):
#h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
mp=[boundary]*(w+2);found={}
for i in range(h):
s=input()
for char in search:
if char in s:
found[char]=((i+1)*(w+2)+s.index(char)+1)
mp_def[char]=mp_def[replacement_of_found]
mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
mp+=[boundary]*(w+2)
return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(k,n=2):
rt=[]
for tb in range(n**k):
s=[tb//(n**bt)%n for bt in range(k)];rt+=[s]
return rt
def show(*inp,end='\n'):
if show_flg:print(*inp,end=end)
YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()
class Tree:
def __init__(self,inp_size=None,init=True):
self.LCA_init_stat=False
self.ETtable=[]
if init:
self.stdin(inp_size)
return
def stdin(self,inp_size=None,index=1):
if inp_size==None:
self.size=int(input())
else:
self.size=inp_size
self.edges,_=GI(self.size,self.size-1,index=index)
return
def listin(self,ls,index=0):
self.size=len(ls)+1
self.edges,_=GI(self.size,self.size-1,ls,index=index)
return
def __str__(self):
return str(self.edges)
def dfs(self,x,func=lambda prv,nx,dist:prv+dist,root_v=0):
q=deque()
q.append(x)
v=[-1]*self.size
v[x]=root_v
while q:
c=q.pop()
for nb,d in self.edges[c]:
if v[nb]==-1:
q.append(nb)
v[nb]=func(v[c],nb,d)
return v
def EulerTour(self,x):
q=deque()
q.append(x)
self.depth=[None]*self.size
self.depth[x]=0
self.ETtable=[]
self.ETdepth=[]
self.ETin=[-1]*self.size
self.ETout=[-1]*self.size
cnt=0
while q:
c=q.pop()
if c<0:
ce=~c
else:
ce=c
for nb,d in self.edges[ce]:
if self.depth[nb]==None:
q.append(~ce)
q.append(nb)
self.depth[nb]=self.depth[ce]+1
self.ETtable.append(ce)
self.ETdepth.append(self.depth[ce])
if self.ETin[ce]==-1:
self.ETin[ce]=cnt
else:
self.ETout[ce]=cnt
cnt+=1
return
def LCA_init(self,root):
self.EulerTour(root)
self.st=SparseTable(self.ETdepth,init_func=min,init_idl=inf)
self.LCA_init_stat=True
return
def LCA(self,root,x,y):
if self.LCA_init_stat==False:
self.LCA_init(root)
xin,xout=self.ETin[x],self.ETout[x]
yin,yout=self.ETin[y],self.ETout[y]
a=min(xin,yin)
b=max(xout,yout,xin,yin)
id_of_min_dep_in_et=self.st.query_id(a,b+1)
return self.ETtable[id_of_min_dep_in_et]
class SparseTable: # O(N log N) for init, O(1) for query(l,r)
def __init__(self,ls,init_func=min,init_idl=float('inf')):
self.func=init_func
self.idl=init_idl
self.size=len(ls)
self.N0=self.size.bit_length()
self.table=[ls[:]]
self.index=[list(range(self.size))]
self.lg=[0]*(self.size+1)
for i in range(2,self.size+1):
self.lg[i]=self.lg[i>>1]+1
for i in range(self.N0):
tmp=[self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) for j in range(self.size)]
tmp_id=[self.index[i][j] if self.table[i][j]==self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) else self.index[i][min(j+(1<<i),self.size-1)] for j in range(self.size)]
self.table+=[tmp]
self.index+=[tmp_id]
# return func of [l,r)
def query(self,l,r):
#N=(r-l).bit_length()-1
N=self.lg[r-l]
return self.func(self.table[N][l],self.table[N][r-(1<<N)])
# return index of which val[i] = func of v among [l,r)
def query_id(self,l,r):
#N=(r-l).bit_length()-1
N=self.lg[r-l]
a,b=self.index[N][l],self.index[N][r-(1<<N)]
if self.table[0][a]==self.func(self.table[N][l],self.table[N][r-(1<<N)]):
b=a
return b
def __str__(self):
return str(self.table[0])
def print(self):
for i in self.table:
print(*i)
show_flg=False
show_flg=True
ans=0
T=I()
for _ in range(T):
a,b=LI()
c,d=LI()
if a>b:
a,b=b,a
if c>d:
c,d=d,c
ans='Yes' if b==d and a+c==b else 'No'
print(ans)
|
Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the input. Then $t$ test cases follow.
Each test case is given in two lines.
The first line contains two integers $a_1$ and $b_1$ ($1 \le a_1, b_1 \le 100$) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length).
The second line contains two integers $a_2$ and $b_2$ ($1 \le a_2, b_2 \le 100$) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length).
-----Output-----
Print $t$ answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower).
-----Example-----
Input
3
2 3
3 1
3 2
1 3
3 3
1 3
Output
Yes
Yes
No
|
q = int(input())
for _ in range(q):
a, b = list(map(int, input().split()))
c, d = list(map(int, input().split()))
a, b = min(a, b), max(a, b)
c, d = min(c, d), max(c, d)
if b == d and a+c == b:
print("Yes")
else:
print("No")
|
Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the input. Then $t$ test cases follow.
Each test case is given in two lines.
The first line contains two integers $a_1$ and $b_1$ ($1 \le a_1, b_1 \le 100$) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length).
The second line contains two integers $a_2$ and $b_2$ ($1 \le a_2, b_2 \le 100$) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length).
-----Output-----
Print $t$ answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower).
-----Example-----
Input
3
2 3
3 1
3 2
1 3
3 3
1 3
Output
Yes
Yes
No
|
t=int(input())
for tests in range(t):
a1,b1=list(map(int,input().split()))
a2,b2=list(map(int,input().split()))
if min(a1,b1)+min(a2,b2)==max(a1,b1)==max(a2,b2):
print("Yes")
else:
print("No")
|
Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the input. Then $t$ test cases follow.
Each test case is given in two lines.
The first line contains two integers $a_1$ and $b_1$ ($1 \le a_1, b_1 \le 100$) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length).
The second line contains two integers $a_2$ and $b_2$ ($1 \le a_2, b_2 \le 100$) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length).
-----Output-----
Print $t$ answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower).
-----Example-----
Input
3
2 3
3 1
3 2
1 3
3 3
1 3
Output
Yes
Yes
No
|
for _ in range(int(input())):
a, b = list(map(int,input().split()))
c, d = list(map(int,input().split()))
if b > a:
a, b = b, a
if d > c:
c, d = d, c
if a == c == b+d:
print("Yes")
else:
print("No")
|
Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the input. Then $t$ test cases follow.
Each test case is given in two lines.
The first line contains two integers $a_1$ and $b_1$ ($1 \le a_1, b_1 \le 100$) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length).
The second line contains two integers $a_2$ and $b_2$ ($1 \le a_2, b_2 \le 100$) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length).
-----Output-----
Print $t$ answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower).
-----Example-----
Input
3
2 3
3 1
3 2
1 3
3 3
1 3
Output
Yes
Yes
No
|
for __ in range(int(input())):
a,b=map(int,input().split())
x,y=map(int,input().split())
if(a==x and b+y==x):
print("Yes")
elif(a==y and b+x==y):
print("Yes")
elif(b==x and a+y==x):
print("Yes")
elif(b==y and a+x==y):
print("Yes")
else:
print("No")
|
Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the input. Then $t$ test cases follow.
Each test case is given in two lines.
The first line contains two integers $a_1$ and $b_1$ ($1 \le a_1, b_1 \le 100$) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length).
The second line contains two integers $a_2$ and $b_2$ ($1 \le a_2, b_2 \le 100$) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length).
-----Output-----
Print $t$ answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower).
-----Example-----
Input
3
2 3
3 1
3 2
1 3
3 3
1 3
Output
Yes
Yes
No
|
t=int(input())
for i in range(t):
a,b=list(map(int,input().split()))
c,d=list(map(int,input().split()))
if max(a,b)==max(c,d):
if min(a,b)+min(c,d)==max(a,b):
print("Yes")
else:
print("No")
else:
print("No")
|
Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the input. Then $t$ test cases follow.
Each test case is given in two lines.
The first line contains two integers $a_1$ and $b_1$ ($1 \le a_1, b_1 \le 100$) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length).
The second line contains two integers $a_2$ and $b_2$ ($1 \le a_2, b_2 \le 100$) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length).
-----Output-----
Print $t$ answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower).
-----Example-----
Input
3
2 3
3 1
3 2
1 3
3 3
1 3
Output
Yes
Yes
No
|
t = int(input())
for i in range(t):
a, b = list(map(int, input().split()))
c, d = list(map(int, input().split()))
if a + c == b == d or a + d == b == c or b + c == a == d or b + d == a == c:
print("Yes")
else:
print("No")
|
Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the input. Then $t$ test cases follow.
Each test case is given in two lines.
The first line contains two integers $a_1$ and $b_1$ ($1 \le a_1, b_1 \le 100$) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length).
The second line contains two integers $a_2$ and $b_2$ ($1 \le a_2, b_2 \le 100$) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length).
-----Output-----
Print $t$ answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower).
-----Example-----
Input
3
2 3
3 1
3 2
1 3
3 3
1 3
Output
Yes
Yes
No
|
for n in range(int(input())):
a,b=map(int,input().split())
c,d=map(int,input().split())
m1=max(a,b)
n1=min(a,b)
m2=max(c,d)
n2=min(c,d)
if m1==m2 and n1+n2==m1:
print('Yes')
else:
print('No')
|
Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the input. Then $t$ test cases follow.
Each test case is given in two lines.
The first line contains two integers $a_1$ and $b_1$ ($1 \le a_1, b_1 \le 100$) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length).
The second line contains two integers $a_2$ and $b_2$ ($1 \le a_2, b_2 \le 100$) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length).
-----Output-----
Print $t$ answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower).
-----Example-----
Input
3
2 3
3 1
3 2
1 3
3 3
1 3
Output
Yes
Yes
No
|
a=int(input())
for i in range(a):
x,y=list(map(int,input().split()))
r,s=list(map(int,input().split()))
if(x==s and y+r==s):
print('Yes')
elif(x==r and y+s==x):
print('Yes')
elif(y==s and x+r==y):
print('Yes')
elif(y==r and x+s==y):
print('Yes')
else:
print('No')
|
Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the input. Then $t$ test cases follow.
Each test case is given in two lines.
The first line contains two integers $a_1$ and $b_1$ ($1 \le a_1, b_1 \le 100$) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length).
The second line contains two integers $a_2$ and $b_2$ ($1 \le a_2, b_2 \le 100$) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length).
-----Output-----
Print $t$ answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower).
-----Example-----
Input
3
2 3
3 1
3 2
1 3
3 3
1 3
Output
Yes
Yes
No
|
from sys import stdin, exit
input = stdin.readline
def i(): return input()
def ii(): return int(input())
def iis(): return list(map(int, input().split()))
def liis(): return list(map(int, input().split()))
def print_array(a): print(" ".join(map(str, a)))
t = ii()
for _ in range(t):
a1, b1 = iis()
a2, b2 = iis()
if (a1 == a2 and b1+b2 == a1) or (a1 == b2 and a2+b1 == a1) or (a2 == b1 and a1+b2 == a2) or (b2 == b1 and a1+a2 == b2):
print("Yes")
else:
print("No")
|
Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the input. Then $t$ test cases follow.
Each test case is given in two lines.
The first line contains two integers $a_1$ and $b_1$ ($1 \le a_1, b_1 \le 100$) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length).
The second line contains two integers $a_2$ and $b_2$ ($1 \le a_2, b_2 \le 100$) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length).
-----Output-----
Print $t$ answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower).
-----Example-----
Input
3
2 3
3 1
3 2
1 3
3 3
1 3
Output
Yes
Yes
No
|
T = int(input())
for t in range(T):
i1 = [int(i) for i in input().split(' ')]
i2 = [int(i) for i in input().split(' ')]
if i1[0]==i2[0] and i1[1]+i2[1]==i1[0]:
print('Yes')
elif i1[0]==i2[1] and i1[1]+i2[0]==i1[0]:
print('Yes')
elif i1[1]==i2[0] and i1[0]+i2[1]==i1[1]:
print('Yes')
elif i1[1]==i2[1] and i1[0]+i2[0]==i1[1]:
print('Yes')
else:
print('No')
|
Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the input. Then $t$ test cases follow.
Each test case is given in two lines.
The first line contains two integers $a_1$ and $b_1$ ($1 \le a_1, b_1 \le 100$) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length).
The second line contains two integers $a_2$ and $b_2$ ($1 \le a_2, b_2 \le 100$) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length).
-----Output-----
Print $t$ answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower).
-----Example-----
Input
3
2 3
3 1
3 2
1 3
3 3
1 3
Output
Yes
Yes
No
|
def read_int():
return int(input())
def read_ints():
return list(map(int, input().split(' ')))
t = read_int()
for case_num in range(t):
a = list(read_ints())
b = list(read_ints())
ok = False
for i in range(2):
for j in range(2):
if a[i] != b[j]:
continue
if a[1 - i] + b[1 - j] == a[i]:
ok = True
print('Yes' if ok else 'No')
|
Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rectangles.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the input. Then $t$ test cases follow.
Each test case is given in two lines.
The first line contains two integers $a_1$ and $b_1$ ($1 \le a_1, b_1 \le 100$) — the dimensions of the first one obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length).
The second line contains two integers $a_2$ and $b_2$ ($1 \le a_2, b_2 \le 100$) — the dimensions of the second obtained after cutting rectangle. The sizes are given in random order (that is, it is not known which of the numbers is the width, and which of the numbers is the length).
-----Output-----
Print $t$ answers, each of which is a string "YES" (in the case of a positive answer) or "NO" (in the case of a negative answer). The letters in words can be printed in any case (upper or lower).
-----Example-----
Input
3
2 3
3 1
3 2
1 3
3 3
1 3
Output
Yes
Yes
No
|
q = int(input())
for i in range(q):
a1, b1 = map(int, input().split())
a2, b2 = map(int, input().split())
if max(a1, b1) == max(a2, b2) == (min(a1, b1) + min(a2, b2)):
print('Yes')
else:
print('No')
|
Screen resolution of Polycarp's monitor is $a \times b$ pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates $(x, y)$ ($0 \le x < a, 0 \le y < b$). You can consider columns of pixels to be numbered from $0$ to $a-1$, and rows — from $0$ to $b-1$.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
-----Input-----
In the first line you are given an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test. In the next lines you are given descriptions of $t$ test cases.
Each test case contains a single line which consists of $4$ integers $a, b, x$ and $y$ ($1 \le a, b \le 10^4$; $0 \le x < a$; $0 \le y < b$) — the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that $a+b>2$ (e.g. $a=b=1$ is impossible).
-----Output-----
Print $t$ integers — the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
-----Example-----
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
-----Note-----
In the first test case, the screen resolution is $8 \times 8$, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window. [Image]
|
from math import *
zzz = int(input())
for zz in range(zzz):
a, b, x, y = list(map(int, input().split()))
print(max(x*b, (a-x-1)*b, y*a, (b - y - 1)*a))
|
Screen resolution of Polycarp's monitor is $a \times b$ pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates $(x, y)$ ($0 \le x < a, 0 \le y < b$). You can consider columns of pixels to be numbered from $0$ to $a-1$, and rows — from $0$ to $b-1$.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
-----Input-----
In the first line you are given an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test. In the next lines you are given descriptions of $t$ test cases.
Each test case contains a single line which consists of $4$ integers $a, b, x$ and $y$ ($1 \le a, b \le 10^4$; $0 \le x < a$; $0 \le y < b$) — the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that $a+b>2$ (e.g. $a=b=1$ is impossible).
-----Output-----
Print $t$ integers — the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
-----Example-----
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
-----Note-----
In the first test case, the screen resolution is $8 \times 8$, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window. [Image]
|
for t in range(int(input())):
a, b, x, y = [int(i) for i in input().split()]
l = max(x, a - 1 - x)
h = max(y, b - 1 - y)
print(max(l * b, h * a))
|
Screen resolution of Polycarp's monitor is $a \times b$ pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates $(x, y)$ ($0 \le x < a, 0 \le y < b$). You can consider columns of pixels to be numbered from $0$ to $a-1$, and rows — from $0$ to $b-1$.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
-----Input-----
In the first line you are given an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test. In the next lines you are given descriptions of $t$ test cases.
Each test case contains a single line which consists of $4$ integers $a, b, x$ and $y$ ($1 \le a, b \le 10^4$; $0 \le x < a$; $0 \le y < b$) — the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that $a+b>2$ (e.g. $a=b=1$ is impossible).
-----Output-----
Print $t$ integers — the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
-----Example-----
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
-----Note-----
In the first test case, the screen resolution is $8 \times 8$, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window. [Image]
|
for _ in range(int(input())):
a, b, x, y = list(map(int, input().split()))
num1 = x * b
num2 = y * a
num3 = (a - x - 1) * b
num4 = (b - y - 1) * a
print(max(num2, num1, num3, num4))
|
Screen resolution of Polycarp's monitor is $a \times b$ pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates $(x, y)$ ($0 \le x < a, 0 \le y < b$). You can consider columns of pixels to be numbered from $0$ to $a-1$, and rows — from $0$ to $b-1$.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
-----Input-----
In the first line you are given an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test. In the next lines you are given descriptions of $t$ test cases.
Each test case contains a single line which consists of $4$ integers $a, b, x$ and $y$ ($1 \le a, b \le 10^4$; $0 \le x < a$; $0 \le y < b$) — the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that $a+b>2$ (e.g. $a=b=1$ is impossible).
-----Output-----
Print $t$ integers — the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
-----Example-----
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
-----Note-----
In the first test case, the screen resolution is $8 \times 8$, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window. [Image]
|
for _ in range(int(input())):
a, b, x, y = map(int, input().split())
w = max(a-1-x, x)
h = max(b-1-y, y)
ans = max(w * b, h * a)
print(ans)
|
Screen resolution of Polycarp's monitor is $a \times b$ pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates $(x, y)$ ($0 \le x < a, 0 \le y < b$). You can consider columns of pixels to be numbered from $0$ to $a-1$, and rows — from $0$ to $b-1$.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
-----Input-----
In the first line you are given an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test. In the next lines you are given descriptions of $t$ test cases.
Each test case contains a single line which consists of $4$ integers $a, b, x$ and $y$ ($1 \le a, b \le 10^4$; $0 \le x < a$; $0 \le y < b$) — the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that $a+b>2$ (e.g. $a=b=1$ is impossible).
-----Output-----
Print $t$ integers — the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
-----Example-----
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
-----Note-----
In the first test case, the screen resolution is $8 \times 8$, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window. [Image]
|
for _ in range(int(input())):
a, b, x, y = list(map(int, input().split()))
print(max(x*b, y*a, (a-x-1)*b, (b-y-1)*a))
|
Screen resolution of Polycarp's monitor is $a \times b$ pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates $(x, y)$ ($0 \le x < a, 0 \le y < b$). You can consider columns of pixels to be numbered from $0$ to $a-1$, and rows — from $0$ to $b-1$.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
-----Input-----
In the first line you are given an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test. In the next lines you are given descriptions of $t$ test cases.
Each test case contains a single line which consists of $4$ integers $a, b, x$ and $y$ ($1 \le a, b \le 10^4$; $0 \le x < a$; $0 \le y < b$) — the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that $a+b>2$ (e.g. $a=b=1$ is impossible).
-----Output-----
Print $t$ integers — the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
-----Example-----
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
-----Note-----
In the first test case, the screen resolution is $8 \times 8$, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window. [Image]
|
t = int(input())
for _ in range(t):
a, b, x, y = map(int, input().split())
r = max([a*y, a*(b-y-1), b*x, b*(a-x-1)])
print(r)
|
Screen resolution of Polycarp's monitor is $a \times b$ pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates $(x, y)$ ($0 \le x < a, 0 \le y < b$). You can consider columns of pixels to be numbered from $0$ to $a-1$, and rows — from $0$ to $b-1$.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
-----Input-----
In the first line you are given an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test. In the next lines you are given descriptions of $t$ test cases.
Each test case contains a single line which consists of $4$ integers $a, b, x$ and $y$ ($1 \le a, b \le 10^4$; $0 \le x < a$; $0 \le y < b$) — the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that $a+b>2$ (e.g. $a=b=1$ is impossible).
-----Output-----
Print $t$ integers — the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
-----Example-----
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
-----Note-----
In the first test case, the screen resolution is $8 \times 8$, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window. [Image]
|
t = int(input())
for _ in range(t):
a, b, x, y = list(map(int, input().split()))
print(max(a*y, a*(b-y-1), x*b, (a-x-1)*b))
|
Screen resolution of Polycarp's monitor is $a \times b$ pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates $(x, y)$ ($0 \le x < a, 0 \le y < b$). You can consider columns of pixels to be numbered from $0$ to $a-1$, and rows — from $0$ to $b-1$.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
-----Input-----
In the first line you are given an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test. In the next lines you are given descriptions of $t$ test cases.
Each test case contains a single line which consists of $4$ integers $a, b, x$ and $y$ ($1 \le a, b \le 10^4$; $0 \le x < a$; $0 \le y < b$) — the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that $a+b>2$ (e.g. $a=b=1$ is impossible).
-----Output-----
Print $t$ integers — the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
-----Example-----
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
-----Note-----
In the first test case, the screen resolution is $8 \times 8$, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window. [Image]
|
t = int(input())
for _ in range(t):
a, b, x, y = map(int, input().split())
l = max(a*y, a*(b-y-1))
ll = max(b*x, b*(a-x-1))
print(max(l, ll))
|
Screen resolution of Polycarp's monitor is $a \times b$ pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates $(x, y)$ ($0 \le x < a, 0 \le y < b$). You can consider columns of pixels to be numbered from $0$ to $a-1$, and rows — from $0$ to $b-1$.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
-----Input-----
In the first line you are given an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test. In the next lines you are given descriptions of $t$ test cases.
Each test case contains a single line which consists of $4$ integers $a, b, x$ and $y$ ($1 \le a, b \le 10^4$; $0 \le x < a$; $0 \le y < b$) — the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that $a+b>2$ (e.g. $a=b=1$ is impossible).
-----Output-----
Print $t$ integers — the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
-----Example-----
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
-----Note-----
In the first test case, the screen resolution is $8 \times 8$, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window. [Image]
|
import sys
input = sys.stdin.readline
for k in range(int(input())):
a, b, x, y = list(map(int, input().split(" ")))
print(max(a*y, b*x, (b-1-y)*a, (a-1-x)*b))
|
Screen resolution of Polycarp's monitor is $a \times b$ pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates $(x, y)$ ($0 \le x < a, 0 \le y < b$). You can consider columns of pixels to be numbered from $0$ to $a-1$, and rows — from $0$ to $b-1$.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
-----Input-----
In the first line you are given an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test. In the next lines you are given descriptions of $t$ test cases.
Each test case contains a single line which consists of $4$ integers $a, b, x$ and $y$ ($1 \le a, b \le 10^4$; $0 \le x < a$; $0 \le y < b$) — the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that $a+b>2$ (e.g. $a=b=1$ is impossible).
-----Output-----
Print $t$ integers — the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
-----Example-----
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
-----Note-----
In the first test case, the screen resolution is $8 \times 8$, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window. [Image]
|
import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
h,w,x,y = map(int,input().split())
can = [h*y,h*(w-1-y),w*x,w*(h-1-x)]
print(max(can))
|
Screen resolution of Polycarp's monitor is $a \times b$ pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates $(x, y)$ ($0 \le x < a, 0 \le y < b$). You can consider columns of pixels to be numbered from $0$ to $a-1$, and rows — from $0$ to $b-1$.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
-----Input-----
In the first line you are given an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test. In the next lines you are given descriptions of $t$ test cases.
Each test case contains a single line which consists of $4$ integers $a, b, x$ and $y$ ($1 \le a, b \le 10^4$; $0 \le x < a$; $0 \le y < b$) — the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that $a+b>2$ (e.g. $a=b=1$ is impossible).
-----Output-----
Print $t$ integers — the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
-----Example-----
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
-----Note-----
In the first test case, the screen resolution is $8 \times 8$, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window. [Image]
|
t = int(input())
for _ in range(t):
n,m,a,b = map(int,input().split())
print(max(max(a,n-a-1)*m,max(b,m-b-1)*n))
|
Screen resolution of Polycarp's monitor is $a \times b$ pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates $(x, y)$ ($0 \le x < a, 0 \le y < b$). You can consider columns of pixels to be numbered from $0$ to $a-1$, and rows — from $0$ to $b-1$.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
-----Input-----
In the first line you are given an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test. In the next lines you are given descriptions of $t$ test cases.
Each test case contains a single line which consists of $4$ integers $a, b, x$ and $y$ ($1 \le a, b \le 10^4$; $0 \le x < a$; $0 \le y < b$) — the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that $a+b>2$ (e.g. $a=b=1$ is impossible).
-----Output-----
Print $t$ integers — the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
-----Example-----
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
-----Note-----
In the first test case, the screen resolution is $8 \times 8$, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window. [Image]
|
# from collections import deque
import sys
input = lambda: sys.stdin.readline().strip()
for i in range(int(input())):
a,b,x,y = map(int,input().split())
print(max(a*y,b*x,a*(b-y-1),b*(a-x-1)))
|
Screen resolution of Polycarp's monitor is $a \times b$ pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates $(x, y)$ ($0 \le x < a, 0 \le y < b$). You can consider columns of pixels to be numbered from $0$ to $a-1$, and rows — from $0$ to $b-1$.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
-----Input-----
In the first line you are given an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test. In the next lines you are given descriptions of $t$ test cases.
Each test case contains a single line which consists of $4$ integers $a, b, x$ and $y$ ($1 \le a, b \le 10^4$; $0 \le x < a$; $0 \le y < b$) — the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that $a+b>2$ (e.g. $a=b=1$ is impossible).
-----Output-----
Print $t$ integers — the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
-----Example-----
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
-----Note-----
In the first test case, the screen resolution is $8 \times 8$, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window. [Image]
|
for _ in range(int(input())):
n,m,x,y=map(int,input().split())
s=0
s=max(s,x*m)
s=max(s,(n-x-1)*m)
s=max(s,y*n)
s=max(s,(m-y-1)*n)
print(s)
|
Screen resolution of Polycarp's monitor is $a \times b$ pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates $(x, y)$ ($0 \le x < a, 0 \le y < b$). You can consider columns of pixels to be numbered from $0$ to $a-1$, and rows — from $0$ to $b-1$.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
-----Input-----
In the first line you are given an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test. In the next lines you are given descriptions of $t$ test cases.
Each test case contains a single line which consists of $4$ integers $a, b, x$ and $y$ ($1 \le a, b \le 10^4$; $0 \le x < a$; $0 \le y < b$) — the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that $a+b>2$ (e.g. $a=b=1$ is impossible).
-----Output-----
Print $t$ integers — the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
-----Example-----
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
-----Note-----
In the first test case, the screen resolution is $8 \times 8$, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window. [Image]
|
t = int(input())
for i in range(t):
a, b, x, y = list(map(int, input().split()))
print(max(x * b, y * a, (a - x - 1) * b, (b - y - 1) * a))
|
Screen resolution of Polycarp's monitor is $a \times b$ pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates $(x, y)$ ($0 \le x < a, 0 \le y < b$). You can consider columns of pixels to be numbered from $0$ to $a-1$, and rows — from $0$ to $b-1$.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
-----Input-----
In the first line you are given an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test. In the next lines you are given descriptions of $t$ test cases.
Each test case contains a single line which consists of $4$ integers $a, b, x$ and $y$ ($1 \le a, b \le 10^4$; $0 \le x < a$; $0 \le y < b$) — the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that $a+b>2$ (e.g. $a=b=1$ is impossible).
-----Output-----
Print $t$ integers — the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
-----Example-----
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
-----Note-----
In the first test case, the screen resolution is $8 \times 8$, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window. [Image]
|
t = int(input())
for _ in range(t):
a,b,x,y = map(int, input().split())
print(max([x*b,(a-x-1)*b,a*y,a*(b-y-1)]))
|
Screen resolution of Polycarp's monitor is $a \times b$ pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates $(x, y)$ ($0 \le x < a, 0 \le y < b$). You can consider columns of pixels to be numbered from $0$ to $a-1$, and rows — from $0$ to $b-1$.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
-----Input-----
In the first line you are given an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test. In the next lines you are given descriptions of $t$ test cases.
Each test case contains a single line which consists of $4$ integers $a, b, x$ and $y$ ($1 \le a, b \le 10^4$; $0 \le x < a$; $0 \le y < b$) — the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that $a+b>2$ (e.g. $a=b=1$ is impossible).
-----Output-----
Print $t$ integers — the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
-----Example-----
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
-----Note-----
In the first test case, the screen resolution is $8 \times 8$, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window. [Image]
|
from math import *
from collections import *
t = int(input())
for y in range(t):
a,b,x,y = map(int,input().split())
l = max(x,a-x-1)
w = max(y,b-y-1)
print(max(l*b,a*w))
|
Screen resolution of Polycarp's monitor is $a \times b$ pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates $(x, y)$ ($0 \le x < a, 0 \le y < b$). You can consider columns of pixels to be numbered from $0$ to $a-1$, and rows — from $0$ to $b-1$.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
-----Input-----
In the first line you are given an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test. In the next lines you are given descriptions of $t$ test cases.
Each test case contains a single line which consists of $4$ integers $a, b, x$ and $y$ ($1 \le a, b \le 10^4$; $0 \le x < a$; $0 \le y < b$) — the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that $a+b>2$ (e.g. $a=b=1$ is impossible).
-----Output-----
Print $t$ integers — the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
-----Example-----
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
-----Note-----
In the first test case, the screen resolution is $8 \times 8$, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window. [Image]
|
import sys
import math
from collections import defaultdict
from collections import deque
from itertools import combinations
from itertools import permutations
input = lambda : sys.stdin.readline().rstrip()
read = lambda : list(map(int, input().split()))
go = lambda : 1/0
def write(*args, sep="\n"):
for i in args:
sys.stdout.write("{}{}".format(i, sep))
INF = float('inf')
MOD = int(1e9 + 7)
YES = "YES"
NO = "NO"
for _ in range(int(input())):
try:
a, b, x, y = read()
up = y * a
down = (b - y - 1) * a
left = x * b
right = (a - x - 1) * b
print(max([up, down, left, right]))
except ZeroDivisionError:
continue
except Exception as e:
print(e)
continue
|
Screen resolution of Polycarp's monitor is $a \times b$ pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates $(x, y)$ ($0 \le x < a, 0 \le y < b$). You can consider columns of pixels to be numbered from $0$ to $a-1$, and rows — from $0$ to $b-1$.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
-----Input-----
In the first line you are given an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test. In the next lines you are given descriptions of $t$ test cases.
Each test case contains a single line which consists of $4$ integers $a, b, x$ and $y$ ($1 \le a, b \le 10^4$; $0 \le x < a$; $0 \le y < b$) — the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that $a+b>2$ (e.g. $a=b=1$ is impossible).
-----Output-----
Print $t$ integers — the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
-----Example-----
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
-----Note-----
In the first test case, the screen resolution is $8 \times 8$, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window. [Image]
|
TC = int(input())
for _ in range(TC):
a, b, x, y = list(map(int, input().split()))
print((max(
y * a,
x * b,
(b - y - 1) * a,
(a - x - 1) * b
)))
|
Screen resolution of Polycarp's monitor is $a \times b$ pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates $(x, y)$ ($0 \le x < a, 0 \le y < b$). You can consider columns of pixels to be numbered from $0$ to $a-1$, and rows — from $0$ to $b-1$.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
-----Input-----
In the first line you are given an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test. In the next lines you are given descriptions of $t$ test cases.
Each test case contains a single line which consists of $4$ integers $a, b, x$ and $y$ ($1 \le a, b \le 10^4$; $0 \le x < a$; $0 \le y < b$) — the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that $a+b>2$ (e.g. $a=b=1$ is impossible).
-----Output-----
Print $t$ integers — the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
-----Example-----
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
-----Note-----
In the first test case, the screen resolution is $8 \times 8$, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window. [Image]
|
for nt in range(int(input())):
a,b,x,y=map(int,input().split())
a1=max(x,0)*b
a2=(a-x-1)*b
a3=(y)*a
a4=(b-y-1)*a
print (max(a1,a2,a3,a4))
|
Screen resolution of Polycarp's monitor is $a \times b$ pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates $(x, y)$ ($0 \le x < a, 0 \le y < b$). You can consider columns of pixels to be numbered from $0$ to $a-1$, and rows — from $0$ to $b-1$.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
-----Input-----
In the first line you are given an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test. In the next lines you are given descriptions of $t$ test cases.
Each test case contains a single line which consists of $4$ integers $a, b, x$ and $y$ ($1 \le a, b \le 10^4$; $0 \le x < a$; $0 \le y < b$) — the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that $a+b>2$ (e.g. $a=b=1$ is impossible).
-----Output-----
Print $t$ integers — the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
-----Example-----
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
-----Note-----
In the first test case, the screen resolution is $8 \times 8$, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window. [Image]
|
def main(a, b, x, y):
sol = max(max(x, a-x-1)*b, max(y, b-y-1)*a)
print(sol)
n = int(input())
for _ in range(n):
lst = list(map(int, input().split()))
a, b, x, y = lst[0], lst[1], lst[2], lst[3]
main(a, b, x, y)
|
Screen resolution of Polycarp's monitor is $a \times b$ pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates $(x, y)$ ($0 \le x < a, 0 \le y < b$). You can consider columns of pixels to be numbered from $0$ to $a-1$, and rows — from $0$ to $b-1$.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
-----Input-----
In the first line you are given an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test. In the next lines you are given descriptions of $t$ test cases.
Each test case contains a single line which consists of $4$ integers $a, b, x$ and $y$ ($1 \le a, b \le 10^4$; $0 \le x < a$; $0 \le y < b$) — the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that $a+b>2$ (e.g. $a=b=1$ is impossible).
-----Output-----
Print $t$ integers — the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
-----Example-----
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
-----Note-----
In the first test case, the screen resolution is $8 \times 8$, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window. [Image]
|
t=int(input())
for i in range(t):
a,b,x,y=list(map(int,input().split()))
r = [a*y, b*x, a*(b-y-1), b*(a-x-1)]
print(max(r))
|
Screen resolution of Polycarp's monitor is $a \times b$ pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates $(x, y)$ ($0 \le x < a, 0 \le y < b$). You can consider columns of pixels to be numbered from $0$ to $a-1$, and rows — from $0$ to $b-1$.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
-----Input-----
In the first line you are given an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test. In the next lines you are given descriptions of $t$ test cases.
Each test case contains a single line which consists of $4$ integers $a, b, x$ and $y$ ($1 \le a, b \le 10^4$; $0 \le x < a$; $0 \le y < b$) — the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that $a+b>2$ (e.g. $a=b=1$ is impossible).
-----Output-----
Print $t$ integers — the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
-----Example-----
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
-----Note-----
In the first test case, the screen resolution is $8 \times 8$, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window. [Image]
|
t = int(input())
while t:
t += -1
a, b, x, y = map(int, input().split())
a1 = b * x
a2 = a * y
a3 = b * (a - x - 1)
a4 = a * (b - y - 1)
print(max(a1, a2, a3, a4))
|
Screen resolution of Polycarp's monitor is $a \times b$ pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates $(x, y)$ ($0 \le x < a, 0 \le y < b$). You can consider columns of pixels to be numbered from $0$ to $a-1$, and rows — from $0$ to $b-1$.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
-----Input-----
In the first line you are given an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test. In the next lines you are given descriptions of $t$ test cases.
Each test case contains a single line which consists of $4$ integers $a, b, x$ and $y$ ($1 \le a, b \le 10^4$; $0 \le x < a$; $0 \le y < b$) — the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that $a+b>2$ (e.g. $a=b=1$ is impossible).
-----Output-----
Print $t$ integers — the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
-----Example-----
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
-----Note-----
In the first test case, the screen resolution is $8 \times 8$, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window. [Image]
|
from sys import stdin,stderr
def rl():
return [int(w) for w in stdin.readline().split()]
t, = rl()
for _ in range(t):
a,b,x,y = rl()
print(max(x*b,y*a,(a-x-1)*b,(b-y-1)*a))
|
Screen resolution of Polycarp's monitor is $a \times b$ pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates $(x, y)$ ($0 \le x < a, 0 \le y < b$). You can consider columns of pixels to be numbered from $0$ to $a-1$, and rows — from $0$ to $b-1$.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
-----Input-----
In the first line you are given an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test. In the next lines you are given descriptions of $t$ test cases.
Each test case contains a single line which consists of $4$ integers $a, b, x$ and $y$ ($1 \le a, b \le 10^4$; $0 \le x < a$; $0 \le y < b$) — the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that $a+b>2$ (e.g. $a=b=1$ is impossible).
-----Output-----
Print $t$ integers — the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
-----Example-----
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
-----Note-----
In the first test case, the screen resolution is $8 \times 8$, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window. [Image]
|
t = int(input())
for _ in range(t):
a, b, x, y = list(map(int, input().split()))
h = max(a-x-1, x) * b
v = max(b-y-1, y) * a
print(max(h, v))
|
Screen resolution of Polycarp's monitor is $a \times b$ pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates $(x, y)$ ($0 \le x < a, 0 \le y < b$). You can consider columns of pixels to be numbered from $0$ to $a-1$, and rows — from $0$ to $b-1$.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
-----Input-----
In the first line you are given an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test. In the next lines you are given descriptions of $t$ test cases.
Each test case contains a single line which consists of $4$ integers $a, b, x$ and $y$ ($1 \le a, b \le 10^4$; $0 \le x < a$; $0 \le y < b$) — the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that $a+b>2$ (e.g. $a=b=1$ is impossible).
-----Output-----
Print $t$ integers — the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
-----Example-----
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
-----Note-----
In the first test case, the screen resolution is $8 \times 8$, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window. [Image]
|
import sys
input = sys.stdin.readline
def main():
t = int(input())
for _ in range(t):
A, B, X, Y = [int(x) for x in input().split()]
ma = 0
ma = max(X * B, ma)
ma = max(Y * A, ma)
ma = max((A - X - 1) * B, ma)
ma = max((B - Y - 1) * A, ma)
print(ma)
def __starting_point():
main()
__starting_point()
|
Screen resolution of Polycarp's monitor is $a \times b$ pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates $(x, y)$ ($0 \le x < a, 0 \le y < b$). You can consider columns of pixels to be numbered from $0$ to $a-1$, and rows — from $0$ to $b-1$.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
-----Input-----
In the first line you are given an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test. In the next lines you are given descriptions of $t$ test cases.
Each test case contains a single line which consists of $4$ integers $a, b, x$ and $y$ ($1 \le a, b \le 10^4$; $0 \le x < a$; $0 \le y < b$) — the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that $a+b>2$ (e.g. $a=b=1$ is impossible).
-----Output-----
Print $t$ integers — the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
-----Example-----
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
-----Note-----
In the first test case, the screen resolution is $8 \times 8$, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window. [Image]
|
t = int(input())
while t:
t -= 1
a, b, x, y = list(map(int, input().split()))
area1 = a * y
area2 = x * b
area3 = (a - 1 - x) * b
area4 = a * (b - 1 - y)
print(max(area1, area2, area3, area4))
|
Screen resolution of Polycarp's monitor is $a \times b$ pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates $(x, y)$ ($0 \le x < a, 0 \le y < b$). You can consider columns of pixels to be numbered from $0$ to $a-1$, and rows — from $0$ to $b-1$.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
-----Input-----
In the first line you are given an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test. In the next lines you are given descriptions of $t$ test cases.
Each test case contains a single line which consists of $4$ integers $a, b, x$ and $y$ ($1 \le a, b \le 10^4$; $0 \le x < a$; $0 \le y < b$) — the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that $a+b>2$ (e.g. $a=b=1$ is impossible).
-----Output-----
Print $t$ integers — the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
-----Example-----
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
-----Note-----
In the first test case, the screen resolution is $8 \times 8$, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window. [Image]
|
for _ in range(int(input())):
a,b,x,y = map(int,input().split())
total = a*b
left = x*b
right = total - left - b
down = a*y
up = total - down - a
print( max( left, right, down, up ) )
|
Screen resolution of Polycarp's monitor is $a \times b$ pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates $(x, y)$ ($0 \le x < a, 0 \le y < b$). You can consider columns of pixels to be numbered from $0$ to $a-1$, and rows — from $0$ to $b-1$.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
-----Input-----
In the first line you are given an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test. In the next lines you are given descriptions of $t$ test cases.
Each test case contains a single line which consists of $4$ integers $a, b, x$ and $y$ ($1 \le a, b \le 10^4$; $0 \le x < a$; $0 \le y < b$) — the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that $a+b>2$ (e.g. $a=b=1$ is impossible).
-----Output-----
Print $t$ integers — the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
-----Example-----
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
-----Note-----
In the first test case, the screen resolution is $8 \times 8$, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window. [Image]
|
for i in range(int(input())):
a, b, x, y = list(map(int, input().split()))
print(max(a*max(y, b-y-1), b*max(x, a-x-1)))
|
Screen resolution of Polycarp's monitor is $a \times b$ pixels. Unfortunately, there is one dead pixel at his screen. It has coordinates $(x, y)$ ($0 \le x < a, 0 \le y < b$). You can consider columns of pixels to be numbered from $0$ to $a-1$, and rows — from $0$ to $b-1$.
Polycarp wants to open a rectangular window of maximal size, which doesn't contain the dead pixel. The boundaries of the window should be parallel to the sides of the screen.
Print the maximal area (in pixels) of a window that doesn't contain the dead pixel inside itself.
-----Input-----
In the first line you are given an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test. In the next lines you are given descriptions of $t$ test cases.
Each test case contains a single line which consists of $4$ integers $a, b, x$ and $y$ ($1 \le a, b \le 10^4$; $0 \le x < a$; $0 \le y < b$) — the resolution of the screen and the coordinates of a dead pixel. It is guaranteed that $a+b>2$ (e.g. $a=b=1$ is impossible).
-----Output-----
Print $t$ integers — the answers for each test case. Each answer should contain an integer equal to the maximal possible area (in pixels) of a rectangular window, that doesn't contain the dead pixel.
-----Example-----
Input
6
8 8 0 0
1 10 0 3
17 31 10 4
2 1 0 0
5 10 3 9
10 10 4 8
Output
56
6
442
1
45
80
-----Note-----
In the first test case, the screen resolution is $8 \times 8$, and the upper left pixel is a dead pixel. Here you can see one of two possible layouts of the maximal window. [Image]
|
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=tf-8
#
"""
"""
from operator import itemgetter
from collections import Counter
def solve(a, b, x, y):
area1 = x*b
area2 = (a-x-1)*b
area3 = a*y
area4 = a*(b-y-1)
print(max(area1,area2,area3,area4))
def main():
t= int(input())
for i in range(t):
a, b, x, y = map(int,input().split())
solve(a, b, x, y)
def __starting_point():
main()
__starting_point()
|
Polycarp, Arkady's friend, prepares to the programming competition and decides to write a contest. The contest consists of $n$ problems and lasts for $T$ minutes. Each of the problems is defined by two positive integers $a_i$ and $p_i$ — its difficulty and the score awarded by its solution.
Polycarp's experience suggests that his skill level is defined with positive real value $s$, and initially $s=1.0$. To solve the $i$-th problem Polycarp needs $a_i/s$ minutes.
Polycarp loves to watch series, and before solving each of the problems he will definitely watch one episode. After Polycarp watches an episode, his skill decreases by $10\%$, that is skill level $s$ decreases to $0.9s$. Each episode takes exactly $10$ minutes to watch. When Polycarp decides to solve some problem, he firstly has to watch one episode, and only then he starts solving the problem without breaks for $a_i/s$ minutes, where $s$ is his current skill level. In calculation of $a_i/s$ no rounding is performed, only division of integer value $a_i$ by real value $s$ happens.
Also, Polycarp can train for some time. If he trains for $t$ minutes, he increases his skill by $C \cdot t$, where $C$ is some given positive real constant. Polycarp can train only before solving any problem (and before watching series). Duration of the training can be arbitrary real value.
Polycarp is interested: what is the largest score he can get in the contest? It is allowed to solve problems in any order, while training is only allowed before solving the first problem.
-----Input-----
The first line contains one integer $tc$ ($1 \le tc \le 20$) — the number of test cases. Then $tc$ test cases follow.
The first line of each test contains one integer $n$ ($1 \le n \le 100$) — the number of problems in the contest.
The second line of the test contains two real values $C, T$ ($0 < C < 10$, $0 \le T \le 2 \cdot 10^5$), where $C$ defines the efficiency of the training and $T$ is the duration of the contest in minutes. Value $C, T$ are given exactly with three digits after the decimal point.
Each of the next $n$ lines of the test contain characteristics of the corresponding problem: two integers $a_i, p_i$ ($1 \le a_i \le 10^4$, $1 \le p_i \le 10$) — the difficulty and the score of the problem.
It is guaranteed that the value of $T$ is such that changing it by the $0.001$ in any direction will not change the test answer.
Please note that in hacks you can only use $tc = 1$.
-----Output-----
Print $tc$ integers — the maximum possible score in each test case.
-----Examples-----
Input
2
4
1.000 31.000
12 3
20 6
30 1
5 1
3
1.000 30.000
1 10
10 10
20 8
Output
7
20
-----Note-----
In the first example, Polycarp can get score of $7$ as follows: Firstly he trains for $4$ minutes, increasing $s$ to the value of $5$; Then he decides to solve $4$-th problem: he watches one episode in $10$ minutes, his skill level decreases to $s=5*0.9=4.5$ and then he solves the problem in $5/s=5/4.5$, which is roughly $1.111$ minutes; Finally, he decides to solve $2$-nd problem: he watches one episode in $10$ minutes, his skill level decreases to $s=4.5*0.9=4.05$ and then he solves the problem in $20/s=20/4.05$, which is roughly $4.938$ minutes.
This way, Polycarp uses roughly $4+10+1.111+10+4.938=30.049$ minutes, to get score of $7$ points. It is not possible to achieve larger score in $31$ minutes.
In the second example, Polycarp can get $20$ points as follows: Firstly he trains for $4$ minutes, increasing $s$ to the value of $5$; Then he decides to solve $1$-st problem: he watches one episode in $10$ minutes, his skill decreases to $s=5*0.9=4.5$ and then he solves problem in $1/s=1/4.5$, which is roughly $0.222$ minutes. Finally, he decides to solve $2$-nd problem: he watches one episode in $10$ minutes, his skill decreases to $s=4.5*0.9=4.05$ and then he solves the problem in $10/s=10/4.05$, which is roughly $2.469$ minutes.
This way, Polycarp gets score of $20$ in $4+10+0.222+10+2.469=26.691$ minutes. It is not possible to achieve larger score in $30$ minutes.
|
from math import sqrt
class pro(object):
def __init__(self,dif,sc):
self.dif=dif
self.sc=sc
def __lt__(self,other):
return self.dif>other.dif
T=int(input())
mul=[1]
for i in range(100):
mul.append(mul[i]*10/9)
inf=1000000007
for t in range(T):
n=int(input())
effi,tim=list(map(float,input().split()))
prob=[]
for i in range(n):
x,y=list(map(int,input().split()))
prob.append(pro(x,y))
prob.sort()
f=[[inf for i in range(n+1)] for j in range(1001)]
f[0][0]=0
totsc=0
for i in range(n):
totsc+=prob[i].sc
for j in range(totsc,prob[i].sc-1,-1):
for k in range(1,i+2):
f[j][k]=min(f[j][k],f[j-prob[i].sc][k-1]+prob[i].dif*mul[k])
for i in range(totsc,-1,-1):
flag=False
for j in range(n+1):
if sqrt(effi*f[i][j])>=1:
res=2*sqrt(f[i][j]/effi)-1/effi+10*j
else:
res=f[i][j]+10*j
if res<=tim:
print(i)
flag=True
break
if flag==True:
break
|
You are given an array $a_1, a_2 \dots a_n$. Calculate the number of tuples $(i, j, k, l)$ such that: $1 \le i < j < k < l \le n$; $a_i = a_k$ and $a_j = a_l$;
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 100$) — the number of test cases.
The first line of each test case contains a single integer $n$ ($4 \le n \le 3000$) — the size of the array $a$.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) — the array $a$.
It's guaranteed that the sum of $n$ in one test doesn't exceed $3000$.
-----Output-----
For each test case, print the number of described tuples.
-----Example-----
Input
2
5
2 2 2 2 2
6
1 3 3 1 2 3
Output
5
2
-----Note-----
In the first test case, for any four indices $i < j < k < l$ are valid, so the answer is the number of tuples.
In the second test case, there are $2$ valid tuples: $(1, 2, 4, 6)$: $a_1 = a_4$ and $a_2 = a_6$; $(1, 3, 4, 6)$: $a_1 = a_4$ and $a_3 = a_6$.
|
class BIT():
def __init__(self,n):
self.BIT=[0]*(n+1)
self.num=n
def query(self,idx):
res_sum = 0
while idx > 0:
res_sum += self.BIT[idx]
idx -= idx&(-idx)
return res_sum
#Ai += x O(logN)
def update(self,idx,x):
while idx <= self.num:
self.BIT[idx] += x
idx += idx&(-idx)
return
import sys,random
input=sys.stdin.readline
for _ in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
pair=[[] for i in range(n+1)]
for i in range(n):
for j in range(i+1,n):
if a[i]==a[j]:
pair[i+1].append(j+1)
bit=BIT(n)
ans=0
for i in range(1,n+1):
minus=bit.query(i)
for r in pair[i]:
ans+=bit.query(r-1)-minus
for r in pair[i]:
bit.update(r,1)
print(ans)
|
You are given an array $a_1, a_2 \dots a_n$. Calculate the number of tuples $(i, j, k, l)$ such that: $1 \le i < j < k < l \le n$; $a_i = a_k$ and $a_j = a_l$;
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 100$) — the number of test cases.
The first line of each test case contains a single integer $n$ ($4 \le n \le 3000$) — the size of the array $a$.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) — the array $a$.
It's guaranteed that the sum of $n$ in one test doesn't exceed $3000$.
-----Output-----
For each test case, print the number of described tuples.
-----Example-----
Input
2
5
2 2 2 2 2
6
1 3 3 1 2 3
Output
5
2
-----Note-----
In the first test case, for any four indices $i < j < k < l$ are valid, so the answer is the number of tuples.
In the second test case, there are $2$ valid tuples: $(1, 2, 4, 6)$: $a_1 = a_4$ and $a_2 = a_6$; $(1, 3, 4, 6)$: $a_1 = a_4$ and $a_3 = a_6$.
|
from sys import stdin
tt = int(stdin.readline())
for loop in range(tt):
n = int(stdin.readline())
a = list(map(int,stdin.readline().split()))
l = [0] * (n+1)
ans = 0
for j in range(n):
r = [0] * (n+1)
for k in range(n-1,j,-1):
ans += l[a[k]] * r[a[j]]
r[a[k]] += 1
l[a[j]] += 1
print (ans)
|
You are given an array $a_1, a_2 \dots a_n$. Calculate the number of tuples $(i, j, k, l)$ such that: $1 \le i < j < k < l \le n$; $a_i = a_k$ and $a_j = a_l$;
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 100$) — the number of test cases.
The first line of each test case contains a single integer $n$ ($4 \le n \le 3000$) — the size of the array $a$.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) — the array $a$.
It's guaranteed that the sum of $n$ in one test doesn't exceed $3000$.
-----Output-----
For each test case, print the number of described tuples.
-----Example-----
Input
2
5
2 2 2 2 2
6
1 3 3 1 2 3
Output
5
2
-----Note-----
In the first test case, for any four indices $i < j < k < l$ are valid, so the answer is the number of tuples.
In the second test case, there are $2$ valid tuples: $(1, 2, 4, 6)$: $a_1 = a_4$ and $a_2 = a_6$; $(1, 3, 4, 6)$: $a_1 = a_4$ and $a_3 = a_6$.
|
def calcCntAtPrefix(a):
cntAtPrefix = [[0] * (len(a) + 1)]
for i, x in enumerate(a):
cntAtPrefix.append(cntAtPrefix[-1][:])
cntAtPrefix[-1][x] += 1
return cntAtPrefix
def solve():
n = int(input())
a = list(map(int, input().split()))
cntAtPrefix = calcCntAtPrefix(a)
cntAtSuffix = calcCntAtPrefix(a[::-1])
ans = 0
for j in range(n):
for k in range(j + 1, n):
ans += cntAtPrefix[j][a[k]] * cntAtSuffix[n - 1 - k][a[j]]
print(ans)
for t in range(int(input())):
solve()
|
You are given an array $a_1, a_2 \dots a_n$. Calculate the number of tuples $(i, j, k, l)$ such that: $1 \le i < j < k < l \le n$; $a_i = a_k$ and $a_j = a_l$;
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 100$) — the number of test cases.
The first line of each test case contains a single integer $n$ ($4 \le n \le 3000$) — the size of the array $a$.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) — the array $a$.
It's guaranteed that the sum of $n$ in one test doesn't exceed $3000$.
-----Output-----
For each test case, print the number of described tuples.
-----Example-----
Input
2
5
2 2 2 2 2
6
1 3 3 1 2 3
Output
5
2
-----Note-----
In the first test case, for any four indices $i < j < k < l$ are valid, so the answer is the number of tuples.
In the second test case, there are $2$ valid tuples: $(1, 2, 4, 6)$: $a_1 = a_4$ and $a_2 = a_6$; $(1, 3, 4, 6)$: $a_1 = a_4$ and $a_3 = a_6$.
|
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
d = [[0] * n for _ in range(n)]
for i in range(n):
for j in range(i + 1, n):
if a[i] == a[j]:
d[i][j] = 1
for i in range(n):
for j in range(n - 1):
d[i][j + 1] += d[i][j]
for i in range(n - 1):
for j in range(n):
d[i + 1][j] += d[i][j]
ans = 0
for i in range(n):
for j in range(i + 1, n):
if a[i] == a[j]:
ans += d[j - 1][n - 1] - d[j - 1][j] - d[i][n - 1] + d[i][j]
print(ans)
|
You are given an array $a_1, a_2 \dots a_n$. Calculate the number of tuples $(i, j, k, l)$ such that: $1 \le i < j < k < l \le n$; $a_i = a_k$ and $a_j = a_l$;
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 100$) — the number of test cases.
The first line of each test case contains a single integer $n$ ($4 \le n \le 3000$) — the size of the array $a$.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) — the array $a$.
It's guaranteed that the sum of $n$ in one test doesn't exceed $3000$.
-----Output-----
For each test case, print the number of described tuples.
-----Example-----
Input
2
5
2 2 2 2 2
6
1 3 3 1 2 3
Output
5
2
-----Note-----
In the first test case, for any four indices $i < j < k < l$ are valid, so the answer is the number of tuples.
In the second test case, there are $2$ valid tuples: $(1, 2, 4, 6)$: $a_1 = a_4$ and $a_2 = a_6$; $(1, 3, 4, 6)$: $a_1 = a_4$ and $a_3 = a_6$.
|
import sys
sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]
for _ in range(II()):
n=II()
aa=LI1()
cnt=[0]*n
ans=0
for i,a in enumerate(aa):
cur=0
for a2 in aa[i+1:]:
if a2==a:ans+=cur
cur+=cnt[a2]
cnt[a]+=1
print(ans)
|
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd.
You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon.
Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square.
You can rotate $2n$-gon and/or the square.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 200$) — the number of test cases.
Next $T$ lines contain descriptions of test cases — one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon.
-----Output-----
Print $T$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
-----Example-----
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
|
import math
T = int(input())
for _ in range(T):
n = int(input())
print(1/math.tan(math.pi/2/n))
|
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd.
You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon.
Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square.
You can rotate $2n$-gon and/or the square.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 200$) — the number of test cases.
Next $T$ lines contain descriptions of test cases — one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon.
-----Output-----
Print $T$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
-----Example-----
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
|
t=int(input())
import math as m
while t:
t-=1
a=int(input())
print(1/(m.tan(m.pi/(2*a))))
|
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd.
You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon.
Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square.
You can rotate $2n$-gon and/or the square.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 200$) — the number of test cases.
Next $T$ lines contain descriptions of test cases — one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon.
-----Output-----
Print $T$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
-----Example-----
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
|
import sys
import math
readline = sys.stdin.readline
read = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')
def solve():
n = ni()
print(1 / math.tan(math.pi / (2 * n)))
return
# solve()
T = ni()
for _ in range(T):
solve()
|
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd.
You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon.
Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square.
You can rotate $2n$-gon and/or the square.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 200$) — the number of test cases.
Next $T$ lines contain descriptions of test cases — one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon.
-----Output-----
Print $T$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
-----Example-----
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
|
# |
# _` | __ \ _` | __| _ \ __ \ _` | _` |
# ( | | | ( | ( ( | | | ( | ( |
# \__,_| _| _| \__,_| \___| \___/ _| _| \__,_| \__,_|
import sys
import math
import operator as op
from functools import reduce
def read_line():
return sys.stdin.readline()[:-1]
def read_int():
return int(sys.stdin.readline())
def read_int_line():
return [int(v) for v in sys.stdin.readline().split()]
def read_float_line():
return [float(v) for v in sys.stdin.readline().split()]
def ncr(n, r):
r = min(r, n-r)
numer = reduce(op.mul, range(n, n-r, -1), 1)
denom = reduce(op.mul, range(1, r+1), 1)
return numer / denom
def rad(x):
return math.pi*x/180
t = read_int()
for i in range(t):
n = read_int()
ans = 1/(math.tan(rad(180/(2*n))))
print(ans)
|
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd.
You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon.
Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square.
You can rotate $2n$-gon and/or the square.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 200$) — the number of test cases.
Next $T$ lines contain descriptions of test cases — one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon.
-----Output-----
Print $T$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
-----Example-----
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
|
import math
def sqare_size(n):
return 1/math.tan(math.pi/(2*n))
t = int(input())
for _ in range(t):
print(sqare_size(int(input())))
|
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd.
You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon.
Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square.
You can rotate $2n$-gon and/or the square.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 200$) — the number of test cases.
Next $T$ lines contain descriptions of test cases — one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon.
-----Output-----
Print $T$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
-----Example-----
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
|
from math import *
t = int(input())
for case in range(t):
n = int(input())
print(1/(tan(pi/(2*n))))
|
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd.
You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon.
Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square.
You can rotate $2n$-gon and/or the square.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 200$) — the number of test cases.
Next $T$ lines contain descriptions of test cases — one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon.
-----Output-----
Print $T$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
-----Example-----
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
|
import sys
import math
input = sys.stdin.readline
flush = sys.stdout.flush
for _ in range(int(input())):
n = int(input())
print(1.0 / math.tan(math.pi / (2.0 * n)))
|
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd.
You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon.
Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square.
You can rotate $2n$-gon and/or the square.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 200$) — the number of test cases.
Next $T$ lines contain descriptions of test cases — one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon.
-----Output-----
Print $T$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
-----Example-----
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
|
"""
arr = list(map(int, input().split()))
n,k=map(int, input().split())
"""
import math
import sys
# input = sys.stdin.readline
############ ---- Input Functions ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(list(map(int,input().split())))
test_cases = int(input())
for _ in range(test_cases):
sides = int(input())
sides *= 2
apothem = 1 / (2 * math.tan((180 / sides) * (math.pi/180)))
print(2 * apothem)
# for _ in range(test_cases):
# size = int(input())
# arr = inlt()
# maxx = -float('inf')
# temp = []
# max_diff = 0
# #Checks the maximum number and difference of decreasing numbers, the moment it increases again, it rechecks for a bigger difference
# for i in range(size):
# if arr[i] < maxx:
# max_diff = max(max_diff, maxx - arr[i])
# maxx = max(arr[i], maxx)
# i = 0
# index = 0
# while i < max_diff:
# i += 2 ** index
# index += 1
# print(index)
|
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd.
You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon.
Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square.
You can rotate $2n$-gon and/or the square.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 200$) — the number of test cases.
Next $T$ lines contain descriptions of test cases — one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon.
-----Output-----
Print $T$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
-----Example-----
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
|
import math
T = int(input())
for i in range(T):
x = 2*int(input())
print(1/math.tan(math.pi/x))
|
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd.
You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon.
Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square.
You can rotate $2n$-gon and/or the square.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 200$) — the number of test cases.
Next $T$ lines contain descriptions of test cases — one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon.
-----Output-----
Print $T$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
-----Example-----
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
|
from math import cos, pi, sin
for _ in range(int(input())):
n = int(input())
alpha = pi / (n * 2)
print(cos(alpha) / sin(alpha))
|
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd.
You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon.
Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square.
You can rotate $2n$-gon and/or the square.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 200$) — the number of test cases.
Next $T$ lines contain descriptions of test cases — one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon.
-----Output-----
Print $T$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
-----Example-----
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
|
from math import tan, pi
for _ in range(int(input())):
n = int(input())
n *= 2
print(1/tan(pi/n))
|
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd.
You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon.
Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square.
You can rotate $2n$-gon and/or the square.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 200$) — the number of test cases.
Next $T$ lines contain descriptions of test cases — one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon.
-----Output-----
Print $T$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
-----Example-----
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
|
import math
import sys
#sys.stdin = open("in.txt")
t = int(input())
for i in range(t):
n = int(input())
n *= 2
a = (n - 2) * math.pi / n / 2
r = 1/2 * math.tan(a)
print(2*r)
|
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd.
You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon.
Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square.
You can rotate $2n$-gon and/or the square.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 200$) — the number of test cases.
Next $T$ lines contain descriptions of test cases — one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon.
-----Output-----
Print $T$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
-----Example-----
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
|
import math
import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
n = int(input())
theta = 2 * n
print(1 / math.tan(math.radians(360 / 4 / n)))
|
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd.
You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon.
Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square.
You can rotate $2n$-gon and/or the square.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 200$) — the number of test cases.
Next $T$ lines contain descriptions of test cases — one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon.
-----Output-----
Print $T$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
-----Example-----
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
|
from math import sin, pi
n = int(input())
def f(a, b):
return sin((b * pi) / a) / sin(pi / a)
for _ in range(n):
m = int(input())
if m % 2 == 0:
print("%.12f" % f(2 * m, m - 1))
else:
print("%.12f" % f(2 * m, m))
|
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd.
You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon.
Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square.
You can rotate $2n$-gon and/or the square.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 200$) — the number of test cases.
Next $T$ lines contain descriptions of test cases — one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon.
-----Output-----
Print $T$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
-----Example-----
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
|
from math import*
for _ in range(int(input())):
n=int(input())
if n%2==0:
print(1/tan(radians(90/n)))
|
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd.
You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon.
Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square.
You can rotate $2n$-gon and/or the square.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 200$) — the number of test cases.
Next $T$ lines contain descriptions of test cases — one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon.
-----Output-----
Print $T$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
-----Example-----
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
|
from math import sin, pi, sqrt, tan
def read_int():
return int(input())
def read_ints():
return list(map(int, input().split(' ')))
t = read_int()
for case_num in range(t):
n = read_int()
angle = pi / n / 2
r = 1 / tan(angle)
print('{:.9f}'.format(r))
|
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd.
You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon.
Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square.
You can rotate $2n$-gon and/or the square.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 200$) — the number of test cases.
Next $T$ lines contain descriptions of test cases — one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon.
-----Output-----
Print $T$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
-----Example-----
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
|
import math
import sys
input = sys.stdin.readline
Q = int(input())
Query = [int(input()) for _ in range(Q)]
for N in Query:
if N%2 == 0:
print(1/math.tan(math.pi/(N*2)))
|
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd.
You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon.
Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square.
You can rotate $2n$-gon and/or the square.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 200$) — the number of test cases.
Next $T$ lines contain descriptions of test cases — one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon.
-----Output-----
Print $T$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
-----Example-----
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
|
import math
t = int(input())
for i in range(0,t):
a = int(input())
pi = math.pi
print(round(1/math.tan(pi/(2*(a))),9))
|
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd.
You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon.
Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square.
You can rotate $2n$-gon and/or the square.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 200$) — the number of test cases.
Next $T$ lines contain descriptions of test cases — one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon.
-----Output-----
Print $T$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
-----Example-----
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
|
from math import cos,sin,pi
t = int(input())
for test in range(t):
n = int(input())
if n == 2:
print(1.)
else:
print(sin(pi/n)/(1-cos(pi/n)))
|
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd.
You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon.
Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square.
You can rotate $2n$-gon and/or the square.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 200$) — the number of test cases.
Next $T$ lines contain descriptions of test cases — one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon.
-----Output-----
Print $T$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
-----Example-----
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
|
import math
t = int(input())
for _ in range(t):
n = int(input())
print(1/math.tan(math.pi/(2*n)))
|
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd.
You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon.
Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square.
You can rotate $2n$-gon and/or the square.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 200$) — the number of test cases.
Next $T$ lines contain descriptions of test cases — one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon.
-----Output-----
Print $T$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
-----Example-----
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
|
import random
import math
LI = lambda: list(map(int,input().split()))
MI = lambda: map(int,input().split())
yes = lambda: print("Yes")
no = lambda: print("No")
I = lambda: list(input())
J = lambda x: "".join(x)
II = lambda: int(input())
SI = lambda: input()
#---khan17---template
t = II()
for q in range(t):
n = II()
R = 1/(2*math.sin(math.pi/(2*n)))
r = math.sqrt(R**2-0.25)
print(2*r)
|
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd.
You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon.
Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square.
You can rotate $2n$-gon and/or the square.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 200$) — the number of test cases.
Next $T$ lines contain descriptions of test cases — one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon.
-----Output-----
Print $T$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
-----Example-----
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
|
mod = 1000000007
eps = 10**-9
def main():
import sys
from math import sin, pi, cos
input = sys.stdin.readline
for _ in range(int(input())):
N = int(input())
NN = N*2
print(cos(pi / NN) / sin(pi / NN))
def __starting_point():
main()
__starting_point()
|
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd.
You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon.
Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square.
You can rotate $2n$-gon and/or the square.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 200$) — the number of test cases.
Next $T$ lines contain descriptions of test cases — one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon.
-----Output-----
Print $T$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
-----Example-----
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
|
import math
t = int(input())
for ti in range(t):
n = int(input())
# n is even
# if n == 2:
# print(1)
a = math.pi / (2*n)
side = (1/math.tan(a))
print(side)
# try:
# raise Exception
# except:
# print("-1")
# thenos.sort(key=lambda x: x[2], reverse=True)
# int(math.log(max(numbers)+1,2))
# 2**3 (power)
|
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd.
You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon.
Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square.
You can rotate $2n$-gon and/or the square.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 200$) — the number of test cases.
Next $T$ lines contain descriptions of test cases — one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon.
-----Output-----
Print $T$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
-----Example-----
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
|
import math as m
def fu(a):
return (a/180)*m.pi
t=int(input())
for _ in range(t):
n=int(input())
a=n//2-1
b=180-360/(2*n)
s=0
for i in range(1,a+1):
s=s+m.cos(fu(i*b-(2*i-1)*90))
print(2*s+1)
|
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd.
You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon.
Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square.
You can rotate $2n$-gon and/or the square.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 200$) — the number of test cases.
Next $T$ lines contain descriptions of test cases — one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon.
-----Output-----
Print $T$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
-----Example-----
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
|
import sys
from math import tan, pi
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
from itertools import islice, cycle
def go():
n = int(input())
# a,b,c,d = map(int, input().split())
# a = list(map(int, input().split()))
# s = input()
return 1/(tan(pi/(2*n)))
# x,s = map(int,input().split())
t = int(input())
# t = 1
ans = []
for _ in range(t):
# print(go())
ans.append(str(go()))
#
print('\n'.join(ans))
|
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd.
You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon.
Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square.
You can rotate $2n$-gon and/or the square.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 200$) — the number of test cases.
Next $T$ lines contain descriptions of test cases — one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon.
-----Output-----
Print $T$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
-----Example-----
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
|
import math
t=int(input())
while(t):
t-=1
n=int(input())
ang= math.pi/(2*n)
ans= 1/math.tan(ang)
print(ans)
|
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd.
You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon.
Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square.
You can rotate $2n$-gon and/or the square.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 200$) — the number of test cases.
Next $T$ lines contain descriptions of test cases — one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon.
-----Output-----
Print $T$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
-----Example-----
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
|
import math
def main():
n = int(input())
a = math.pi/(2*n)
x = 1 / (math.sin(a)) / 2
res = 2 * math.cos(a) * x
print(res)
for _ in range(int(input())):
main()
|
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd.
You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon.
Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square.
You can rotate $2n$-gon and/or the square.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 200$) — the number of test cases.
Next $T$ lines contain descriptions of test cases — one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon.
-----Output-----
Print $T$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
-----Example-----
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
|
import math
for nt in range(int(input())):
n=int(input())
m=2*n
a=((m-2)*180)/m
s=180-a
t=s
ans=0
for i in range((n-2)//2):
# print (t,ans)
ans+=(math.cos((t*math.pi)/180))
t+=s
print(ans*2+1)
|
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd.
You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon.
Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square.
You can rotate $2n$-gon and/or the square.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 200$) — the number of test cases.
Next $T$ lines contain descriptions of test cases — one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon.
-----Output-----
Print $T$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
-----Example-----
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
|
import os
import sys
if os.path.exists('/mnt/c/Users/Square/square/codeforces'):
f = iter(open('C.txt').readlines())
def input():
return next(f).strip()
# input = lambda: sys.stdin.readline().strip()
else:
input = lambda: sys.stdin.readline().strip()
fprint = lambda *args: print(*args, flush=True)
import math
t = int(input())
for _ in range(t):
n = int(input())
print(1.0 / math.tan(math.pi / 2 / n))
|
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd.
You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon.
Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square.
You can rotate $2n$-gon and/or the square.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 200$) — the number of test cases.
Next $T$ lines contain descriptions of test cases — one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon.
-----Output-----
Print $T$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
-----Example-----
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
|
from math import sin, pi
def solve():
n = int( input())
return(sin(((n-1)*pi/(2*n)))/sin(pi/(2*n)))
def main():
t = int( input())
print("\n".join( map( str, [ solve() for _ in range(t)])))
def __starting_point():
main()
__starting_point()
|
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd.
You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon.
Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square.
You can rotate $2n$-gon and/or the square.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 200$) — the number of test cases.
Next $T$ lines contain descriptions of test cases — one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon.
-----Output-----
Print $T$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
-----Example-----
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
|
from math import *
for _ in range(int(input())):
n = 2 * int(input())
a = pi - (pi * (n - 2) / n)
ans = 0
for i in range(1, n // 4):
ans += cos(i * a)
print(2 * ans + 1)
|
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd.
You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon.
Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square.
You can rotate $2n$-gon and/or the square.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 200$) — the number of test cases.
Next $T$ lines contain descriptions of test cases — one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon.
-----Output-----
Print $T$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
-----Example-----
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
|
import math
r=math.pi
for _ in range(int(input())):
N=int(input())
w=2*N
t=(math.cos(r/w))/(math.sin(r/w))
print(t)
|
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd.
You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon.
Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square.
You can rotate $2n$-gon and/or the square.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 200$) — the number of test cases.
Next $T$ lines contain descriptions of test cases — one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon.
-----Output-----
Print $T$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
-----Example-----
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
|
from math import tan, pi
t = int(input())
for _ in range(t):
n = int(input())
print(1 / tan(pi / (2 * n)))
|
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd.
You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon.
Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square.
You can rotate $2n$-gon and/or the square.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 200$) — the number of test cases.
Next $T$ lines contain descriptions of test cases — one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon.
-----Output-----
Print $T$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
-----Example-----
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
|
import math
q = int(input())
for _ in range(q):
n = int(input())
n*=2
print(math.tan(math.pi/2-math.pi/n))
|
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd.
You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon.
Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square.
You can rotate $2n$-gon and/or the square.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 200$) — the number of test cases.
Next $T$ lines contain descriptions of test cases — one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon.
-----Output-----
Print $T$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
-----Example-----
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
|
from math import sin,pi,radians
def solve():
n = int(input())*2
a = 180*(n-2)/n
bc = (180-a)/2
d = 0.5/sin(radians(bc))
return round(2*(d**2-0.25)**0.5,8)
for _ in range(int(input())):
print(solve())
|
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd.
You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon.
Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square.
You can rotate $2n$-gon and/or the square.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 200$) — the number of test cases.
Next $T$ lines contain descriptions of test cases — one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon.
-----Output-----
Print $T$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
-----Example-----
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
|
import sys
import math
# from collections import deque
# import heapq
# from math import inf
# from math import gcd
# print(help(deque))
# 26
pprint = lambda s: print(' '.join(map(str, s)))
input = lambda: sys.stdin.readline().strip()
ipnut = input
# a, b, c, d = map(int, input().split())
# n = int(input())
# e = list(map(int,input().split()))
for i in range(int(input())):
n = int(input())
print(1/math.tan(math.pi/(2*n)))
"""
10
10 11 12 13 14 15 16 17 11 11
"""
|
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd.
You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon.
Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square.
You can rotate $2n$-gon and/or the square.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 200$) — the number of test cases.
Next $T$ lines contain descriptions of test cases — one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon.
-----Output-----
Print $T$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
-----Example-----
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
|
T = int(input())
import math
n = [0]*T
m = [0]*T
a = [0]*T
p = [0]*T
for t in range(T):
n = 2*int(input()) #,m[t] = [int(i) for i in input().split(' ')]
#a = [int(i) for i in input().split(' ')]
out = 0
if n%4 == 0:
print((math.tan(math.pi/n))**-1)
else:
print((math.sin(math.pi/n))**-1)
|
The statement of this problem is the same as the statement of problem C2. The only difference is that, in problem C1, $n$ is always even, and in C2, $n$ is always odd.
You are given a regular polygon with $2 \cdot n$ vertices (it's convex and has equal sides and equal angles) and all its sides have length $1$. Let's name it as $2n$-gon.
Your task is to find the square of the minimum size such that you can embed $2n$-gon in the square. Embedding $2n$-gon in the square means that you need to place $2n$-gon in the square in such way that each point which lies inside or on a border of $2n$-gon should also lie inside or on a border of the square.
You can rotate $2n$-gon and/or the square.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 200$) — the number of test cases.
Next $T$ lines contain descriptions of test cases — one per line. Each line contains single even integer $n$ ($2 \le n \le 200$). Don't forget you need to embed $2n$-gon, not an $n$-gon.
-----Output-----
Print $T$ real numbers — one per test case. For each test case, print the minimum length of a side of the square $2n$-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
-----Example-----
Input
3
2
4
200
Output
1.000000000
2.414213562
127.321336469
|
from math import pi, sin
for i in range(int(input())):
n = int(input())
a = 0
ans = 0
x = pi - pi * (n - 1) / n
for j in range(n - 1):
a += x
ans += sin(a)
print(ans)
|
The only difference between easy and hard versions is constraints.
The BerTV channel every day broadcasts one episode of one of the $k$ TV shows. You know the schedule for the next $n$ days: a sequence of integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le k$), where $a_i$ is the show, the episode of which will be shown in $i$-th day.
The subscription to the show is bought for the entire show (i.e. for all its episodes), for each show the subscription is bought separately.
How many minimum subscriptions do you need to buy in order to have the opportunity to watch episodes of purchased shows $d$ ($1 \le d \le n$) days in a row? In other words, you want to buy the minimum number of TV shows so that there is some segment of $d$ consecutive days in which all episodes belong to the purchased shows.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10000$) — the number of test cases in the input. Then $t$ test case descriptions follow.
The first line of each test case contains three integers $n, k$ and $d$ ($1 \le n \le 2\cdot10^5$, $1 \le k \le 10^6$, $1 \le d \le n$). The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le k$), where $a_i$ is the show that is broadcasted on the $i$-th day.
It is guaranteed that the sum of the values of $n$ for all test cases in the input does not exceed $2\cdot10^5$.
-----Output-----
Print $t$ integers — the answers to the test cases in the input in the order they follow. The answer to a test case is the minimum number of TV shows for which you need to purchase a subscription so that you can watch episodes of the purchased TV shows on BerTV for $d$ consecutive days. Please note that it is permissible that you will be able to watch more than $d$ days in a row.
-----Example-----
Input
4
5 2 2
1 2 1 2 1
9 3 3
3 3 3 2 2 2 1 1 1
4 10 4
10 8 6 4
16 9 8
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3
Output
2
1
4
5
-----Note-----
In the first test case to have an opportunity to watch shows for two consecutive days, you need to buy a subscription on show $1$ and on show $2$. So the answer is two.
In the second test case, you can buy a subscription to any show because for each show you can find a segment of three consecutive days, consisting only of episodes of this show.
In the third test case in the unique segment of four days, you have four different shows, so you need to buy a subscription to all these four shows.
In the fourth test case, you can buy subscriptions to shows $3,5,7,8,9$, and you will be able to watch shows for the last eight days.
|
for _ in range(int(input())):
n, k, d = list(map(int, input().split()))
a = list(map(int, input().split()))
s = {}
for q in range(d):
s[a[q]] = s.get(a[q], 0)+1
ans = len(s)
for q in range(d, n):
if s[a[q-d]] == 1:
del s[a[q-d]]
else:
s[a[q-d]] -= 1
s[a[q]] = s.get(a[q], 0)+1
ans = min(ans, len(s))
print(ans)
|
The only difference between easy and hard versions is constraints.
The BerTV channel every day broadcasts one episode of one of the $k$ TV shows. You know the schedule for the next $n$ days: a sequence of integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le k$), where $a_i$ is the show, the episode of which will be shown in $i$-th day.
The subscription to the show is bought for the entire show (i.e. for all its episodes), for each show the subscription is bought separately.
How many minimum subscriptions do you need to buy in order to have the opportunity to watch episodes of purchased shows $d$ ($1 \le d \le n$) days in a row? In other words, you want to buy the minimum number of TV shows so that there is some segment of $d$ consecutive days in which all episodes belong to the purchased shows.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10000$) — the number of test cases in the input. Then $t$ test case descriptions follow.
The first line of each test case contains three integers $n, k$ and $d$ ($1 \le n \le 2\cdot10^5$, $1 \le k \le 10^6$, $1 \le d \le n$). The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le k$), where $a_i$ is the show that is broadcasted on the $i$-th day.
It is guaranteed that the sum of the values of $n$ for all test cases in the input does not exceed $2\cdot10^5$.
-----Output-----
Print $t$ integers — the answers to the test cases in the input in the order they follow. The answer to a test case is the minimum number of TV shows for which you need to purchase a subscription so that you can watch episodes of the purchased TV shows on BerTV for $d$ consecutive days. Please note that it is permissible that you will be able to watch more than $d$ days in a row.
-----Example-----
Input
4
5 2 2
1 2 1 2 1
9 3 3
3 3 3 2 2 2 1 1 1
4 10 4
10 8 6 4
16 9 8
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3
Output
2
1
4
5
-----Note-----
In the first test case to have an opportunity to watch shows for two consecutive days, you need to buy a subscription on show $1$ and on show $2$. So the answer is two.
In the second test case, you can buy a subscription to any show because for each show you can find a segment of three consecutive days, consisting only of episodes of this show.
In the third test case in the unique segment of four days, you have four different shows, so you need to buy a subscription to all these four shows.
In the fourth test case, you can buy subscriptions to shows $3,5,7,8,9$, and you will be able to watch shows for the last eight days.
|
Q = int(input())
for q in range(Q):
n, k, d = tuple(map(int, input().split()))
arr = list(map(int, input().split()))
nums = {}
for i in range(d):
if arr[i] in nums:
nums[arr[i]] += 1
else:
nums[arr[i]] = 1
ans = len(nums)
for i in range(d, n):
if nums[arr[i - d]] == 1:
nums.pop(arr[i - d])
else:
nums[arr[i - d]] -= 1
if arr[i] in nums:
nums[arr[i]] += 1
else:
nums[arr[i]] = 1
ans = min(ans, len(nums))
print(ans)
|
The only difference between easy and hard versions is constraints.
The BerTV channel every day broadcasts one episode of one of the $k$ TV shows. You know the schedule for the next $n$ days: a sequence of integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le k$), where $a_i$ is the show, the episode of which will be shown in $i$-th day.
The subscription to the show is bought for the entire show (i.e. for all its episodes), for each show the subscription is bought separately.
How many minimum subscriptions do you need to buy in order to have the opportunity to watch episodes of purchased shows $d$ ($1 \le d \le n$) days in a row? In other words, you want to buy the minimum number of TV shows so that there is some segment of $d$ consecutive days in which all episodes belong to the purchased shows.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10000$) — the number of test cases in the input. Then $t$ test case descriptions follow.
The first line of each test case contains three integers $n, k$ and $d$ ($1 \le n \le 2\cdot10^5$, $1 \le k \le 10^6$, $1 \le d \le n$). The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le k$), where $a_i$ is the show that is broadcasted on the $i$-th day.
It is guaranteed that the sum of the values of $n$ for all test cases in the input does not exceed $2\cdot10^5$.
-----Output-----
Print $t$ integers — the answers to the test cases in the input in the order they follow. The answer to a test case is the minimum number of TV shows for which you need to purchase a subscription so that you can watch episodes of the purchased TV shows on BerTV for $d$ consecutive days. Please note that it is permissible that you will be able to watch more than $d$ days in a row.
-----Example-----
Input
4
5 2 2
1 2 1 2 1
9 3 3
3 3 3 2 2 2 1 1 1
4 10 4
10 8 6 4
16 9 8
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3
Output
2
1
4
5
-----Note-----
In the first test case to have an opportunity to watch shows for two consecutive days, you need to buy a subscription on show $1$ and on show $2$. So the answer is two.
In the second test case, you can buy a subscription to any show because for each show you can find a segment of three consecutive days, consisting only of episodes of this show.
In the third test case in the unique segment of four days, you have four different shows, so you need to buy a subscription to all these four shows.
In the fourth test case, you can buy subscriptions to shows $3,5,7,8,9$, and you will be able to watch shows for the last eight days.
|
for __ in range(int(input())):
n, k, d = list(map(int, input().split()))
ar = list(map(int, input().split()))
A = dict()
num = 0
for i in range(d):
if ar[i] in A:
A[ar[i]] += 1
else:
A[ar[i]] = 1
num += 1
ans = num
for j in range(d, n):
A[ar[j - d]] -= 1
if A[ar[j - d]] == 0:
num -= 1
if ar[j] in A:
if A[ar[j]] == 0:
num += 1
A[ar[j]] += 1
else:
A[ar[j]] = 1
num += 1
ans = min(num, ans)
print(ans)
|
The only difference between easy and hard versions is constraints.
The BerTV channel every day broadcasts one episode of one of the $k$ TV shows. You know the schedule for the next $n$ days: a sequence of integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le k$), where $a_i$ is the show, the episode of which will be shown in $i$-th day.
The subscription to the show is bought for the entire show (i.e. for all its episodes), for each show the subscription is bought separately.
How many minimum subscriptions do you need to buy in order to have the opportunity to watch episodes of purchased shows $d$ ($1 \le d \le n$) days in a row? In other words, you want to buy the minimum number of TV shows so that there is some segment of $d$ consecutive days in which all episodes belong to the purchased shows.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10000$) — the number of test cases in the input. Then $t$ test case descriptions follow.
The first line of each test case contains three integers $n, k$ and $d$ ($1 \le n \le 2\cdot10^5$, $1 \le k \le 10^6$, $1 \le d \le n$). The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le k$), where $a_i$ is the show that is broadcasted on the $i$-th day.
It is guaranteed that the sum of the values of $n$ for all test cases in the input does not exceed $2\cdot10^5$.
-----Output-----
Print $t$ integers — the answers to the test cases in the input in the order they follow. The answer to a test case is the minimum number of TV shows for which you need to purchase a subscription so that you can watch episodes of the purchased TV shows on BerTV for $d$ consecutive days. Please note that it is permissible that you will be able to watch more than $d$ days in a row.
-----Example-----
Input
4
5 2 2
1 2 1 2 1
9 3 3
3 3 3 2 2 2 1 1 1
4 10 4
10 8 6 4
16 9 8
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3
Output
2
1
4
5
-----Note-----
In the first test case to have an opportunity to watch shows for two consecutive days, you need to buy a subscription on show $1$ and on show $2$. So the answer is two.
In the second test case, you can buy a subscription to any show because for each show you can find a segment of three consecutive days, consisting only of episodes of this show.
In the third test case in the unique segment of four days, you have four different shows, so you need to buy a subscription to all these four shows.
In the fourth test case, you can buy subscriptions to shows $3,5,7,8,9$, and you will be able to watch shows for the last eight days.
|
t = int(input())
for i in range(t):
n, k, d = list(map(int, input().split()))
a = list(map(int, input().split()))
b = dict()
for i in range(n):
b[a[i]] = 0
count = 0
for i in range(d):
if b[a[i]] == 0:
count += 1
b[a[i]] += 1
ans = count
for i in range(n - d):
if b[a[i]] == 1:
count -=1
b[a[i]] -= 1
if b[a[i + d]] == 0:
count += 1
b[a[i + d]] += 1
ans = min(ans, count)
print(ans)
|
The only difference between easy and hard versions is constraints.
The BerTV channel every day broadcasts one episode of one of the $k$ TV shows. You know the schedule for the next $n$ days: a sequence of integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le k$), where $a_i$ is the show, the episode of which will be shown in $i$-th day.
The subscription to the show is bought for the entire show (i.e. for all its episodes), for each show the subscription is bought separately.
How many minimum subscriptions do you need to buy in order to have the opportunity to watch episodes of purchased shows $d$ ($1 \le d \le n$) days in a row? In other words, you want to buy the minimum number of TV shows so that there is some segment of $d$ consecutive days in which all episodes belong to the purchased shows.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10000$) — the number of test cases in the input. Then $t$ test case descriptions follow.
The first line of each test case contains three integers $n, k$ and $d$ ($1 \le n \le 2\cdot10^5$, $1 \le k \le 10^6$, $1 \le d \le n$). The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le k$), where $a_i$ is the show that is broadcasted on the $i$-th day.
It is guaranteed that the sum of the values of $n$ for all test cases in the input does not exceed $2\cdot10^5$.
-----Output-----
Print $t$ integers — the answers to the test cases in the input in the order they follow. The answer to a test case is the minimum number of TV shows for which you need to purchase a subscription so that you can watch episodes of the purchased TV shows on BerTV for $d$ consecutive days. Please note that it is permissible that you will be able to watch more than $d$ days in a row.
-----Example-----
Input
4
5 2 2
1 2 1 2 1
9 3 3
3 3 3 2 2 2 1 1 1
4 10 4
10 8 6 4
16 9 8
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3
Output
2
1
4
5
-----Note-----
In the first test case to have an opportunity to watch shows for two consecutive days, you need to buy a subscription on show $1$ and on show $2$. So the answer is two.
In the second test case, you can buy a subscription to any show because for each show you can find a segment of three consecutive days, consisting only of episodes of this show.
In the third test case in the unique segment of four days, you have four different shows, so you need to buy a subscription to all these four shows.
In the fourth test case, you can buy subscriptions to shows $3,5,7,8,9$, and you will be able to watch shows for the last eight days.
|
n=int(input())
for i in range(n):
n,k,d=list(map(int,input().split()))
a=[int(j) for j in input().split()]
dv=dict()
s=set()
mn=n
for j in range(n):
if j>=d:
mn=min(mn,len(s))
t=a[j-d]
dv[t]-=1
if dv[t]==0:
s.discard(t)
t=a[j]
if t in dv:
dv[t]+=1
else:
dv[t]=1
s.add(t)
mn=min(mn,len(s))
print(mn)
|
The only difference between easy and hard versions is constraints.
The BerTV channel every day broadcasts one episode of one of the $k$ TV shows. You know the schedule for the next $n$ days: a sequence of integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le k$), where $a_i$ is the show, the episode of which will be shown in $i$-th day.
The subscription to the show is bought for the entire show (i.e. for all its episodes), for each show the subscription is bought separately.
How many minimum subscriptions do you need to buy in order to have the opportunity to watch episodes of purchased shows $d$ ($1 \le d \le n$) days in a row? In other words, you want to buy the minimum number of TV shows so that there is some segment of $d$ consecutive days in which all episodes belong to the purchased shows.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10000$) — the number of test cases in the input. Then $t$ test case descriptions follow.
The first line of each test case contains three integers $n, k$ and $d$ ($1 \le n \le 2\cdot10^5$, $1 \le k \le 10^6$, $1 \le d \le n$). The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le k$), where $a_i$ is the show that is broadcasted on the $i$-th day.
It is guaranteed that the sum of the values of $n$ for all test cases in the input does not exceed $2\cdot10^5$.
-----Output-----
Print $t$ integers — the answers to the test cases in the input in the order they follow. The answer to a test case is the minimum number of TV shows for which you need to purchase a subscription so that you can watch episodes of the purchased TV shows on BerTV for $d$ consecutive days. Please note that it is permissible that you will be able to watch more than $d$ days in a row.
-----Example-----
Input
4
5 2 2
1 2 1 2 1
9 3 3
3 3 3 2 2 2 1 1 1
4 10 4
10 8 6 4
16 9 8
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3
Output
2
1
4
5
-----Note-----
In the first test case to have an opportunity to watch shows for two consecutive days, you need to buy a subscription on show $1$ and on show $2$. So the answer is two.
In the second test case, you can buy a subscription to any show because for each show you can find a segment of three consecutive days, consisting only of episodes of this show.
In the third test case in the unique segment of four days, you have four different shows, so you need to buy a subscription to all these four shows.
In the fourth test case, you can buy subscriptions to shows $3,5,7,8,9$, and you will be able to watch shows for the last eight days.
|
t = int(input())
for u in range(t):
n, d, k = map(int, input().split())
a = list(map(int, input().split()))
c = set()
b = {}
ans = 10 ** 9
for i in range(min(n, k)):
c.add(a[i])
if a[i] in b:
b[a[i]] += 1
else:
b[a[i]] = 1
i = k
ans = min(ans, len(c))
while i < n:
b[a[i - k]] -= 1
if b[a[i - k]] == 0:
c.discard(a[i - k])
if a[i] in b:
b[a[i]] += 1
else:
b[a[i]] = 1
c.add(a[i])
ans = min(ans, len(c))
i += 1
print(ans)
|
The only difference between easy and hard versions is constraints.
The BerTV channel every day broadcasts one episode of one of the $k$ TV shows. You know the schedule for the next $n$ days: a sequence of integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le k$), where $a_i$ is the show, the episode of which will be shown in $i$-th day.
The subscription to the show is bought for the entire show (i.e. for all its episodes), for each show the subscription is bought separately.
How many minimum subscriptions do you need to buy in order to have the opportunity to watch episodes of purchased shows $d$ ($1 \le d \le n$) days in a row? In other words, you want to buy the minimum number of TV shows so that there is some segment of $d$ consecutive days in which all episodes belong to the purchased shows.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10000$) — the number of test cases in the input. Then $t$ test case descriptions follow.
The first line of each test case contains three integers $n, k$ and $d$ ($1 \le n \le 2\cdot10^5$, $1 \le k \le 10^6$, $1 \le d \le n$). The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le k$), where $a_i$ is the show that is broadcasted on the $i$-th day.
It is guaranteed that the sum of the values of $n$ for all test cases in the input does not exceed $2\cdot10^5$.
-----Output-----
Print $t$ integers — the answers to the test cases in the input in the order they follow. The answer to a test case is the minimum number of TV shows for which you need to purchase a subscription so that you can watch episodes of the purchased TV shows on BerTV for $d$ consecutive days. Please note that it is permissible that you will be able to watch more than $d$ days in a row.
-----Example-----
Input
4
5 2 2
1 2 1 2 1
9 3 3
3 3 3 2 2 2 1 1 1
4 10 4
10 8 6 4
16 9 8
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3
Output
2
1
4
5
-----Note-----
In the first test case to have an opportunity to watch shows for two consecutive days, you need to buy a subscription on show $1$ and on show $2$. So the answer is two.
In the second test case, you can buy a subscription to any show because for each show you can find a segment of three consecutive days, consisting only of episodes of this show.
In the third test case in the unique segment of four days, you have four different shows, so you need to buy a subscription to all these four shows.
In the fourth test case, you can buy subscriptions to shows $3,5,7,8,9$, and you will be able to watch shows for the last eight days.
|
import sys
input = sys.stdin.readline
def getInt(): return int(input())
def getVars(): return list(map(int, input().split()))
def getList(): return list(map(int, input().split()))
def getStr(): return input().strip()
## -------------------------------
t = getInt()
for _ in range(t):
n, k, d = getVars()
a = getList()
b = {}
for i in range(d):
if a[i] not in b:
b[a[i]] = 0
b[a[i]] += 1
res = len(list(b.keys()))
res1 = res
for i in range(d, n):
b[a[i-d]] -= 1
if b[a[i-d]] == 0:
del b[a[i-d]]
res1 -= 1
if a[i] not in b:
b[a[i]] = 0
res1 += 1
b[a[i]] += 1
res = min(res, res1)
print(res)
|
The only difference between easy and hard versions is constraints.
The BerTV channel every day broadcasts one episode of one of the $k$ TV shows. You know the schedule for the next $n$ days: a sequence of integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le k$), where $a_i$ is the show, the episode of which will be shown in $i$-th day.
The subscription to the show is bought for the entire show (i.e. for all its episodes), for each show the subscription is bought separately.
How many minimum subscriptions do you need to buy in order to have the opportunity to watch episodes of purchased shows $d$ ($1 \le d \le n$) days in a row? In other words, you want to buy the minimum number of TV shows so that there is some segment of $d$ consecutive days in which all episodes belong to the purchased shows.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10000$) — the number of test cases in the input. Then $t$ test case descriptions follow.
The first line of each test case contains three integers $n, k$ and $d$ ($1 \le n \le 2\cdot10^5$, $1 \le k \le 10^6$, $1 \le d \le n$). The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le k$), where $a_i$ is the show that is broadcasted on the $i$-th day.
It is guaranteed that the sum of the values of $n$ for all test cases in the input does not exceed $2\cdot10^5$.
-----Output-----
Print $t$ integers — the answers to the test cases in the input in the order they follow. The answer to a test case is the minimum number of TV shows for which you need to purchase a subscription so that you can watch episodes of the purchased TV shows on BerTV for $d$ consecutive days. Please note that it is permissible that you will be able to watch more than $d$ days in a row.
-----Example-----
Input
4
5 2 2
1 2 1 2 1
9 3 3
3 3 3 2 2 2 1 1 1
4 10 4
10 8 6 4
16 9 8
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3
Output
2
1
4
5
-----Note-----
In the first test case to have an opportunity to watch shows for two consecutive days, you need to buy a subscription on show $1$ and on show $2$. So the answer is two.
In the second test case, you can buy a subscription to any show because for each show you can find a segment of three consecutive days, consisting only of episodes of this show.
In the third test case in the unique segment of four days, you have four different shows, so you need to buy a subscription to all these four shows.
In the fourth test case, you can buy subscriptions to shows $3,5,7,8,9$, and you will be able to watch shows for the last eight days.
|
from collections import deque
t=int(input())
for i in range(t):
n,k,dp=[int(x) for x in input().split()]
d={}
i=0
p=deque()
cur=0
min=k
for el in input().split():
i+=1
if i<=dp:
p.append(el)
if el in list(d.keys()):
d[el]+=1
else:
d[el]=1
cur+=1
else:
if cur<min:
min=cur
##deleting
exc=p.popleft()
if d[exc]==1:
d.pop(exc)
cur-=1
else:
d[exc]-=1
##adding
p.append(el)
if el in list(d.keys()):
d[el]+=1
else:
d[el]=1
cur+=1
##print(d,p)
if min>cur:
min=cur
print(min)
|
The only difference between easy and hard versions is constraints.
The BerTV channel every day broadcasts one episode of one of the $k$ TV shows. You know the schedule for the next $n$ days: a sequence of integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le k$), where $a_i$ is the show, the episode of which will be shown in $i$-th day.
The subscription to the show is bought for the entire show (i.e. for all its episodes), for each show the subscription is bought separately.
How many minimum subscriptions do you need to buy in order to have the opportunity to watch episodes of purchased shows $d$ ($1 \le d \le n$) days in a row? In other words, you want to buy the minimum number of TV shows so that there is some segment of $d$ consecutive days in which all episodes belong to the purchased shows.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10000$) — the number of test cases in the input. Then $t$ test case descriptions follow.
The first line of each test case contains three integers $n, k$ and $d$ ($1 \le n \le 2\cdot10^5$, $1 \le k \le 10^6$, $1 \le d \le n$). The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le k$), where $a_i$ is the show that is broadcasted on the $i$-th day.
It is guaranteed that the sum of the values of $n$ for all test cases in the input does not exceed $2\cdot10^5$.
-----Output-----
Print $t$ integers — the answers to the test cases in the input in the order they follow. The answer to a test case is the minimum number of TV shows for which you need to purchase a subscription so that you can watch episodes of the purchased TV shows on BerTV for $d$ consecutive days. Please note that it is permissible that you will be able to watch more than $d$ days in a row.
-----Example-----
Input
4
5 2 2
1 2 1 2 1
9 3 3
3 3 3 2 2 2 1 1 1
4 10 4
10 8 6 4
16 9 8
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3
Output
2
1
4
5
-----Note-----
In the first test case to have an opportunity to watch shows for two consecutive days, you need to buy a subscription on show $1$ and on show $2$. So the answer is two.
In the second test case, you can buy a subscription to any show because for each show you can find a segment of three consecutive days, consisting only of episodes of this show.
In the third test case in the unique segment of four days, you have four different shows, so you need to buy a subscription to all these four shows.
In the fourth test case, you can buy subscriptions to shows $3,5,7,8,9$, and you will be able to watch shows for the last eight days.
|
import math
import collections
arrK = [0] * 1000050
def cleanK(q):
while len(q):
arrK[q.pop()] = 0
def test():
n, k, d = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = math.inf
q = collections.deque()
sumK = 0
for i in range(len(a)):
q.append(a[i])
if arrK[a[i]] == 0:
sumK += 1
arrK[a[i]] += 1
if len(q) > d:
var = q.popleft()
arrK[var] -= 1
if arrK[var] == 0:
sumK -= 1
if len(q) == d and sumK < ans:
ans = sumK
cleanK(q)
print(ans)
#
# def print2d(a):
# for i in a:
# print(' '.join(list(map(str, i))))
t = int(input())
for i in range(t):
test()
|
The only difference between easy and hard versions is constraints.
The BerTV channel every day broadcasts one episode of one of the $k$ TV shows. You know the schedule for the next $n$ days: a sequence of integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le k$), where $a_i$ is the show, the episode of which will be shown in $i$-th day.
The subscription to the show is bought for the entire show (i.e. for all its episodes), for each show the subscription is bought separately.
How many minimum subscriptions do you need to buy in order to have the opportunity to watch episodes of purchased shows $d$ ($1 \le d \le n$) days in a row? In other words, you want to buy the minimum number of TV shows so that there is some segment of $d$ consecutive days in which all episodes belong to the purchased shows.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10000$) — the number of test cases in the input. Then $t$ test case descriptions follow.
The first line of each test case contains three integers $n, k$ and $d$ ($1 \le n \le 2\cdot10^5$, $1 \le k \le 10^6$, $1 \le d \le n$). The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le k$), where $a_i$ is the show that is broadcasted on the $i$-th day.
It is guaranteed that the sum of the values of $n$ for all test cases in the input does not exceed $2\cdot10^5$.
-----Output-----
Print $t$ integers — the answers to the test cases in the input in the order they follow. The answer to a test case is the minimum number of TV shows for which you need to purchase a subscription so that you can watch episodes of the purchased TV shows on BerTV for $d$ consecutive days. Please note that it is permissible that you will be able to watch more than $d$ days in a row.
-----Example-----
Input
4
5 2 2
1 2 1 2 1
9 3 3
3 3 3 2 2 2 1 1 1
4 10 4
10 8 6 4
16 9 8
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3
Output
2
1
4
5
-----Note-----
In the first test case to have an opportunity to watch shows for two consecutive days, you need to buy a subscription on show $1$ and on show $2$. So the answer is two.
In the second test case, you can buy a subscription to any show because for each show you can find a segment of three consecutive days, consisting only of episodes of this show.
In the third test case in the unique segment of four days, you have four different shows, so you need to buy a subscription to all these four shows.
In the fourth test case, you can buy subscriptions to shows $3,5,7,8,9$, and you will be able to watch shows for the last eight days.
|
def main():
n, k, d = list(map(int, input().split()))
l = list(map(int, input().split()))
rez = 0
rezline = {}
for i in range(d):
if rezline.get(l[i]) is None:
rezline[l[i]] = 0
rez += 1
rezline[l[i]] += 1
rez_p = rez
for i in range(d, n):
if rezline[l[i-d]] == 1:
rez_p -= 1
rezline[l[i-d]] -= 1
if rezline.get(l[i]) in [0, None]:
rez_p += 1
rezline[l[i]] = 1
else:
rezline[l[i]] += 1
rez = min(rez, rez_p)
print(rez)
t = int(input())
for i in range(t):
main()
|
The only difference between easy and hard versions is constraints.
The BerTV channel every day broadcasts one episode of one of the $k$ TV shows. You know the schedule for the next $n$ days: a sequence of integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le k$), where $a_i$ is the show, the episode of which will be shown in $i$-th day.
The subscription to the show is bought for the entire show (i.e. for all its episodes), for each show the subscription is bought separately.
How many minimum subscriptions do you need to buy in order to have the opportunity to watch episodes of purchased shows $d$ ($1 \le d \le n$) days in a row? In other words, you want to buy the minimum number of TV shows so that there is some segment of $d$ consecutive days in which all episodes belong to the purchased shows.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10000$) — the number of test cases in the input. Then $t$ test case descriptions follow.
The first line of each test case contains three integers $n, k$ and $d$ ($1 \le n \le 2\cdot10^5$, $1 \le k \le 10^6$, $1 \le d \le n$). The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le k$), where $a_i$ is the show that is broadcasted on the $i$-th day.
It is guaranteed that the sum of the values of $n$ for all test cases in the input does not exceed $2\cdot10^5$.
-----Output-----
Print $t$ integers — the answers to the test cases in the input in the order they follow. The answer to a test case is the minimum number of TV shows for which you need to purchase a subscription so that you can watch episodes of the purchased TV shows on BerTV for $d$ consecutive days. Please note that it is permissible that you will be able to watch more than $d$ days in a row.
-----Example-----
Input
4
5 2 2
1 2 1 2 1
9 3 3
3 3 3 2 2 2 1 1 1
4 10 4
10 8 6 4
16 9 8
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3
Output
2
1
4
5
-----Note-----
In the first test case to have an opportunity to watch shows for two consecutive days, you need to buy a subscription on show $1$ and on show $2$. So the answer is two.
In the second test case, you can buy a subscription to any show because for each show you can find a segment of three consecutive days, consisting only of episodes of this show.
In the third test case in the unique segment of four days, you have four different shows, so you need to buy a subscription to all these four shows.
In the fourth test case, you can buy subscriptions to shows $3,5,7,8,9$, and you will be able to watch shows for the last eight days.
|
t = int(input())
for _ in range(t):
n, k, d = list(map(int, input().split()))
a = list(map(int, input().split()))
m = dict()
for i in range(d):
if a[i] not in m:
m[a[i]] = 0
m[a[i]] += 1
ans = len(m)
for i in range(n - d):
m[a[i]] -= 1
if m[a[i]] == 0:
m.pop(a[i])
if a[i + d] not in m:
m[a[i + d]] = 0
m[a[i + d]] += 1
ans = min(ans, len(m))
print(ans)
|
The only difference between easy and hard versions is constraints.
The BerTV channel every day broadcasts one episode of one of the $k$ TV shows. You know the schedule for the next $n$ days: a sequence of integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le k$), where $a_i$ is the show, the episode of which will be shown in $i$-th day.
The subscription to the show is bought for the entire show (i.e. for all its episodes), for each show the subscription is bought separately.
How many minimum subscriptions do you need to buy in order to have the opportunity to watch episodes of purchased shows $d$ ($1 \le d \le n$) days in a row? In other words, you want to buy the minimum number of TV shows so that there is some segment of $d$ consecutive days in which all episodes belong to the purchased shows.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10000$) — the number of test cases in the input. Then $t$ test case descriptions follow.
The first line of each test case contains three integers $n, k$ and $d$ ($1 \le n \le 2\cdot10^5$, $1 \le k \le 10^6$, $1 \le d \le n$). The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le k$), where $a_i$ is the show that is broadcasted on the $i$-th day.
It is guaranteed that the sum of the values of $n$ for all test cases in the input does not exceed $2\cdot10^5$.
-----Output-----
Print $t$ integers — the answers to the test cases in the input in the order they follow. The answer to a test case is the minimum number of TV shows for which you need to purchase a subscription so that you can watch episodes of the purchased TV shows on BerTV for $d$ consecutive days. Please note that it is permissible that you will be able to watch more than $d$ days in a row.
-----Example-----
Input
4
5 2 2
1 2 1 2 1
9 3 3
3 3 3 2 2 2 1 1 1
4 10 4
10 8 6 4
16 9 8
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3
Output
2
1
4
5
-----Note-----
In the first test case to have an opportunity to watch shows for two consecutive days, you need to buy a subscription on show $1$ and on show $2$. So the answer is two.
In the second test case, you can buy a subscription to any show because for each show you can find a segment of three consecutive days, consisting only of episodes of this show.
In the third test case in the unique segment of four days, you have four different shows, so you need to buy a subscription to all these four shows.
In the fourth test case, you can buy subscriptions to shows $3,5,7,8,9$, and you will be able to watch shows for the last eight days.
|
def check(m):
dictsums = dict()
i, j = 0, 0
dictsums[series[0]] = 1
while i < len(series) - 1 and i - j + 1 < d:
if series[i + 1] not in dictsums and len(dictsums) == m:
while dictsums[series[j]] > 1:
dictsums[series[j]] -= 1
j += 1
dictsums.pop(series[j])
dictsums[series[i + 1]] = 1
j += 1
elif series[i + 1] not in dictsums and len(dictsums) < m:
dictsums[series[i + 1]] = 1
else:
dictsums[series[i + 1]] += 1
i += 1
if i - j + 1 >= d:
return 1
else:
return 0
q = int(input())
for i in range(q):
n, k, d = map(int, input().split())
series = list(map(int, input().split()))
L = 0
R = k
while R - L > 1:
m = (R + L) // 2
if check(m):
R = m
else:
L = m
print(R)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.