inputs
stringlengths 50
14k
| targets
stringlengths 4
655k
|
|---|---|
You're given an array $a$ of $n$ integers, such that $a_1 + a_2 + \cdots + a_n = 0$.
In one operation, you can choose two different indices $i$ and $j$ ($1 \le i, j \le n$), decrement $a_i$ by one and increment $a_j$ by one. If $i < j$ this operation is free, otherwise it costs one coin.
How many coins do you have to spend in order to make all elements equal to $0$?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 5000$). Description of the test cases follows.
The first line of each test case contains an integer $n$ ($1 \le n \le 10^5$) — the number of elements.
The next line contains $n$ integers $a_1, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$). It is given that $\sum_{i=1}^n a_i = 0$.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $0$.
-----Example-----
Input
7
4
-3 5 -3 1
2
1 -1
4
-3 2 -3 4
4
-1 1 1 -1
7
-5 7 -6 -4 17 -13 4
6
-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000
1
0
Output
3
0
4
1
8
3000000000
0
-----Note-----
Possible strategy for the first test case: Do $(i=2, j=3)$ three times (free), $a = [-3, 2, 0, 1]$. Do $(i=2, j=1)$ two times (pay two coins), $a = [-1, 0, 0, 1]$. Do $(i=4, j=1)$ one time (pay one coin), $a = [0, 0, 0, 0]$.
|
tests = int(input())
for t in range(tests):
n = int(input())
ls = list(map(int, input().split()))
curr = 0
res = 0
for item in ls:
curr += item
if curr < res:
res = curr
print(-res)
|
You're given an array $a$ of $n$ integers, such that $a_1 + a_2 + \cdots + a_n = 0$.
In one operation, you can choose two different indices $i$ and $j$ ($1 \le i, j \le n$), decrement $a_i$ by one and increment $a_j$ by one. If $i < j$ this operation is free, otherwise it costs one coin.
How many coins do you have to spend in order to make all elements equal to $0$?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 5000$). Description of the test cases follows.
The first line of each test case contains an integer $n$ ($1 \le n \le 10^5$) — the number of elements.
The next line contains $n$ integers $a_1, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$). It is given that $\sum_{i=1}^n a_i = 0$.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $0$.
-----Example-----
Input
7
4
-3 5 -3 1
2
1 -1
4
-3 2 -3 4
4
-1 1 1 -1
7
-5 7 -6 -4 17 -13 4
6
-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000
1
0
Output
3
0
4
1
8
3000000000
0
-----Note-----
Possible strategy for the first test case: Do $(i=2, j=3)$ three times (free), $a = [-3, 2, 0, 1]$. Do $(i=2, j=1)$ two times (pay two coins), $a = [-1, 0, 0, 1]$. Do $(i=4, j=1)$ one time (pay one coin), $a = [0, 0, 0, 0]$.
|
def main():
t = int(input())
for _ in range(t):
n = int(input())
alst = list(map(int, input().split()))
ans = 0
total = 0
for a in alst:
total -= a
ans = max(ans, total)
print(ans)
main()
|
You're given an array $a$ of $n$ integers, such that $a_1 + a_2 + \cdots + a_n = 0$.
In one operation, you can choose two different indices $i$ and $j$ ($1 \le i, j \le n$), decrement $a_i$ by one and increment $a_j$ by one. If $i < j$ this operation is free, otherwise it costs one coin.
How many coins do you have to spend in order to make all elements equal to $0$?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 5000$). Description of the test cases follows.
The first line of each test case contains an integer $n$ ($1 \le n \le 10^5$) — the number of elements.
The next line contains $n$ integers $a_1, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$). It is given that $\sum_{i=1}^n a_i = 0$.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $0$.
-----Example-----
Input
7
4
-3 5 -3 1
2
1 -1
4
-3 2 -3 4
4
-1 1 1 -1
7
-5 7 -6 -4 17 -13 4
6
-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000
1
0
Output
3
0
4
1
8
3000000000
0
-----Note-----
Possible strategy for the first test case: Do $(i=2, j=3)$ three times (free), $a = [-3, 2, 0, 1]$. Do $(i=2, j=1)$ two times (pay two coins), $a = [-1, 0, 0, 1]$. Do $(i=4, j=1)$ one time (pay one coin), $a = [0, 0, 0, 0]$.
|
for _ in range (int(input())):
n=int(input())
a=list(map(int,input().split()))
r=0
avl=0
for i in a:
if i>0:
avl+=i
else:
i=abs(i)
d=min(avl,i)
avl-=d
r+=i-d
print(r)
|
You're given an array $a$ of $n$ integers, such that $a_1 + a_2 + \cdots + a_n = 0$.
In one operation, you can choose two different indices $i$ and $j$ ($1 \le i, j \le n$), decrement $a_i$ by one and increment $a_j$ by one. If $i < j$ this operation is free, otherwise it costs one coin.
How many coins do you have to spend in order to make all elements equal to $0$?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 5000$). Description of the test cases follows.
The first line of each test case contains an integer $n$ ($1 \le n \le 10^5$) — the number of elements.
The next line contains $n$ integers $a_1, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$). It is given that $\sum_{i=1}^n a_i = 0$.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $0$.
-----Example-----
Input
7
4
-3 5 -3 1
2
1 -1
4
-3 2 -3 4
4
-1 1 1 -1
7
-5 7 -6 -4 17 -13 4
6
-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000
1
0
Output
3
0
4
1
8
3000000000
0
-----Note-----
Possible strategy for the first test case: Do $(i=2, j=3)$ three times (free), $a = [-3, 2, 0, 1]$. Do $(i=2, j=1)$ two times (pay two coins), $a = [-1, 0, 0, 1]$. Do $(i=4, j=1)$ one time (pay one coin), $a = [0, 0, 0, 0]$.
|
import bisect
import copy
import fractions
import functools
import heapq
import math
import random
import sys
def __starting_point():
T = int(input())
for t in range(T):
N = int(input())
A = list(map(int, input().split()))
total = 0
min_ = 0
for a in A:
total += a
min_ = min(min_, total)
print(str(abs(min_)))
__starting_point()
|
You're given an array $a$ of $n$ integers, such that $a_1 + a_2 + \cdots + a_n = 0$.
In one operation, you can choose two different indices $i$ and $j$ ($1 \le i, j \le n$), decrement $a_i$ by one and increment $a_j$ by one. If $i < j$ this operation is free, otherwise it costs one coin.
How many coins do you have to spend in order to make all elements equal to $0$?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 5000$). Description of the test cases follows.
The first line of each test case contains an integer $n$ ($1 \le n \le 10^5$) — the number of elements.
The next line contains $n$ integers $a_1, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$). It is given that $\sum_{i=1}^n a_i = 0$.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $0$.
-----Example-----
Input
7
4
-3 5 -3 1
2
1 -1
4
-3 2 -3 4
4
-1 1 1 -1
7
-5 7 -6 -4 17 -13 4
6
-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000
1
0
Output
3
0
4
1
8
3000000000
0
-----Note-----
Possible strategy for the first test case: Do $(i=2, j=3)$ three times (free), $a = [-3, 2, 0, 1]$. Do $(i=2, j=1)$ two times (pay two coins), $a = [-1, 0, 0, 1]$. Do $(i=4, j=1)$ one time (pay one coin), $a = [0, 0, 0, 0]$.
|
t = int(input())
for _ in range(t):
n = int(input())
A = list(map(int,input().split()))
res = 0
temp = 0
for a in A:
temp+=a
res = min(res,temp)
print(-res)
|
You're given an array $a$ of $n$ integers, such that $a_1 + a_2 + \cdots + a_n = 0$.
In one operation, you can choose two different indices $i$ and $j$ ($1 \le i, j \le n$), decrement $a_i$ by one and increment $a_j$ by one. If $i < j$ this operation is free, otherwise it costs one coin.
How many coins do you have to spend in order to make all elements equal to $0$?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 5000$). Description of the test cases follows.
The first line of each test case contains an integer $n$ ($1 \le n \le 10^5$) — the number of elements.
The next line contains $n$ integers $a_1, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$). It is given that $\sum_{i=1}^n a_i = 0$.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $0$.
-----Example-----
Input
7
4
-3 5 -3 1
2
1 -1
4
-3 2 -3 4
4
-1 1 1 -1
7
-5 7 -6 -4 17 -13 4
6
-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000
1
0
Output
3
0
4
1
8
3000000000
0
-----Note-----
Possible strategy for the first test case: Do $(i=2, j=3)$ three times (free), $a = [-3, 2, 0, 1]$. Do $(i=2, j=1)$ two times (pay two coins), $a = [-1, 0, 0, 1]$. Do $(i=4, j=1)$ one time (pay one coin), $a = [0, 0, 0, 0]$.
|
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
pre = [0]*(n+1)
for i in range(n):
pre[i+1] = pre[i]+a[i]
print(abs(min(pre)))
|
You're given an array $a$ of $n$ integers, such that $a_1 + a_2 + \cdots + a_n = 0$.
In one operation, you can choose two different indices $i$ and $j$ ($1 \le i, j \le n$), decrement $a_i$ by one and increment $a_j$ by one. If $i < j$ this operation is free, otherwise it costs one coin.
How many coins do you have to spend in order to make all elements equal to $0$?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 5000$). Description of the test cases follows.
The first line of each test case contains an integer $n$ ($1 \le n \le 10^5$) — the number of elements.
The next line contains $n$ integers $a_1, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$). It is given that $\sum_{i=1}^n a_i = 0$.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $0$.
-----Example-----
Input
7
4
-3 5 -3 1
2
1 -1
4
-3 2 -3 4
4
-1 1 1 -1
7
-5 7 -6 -4 17 -13 4
6
-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000
1
0
Output
3
0
4
1
8
3000000000
0
-----Note-----
Possible strategy for the first test case: Do $(i=2, j=3)$ three times (free), $a = [-3, 2, 0, 1]$. Do $(i=2, j=1)$ two times (pay two coins), $a = [-1, 0, 0, 1]$. Do $(i=4, j=1)$ one time (pay one coin), $a = [0, 0, 0, 0]$.
|
t = int(input())
while t:
t += -1
n = int(input())
l = list(map(int, input().split()))
ans = 0
sm = 0
for i in l:
sm += i
ans = min(ans, sm)
print(abs(ans))
|
You're given an array $a$ of $n$ integers, such that $a_1 + a_2 + \cdots + a_n = 0$.
In one operation, you can choose two different indices $i$ and $j$ ($1 \le i, j \le n$), decrement $a_i$ by one and increment $a_j$ by one. If $i < j$ this operation is free, otherwise it costs one coin.
How many coins do you have to spend in order to make all elements equal to $0$?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 5000$). Description of the test cases follows.
The first line of each test case contains an integer $n$ ($1 \le n \le 10^5$) — the number of elements.
The next line contains $n$ integers $a_1, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$). It is given that $\sum_{i=1}^n a_i = 0$.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $0$.
-----Example-----
Input
7
4
-3 5 -3 1
2
1 -1
4
-3 2 -3 4
4
-1 1 1 -1
7
-5 7 -6 -4 17 -13 4
6
-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000
1
0
Output
3
0
4
1
8
3000000000
0
-----Note-----
Possible strategy for the first test case: Do $(i=2, j=3)$ three times (free), $a = [-3, 2, 0, 1]$. Do $(i=2, j=1)$ two times (pay two coins), $a = [-1, 0, 0, 1]$. Do $(i=4, j=1)$ one time (pay one coin), $a = [0, 0, 0, 0]$.
|
"""
Author: Q.E.D
Time: 2020-09-06 09:39:09
"""
T = int(input())
for _ in range(T):
n = int(input())
a = list(map(int, input().split()))
ans = 0
quota = 0
for x in a:
k = abs(x)
if x >= 0:
quota += k
else:
r = max(0, k - quota)
quota -= (k - r)
ans += r
print(ans)
|
You're given an array $a$ of $n$ integers, such that $a_1 + a_2 + \cdots + a_n = 0$.
In one operation, you can choose two different indices $i$ and $j$ ($1 \le i, j \le n$), decrement $a_i$ by one and increment $a_j$ by one. If $i < j$ this operation is free, otherwise it costs one coin.
How many coins do you have to spend in order to make all elements equal to $0$?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 5000$). Description of the test cases follows.
The first line of each test case contains an integer $n$ ($1 \le n \le 10^5$) — the number of elements.
The next line contains $n$ integers $a_1, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$). It is given that $\sum_{i=1}^n a_i = 0$.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $0$.
-----Example-----
Input
7
4
-3 5 -3 1
2
1 -1
4
-3 2 -3 4
4
-1 1 1 -1
7
-5 7 -6 -4 17 -13 4
6
-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000
1
0
Output
3
0
4
1
8
3000000000
0
-----Note-----
Possible strategy for the first test case: Do $(i=2, j=3)$ three times (free), $a = [-3, 2, 0, 1]$. Do $(i=2, j=1)$ two times (pay two coins), $a = [-1, 0, 0, 1]$. Do $(i=4, j=1)$ one time (pay one coin), $a = [0, 0, 0, 0]$.
|
#!/usr/bin/env pypy3
from sys import stdin, stdout
def input():
return stdin.readline().strip()
def ans(A):
A = A[::-1]
ret = float("-inf")
s = 0
for a in A:
s += a
ret = max(ret, s)
return ret
T = int(input())
for t in range(T):
input()
A = list(map(int, input().split()))
print(ans(A))
|
You're given an array $a$ of $n$ integers, such that $a_1 + a_2 + \cdots + a_n = 0$.
In one operation, you can choose two different indices $i$ and $j$ ($1 \le i, j \le n$), decrement $a_i$ by one and increment $a_j$ by one. If $i < j$ this operation is free, otherwise it costs one coin.
How many coins do you have to spend in order to make all elements equal to $0$?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 5000$). Description of the test cases follows.
The first line of each test case contains an integer $n$ ($1 \le n \le 10^5$) — the number of elements.
The next line contains $n$ integers $a_1, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$). It is given that $\sum_{i=1}^n a_i = 0$.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $0$.
-----Example-----
Input
7
4
-3 5 -3 1
2
1 -1
4
-3 2 -3 4
4
-1 1 1 -1
7
-5 7 -6 -4 17 -13 4
6
-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000
1
0
Output
3
0
4
1
8
3000000000
0
-----Note-----
Possible strategy for the first test case: Do $(i=2, j=3)$ three times (free), $a = [-3, 2, 0, 1]$. Do $(i=2, j=1)$ two times (pay two coins), $a = [-1, 0, 0, 1]$. Do $(i=4, j=1)$ one time (pay one coin), $a = [0, 0, 0, 0]$.
|
t = int(input())
for i in range(t):
n = int(input())
a = list(map(int, input().split()))
min = 0
s = 0
for i in range(n):
s = s + a[i]
if s < min:
min = s
print(abs(min))
|
You're given an array $a$ of $n$ integers, such that $a_1 + a_2 + \cdots + a_n = 0$.
In one operation, you can choose two different indices $i$ and $j$ ($1 \le i, j \le n$), decrement $a_i$ by one and increment $a_j$ by one. If $i < j$ this operation is free, otherwise it costs one coin.
How many coins do you have to spend in order to make all elements equal to $0$?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 5000$). Description of the test cases follows.
The first line of each test case contains an integer $n$ ($1 \le n \le 10^5$) — the number of elements.
The next line contains $n$ integers $a_1, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$). It is given that $\sum_{i=1}^n a_i = 0$.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $0$.
-----Example-----
Input
7
4
-3 5 -3 1
2
1 -1
4
-3 2 -3 4
4
-1 1 1 -1
7
-5 7 -6 -4 17 -13 4
6
-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000
1
0
Output
3
0
4
1
8
3000000000
0
-----Note-----
Possible strategy for the first test case: Do $(i=2, j=3)$ three times (free), $a = [-3, 2, 0, 1]$. Do $(i=2, j=1)$ two times (pay two coins), $a = [-1, 0, 0, 1]$. Do $(i=4, j=1)$ one time (pay one coin), $a = [0, 0, 0, 0]$.
|
from collections import defaultdict as dd
import sys
input=sys.stdin.readline
t=int(input())
while t:
n=int(input())
#n,m=map(int,input().split())
l=list(map(int,input().split()))
st=0
for i in range(n):
if(l[i]>0):
st+=l[i]
else:
if(st):
mi=min(st,-l[i])
st-=mi
print(st)
t-=1
|
You're given an array $a$ of $n$ integers, such that $a_1 + a_2 + \cdots + a_n = 0$.
In one operation, you can choose two different indices $i$ and $j$ ($1 \le i, j \le n$), decrement $a_i$ by one and increment $a_j$ by one. If $i < j$ this operation is free, otherwise it costs one coin.
How many coins do you have to spend in order to make all elements equal to $0$?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 5000$). Description of the test cases follows.
The first line of each test case contains an integer $n$ ($1 \le n \le 10^5$) — the number of elements.
The next line contains $n$ integers $a_1, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$). It is given that $\sum_{i=1}^n a_i = 0$.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $0$.
-----Example-----
Input
7
4
-3 5 -3 1
2
1 -1
4
-3 2 -3 4
4
-1 1 1 -1
7
-5 7 -6 -4 17 -13 4
6
-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000
1
0
Output
3
0
4
1
8
3000000000
0
-----Note-----
Possible strategy for the first test case: Do $(i=2, j=3)$ three times (free), $a = [-3, 2, 0, 1]$. Do $(i=2, j=1)$ two times (pay two coins), $a = [-1, 0, 0, 1]$. Do $(i=4, j=1)$ one time (pay one coin), $a = [0, 0, 0, 0]$.
|
from sys import stdin
from math import ceil
inp = lambda : stdin.readline().strip()
t = int(inp())
for _ in range(t):
n = int(inp())
a = [int(x) for x in inp().split()]
cumm = 0
ans = 0
for i in range(n):
cumm += a[i]
if cumm < 0:
ans = min(ans,cumm)
print(-1*ans)
|
You're given an array $a$ of $n$ integers, such that $a_1 + a_2 + \cdots + a_n = 0$.
In one operation, you can choose two different indices $i$ and $j$ ($1 \le i, j \le n$), decrement $a_i$ by one and increment $a_j$ by one. If $i < j$ this operation is free, otherwise it costs one coin.
How many coins do you have to spend in order to make all elements equal to $0$?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 5000$). Description of the test cases follows.
The first line of each test case contains an integer $n$ ($1 \le n \le 10^5$) — the number of elements.
The next line contains $n$ integers $a_1, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$). It is given that $\sum_{i=1}^n a_i = 0$.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $0$.
-----Example-----
Input
7
4
-3 5 -3 1
2
1 -1
4
-3 2 -3 4
4
-1 1 1 -1
7
-5 7 -6 -4 17 -13 4
6
-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000
1
0
Output
3
0
4
1
8
3000000000
0
-----Note-----
Possible strategy for the first test case: Do $(i=2, j=3)$ three times (free), $a = [-3, 2, 0, 1]$. Do $(i=2, j=1)$ two times (pay two coins), $a = [-1, 0, 0, 1]$. Do $(i=4, j=1)$ one time (pay one coin), $a = [0, 0, 0, 0]$.
|
t=int(input())
for t in range(t):
n=int(input())
a=[int(x) for x in input().split(' ')]
b=[0]
for i in range(n):
b.append(b[-1]+a[i])
# print(b)
mn=b[0]
for x in b:
mn=min(mn,x)
print(abs(mn))
|
You're given an array $a$ of $n$ integers, such that $a_1 + a_2 + \cdots + a_n = 0$.
In one operation, you can choose two different indices $i$ and $j$ ($1 \le i, j \le n$), decrement $a_i$ by one and increment $a_j$ by one. If $i < j$ this operation is free, otherwise it costs one coin.
How many coins do you have to spend in order to make all elements equal to $0$?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 5000$). Description of the test cases follows.
The first line of each test case contains an integer $n$ ($1 \le n \le 10^5$) — the number of elements.
The next line contains $n$ integers $a_1, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$). It is given that $\sum_{i=1}^n a_i = 0$.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $0$.
-----Example-----
Input
7
4
-3 5 -3 1
2
1 -1
4
-3 2 -3 4
4
-1 1 1 -1
7
-5 7 -6 -4 17 -13 4
6
-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000
1
0
Output
3
0
4
1
8
3000000000
0
-----Note-----
Possible strategy for the first test case: Do $(i=2, j=3)$ three times (free), $a = [-3, 2, 0, 1]$. Do $(i=2, j=1)$ two times (pay two coins), $a = [-1, 0, 0, 1]$. Do $(i=4, j=1)$ one time (pay one coin), $a = [0, 0, 0, 0]$.
|
for _ in range(int(input())):
n = int(input())
a = list(map(int,input().split()))
cnt = 0
av = 0
for i in range(n):
if a[i]<0:
cr = min(-1*a[i],av)
a[i]+=cr
av-=cr
cnt+=a[i]
a[i]=0
else:
av+=a[i]
print(-1*cnt)
|
You're given an array $a$ of $n$ integers, such that $a_1 + a_2 + \cdots + a_n = 0$.
In one operation, you can choose two different indices $i$ and $j$ ($1 \le i, j \le n$), decrement $a_i$ by one and increment $a_j$ by one. If $i < j$ this operation is free, otherwise it costs one coin.
How many coins do you have to spend in order to make all elements equal to $0$?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 5000$). Description of the test cases follows.
The first line of each test case contains an integer $n$ ($1 \le n \le 10^5$) — the number of elements.
The next line contains $n$ integers $a_1, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$). It is given that $\sum_{i=1}^n a_i = 0$.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $0$.
-----Example-----
Input
7
4
-3 5 -3 1
2
1 -1
4
-3 2 -3 4
4
-1 1 1 -1
7
-5 7 -6 -4 17 -13 4
6
-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000
1
0
Output
3
0
4
1
8
3000000000
0
-----Note-----
Possible strategy for the first test case: Do $(i=2, j=3)$ three times (free), $a = [-3, 2, 0, 1]$. Do $(i=2, j=1)$ two times (pay two coins), $a = [-1, 0, 0, 1]$. Do $(i=4, j=1)$ one time (pay one coin), $a = [0, 0, 0, 0]$.
|
# cook your dish here
# code
# ___________________________________
# | |
# | |
# | _, _ _ ,_ |
# | .-'` / \'-'/ \ `'-. |
# | / | | | | \ |
# | ; \_ _/ \_ _/ ; |
# | | `` `` | |
# | | | |
# | ; .-. .-. .-. .-. ; |
# | \ ( '.' \ / '.' ) / |
# | '-.; V ;.-' |
# | ` ` |
# | |
# |___________________________________|
# | |
# | Author : Ramzz |
# | Created On : 21-07-2020 |
# |___________________________________|
#
# _ __ __ _ _ __ ___ ________
# | '__/ _` | '_ ` _ \|_ /_ /
# | | | (_| | | | | | |/ / / /
# |_| \__,_|_| |_| |_/___/___|
#
import math
import collections
from sys import stdin,stdout,setrecursionlimit
from bisect import bisect_left as bsl
from bisect import bisect_right as bsr
import heapq as hq
setrecursionlimit(2**20)
t = 1
t = int(stdin.readline())
for _ in range(t):
n = int(stdin.readline())
#s = stdin.readline().strip('\n')
a = list(map(int, stdin.readline().rstrip().split()))
ans = 0
s = 0
for i in range(n):
s += a[i]
if(s<0 and abs(s)>ans):
ans = abs(s)
print(ans)
|
You're given an array $a$ of $n$ integers, such that $a_1 + a_2 + \cdots + a_n = 0$.
In one operation, you can choose two different indices $i$ and $j$ ($1 \le i, j \le n$), decrement $a_i$ by one and increment $a_j$ by one. If $i < j$ this operation is free, otherwise it costs one coin.
How many coins do you have to spend in order to make all elements equal to $0$?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 5000$). Description of the test cases follows.
The first line of each test case contains an integer $n$ ($1 \le n \le 10^5$) — the number of elements.
The next line contains $n$ integers $a_1, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$). It is given that $\sum_{i=1}^n a_i = 0$.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $0$.
-----Example-----
Input
7
4
-3 5 -3 1
2
1 -1
4
-3 2 -3 4
4
-1 1 1 -1
7
-5 7 -6 -4 17 -13 4
6
-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000
1
0
Output
3
0
4
1
8
3000000000
0
-----Note-----
Possible strategy for the first test case: Do $(i=2, j=3)$ three times (free), $a = [-3, 2, 0, 1]$. Do $(i=2, j=1)$ two times (pay two coins), $a = [-1, 0, 0, 1]$. Do $(i=4, j=1)$ one time (pay one coin), $a = [0, 0, 0, 0]$.
|
from math import ceil
from collections import deque
for _ in range(int(input())):
n = int(input())
a = [int(i) for i in input().split()]
ans = 0
s = 0
for i in range(n):
if a[i]<s:
ans += s-a[i]
s = 0
else:
s -= a[i]
print(ans)
|
You're given an array $a$ of $n$ integers, such that $a_1 + a_2 + \cdots + a_n = 0$.
In one operation, you can choose two different indices $i$ and $j$ ($1 \le i, j \le n$), decrement $a_i$ by one and increment $a_j$ by one. If $i < j$ this operation is free, otherwise it costs one coin.
How many coins do you have to spend in order to make all elements equal to $0$?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 5000$). Description of the test cases follows.
The first line of each test case contains an integer $n$ ($1 \le n \le 10^5$) — the number of elements.
The next line contains $n$ integers $a_1, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$). It is given that $\sum_{i=1}^n a_i = 0$.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $0$.
-----Example-----
Input
7
4
-3 5 -3 1
2
1 -1
4
-3 2 -3 4
4
-1 1 1 -1
7
-5 7 -6 -4 17 -13 4
6
-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000
1
0
Output
3
0
4
1
8
3000000000
0
-----Note-----
Possible strategy for the first test case: Do $(i=2, j=3)$ three times (free), $a = [-3, 2, 0, 1]$. Do $(i=2, j=1)$ two times (pay two coins), $a = [-1, 0, 0, 1]$. Do $(i=4, j=1)$ one time (pay one coin), $a = [0, 0, 0, 0]$.
|
#Codeforces.com round #668
#Problem B
import sys
#
#BEGIN TEMPLATE
#
def input():
return sys.stdin.readline()[:-1]
def getInt():
#Assumes next line consists of only one integer and returns an integer
return int(input())
def getIntIter():
return list(map(int, input().split()))
def getIntList():
return list(getIntIter())
#
#END TEMPLATE
#
for _ in range(getInt()):
n = getInt()
nums = getIntList()
minSum = 0
currSum = 0
for num in nums:
currSum += num
minSum = min(currSum, minSum)
print(abs(minSum))
|
You're given an array $a$ of $n$ integers, such that $a_1 + a_2 + \cdots + a_n = 0$.
In one operation, you can choose two different indices $i$ and $j$ ($1 \le i, j \le n$), decrement $a_i$ by one and increment $a_j$ by one. If $i < j$ this operation is free, otherwise it costs one coin.
How many coins do you have to spend in order to make all elements equal to $0$?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 5000$). Description of the test cases follows.
The first line of each test case contains an integer $n$ ($1 \le n \le 10^5$) — the number of elements.
The next line contains $n$ integers $a_1, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$). It is given that $\sum_{i=1}^n a_i = 0$.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $0$.
-----Example-----
Input
7
4
-3 5 -3 1
2
1 -1
4
-3 2 -3 4
4
-1 1 1 -1
7
-5 7 -6 -4 17 -13 4
6
-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000
1
0
Output
3
0
4
1
8
3000000000
0
-----Note-----
Possible strategy for the first test case: Do $(i=2, j=3)$ three times (free), $a = [-3, 2, 0, 1]$. Do $(i=2, j=1)$ two times (pay two coins), $a = [-1, 0, 0, 1]$. Do $(i=4, j=1)$ one time (pay one coin), $a = [0, 0, 0, 0]$.
|
for T in range(int(input())) :
n = int(input())
l = list(map(int,input().split()))
bal = 0
ans = 0
for i in l :
if i >= 0 :
bal += i
else :
if abs(i) > bal :
ans += abs(i)-bal
bal = 0
else :
bal += i
print(ans)
|
You're given an array $a$ of $n$ integers, such that $a_1 + a_2 + \cdots + a_n = 0$.
In one operation, you can choose two different indices $i$ and $j$ ($1 \le i, j \le n$), decrement $a_i$ by one and increment $a_j$ by one. If $i < j$ this operation is free, otherwise it costs one coin.
How many coins do you have to spend in order to make all elements equal to $0$?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 5000$). Description of the test cases follows.
The first line of each test case contains an integer $n$ ($1 \le n \le 10^5$) — the number of elements.
The next line contains $n$ integers $a_1, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$). It is given that $\sum_{i=1}^n a_i = 0$.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $0$.
-----Example-----
Input
7
4
-3 5 -3 1
2
1 -1
4
-3 2 -3 4
4
-1 1 1 -1
7
-5 7 -6 -4 17 -13 4
6
-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000
1
0
Output
3
0
4
1
8
3000000000
0
-----Note-----
Possible strategy for the first test case: Do $(i=2, j=3)$ three times (free), $a = [-3, 2, 0, 1]$. Do $(i=2, j=1)$ two times (pay two coins), $a = [-1, 0, 0, 1]$. Do $(i=4, j=1)$ one time (pay one coin), $a = [0, 0, 0, 0]$.
|
import sys
import math
def II():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
def MI():
return list(map(int, sys.stdin.readline().split()))
def SI():
return sys.stdin.readline().strip()
t = II()
for q in range(t):
n = II()
a = LI()
d = [0]*n
s = 0
for i in range(n):
s+=a[i]
d[i] = s
ans = min(d)
if ans>0:
ans = 0
print(-ans)
|
You're given an array $a$ of $n$ integers, such that $a_1 + a_2 + \cdots + a_n = 0$.
In one operation, you can choose two different indices $i$ and $j$ ($1 \le i, j \le n$), decrement $a_i$ by one and increment $a_j$ by one. If $i < j$ this operation is free, otherwise it costs one coin.
How many coins do you have to spend in order to make all elements equal to $0$?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 5000$). Description of the test cases follows.
The first line of each test case contains an integer $n$ ($1 \le n \le 10^5$) — the number of elements.
The next line contains $n$ integers $a_1, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$). It is given that $\sum_{i=1}^n a_i = 0$.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $0$.
-----Example-----
Input
7
4
-3 5 -3 1
2
1 -1
4
-3 2 -3 4
4
-1 1 1 -1
7
-5 7 -6 -4 17 -13 4
6
-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000
1
0
Output
3
0
4
1
8
3000000000
0
-----Note-----
Possible strategy for the first test case: Do $(i=2, j=3)$ three times (free), $a = [-3, 2, 0, 1]$. Do $(i=2, j=1)$ two times (pay two coins), $a = [-1, 0, 0, 1]$. Do $(i=4, j=1)$ one time (pay one coin), $a = [0, 0, 0, 0]$.
|
import math
from collections import deque
from sys import stdin, stdout
from string import ascii_letters
import sys
letters = ascii_letters
input = stdin.readline
#print = stdout.write
for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
need = sum([i for i in arr if i >= 0])
was = 0
have = [0] * n
for i in range(n):
if i != 0:
have[i] = have[i - 1]
if arr[i] > 0:
have[i] += arr[i]
for i in range(n - 1, -1, -1):
if arr[i] < 0:
bf = min(abs(arr[i]), have[i] - was)
was += bf
need -= bf
else:
was = max(0, was - arr[i])
print(need)
|
You're given an array $a$ of $n$ integers, such that $a_1 + a_2 + \cdots + a_n = 0$.
In one operation, you can choose two different indices $i$ and $j$ ($1 \le i, j \le n$), decrement $a_i$ by one and increment $a_j$ by one. If $i < j$ this operation is free, otherwise it costs one coin.
How many coins do you have to spend in order to make all elements equal to $0$?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 5000$). Description of the test cases follows.
The first line of each test case contains an integer $n$ ($1 \le n \le 10^5$) — the number of elements.
The next line contains $n$ integers $a_1, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$). It is given that $\sum_{i=1}^n a_i = 0$.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $0$.
-----Example-----
Input
7
4
-3 5 -3 1
2
1 -1
4
-3 2 -3 4
4
-1 1 1 -1
7
-5 7 -6 -4 17 -13 4
6
-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000
1
0
Output
3
0
4
1
8
3000000000
0
-----Note-----
Possible strategy for the first test case: Do $(i=2, j=3)$ three times (free), $a = [-3, 2, 0, 1]$. Do $(i=2, j=1)$ two times (pay two coins), $a = [-1, 0, 0, 1]$. Do $(i=4, j=1)$ one time (pay one coin), $a = [0, 0, 0, 0]$.
|
t = int(input())
for i in range(t):
n = int(input())
l = list(map(int,input().split()))
h = 0
ans = 0
for j in range(n):
h+=l[j]
if h<0:
ans = max(ans,abs(h))
print(ans)
|
You're given an array $a$ of $n$ integers, such that $a_1 + a_2 + \cdots + a_n = 0$.
In one operation, you can choose two different indices $i$ and $j$ ($1 \le i, j \le n$), decrement $a_i$ by one and increment $a_j$ by one. If $i < j$ this operation is free, otherwise it costs one coin.
How many coins do you have to spend in order to make all elements equal to $0$?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 5000$). Description of the test cases follows.
The first line of each test case contains an integer $n$ ($1 \le n \le 10^5$) — the number of elements.
The next line contains $n$ integers $a_1, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$). It is given that $\sum_{i=1}^n a_i = 0$.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $0$.
-----Example-----
Input
7
4
-3 5 -3 1
2
1 -1
4
-3 2 -3 4
4
-1 1 1 -1
7
-5 7 -6 -4 17 -13 4
6
-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000
1
0
Output
3
0
4
1
8
3000000000
0
-----Note-----
Possible strategy for the first test case: Do $(i=2, j=3)$ three times (free), $a = [-3, 2, 0, 1]$. Do $(i=2, j=1)$ two times (pay two coins), $a = [-1, 0, 0, 1]$. Do $(i=4, j=1)$ one time (pay one coin), $a = [0, 0, 0, 0]$.
|
for __ in range(int(input())):
n = int(input())
ar = list(map(int, input().split()))
ans = 0
a = 0
b = 0
for elem in ar:
if elem < 0:
if b > -elem:
b += elem
a += elem
else:
ans += abs(elem) - b
b = 0
a += abs(elem) - b
else:
b += elem
print(ans)
|
You're given an array $a$ of $n$ integers, such that $a_1 + a_2 + \cdots + a_n = 0$.
In one operation, you can choose two different indices $i$ and $j$ ($1 \le i, j \le n$), decrement $a_i$ by one and increment $a_j$ by one. If $i < j$ this operation is free, otherwise it costs one coin.
How many coins do you have to spend in order to make all elements equal to $0$?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 5000$). Description of the test cases follows.
The first line of each test case contains an integer $n$ ($1 \le n \le 10^5$) — the number of elements.
The next line contains $n$ integers $a_1, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$). It is given that $\sum_{i=1}^n a_i = 0$.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $0$.
-----Example-----
Input
7
4
-3 5 -3 1
2
1 -1
4
-3 2 -3 4
4
-1 1 1 -1
7
-5 7 -6 -4 17 -13 4
6
-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000
1
0
Output
3
0
4
1
8
3000000000
0
-----Note-----
Possible strategy for the first test case: Do $(i=2, j=3)$ three times (free), $a = [-3, 2, 0, 1]$. Do $(i=2, j=1)$ two times (pay two coins), $a = [-1, 0, 0, 1]$. Do $(i=4, j=1)$ one time (pay one coin), $a = [0, 0, 0, 0]$.
|
# Lack of emotion causes lack of progress and lack of motivation. Tony Robbins
for _ in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
s=0
ans=0
for x in a:
s+=x
ans=min(ans,s)
print(-ans)
|
You're given an array $a$ of $n$ integers, such that $a_1 + a_2 + \cdots + a_n = 0$.
In one operation, you can choose two different indices $i$ and $j$ ($1 \le i, j \le n$), decrement $a_i$ by one and increment $a_j$ by one. If $i < j$ this operation is free, otherwise it costs one coin.
How many coins do you have to spend in order to make all elements equal to $0$?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 5000$). Description of the test cases follows.
The first line of each test case contains an integer $n$ ($1 \le n \le 10^5$) — the number of elements.
The next line contains $n$ integers $a_1, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$). It is given that $\sum_{i=1}^n a_i = 0$.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $0$.
-----Example-----
Input
7
4
-3 5 -3 1
2
1 -1
4
-3 2 -3 4
4
-1 1 1 -1
7
-5 7 -6 -4 17 -13 4
6
-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000
1
0
Output
3
0
4
1
8
3000000000
0
-----Note-----
Possible strategy for the first test case: Do $(i=2, j=3)$ three times (free), $a = [-3, 2, 0, 1]$. Do $(i=2, j=1)$ two times (pay two coins), $a = [-1, 0, 0, 1]$. Do $(i=4, j=1)$ one time (pay one coin), $a = [0, 0, 0, 0]$.
|
for _ in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
m=a[0]
s=a[0]
for i in range(1,n):
s+=a[i]
m=min(m,s)
print(max(abs(m),0))
|
You're given an array $a$ of $n$ integers, such that $a_1 + a_2 + \cdots + a_n = 0$.
In one operation, you can choose two different indices $i$ and $j$ ($1 \le i, j \le n$), decrement $a_i$ by one and increment $a_j$ by one. If $i < j$ this operation is free, otherwise it costs one coin.
How many coins do you have to spend in order to make all elements equal to $0$?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 5000$). Description of the test cases follows.
The first line of each test case contains an integer $n$ ($1 \le n \le 10^5$) — the number of elements.
The next line contains $n$ integers $a_1, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$). It is given that $\sum_{i=1}^n a_i = 0$.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $0$.
-----Example-----
Input
7
4
-3 5 -3 1
2
1 -1
4
-3 2 -3 4
4
-1 1 1 -1
7
-5 7 -6 -4 17 -13 4
6
-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000
1
0
Output
3
0
4
1
8
3000000000
0
-----Note-----
Possible strategy for the first test case: Do $(i=2, j=3)$ three times (free), $a = [-3, 2, 0, 1]$. Do $(i=2, j=1)$ two times (pay two coins), $a = [-1, 0, 0, 1]$. Do $(i=4, j=1)$ one time (pay one coin), $a = [0, 0, 0, 0]$.
|
import math
t = int(input())
for q in range(t):
n = int(input())
P = [int(i) for i in input().split()]
c = 0
res = 0
for i in P:
if i > 0:
c += i
elif i < 0:
if i < -1 * c:
res += abs(i + c)
c = 0
else:
c += i
print(res)
|
You're given an array $a$ of $n$ integers, such that $a_1 + a_2 + \cdots + a_n = 0$.
In one operation, you can choose two different indices $i$ and $j$ ($1 \le i, j \le n$), decrement $a_i$ by one and increment $a_j$ by one. If $i < j$ this operation is free, otherwise it costs one coin.
How many coins do you have to spend in order to make all elements equal to $0$?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 5000$). Description of the test cases follows.
The first line of each test case contains an integer $n$ ($1 \le n \le 10^5$) — the number of elements.
The next line contains $n$ integers $a_1, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$). It is given that $\sum_{i=1}^n a_i = 0$.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $0$.
-----Example-----
Input
7
4
-3 5 -3 1
2
1 -1
4
-3 2 -3 4
4
-1 1 1 -1
7
-5 7 -6 -4 17 -13 4
6
-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000
1
0
Output
3
0
4
1
8
3000000000
0
-----Note-----
Possible strategy for the first test case: Do $(i=2, j=3)$ three times (free), $a = [-3, 2, 0, 1]$. Do $(i=2, j=1)$ two times (pay two coins), $a = [-1, 0, 0, 1]$. Do $(i=4, j=1)$ one time (pay one coin), $a = [0, 0, 0, 0]$.
|
for _ in range(int(input())):
n = int(input())
arr = list(map(int,input().split()))
pos = 0
i = 0
while i < n:
if arr[i] < 0:
if pos >= abs(arr[i]):
pos += arr[i]
arr[i] = 0
else:
arr[i] += pos
pos = 0
else:
pos += arr[i]
i += 1
print(pos)
|
You're given an array $a$ of $n$ integers, such that $a_1 + a_2 + \cdots + a_n = 0$.
In one operation, you can choose two different indices $i$ and $j$ ($1 \le i, j \le n$), decrement $a_i$ by one and increment $a_j$ by one. If $i < j$ this operation is free, otherwise it costs one coin.
How many coins do you have to spend in order to make all elements equal to $0$?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 5000$). Description of the test cases follows.
The first line of each test case contains an integer $n$ ($1 \le n \le 10^5$) — the number of elements.
The next line contains $n$ integers $a_1, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$). It is given that $\sum_{i=1}^n a_i = 0$.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $0$.
-----Example-----
Input
7
4
-3 5 -3 1
2
1 -1
4
-3 2 -3 4
4
-1 1 1 -1
7
-5 7 -6 -4 17 -13 4
6
-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000
1
0
Output
3
0
4
1
8
3000000000
0
-----Note-----
Possible strategy for the first test case: Do $(i=2, j=3)$ three times (free), $a = [-3, 2, 0, 1]$. Do $(i=2, j=1)$ two times (pay two coins), $a = [-1, 0, 0, 1]$. Do $(i=4, j=1)$ one time (pay one coin), $a = [0, 0, 0, 0]$.
|
gans = []
for _ in range(int(input())):
n = int(input())
u = list(map(int, input().split()))
cur = 0
ans = 0
for i in range(n):
if u[i] == 0:
continue
if u[i] > 0:
cur += u[i]
else:
u[i] = -u[i]
if cur > u[i]:
cur -= u[i]
else:
ans += u[i] - cur
cur = 0
#print(cur, u[i])
gans.append(ans)
print('\n'.join(map(str, gans)))
|
You're given an array $a$ of $n$ integers, such that $a_1 + a_2 + \cdots + a_n = 0$.
In one operation, you can choose two different indices $i$ and $j$ ($1 \le i, j \le n$), decrement $a_i$ by one and increment $a_j$ by one. If $i < j$ this operation is free, otherwise it costs one coin.
How many coins do you have to spend in order to make all elements equal to $0$?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 5000$). Description of the test cases follows.
The first line of each test case contains an integer $n$ ($1 \le n \le 10^5$) — the number of elements.
The next line contains $n$ integers $a_1, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$). It is given that $\sum_{i=1}^n a_i = 0$.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $0$.
-----Example-----
Input
7
4
-3 5 -3 1
2
1 -1
4
-3 2 -3 4
4
-1 1 1 -1
7
-5 7 -6 -4 17 -13 4
6
-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000
1
0
Output
3
0
4
1
8
3000000000
0
-----Note-----
Possible strategy for the first test case: Do $(i=2, j=3)$ three times (free), $a = [-3, 2, 0, 1]$. Do $(i=2, j=1)$ two times (pay two coins), $a = [-1, 0, 0, 1]$. Do $(i=4, j=1)$ one time (pay one coin), $a = [0, 0, 0, 0]$.
|
from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush,heappop,heapify
import math
from collections import *
from functools import reduce,cmp_to_key
import sys
input = sys.stdin.readline
from itertools import accumulate
from functools import lru_cache
M = mod = 998244353
def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))
def inv_mod(n):return pow(n, mod - 2, mod)
def li():return [int(i) for i in input().rstrip('\n').split()]
def st():return input().rstrip('\n')
def val():return int(input().rstrip('\n'))
def li2():return [i for i in input().rstrip('\n')]
def li3():return [int(i) for i in input().rstrip('\n')]
for _ in range(val()):
n = val()
l = li()
ans = curr = 0
for i in l:
if i >= 0:
curr += i
continue
else:
temp = min(curr, abs(i))
curr -= temp
if abs(i) > temp:
ans += abs(i) - temp
print(ans)
|
You're given an array $a$ of $n$ integers, such that $a_1 + a_2 + \cdots + a_n = 0$.
In one operation, you can choose two different indices $i$ and $j$ ($1 \le i, j \le n$), decrement $a_i$ by one and increment $a_j$ by one. If $i < j$ this operation is free, otherwise it costs one coin.
How many coins do you have to spend in order to make all elements equal to $0$?
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 5000$). Description of the test cases follows.
The first line of each test case contains an integer $n$ ($1 \le n \le 10^5$) — the number of elements.
The next line contains $n$ integers $a_1, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$). It is given that $\sum_{i=1}^n a_i = 0$.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case, print the minimum number of coins we have to spend in order to make all elements equal to $0$.
-----Example-----
Input
7
4
-3 5 -3 1
2
1 -1
4
-3 2 -3 4
4
-1 1 1 -1
7
-5 7 -6 -4 17 -13 4
6
-1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000
1
0
Output
3
0
4
1
8
3000000000
0
-----Note-----
Possible strategy for the first test case: Do $(i=2, j=3)$ three times (free), $a = [-3, 2, 0, 1]$. Do $(i=2, j=1)$ two times (pay two coins), $a = [-1, 0, 0, 1]$. Do $(i=4, j=1)$ one time (pay one coin), $a = [0, 0, 0, 0]$.
|
"""T=int(input())
for _ in range(0,T):
n=int(input())
a,b=map(int,input().split())
s=input()
s=[int(x) for x in input().split()]
for i in range(0,len(s)):
a,b=map(int,input().split())"""
T=int(input())
for _ in range(0,T):
n=int(input())
s=[int(x) for x in input().split()]
nrem = 0
ans=0
for i in range(len(s)-1,-1,-1):
if(s[i]>0):
tt=min(nrem,s[i])
s[i]-=tt
ans+=s[i]
nrem-=tt
else:
nrem+=abs(s[i])
print(ans)
|
Phoenix loves beautiful arrays. An array is beautiful if all its subarrays of length $k$ have the same sum. A subarray of an array is any sequence of consecutive elements.
Phoenix currently has an array $a$ of length $n$. He wants to insert some number of integers, possibly zero, into his array such that it becomes beautiful. The inserted integers must be between $1$ and $n$ inclusive. Integers may be inserted anywhere (even before the first or after the last element), and he is not trying to minimize the number of inserted integers.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 50$) — the number of test cases.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 100$).
The second line of each test case contains $n$ space-separated integers ($1 \le a_i \le n$) — the array that Phoenix currently has. This array may or may not be already beautiful.
-----Output-----
For each test case, if it is impossible to create a beautiful array, print -1. Otherwise, print two lines.
The first line should contain the length of the beautiful array $m$ ($n \le m \le 10^4$). You don't need to minimize $m$.
The second line should contain $m$ space-separated integers ($1 \le b_i \le n$) — a beautiful array that Phoenix can obtain after inserting some, possibly zero, integers into his array $a$. You may print integers that weren't originally in array $a$.
If there are multiple solutions, print any. It's guaranteed that if we can make array $a$ beautiful, we can always make it with resulting length no more than $10^4$.
-----Example-----
Input
4
4 2
1 2 2 1
4 3
1 2 2 1
3 2
1 2 3
4 4
4 3 4 2
Output
5
1 2 1 2 1
4
1 2 2 1
-1
7
4 3 2 1 4 3 2
-----Note-----
In the first test case, we can make array $a$ beautiful by inserting the integer $1$ at index $3$ (in between the two existing $2$s). Now, all subarrays of length $k=2$ have the same sum $3$. There exists many other possible solutions, for example: $2, 1, 2, 1, 2, 1$ $1, 2, 1, 2, 1, 2$
In the second test case, the array is already beautiful: all subarrays of length $k=3$ have the same sum $5$.
In the third test case, it can be shown that we cannot insert numbers to make array $a$ beautiful.
In the fourth test case, the array $b$ shown is beautiful and all subarrays of length $k=4$ have the same sum $10$. There exist other solutions also.
|
t = int(input())
for _ in range(t):
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
if len(set(a)) > k:
print(-1)
continue
l = list(set(a))
l.extend([1]*(k - len(l)))
print(n*k)
for _ in range(n):
print(*l, end=" ")
print()
|
Phoenix loves beautiful arrays. An array is beautiful if all its subarrays of length $k$ have the same sum. A subarray of an array is any sequence of consecutive elements.
Phoenix currently has an array $a$ of length $n$. He wants to insert some number of integers, possibly zero, into his array such that it becomes beautiful. The inserted integers must be between $1$ and $n$ inclusive. Integers may be inserted anywhere (even before the first or after the last element), and he is not trying to minimize the number of inserted integers.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 50$) — the number of test cases.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 100$).
The second line of each test case contains $n$ space-separated integers ($1 \le a_i \le n$) — the array that Phoenix currently has. This array may or may not be already beautiful.
-----Output-----
For each test case, if it is impossible to create a beautiful array, print -1. Otherwise, print two lines.
The first line should contain the length of the beautiful array $m$ ($n \le m \le 10^4$). You don't need to minimize $m$.
The second line should contain $m$ space-separated integers ($1 \le b_i \le n$) — a beautiful array that Phoenix can obtain after inserting some, possibly zero, integers into his array $a$. You may print integers that weren't originally in array $a$.
If there are multiple solutions, print any. It's guaranteed that if we can make array $a$ beautiful, we can always make it with resulting length no more than $10^4$.
-----Example-----
Input
4
4 2
1 2 2 1
4 3
1 2 2 1
3 2
1 2 3
4 4
4 3 4 2
Output
5
1 2 1 2 1
4
1 2 2 1
-1
7
4 3 2 1 4 3 2
-----Note-----
In the first test case, we can make array $a$ beautiful by inserting the integer $1$ at index $3$ (in between the two existing $2$s). Now, all subarrays of length $k=2$ have the same sum $3$. There exists many other possible solutions, for example: $2, 1, 2, 1, 2, 1$ $1, 2, 1, 2, 1, 2$
In the second test case, the array is already beautiful: all subarrays of length $k=3$ have the same sum $5$.
In the third test case, it can be shown that we cannot insert numbers to make array $a$ beautiful.
In the fourth test case, the array $b$ shown is beautiful and all subarrays of length $k=4$ have the same sum $10$. There exist other solutions also.
|
for i in range(int(input())):
n, k=(int(j) for j in input().split())
a=[int(j) for j in input().split()]
mm=set(a)
if(len(mm)>k):
print("-1", end=" ")
else:
if(len(mm)<k):
for j in range(1, 101):
if(j not in mm):
mm.add(j)
if(len(mm)==k):
break
print(n*len(mm))
for j in range(n):
print(" ".join(str(x) for x in mm), end=" ")
print()
|
Phoenix loves beautiful arrays. An array is beautiful if all its subarrays of length $k$ have the same sum. A subarray of an array is any sequence of consecutive elements.
Phoenix currently has an array $a$ of length $n$. He wants to insert some number of integers, possibly zero, into his array such that it becomes beautiful. The inserted integers must be between $1$ and $n$ inclusive. Integers may be inserted anywhere (even before the first or after the last element), and he is not trying to minimize the number of inserted integers.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 50$) — the number of test cases.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 100$).
The second line of each test case contains $n$ space-separated integers ($1 \le a_i \le n$) — the array that Phoenix currently has. This array may or may not be already beautiful.
-----Output-----
For each test case, if it is impossible to create a beautiful array, print -1. Otherwise, print two lines.
The first line should contain the length of the beautiful array $m$ ($n \le m \le 10^4$). You don't need to minimize $m$.
The second line should contain $m$ space-separated integers ($1 \le b_i \le n$) — a beautiful array that Phoenix can obtain after inserting some, possibly zero, integers into his array $a$. You may print integers that weren't originally in array $a$.
If there are multiple solutions, print any. It's guaranteed that if we can make array $a$ beautiful, we can always make it with resulting length no more than $10^4$.
-----Example-----
Input
4
4 2
1 2 2 1
4 3
1 2 2 1
3 2
1 2 3
4 4
4 3 4 2
Output
5
1 2 1 2 1
4
1 2 2 1
-1
7
4 3 2 1 4 3 2
-----Note-----
In the first test case, we can make array $a$ beautiful by inserting the integer $1$ at index $3$ (in between the two existing $2$s). Now, all subarrays of length $k=2$ have the same sum $3$. There exists many other possible solutions, for example: $2, 1, 2, 1, 2, 1$ $1, 2, 1, 2, 1, 2$
In the second test case, the array is already beautiful: all subarrays of length $k=3$ have the same sum $5$.
In the third test case, it can be shown that we cannot insert numbers to make array $a$ beautiful.
In the fourth test case, the array $b$ shown is beautiful and all subarrays of length $k=4$ have the same sum $10$. There exist other solutions also.
|
import sys
stdin = sys.stdin
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: list(map(int, stdin.readline().split()))
nl = lambda: list(map(int, stdin.readline().split()))
def solve():
n, k = nm()
a = nl()
if k < len(set(a)):
print(-1)
return
f = list(set(a))
f += [1]*(k-len(f))
f *= n
print(len(f))
print(*f)
return
t = ni()
for _ in range(t):
solve()
|
Phoenix loves beautiful arrays. An array is beautiful if all its subarrays of length $k$ have the same sum. A subarray of an array is any sequence of consecutive elements.
Phoenix currently has an array $a$ of length $n$. He wants to insert some number of integers, possibly zero, into his array such that it becomes beautiful. The inserted integers must be between $1$ and $n$ inclusive. Integers may be inserted anywhere (even before the first or after the last element), and he is not trying to minimize the number of inserted integers.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 50$) — the number of test cases.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 100$).
The second line of each test case contains $n$ space-separated integers ($1 \le a_i \le n$) — the array that Phoenix currently has. This array may or may not be already beautiful.
-----Output-----
For each test case, if it is impossible to create a beautiful array, print -1. Otherwise, print two lines.
The first line should contain the length of the beautiful array $m$ ($n \le m \le 10^4$). You don't need to minimize $m$.
The second line should contain $m$ space-separated integers ($1 \le b_i \le n$) — a beautiful array that Phoenix can obtain after inserting some, possibly zero, integers into his array $a$. You may print integers that weren't originally in array $a$.
If there are multiple solutions, print any. It's guaranteed that if we can make array $a$ beautiful, we can always make it with resulting length no more than $10^4$.
-----Example-----
Input
4
4 2
1 2 2 1
4 3
1 2 2 1
3 2
1 2 3
4 4
4 3 4 2
Output
5
1 2 1 2 1
4
1 2 2 1
-1
7
4 3 2 1 4 3 2
-----Note-----
In the first test case, we can make array $a$ beautiful by inserting the integer $1$ at index $3$ (in between the two existing $2$s). Now, all subarrays of length $k=2$ have the same sum $3$. There exists many other possible solutions, for example: $2, 1, 2, 1, 2, 1$ $1, 2, 1, 2, 1, 2$
In the second test case, the array is already beautiful: all subarrays of length $k=3$ have the same sum $5$.
In the third test case, it can be shown that we cannot insert numbers to make array $a$ beautiful.
In the fourth test case, the array $b$ shown is beautiful and all subarrays of length $k=4$ have the same sum $10$. There exist other solutions also.
|
for _ in range(int(input())):
n, k = list(map(int, input().split()))
arr = list(map(int, input().split()))
if len(set(arr)) > k:
print(-1)
else:
result = []
temp = list(set(arr))
for i in range(1, n + 1):
if len(temp) == k:
break
if i not in temp:
temp.append(i)
for i in range(len(arr)):
result.extend(temp)
print(len(result))
print(*result)
|
Phoenix loves beautiful arrays. An array is beautiful if all its subarrays of length $k$ have the same sum. A subarray of an array is any sequence of consecutive elements.
Phoenix currently has an array $a$ of length $n$. He wants to insert some number of integers, possibly zero, into his array such that it becomes beautiful. The inserted integers must be between $1$ and $n$ inclusive. Integers may be inserted anywhere (even before the first or after the last element), and he is not trying to minimize the number of inserted integers.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 50$) — the number of test cases.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 100$).
The second line of each test case contains $n$ space-separated integers ($1 \le a_i \le n$) — the array that Phoenix currently has. This array may or may not be already beautiful.
-----Output-----
For each test case, if it is impossible to create a beautiful array, print -1. Otherwise, print two lines.
The first line should contain the length of the beautiful array $m$ ($n \le m \le 10^4$). You don't need to minimize $m$.
The second line should contain $m$ space-separated integers ($1 \le b_i \le n$) — a beautiful array that Phoenix can obtain after inserting some, possibly zero, integers into his array $a$. You may print integers that weren't originally in array $a$.
If there are multiple solutions, print any. It's guaranteed that if we can make array $a$ beautiful, we can always make it with resulting length no more than $10^4$.
-----Example-----
Input
4
4 2
1 2 2 1
4 3
1 2 2 1
3 2
1 2 3
4 4
4 3 4 2
Output
5
1 2 1 2 1
4
1 2 2 1
-1
7
4 3 2 1 4 3 2
-----Note-----
In the first test case, we can make array $a$ beautiful by inserting the integer $1$ at index $3$ (in between the two existing $2$s). Now, all subarrays of length $k=2$ have the same sum $3$. There exists many other possible solutions, for example: $2, 1, 2, 1, 2, 1$ $1, 2, 1, 2, 1, 2$
In the second test case, the array is already beautiful: all subarrays of length $k=3$ have the same sum $5$.
In the third test case, it can be shown that we cannot insert numbers to make array $a$ beautiful.
In the fourth test case, the array $b$ shown is beautiful and all subarrays of length $k=4$ have the same sum $10$. There exist other solutions also.
|
import collections
t=int(input())
for _ in range(t):
n,k=map(int,input().split())
arr=list(map(int,input().split()))
if len(collections.Counter(arr))>k:
print(-1)
else:
cand=list(collections.Counter(arr).keys())
cnt=len(cand)
for i in range(1,n+1):
if cnt>=k:
break
else:
if i not in cand:
cand.append(i)
cnt+=1
print(cnt*n)
print(*(cand*n))
|
Phoenix loves beautiful arrays. An array is beautiful if all its subarrays of length $k$ have the same sum. A subarray of an array is any sequence of consecutive elements.
Phoenix currently has an array $a$ of length $n$. He wants to insert some number of integers, possibly zero, into his array such that it becomes beautiful. The inserted integers must be between $1$ and $n$ inclusive. Integers may be inserted anywhere (even before the first or after the last element), and he is not trying to minimize the number of inserted integers.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 50$) — the number of test cases.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 100$).
The second line of each test case contains $n$ space-separated integers ($1 \le a_i \le n$) — the array that Phoenix currently has. This array may or may not be already beautiful.
-----Output-----
For each test case, if it is impossible to create a beautiful array, print -1. Otherwise, print two lines.
The first line should contain the length of the beautiful array $m$ ($n \le m \le 10^4$). You don't need to minimize $m$.
The second line should contain $m$ space-separated integers ($1 \le b_i \le n$) — a beautiful array that Phoenix can obtain after inserting some, possibly zero, integers into his array $a$. You may print integers that weren't originally in array $a$.
If there are multiple solutions, print any. It's guaranteed that if we can make array $a$ beautiful, we can always make it with resulting length no more than $10^4$.
-----Example-----
Input
4
4 2
1 2 2 1
4 3
1 2 2 1
3 2
1 2 3
4 4
4 3 4 2
Output
5
1 2 1 2 1
4
1 2 2 1
-1
7
4 3 2 1 4 3 2
-----Note-----
In the first test case, we can make array $a$ beautiful by inserting the integer $1$ at index $3$ (in between the two existing $2$s). Now, all subarrays of length $k=2$ have the same sum $3$. There exists many other possible solutions, for example: $2, 1, 2, 1, 2, 1$ $1, 2, 1, 2, 1, 2$
In the second test case, the array is already beautiful: all subarrays of length $k=3$ have the same sum $5$.
In the third test case, it can be shown that we cannot insert numbers to make array $a$ beautiful.
In the fourth test case, the array $b$ shown is beautiful and all subarrays of length $k=4$ have the same sum $10$. There exist other solutions also.
|
from collections import Counter
def read_int():
return int(input())
def read_ints():
return map(int, input().split(' '))
t = read_int()
for case_num in range(t):
n, k = read_ints()
a = list(read_ints())
cnt = Counter(a)
distinct = len(cnt)
if distinct > k:
print(-1)
else:
print(n * k)
s = set(cnt)
for i in range(1, n + 1):
if len(s) < k and not i in s:
s.add(i)
ans = list(s) * n
print(' '.join(map(str, ans)))
|
Phoenix loves beautiful arrays. An array is beautiful if all its subarrays of length $k$ have the same sum. A subarray of an array is any sequence of consecutive elements.
Phoenix currently has an array $a$ of length $n$. He wants to insert some number of integers, possibly zero, into his array such that it becomes beautiful. The inserted integers must be between $1$ and $n$ inclusive. Integers may be inserted anywhere (even before the first or after the last element), and he is not trying to minimize the number of inserted integers.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 50$) — the number of test cases.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 100$).
The second line of each test case contains $n$ space-separated integers ($1 \le a_i \le n$) — the array that Phoenix currently has. This array may or may not be already beautiful.
-----Output-----
For each test case, if it is impossible to create a beautiful array, print -1. Otherwise, print two lines.
The first line should contain the length of the beautiful array $m$ ($n \le m \le 10^4$). You don't need to minimize $m$.
The second line should contain $m$ space-separated integers ($1 \le b_i \le n$) — a beautiful array that Phoenix can obtain after inserting some, possibly zero, integers into his array $a$. You may print integers that weren't originally in array $a$.
If there are multiple solutions, print any. It's guaranteed that if we can make array $a$ beautiful, we can always make it with resulting length no more than $10^4$.
-----Example-----
Input
4
4 2
1 2 2 1
4 3
1 2 2 1
3 2
1 2 3
4 4
4 3 4 2
Output
5
1 2 1 2 1
4
1 2 2 1
-1
7
4 3 2 1 4 3 2
-----Note-----
In the first test case, we can make array $a$ beautiful by inserting the integer $1$ at index $3$ (in between the two existing $2$s). Now, all subarrays of length $k=2$ have the same sum $3$. There exists many other possible solutions, for example: $2, 1, 2, 1, 2, 1$ $1, 2, 1, 2, 1, 2$
In the second test case, the array is already beautiful: all subarrays of length $k=3$ have the same sum $5$.
In the third test case, it can be shown that we cannot insert numbers to make array $a$ beautiful.
In the fourth test case, the array $b$ shown is beautiful and all subarrays of length $k=4$ have the same sum $10$. There exist other solutions also.
|
import sys
readline = sys.stdin.readline
T = int(readline())
Ans = []
for qu in range(T):
N, K = map(int, readline().split())
A = list(map(int, readline().split()))
SA = set(A)
if len(SA) <= K:
res = list(SA)
for i in range(1, N+1):
if len(res) == K:
break
if i not in SA:
res.append(i)
Ans.append(str(N*K))
Ans.append(' '.join(map(str, res*N)))
else:
Ans.append('-1')
print('\n'.join(map(str, Ans)))
|
Phoenix loves beautiful arrays. An array is beautiful if all its subarrays of length $k$ have the same sum. A subarray of an array is any sequence of consecutive elements.
Phoenix currently has an array $a$ of length $n$. He wants to insert some number of integers, possibly zero, into his array such that it becomes beautiful. The inserted integers must be between $1$ and $n$ inclusive. Integers may be inserted anywhere (even before the first or after the last element), and he is not trying to minimize the number of inserted integers.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 50$) — the number of test cases.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 100$).
The second line of each test case contains $n$ space-separated integers ($1 \le a_i \le n$) — the array that Phoenix currently has. This array may or may not be already beautiful.
-----Output-----
For each test case, if it is impossible to create a beautiful array, print -1. Otherwise, print two lines.
The first line should contain the length of the beautiful array $m$ ($n \le m \le 10^4$). You don't need to minimize $m$.
The second line should contain $m$ space-separated integers ($1 \le b_i \le n$) — a beautiful array that Phoenix can obtain after inserting some, possibly zero, integers into his array $a$. You may print integers that weren't originally in array $a$.
If there are multiple solutions, print any. It's guaranteed that if we can make array $a$ beautiful, we can always make it with resulting length no more than $10^4$.
-----Example-----
Input
4
4 2
1 2 2 1
4 3
1 2 2 1
3 2
1 2 3
4 4
4 3 4 2
Output
5
1 2 1 2 1
4
1 2 2 1
-1
7
4 3 2 1 4 3 2
-----Note-----
In the first test case, we can make array $a$ beautiful by inserting the integer $1$ at index $3$ (in between the two existing $2$s). Now, all subarrays of length $k=2$ have the same sum $3$. There exists many other possible solutions, for example: $2, 1, 2, 1, 2, 1$ $1, 2, 1, 2, 1, 2$
In the second test case, the array is already beautiful: all subarrays of length $k=3$ have the same sum $5$.
In the third test case, it can be shown that we cannot insert numbers to make array $a$ beautiful.
In the fourth test case, the array $b$ shown is beautiful and all subarrays of length $k=4$ have the same sum $10$. There exist other solutions also.
|
import sys
input = sys.stdin.readline
for _ in range(int(input())):
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
if len(set(a)) > k:
print(-1)
continue
a = list(set(a))
a += [1] * (k - len(a))
print(k * n)
print(*(a * n))
|
Phoenix loves beautiful arrays. An array is beautiful if all its subarrays of length $k$ have the same sum. A subarray of an array is any sequence of consecutive elements.
Phoenix currently has an array $a$ of length $n$. He wants to insert some number of integers, possibly zero, into his array such that it becomes beautiful. The inserted integers must be between $1$ and $n$ inclusive. Integers may be inserted anywhere (even before the first or after the last element), and he is not trying to minimize the number of inserted integers.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 50$) — the number of test cases.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 100$).
The second line of each test case contains $n$ space-separated integers ($1 \le a_i \le n$) — the array that Phoenix currently has. This array may or may not be already beautiful.
-----Output-----
For each test case, if it is impossible to create a beautiful array, print -1. Otherwise, print two lines.
The first line should contain the length of the beautiful array $m$ ($n \le m \le 10^4$). You don't need to minimize $m$.
The second line should contain $m$ space-separated integers ($1 \le b_i \le n$) — a beautiful array that Phoenix can obtain after inserting some, possibly zero, integers into his array $a$. You may print integers that weren't originally in array $a$.
If there are multiple solutions, print any. It's guaranteed that if we can make array $a$ beautiful, we can always make it with resulting length no more than $10^4$.
-----Example-----
Input
4
4 2
1 2 2 1
4 3
1 2 2 1
3 2
1 2 3
4 4
4 3 4 2
Output
5
1 2 1 2 1
4
1 2 2 1
-1
7
4 3 2 1 4 3 2
-----Note-----
In the first test case, we can make array $a$ beautiful by inserting the integer $1$ at index $3$ (in between the two existing $2$s). Now, all subarrays of length $k=2$ have the same sum $3$. There exists many other possible solutions, for example: $2, 1, 2, 1, 2, 1$ $1, 2, 1, 2, 1, 2$
In the second test case, the array is already beautiful: all subarrays of length $k=3$ have the same sum $5$.
In the third test case, it can be shown that we cannot insert numbers to make array $a$ beautiful.
In the fourth test case, the array $b$ shown is beautiful and all subarrays of length $k=4$ have the same sum $10$. There exist other solutions also.
|
def Solve(nCase):
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
l = list(set(a))
p = len(l)
if p > k:
print(-1)
return
for i in range(k - p):
l.append(a[0])
ans = n * l
print(len(ans))
print(' '.join(str(x) for x in ans))
T = int(input())
for i in range(1, T + 1):
Solve(i)
|
Phoenix loves beautiful arrays. An array is beautiful if all its subarrays of length $k$ have the same sum. A subarray of an array is any sequence of consecutive elements.
Phoenix currently has an array $a$ of length $n$. He wants to insert some number of integers, possibly zero, into his array such that it becomes beautiful. The inserted integers must be between $1$ and $n$ inclusive. Integers may be inserted anywhere (even before the first or after the last element), and he is not trying to minimize the number of inserted integers.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 50$) — the number of test cases.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 100$).
The second line of each test case contains $n$ space-separated integers ($1 \le a_i \le n$) — the array that Phoenix currently has. This array may or may not be already beautiful.
-----Output-----
For each test case, if it is impossible to create a beautiful array, print -1. Otherwise, print two lines.
The first line should contain the length of the beautiful array $m$ ($n \le m \le 10^4$). You don't need to minimize $m$.
The second line should contain $m$ space-separated integers ($1 \le b_i \le n$) — a beautiful array that Phoenix can obtain after inserting some, possibly zero, integers into his array $a$. You may print integers that weren't originally in array $a$.
If there are multiple solutions, print any. It's guaranteed that if we can make array $a$ beautiful, we can always make it with resulting length no more than $10^4$.
-----Example-----
Input
4
4 2
1 2 2 1
4 3
1 2 2 1
3 2
1 2 3
4 4
4 3 4 2
Output
5
1 2 1 2 1
4
1 2 2 1
-1
7
4 3 2 1 4 3 2
-----Note-----
In the first test case, we can make array $a$ beautiful by inserting the integer $1$ at index $3$ (in between the two existing $2$s). Now, all subarrays of length $k=2$ have the same sum $3$. There exists many other possible solutions, for example: $2, 1, 2, 1, 2, 1$ $1, 2, 1, 2, 1, 2$
In the second test case, the array is already beautiful: all subarrays of length $k=3$ have the same sum $5$.
In the third test case, it can be shown that we cannot insert numbers to make array $a$ beautiful.
In the fourth test case, the array $b$ shown is beautiful and all subarrays of length $k=4$ have the same sum $10$. There exist other solutions also.
|
def beauty(n, k, array):
s = set(array)
if len(s) > k:
print(-1)
return
L = list(s)
L.extend([array[0]] * (k - len(s)))
L *= n
print(len(L))
print(*L)
t = int(input())
for i in range(t):
n, k = list(map(int, input().split()))
array = list(map(int, input().split()))
beauty(n, k, array)
|
Phoenix loves beautiful arrays. An array is beautiful if all its subarrays of length $k$ have the same sum. A subarray of an array is any sequence of consecutive elements.
Phoenix currently has an array $a$ of length $n$. He wants to insert some number of integers, possibly zero, into his array such that it becomes beautiful. The inserted integers must be between $1$ and $n$ inclusive. Integers may be inserted anywhere (even before the first or after the last element), and he is not trying to minimize the number of inserted integers.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 50$) — the number of test cases.
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 100$).
The second line of each test case contains $n$ space-separated integers ($1 \le a_i \le n$) — the array that Phoenix currently has. This array may or may not be already beautiful.
-----Output-----
For each test case, if it is impossible to create a beautiful array, print -1. Otherwise, print two lines.
The first line should contain the length of the beautiful array $m$ ($n \le m \le 10^4$). You don't need to minimize $m$.
The second line should contain $m$ space-separated integers ($1 \le b_i \le n$) — a beautiful array that Phoenix can obtain after inserting some, possibly zero, integers into his array $a$. You may print integers that weren't originally in array $a$.
If there are multiple solutions, print any. It's guaranteed that if we can make array $a$ beautiful, we can always make it with resulting length no more than $10^4$.
-----Example-----
Input
4
4 2
1 2 2 1
4 3
1 2 2 1
3 2
1 2 3
4 4
4 3 4 2
Output
5
1 2 1 2 1
4
1 2 2 1
-1
7
4 3 2 1 4 3 2
-----Note-----
In the first test case, we can make array $a$ beautiful by inserting the integer $1$ at index $3$ (in between the two existing $2$s). Now, all subarrays of length $k=2$ have the same sum $3$. There exists many other possible solutions, for example: $2, 1, 2, 1, 2, 1$ $1, 2, 1, 2, 1, 2$
In the second test case, the array is already beautiful: all subarrays of length $k=3$ have the same sum $5$.
In the third test case, it can be shown that we cannot insert numbers to make array $a$ beautiful.
In the fourth test case, the array $b$ shown is beautiful and all subarrays of length $k=4$ have the same sum $10$. There exist other solutions also.
|
q = int(input())
for _ in range(q):
n,k = map(int,input().split())
l = list(map(int,input().split()))
#szukamy tak zeby okres byl k-1
if k==1:
if max(l) == min(l):
print(len(l))
print(*l)
else:
print(-1)
else:
cyk = set()
for i in l:
cyk.add(i)
if len(cyk) > k:
dasie = 0
else:
dasie = 1
if dasie == 0:
print(-1)
else:
a = list(cyk)
while len(a) != k:
a.append(l[0])
odp = n*a
print(len(odp))
print(*odp)
|
You're given an array of $n$ integers between $0$ and $n$ inclusive.
In one operation, you can choose any element of the array and replace it by the MEX of the elements of the array (which may change after the operation).
For example, if the current array is $[0, 2, 2, 1, 4]$, you can choose the second element and replace it by the MEX of the present elements — $3$. Array will become $[0, 3, 2, 1, 4]$.
You must make the array non-decreasing, using at most $2n$ operations.
It can be proven that it is always possible. Please note that you do not have to minimize the number of operations. If there are many solutions, you can print any of them.
–
An array $b[1 \ldots n]$ is non-decreasing if and only if $b_1 \le b_2 \le \ldots \le b_n$.
The MEX (minimum excluded) of an array is the smallest non-negative integer that does not belong to the array. For instance: The MEX of $[2, 2, 1]$ is $0$, because $0$ does not belong to the array. The MEX of $[3, 1, 0, 1]$ is $2$, because $0$ and $1$ belong to the array, but $2$ does not. The MEX of $[0, 3, 1, 2]$ is $4$ because $0$, $1$, $2$ and $3$ belong to the array, but $4$ does not.
It's worth mentioning that the MEX of an array of length $n$ is always between $0$ and $n$ inclusive.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 200$) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer $n$ ($3 \le n \le 1000$) — length of the array.
The second line of each test case contains $n$ integers $a_1, \ldots, a_n$ ($0 \le a_i \le n$) — elements of the array. Note that they don't have to be distinct.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $1000$.
-----Output-----
For each test case, you must output two lines:
The first line must contain a single integer $k$ ($0 \le k \le 2n$) — the number of operations you perform.
The second line must contain $k$ integers $x_1, \ldots, x_k$ ($1 \le x_i \le n$), where $x_i$ is the index chosen for the $i$-th operation.
If there are many solutions, you can find any of them. Please remember that it is not required to minimize $k$.
-----Example-----
Input
5
3
2 2 3
3
2 1 0
7
0 7 3 1 3 7 7
9
2 0 1 1 2 4 4 2 0
9
8 4 7 6 1 2 3 0 5
Output
0
2
3 1
4
2 5 5 4
11
3 8 9 7 8 5 9 6 4 1 2
10
1 8 1 9 5 2 4 6 3 7
-----Note-----
In the first test case, the array is already non-decreasing ($2 \le 2 \le 3$).
Explanation of the second test case (the element modified by each operation is colored in red): $a = [2, 1, 0]$ ; the initial MEX is $3$. $a = [2, 1, \color{red}{3}]$ ; the new MEX is $0$. $a = [\color{red}{0}, 1, 3]$ ; the new MEX is $2$. The final array is non-decreasing: $0 \le 1 \le 3$.
Explanation of the third test case: $a = [0, 7, 3, 1, 3, 7, 7]$ ; the initial MEX is $2$. $a = [0, \color{red}{2}, 3, 1, 3, 7, 7]$ ; the new MEX is $4$. $a = [0, 2, 3, 1, \color{red}{4}, 7, 7]$ ; the new MEX is $5$. $a = [0, 2, 3, 1, \color{red}{5}, 7, 7]$ ; the new MEX is $4$. $a = [0, 2, 3, \color{red}{4}, 5, 7, 7]$ ; the new MEX is $1$. The final array is non-decreasing: $0 \le 2 \le 3 \le 4 \le 5 \le 7 \le 7$.
|
def solve():
n = int(input())
a = list(map(int, input().split()))
c = [0] * (n + 1)
def inc():
for i in range(n - 1):
if a[i] > a[i + 1]:
return False
return True
def calc():
for i in range(n + 1):
c[i] = 0
for i in a:
c[i] += 1
for i in range(n + 1):
if not c[i]:
return i
return n + 1
ans = []
while not inc():
x = calc()
if x >= n:
y = 0
while y < n and a[y] == y:
y += 1
a[y] = x
ans.append(y)
else:
a[x] = x
ans.append(x)
print(len(ans))
print(*map(lambda x: x + 1, ans))
t = int(input())
for _ in range(t):
solve()
|
You're given an array of $n$ integers between $0$ and $n$ inclusive.
In one operation, you can choose any element of the array and replace it by the MEX of the elements of the array (which may change after the operation).
For example, if the current array is $[0, 2, 2, 1, 4]$, you can choose the second element and replace it by the MEX of the present elements — $3$. Array will become $[0, 3, 2, 1, 4]$.
You must make the array non-decreasing, using at most $2n$ operations.
It can be proven that it is always possible. Please note that you do not have to minimize the number of operations. If there are many solutions, you can print any of them.
–
An array $b[1 \ldots n]$ is non-decreasing if and only if $b_1 \le b_2 \le \ldots \le b_n$.
The MEX (minimum excluded) of an array is the smallest non-negative integer that does not belong to the array. For instance: The MEX of $[2, 2, 1]$ is $0$, because $0$ does not belong to the array. The MEX of $[3, 1, 0, 1]$ is $2$, because $0$ and $1$ belong to the array, but $2$ does not. The MEX of $[0, 3, 1, 2]$ is $4$ because $0$, $1$, $2$ and $3$ belong to the array, but $4$ does not.
It's worth mentioning that the MEX of an array of length $n$ is always between $0$ and $n$ inclusive.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 200$) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer $n$ ($3 \le n \le 1000$) — length of the array.
The second line of each test case contains $n$ integers $a_1, \ldots, a_n$ ($0 \le a_i \le n$) — elements of the array. Note that they don't have to be distinct.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $1000$.
-----Output-----
For each test case, you must output two lines:
The first line must contain a single integer $k$ ($0 \le k \le 2n$) — the number of operations you perform.
The second line must contain $k$ integers $x_1, \ldots, x_k$ ($1 \le x_i \le n$), where $x_i$ is the index chosen for the $i$-th operation.
If there are many solutions, you can find any of them. Please remember that it is not required to minimize $k$.
-----Example-----
Input
5
3
2 2 3
3
2 1 0
7
0 7 3 1 3 7 7
9
2 0 1 1 2 4 4 2 0
9
8 4 7 6 1 2 3 0 5
Output
0
2
3 1
4
2 5 5 4
11
3 8 9 7 8 5 9 6 4 1 2
10
1 8 1 9 5 2 4 6 3 7
-----Note-----
In the first test case, the array is already non-decreasing ($2 \le 2 \le 3$).
Explanation of the second test case (the element modified by each operation is colored in red): $a = [2, 1, 0]$ ; the initial MEX is $3$. $a = [2, 1, \color{red}{3}]$ ; the new MEX is $0$. $a = [\color{red}{0}, 1, 3]$ ; the new MEX is $2$. The final array is non-decreasing: $0 \le 1 \le 3$.
Explanation of the third test case: $a = [0, 7, 3, 1, 3, 7, 7]$ ; the initial MEX is $2$. $a = [0, \color{red}{2}, 3, 1, 3, 7, 7]$ ; the new MEX is $4$. $a = [0, 2, 3, 1, \color{red}{4}, 7, 7]$ ; the new MEX is $5$. $a = [0, 2, 3, 1, \color{red}{5}, 7, 7]$ ; the new MEX is $4$. $a = [0, 2, 3, \color{red}{4}, 5, 7, 7]$ ; the new MEX is $1$. The final array is non-decreasing: $0 \le 2 \le 3 \le 4 \le 5 \le 7 \le 7$.
|
# Fast IO (only use in integer input) or take care about string
# import os,io
# input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int,input().split()))
operation = []
while True:
isNonDecreasing = True
for i in range(n-1):
if a[i] > a[i+1]:
isNonDecreasing = False
break
if isNonDecreasing:
break
isNIn = [False] * (n + 1)
for elem in a:
isNIn[elem] = True
for i in range(n + 1):
if isNIn[i] == False:
MEX = i
break
if MEX == n:
for i in range(n):
if a[i] != i and a[i] != n:
break
operation.append(str(i + 1))
a[i] = n
else:
operation.append(str(MEX+1))
a[MEX] = MEX
print(len(operation))
if len(operation) != 0:
print(' '.join(operation))
|
Polycarp plays a computer game. In this game, the players summon armies of magical minions, which then fight each other.
Polycarp can summon $n$ different minions. The initial power level of the $i$-th minion is $a_i$, and when it is summoned, all previously summoned minions' power levels are increased by $b_i$. The minions can be summoned in any order.
Unfortunately, Polycarp cannot have more than $k$ minions under his control. To get rid of unwanted minions after summoning them, he may destroy them. Each minion can be summoned (and destroyed) only once.
Polycarp's goal is to summon the strongest possible army. Formally, he wants to maximize the sum of power levels of all minions under his control (those which are summoned and not destroyed).
Help Polycarp to make up a plan of actions to summon the strongest possible army!
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 75$) — the number of test cases.
Each test case begins with a line containing two integers $n$ and $k$ ($1 \le k \le n \le 75$) — the number of minions availible for summoning, and the maximum number of minions that can be controlled by Polycarp, respectively.
Then $n$ lines follow, the $i$-th line contains $2$ integers $a_i$ and $b_i$ ($1 \le a_i \le 10^5$, $0 \le b_i \le 10^5$) — the parameters of the $i$-th minion.
-----Output-----
For each test case print the optimal sequence of actions as follows:
Firstly, print $m$ — the number of actions which Polycarp has to perform ($0 \le m \le 2n$). Then print $m$ integers $o_1$, $o_2$, ..., $o_m$, where $o_i$ denotes the $i$-th action as follows: if the $i$-th action is to summon the minion $x$, then $o_i = x$, and if the $i$-th action is to destroy the minion $x$, then $o_i = -x$. Each minion can be summoned at most once and cannot be destroyed before being summoned (and, obviously, cannot be destroyed more than once). The number of minions in Polycarp's army should be not greater than $k$ after every action.
If there are multiple optimal sequences, print any of them.
-----Example-----
Input
3
5 2
5 3
7 0
5 0
4 0
10 0
2 1
10 100
50 10
5 5
1 5
2 4
3 3
4 2
5 1
Output
4
2 1 -1 5
1
2
5
5 4 3 2 1
-----Note-----
Consider the example test.
In the first test case, Polycarp can summon the minion $2$ with power level $7$, then summon the minion $1$, which will increase the power level of the previous minion by $3$, then destroy the minion $1$, and finally, summon the minion $5$. After this, Polycarp will have two minions with power levels of $10$.
In the second test case, Polycarp can control only one minion, so he should choose the strongest of them and summon it.
In the third test case, Polycarp is able to summon and control all five minions.
|
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, k = read_ints()
p = []
for i in range(n):
ai, bi = read_ints()
p.append((bi, ai, i + 1))
p.sort()
dp = [[0 for j in range(k + 1)] for i in range(n + 1)]
use = [[False for j in range(k + 1)] for i in range(n + 1)]
for i in range(1, n + 1):
for j in range(min(i, k) + 1):
if i - 1 >= j:
dp[i][j] = dp[i - 1][j] + (k - 1) * p[i - 1][0]
if j > 0:
x = dp[i - 1][j - 1] + (j - 1) * p[i - 1][0] + p[i - 1][1]
if x > dp[i][j]:
dp[i][j] = x
use[i][j] = True
used = []
curr = k
for i in range(n, 0, -1):
if use[i][curr]:
used.append(p[i - 1][2])
curr -= 1
used.reverse()
seq = used[:-1]
st = set(used)
for i in range(1, n + 1):
if not i in st:
seq.append(i)
seq.append(-i)
seq.append(used[-1])
print(len(seq))
print(' '.join(map(str, seq)))
|
Polycarp plays a computer game. In this game, the players summon armies of magical minions, which then fight each other.
Polycarp can summon $n$ different minions. The initial power level of the $i$-th minion is $a_i$, and when it is summoned, all previously summoned minions' power levels are increased by $b_i$. The minions can be summoned in any order.
Unfortunately, Polycarp cannot have more than $k$ minions under his control. To get rid of unwanted minions after summoning them, he may destroy them. Each minion can be summoned (and destroyed) only once.
Polycarp's goal is to summon the strongest possible army. Formally, he wants to maximize the sum of power levels of all minions under his control (those which are summoned and not destroyed).
Help Polycarp to make up a plan of actions to summon the strongest possible army!
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 75$) — the number of test cases.
Each test case begins with a line containing two integers $n$ and $k$ ($1 \le k \le n \le 75$) — the number of minions availible for summoning, and the maximum number of minions that can be controlled by Polycarp, respectively.
Then $n$ lines follow, the $i$-th line contains $2$ integers $a_i$ and $b_i$ ($1 \le a_i \le 10^5$, $0 \le b_i \le 10^5$) — the parameters of the $i$-th minion.
-----Output-----
For each test case print the optimal sequence of actions as follows:
Firstly, print $m$ — the number of actions which Polycarp has to perform ($0 \le m \le 2n$). Then print $m$ integers $o_1$, $o_2$, ..., $o_m$, where $o_i$ denotes the $i$-th action as follows: if the $i$-th action is to summon the minion $x$, then $o_i = x$, and if the $i$-th action is to destroy the minion $x$, then $o_i = -x$. Each minion can be summoned at most once and cannot be destroyed before being summoned (and, obviously, cannot be destroyed more than once). The number of minions in Polycarp's army should be not greater than $k$ after every action.
If there are multiple optimal sequences, print any of them.
-----Example-----
Input
3
5 2
5 3
7 0
5 0
4 0
10 0
2 1
10 100
50 10
5 5
1 5
2 4
3 3
4 2
5 1
Output
4
2 1 -1 5
1
2
5
5 4 3 2 1
-----Note-----
Consider the example test.
In the first test case, Polycarp can summon the minion $2$ with power level $7$, then summon the minion $1$, which will increase the power level of the previous minion by $3$, then destroy the minion $1$, and finally, summon the minion $5$. After this, Polycarp will have two minions with power levels of $10$.
In the second test case, Polycarp can control only one minion, so he should choose the strongest of them and summon it.
In the third test case, Polycarp is able to summon and control all five minions.
|
from operator import itemgetter
import sys
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 LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]
def main():
inf = 10 ** 9
for _ in range(II()):
n, k = MI()
ab = [(a, b, i) for i, (a, b) in enumerate(LLI(n))]
dp = [[inf] * n for _ in range(k)]
log = [[[] for _ in range(n)] for _ in range(k)]
for e in range(n): dp[0][e] = -ab[e][0]
ab.sort(key=itemgetter(1))
for a, b, i in ab:
for j in range(k - 2, -1, -1):
for e in range(n):
if i==e:continue
pre = dp[j][e]
if pre==inf:continue
cur = pre + b * (k - 1 - j) - a
if cur < dp[j + 1][e]:
dp[j + 1][e] = cur
log[j+1][e]=log[j][e]+[i]
#print(ab)
#p2D(dp)
#p2D(log)
#print()
mn=mne=inf
for e in range(n):
cur=dp[-1][e]
if cur<mn:
mn=cur
mne=e
first=log[-1][mne]
use=[False]*n
use[mne]=True
ans=[]
for i in first:
ans.append(i+1)
use[i]=True
for i in range(n):
if use[i]:continue
ans.append(i+1)
ans.append(-i-1)
ans.append(mne+1)
print(len(ans))
print(*ans)
main()
|
Polycarp plays a computer game. In this game, the players summon armies of magical minions, which then fight each other.
Polycarp can summon $n$ different minions. The initial power level of the $i$-th minion is $a_i$, and when it is summoned, all previously summoned minions' power levels are increased by $b_i$. The minions can be summoned in any order.
Unfortunately, Polycarp cannot have more than $k$ minions under his control. To get rid of unwanted minions after summoning them, he may destroy them. Each minion can be summoned (and destroyed) only once.
Polycarp's goal is to summon the strongest possible army. Formally, he wants to maximize the sum of power levels of all minions under his control (those which are summoned and not destroyed).
Help Polycarp to make up a plan of actions to summon the strongest possible army!
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 75$) — the number of test cases.
Each test case begins with a line containing two integers $n$ and $k$ ($1 \le k \le n \le 75$) — the number of minions availible for summoning, and the maximum number of minions that can be controlled by Polycarp, respectively.
Then $n$ lines follow, the $i$-th line contains $2$ integers $a_i$ and $b_i$ ($1 \le a_i \le 10^5$, $0 \le b_i \le 10^5$) — the parameters of the $i$-th minion.
-----Output-----
For each test case print the optimal sequence of actions as follows:
Firstly, print $m$ — the number of actions which Polycarp has to perform ($0 \le m \le 2n$). Then print $m$ integers $o_1$, $o_2$, ..., $o_m$, where $o_i$ denotes the $i$-th action as follows: if the $i$-th action is to summon the minion $x$, then $o_i = x$, and if the $i$-th action is to destroy the minion $x$, then $o_i = -x$. Each minion can be summoned at most once and cannot be destroyed before being summoned (and, obviously, cannot be destroyed more than once). The number of minions in Polycarp's army should be not greater than $k$ after every action.
If there are multiple optimal sequences, print any of them.
-----Example-----
Input
3
5 2
5 3
7 0
5 0
4 0
10 0
2 1
10 100
50 10
5 5
1 5
2 4
3 3
4 2
5 1
Output
4
2 1 -1 5
1
2
5
5 4 3 2 1
-----Note-----
Consider the example test.
In the first test case, Polycarp can summon the minion $2$ with power level $7$, then summon the minion $1$, which will increase the power level of the previous minion by $3$, then destroy the minion $1$, and finally, summon the minion $5$. After this, Polycarp will have two minions with power levels of $10$.
In the second test case, Polycarp can control only one minion, so he should choose the strongest of them and summon it.
In the third test case, Polycarp is able to summon and control all five minions.
|
import sys
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, k = nm()
mini = [tuple(nl() + [i+1]) for i in range(n)]
mini.sort(key = lambda x: x[1])
# print(mini)
dp = [-1]*(k+1)
dp[0] = 0
f = [[0]*(k+1) for _ in range(n)]
for i in range(n):
if dp[k] > 0:
dp[k] += (k - 1) * mini[i][1]
for j in range(k-1, -1, -1):
if dp[j] >= 0:
if dp[j+1] < dp[j] + mini[i][0] + j * mini[i][1]:
dp[j+1] = dp[j] + mini[i][0] + j * mini[i][1]
f[i][j+1] = 1
dp[j] += (k - 1) * mini[i][1]
cx = k
a = list()
b = list()
for i in range(n-1, -1, -1):
if f[i][cx]:
a.append(mini[i][2])
cx -= 1
else:
b.append(mini[i][2])
com = list()
for x in a[:0:-1]:
com.append(x)
for x in b:
com.append(x)
com.append(-x)
com.append(a[0])
print(len(com))
print(*com)
return
T = ni()
for _ in range(T):
solve()
|
Polycarp plays a computer game. In this game, the players summon armies of magical minions, which then fight each other.
Polycarp can summon $n$ different minions. The initial power level of the $i$-th minion is $a_i$, and when it is summoned, all previously summoned minions' power levels are increased by $b_i$. The minions can be summoned in any order.
Unfortunately, Polycarp cannot have more than $k$ minions under his control. To get rid of unwanted minions after summoning them, he may destroy them. Each minion can be summoned (and destroyed) only once.
Polycarp's goal is to summon the strongest possible army. Formally, he wants to maximize the sum of power levels of all minions under his control (those which are summoned and not destroyed).
Help Polycarp to make up a plan of actions to summon the strongest possible army!
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 75$) — the number of test cases.
Each test case begins with a line containing two integers $n$ and $k$ ($1 \le k \le n \le 75$) — the number of minions availible for summoning, and the maximum number of minions that can be controlled by Polycarp, respectively.
Then $n$ lines follow, the $i$-th line contains $2$ integers $a_i$ and $b_i$ ($1 \le a_i \le 10^5$, $0 \le b_i \le 10^5$) — the parameters of the $i$-th minion.
-----Output-----
For each test case print the optimal sequence of actions as follows:
Firstly, print $m$ — the number of actions which Polycarp has to perform ($0 \le m \le 2n$). Then print $m$ integers $o_1$, $o_2$, ..., $o_m$, where $o_i$ denotes the $i$-th action as follows: if the $i$-th action is to summon the minion $x$, then $o_i = x$, and if the $i$-th action is to destroy the minion $x$, then $o_i = -x$. Each minion can be summoned at most once and cannot be destroyed before being summoned (and, obviously, cannot be destroyed more than once). The number of minions in Polycarp's army should be not greater than $k$ after every action.
If there are multiple optimal sequences, print any of them.
-----Example-----
Input
3
5 2
5 3
7 0
5 0
4 0
10 0
2 1
10 100
50 10
5 5
1 5
2 4
3 3
4 2
5 1
Output
4
2 1 -1 5
1
2
5
5 4 3 2 1
-----Note-----
Consider the example test.
In the first test case, Polycarp can summon the minion $2$ with power level $7$, then summon the minion $1$, which will increase the power level of the previous minion by $3$, then destroy the minion $1$, and finally, summon the minion $5$. After this, Polycarp will have two minions with power levels of $10$.
In the second test case, Polycarp can control only one minion, so he should choose the strongest of them and summon it.
In the third test case, Polycarp is able to summon and control all five minions.
|
from typing import List
import sys
input = sys.stdin.readline
import math
############ ---- Input Functions ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input().strip()
return(list(s[:len(s)]))
def invr():
return(list(map(int,input().strip().split())))
def solve_hungarian(a: List[List[int]], n: int, m: int):
"""
Implementation of Hungarian algorithm in n^2 m
"""
# potentials
u = [0] * (n+1)
v = [0] * (m+1)
# pair row of each col
p = [0] * (m+1)
# for each col the number of prev col along the augmenting path
way = [0] * (m+1)
for i in range(1, n+1):
p[0] = i
j0 = 0
minv = [float('inf')] * (m+1)
used = [False] * (m+1)
# iterative Kun starts here
condition = True
while condition:
# mark the current col as reachable
used[j0] = True
i0 = p[j0]
delta = float('inf')
# determine which col will become reachable after next potential update
for j in range(1, m+1):
if not used[j]:
cur = a[i0][j] - u[i0]-v[j]
if cur < minv[j]:
minv[j] = cur
way[j] = j0
if minv[j] < delta:
delta = minv[j]
j1 = j
# j1 will hold the col with min
# way[j1] - the prev col in dfs
# update the potential
for j in range(0, m+1):
if used[j]: # if col j was discovered:
u[p[j]] += delta
v[j] -= delta
else: # not discovered - update min?
minv[j] -= delta
# j0 becomes the col on which the delta is achieved
j0 = j1
# p[j0] == 0 => j0 - a col not in matching
condition = p[j0] != 0
# the augmenting path was found - update the mapping
condition = True
while condition:
# j1 is the prev column of j0 in augmenting path
j1 = way[j0]
p[j0] = p[j1]
j0 = j1
condition = j0 != 0
ans = [0] * (n+1)
for j in range(1, m+1):
ans[p[j]] = j
return -v[0], ans
def solve(n, k, a, b):
A = [[0] * (n+1) for _ in range(n+1) ]
for i in range(1, n+1):
for j in range(1, k+1):
A[i][j] = a[i] + (j-1) * b[i]
for j in range(k+1, n+1):
A[i][j] = (k-1) * b[i]
# turn into a max problem
for i, row in enumerate(A):
M = max(row)
for j in range(n+1):
A[i][j] = M - A[i][j]
cost, match = solve_hungarian(A, n, n)
print(n + (n-k))
role_to_creature = list(zip(match, list(range(len(match)))))
role_to_creature.sort()
res = []
for index in range(1, k):
res.append(role_to_creature[index][1])
for index in range(k+1, n+1):
res.append(role_to_creature[index][1])
res.append(-role_to_creature[index][1])
res.append(role_to_creature[k][1])
print(" ".join(map(str, res)))
def from_file(f):
return f.readline
# with open('test.txt') as f:
# input = from_file(f)
t = inp()
for _ in range(t):
n, k = invr()
a = [0]
b = [0]
for _ in range(n):
ai, bi = invr()
a.append(ai)
b.append(bi)
solve(n, k, a, b)
|
The statement of this problem is the same as the statement of problem C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
import math
T = int(input())
for _ in range(T):
n = int(input())
diags = 1/math.sin(math.pi/2/n)
print(diags * math.cos(math.pi/4/n))
|
The statement of this problem is the same as the statement of problem C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
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.cos(a)
a2 = (math.pi/2 - a) / 2
r2 = r * math.cos(a2)
print(r2*2)
|
The statement of this problem is the same as the statement of problem C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
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(math.cos(math.pi / (4 * n)) / math.sin(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 C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
import math
def sqare_size(n):
return math.sin((2*n-1)/(4*n)*math.pi)/math.sin(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 C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
import sys
import math
input = sys.stdin.readline
flush = sys.stdout.flush
for _ in range(int(input())):
n = int(input())
print(2.0 * math.cos(math.pi / (4.0 * n)) / (2.0 * math.sin(math.pi / (2.0 * n))))
|
The statement of this problem is the same as the statement of problem C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
# cook your dish here
# import sys
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
import math
import collections
from sys import stdin,stdout,setrecursionlimit
import bisect as bs
T = int(stdin.readline())
for _ in range(T):
n = int(stdin.readline())
# a,b,c,d = list(map(int,stdin.readline().split()))
# h = list(map(int,stdin.readline().split()))
# b = list(map(int,stdin.readline().split()))
# a = stdin.readline().strip('\n')
t = 2*n
x = math.pi/(2*t)
h = 0.5 / (math.sin(x))
print(round(h,7))
|
The statement of this problem is the same as the statement of problem C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
import sys
from math import tan, pi, cos, sin
_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()
nn = 2*n
pin = pi/nn
l,r = 0, pin
for i in range(100):
c = (l+r)/2
if cos(c)-(cos(pin-c))>0:
l=c
else:
r=c
return cos(c)/(sin(pin))
# 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 C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
from math import pi, sin, cos
T = int(input().strip())
for t in range(T):
n = int(input().strip())
alpha = pi/n
R = 1/(2*sin(alpha/2))
if n %2 ==0:
gamma = alpha/2
else:
k = n//2
gamma = (pi/2 - alpha*k)/2
# print(alpha*180/pi)
# print(gamma * 180 / pi)
res = R* 2*cos(gamma)
print(res)
|
The statement of this problem is the same as the statement of problem C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
import math
t=int(input())
while(t):
t-=1
n=int(input())
ang= math.pi/(2*n)
ans= 1/math.sin(ang)
print(ans*math.cos(ang/2))
|
The statement of this problem is the same as the statement of problem C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
from math import*
for _ in range(int(input())):
n=int(input())
if n%2==0:print(1/tan(radians(90/n)))
else:print(cos(radians(45/n))/sin(radians(90/n)))
|
The statement of this problem is the same as the statement of problem C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
import math
# your code goes here
for _ in range(int(input())):
n=2*int(input())
print(math.cos(math.pi/(2*n))/math.sin(math.pi/n))
|
The statement of this problem is the same as the statement of problem C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
import math
import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
n = int(input())
theta = 2 * n
y = 1 / math.sin(math.radians(360 / 4 / n)) / 2
p = [(0, y)]
rot45 = [math.cos(math.radians(45)), -math.sin(math.radians(45))], [math.sin(math.radians(45)), math.cos(math.radians(45))]
tmp = p[-1]
x = rot45[0][0] * tmp[0] + rot45[0][1] * tmp[1]
y = rot45[1][0] * tmp[0] + rot45[1][1] * tmp[1]
p[0] = (x, y)
the = 360 / (2 * n)
rot = [math.cos(math.radians(the)), -math.sin(math.radians(the))], [math.sin(math.radians(the)), math.cos(math.radians(the))]
max_x = 0
max_y = 0
for i in range(2 * n - 1):
tmp = p[-1]
x = rot[0][0] * tmp[0] + rot[0][1] * tmp[1]
y = rot[1][0] * tmp[0] + rot[1][1] * tmp[1]
max_x = max(abs(x), max_x)
max_y = max(abs(y), max_y)
p.append((x, y))
print(2 * max_x)
|
The statement of this problem is the same as the statement of problem C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
import os
import sys
if os.path.exists('/mnt/c/Users/Square/square/codeforces'):
f = iter(open('D.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))
a = math.pi / 2 / n
tmp = 0.5 / math.sin(a)
# def func(phi):
# return max(math.cos(phi), math.cos(a-phi))
# l, r = 0, a
# while l - r > 1e-10:
# u = func(l)
# v = func(r)
# x = func((l*2+r*1)/3)
# y = func((l*1+r*2)/3)
# if x < y:
# r = (l*2+r*1)/3
# else:
# l = (l*1+r*2)/3
print(tmp * math.cos(a/2)*2)
# print(n, tmp * func(0))
# print(tmp * math.cos(0), tmp * math.cos(a-0))
# print(tmp * func(l))
# print()
|
The statement of this problem is the same as the statement of problem C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
from math import sin, tan, cos, pi
for t in range(int(input())):
n = int(input())
if n % 2 == 0:
print(1 / tan(pi / (2 * n)))
else:
#print(1 + 1 / tan(pi / (2 * n)) / 2 ** 0.5)
print(1 / sin(pi / (2 * n)) * cos(pi / (4 * n)))
|
The statement of this problem is the same as the statement of problem C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
t = int(input())
import math
ans=[0]*t
for i in range(t):
n=int(input())
theta=90/n
temp=1/math.sin(math.radians(theta))
ans[i]=temp*math.cos(math.radians(theta/2))
for i in range(t):
print(format(ans[i], '.9f'))
|
The statement of this problem is the same as the statement of problem C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
import sys
from math import pi, sin
def I():
return sys.stdin.readline().rstrip()
def h(n):
m = n // 2 - 0.5
a = 1
return a * sin(pi * m / n) / sin(pi / n)
def main():
for tc in range(1, 1+int(I())):
n = int(I())
n *= 2
print(h(n))
main()
|
The statement of this problem is the same as the statement of problem C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
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 = 0.5 / sin(angle)
a = 0
for i in range(1, n // 2 + 1):
A = 3 * pi / 4 - i * pi / n
a = max(a, 2 * r * sin(A))
print('{:.9f}'.format(a))
|
The statement of this problem is the same as the statement of problem C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
from math import cos, pi, sin, sqrt
for _ in range(int(input())):
n = int(input())
k0 = (n + 2) // 4
alpha = k0 * pi / n
print((sin(alpha) + cos(alpha)) / (sqrt(2) * sin(pi / (2 * n))))
|
The statement of this problem is the same as the statement of problem C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
from math import radians,sin,cos
t = int(input())
for _ in range(t):
n = int(input())
alpha = radians(90/n)
r = 0.5/(sin(alpha))
beta = 180*(n//2)/n
gamma = radians((90-beta)/2)
d = r*cos(gamma)
print(2*d)
|
The statement of this problem is the same as the statement of problem C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
import math
T = int(input())
for _ in range(T):
n = int(input())
th = math.pi / (2*n)
l = 1. / math.sin(th)
th1 = (n // 2) * (2*th)
th = math.atan((1 - math.sin(th1)) / math.cos(th1))
res = l*math.cos(th)
print(res)
# print(math.cos(th), math.sin(th+th1), th1, l, math.pi/3)
|
The statement of this problem is the same as the statement of problem C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
import math
def solve(n):
if n == 2:
return 1.0
each_angle = math.pi / n
height = 0
width = 0
for i in range(n):
angle = each_angle * i
height += math.sin(angle) * 1.0
width += abs(math.cos(angle)) * 1.0
if width > height:
sectors = n // 2
angle = each_angle * (0.5 + sectors / 2) - math.pi / 4
ans = width * math.cos(angle)
else:
ans = height
# print(height, width, ans)
return ans
def main():
T = int(input())
for _ in range(1, T + 1):
n = int(input())
print(solve(n))
def __starting_point():
main()
__starting_point()
|
The statement of this problem is the same as the statement of problem C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
from math import sin, pi, cos
def solve():
n = int( input())
return(cos(pi/(4*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 C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
import math
for _ in range(int(input())):
n=int(input())
s=2*n
#side = (((1/2*(math.sin(math.pi/(2*s))))**2)-1)**.5
side = 1/(2*(math.sin(math.pi/(2*s))))
print(side)
|
The statement of this problem is the same as the statement of problem C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
import math
q = int(input())
for _ in range(q):
n = int(input())
alfa = 3*math.pi/4 - ((n//2)*math.pi/(2*n))
y = math.tan(math.pi/2-math.pi/(2*n))
x = y/math.cos(math.pi/(2*n))
bok = math.sin(alfa)*x
print(bok)
|
The statement of this problem is the same as the statement of problem C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
import math
PI = math.pi
def radius(n):
return 0.5/math.sin(PI/(2*n))
def chord(num_sides, n):
return 2*radius(n)*math.sin((PI*num_sides)/(2*n))
t = int(input())
for i in range(t):
n = int(input())
x = int(n/2)+1
y = int(n/2)
print(chord(x,n)/math.sqrt(2)+chord(y,n)/math.sqrt(2))
|
The statement of this problem is the same as the statement of problem C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
# for n in range(3, 200, 2):
# N = 2 * n
# alpha = (2 * pi) / (2 * n)
# beta = (pi - alpha) / 2
# L = sin(beta) / sin(alpha)
# ans = 10 ** 10
# MAX = 1000
# for i in range(MAX):
# t0 = alpha * i / MAX
# xx = []
# yy = []
# for i in range(N):
# t = alpha * i + t0
# x, y = L * cos(t), L * sin(t)
# xx.append(x)
# yy.append(y)
# tmpr = max(max(xx) - min(xx), max(yy) - min(yy))
# ans = min(ans, tmpr)
# print(f"{n} : {ans},")
ans = {3: 1.931851652578137,
5: 3.1962266107498305,
7: 4.465702135190254,
9: 5.736856622834928,
11: 7.00877102284205,
13: 8.281093789118495,
15: 9.553661304648701,
17: 10.826387080174316,
19: 12.099221090606225,
21: 13.372132387773904,
23: 14.64510079714694,
25: 15.918112604548812,
27: 17.191158161652254,
29: 18.464230483075124,
31: 19.737324386897843,
33: 21.010435947900465,
35: 22.283562138356153,
37: 23.556700585376017,
39: 24.829849402946724,
41: 26.10300707314532,
43: 27.376172360514047,
45: 28.649344249275092,
47: 29.922521896579926,
49: 31.195704597210476,
51: 32.46889175658776,
53: 33.742082869893075,
55: 35.015277505745324,
57: 36.28847529331536,
59: 37.561675912061524,
61: 38.8348790834848,
63: 40.10808456445453,
65: 41.38129214176658,
67: 42.65450162767617,
69: 43.927712856207805,
71: 45.20092568008886,
73: 46.47413996818731,
75: 47.747355603359544,
77: 49.02057248063344,
79: 50.29379050566765,
81: 51.56700959343902,
83: 52.84022966711982,
85: 54.1134506571136,
87: 55.386672500223845,
89: 56.659895138934914,
91: 57.93311852078775,
93: 59.20634259783608,
95: 60.47956732617132,
97: 61.75279266550647,
99: 63.026018578810074,
101: 64.29924503198401,
103: 65.57247199357865,
105: 66.84569943454059,
107: 68.11892732798874,
109: 69.39215564901495,
111: 70.66538437450639,
113: 71.93861348298648,
115: 73.21184295447279,
117: 74.4850727703492,
119: 75.75830291325114,
121: 77.03153336696215,
123: 78.3047641163205,
125: 79.57799514713487,
127: 80.85122644610789,
129: 82.12445800076682,
131: 83.39768979940062,
133: 84.67092183100281,
135: 85.94415408521901,
137: 87.21738655229956,
139: 88.49061922305593,
141: 89.76385208882093,
143: 91.0370851414123,
145: 92.31031837309914,
147: 93.58355177657134,
149: 94.85678534491129,
151: 96.13001907156787,
153: 97.40325295033253,
155: 98.67648697531708,
157: 99.94972114093346,
159: 101.22295544187476,
161: 102.49618987309775,
163: 103.76942442980673,
165: 105.04265910743855,
167: 106.31589390164861,
169: 107.58912880829797,
171: 108.8623638234414,
173: 110.13559894331603,
175: 111.40883416433105,
177: 112.68206948305792,
179: 113.95530489622139,
181: 115.22854040069092,
183: 116.50177599347283,
185: 117.77501167170294,
187: 119.04824743263957,
189: 120.32148327365705,
191: 121.5947191922398,
193: 122.86795518597636,
195: 124.14119125255439,
197: 125.41442738975526,
199: 126.68766359544964,
}
T = int(input())
for t in range(T):
n = int(input())
print(ans[n])
|
The statement of this problem is the same as the statement of problem C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
import math
def rad(angle) :
return (angle / 180) * math.pi
def dist(a, b, c, d) :
return math.sqrt((a - c) * (a - c) + (b - d) * (b - d))
tt = int(input())
while tt > 0 :
tt -= 1
n = int(input())
angle = rad(360 / (2 * n))
l1, l2 = n // 2, n - n // 2
px, py = 0, 0
vx, vy = 1, 0
ans = 0
cur = 0
for i in range(1, n + 1) :
px += vx
py += vy
if i == l1 or i == l2 :
ans += dist(0, 0, px, py)
cur += angle
vx = math.cos(cur)
vy = math.sin(cur)
print(ans / math.sqrt(2))
|
The statement of this problem is the same as the statement of problem C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
import math
T = int(input())
while T !=0:
n = int(input())
side = math.sin(math.pi/(4*n)) * 2
print(1/side)
T -= 1
|
The statement of this problem is the same as the statement of problem C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
from math import sin, pi
t = int(input())
while t!=0:
t-=1
n = int(input())
k = 1/(sin(pi/(4*n)))
print(k/2)
|
The statement of this problem is the same as the statement of problem C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
import math
t = int(input())
for _ in range(t):
n = int(input())
print("{:.10f}".format(math.cos(math.pi/(4*n))/math.sin(math.pi/(2*n))))
|
The statement of this problem is the same as the statement of problem C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
from sys import stdin
from math import cos,sin,radians
import math
inp = lambda: stdin.readline().strip()
# [int(x) for x in inp().split()]
def diagonal(x):
return 1/(2*sin(radians(90/x)))
t = int(inp())
for _ in range(t):
n = int(inp())
# f = (diagonal(2*n)**2)**(1/2)
print(diagonal(2*n))
|
The statement of this problem is the same as the statement of problem C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
from math import sin, cos, pi
n = int(input())
def f(a, b):
return sin((b * pi) / a) / sin(pi / a)
for _ in range(n):
m = int(input())
print("%.12f" % (f(2 * m, m) * cos(pi / (4 * m))))
|
The statement of this problem is the same as the statement of problem C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
import math
t = int(input())
for _ in range(t):
n = int(input())
a = 1.0 / (2.0 * math.tan(math.pi / (n * 2)))
b = 1.0 * math.sin(math.pi / 2.0) / (math.sin(math.pi / (n * 2)))
if n % 2 == 0:
print(a * 2.0)
else:
rotation = [math.pi * 2.0 / (2 * n) * item for item in range(2 * n)]
l = 0.0; r = math.pi / 2.0
eps_rot = [(math.pi * 2.0 / (2 * n) / 10**2) * item for item in range(10**2)]
ret = b
for eps in eps_rot:
max_rad = 0.0
for rad in rotation:
val = max(b * abs(math.sin(rad + eps)), b * abs(math.cos(rad + eps)))
max_rad = max(max_rad, val)
ret = min(ret, max_rad)
print(ret)
|
The statement of this problem is the same as the statement of problem C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
import math
T = int(input())
for _ in range(T):
N = int(input())
v1 = complex(1, 0)
angle = (N//2)*(math.pi/N)
v2 = complex(math.cos(angle), math.sin(angle))
print(math.sqrt(2) * 0.5 * (abs(v1+v2) + abs(v1-v2)) * (1/(2*math.sin(math.pi/(2*N)))))
|
The statement of this problem is the same as the statement of problem C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
import math
MIN_INF, MAX_INF = float('-inf'), float('inf')
def get_len(n, R, alpha, beta):
maxx, maxy = MIN_INF, MIN_INF
minx, miny = MAX_INF, MAX_INF
d = MAX_INF
for i in range(n):
theta = alpha * i + beta
x = math.cos(theta) * R
y = math.sin(theta) * R
maxx = max(x, maxx)
maxy = max(y, maxy)
minx = min(x, minx)
miny = min(y, miny)
d = min(d, max(abs(maxx - minx), abs(maxy - miny)))
return d
def main():
T = int(input())
for t in range(T):
n = int(input()) * 2
alpha = 2 * math.pi / n
R = 1.0 / 2.0 / (math.sin(math.pi / n))
# ans = float('inf')
# a, b = 0, alpha
# va, vb = get_len(n, R, alpha, a), get_len(n, R, alpha, b)
print(get_len(n, R, alpha, alpha / 4))
# while True:
# d3 = (b - a) / 3
# c, d = a + d3, b - d3
# vc, vd = get_len(n, R, alpha, c), get_len(n, R, alpha, d)
# if abs(vc - vd) < 1e-10:
# print(n, R, alpha, c, vc)
# break
# if vc < vd:
# b, vb = d, vd
# else:
# a, va = c, vc
main()
|
The statement of this problem is the same as the statement of problem C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
import math
for _ in range(int(input())):
n = int(input())
n = 2*n
L = (1/math.sin(math.pi/(2*n)))*abs(math.sin(math.pi*(n-1)/4*n))
print(L/2)
|
The statement of this problem is the same as the statement of problem C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
from math import pi,sin
def solve(n):
r= pi/(4*n)
m= 1/sin(r)
return round(m/2,9)
for _ in range(int(input())):
n= int(input())
print(solve(n))
|
The statement of this problem is the same as the statement of problem C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
import math
for ad in range(int(input())):
n=int(input())
n*=2
t=math.pi/n
x=math.cos(t/2)/(2*math.sin(t))
print(2*x)
|
The statement of this problem is the same as the statement of problem C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
import math
from sys import stdin, stdout
for _ in range(int(stdin.readline().strip())):
n = 2*int(stdin.readline().strip())
ans = 1/((math.sin(math.radians(90/n))))
print("{0:.9f}".format(ans/2))
|
The statement of this problem is the same as the statement of problem C1. 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 odd integer $n$ ($3 \le n \le 199$). 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
3
5
199
Output
1.931851653
3.196226611
126.687663595
|
import math
def solve(n):
alpha = 2*math.pi/(4*n)
ratio = math.sin(alpha)
half = 0.5/ratio
ag = 180/(4*n)
ag = ag*2*math.pi/360
return half*2*math.cos(ag)
t = int(input())
for _ in range(t):
s = int(input())
print(solve(s))
|
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...
Lee thinks a regular $n$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $OX$-axis and at least one of its edges is parallel to the $OY$-axis at the same time.
Recall that a regular $n$-sided polygon is a convex polygon with $n$ vertices such that all the edges and angles are equal.
Now he is shopping: the market has $t$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of polygons in the market.
Each of the next $t$ lines contains a single integer $n_i$ ($3 \le n_i \le 10^9$): it means that the $i$-th polygon is a regular $n_i$-sided polygon.
-----Output-----
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
-----Example-----
Input
4
3
4
12
1000000000
Output
NO
YES
YES
YES
-----Note-----
In the example, there are $4$ polygons in the market. It's easy to see that an equilateral triangle (a regular $3$-sided polygon) is not beautiful, a square (a regular $4$-sided polygon) is beautiful and a regular $12$-sided polygon (is shown below) is beautiful as well. [Image]
|
t = int(input())
for _ in range(t):
n = int(input())
if n%4 == 0:
print("YES")
else:
print("NO")
|
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...
Lee thinks a regular $n$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $OX$-axis and at least one of its edges is parallel to the $OY$-axis at the same time.
Recall that a regular $n$-sided polygon is a convex polygon with $n$ vertices such that all the edges and angles are equal.
Now he is shopping: the market has $t$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of polygons in the market.
Each of the next $t$ lines contains a single integer $n_i$ ($3 \le n_i \le 10^9$): it means that the $i$-th polygon is a regular $n_i$-sided polygon.
-----Output-----
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
-----Example-----
Input
4
3
4
12
1000000000
Output
NO
YES
YES
YES
-----Note-----
In the example, there are $4$ polygons in the market. It's easy to see that an equilateral triangle (a regular $3$-sided polygon) is not beautiful, a square (a regular $4$-sided polygon) is beautiful and a regular $12$-sided polygon (is shown below) is beautiful as well. [Image]
|
for _ in range(int(input())):
# a, b = map(int, input().split())
n = int(input())
# arr = list(map(int, input().split()))
if n % 4 == 0:
print('YES')
else:
print('NO')
|
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...
Lee thinks a regular $n$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $OX$-axis and at least one of its edges is parallel to the $OY$-axis at the same time.
Recall that a regular $n$-sided polygon is a convex polygon with $n$ vertices such that all the edges and angles are equal.
Now he is shopping: the market has $t$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of polygons in the market.
Each of the next $t$ lines contains a single integer $n_i$ ($3 \le n_i \le 10^9$): it means that the $i$-th polygon is a regular $n_i$-sided polygon.
-----Output-----
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
-----Example-----
Input
4
3
4
12
1000000000
Output
NO
YES
YES
YES
-----Note-----
In the example, there are $4$ polygons in the market. It's easy to see that an equilateral triangle (a regular $3$-sided polygon) is not beautiful, a square (a regular $4$-sided polygon) is beautiful and a regular $12$-sided polygon (is shown below) is beautiful as well. [Image]
|
t11 = int(input())
for _ in range(t11):
a = int(input())
if a % 4 == 0:
print("YES")
else:
print("NO")
|
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...
Lee thinks a regular $n$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $OX$-axis and at least one of its edges is parallel to the $OY$-axis at the same time.
Recall that a regular $n$-sided polygon is a convex polygon with $n$ vertices such that all the edges and angles are equal.
Now he is shopping: the market has $t$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of polygons in the market.
Each of the next $t$ lines contains a single integer $n_i$ ($3 \le n_i \le 10^9$): it means that the $i$-th polygon is a regular $n_i$-sided polygon.
-----Output-----
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
-----Example-----
Input
4
3
4
12
1000000000
Output
NO
YES
YES
YES
-----Note-----
In the example, there are $4$ polygons in the market. It's easy to see that an equilateral triangle (a regular $3$-sided polygon) is not beautiful, a square (a regular $4$-sided polygon) is beautiful and a regular $12$-sided polygon (is shown below) is beautiful as well. [Image]
|
import math as ma
# import sys
# input=sys.stdin.readline
t=int(input())
for _ in range(t):
n=int(input())
if n%4==0:
print("YES")
else:
print("NO")
|
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...
Lee thinks a regular $n$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $OX$-axis and at least one of its edges is parallel to the $OY$-axis at the same time.
Recall that a regular $n$-sided polygon is a convex polygon with $n$ vertices such that all the edges and angles are equal.
Now he is shopping: the market has $t$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of polygons in the market.
Each of the next $t$ lines contains a single integer $n_i$ ($3 \le n_i \le 10^9$): it means that the $i$-th polygon is a regular $n_i$-sided polygon.
-----Output-----
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
-----Example-----
Input
4
3
4
12
1000000000
Output
NO
YES
YES
YES
-----Note-----
In the example, there are $4$ polygons in the market. It's easy to see that an equilateral triangle (a regular $3$-sided polygon) is not beautiful, a square (a regular $4$-sided polygon) is beautiful and a regular $12$-sided polygon (is shown below) is beautiful as well. [Image]
|
t11 = int(input())
for _ in range(t11):
n = int(input())
if n % 4 == 0:
print("YES")
else:
print("NO")
|
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...
Lee thinks a regular $n$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $OX$-axis and at least one of its edges is parallel to the $OY$-axis at the same time.
Recall that a regular $n$-sided polygon is a convex polygon with $n$ vertices such that all the edges and angles are equal.
Now he is shopping: the market has $t$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of polygons in the market.
Each of the next $t$ lines contains a single integer $n_i$ ($3 \le n_i \le 10^9$): it means that the $i$-th polygon is a regular $n_i$-sided polygon.
-----Output-----
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
-----Example-----
Input
4
3
4
12
1000000000
Output
NO
YES
YES
YES
-----Note-----
In the example, there are $4$ polygons in the market. It's easy to see that an equilateral triangle (a regular $3$-sided polygon) is not beautiful, a square (a regular $4$-sided polygon) is beautiful and a regular $12$-sided polygon (is shown below) is beautiful as well. [Image]
|
import math
t = int(input())
for g in range(t):
n = int(input())
if(n%4==0):
print("YES")
else:
print("NO")
|
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...
Lee thinks a regular $n$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $OX$-axis and at least one of its edges is parallel to the $OY$-axis at the same time.
Recall that a regular $n$-sided polygon is a convex polygon with $n$ vertices such that all the edges and angles are equal.
Now he is shopping: the market has $t$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of polygons in the market.
Each of the next $t$ lines contains a single integer $n_i$ ($3 \le n_i \le 10^9$): it means that the $i$-th polygon is a regular $n_i$-sided polygon.
-----Output-----
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
-----Example-----
Input
4
3
4
12
1000000000
Output
NO
YES
YES
YES
-----Note-----
In the example, there are $4$ polygons in the market. It's easy to see that an equilateral triangle (a regular $3$-sided polygon) is not beautiful, a square (a regular $4$-sided polygon) is beautiful and a regular $12$-sided polygon (is shown below) is beautiful as well. [Image]
|
for _ in range(int(input())):
if int(input()) % 4 == 0:
print("YES")
else:
print("NO")
|
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...
Lee thinks a regular $n$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $OX$-axis and at least one of its edges is parallel to the $OY$-axis at the same time.
Recall that a regular $n$-sided polygon is a convex polygon with $n$ vertices such that all the edges and angles are equal.
Now he is shopping: the market has $t$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of polygons in the market.
Each of the next $t$ lines contains a single integer $n_i$ ($3 \le n_i \le 10^9$): it means that the $i$-th polygon is a regular $n_i$-sided polygon.
-----Output-----
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
-----Example-----
Input
4
3
4
12
1000000000
Output
NO
YES
YES
YES
-----Note-----
In the example, there are $4$ polygons in the market. It's easy to see that an equilateral triangle (a regular $3$-sided polygon) is not beautiful, a square (a regular $4$-sided polygon) is beautiful and a regular $12$-sided polygon (is shown below) is beautiful as well. [Image]
|
import math
t = int(input())
for helloworld in range(t):
n = int(input())
if n % 4 == 0:
print('YES')
else:
print('NO')
|
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...
Lee thinks a regular $n$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $OX$-axis and at least one of its edges is parallel to the $OY$-axis at the same time.
Recall that a regular $n$-sided polygon is a convex polygon with $n$ vertices such that all the edges and angles are equal.
Now he is shopping: the market has $t$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of polygons in the market.
Each of the next $t$ lines contains a single integer $n_i$ ($3 \le n_i \le 10^9$): it means that the $i$-th polygon is a regular $n_i$-sided polygon.
-----Output-----
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
-----Example-----
Input
4
3
4
12
1000000000
Output
NO
YES
YES
YES
-----Note-----
In the example, there are $4$ polygons in the market. It's easy to see that an equilateral triangle (a regular $3$-sided polygon) is not beautiful, a square (a regular $4$-sided polygon) is beautiful and a regular $12$-sided polygon (is shown below) is beautiful as well. [Image]
|
for nt in range(int(input())):
n = int(input())
if n%4==0:
print ("YES")
else:
print ("NO")
|
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...
Lee thinks a regular $n$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $OX$-axis and at least one of its edges is parallel to the $OY$-axis at the same time.
Recall that a regular $n$-sided polygon is a convex polygon with $n$ vertices such that all the edges and angles are equal.
Now he is shopping: the market has $t$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of polygons in the market.
Each of the next $t$ lines contains a single integer $n_i$ ($3 \le n_i \le 10^9$): it means that the $i$-th polygon is a regular $n_i$-sided polygon.
-----Output-----
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
-----Example-----
Input
4
3
4
12
1000000000
Output
NO
YES
YES
YES
-----Note-----
In the example, there are $4$ polygons in the market. It's easy to see that an equilateral triangle (a regular $3$-sided polygon) is not beautiful, a square (a regular $4$-sided polygon) is beautiful and a regular $12$-sided polygon (is shown below) is beautiful as well. [Image]
|
import sys
def ii():
return sys.stdin.readline().strip()
def idata():
return [int(x) for x in ii().split()]
def solve():
n = int(ii())
if n % 4 == 0:
print('YES')
else:
print('NO')
return
for t in range(int(ii())):
solve()
|
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...
Lee thinks a regular $n$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $OX$-axis and at least one of its edges is parallel to the $OY$-axis at the same time.
Recall that a regular $n$-sided polygon is a convex polygon with $n$ vertices such that all the edges and angles are equal.
Now he is shopping: the market has $t$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of polygons in the market.
Each of the next $t$ lines contains a single integer $n_i$ ($3 \le n_i \le 10^9$): it means that the $i$-th polygon is a regular $n_i$-sided polygon.
-----Output-----
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
-----Example-----
Input
4
3
4
12
1000000000
Output
NO
YES
YES
YES
-----Note-----
In the example, there are $4$ polygons in the market. It's easy to see that an equilateral triangle (a regular $3$-sided polygon) is not beautiful, a square (a regular $4$-sided polygon) is beautiful and a regular $12$-sided polygon (is shown below) is beautiful as well. [Image]
|
t = int(input())
for _ in range(t):
n = int(input())
if n % 4 == 0:
print("YES")
else:
print("NO")
|
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...
Lee thinks a regular $n$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $OX$-axis and at least one of its edges is parallel to the $OY$-axis at the same time.
Recall that a regular $n$-sided polygon is a convex polygon with $n$ vertices such that all the edges and angles are equal.
Now he is shopping: the market has $t$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of polygons in the market.
Each of the next $t$ lines contains a single integer $n_i$ ($3 \le n_i \le 10^9$): it means that the $i$-th polygon is a regular $n_i$-sided polygon.
-----Output-----
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
-----Example-----
Input
4
3
4
12
1000000000
Output
NO
YES
YES
YES
-----Note-----
In the example, there are $4$ polygons in the market. It's easy to see that an equilateral triangle (a regular $3$-sided polygon) is not beautiful, a square (a regular $4$-sided polygon) is beautiful and a regular $12$-sided polygon (is shown below) is beautiful as well. [Image]
|
from math import *
def r1(t):
return t(input())
def r2(t):
return [t(i) for i in input().split()]
for _ in range(r1(int)):
n = r1(int)
if n % 4 == 0:
print('YES')
else:
print('NO')
|
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...
Lee thinks a regular $n$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $OX$-axis and at least one of its edges is parallel to the $OY$-axis at the same time.
Recall that a regular $n$-sided polygon is a convex polygon with $n$ vertices such that all the edges and angles are equal.
Now he is shopping: the market has $t$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of polygons in the market.
Each of the next $t$ lines contains a single integer $n_i$ ($3 \le n_i \le 10^9$): it means that the $i$-th polygon is a regular $n_i$-sided polygon.
-----Output-----
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
-----Example-----
Input
4
3
4
12
1000000000
Output
NO
YES
YES
YES
-----Note-----
In the example, there are $4$ polygons in the market. It's easy to see that an equilateral triangle (a regular $3$-sided polygon) is not beautiful, a square (a regular $4$-sided polygon) is beautiful and a regular $12$-sided polygon (is shown below) is beautiful as well. [Image]
|
t=int(input())
for i in range(t):
n=int(input())
if n%4==0:
print('YES')
else:
print('NO')
|
Lee is going to fashionably decorate his house for a party, using some regular convex polygons...
Lee thinks a regular $n$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $OX$-axis and at least one of its edges is parallel to the $OY$-axis at the same time.
Recall that a regular $n$-sided polygon is a convex polygon with $n$ vertices such that all the edges and angles are equal.
Now he is shopping: the market has $t$ regular polygons. For each of them print YES if it is beautiful and NO otherwise.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of polygons in the market.
Each of the next $t$ lines contains a single integer $n_i$ ($3 \le n_i \le 10^9$): it means that the $i$-th polygon is a regular $n_i$-sided polygon.
-----Output-----
For each polygon, print YES if it's beautiful or NO otherwise (case insensitive).
-----Example-----
Input
4
3
4
12
1000000000
Output
NO
YES
YES
YES
-----Note-----
In the example, there are $4$ polygons in the market. It's easy to see that an equilateral triangle (a regular $3$-sided polygon) is not beautiful, a square (a regular $4$-sided polygon) is beautiful and a regular $12$-sided polygon (is shown below) is beautiful as well. [Image]
|
t = int(input())
for q in range(t):
n = int(input())
if n % 4 == 0:
print('YES')
else:
print('NO')
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.