inputs
stringlengths 50
14k
| targets
stringlengths 4
655k
|
|---|---|
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.
So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.
You are a coach at a very large university and you know that $c$ of your students are coders, $m$ are mathematicians and $x$ have no specialization.
What is the maximum number of full perfect teams you can distribute them into?
Note that some students can be left without a team and each student can be a part of no more than one team.
You are also asked to answer $q$ independent queries.
-----Input-----
The first line contains a single integer $q$ ($1 \le q \le 10^4$) β the number of queries.
Each of the next $q$ lines contains three integers $c$, $m$ and $x$ ($0 \le c, m, x \le 10^8$) β the number of coders, mathematicians and students without any specialization in the university, respectively.
Note that the no student is both coder and mathematician at the same time.
-----Output-----
Print $q$ integers β the $i$-th of them should be the answer to the $i$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
-----Example-----
Input
6
1 1 1
3 6 0
0 0 0
0 1 1
10 1 10
4 4 1
Output
1
3
0
0
1
3
-----Note-----
In the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
|
for q in range(int(input())):
c,m,x=list(map(int,input().split()))
a=min(c,m,(c+m+x)//3)
print(a)
|
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.
So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.
You are a coach at a very large university and you know that $c$ of your students are coders, $m$ are mathematicians and $x$ have no specialization.
What is the maximum number of full perfect teams you can distribute them into?
Note that some students can be left without a team and each student can be a part of no more than one team.
You are also asked to answer $q$ independent queries.
-----Input-----
The first line contains a single integer $q$ ($1 \le q \le 10^4$) β the number of queries.
Each of the next $q$ lines contains three integers $c$, $m$ and $x$ ($0 \le c, m, x \le 10^8$) β the number of coders, mathematicians and students without any specialization in the university, respectively.
Note that the no student is both coder and mathematician at the same time.
-----Output-----
Print $q$ integers β the $i$-th of them should be the answer to the $i$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
-----Example-----
Input
6
1 1 1
3 6 0
0 0 0
0 1 1
10 1 10
4 4 1
Output
1
3
0
0
1
3
-----Note-----
In the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
|
Q = int(input())
def solve():
[c,m,x] = list(map(int,input().split()))
def canMakeK(k):
if c < k or m < k:
return False
return ((c-k) + (m-k) + x) >= k
ans = 0
jump = max(c,m,x)
while jump > 0:
while canMakeK(ans+jump):
ans += jump
jump //= 2
return ans
for _ in range(Q):
print(solve())
|
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.
So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.
You are a coach at a very large university and you know that $c$ of your students are coders, $m$ are mathematicians and $x$ have no specialization.
What is the maximum number of full perfect teams you can distribute them into?
Note that some students can be left without a team and each student can be a part of no more than one team.
You are also asked to answer $q$ independent queries.
-----Input-----
The first line contains a single integer $q$ ($1 \le q \le 10^4$) β the number of queries.
Each of the next $q$ lines contains three integers $c$, $m$ and $x$ ($0 \le c, m, x \le 10^8$) β the number of coders, mathematicians and students without any specialization in the university, respectively.
Note that the no student is both coder and mathematician at the same time.
-----Output-----
Print $q$ integers β the $i$-th of them should be the answer to the $i$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
-----Example-----
Input
6
1 1 1
3 6 0
0 0 0
0 1 1
10 1 10
4 4 1
Output
1
3
0
0
1
3
-----Note-----
In the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
|
from sys import stdin
for i in range(int(stdin.readline())):
c, m, x = list(map(int, stdin.readline().split()))
def ok(nteam):
return c >= nteam and m >= nteam and x + c + m >= 3 * nteam
l = 0
r = max(c, m, x) + 1
while r - l > 1:
mid = (r + l) // 2
if ok(mid):
l = mid
else:
r = mid
print(l)
|
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.
So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.
You are a coach at a very large university and you know that $c$ of your students are coders, $m$ are mathematicians and $x$ have no specialization.
What is the maximum number of full perfect teams you can distribute them into?
Note that some students can be left without a team and each student can be a part of no more than one team.
You are also asked to answer $q$ independent queries.
-----Input-----
The first line contains a single integer $q$ ($1 \le q \le 10^4$) β the number of queries.
Each of the next $q$ lines contains three integers $c$, $m$ and $x$ ($0 \le c, m, x \le 10^8$) β the number of coders, mathematicians and students without any specialization in the university, respectively.
Note that the no student is both coder and mathematician at the same time.
-----Output-----
Print $q$ integers β the $i$-th of them should be the answer to the $i$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
-----Example-----
Input
6
1 1 1
3 6 0
0 0 0
0 1 1
10 1 10
4 4 1
Output
1
3
0
0
1
3
-----Note-----
In the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
|
import sys
input = sys.stdin.readline
def getInt(): return int(input())
def getVars(): return list(map(int, input().split()))
def getList(): return list(map(int, input().split()))
def getStr(): return input().strip()
## -------------------------------
def addDictList(d, key, val):
if key not in d: d[key] = []
d[key].append(val)
def addDictInt(d, key, val):
if key not in d: d[key] = 0
d[key] = val
def addDictCount(d, key):
if key not in d: d[key] = 0
d[key] += 1
def addDictSum(d, key, val):
if key not in d: d[key] = 0
d[key] += val
## -------------------------------
t=getInt()
for _ in range(t):
c, m, x = getVars()
res = min(c, m)
res = min(res, (c+m+x)//3)
print(res)
|
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.
So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.
You are a coach at a very large university and you know that $c$ of your students are coders, $m$ are mathematicians and $x$ have no specialization.
What is the maximum number of full perfect teams you can distribute them into?
Note that some students can be left without a team and each student can be a part of no more than one team.
You are also asked to answer $q$ independent queries.
-----Input-----
The first line contains a single integer $q$ ($1 \le q \le 10^4$) β the number of queries.
Each of the next $q$ lines contains three integers $c$, $m$ and $x$ ($0 \le c, m, x \le 10^8$) β the number of coders, mathematicians and students without any specialization in the university, respectively.
Note that the no student is both coder and mathematician at the same time.
-----Output-----
Print $q$ integers β the $i$-th of them should be the answer to the $i$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
-----Example-----
Input
6
1 1 1
3 6 0
0 0 0
0 1 1
10 1 10
4 4 1
Output
1
3
0
0
1
3
-----Note-----
In the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
|
q = int(input())
for _ in range(q):
c, m, x = list(map(int, input().split()))
s = c + m + x
i = min(c, m)
if s//3 <= i:
print(s//3)
else:
print(min(i, s-i*2))
|
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.
So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.
You are a coach at a very large university and you know that $c$ of your students are coders, $m$ are mathematicians and $x$ have no specialization.
What is the maximum number of full perfect teams you can distribute them into?
Note that some students can be left without a team and each student can be a part of no more than one team.
You are also asked to answer $q$ independent queries.
-----Input-----
The first line contains a single integer $q$ ($1 \le q \le 10^4$) β the number of queries.
Each of the next $q$ lines contains three integers $c$, $m$ and $x$ ($0 \le c, m, x \le 10^8$) β the number of coders, mathematicians and students without any specialization in the university, respectively.
Note that the no student is both coder and mathematician at the same time.
-----Output-----
Print $q$ integers β the $i$-th of them should be the answer to the $i$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
-----Example-----
Input
6
1 1 1
3 6 0
0 0 0
0 1 1
10 1 10
4 4 1
Output
1
3
0
0
1
3
-----Note-----
In the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
|
def solve():
c, m, x = list(map(int, input().split()))
u = min(c, m)
y = c - u + m - u + x
if y >= u:
print(u)
return
print(y + (u - y) * 2 // 3)
t = int(input())
for _ in range(t):
solve()
|
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.
So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.
You are a coach at a very large university and you know that $c$ of your students are coders, $m$ are mathematicians and $x$ have no specialization.
What is the maximum number of full perfect teams you can distribute them into?
Note that some students can be left without a team and each student can be a part of no more than one team.
You are also asked to answer $q$ independent queries.
-----Input-----
The first line contains a single integer $q$ ($1 \le q \le 10^4$) β the number of queries.
Each of the next $q$ lines contains three integers $c$, $m$ and $x$ ($0 \le c, m, x \le 10^8$) β the number of coders, mathematicians and students without any specialization in the university, respectively.
Note that the no student is both coder and mathematician at the same time.
-----Output-----
Print $q$ integers β the $i$-th of them should be the answer to the $i$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
-----Example-----
Input
6
1 1 1
3 6 0
0 0 0
0 1 1
10 1 10
4 4 1
Output
1
3
0
0
1
3
-----Note-----
In the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
|
for i in range(int(input())):
c,m,x=map(int,input().split())
print(min((c+m+x)//3,min(c,m)))
|
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.
So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.
You are a coach at a very large university and you know that $c$ of your students are coders, $m$ are mathematicians and $x$ have no specialization.
What is the maximum number of full perfect teams you can distribute them into?
Note that some students can be left without a team and each student can be a part of no more than one team.
You are also asked to answer $q$ independent queries.
-----Input-----
The first line contains a single integer $q$ ($1 \le q \le 10^4$) β the number of queries.
Each of the next $q$ lines contains three integers $c$, $m$ and $x$ ($0 \le c, m, x \le 10^8$) β the number of coders, mathematicians and students without any specialization in the university, respectively.
Note that the no student is both coder and mathematician at the same time.
-----Output-----
Print $q$ integers β the $i$-th of them should be the answer to the $i$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
-----Example-----
Input
6
1 1 1
3 6 0
0 0 0
0 1 1
10 1 10
4 4 1
Output
1
3
0
0
1
3
-----Note-----
In the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
|
for _ in range(int(input())):
c,m,s = [int(i) for i in input().split()]
a,b = min(c,m),max(c,m)
if(s>=a):
print(a)
else:
a = a-s
b = b-s
temp = (a+b)//3
print(s + min(temp,a))
|
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.
So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.
You are a coach at a very large university and you know that $c$ of your students are coders, $m$ are mathematicians and $x$ have no specialization.
What is the maximum number of full perfect teams you can distribute them into?
Note that some students can be left without a team and each student can be a part of no more than one team.
You are also asked to answer $q$ independent queries.
-----Input-----
The first line contains a single integer $q$ ($1 \le q \le 10^4$) β the number of queries.
Each of the next $q$ lines contains three integers $c$, $m$ and $x$ ($0 \le c, m, x \le 10^8$) β the number of coders, mathematicians and students without any specialization in the university, respectively.
Note that the no student is both coder and mathematician at the same time.
-----Output-----
Print $q$ integers β the $i$-th of them should be the answer to the $i$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
-----Example-----
Input
6
1 1 1
3 6 0
0 0 0
0 1 1
10 1 10
4 4 1
Output
1
3
0
0
1
3
-----Note-----
In the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
|
n = int(input())
for i in range(n):
c, m, x = list(map(int, input().split()))
wynik = 0
wynik += min(c, m,x)
huj = min(c,m,x)
c -= huj
m -= huj
x -= huj
if x > 0:
print(wynik)
else:
if c > m:
c, m = m, c
wynik += min(m,c,(m+c)//3)
print(wynik)
|
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.
So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.
You are a coach at a very large university and you know that $c$ of your students are coders, $m$ are mathematicians and $x$ have no specialization.
What is the maximum number of full perfect teams you can distribute them into?
Note that some students can be left without a team and each student can be a part of no more than one team.
You are also asked to answer $q$ independent queries.
-----Input-----
The first line contains a single integer $q$ ($1 \le q \le 10^4$) β the number of queries.
Each of the next $q$ lines contains three integers $c$, $m$ and $x$ ($0 \le c, m, x \le 10^8$) β the number of coders, mathematicians and students without any specialization in the university, respectively.
Note that the no student is both coder and mathematician at the same time.
-----Output-----
Print $q$ integers β the $i$-th of them should be the answer to the $i$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
-----Example-----
Input
6
1 1 1
3 6 0
0 0 0
0 1 1
10 1 10
4 4 1
Output
1
3
0
0
1
3
-----Note-----
In the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
|
for _ in range(int(input())):
c, m, a = map(int, input().split())
print(min(c, m, (c + m + a) // 3))
|
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.
So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.
You are a coach at a very large university and you know that $c$ of your students are coders, $m$ are mathematicians and $x$ have no specialization.
What is the maximum number of full perfect teams you can distribute them into?
Note that some students can be left without a team and each student can be a part of no more than one team.
You are also asked to answer $q$ independent queries.
-----Input-----
The first line contains a single integer $q$ ($1 \le q \le 10^4$) β the number of queries.
Each of the next $q$ lines contains three integers $c$, $m$ and $x$ ($0 \le c, m, x \le 10^8$) β the number of coders, mathematicians and students without any specialization in the university, respectively.
Note that the no student is both coder and mathematician at the same time.
-----Output-----
Print $q$ integers β the $i$-th of them should be the answer to the $i$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
-----Example-----
Input
6
1 1 1
3 6 0
0 0 0
0 1 1
10 1 10
4 4 1
Output
1
3
0
0
1
3
-----Note-----
In the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
|
from sys import stdin
q=int(stdin.readline().strip())
for i in range(q):
c,m,x=list(map(int,stdin.readline().strip().split()))
n=c+m+x
y=min(c,m)
t=n//3
ans=min(y,t)
print(ans)
|
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.
So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.
You are a coach at a very large university and you know that $c$ of your students are coders, $m$ are mathematicians and $x$ have no specialization.
What is the maximum number of full perfect teams you can distribute them into?
Note that some students can be left without a team and each student can be a part of no more than one team.
You are also asked to answer $q$ independent queries.
-----Input-----
The first line contains a single integer $q$ ($1 \le q \le 10^4$) β the number of queries.
Each of the next $q$ lines contains three integers $c$, $m$ and $x$ ($0 \le c, m, x \le 10^8$) β the number of coders, mathematicians and students without any specialization in the university, respectively.
Note that the no student is both coder and mathematician at the same time.
-----Output-----
Print $q$ integers β the $i$-th of them should be the answer to the $i$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
-----Example-----
Input
6
1 1 1
3 6 0
0 0 0
0 1 1
10 1 10
4 4 1
Output
1
3
0
0
1
3
-----Note-----
In the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
|
q = int(input())
for i in range(q):
c, m, x = map(int, input().split())
print(min(min(c, m), (c + m + x) // 3))
|
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.
So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.
You are a coach at a very large university and you know that $c$ of your students are coders, $m$ are mathematicians and $x$ have no specialization.
What is the maximum number of full perfect teams you can distribute them into?
Note that some students can be left without a team and each student can be a part of no more than one team.
You are also asked to answer $q$ independent queries.
-----Input-----
The first line contains a single integer $q$ ($1 \le q \le 10^4$) β the number of queries.
Each of the next $q$ lines contains three integers $c$, $m$ and $x$ ($0 \le c, m, x \le 10^8$) β the number of coders, mathematicians and students without any specialization in the university, respectively.
Note that the no student is both coder and mathematician at the same time.
-----Output-----
Print $q$ integers β the $i$-th of them should be the answer to the $i$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
-----Example-----
Input
6
1 1 1
3 6 0
0 0 0
0 1 1
10 1 10
4 4 1
Output
1
3
0
0
1
3
-----Note-----
In the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
|
q = int(input())
for i in range(q):
c, m, x = map(int, input().split())
if min(c, m) <= x:
print(min(c, m))
else:
l = -1
r = min(c, m) + 1
while l + 1 < r:
mid = (l + r) // 2
if c - mid + m - mid + x >= mid:
l = mid
else:
r = mid
if l == -1:
l = 0
print(l)
|
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.
So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.
You are a coach at a very large university and you know that $c$ of your students are coders, $m$ are mathematicians and $x$ have no specialization.
What is the maximum number of full perfect teams you can distribute them into?
Note that some students can be left without a team and each student can be a part of no more than one team.
You are also asked to answer $q$ independent queries.
-----Input-----
The first line contains a single integer $q$ ($1 \le q \le 10^4$) β the number of queries.
Each of the next $q$ lines contains three integers $c$, $m$ and $x$ ($0 \le c, m, x \le 10^8$) β the number of coders, mathematicians and students without any specialization in the university, respectively.
Note that the no student is both coder and mathematician at the same time.
-----Output-----
Print $q$ integers β the $i$-th of them should be the answer to the $i$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
-----Example-----
Input
6
1 1 1
3 6 0
0 0 0
0 1 1
10 1 10
4 4 1
Output
1
3
0
0
1
3
-----Note-----
In the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
|
import sys
def read():
return sys.stdin.readline()
def main():
q = int(read())
for i in range(q):
c, m, x = list(map(int, read().split()))
if c <= m and c <= x:
print(c)
elif m <= c and m <= x:
print(m)
else:
t = x
c -= x
m -= x
q = min(m, c, (m + c) // 3)
print(t + q)
def __starting_point():
main()
__starting_point()
|
You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't have both at the same time.
So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.
You are a coach at a very large university and you know that $c$ of your students are coders, $m$ are mathematicians and $x$ have no specialization.
What is the maximum number of full perfect teams you can distribute them into?
Note that some students can be left without a team and each student can be a part of no more than one team.
You are also asked to answer $q$ independent queries.
-----Input-----
The first line contains a single integer $q$ ($1 \le q \le 10^4$) β the number of queries.
Each of the next $q$ lines contains three integers $c$, $m$ and $x$ ($0 \le c, m, x \le 10^8$) β the number of coders, mathematicians and students without any specialization in the university, respectively.
Note that the no student is both coder and mathematician at the same time.
-----Output-----
Print $q$ integers β the $i$-th of them should be the answer to the $i$ query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.
-----Example-----
Input
6
1 1 1
3 6 0
0 0 0
0 1 1
10 1 10
4 4 1
Output
1
3
0
0
1
3
-----Note-----
In the first example here are how teams are formed: the only team of 1 coder, 1 mathematician and 1 without specialization; all three teams consist of 1 coder and 2 mathematicians; no teams can be formed; no teams can be formed; one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren't able to form any team; one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
|
q=int(input())
for _ in range(q):
c,m,x=map(int,input().split())
if c<m:
c,m,x=c,c,x+m-c
elif c>m:
c,m,x=m,m,x+c-m
ans=min(c,m,x)
if c>x:
ans+=2*(c-x)//3
print(ans)
|
Lee was cleaning his house for the party when he found a messy string under the carpets. Now he'd like to make it clean accurately and in a stylish way...
The string $s$ he found is a binary string of length $n$ (i. e. string consists only of 0-s and 1-s).
In one move he can choose two consecutive characters $s_i$ and $s_{i+1}$, and if $s_i$ is 1 and $s_{i + 1}$ is 0, he can erase exactly one of them (he can choose which one to erase but he can't erase both characters simultaneously). The string shrinks after erasing.
Lee can make an arbitrary number of moves (possibly zero) and he'd like to make the string $s$ as clean as possible. He thinks for two different strings $x$ and $y$, the shorter string is cleaner, and if they are the same length, then the lexicographically smaller string is cleaner.
Now you should answer $t$ test cases: for the $i$-th test case, print the cleanest possible string that Lee can get by doing some number of moves.
Small reminder: if we have two strings $x$ and $y$ of the same length then $x$ is lexicographically smaller than $y$ if there is a position $i$ such that $x_1 = y_1$, $x_2 = y_2$,..., $x_{i - 1} = y_{i - 1}$ and $x_i < y_i$.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 10^4$)Β β the number of test cases.
Next $2t$ lines contain test casesΒ β one per two lines.
The first line of each test case contains the integer $n$ ($1 \le n \le 10^5$)Β β the length of the string $s$.
The second line contains the binary string $s$. The string $s$ is a string of length $n$ which consists only of zeroes and ones.
It's guaranteed that sum of $n$ over test cases doesn't exceed $10^5$.
-----Output-----
Print $t$ answersΒ β one per test case.
The answer to the $i$-th test case is the cleanest string Lee can get after doing some number of moves (possibly zero).
-----Example-----
Input
5
10
0001111111
4
0101
8
11001101
10
1110000000
1
1
Output
0001111111
001
01
0
1
-----Note-----
In the first test case, Lee can't perform any moves.
In the second test case, Lee should erase $s_2$.
In the third test case, Lee can make moves, for example, in the following order: 11001101Β $\rightarrow$ 1100101Β $\rightarrow$ 110101Β $\rightarrow$ 10101Β $\rightarrow$ 1101Β $\rightarrow$ 101Β $\rightarrow$ 01.
|
for _ in range(int(input())):
# a, b = map(int, input().split())
n = int(input())
# arr = list(map(int, input().split()))
s = input()
l = 0
r = n - 1
if s.count('0') == n:
print(s)
continue
if s.count('1') == n:
print(s)
continue
while s[l] == '0':
l += 1
while s[r] == '1':
r -= 1
if r <= l:
print(s)
continue
print(l * '0' + '0' + (n - r - 1) * '1')
|
Lee was cleaning his house for the party when he found a messy string under the carpets. Now he'd like to make it clean accurately and in a stylish way...
The string $s$ he found is a binary string of length $n$ (i. e. string consists only of 0-s and 1-s).
In one move he can choose two consecutive characters $s_i$ and $s_{i+1}$, and if $s_i$ is 1 and $s_{i + 1}$ is 0, he can erase exactly one of them (he can choose which one to erase but he can't erase both characters simultaneously). The string shrinks after erasing.
Lee can make an arbitrary number of moves (possibly zero) and he'd like to make the string $s$ as clean as possible. He thinks for two different strings $x$ and $y$, the shorter string is cleaner, and if they are the same length, then the lexicographically smaller string is cleaner.
Now you should answer $t$ test cases: for the $i$-th test case, print the cleanest possible string that Lee can get by doing some number of moves.
Small reminder: if we have two strings $x$ and $y$ of the same length then $x$ is lexicographically smaller than $y$ if there is a position $i$ such that $x_1 = y_1$, $x_2 = y_2$,..., $x_{i - 1} = y_{i - 1}$ and $x_i < y_i$.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 10^4$)Β β the number of test cases.
Next $2t$ lines contain test casesΒ β one per two lines.
The first line of each test case contains the integer $n$ ($1 \le n \le 10^5$)Β β the length of the string $s$.
The second line contains the binary string $s$. The string $s$ is a string of length $n$ which consists only of zeroes and ones.
It's guaranteed that sum of $n$ over test cases doesn't exceed $10^5$.
-----Output-----
Print $t$ answersΒ β one per test case.
The answer to the $i$-th test case is the cleanest string Lee can get after doing some number of moves (possibly zero).
-----Example-----
Input
5
10
0001111111
4
0101
8
11001101
10
1110000000
1
1
Output
0001111111
001
01
0
1
-----Note-----
In the first test case, Lee can't perform any moves.
In the second test case, Lee should erase $s_2$.
In the third test case, Lee can make moves, for example, in the following order: 11001101Β $\rightarrow$ 1100101Β $\rightarrow$ 110101Β $\rightarrow$ 10101Β $\rightarrow$ 1101Β $\rightarrow$ 101Β $\rightarrow$ 01.
|
ans = []
for _ in range(int(input())):
n = int(input())
u = list(map(int, list(input())))
for i in range(n):
if u[i] == 1:
i1 = i
break
else:
ans.append(''.join(map(str, u)))
continue
for i in range(n - 1, -1, -1):
if u[i] == 0:
i2 = i
break
else:
ans.append(''.join(map(str, u)))
continue
if i2 < i1:
ans.append(''.join(map(str, u)))
continue
u1 = '0' * i1 + '0' + '1' * (n - i2 - 1)
ans.append(u1)
print('\n'.join(ans))
|
Lee was cleaning his house for the party when he found a messy string under the carpets. Now he'd like to make it clean accurately and in a stylish way...
The string $s$ he found is a binary string of length $n$ (i. e. string consists only of 0-s and 1-s).
In one move he can choose two consecutive characters $s_i$ and $s_{i+1}$, and if $s_i$ is 1 and $s_{i + 1}$ is 0, he can erase exactly one of them (he can choose which one to erase but he can't erase both characters simultaneously). The string shrinks after erasing.
Lee can make an arbitrary number of moves (possibly zero) and he'd like to make the string $s$ as clean as possible. He thinks for two different strings $x$ and $y$, the shorter string is cleaner, and if they are the same length, then the lexicographically smaller string is cleaner.
Now you should answer $t$ test cases: for the $i$-th test case, print the cleanest possible string that Lee can get by doing some number of moves.
Small reminder: if we have two strings $x$ and $y$ of the same length then $x$ is lexicographically smaller than $y$ if there is a position $i$ such that $x_1 = y_1$, $x_2 = y_2$,..., $x_{i - 1} = y_{i - 1}$ and $x_i < y_i$.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 10^4$)Β β the number of test cases.
Next $2t$ lines contain test casesΒ β one per two lines.
The first line of each test case contains the integer $n$ ($1 \le n \le 10^5$)Β β the length of the string $s$.
The second line contains the binary string $s$. The string $s$ is a string of length $n$ which consists only of zeroes and ones.
It's guaranteed that sum of $n$ over test cases doesn't exceed $10^5$.
-----Output-----
Print $t$ answersΒ β one per test case.
The answer to the $i$-th test case is the cleanest string Lee can get after doing some number of moves (possibly zero).
-----Example-----
Input
5
10
0001111111
4
0101
8
11001101
10
1110000000
1
1
Output
0001111111
001
01
0
1
-----Note-----
In the first test case, Lee can't perform any moves.
In the second test case, Lee should erase $s_2$.
In the third test case, Lee can make moves, for example, in the following order: 11001101Β $\rightarrow$ 1100101Β $\rightarrow$ 110101Β $\rightarrow$ 10101Β $\rightarrow$ 1101Β $\rightarrow$ 101Β $\rightarrow$ 01.
|
def solve():
n = int(input())
st = input()
pref0 = 0
for i in st:
if i == "0":
pref0 += 1
else:
break
post1 = 0
for i in st[::-1]:
if i == "1":
post1 += 1
else:
break
if n != post1 + pref0:
print(pref0 *"0"+"0"+post1*"1")
else:
print(pref0 * "0" + post1 * "1")
for i in range(int(input())):
solve()
|
Lee was cleaning his house for the party when he found a messy string under the carpets. Now he'd like to make it clean accurately and in a stylish way...
The string $s$ he found is a binary string of length $n$ (i. e. string consists only of 0-s and 1-s).
In one move he can choose two consecutive characters $s_i$ and $s_{i+1}$, and if $s_i$ is 1 and $s_{i + 1}$ is 0, he can erase exactly one of them (he can choose which one to erase but he can't erase both characters simultaneously). The string shrinks after erasing.
Lee can make an arbitrary number of moves (possibly zero) and he'd like to make the string $s$ as clean as possible. He thinks for two different strings $x$ and $y$, the shorter string is cleaner, and if they are the same length, then the lexicographically smaller string is cleaner.
Now you should answer $t$ test cases: for the $i$-th test case, print the cleanest possible string that Lee can get by doing some number of moves.
Small reminder: if we have two strings $x$ and $y$ of the same length then $x$ is lexicographically smaller than $y$ if there is a position $i$ such that $x_1 = y_1$, $x_2 = y_2$,..., $x_{i - 1} = y_{i - 1}$ and $x_i < y_i$.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 10^4$)Β β the number of test cases.
Next $2t$ lines contain test casesΒ β one per two lines.
The first line of each test case contains the integer $n$ ($1 \le n \le 10^5$)Β β the length of the string $s$.
The second line contains the binary string $s$. The string $s$ is a string of length $n$ which consists only of zeroes and ones.
It's guaranteed that sum of $n$ over test cases doesn't exceed $10^5$.
-----Output-----
Print $t$ answersΒ β one per test case.
The answer to the $i$-th test case is the cleanest string Lee can get after doing some number of moves (possibly zero).
-----Example-----
Input
5
10
0001111111
4
0101
8
11001101
10
1110000000
1
1
Output
0001111111
001
01
0
1
-----Note-----
In the first test case, Lee can't perform any moves.
In the second test case, Lee should erase $s_2$.
In the third test case, Lee can make moves, for example, in the following order: 11001101Β $\rightarrow$ 1100101Β $\rightarrow$ 110101Β $\rightarrow$ 10101Β $\rightarrow$ 1101Β $\rightarrow$ 101Β $\rightarrow$ 01.
|
#list(map(int,input().split()))
t=int(input())
for _ in range(t):
n=int(input())
s=input()
co=0
for i in range(n):
if(s[i]=='1'):
break
print('0',end="")
co+=1
ind=n
for i in range(n-1,-1,-1):
if(s[i]=='0'):
break
ind=i
if(co-1<ind-1):
print('0',end="")
for i in range(ind,n):
print('1',end="")
print()
|
Lee was cleaning his house for the party when he found a messy string under the carpets. Now he'd like to make it clean accurately and in a stylish way...
The string $s$ he found is a binary string of length $n$ (i. e. string consists only of 0-s and 1-s).
In one move he can choose two consecutive characters $s_i$ and $s_{i+1}$, and if $s_i$ is 1 and $s_{i + 1}$ is 0, he can erase exactly one of them (he can choose which one to erase but he can't erase both characters simultaneously). The string shrinks after erasing.
Lee can make an arbitrary number of moves (possibly zero) and he'd like to make the string $s$ as clean as possible. He thinks for two different strings $x$ and $y$, the shorter string is cleaner, and if they are the same length, then the lexicographically smaller string is cleaner.
Now you should answer $t$ test cases: for the $i$-th test case, print the cleanest possible string that Lee can get by doing some number of moves.
Small reminder: if we have two strings $x$ and $y$ of the same length then $x$ is lexicographically smaller than $y$ if there is a position $i$ such that $x_1 = y_1$, $x_2 = y_2$,..., $x_{i - 1} = y_{i - 1}$ and $x_i < y_i$.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 10^4$)Β β the number of test cases.
Next $2t$ lines contain test casesΒ β one per two lines.
The first line of each test case contains the integer $n$ ($1 \le n \le 10^5$)Β β the length of the string $s$.
The second line contains the binary string $s$. The string $s$ is a string of length $n$ which consists only of zeroes and ones.
It's guaranteed that sum of $n$ over test cases doesn't exceed $10^5$.
-----Output-----
Print $t$ answersΒ β one per test case.
The answer to the $i$-th test case is the cleanest string Lee can get after doing some number of moves (possibly zero).
-----Example-----
Input
5
10
0001111111
4
0101
8
11001101
10
1110000000
1
1
Output
0001111111
001
01
0
1
-----Note-----
In the first test case, Lee can't perform any moves.
In the second test case, Lee should erase $s_2$.
In the third test case, Lee can make moves, for example, in the following order: 11001101Β $\rightarrow$ 1100101Β $\rightarrow$ 110101Β $\rightarrow$ 10101Β $\rightarrow$ 1101Β $\rightarrow$ 101Β $\rightarrow$ 01.
|
for test_i in range(int(input())):
n = int(input())
s = input()
l1 = 0
while l1 < n:
if s[-l1 - 1] == '1':
l1 += 1
else:
break
l0 = 0
while l0 < n:
if s[l0] == '0':
l0 += 1
else:
break
if l0 + l1 < len(s):
print('0' * (l0 + 1) + '1' * l1)
else:
print('0' * l0 + '1' * l1)
|
Lee was cleaning his house for the party when he found a messy string under the carpets. Now he'd like to make it clean accurately and in a stylish way...
The string $s$ he found is a binary string of length $n$ (i. e. string consists only of 0-s and 1-s).
In one move he can choose two consecutive characters $s_i$ and $s_{i+1}$, and if $s_i$ is 1 and $s_{i + 1}$ is 0, he can erase exactly one of them (he can choose which one to erase but he can't erase both characters simultaneously). The string shrinks after erasing.
Lee can make an arbitrary number of moves (possibly zero) and he'd like to make the string $s$ as clean as possible. He thinks for two different strings $x$ and $y$, the shorter string is cleaner, and if they are the same length, then the lexicographically smaller string is cleaner.
Now you should answer $t$ test cases: for the $i$-th test case, print the cleanest possible string that Lee can get by doing some number of moves.
Small reminder: if we have two strings $x$ and $y$ of the same length then $x$ is lexicographically smaller than $y$ if there is a position $i$ such that $x_1 = y_1$, $x_2 = y_2$,..., $x_{i - 1} = y_{i - 1}$ and $x_i < y_i$.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 10^4$)Β β the number of test cases.
Next $2t$ lines contain test casesΒ β one per two lines.
The first line of each test case contains the integer $n$ ($1 \le n \le 10^5$)Β β the length of the string $s$.
The second line contains the binary string $s$. The string $s$ is a string of length $n$ which consists only of zeroes and ones.
It's guaranteed that sum of $n$ over test cases doesn't exceed $10^5$.
-----Output-----
Print $t$ answersΒ β one per test case.
The answer to the $i$-th test case is the cleanest string Lee can get after doing some number of moves (possibly zero).
-----Example-----
Input
5
10
0001111111
4
0101
8
11001101
10
1110000000
1
1
Output
0001111111
001
01
0
1
-----Note-----
In the first test case, Lee can't perform any moves.
In the second test case, Lee should erase $s_2$.
In the third test case, Lee can make moves, for example, in the following order: 11001101Β $\rightarrow$ 1100101Β $\rightarrow$ 110101Β $\rightarrow$ 10101Β $\rightarrow$ 1101Β $\rightarrow$ 101Β $\rightarrow$ 01.
|
import sys
input = sys.stdin.readline
Q = int(input())
Query = []
for _ in range(Q):
N = int(input())
S = input().rstrip()
Query.append((N, S))
for N, S in Query:
i1 = N
while i1 > 0 and S[i1-1] == "1":
i1 -= 1
i2 = -1
while i2 +1< N-1 and S[i2+1] == "0":
i2 += 1
if i2 + 1 == i1:
tmp = ""
else:
tmp = "0"
ans = "0"*(i2+1) + tmp + "1"*(N-i1)
print(ans)
|
Lee was cleaning his house for the party when he found a messy string under the carpets. Now he'd like to make it clean accurately and in a stylish way...
The string $s$ he found is a binary string of length $n$ (i. e. string consists only of 0-s and 1-s).
In one move he can choose two consecutive characters $s_i$ and $s_{i+1}$, and if $s_i$ is 1 and $s_{i + 1}$ is 0, he can erase exactly one of them (he can choose which one to erase but he can't erase both characters simultaneously). The string shrinks after erasing.
Lee can make an arbitrary number of moves (possibly zero) and he'd like to make the string $s$ as clean as possible. He thinks for two different strings $x$ and $y$, the shorter string is cleaner, and if they are the same length, then the lexicographically smaller string is cleaner.
Now you should answer $t$ test cases: for the $i$-th test case, print the cleanest possible string that Lee can get by doing some number of moves.
Small reminder: if we have two strings $x$ and $y$ of the same length then $x$ is lexicographically smaller than $y$ if there is a position $i$ such that $x_1 = y_1$, $x_2 = y_2$,..., $x_{i - 1} = y_{i - 1}$ and $x_i < y_i$.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 10^4$)Β β the number of test cases.
Next $2t$ lines contain test casesΒ β one per two lines.
The first line of each test case contains the integer $n$ ($1 \le n \le 10^5$)Β β the length of the string $s$.
The second line contains the binary string $s$. The string $s$ is a string of length $n$ which consists only of zeroes and ones.
It's guaranteed that sum of $n$ over test cases doesn't exceed $10^5$.
-----Output-----
Print $t$ answersΒ β one per test case.
The answer to the $i$-th test case is the cleanest string Lee can get after doing some number of moves (possibly zero).
-----Example-----
Input
5
10
0001111111
4
0101
8
11001101
10
1110000000
1
1
Output
0001111111
001
01
0
1
-----Note-----
In the first test case, Lee can't perform any moves.
In the second test case, Lee should erase $s_2$.
In the third test case, Lee can make moves, for example, in the following order: 11001101Β $\rightarrow$ 1100101Β $\rightarrow$ 110101Β $\rightarrow$ 10101Β $\rightarrow$ 1101Β $\rightarrow$ 101Β $\rightarrow$ 01.
|
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# import numpy as np
sys.setrecursionlimit(int(pow(10,6)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]
# @lru_cache(None)
term=l()[0]
# term=1
for _ in range(term):
n=l()[0]
s=list(input())
i=0
while(i<n and s[i]!="1"):
i+=1
j=n-1
while j>=0 and s[j]!="0":
j-=1
if(i<j+1):
del(s[i:j])
print("".join(s))
|
Lee was cleaning his house for the party when he found a messy string under the carpets. Now he'd like to make it clean accurately and in a stylish way...
The string $s$ he found is a binary string of length $n$ (i. e. string consists only of 0-s and 1-s).
In one move he can choose two consecutive characters $s_i$ and $s_{i+1}$, and if $s_i$ is 1 and $s_{i + 1}$ is 0, he can erase exactly one of them (he can choose which one to erase but he can't erase both characters simultaneously). The string shrinks after erasing.
Lee can make an arbitrary number of moves (possibly zero) and he'd like to make the string $s$ as clean as possible. He thinks for two different strings $x$ and $y$, the shorter string is cleaner, and if they are the same length, then the lexicographically smaller string is cleaner.
Now you should answer $t$ test cases: for the $i$-th test case, print the cleanest possible string that Lee can get by doing some number of moves.
Small reminder: if we have two strings $x$ and $y$ of the same length then $x$ is lexicographically smaller than $y$ if there is a position $i$ such that $x_1 = y_1$, $x_2 = y_2$,..., $x_{i - 1} = y_{i - 1}$ and $x_i < y_i$.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 10^4$)Β β the number of test cases.
Next $2t$ lines contain test casesΒ β one per two lines.
The first line of each test case contains the integer $n$ ($1 \le n \le 10^5$)Β β the length of the string $s$.
The second line contains the binary string $s$. The string $s$ is a string of length $n$ which consists only of zeroes and ones.
It's guaranteed that sum of $n$ over test cases doesn't exceed $10^5$.
-----Output-----
Print $t$ answersΒ β one per test case.
The answer to the $i$-th test case is the cleanest string Lee can get after doing some number of moves (possibly zero).
-----Example-----
Input
5
10
0001111111
4
0101
8
11001101
10
1110000000
1
1
Output
0001111111
001
01
0
1
-----Note-----
In the first test case, Lee can't perform any moves.
In the second test case, Lee should erase $s_2$.
In the third test case, Lee can make moves, for example, in the following order: 11001101Β $\rightarrow$ 1100101Β $\rightarrow$ 110101Β $\rightarrow$ 10101Β $\rightarrow$ 1101Β $\rightarrow$ 101Β $\rightarrow$ 01.
|
for nt in range(int(input())):
n = int(input())
s = input()
if "1" not in s:
print (s)
continue
ans = ""
for i in range(n):
if s[i]=="0":
ans += s[i]
else:
ind = i
break
temp = ""
for i in range(n-1,ind-1,-1):
if s[i]=="0":
ans += "0"
break
else:
temp += "1"
ans += temp
print (ans)
|
Lee was cleaning his house for the party when he found a messy string under the carpets. Now he'd like to make it clean accurately and in a stylish way...
The string $s$ he found is a binary string of length $n$ (i. e. string consists only of 0-s and 1-s).
In one move he can choose two consecutive characters $s_i$ and $s_{i+1}$, and if $s_i$ is 1 and $s_{i + 1}$ is 0, he can erase exactly one of them (he can choose which one to erase but he can't erase both characters simultaneously). The string shrinks after erasing.
Lee can make an arbitrary number of moves (possibly zero) and he'd like to make the string $s$ as clean as possible. He thinks for two different strings $x$ and $y$, the shorter string is cleaner, and if they are the same length, then the lexicographically smaller string is cleaner.
Now you should answer $t$ test cases: for the $i$-th test case, print the cleanest possible string that Lee can get by doing some number of moves.
Small reminder: if we have two strings $x$ and $y$ of the same length then $x$ is lexicographically smaller than $y$ if there is a position $i$ such that $x_1 = y_1$, $x_2 = y_2$,..., $x_{i - 1} = y_{i - 1}$ and $x_i < y_i$.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 10^4$)Β β the number of test cases.
Next $2t$ lines contain test casesΒ β one per two lines.
The first line of each test case contains the integer $n$ ($1 \le n \le 10^5$)Β β the length of the string $s$.
The second line contains the binary string $s$. The string $s$ is a string of length $n$ which consists only of zeroes and ones.
It's guaranteed that sum of $n$ over test cases doesn't exceed $10^5$.
-----Output-----
Print $t$ answersΒ β one per test case.
The answer to the $i$-th test case is the cleanest string Lee can get after doing some number of moves (possibly zero).
-----Example-----
Input
5
10
0001111111
4
0101
8
11001101
10
1110000000
1
1
Output
0001111111
001
01
0
1
-----Note-----
In the first test case, Lee can't perform any moves.
In the second test case, Lee should erase $s_2$.
In the third test case, Lee can make moves, for example, in the following order: 11001101Β $\rightarrow$ 1100101Β $\rightarrow$ 110101Β $\rightarrow$ 10101Β $\rightarrow$ 1101Β $\rightarrow$ 101Β $\rightarrow$ 01.
|
from sys import stdin, stdout
import math
t = int(stdin.readline())
for _ in range(t):
n = int(stdin.readline())
s = stdin.readline().strip()
st, end = float('inf'), -1
for i in range(n):
if s[i] == '1':
st = i
break
for i in range(n-1, -1, -1):
if s[i] == '0':
end = i
break
if st < end:
print(s[:st]+'0'+s[end+1:])
else:
print(s)
|
Lee was cleaning his house for the party when he found a messy string under the carpets. Now he'd like to make it clean accurately and in a stylish way...
The string $s$ he found is a binary string of length $n$ (i. e. string consists only of 0-s and 1-s).
In one move he can choose two consecutive characters $s_i$ and $s_{i+1}$, and if $s_i$ is 1 and $s_{i + 1}$ is 0, he can erase exactly one of them (he can choose which one to erase but he can't erase both characters simultaneously). The string shrinks after erasing.
Lee can make an arbitrary number of moves (possibly zero) and he'd like to make the string $s$ as clean as possible. He thinks for two different strings $x$ and $y$, the shorter string is cleaner, and if they are the same length, then the lexicographically smaller string is cleaner.
Now you should answer $t$ test cases: for the $i$-th test case, print the cleanest possible string that Lee can get by doing some number of moves.
Small reminder: if we have two strings $x$ and $y$ of the same length then $x$ is lexicographically smaller than $y$ if there is a position $i$ such that $x_1 = y_1$, $x_2 = y_2$,..., $x_{i - 1} = y_{i - 1}$ and $x_i < y_i$.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 10^4$)Β β the number of test cases.
Next $2t$ lines contain test casesΒ β one per two lines.
The first line of each test case contains the integer $n$ ($1 \le n \le 10^5$)Β β the length of the string $s$.
The second line contains the binary string $s$. The string $s$ is a string of length $n$ which consists only of zeroes and ones.
It's guaranteed that sum of $n$ over test cases doesn't exceed $10^5$.
-----Output-----
Print $t$ answersΒ β one per test case.
The answer to the $i$-th test case is the cleanest string Lee can get after doing some number of moves (possibly zero).
-----Example-----
Input
5
10
0001111111
4
0101
8
11001101
10
1110000000
1
1
Output
0001111111
001
01
0
1
-----Note-----
In the first test case, Lee can't perform any moves.
In the second test case, Lee should erase $s_2$.
In the third test case, Lee can make moves, for example, in the following order: 11001101Β $\rightarrow$ 1100101Β $\rightarrow$ 110101Β $\rightarrow$ 10101Β $\rightarrow$ 1101Β $\rightarrow$ 101Β $\rightarrow$ 01.
|
from itertools import groupby as gb
t = int(input())
for _ in range(t):
n = int(input())
s = input()
if s.count('10') == 0:
print(s)
continue
res = ""
suf = ""
l = [(k, len(list(v))) for k, v in gb(s)]
if len(l) > 0 and l[0][0] == '0':
res += l[0][0] * l[0][1]
l = l[1:]
if len(l) > 0 and l[-1][0] == '1':
suf = l[-1][0] * l[-1][1]
l = l[:-1]
print(res + '0' + suf)
|
Lee was cleaning his house for the party when he found a messy string under the carpets. Now he'd like to make it clean accurately and in a stylish way...
The string $s$ he found is a binary string of length $n$ (i. e. string consists only of 0-s and 1-s).
In one move he can choose two consecutive characters $s_i$ and $s_{i+1}$, and if $s_i$ is 1 and $s_{i + 1}$ is 0, he can erase exactly one of them (he can choose which one to erase but he can't erase both characters simultaneously). The string shrinks after erasing.
Lee can make an arbitrary number of moves (possibly zero) and he'd like to make the string $s$ as clean as possible. He thinks for two different strings $x$ and $y$, the shorter string is cleaner, and if they are the same length, then the lexicographically smaller string is cleaner.
Now you should answer $t$ test cases: for the $i$-th test case, print the cleanest possible string that Lee can get by doing some number of moves.
Small reminder: if we have two strings $x$ and $y$ of the same length then $x$ is lexicographically smaller than $y$ if there is a position $i$ such that $x_1 = y_1$, $x_2 = y_2$,..., $x_{i - 1} = y_{i - 1}$ and $x_i < y_i$.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 10^4$)Β β the number of test cases.
Next $2t$ lines contain test casesΒ β one per two lines.
The first line of each test case contains the integer $n$ ($1 \le n \le 10^5$)Β β the length of the string $s$.
The second line contains the binary string $s$. The string $s$ is a string of length $n$ which consists only of zeroes and ones.
It's guaranteed that sum of $n$ over test cases doesn't exceed $10^5$.
-----Output-----
Print $t$ answersΒ β one per test case.
The answer to the $i$-th test case is the cleanest string Lee can get after doing some number of moves (possibly zero).
-----Example-----
Input
5
10
0001111111
4
0101
8
11001101
10
1110000000
1
1
Output
0001111111
001
01
0
1
-----Note-----
In the first test case, Lee can't perform any moves.
In the second test case, Lee should erase $s_2$.
In the third test case, Lee can make moves, for example, in the following order: 11001101Β $\rightarrow$ 1100101Β $\rightarrow$ 110101Β $\rightarrow$ 10101Β $\rightarrow$ 1101Β $\rightarrow$ 101Β $\rightarrow$ 01.
|
import math
def main():
n = int(input())
line = input()
zero = 0
one = 0
i = 0
while i < n and line[i] == '0':
zero += 1
i += 1
i = n - 1
while i > -1 and line[i] == '1':
one += 1
i -= 1
zr = False
on = False
for i in range(n):
if line[i] == '0':
zr = True
for i in range(n - 1, -1, -1):
if line[i] == "0":
on = True
if line[i] == "1" and on:
zero += 1
break
if zero == 0 and one == 0:
if zr:
print(0)
else:
print(1)
else:
line = ""
for k in range(zero):
line += "0"
for k in range(one):
line += "1"
print(line)
def __starting_point():
t = int(input())
for i in range(t):
main()
__starting_point()
|
Lee was cleaning his house for the party when he found a messy string under the carpets. Now he'd like to make it clean accurately and in a stylish way...
The string $s$ he found is a binary string of length $n$ (i. e. string consists only of 0-s and 1-s).
In one move he can choose two consecutive characters $s_i$ and $s_{i+1}$, and if $s_i$ is 1 and $s_{i + 1}$ is 0, he can erase exactly one of them (he can choose which one to erase but he can't erase both characters simultaneously). The string shrinks after erasing.
Lee can make an arbitrary number of moves (possibly zero) and he'd like to make the string $s$ as clean as possible. He thinks for two different strings $x$ and $y$, the shorter string is cleaner, and if they are the same length, then the lexicographically smaller string is cleaner.
Now you should answer $t$ test cases: for the $i$-th test case, print the cleanest possible string that Lee can get by doing some number of moves.
Small reminder: if we have two strings $x$ and $y$ of the same length then $x$ is lexicographically smaller than $y$ if there is a position $i$ such that $x_1 = y_1$, $x_2 = y_2$,..., $x_{i - 1} = y_{i - 1}$ and $x_i < y_i$.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 10^4$)Β β the number of test cases.
Next $2t$ lines contain test casesΒ β one per two lines.
The first line of each test case contains the integer $n$ ($1 \le n \le 10^5$)Β β the length of the string $s$.
The second line contains the binary string $s$. The string $s$ is a string of length $n$ which consists only of zeroes and ones.
It's guaranteed that sum of $n$ over test cases doesn't exceed $10^5$.
-----Output-----
Print $t$ answersΒ β one per test case.
The answer to the $i$-th test case is the cleanest string Lee can get after doing some number of moves (possibly zero).
-----Example-----
Input
5
10
0001111111
4
0101
8
11001101
10
1110000000
1
1
Output
0001111111
001
01
0
1
-----Note-----
In the first test case, Lee can't perform any moves.
In the second test case, Lee should erase $s_2$.
In the third test case, Lee can make moves, for example, in the following order: 11001101Β $\rightarrow$ 1100101Β $\rightarrow$ 110101Β $\rightarrow$ 10101Β $\rightarrow$ 1101Β $\rightarrow$ 101Β $\rightarrow$ 01.
|
for _ in range(int(input())):
n = int(input())
s = input()
if n == 1:
print(s)
continue
zero = -1
one = -1
for i in range(n):
if s[i] == "0":
zero = i
if s[i] == "1" and one < 0:
one = i
if zero < one or one == -1 or zero == -1:
print(s)
else:
print((one+1) * "0" + (n-zero-1) * "1")
|
Lee was cleaning his house for the party when he found a messy string under the carpets. Now he'd like to make it clean accurately and in a stylish way...
The string $s$ he found is a binary string of length $n$ (i. e. string consists only of 0-s and 1-s).
In one move he can choose two consecutive characters $s_i$ and $s_{i+1}$, and if $s_i$ is 1 and $s_{i + 1}$ is 0, he can erase exactly one of them (he can choose which one to erase but he can't erase both characters simultaneously). The string shrinks after erasing.
Lee can make an arbitrary number of moves (possibly zero) and he'd like to make the string $s$ as clean as possible. He thinks for two different strings $x$ and $y$, the shorter string is cleaner, and if they are the same length, then the lexicographically smaller string is cleaner.
Now you should answer $t$ test cases: for the $i$-th test case, print the cleanest possible string that Lee can get by doing some number of moves.
Small reminder: if we have two strings $x$ and $y$ of the same length then $x$ is lexicographically smaller than $y$ if there is a position $i$ such that $x_1 = y_1$, $x_2 = y_2$,..., $x_{i - 1} = y_{i - 1}$ and $x_i < y_i$.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 10^4$)Β β the number of test cases.
Next $2t$ lines contain test casesΒ β one per two lines.
The first line of each test case contains the integer $n$ ($1 \le n \le 10^5$)Β β the length of the string $s$.
The second line contains the binary string $s$. The string $s$ is a string of length $n$ which consists only of zeroes and ones.
It's guaranteed that sum of $n$ over test cases doesn't exceed $10^5$.
-----Output-----
Print $t$ answersΒ β one per test case.
The answer to the $i$-th test case is the cleanest string Lee can get after doing some number of moves (possibly zero).
-----Example-----
Input
5
10
0001111111
4
0101
8
11001101
10
1110000000
1
1
Output
0001111111
001
01
0
1
-----Note-----
In the first test case, Lee can't perform any moves.
In the second test case, Lee should erase $s_2$.
In the third test case, Lee can make moves, for example, in the following order: 11001101Β $\rightarrow$ 1100101Β $\rightarrow$ 110101Β $\rightarrow$ 10101Β $\rightarrow$ 1101Β $\rightarrow$ 101Β $\rightarrow$ 01.
|
# Contest No.: 652
# Problem No.: B
# Solver: JEMINI
# Date: 20200623
import sys
import heapq
def main():
t = int(input())
for _ in range(t):
n = int(sys.stdin.readline().strip())
s = sys.stdin.readline().strip()
if ("1" in s and "0" not in s) or ("1" not in s and "0" in s):
print(s)
continue
lPoint = 0
while s[lPoint] == "0":
lPoint += 1
rPoint = n - 1
while s[rPoint] == "1":
rPoint -= 1
if lPoint > rPoint:
print(s)
continue
if lPoint != n - 1:
ans = s[:lPoint]
else:
ans = ""
ans += "0"
if rPoint != n - 1:
ans += s[rPoint + 1:]
print(ans)
return
def __starting_point():
main()
__starting_point()
|
Lee was cleaning his house for the party when he found a messy string under the carpets. Now he'd like to make it clean accurately and in a stylish way...
The string $s$ he found is a binary string of length $n$ (i. e. string consists only of 0-s and 1-s).
In one move he can choose two consecutive characters $s_i$ and $s_{i+1}$, and if $s_i$ is 1 and $s_{i + 1}$ is 0, he can erase exactly one of them (he can choose which one to erase but he can't erase both characters simultaneously). The string shrinks after erasing.
Lee can make an arbitrary number of moves (possibly zero) and he'd like to make the string $s$ as clean as possible. He thinks for two different strings $x$ and $y$, the shorter string is cleaner, and if they are the same length, then the lexicographically smaller string is cleaner.
Now you should answer $t$ test cases: for the $i$-th test case, print the cleanest possible string that Lee can get by doing some number of moves.
Small reminder: if we have two strings $x$ and $y$ of the same length then $x$ is lexicographically smaller than $y$ if there is a position $i$ such that $x_1 = y_1$, $x_2 = y_2$,..., $x_{i - 1} = y_{i - 1}$ and $x_i < y_i$.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 10^4$)Β β the number of test cases.
Next $2t$ lines contain test casesΒ β one per two lines.
The first line of each test case contains the integer $n$ ($1 \le n \le 10^5$)Β β the length of the string $s$.
The second line contains the binary string $s$. The string $s$ is a string of length $n$ which consists only of zeroes and ones.
It's guaranteed that sum of $n$ over test cases doesn't exceed $10^5$.
-----Output-----
Print $t$ answersΒ β one per test case.
The answer to the $i$-th test case is the cleanest string Lee can get after doing some number of moves (possibly zero).
-----Example-----
Input
5
10
0001111111
4
0101
8
11001101
10
1110000000
1
1
Output
0001111111
001
01
0
1
-----Note-----
In the first test case, Lee can't perform any moves.
In the second test case, Lee should erase $s_2$.
In the third test case, Lee can make moves, for example, in the following order: 11001101Β $\rightarrow$ 1100101Β $\rightarrow$ 110101Β $\rightarrow$ 10101Β $\rightarrow$ 1101Β $\rightarrow$ 101Β $\rightarrow$ 01.
|
import sys
input = sys.stdin.readline
t=int(input())
for tests in range(t):
n=int(input())
S=input().strip()
OPENING=-1
for i in range(n):
if S[i]=="1":
OPENING=i
break
ENDING=n
for i in range(n-1,-1,-1):
if S[i]=="0":
ENDING=i
break
if OPENING==-1 or ENDING==n:
print(S)
elif OPENING>ENDING:
print(S)
else:
print("".join(map(str,[0]*(OPENING+1)+[1]*(n-1-ENDING))))
|
Lee was cleaning his house for the party when he found a messy string under the carpets. Now he'd like to make it clean accurately and in a stylish way...
The string $s$ he found is a binary string of length $n$ (i. e. string consists only of 0-s and 1-s).
In one move he can choose two consecutive characters $s_i$ and $s_{i+1}$, and if $s_i$ is 1 and $s_{i + 1}$ is 0, he can erase exactly one of them (he can choose which one to erase but he can't erase both characters simultaneously). The string shrinks after erasing.
Lee can make an arbitrary number of moves (possibly zero) and he'd like to make the string $s$ as clean as possible. He thinks for two different strings $x$ and $y$, the shorter string is cleaner, and if they are the same length, then the lexicographically smaller string is cleaner.
Now you should answer $t$ test cases: for the $i$-th test case, print the cleanest possible string that Lee can get by doing some number of moves.
Small reminder: if we have two strings $x$ and $y$ of the same length then $x$ is lexicographically smaller than $y$ if there is a position $i$ such that $x_1 = y_1$, $x_2 = y_2$,..., $x_{i - 1} = y_{i - 1}$ and $x_i < y_i$.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 10^4$)Β β the number of test cases.
Next $2t$ lines contain test casesΒ β one per two lines.
The first line of each test case contains the integer $n$ ($1 \le n \le 10^5$)Β β the length of the string $s$.
The second line contains the binary string $s$. The string $s$ is a string of length $n$ which consists only of zeroes and ones.
It's guaranteed that sum of $n$ over test cases doesn't exceed $10^5$.
-----Output-----
Print $t$ answersΒ β one per test case.
The answer to the $i$-th test case is the cleanest string Lee can get after doing some number of moves (possibly zero).
-----Example-----
Input
5
10
0001111111
4
0101
8
11001101
10
1110000000
1
1
Output
0001111111
001
01
0
1
-----Note-----
In the first test case, Lee can't perform any moves.
In the second test case, Lee should erase $s_2$.
In the third test case, Lee can make moves, for example, in the following order: 11001101Β $\rightarrow$ 1100101Β $\rightarrow$ 110101Β $\rightarrow$ 10101Β $\rightarrow$ 1101Β $\rightarrow$ 101Β $\rightarrow$ 01.
|
for _ in range(int(input())):
#n, m = map(int, input().split())
#A = list(map(int, input().split()))
n = int(input())
s = input()
if s == '0' * n or s == '1' * n:
print(s)
else:
i = 0
while s[i] == '0':
i += 1
j = n - 1
while s[j] == '1':
j -= 1
if '1' in s[i:j + 1] and '0' in s[i:j + 1]:
print(s[:i] + '0' + s[j + 1:])
else:
print(s)
|
You have three piles of candies: red, green and blue candies: the first pile contains only red candies and there are $r$ candies in it, the second pile contains only green candies and there are $g$ candies in it, the third pile contains only blue candies and there are $b$ candies in it.
Each day Tanya eats exactly two candies of different colors. She is free to choose the colors of eaten candies: the only restriction that she can't eat two candies of the same color in a day.
Find the maximal number of days Tanya can eat candies? Each day she needs to eat exactly two candies.
-----Input-----
The first line contains integer $t$ ($1 \le t \le 1000$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case is given as a separate line of the input. It contains three integers $r$, $g$ and $b$ ($1 \le r, g, b \le 10^8$) β the number of red, green and blue candies, respectively.
-----Output-----
Print $t$ integers: the $i$-th printed integer is the answer on the $i$-th test case in the input.
-----Example-----
Input
6
1 1 1
1 2 1
4 1 1
7 4 10
8 1 4
8 2 8
Output
1
2
2
10
5
9
-----Note-----
In the first example, Tanya can eat candies for one day only. She can eat any pair of candies this day because all of them have different colors.
In the second example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and green and blue candies on the second day.
In the third example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and red and blue candies on the second day. Note, that two red candies will remain uneaten.
|
n = int(input())
for _ in range(n):
a, b, c = list(map(int, input().split()))
print(min((a+b+c)//2, a+b, a+c, b+c))
|
You have three piles of candies: red, green and blue candies: the first pile contains only red candies and there are $r$ candies in it, the second pile contains only green candies and there are $g$ candies in it, the third pile contains only blue candies and there are $b$ candies in it.
Each day Tanya eats exactly two candies of different colors. She is free to choose the colors of eaten candies: the only restriction that she can't eat two candies of the same color in a day.
Find the maximal number of days Tanya can eat candies? Each day she needs to eat exactly two candies.
-----Input-----
The first line contains integer $t$ ($1 \le t \le 1000$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case is given as a separate line of the input. It contains three integers $r$, $g$ and $b$ ($1 \le r, g, b \le 10^8$) β the number of red, green and blue candies, respectively.
-----Output-----
Print $t$ integers: the $i$-th printed integer is the answer on the $i$-th test case in the input.
-----Example-----
Input
6
1 1 1
1 2 1
4 1 1
7 4 10
8 1 4
8 2 8
Output
1
2
2
10
5
9
-----Note-----
In the first example, Tanya can eat candies for one day only. She can eat any pair of candies this day because all of them have different colors.
In the second example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and green and blue candies on the second day.
In the third example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and red and blue candies on the second day. Note, that two red candies will remain uneaten.
|
t = int(input())
for _ in range(t):
li = list(map(int, input().split()))
li = sorted(li)
if li[0] + li[1] <= li[2]:
print(li[0] + li[1])
else:
print(sum(li) // 2)
|
You have three piles of candies: red, green and blue candies: the first pile contains only red candies and there are $r$ candies in it, the second pile contains only green candies and there are $g$ candies in it, the third pile contains only blue candies and there are $b$ candies in it.
Each day Tanya eats exactly two candies of different colors. She is free to choose the colors of eaten candies: the only restriction that she can't eat two candies of the same color in a day.
Find the maximal number of days Tanya can eat candies? Each day she needs to eat exactly two candies.
-----Input-----
The first line contains integer $t$ ($1 \le t \le 1000$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case is given as a separate line of the input. It contains three integers $r$, $g$ and $b$ ($1 \le r, g, b \le 10^8$) β the number of red, green and blue candies, respectively.
-----Output-----
Print $t$ integers: the $i$-th printed integer is the answer on the $i$-th test case in the input.
-----Example-----
Input
6
1 1 1
1 2 1
4 1 1
7 4 10
8 1 4
8 2 8
Output
1
2
2
10
5
9
-----Note-----
In the first example, Tanya can eat candies for one day only. She can eat any pair of candies this day because all of them have different colors.
In the second example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and green and blue candies on the second day.
In the third example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and red and blue candies on the second day. Note, that two red candies will remain uneaten.
|
for _ in range(int(input())):
l = sorted(map(int, input().split()))
print(min(sum(l) // 2, l[0] + l[1]))
|
You have three piles of candies: red, green and blue candies: the first pile contains only red candies and there are $r$ candies in it, the second pile contains only green candies and there are $g$ candies in it, the third pile contains only blue candies and there are $b$ candies in it.
Each day Tanya eats exactly two candies of different colors. She is free to choose the colors of eaten candies: the only restriction that she can't eat two candies of the same color in a day.
Find the maximal number of days Tanya can eat candies? Each day she needs to eat exactly two candies.
-----Input-----
The first line contains integer $t$ ($1 \le t \le 1000$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case is given as a separate line of the input. It contains three integers $r$, $g$ and $b$ ($1 \le r, g, b \le 10^8$) β the number of red, green and blue candies, respectively.
-----Output-----
Print $t$ integers: the $i$-th printed integer is the answer on the $i$-th test case in the input.
-----Example-----
Input
6
1 1 1
1 2 1
4 1 1
7 4 10
8 1 4
8 2 8
Output
1
2
2
10
5
9
-----Note-----
In the first example, Tanya can eat candies for one day only. She can eat any pair of candies this day because all of them have different colors.
In the second example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and green and blue candies on the second day.
In the third example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and red and blue candies on the second day. Note, that two red candies will remain uneaten.
|
for _ in range(int(input())):
l=sorted(list(map(int,input().split())))
print(min(l[0]+l[1],sum(l)//2))
|
You have three piles of candies: red, green and blue candies: the first pile contains only red candies and there are $r$ candies in it, the second pile contains only green candies and there are $g$ candies in it, the third pile contains only blue candies and there are $b$ candies in it.
Each day Tanya eats exactly two candies of different colors. She is free to choose the colors of eaten candies: the only restriction that she can't eat two candies of the same color in a day.
Find the maximal number of days Tanya can eat candies? Each day she needs to eat exactly two candies.
-----Input-----
The first line contains integer $t$ ($1 \le t \le 1000$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case is given as a separate line of the input. It contains three integers $r$, $g$ and $b$ ($1 \le r, g, b \le 10^8$) β the number of red, green and blue candies, respectively.
-----Output-----
Print $t$ integers: the $i$-th printed integer is the answer on the $i$-th test case in the input.
-----Example-----
Input
6
1 1 1
1 2 1
4 1 1
7 4 10
8 1 4
8 2 8
Output
1
2
2
10
5
9
-----Note-----
In the first example, Tanya can eat candies for one day only. She can eat any pair of candies this day because all of them have different colors.
In the second example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and green and blue candies on the second day.
In the third example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and red and blue candies on the second day. Note, that two red candies will remain uneaten.
|
t=int(input())
for _ in range(t):
a,b,c=list(map(int,input().split()))
a,b,c=sorted([a,b,c])
aa=a
bb=b
cc=c
d=c-b
c-=min(d,a)
a-=min(a,d)
b-=min(a//2,0)
a-=min(a//2,0)
c-=min(a,0)
a-=min(a,0)
b,c=sorted([b,c])
c-=b
b=0
print((aa+bb+cc-c)//2)
|
You have three piles of candies: red, green and blue candies: the first pile contains only red candies and there are $r$ candies in it, the second pile contains only green candies and there are $g$ candies in it, the third pile contains only blue candies and there are $b$ candies in it.
Each day Tanya eats exactly two candies of different colors. She is free to choose the colors of eaten candies: the only restriction that she can't eat two candies of the same color in a day.
Find the maximal number of days Tanya can eat candies? Each day she needs to eat exactly two candies.
-----Input-----
The first line contains integer $t$ ($1 \le t \le 1000$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case is given as a separate line of the input. It contains three integers $r$, $g$ and $b$ ($1 \le r, g, b \le 10^8$) β the number of red, green and blue candies, respectively.
-----Output-----
Print $t$ integers: the $i$-th printed integer is the answer on the $i$-th test case in the input.
-----Example-----
Input
6
1 1 1
1 2 1
4 1 1
7 4 10
8 1 4
8 2 8
Output
1
2
2
10
5
9
-----Note-----
In the first example, Tanya can eat candies for one day only. She can eat any pair of candies this day because all of them have different colors.
In the second example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and green and blue candies on the second day.
In the third example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and red and blue candies on the second day. Note, that two red candies will remain uneaten.
|
import sys
input = sys.stdin.readline
t=int(input())
for testcases in range(t):
r,g,b=sorted(map(int,input().split()))
if b>r+g:
print(r+g)
else:
print((r+g+b)//2)
|
You have three piles of candies: red, green and blue candies: the first pile contains only red candies and there are $r$ candies in it, the second pile contains only green candies and there are $g$ candies in it, the third pile contains only blue candies and there are $b$ candies in it.
Each day Tanya eats exactly two candies of different colors. She is free to choose the colors of eaten candies: the only restriction that she can't eat two candies of the same color in a day.
Find the maximal number of days Tanya can eat candies? Each day she needs to eat exactly two candies.
-----Input-----
The first line contains integer $t$ ($1 \le t \le 1000$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case is given as a separate line of the input. It contains three integers $r$, $g$ and $b$ ($1 \le r, g, b \le 10^8$) β the number of red, green and blue candies, respectively.
-----Output-----
Print $t$ integers: the $i$-th printed integer is the answer on the $i$-th test case in the input.
-----Example-----
Input
6
1 1 1
1 2 1
4 1 1
7 4 10
8 1 4
8 2 8
Output
1
2
2
10
5
9
-----Note-----
In the first example, Tanya can eat candies for one day only. She can eat any pair of candies this day because all of them have different colors.
In the second example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and green and blue candies on the second day.
In the third example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and red and blue candies on the second day. Note, that two red candies will remain uneaten.
|
t = int(input())
for i in range (t):
r, g, b = list(map(int,input().split()))
maxi = max(r, g, b)
total = r + g + b
if 2 * maxi > total:
print(total - maxi)
else:
print(total//2)
|
You have three piles of candies: red, green and blue candies: the first pile contains only red candies and there are $r$ candies in it, the second pile contains only green candies and there are $g$ candies in it, the third pile contains only blue candies and there are $b$ candies in it.
Each day Tanya eats exactly two candies of different colors. She is free to choose the colors of eaten candies: the only restriction that she can't eat two candies of the same color in a day.
Find the maximal number of days Tanya can eat candies? Each day she needs to eat exactly two candies.
-----Input-----
The first line contains integer $t$ ($1 \le t \le 1000$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case is given as a separate line of the input. It contains three integers $r$, $g$ and $b$ ($1 \le r, g, b \le 10^8$) β the number of red, green and blue candies, respectively.
-----Output-----
Print $t$ integers: the $i$-th printed integer is the answer on the $i$-th test case in the input.
-----Example-----
Input
6
1 1 1
1 2 1
4 1 1
7 4 10
8 1 4
8 2 8
Output
1
2
2
10
5
9
-----Note-----
In the first example, Tanya can eat candies for one day only. She can eat any pair of candies this day because all of them have different colors.
In the second example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and green and blue candies on the second day.
In the third example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and red and blue candies on the second day. Note, that two red candies will remain uneaten.
|
q=int(input())
for i in range(q):
r=[int(x) for x in input().split()]
print(min(int(sum(r)/2),sum(r)-max(r)))
|
You have three piles of candies: red, green and blue candies: the first pile contains only red candies and there are $r$ candies in it, the second pile contains only green candies and there are $g$ candies in it, the third pile contains only blue candies and there are $b$ candies in it.
Each day Tanya eats exactly two candies of different colors. She is free to choose the colors of eaten candies: the only restriction that she can't eat two candies of the same color in a day.
Find the maximal number of days Tanya can eat candies? Each day she needs to eat exactly two candies.
-----Input-----
The first line contains integer $t$ ($1 \le t \le 1000$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case is given as a separate line of the input. It contains three integers $r$, $g$ and $b$ ($1 \le r, g, b \le 10^8$) β the number of red, green and blue candies, respectively.
-----Output-----
Print $t$ integers: the $i$-th printed integer is the answer on the $i$-th test case in the input.
-----Example-----
Input
6
1 1 1
1 2 1
4 1 1
7 4 10
8 1 4
8 2 8
Output
1
2
2
10
5
9
-----Note-----
In the first example, Tanya can eat candies for one day only. She can eat any pair of candies this day because all of them have different colors.
In the second example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and green and blue candies on the second day.
In the third example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and red and blue candies on the second day. Note, that two red candies will remain uneaten.
|
T = int(input())
for t in range(T):
a, b, c = sorted(map(int, input().strip().split()))
d = c - b
v = a
if d > a:
v += min(c - a, b)
else:
a -= d
c -= d + a // 2
b -= a - a // 2
v += min(c, b)
print(v)
|
You have three piles of candies: red, green and blue candies: the first pile contains only red candies and there are $r$ candies in it, the second pile contains only green candies and there are $g$ candies in it, the third pile contains only blue candies and there are $b$ candies in it.
Each day Tanya eats exactly two candies of different colors. She is free to choose the colors of eaten candies: the only restriction that she can't eat two candies of the same color in a day.
Find the maximal number of days Tanya can eat candies? Each day she needs to eat exactly two candies.
-----Input-----
The first line contains integer $t$ ($1 \le t \le 1000$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case is given as a separate line of the input. It contains three integers $r$, $g$ and $b$ ($1 \le r, g, b \le 10^8$) β the number of red, green and blue candies, respectively.
-----Output-----
Print $t$ integers: the $i$-th printed integer is the answer on the $i$-th test case in the input.
-----Example-----
Input
6
1 1 1
1 2 1
4 1 1
7 4 10
8 1 4
8 2 8
Output
1
2
2
10
5
9
-----Note-----
In the first example, Tanya can eat candies for one day only. She can eat any pair of candies this day because all of them have different colors.
In the second example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and green and blue candies on the second day.
In the third example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and red and blue candies on the second day. Note, that two red candies will remain uneaten.
|
for i in range(int(input())):
a = sorted([int(i) for i in input().split()])
print(min(a[0]+a[1], sum(a)//2))
|
You have three piles of candies: red, green and blue candies: the first pile contains only red candies and there are $r$ candies in it, the second pile contains only green candies and there are $g$ candies in it, the third pile contains only blue candies and there are $b$ candies in it.
Each day Tanya eats exactly two candies of different colors. She is free to choose the colors of eaten candies: the only restriction that she can't eat two candies of the same color in a day.
Find the maximal number of days Tanya can eat candies? Each day she needs to eat exactly two candies.
-----Input-----
The first line contains integer $t$ ($1 \le t \le 1000$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case is given as a separate line of the input. It contains three integers $r$, $g$ and $b$ ($1 \le r, g, b \le 10^8$) β the number of red, green and blue candies, respectively.
-----Output-----
Print $t$ integers: the $i$-th printed integer is the answer on the $i$-th test case in the input.
-----Example-----
Input
6
1 1 1
1 2 1
4 1 1
7 4 10
8 1 4
8 2 8
Output
1
2
2
10
5
9
-----Note-----
In the first example, Tanya can eat candies for one day only. She can eat any pair of candies this day because all of them have different colors.
In the second example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and green and blue candies on the second day.
In the third example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and red and blue candies on the second day. Note, that two red candies will remain uneaten.
|
t = int(input())
for _ in range(t):
r, g, b = sorted(map(int, input().split()))
s = sum([r, g, b])
print(min([r + g, s // 2]))
|
You have three piles of candies: red, green and blue candies: the first pile contains only red candies and there are $r$ candies in it, the second pile contains only green candies and there are $g$ candies in it, the third pile contains only blue candies and there are $b$ candies in it.
Each day Tanya eats exactly two candies of different colors. She is free to choose the colors of eaten candies: the only restriction that she can't eat two candies of the same color in a day.
Find the maximal number of days Tanya can eat candies? Each day she needs to eat exactly two candies.
-----Input-----
The first line contains integer $t$ ($1 \le t \le 1000$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case is given as a separate line of the input. It contains three integers $r$, $g$ and $b$ ($1 \le r, g, b \le 10^8$) β the number of red, green and blue candies, respectively.
-----Output-----
Print $t$ integers: the $i$-th printed integer is the answer on the $i$-th test case in the input.
-----Example-----
Input
6
1 1 1
1 2 1
4 1 1
7 4 10
8 1 4
8 2 8
Output
1
2
2
10
5
9
-----Note-----
In the first example, Tanya can eat candies for one day only. She can eat any pair of candies this day because all of them have different colors.
In the second example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and green and blue candies on the second day.
In the third example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and red and blue candies on the second day. Note, that two red candies will remain uneaten.
|
def solve():
r,g,b = map(int, input().split())
a,b,c = sorted([r,g,b])
if a+b <= c:
ans = a+b
else:
ans = a+b+c
ans //= 2
print(ans)
t = int(input())
for i in range(t):
solve()
|
You have three piles of candies: red, green and blue candies: the first pile contains only red candies and there are $r$ candies in it, the second pile contains only green candies and there are $g$ candies in it, the third pile contains only blue candies and there are $b$ candies in it.
Each day Tanya eats exactly two candies of different colors. She is free to choose the colors of eaten candies: the only restriction that she can't eat two candies of the same color in a day.
Find the maximal number of days Tanya can eat candies? Each day she needs to eat exactly two candies.
-----Input-----
The first line contains integer $t$ ($1 \le t \le 1000$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case is given as a separate line of the input. It contains three integers $r$, $g$ and $b$ ($1 \le r, g, b \le 10^8$) β the number of red, green and blue candies, respectively.
-----Output-----
Print $t$ integers: the $i$-th printed integer is the answer on the $i$-th test case in the input.
-----Example-----
Input
6
1 1 1
1 2 1
4 1 1
7 4 10
8 1 4
8 2 8
Output
1
2
2
10
5
9
-----Note-----
In the first example, Tanya can eat candies for one day only. She can eat any pair of candies this day because all of them have different colors.
In the second example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and green and blue candies on the second day.
In the third example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and red and blue candies on the second day. Note, that two red candies will remain uneaten.
|
# https://codeforces.com/contest/1263/problem/A
t = int(input())
for i in range(t):
rgb = list(map(int, input().split()))
rgb.sort()
ans = min(sum(rgb) // 2, sum(rgb[:2]))
print(ans)
|
You have three piles of candies: red, green and blue candies: the first pile contains only red candies and there are $r$ candies in it, the second pile contains only green candies and there are $g$ candies in it, the third pile contains only blue candies and there are $b$ candies in it.
Each day Tanya eats exactly two candies of different colors. She is free to choose the colors of eaten candies: the only restriction that she can't eat two candies of the same color in a day.
Find the maximal number of days Tanya can eat candies? Each day she needs to eat exactly two candies.
-----Input-----
The first line contains integer $t$ ($1 \le t \le 1000$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case is given as a separate line of the input. It contains three integers $r$, $g$ and $b$ ($1 \le r, g, b \le 10^8$) β the number of red, green and blue candies, respectively.
-----Output-----
Print $t$ integers: the $i$-th printed integer is the answer on the $i$-th test case in the input.
-----Example-----
Input
6
1 1 1
1 2 1
4 1 1
7 4 10
8 1 4
8 2 8
Output
1
2
2
10
5
9
-----Note-----
In the first example, Tanya can eat candies for one day only. She can eat any pair of candies this day because all of them have different colors.
In the second example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and green and blue candies on the second day.
In the third example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and red and blue candies on the second day. Note, that two red candies will remain uneaten.
|
t=int(input())
for ij in range(0,t):
l=list(map(int,input().split()))
l=sorted(l)
if l[2]>l[1]+l[0]:
print(l[1]+l[0])
else:
print(sum(l)//2)
|
You have three piles of candies: red, green and blue candies: the first pile contains only red candies and there are $r$ candies in it, the second pile contains only green candies and there are $g$ candies in it, the third pile contains only blue candies and there are $b$ candies in it.
Each day Tanya eats exactly two candies of different colors. She is free to choose the colors of eaten candies: the only restriction that she can't eat two candies of the same color in a day.
Find the maximal number of days Tanya can eat candies? Each day she needs to eat exactly two candies.
-----Input-----
The first line contains integer $t$ ($1 \le t \le 1000$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case is given as a separate line of the input. It contains three integers $r$, $g$ and $b$ ($1 \le r, g, b \le 10^8$) β the number of red, green and blue candies, respectively.
-----Output-----
Print $t$ integers: the $i$-th printed integer is the answer on the $i$-th test case in the input.
-----Example-----
Input
6
1 1 1
1 2 1
4 1 1
7 4 10
8 1 4
8 2 8
Output
1
2
2
10
5
9
-----Note-----
In the first example, Tanya can eat candies for one day only. She can eat any pair of candies this day because all of them have different colors.
In the second example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and green and blue candies on the second day.
In the third example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and red and blue candies on the second day. Note, that two red candies will remain uneaten.
|
a = int(input())
for i in range(a):
x, y, z = map(int, input().split())
x, y, z = sorted([x, y, z])
k = z - y
if k == 0:
y += x//2
print(y)
elif k > x:
y += x
print(y)
else:
x -= z - y
y = z
z += x//2
print(z)
|
You have three piles of candies: red, green and blue candies: the first pile contains only red candies and there are $r$ candies in it, the second pile contains only green candies and there are $g$ candies in it, the third pile contains only blue candies and there are $b$ candies in it.
Each day Tanya eats exactly two candies of different colors. She is free to choose the colors of eaten candies: the only restriction that she can't eat two candies of the same color in a day.
Find the maximal number of days Tanya can eat candies? Each day she needs to eat exactly two candies.
-----Input-----
The first line contains integer $t$ ($1 \le t \le 1000$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case is given as a separate line of the input. It contains three integers $r$, $g$ and $b$ ($1 \le r, g, b \le 10^8$) β the number of red, green and blue candies, respectively.
-----Output-----
Print $t$ integers: the $i$-th printed integer is the answer on the $i$-th test case in the input.
-----Example-----
Input
6
1 1 1
1 2 1
4 1 1
7 4 10
8 1 4
8 2 8
Output
1
2
2
10
5
9
-----Note-----
In the first example, Tanya can eat candies for one day only. She can eat any pair of candies this day because all of them have different colors.
In the second example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and green and blue candies on the second day.
In the third example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and red and blue candies on the second day. Note, that two red candies will remain uneaten.
|
import sys
# sys.stdin = open("in.txt")
for _ in range(int(input())):
a, b, c = sorted(list(map(int, input().split())))
print((a + b + c - max(0, c - (a + b))) // 2)
# res = min(a, b)
# a -= res
# b -= res
# res2 = min(b, c)
# b -= res2
# c -= res2
# res3 = min(a, c)
# a -= res3
# c -= res3
# print(res + res2 + res3)
|
You have three piles of candies: red, green and blue candies: the first pile contains only red candies and there are $r$ candies in it, the second pile contains only green candies and there are $g$ candies in it, the third pile contains only blue candies and there are $b$ candies in it.
Each day Tanya eats exactly two candies of different colors. She is free to choose the colors of eaten candies: the only restriction that she can't eat two candies of the same color in a day.
Find the maximal number of days Tanya can eat candies? Each day she needs to eat exactly two candies.
-----Input-----
The first line contains integer $t$ ($1 \le t \le 1000$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case is given as a separate line of the input. It contains three integers $r$, $g$ and $b$ ($1 \le r, g, b \le 10^8$) β the number of red, green and blue candies, respectively.
-----Output-----
Print $t$ integers: the $i$-th printed integer is the answer on the $i$-th test case in the input.
-----Example-----
Input
6
1 1 1
1 2 1
4 1 1
7 4 10
8 1 4
8 2 8
Output
1
2
2
10
5
9
-----Note-----
In the first example, Tanya can eat candies for one day only. She can eat any pair of candies this day because all of them have different colors.
In the second example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and green and blue candies on the second day.
In the third example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and red and blue candies on the second day. Note, that two red candies will remain uneaten.
|
n = int(input())
for i in range(n):
a = sorted(list(map(int, input().split())))
if a[2] >= a[0]+a[1]:
print(a[0]+a[1])
else:
print(a[2]+(a[0]+a[1]-a[2])//2)
|
You have three piles of candies: red, green and blue candies: the first pile contains only red candies and there are $r$ candies in it, the second pile contains only green candies and there are $g$ candies in it, the third pile contains only blue candies and there are $b$ candies in it.
Each day Tanya eats exactly two candies of different colors. She is free to choose the colors of eaten candies: the only restriction that she can't eat two candies of the same color in a day.
Find the maximal number of days Tanya can eat candies? Each day she needs to eat exactly two candies.
-----Input-----
The first line contains integer $t$ ($1 \le t \le 1000$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case is given as a separate line of the input. It contains three integers $r$, $g$ and $b$ ($1 \le r, g, b \le 10^8$) β the number of red, green and blue candies, respectively.
-----Output-----
Print $t$ integers: the $i$-th printed integer is the answer on the $i$-th test case in the input.
-----Example-----
Input
6
1 1 1
1 2 1
4 1 1
7 4 10
8 1 4
8 2 8
Output
1
2
2
10
5
9
-----Note-----
In the first example, Tanya can eat candies for one day only. She can eat any pair of candies this day because all of them have different colors.
In the second example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and green and blue candies on the second day.
In the third example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and red and blue candies on the second day. Note, that two red candies will remain uneaten.
|
sp = lambda: list(map(int, input().split()))
si = lambda: int(input())
TESTCASES = int(input())
for tc in range(TESTCASES):
r,g,b=sorted(sp())
if b>r+g: b=r+g
print((r+g+b)//2)
|
You have three piles of candies: red, green and blue candies: the first pile contains only red candies and there are $r$ candies in it, the second pile contains only green candies and there are $g$ candies in it, the third pile contains only blue candies and there are $b$ candies in it.
Each day Tanya eats exactly two candies of different colors. She is free to choose the colors of eaten candies: the only restriction that she can't eat two candies of the same color in a day.
Find the maximal number of days Tanya can eat candies? Each day she needs to eat exactly two candies.
-----Input-----
The first line contains integer $t$ ($1 \le t \le 1000$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case is given as a separate line of the input. It contains three integers $r$, $g$ and $b$ ($1 \le r, g, b \le 10^8$) β the number of red, green and blue candies, respectively.
-----Output-----
Print $t$ integers: the $i$-th printed integer is the answer on the $i$-th test case in the input.
-----Example-----
Input
6
1 1 1
1 2 1
4 1 1
7 4 10
8 1 4
8 2 8
Output
1
2
2
10
5
9
-----Note-----
In the first example, Tanya can eat candies for one day only. She can eat any pair of candies this day because all of them have different colors.
In the second example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and green and blue candies on the second day.
In the third example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and red and blue candies on the second day. Note, that two red candies will remain uneaten.
|
t = int(input())
for i in range(t):
r, g, b = list(map(int, input().split()))
if 2 * max(r, g, b) >= (r + g + b):
print(r + g + b - max(r, g, b))
else:
print((r + g + b) // 2)
|
You have three piles of candies: red, green and blue candies: the first pile contains only red candies and there are $r$ candies in it, the second pile contains only green candies and there are $g$ candies in it, the third pile contains only blue candies and there are $b$ candies in it.
Each day Tanya eats exactly two candies of different colors. She is free to choose the colors of eaten candies: the only restriction that she can't eat two candies of the same color in a day.
Find the maximal number of days Tanya can eat candies? Each day she needs to eat exactly two candies.
-----Input-----
The first line contains integer $t$ ($1 \le t \le 1000$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case is given as a separate line of the input. It contains three integers $r$, $g$ and $b$ ($1 \le r, g, b \le 10^8$) β the number of red, green and blue candies, respectively.
-----Output-----
Print $t$ integers: the $i$-th printed integer is the answer on the $i$-th test case in the input.
-----Example-----
Input
6
1 1 1
1 2 1
4 1 1
7 4 10
8 1 4
8 2 8
Output
1
2
2
10
5
9
-----Note-----
In the first example, Tanya can eat candies for one day only. She can eat any pair of candies this day because all of them have different colors.
In the second example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and green and blue candies on the second day.
In the third example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and red and blue candies on the second day. Note, that two red candies will remain uneaten.
|
t=int(input())
for i in range(t):
r,g,b = map(int,input().split())
arr = [r,g,b]
arr.sort()
diff = arr[2]-arr[1]
arr[2] -= arr[0]
if arr[2] < arr[1]:
arr[2] = int((arr[1]+arr[2])/2)
arr[1] = arr[2]
print(arr[0]+min(arr[2],arr[1]))
|
You have three piles of candies: red, green and blue candies: the first pile contains only red candies and there are $r$ candies in it, the second pile contains only green candies and there are $g$ candies in it, the third pile contains only blue candies and there are $b$ candies in it.
Each day Tanya eats exactly two candies of different colors. She is free to choose the colors of eaten candies: the only restriction that she can't eat two candies of the same color in a day.
Find the maximal number of days Tanya can eat candies? Each day she needs to eat exactly two candies.
-----Input-----
The first line contains integer $t$ ($1 \le t \le 1000$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case is given as a separate line of the input. It contains three integers $r$, $g$ and $b$ ($1 \le r, g, b \le 10^8$) β the number of red, green and blue candies, respectively.
-----Output-----
Print $t$ integers: the $i$-th printed integer is the answer on the $i$-th test case in the input.
-----Example-----
Input
6
1 1 1
1 2 1
4 1 1
7 4 10
8 1 4
8 2 8
Output
1
2
2
10
5
9
-----Note-----
In the first example, Tanya can eat candies for one day only. She can eat any pair of candies this day because all of them have different colors.
In the second example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and green and blue candies on the second day.
In the third example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and red and blue candies on the second day. Note, that two red candies will remain uneaten.
|
for _ in range(int(input())):
l =list( map( int, input().split()) )
l.sort()
s, m , b = l
a = s
c = min( s, b - m )
s -= c
b -= c
b -= s // 2
m -= s - s // 2
a += min( m, b )
print( a )
|
You have three piles of candies: red, green and blue candies: the first pile contains only red candies and there are $r$ candies in it, the second pile contains only green candies and there are $g$ candies in it, the third pile contains only blue candies and there are $b$ candies in it.
Each day Tanya eats exactly two candies of different colors. She is free to choose the colors of eaten candies: the only restriction that she can't eat two candies of the same color in a day.
Find the maximal number of days Tanya can eat candies? Each day she needs to eat exactly two candies.
-----Input-----
The first line contains integer $t$ ($1 \le t \le 1000$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case is given as a separate line of the input. It contains three integers $r$, $g$ and $b$ ($1 \le r, g, b \le 10^8$) β the number of red, green and blue candies, respectively.
-----Output-----
Print $t$ integers: the $i$-th printed integer is the answer on the $i$-th test case in the input.
-----Example-----
Input
6
1 1 1
1 2 1
4 1 1
7 4 10
8 1 4
8 2 8
Output
1
2
2
10
5
9
-----Note-----
In the first example, Tanya can eat candies for one day only. She can eat any pair of candies this day because all of them have different colors.
In the second example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and green and blue candies on the second day.
In the third example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and red and blue candies on the second day. Note, that two red candies will remain uneaten.
|
n = int(input())
while n != 0:
n -= 1
a = list(map(int, input().split()))
a.sort()
if a[0] + a[1] >= a[2]:
print(sum(a)//2)
else:
print(a[0] + a[1])
|
You have three piles of candies: red, green and blue candies: the first pile contains only red candies and there are $r$ candies in it, the second pile contains only green candies and there are $g$ candies in it, the third pile contains only blue candies and there are $b$ candies in it.
Each day Tanya eats exactly two candies of different colors. She is free to choose the colors of eaten candies: the only restriction that she can't eat two candies of the same color in a day.
Find the maximal number of days Tanya can eat candies? Each day she needs to eat exactly two candies.
-----Input-----
The first line contains integer $t$ ($1 \le t \le 1000$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case is given as a separate line of the input. It contains three integers $r$, $g$ and $b$ ($1 \le r, g, b \le 10^8$) β the number of red, green and blue candies, respectively.
-----Output-----
Print $t$ integers: the $i$-th printed integer is the answer on the $i$-th test case in the input.
-----Example-----
Input
6
1 1 1
1 2 1
4 1 1
7 4 10
8 1 4
8 2 8
Output
1
2
2
10
5
9
-----Note-----
In the first example, Tanya can eat candies for one day only. She can eat any pair of candies this day because all of them have different colors.
In the second example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and green and blue candies on the second day.
In the third example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and red and blue candies on the second day. Note, that two red candies will remain uneaten.
|
import sys
# inf = open('input.txt', 'r')
# reader = (map(int, line.split()) for line in inf)
reader = (list(map(int, s.split())) for s in sys.stdin)
def sweets(r, g, b):
total = g - r
g -= total
b -= total
if b > r + g:
total += r + g
else:
total += (r + b + g) // 2
return total
t, = next(reader)
for _ in range(t):
r, g, b = sorted(list(next(reader)))
ans = sweets(r, g, b)
print(ans)
# inf.close()
|
You have three piles of candies: red, green and blue candies: the first pile contains only red candies and there are $r$ candies in it, the second pile contains only green candies and there are $g$ candies in it, the third pile contains only blue candies and there are $b$ candies in it.
Each day Tanya eats exactly two candies of different colors. She is free to choose the colors of eaten candies: the only restriction that she can't eat two candies of the same color in a day.
Find the maximal number of days Tanya can eat candies? Each day she needs to eat exactly two candies.
-----Input-----
The first line contains integer $t$ ($1 \le t \le 1000$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case is given as a separate line of the input. It contains three integers $r$, $g$ and $b$ ($1 \le r, g, b \le 10^8$) β the number of red, green and blue candies, respectively.
-----Output-----
Print $t$ integers: the $i$-th printed integer is the answer on the $i$-th test case in the input.
-----Example-----
Input
6
1 1 1
1 2 1
4 1 1
7 4 10
8 1 4
8 2 8
Output
1
2
2
10
5
9
-----Note-----
In the first example, Tanya can eat candies for one day only. She can eat any pair of candies this day because all of them have different colors.
In the second example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and green and blue candies on the second day.
In the third example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and red and blue candies on the second day. Note, that two red candies will remain uneaten.
|
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
candy = [int(item) for item in input().split()]
candy.sort(reverse=True)
total = sum(candy)
if candy[0] <= candy[1] + candy[2]:
print((total - total % 2) // 2)
else:
print(total - (candy[0] - candy[1] - candy[2]) // 2)
|
You have three piles of candies: red, green and blue candies: the first pile contains only red candies and there are $r$ candies in it, the second pile contains only green candies and there are $g$ candies in it, the third pile contains only blue candies and there are $b$ candies in it.
Each day Tanya eats exactly two candies of different colors. She is free to choose the colors of eaten candies: the only restriction that she can't eat two candies of the same color in a day.
Find the maximal number of days Tanya can eat candies? Each day she needs to eat exactly two candies.
-----Input-----
The first line contains integer $t$ ($1 \le t \le 1000$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case is given as a separate line of the input. It contains three integers $r$, $g$ and $b$ ($1 \le r, g, b \le 10^8$) β the number of red, green and blue candies, respectively.
-----Output-----
Print $t$ integers: the $i$-th printed integer is the answer on the $i$-th test case in the input.
-----Example-----
Input
6
1 1 1
1 2 1
4 1 1
7 4 10
8 1 4
8 2 8
Output
1
2
2
10
5
9
-----Note-----
In the first example, Tanya can eat candies for one day only. She can eat any pair of candies this day because all of them have different colors.
In the second example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and green and blue candies on the second day.
In the third example, Tanya can eat candies for two days. For example, she can eat red and green candies on the first day, and red and blue candies on the second day. Note, that two red candies will remain uneaten.
|
from math import *
from collections import *
import sys
sys.setrecursionlimit(10**9)
t = int(input())
for y in range(t):
r,g,b = list(map(int,input().split()))
m = max(r,g,b)
if(r + g + b - m >= m):
ans = (r+g+b)//2
else:
ans = r+g+b - m
print(ans)
|
Polycarp lives on the coordinate axis $Ox$ and travels from the point $x=a$ to $x=b$. It moves uniformly rectilinearly at a speed of one unit of distance per minute.
On the axis $Ox$ at the point $x=c$ the base station of the mobile operator is placed. It is known that the radius of its coverage is $r$. Thus, if Polycarp is at a distance less than or equal to $r$ from the point $x=c$, then he is in the network coverage area, otherwiseΒ β no. The base station can be located both on the route of Polycarp and outside it.
Print the time in minutes during which Polycarp will not be in the coverage area of the network, with a rectilinear uniform movement from $x=a$ to $x=b$. His speedΒ β one unit of distance per minute.
-----Input-----
The first line contains a positive integer $t$ ($1 \le t \le 1000$)Β β the number of test cases. In the following lines are written $t$ test cases.
The description of each test case is one line, which contains four integers $a$, $b$, $c$ and $r$ ($-10^8 \le a,b,c \le 10^8$, $0 \le r \le 10^8$)Β β the coordinates of the starting and ending points of the path, the base station, and its coverage radius, respectively.
Any of the numbers $a$, $b$ and $c$ can be equal (either any pair or all three numbers). The base station can be located both on the route of Polycarp and outside it.
-----Output-----
Print $t$ numbersΒ β answers to given test cases in the order they are written in the test. Each answer is an integerΒ β the number of minutes during which Polycarp will be unavailable during his movement.
-----Example-----
Input
9
1 10 7 1
3 3 3 0
8 2 10 4
8 2 10 100
-10 20 -17 2
-3 2 2 0
-3 1 2 0
2 3 2 3
-1 3 -2 2
Output
7
0
4
0
30
5
4
0
3
-----Note-----
The following picture illustrates the first test case. [Image] Polycarp goes from $1$ to $10$. The yellow area shows the coverage area of the station with a radius of coverage of $1$, which is located at the point of $7$. The green area shows a part of the path when Polycarp is out of coverage area.
|
import os
from io import BytesIO
# input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
for i in range(int(input())):
a, b, c, r = list(map(int, input().split()))
a, b = min(a, b), max(a, b)
left = max(c - r, a)
right = min(c + r, b)
if right >= a and left <= right:
print(b - a - (right - left))
else:
print(b - a)
|
Polycarp lives on the coordinate axis $Ox$ and travels from the point $x=a$ to $x=b$. It moves uniformly rectilinearly at a speed of one unit of distance per minute.
On the axis $Ox$ at the point $x=c$ the base station of the mobile operator is placed. It is known that the radius of its coverage is $r$. Thus, if Polycarp is at a distance less than or equal to $r$ from the point $x=c$, then he is in the network coverage area, otherwiseΒ β no. The base station can be located both on the route of Polycarp and outside it.
Print the time in minutes during which Polycarp will not be in the coverage area of the network, with a rectilinear uniform movement from $x=a$ to $x=b$. His speedΒ β one unit of distance per minute.
-----Input-----
The first line contains a positive integer $t$ ($1 \le t \le 1000$)Β β the number of test cases. In the following lines are written $t$ test cases.
The description of each test case is one line, which contains four integers $a$, $b$, $c$ and $r$ ($-10^8 \le a,b,c \le 10^8$, $0 \le r \le 10^8$)Β β the coordinates of the starting and ending points of the path, the base station, and its coverage radius, respectively.
Any of the numbers $a$, $b$ and $c$ can be equal (either any pair or all three numbers). The base station can be located both on the route of Polycarp and outside it.
-----Output-----
Print $t$ numbersΒ β answers to given test cases in the order they are written in the test. Each answer is an integerΒ β the number of minutes during which Polycarp will be unavailable during his movement.
-----Example-----
Input
9
1 10 7 1
3 3 3 0
8 2 10 4
8 2 10 100
-10 20 -17 2
-3 2 2 0
-3 1 2 0
2 3 2 3
-1 3 -2 2
Output
7
0
4
0
30
5
4
0
3
-----Note-----
The following picture illustrates the first test case. [Image] Polycarp goes from $1$ to $10$. The yellow area shows the coverage area of the station with a radius of coverage of $1$, which is located at the point of $7$. The green area shows a part of the path when Polycarp is out of coverage area.
|
from math import *
import os, sys
from io import BytesIO
#input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
sys.setrecursionlimit(10 ** 9)
#sys.stdin = open("moobuzz.in", 'r')
#sys.stdout = open("moobuzz.out", 'w')
for i in range(int(input())):
a, b, c, r = list(map(int, input().split()))
c1 = c - r
c2 = c + r
d1 = max(min(a, b), min(c1, c2))
d2 = min(max(a, b), max(c1, c2))
print(abs(b - a) - max(d2 - d1, 0))
|
Polycarp lives on the coordinate axis $Ox$ and travels from the point $x=a$ to $x=b$. It moves uniformly rectilinearly at a speed of one unit of distance per minute.
On the axis $Ox$ at the point $x=c$ the base station of the mobile operator is placed. It is known that the radius of its coverage is $r$. Thus, if Polycarp is at a distance less than or equal to $r$ from the point $x=c$, then he is in the network coverage area, otherwiseΒ β no. The base station can be located both on the route of Polycarp and outside it.
Print the time in minutes during which Polycarp will not be in the coverage area of the network, with a rectilinear uniform movement from $x=a$ to $x=b$. His speedΒ β one unit of distance per minute.
-----Input-----
The first line contains a positive integer $t$ ($1 \le t \le 1000$)Β β the number of test cases. In the following lines are written $t$ test cases.
The description of each test case is one line, which contains four integers $a$, $b$, $c$ and $r$ ($-10^8 \le a,b,c \le 10^8$, $0 \le r \le 10^8$)Β β the coordinates of the starting and ending points of the path, the base station, and its coverage radius, respectively.
Any of the numbers $a$, $b$ and $c$ can be equal (either any pair or all three numbers). The base station can be located both on the route of Polycarp and outside it.
-----Output-----
Print $t$ numbersΒ β answers to given test cases in the order they are written in the test. Each answer is an integerΒ β the number of minutes during which Polycarp will be unavailable during his movement.
-----Example-----
Input
9
1 10 7 1
3 3 3 0
8 2 10 4
8 2 10 100
-10 20 -17 2
-3 2 2 0
-3 1 2 0
2 3 2 3
-1 3 -2 2
Output
7
0
4
0
30
5
4
0
3
-----Note-----
The following picture illustrates the first test case. [Image] Polycarp goes from $1$ to $10$. The yellow area shows the coverage area of the station with a radius of coverage of $1$, which is located at the point of $7$. The green area shows a part of the path when Polycarp is out of coverage area.
|
t = int(input())
for i in range(t):
a, b, c, r = list(map(int, input().split()))
s = max(min(a, b), c - r)
f = min(max(a, b), c + r)
l = max(0, f - s)
print(abs(a - b) - l)
|
Polycarp lives on the coordinate axis $Ox$ and travels from the point $x=a$ to $x=b$. It moves uniformly rectilinearly at a speed of one unit of distance per minute.
On the axis $Ox$ at the point $x=c$ the base station of the mobile operator is placed. It is known that the radius of its coverage is $r$. Thus, if Polycarp is at a distance less than or equal to $r$ from the point $x=c$, then he is in the network coverage area, otherwiseΒ β no. The base station can be located both on the route of Polycarp and outside it.
Print the time in minutes during which Polycarp will not be in the coverage area of the network, with a rectilinear uniform movement from $x=a$ to $x=b$. His speedΒ β one unit of distance per minute.
-----Input-----
The first line contains a positive integer $t$ ($1 \le t \le 1000$)Β β the number of test cases. In the following lines are written $t$ test cases.
The description of each test case is one line, which contains four integers $a$, $b$, $c$ and $r$ ($-10^8 \le a,b,c \le 10^8$, $0 \le r \le 10^8$)Β β the coordinates of the starting and ending points of the path, the base station, and its coverage radius, respectively.
Any of the numbers $a$, $b$ and $c$ can be equal (either any pair or all three numbers). The base station can be located both on the route of Polycarp and outside it.
-----Output-----
Print $t$ numbersΒ β answers to given test cases in the order they are written in the test. Each answer is an integerΒ β the number of minutes during which Polycarp will be unavailable during his movement.
-----Example-----
Input
9
1 10 7 1
3 3 3 0
8 2 10 4
8 2 10 100
-10 20 -17 2
-3 2 2 0
-3 1 2 0
2 3 2 3
-1 3 -2 2
Output
7
0
4
0
30
5
4
0
3
-----Note-----
The following picture illustrates the first test case. [Image] Polycarp goes from $1$ to $10$. The yellow area shows the coverage area of the station with a radius of coverage of $1$, which is located at the point of $7$. The green area shows a part of the path when Polycarp is out of coverage area.
|
#!/usr/bin/env python3
# coding: utf-8
# Last Modified: 24/Dec/19 08:08:49 PM
import sys
def main():
for tc in range(int(input())):
a, b, c, r = get_ints()
if a > b:
a, b = b, a
arr = [c - r, c + r]
ans = 0
if a > c + r:
print(abs(b - a))
continue
if b < c - r:
print(abs(b - a))
continue
if a < c - r:
ans += abs(a - (c - r))
if b > c + r:
ans += abs(b - (c + r))
print(ans)
get_array = lambda: list(map(int, sys.stdin.readline().split()))
get_ints = lambda: list(map(int, sys.stdin.readline().split()))
input = lambda: sys.stdin.readline().strip()
def __starting_point():
main()
__starting_point()
|
Polycarp lives on the coordinate axis $Ox$ and travels from the point $x=a$ to $x=b$. It moves uniformly rectilinearly at a speed of one unit of distance per minute.
On the axis $Ox$ at the point $x=c$ the base station of the mobile operator is placed. It is known that the radius of its coverage is $r$. Thus, if Polycarp is at a distance less than or equal to $r$ from the point $x=c$, then he is in the network coverage area, otherwiseΒ β no. The base station can be located both on the route of Polycarp and outside it.
Print the time in minutes during which Polycarp will not be in the coverage area of the network, with a rectilinear uniform movement from $x=a$ to $x=b$. His speedΒ β one unit of distance per minute.
-----Input-----
The first line contains a positive integer $t$ ($1 \le t \le 1000$)Β β the number of test cases. In the following lines are written $t$ test cases.
The description of each test case is one line, which contains four integers $a$, $b$, $c$ and $r$ ($-10^8 \le a,b,c \le 10^8$, $0 \le r \le 10^8$)Β β the coordinates of the starting and ending points of the path, the base station, and its coverage radius, respectively.
Any of the numbers $a$, $b$ and $c$ can be equal (either any pair or all three numbers). The base station can be located both on the route of Polycarp and outside it.
-----Output-----
Print $t$ numbersΒ β answers to given test cases in the order they are written in the test. Each answer is an integerΒ β the number of minutes during which Polycarp will be unavailable during his movement.
-----Example-----
Input
9
1 10 7 1
3 3 3 0
8 2 10 4
8 2 10 100
-10 20 -17 2
-3 2 2 0
-3 1 2 0
2 3 2 3
-1 3 -2 2
Output
7
0
4
0
30
5
4
0
3
-----Note-----
The following picture illustrates the first test case. [Image] Polycarp goes from $1$ to $10$. The yellow area shows the coverage area of the station with a radius of coverage of $1$, which is located at the point of $7$. The green area shows a part of the path when Polycarp is out of coverage area.
|
for _ in range(int(input())):
a,b,c,r=map(int,input().split())
a,b=min(a,b),max(a,b)
n = b - a
l,f = c-r,c+r
if a>l:
a,b,l,f=l,f,a,b
# print (a,b,l,f)
if l >= b:
print (n)
else:
if f <= b:
print (n - (f - l))
else:
print (n - (b - l))
|
Polycarp lives on the coordinate axis $Ox$ and travels from the point $x=a$ to $x=b$. It moves uniformly rectilinearly at a speed of one unit of distance per minute.
On the axis $Ox$ at the point $x=c$ the base station of the mobile operator is placed. It is known that the radius of its coverage is $r$. Thus, if Polycarp is at a distance less than or equal to $r$ from the point $x=c$, then he is in the network coverage area, otherwiseΒ β no. The base station can be located both on the route of Polycarp and outside it.
Print the time in minutes during which Polycarp will not be in the coverage area of the network, with a rectilinear uniform movement from $x=a$ to $x=b$. His speedΒ β one unit of distance per minute.
-----Input-----
The first line contains a positive integer $t$ ($1 \le t \le 1000$)Β β the number of test cases. In the following lines are written $t$ test cases.
The description of each test case is one line, which contains four integers $a$, $b$, $c$ and $r$ ($-10^8 \le a,b,c \le 10^8$, $0 \le r \le 10^8$)Β β the coordinates of the starting and ending points of the path, the base station, and its coverage radius, respectively.
Any of the numbers $a$, $b$ and $c$ can be equal (either any pair or all three numbers). The base station can be located both on the route of Polycarp and outside it.
-----Output-----
Print $t$ numbersΒ β answers to given test cases in the order they are written in the test. Each answer is an integerΒ β the number of minutes during which Polycarp will be unavailable during his movement.
-----Example-----
Input
9
1 10 7 1
3 3 3 0
8 2 10 4
8 2 10 100
-10 20 -17 2
-3 2 2 0
-3 1 2 0
2 3 2 3
-1 3 -2 2
Output
7
0
4
0
30
5
4
0
3
-----Note-----
The following picture illustrates the first test case. [Image] Polycarp goes from $1$ to $10$. The yellow area shows the coverage area of the station with a radius of coverage of $1$, which is located at the point of $7$. The green area shows a part of the path when Polycarp is out of coverage area.
|
t = int(input())
for i in range(t):
a, b, c, r = list(map(int, input().split()))
if b < a:
a, b = b, a
k = min(c + r, b) - max(c - r, a)
d = b - a
if k <= 0:
print(d)
else:
print(d - k)
|
Polycarp lives on the coordinate axis $Ox$ and travels from the point $x=a$ to $x=b$. It moves uniformly rectilinearly at a speed of one unit of distance per minute.
On the axis $Ox$ at the point $x=c$ the base station of the mobile operator is placed. It is known that the radius of its coverage is $r$. Thus, if Polycarp is at a distance less than or equal to $r$ from the point $x=c$, then he is in the network coverage area, otherwiseΒ β no. The base station can be located both on the route of Polycarp and outside it.
Print the time in minutes during which Polycarp will not be in the coverage area of the network, with a rectilinear uniform movement from $x=a$ to $x=b$. His speedΒ β one unit of distance per minute.
-----Input-----
The first line contains a positive integer $t$ ($1 \le t \le 1000$)Β β the number of test cases. In the following lines are written $t$ test cases.
The description of each test case is one line, which contains four integers $a$, $b$, $c$ and $r$ ($-10^8 \le a,b,c \le 10^8$, $0 \le r \le 10^8$)Β β the coordinates of the starting and ending points of the path, the base station, and its coverage radius, respectively.
Any of the numbers $a$, $b$ and $c$ can be equal (either any pair or all three numbers). The base station can be located both on the route of Polycarp and outside it.
-----Output-----
Print $t$ numbersΒ β answers to given test cases in the order they are written in the test. Each answer is an integerΒ β the number of minutes during which Polycarp will be unavailable during his movement.
-----Example-----
Input
9
1 10 7 1
3 3 3 0
8 2 10 4
8 2 10 100
-10 20 -17 2
-3 2 2 0
-3 1 2 0
2 3 2 3
-1 3 -2 2
Output
7
0
4
0
30
5
4
0
3
-----Note-----
The following picture illustrates the first test case. [Image] Polycarp goes from $1$ to $10$. The yellow area shows the coverage area of the station with a radius of coverage of $1$, which is located at the point of $7$. The green area shows a part of the path when Polycarp is out of coverage area.
|
import sys
def minp():
return sys.stdin.readline().strip()
def mint():
return int(minp())
def mints():
return list(map(int,minp().split()))
def solve():
a,b,c,r = mints()
if a > b:
a, b = b, a
return b-a-max(min(c+r,b)-max(c-r,a), 0)
for i in range(mint()):
print(solve())
|
Polycarp lives on the coordinate axis $Ox$ and travels from the point $x=a$ to $x=b$. It moves uniformly rectilinearly at a speed of one unit of distance per minute.
On the axis $Ox$ at the point $x=c$ the base station of the mobile operator is placed. It is known that the radius of its coverage is $r$. Thus, if Polycarp is at a distance less than or equal to $r$ from the point $x=c$, then he is in the network coverage area, otherwiseΒ β no. The base station can be located both on the route of Polycarp and outside it.
Print the time in minutes during which Polycarp will not be in the coverage area of the network, with a rectilinear uniform movement from $x=a$ to $x=b$. His speedΒ β one unit of distance per minute.
-----Input-----
The first line contains a positive integer $t$ ($1 \le t \le 1000$)Β β the number of test cases. In the following lines are written $t$ test cases.
The description of each test case is one line, which contains four integers $a$, $b$, $c$ and $r$ ($-10^8 \le a,b,c \le 10^8$, $0 \le r \le 10^8$)Β β the coordinates of the starting and ending points of the path, the base station, and its coverage radius, respectively.
Any of the numbers $a$, $b$ and $c$ can be equal (either any pair or all three numbers). The base station can be located both on the route of Polycarp and outside it.
-----Output-----
Print $t$ numbersΒ β answers to given test cases in the order they are written in the test. Each answer is an integerΒ β the number of minutes during which Polycarp will be unavailable during his movement.
-----Example-----
Input
9
1 10 7 1
3 3 3 0
8 2 10 4
8 2 10 100
-10 20 -17 2
-3 2 2 0
-3 1 2 0
2 3 2 3
-1 3 -2 2
Output
7
0
4
0
30
5
4
0
3
-----Note-----
The following picture illustrates the first test case. [Image] Polycarp goes from $1$ to $10$. The yellow area shows the coverage area of the station with a radius of coverage of $1$, which is located at the point of $7$. The green area shows a part of the path when Polycarp is out of coverage area.
|
for tcase in range(int(input())):
a,b,c,r = list(map(int, input().split()))
ca, cb = c-r, c+r
a,b = min(a,b), max(a,b)
if b<=ca:
print(b-a)
elif cb<=a:
print(b-a)
elif a<=ca<=b<=cb:
print(ca-a)
elif ca<=a<=cb<=b:
print(b-cb)
elif a<=ca<=cb<=b:
print((ca-a)+(b-cb))
elif ca<=a<=b<=cb:
print(0)
else:
print(0)
|
Polycarp lives on the coordinate axis $Ox$ and travels from the point $x=a$ to $x=b$. It moves uniformly rectilinearly at a speed of one unit of distance per minute.
On the axis $Ox$ at the point $x=c$ the base station of the mobile operator is placed. It is known that the radius of its coverage is $r$. Thus, if Polycarp is at a distance less than or equal to $r$ from the point $x=c$, then he is in the network coverage area, otherwiseΒ β no. The base station can be located both on the route of Polycarp and outside it.
Print the time in minutes during which Polycarp will not be in the coverage area of the network, with a rectilinear uniform movement from $x=a$ to $x=b$. His speedΒ β one unit of distance per minute.
-----Input-----
The first line contains a positive integer $t$ ($1 \le t \le 1000$)Β β the number of test cases. In the following lines are written $t$ test cases.
The description of each test case is one line, which contains four integers $a$, $b$, $c$ and $r$ ($-10^8 \le a,b,c \le 10^8$, $0 \le r \le 10^8$)Β β the coordinates of the starting and ending points of the path, the base station, and its coverage radius, respectively.
Any of the numbers $a$, $b$ and $c$ can be equal (either any pair or all three numbers). The base station can be located both on the route of Polycarp and outside it.
-----Output-----
Print $t$ numbersΒ β answers to given test cases in the order they are written in the test. Each answer is an integerΒ β the number of minutes during which Polycarp will be unavailable during his movement.
-----Example-----
Input
9
1 10 7 1
3 3 3 0
8 2 10 4
8 2 10 100
-10 20 -17 2
-3 2 2 0
-3 1 2 0
2 3 2 3
-1 3 -2 2
Output
7
0
4
0
30
5
4
0
3
-----Note-----
The following picture illustrates the first test case. [Image] Polycarp goes from $1$ to $10$. The yellow area shows the coverage area of the station with a radius of coverage of $1$, which is located at the point of $7$. The green area shows a part of the path when Polycarp is out of coverage area.
|
import sys
from collections import Counter
from math import *
# sys.stdin = open("in.txt")
for _ in range(int(input())):
a, b, c, r = map(int, input().split())
if b < a:
a, b = b, a
res1 = max(a, c - r)
res2 = min(b, c + r)
print(max(0, b - a - max(0, res2 - res1)))
|
Polycarp lives on the coordinate axis $Ox$ and travels from the point $x=a$ to $x=b$. It moves uniformly rectilinearly at a speed of one unit of distance per minute.
On the axis $Ox$ at the point $x=c$ the base station of the mobile operator is placed. It is known that the radius of its coverage is $r$. Thus, if Polycarp is at a distance less than or equal to $r$ from the point $x=c$, then he is in the network coverage area, otherwiseΒ β no. The base station can be located both on the route of Polycarp and outside it.
Print the time in minutes during which Polycarp will not be in the coverage area of the network, with a rectilinear uniform movement from $x=a$ to $x=b$. His speedΒ β one unit of distance per minute.
-----Input-----
The first line contains a positive integer $t$ ($1 \le t \le 1000$)Β β the number of test cases. In the following lines are written $t$ test cases.
The description of each test case is one line, which contains four integers $a$, $b$, $c$ and $r$ ($-10^8 \le a,b,c \le 10^8$, $0 \le r \le 10^8$)Β β the coordinates of the starting and ending points of the path, the base station, and its coverage radius, respectively.
Any of the numbers $a$, $b$ and $c$ can be equal (either any pair or all three numbers). The base station can be located both on the route of Polycarp and outside it.
-----Output-----
Print $t$ numbersΒ β answers to given test cases in the order they are written in the test. Each answer is an integerΒ β the number of minutes during which Polycarp will be unavailable during his movement.
-----Example-----
Input
9
1 10 7 1
3 3 3 0
8 2 10 4
8 2 10 100
-10 20 -17 2
-3 2 2 0
-3 1 2 0
2 3 2 3
-1 3 -2 2
Output
7
0
4
0
30
5
4
0
3
-----Note-----
The following picture illustrates the first test case. [Image] Polycarp goes from $1$ to $10$. The yellow area shows the coverage area of the station with a radius of coverage of $1$, which is located at the point of $7$. The green area shows a part of the path when Polycarp is out of coverage area.
|
for _ in range(int(input())):
a,b,c,r = map(int,input().split())
if a > b: a,b = b,a
x = max(c-r,a)
y = min(c+r,b)
ans = b-a
ans -= max(0,y-x)
print(max(ans,0))
|
Polycarp lives on the coordinate axis $Ox$ and travels from the point $x=a$ to $x=b$. It moves uniformly rectilinearly at a speed of one unit of distance per minute.
On the axis $Ox$ at the point $x=c$ the base station of the mobile operator is placed. It is known that the radius of its coverage is $r$. Thus, if Polycarp is at a distance less than or equal to $r$ from the point $x=c$, then he is in the network coverage area, otherwiseΒ β no. The base station can be located both on the route of Polycarp and outside it.
Print the time in minutes during which Polycarp will not be in the coverage area of the network, with a rectilinear uniform movement from $x=a$ to $x=b$. His speedΒ β one unit of distance per minute.
-----Input-----
The first line contains a positive integer $t$ ($1 \le t \le 1000$)Β β the number of test cases. In the following lines are written $t$ test cases.
The description of each test case is one line, which contains four integers $a$, $b$, $c$ and $r$ ($-10^8 \le a,b,c \le 10^8$, $0 \le r \le 10^8$)Β β the coordinates of the starting and ending points of the path, the base station, and its coverage radius, respectively.
Any of the numbers $a$, $b$ and $c$ can be equal (either any pair or all three numbers). The base station can be located both on the route of Polycarp and outside it.
-----Output-----
Print $t$ numbersΒ β answers to given test cases in the order they are written in the test. Each answer is an integerΒ β the number of minutes during which Polycarp will be unavailable during his movement.
-----Example-----
Input
9
1 10 7 1
3 3 3 0
8 2 10 4
8 2 10 100
-10 20 -17 2
-3 2 2 0
-3 1 2 0
2 3 2 3
-1 3 -2 2
Output
7
0
4
0
30
5
4
0
3
-----Note-----
The following picture illustrates the first test case. [Image] Polycarp goes from $1$ to $10$. The yellow area shows the coverage area of the station with a radius of coverage of $1$, which is located at the point of $7$. The green area shows a part of the path when Polycarp is out of coverage area.
|
for _ in range(int(input())):
a, b, c, r = list(map(int, input().split()))
if a > b:
a, b = b, a
x, y = c - r, c + r
d = max(0, min(b, y) - max(x, a))
print(b - a - d)
|
Polycarp lives on the coordinate axis $Ox$ and travels from the point $x=a$ to $x=b$. It moves uniformly rectilinearly at a speed of one unit of distance per minute.
On the axis $Ox$ at the point $x=c$ the base station of the mobile operator is placed. It is known that the radius of its coverage is $r$. Thus, if Polycarp is at a distance less than or equal to $r$ from the point $x=c$, then he is in the network coverage area, otherwiseΒ β no. The base station can be located both on the route of Polycarp and outside it.
Print the time in minutes during which Polycarp will not be in the coverage area of the network, with a rectilinear uniform movement from $x=a$ to $x=b$. His speedΒ β one unit of distance per minute.
-----Input-----
The first line contains a positive integer $t$ ($1 \le t \le 1000$)Β β the number of test cases. In the following lines are written $t$ test cases.
The description of each test case is one line, which contains four integers $a$, $b$, $c$ and $r$ ($-10^8 \le a,b,c \le 10^8$, $0 \le r \le 10^8$)Β β the coordinates of the starting and ending points of the path, the base station, and its coverage radius, respectively.
Any of the numbers $a$, $b$ and $c$ can be equal (either any pair or all three numbers). The base station can be located both on the route of Polycarp and outside it.
-----Output-----
Print $t$ numbersΒ β answers to given test cases in the order they are written in the test. Each answer is an integerΒ β the number of minutes during which Polycarp will be unavailable during his movement.
-----Example-----
Input
9
1 10 7 1
3 3 3 0
8 2 10 4
8 2 10 100
-10 20 -17 2
-3 2 2 0
-3 1 2 0
2 3 2 3
-1 3 -2 2
Output
7
0
4
0
30
5
4
0
3
-----Note-----
The following picture illustrates the first test case. [Image] Polycarp goes from $1$ to $10$. The yellow area shows the coverage area of the station with a radius of coverage of $1$, which is located at the point of $7$. The green area shows a part of the path when Polycarp is out of coverage area.
|
t = int(input())
for _ in range(t):
a, b, c, r = list(map(int, input().strip().split()))
a, b = min(a,b), max(a, b)
low = max(a, c-r)
high = min(b, c+r)
unavaialbe = high - low
unavaialbe = max(unavaialbe, 0)
print(b - a - unavaialbe)
|
Polycarp lives on the coordinate axis $Ox$ and travels from the point $x=a$ to $x=b$. It moves uniformly rectilinearly at a speed of one unit of distance per minute.
On the axis $Ox$ at the point $x=c$ the base station of the mobile operator is placed. It is known that the radius of its coverage is $r$. Thus, if Polycarp is at a distance less than or equal to $r$ from the point $x=c$, then he is in the network coverage area, otherwiseΒ β no. The base station can be located both on the route of Polycarp and outside it.
Print the time in minutes during which Polycarp will not be in the coverage area of the network, with a rectilinear uniform movement from $x=a$ to $x=b$. His speedΒ β one unit of distance per minute.
-----Input-----
The first line contains a positive integer $t$ ($1 \le t \le 1000$)Β β the number of test cases. In the following lines are written $t$ test cases.
The description of each test case is one line, which contains four integers $a$, $b$, $c$ and $r$ ($-10^8 \le a,b,c \le 10^8$, $0 \le r \le 10^8$)Β β the coordinates of the starting and ending points of the path, the base station, and its coverage radius, respectively.
Any of the numbers $a$, $b$ and $c$ can be equal (either any pair or all three numbers). The base station can be located both on the route of Polycarp and outside it.
-----Output-----
Print $t$ numbersΒ β answers to given test cases in the order they are written in the test. Each answer is an integerΒ β the number of minutes during which Polycarp will be unavailable during his movement.
-----Example-----
Input
9
1 10 7 1
3 3 3 0
8 2 10 4
8 2 10 100
-10 20 -17 2
-3 2 2 0
-3 1 2 0
2 3 2 3
-1 3 -2 2
Output
7
0
4
0
30
5
4
0
3
-----Note-----
The following picture illustrates the first test case. [Image] Polycarp goes from $1$ to $10$. The yellow area shows the coverage area of the station with a radius of coverage of $1$, which is located at the point of $7$. The green area shows a part of the path when Polycarp is out of coverage area.
|
t = int(input())
while t>0:
t-=1
a,b,c,r = map(int,input().split())
if a>b:
a,b=b,a
print(min(max((c-r)-a,0)+max(b-(c+r),0),abs(b-a)))
|
Polycarp lives on the coordinate axis $Ox$ and travels from the point $x=a$ to $x=b$. It moves uniformly rectilinearly at a speed of one unit of distance per minute.
On the axis $Ox$ at the point $x=c$ the base station of the mobile operator is placed. It is known that the radius of its coverage is $r$. Thus, if Polycarp is at a distance less than or equal to $r$ from the point $x=c$, then he is in the network coverage area, otherwiseΒ β no. The base station can be located both on the route of Polycarp and outside it.
Print the time in minutes during which Polycarp will not be in the coverage area of the network, with a rectilinear uniform movement from $x=a$ to $x=b$. His speedΒ β one unit of distance per minute.
-----Input-----
The first line contains a positive integer $t$ ($1 \le t \le 1000$)Β β the number of test cases. In the following lines are written $t$ test cases.
The description of each test case is one line, which contains four integers $a$, $b$, $c$ and $r$ ($-10^8 \le a,b,c \le 10^8$, $0 \le r \le 10^8$)Β β the coordinates of the starting and ending points of the path, the base station, and its coverage radius, respectively.
Any of the numbers $a$, $b$ and $c$ can be equal (either any pair or all three numbers). The base station can be located both on the route of Polycarp and outside it.
-----Output-----
Print $t$ numbersΒ β answers to given test cases in the order they are written in the test. Each answer is an integerΒ β the number of minutes during which Polycarp will be unavailable during his movement.
-----Example-----
Input
9
1 10 7 1
3 3 3 0
8 2 10 4
8 2 10 100
-10 20 -17 2
-3 2 2 0
-3 1 2 0
2 3 2 3
-1 3 -2 2
Output
7
0
4
0
30
5
4
0
3
-----Note-----
The following picture illustrates the first test case. [Image] Polycarp goes from $1$ to $10$. The yellow area shows the coverage area of the station with a radius of coverage of $1$, which is located at the point of $7$. The green area shows a part of the path when Polycarp is out of coverage area.
|
t = int(input())
for _ in range(t):
a, b, c, r = list(map(int, input().split()))
if b < a:
a, b = b, a
ans = 0
if c < a:
if c + r < a:
ans = b - a
else:
ans = max(b - (c + r), 0)
elif c > b:
if c - r > b:
ans = b - a
else:
ans = max((c - r) - a, 0)
else:
ans += max(0, b - (c + r)) + max(0, c - r - a)
print(ans)
|
Polycarp lives on the coordinate axis $Ox$ and travels from the point $x=a$ to $x=b$. It moves uniformly rectilinearly at a speed of one unit of distance per minute.
On the axis $Ox$ at the point $x=c$ the base station of the mobile operator is placed. It is known that the radius of its coverage is $r$. Thus, if Polycarp is at a distance less than or equal to $r$ from the point $x=c$, then he is in the network coverage area, otherwiseΒ β no. The base station can be located both on the route of Polycarp and outside it.
Print the time in minutes during which Polycarp will not be in the coverage area of the network, with a rectilinear uniform movement from $x=a$ to $x=b$. His speedΒ β one unit of distance per minute.
-----Input-----
The first line contains a positive integer $t$ ($1 \le t \le 1000$)Β β the number of test cases. In the following lines are written $t$ test cases.
The description of each test case is one line, which contains four integers $a$, $b$, $c$ and $r$ ($-10^8 \le a,b,c \le 10^8$, $0 \le r \le 10^8$)Β β the coordinates of the starting and ending points of the path, the base station, and its coverage radius, respectively.
Any of the numbers $a$, $b$ and $c$ can be equal (either any pair or all three numbers). The base station can be located both on the route of Polycarp and outside it.
-----Output-----
Print $t$ numbersΒ β answers to given test cases in the order they are written in the test. Each answer is an integerΒ β the number of minutes during which Polycarp will be unavailable during his movement.
-----Example-----
Input
9
1 10 7 1
3 3 3 0
8 2 10 4
8 2 10 100
-10 20 -17 2
-3 2 2 0
-3 1 2 0
2 3 2 3
-1 3 -2 2
Output
7
0
4
0
30
5
4
0
3
-----Note-----
The following picture illustrates the first test case. [Image] Polycarp goes from $1$ to $10$. The yellow area shows the coverage area of the station with a radius of coverage of $1$, which is located at the point of $7$. The green area shows a part of the path when Polycarp is out of coverage area.
|
from sys import stdin, exit
from math import *
def main():
def len_intersect(a, b, c, d):
if d <= a or c >= b:
return 0
u, v = (max(a, c), min(b, d))
return max(0, v - u)
for testcase in range(int(stdin.readline())):
a, b, c, r = list(map(int, stdin.readline().split()))
if a > b:
a, b = b, a
print(b - a - len_intersect(a, b, c - r, c + r))
def __starting_point():
main()
__starting_point()
|
Polycarp lives on the coordinate axis $Ox$ and travels from the point $x=a$ to $x=b$. It moves uniformly rectilinearly at a speed of one unit of distance per minute.
On the axis $Ox$ at the point $x=c$ the base station of the mobile operator is placed. It is known that the radius of its coverage is $r$. Thus, if Polycarp is at a distance less than or equal to $r$ from the point $x=c$, then he is in the network coverage area, otherwiseΒ β no. The base station can be located both on the route of Polycarp and outside it.
Print the time in minutes during which Polycarp will not be in the coverage area of the network, with a rectilinear uniform movement from $x=a$ to $x=b$. His speedΒ β one unit of distance per minute.
-----Input-----
The first line contains a positive integer $t$ ($1 \le t \le 1000$)Β β the number of test cases. In the following lines are written $t$ test cases.
The description of each test case is one line, which contains four integers $a$, $b$, $c$ and $r$ ($-10^8 \le a,b,c \le 10^8$, $0 \le r \le 10^8$)Β β the coordinates of the starting and ending points of the path, the base station, and its coverage radius, respectively.
Any of the numbers $a$, $b$ and $c$ can be equal (either any pair or all three numbers). The base station can be located both on the route of Polycarp and outside it.
-----Output-----
Print $t$ numbersΒ β answers to given test cases in the order they are written in the test. Each answer is an integerΒ β the number of minutes during which Polycarp will be unavailable during his movement.
-----Example-----
Input
9
1 10 7 1
3 3 3 0
8 2 10 4
8 2 10 100
-10 20 -17 2
-3 2 2 0
-3 1 2 0
2 3 2 3
-1 3 -2 2
Output
7
0
4
0
30
5
4
0
3
-----Note-----
The following picture illustrates the first test case. [Image] Polycarp goes from $1$ to $10$. The yellow area shows the coverage area of the station with a radius of coverage of $1$, which is located at the point of $7$. The green area shows a part of the path when Polycarp is out of coverage area.
|
for i in range(int(input())):
a,b,c,r=map(int,input().split())
x=c-r
y=c+r
if a>b:a,b=b,a
z=max(0,min(y,b)-max(x,a))
print(b-a-z)
|
Hooray! Polycarp turned $n$ years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his $n$ birthdays: from the $1$-th to the $n$-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $1$, $77$, $777$, $44$ and $999999$. The following numbers are not beautiful: $12$, $11110$, $6969$ and $987654321$.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from $1$ to $n$ (inclusive) that are beautiful.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case consists of one line, which contains a positive integer $n$ ($1 \le n \le 10^9$) β how many years Polycarp has turned.
-----Output-----
Print $t$ integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $1$ and $n$, inclusive.
-----Example-----
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
-----Note-----
In the first test case of the example beautiful years are $1$, $2$, $3$, $4$, $5$, $6$, $7$, $8$, $9$ and $11$.
|
s = []
for i in range(1, 10):
k = 0
for l in range(1, 10):
k *= 10
k += i
s.append(k)
s.sort()
q = int(input())
while q:
n = int(input())
l = 0
r = len(s)
while l + 1 < r:
m = (l + r) // 2
if s[m] <= n:
l = m
else:
r = m
print(r)
q -= 1
|
Hooray! Polycarp turned $n$ years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his $n$ birthdays: from the $1$-th to the $n$-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $1$, $77$, $777$, $44$ and $999999$. The following numbers are not beautiful: $12$, $11110$, $6969$ and $987654321$.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from $1$ to $n$ (inclusive) that are beautiful.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case consists of one line, which contains a positive integer $n$ ($1 \le n \le 10^9$) β how many years Polycarp has turned.
-----Output-----
Print $t$ integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $1$ and $n$, inclusive.
-----Example-----
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
-----Note-----
In the first test case of the example beautiful years are $1$, $2$, $3$, $4$, $5$, $6$, $7$, $8$, $9$ and $11$.
|
t = int(input())
for i in range(t):
ans = 0
n = int(input())
for i in range(1, 10):
now = i
while now <= n:
now *= 10
now += i
ans += 1
print(ans)
|
Hooray! Polycarp turned $n$ years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his $n$ birthdays: from the $1$-th to the $n$-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $1$, $77$, $777$, $44$ and $999999$. The following numbers are not beautiful: $12$, $11110$, $6969$ and $987654321$.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from $1$ to $n$ (inclusive) that are beautiful.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case consists of one line, which contains a positive integer $n$ ($1 \le n \le 10^9$) β how many years Polycarp has turned.
-----Output-----
Print $t$ integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $1$ and $n$, inclusive.
-----Example-----
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
-----Note-----
In the first test case of the example beautiful years are $1$, $2$, $3$, $4$, $5$, $6$, $7$, $8$, $9$ and $11$.
|
for t in range(int(input())):
n = int(input())
tt = 1
razr = 1
c = 0
while int(str(tt)*razr) <= n:
c += 1
tt += 1
if tt == 10:
tt = 1
razr += 1
print(c)
|
Hooray! Polycarp turned $n$ years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his $n$ birthdays: from the $1$-th to the $n$-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $1$, $77$, $777$, $44$ and $999999$. The following numbers are not beautiful: $12$, $11110$, $6969$ and $987654321$.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from $1$ to $n$ (inclusive) that are beautiful.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case consists of one line, which contains a positive integer $n$ ($1 \le n \le 10^9$) β how many years Polycarp has turned.
-----Output-----
Print $t$ integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $1$ and $n$, inclusive.
-----Example-----
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
-----Note-----
In the first test case of the example beautiful years are $1$, $2$, $3$, $4$, $5$, $6$, $7$, $8$, $9$ and $11$.
|
for i in range(int(input())):
n = int(input())
ans = 0
for k in range (1,11):
for j in range (1,10):
s = str(j)*k
if int(s) <= n:
ans+=1
print(ans)
|
Hooray! Polycarp turned $n$ years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his $n$ birthdays: from the $1$-th to the $n$-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $1$, $77$, $777$, $44$ and $999999$. The following numbers are not beautiful: $12$, $11110$, $6969$ and $987654321$.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from $1$ to $n$ (inclusive) that are beautiful.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case consists of one line, which contains a positive integer $n$ ($1 \le n \le 10^9$) β how many years Polycarp has turned.
-----Output-----
Print $t$ integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $1$ and $n$, inclusive.
-----Example-----
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
-----Note-----
In the first test case of the example beautiful years are $1$, $2$, $3$, $4$, $5$, $6$, $7$, $8$, $9$ and $11$.
|
for t in range(int(input())):
a = input()
out = 9 * (len(a) - 1)
for i in range(1, 10):
if(int(a) >= int(str(i) * len(a))):
out += 1
else:
break
print(out)
|
Hooray! Polycarp turned $n$ years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his $n$ birthdays: from the $1$-th to the $n$-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $1$, $77$, $777$, $44$ and $999999$. The following numbers are not beautiful: $12$, $11110$, $6969$ and $987654321$.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from $1$ to $n$ (inclusive) that are beautiful.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case consists of one line, which contains a positive integer $n$ ($1 \le n \le 10^9$) β how many years Polycarp has turned.
-----Output-----
Print $t$ integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $1$ and $n$, inclusive.
-----Example-----
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
-----Note-----
In the first test case of the example beautiful years are $1$, $2$, $3$, $4$, $5$, $6$, $7$, $8$, $9$ and $11$.
|
t=int(input())
for i in range(t):
n=int(input())
count=0
for j in range(1,10):
s=str(j)
while int(s)<=n:
s=s+str(j)
count+=1
print(count)
|
Hooray! Polycarp turned $n$ years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his $n$ birthdays: from the $1$-th to the $n$-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $1$, $77$, $777$, $44$ and $999999$. The following numbers are not beautiful: $12$, $11110$, $6969$ and $987654321$.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from $1$ to $n$ (inclusive) that are beautiful.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case consists of one line, which contains a positive integer $n$ ($1 \le n \le 10^9$) β how many years Polycarp has turned.
-----Output-----
Print $t$ integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $1$ and $n$, inclusive.
-----Example-----
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
-----Note-----
In the first test case of the example beautiful years are $1$, $2$, $3$, $4$, $5$, $6$, $7$, $8$, $9$ and $11$.
|
N = int(input())
def check(n, cifra):
f = cifra
count = 0
while cifra <= n:
cifra = cifra * 10 + f
count += 1
return count
for i in range (N):
a = int(input())
print(check(a, 1) + check(a, 2) + check(a, 3) + check(a, 4) + check(a, 5) + check(a, 6) + check(a, 7) + check(a, 8) + check(a, 9))
|
Hooray! Polycarp turned $n$ years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his $n$ birthdays: from the $1$-th to the $n$-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $1$, $77$, $777$, $44$ and $999999$. The following numbers are not beautiful: $12$, $11110$, $6969$ and $987654321$.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from $1$ to $n$ (inclusive) that are beautiful.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case consists of one line, which contains a positive integer $n$ ($1 \le n \le 10^9$) β how many years Polycarp has turned.
-----Output-----
Print $t$ integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $1$ and $n$, inclusive.
-----Example-----
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
-----Note-----
In the first test case of the example beautiful years are $1$, $2$, $3$, $4$, $5$, $6$, $7$, $8$, $9$ and $11$.
|
q = int(input())
while q:
a = int(input())
g = len(str(a))
ans = (g - 1)*9
h = (pow(10, g) - 1)/9
x = h
while a - (x + h) >= 0:
x += h
ans += int(str(x)[0])
if x > a:
ans -= 1
print(ans)
q -= 1
|
Hooray! Polycarp turned $n$ years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his $n$ birthdays: from the $1$-th to the $n$-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $1$, $77$, $777$, $44$ and $999999$. The following numbers are not beautiful: $12$, $11110$, $6969$ and $987654321$.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from $1$ to $n$ (inclusive) that are beautiful.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case consists of one line, which contains a positive integer $n$ ($1 \le n \le 10^9$) β how many years Polycarp has turned.
-----Output-----
Print $t$ integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $1$ and $n$, inclusive.
-----Example-----
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
-----Note-----
In the first test case of the example beautiful years are $1$, $2$, $3$, $4$, $5$, $6$, $7$, $8$, $9$ and $11$.
|
tests = int(input())
for test in range(tests):
n = int(input())
l = len(str(n))
c = 0
for i in range(1, l+1):
for j in range(1, 10):
a = int(str(j)*i)
if a <= n:
c += 1
print(c)
|
Hooray! Polycarp turned $n$ years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his $n$ birthdays: from the $1$-th to the $n$-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $1$, $77$, $777$, $44$ and $999999$. The following numbers are not beautiful: $12$, $11110$, $6969$ and $987654321$.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from $1$ to $n$ (inclusive) that are beautiful.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case consists of one line, which contains a positive integer $n$ ($1 \le n \le 10^9$) β how many years Polycarp has turned.
-----Output-----
Print $t$ integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $1$ and $n$, inclusive.
-----Example-----
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
-----Note-----
In the first test case of the example beautiful years are $1$, $2$, $3$, $4$, $5$, $6$, $7$, $8$, $9$ and $11$.
|
for _ in range(int(input())):
limit = int(input())
count = 0
for numb in range(1, 10):
i = 1
while int(str(numb) * i) <= limit:
count += 1
i += 1
print(count)
|
Hooray! Polycarp turned $n$ years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his $n$ birthdays: from the $1$-th to the $n$-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $1$, $77$, $777$, $44$ and $999999$. The following numbers are not beautiful: $12$, $11110$, $6969$ and $987654321$.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from $1$ to $n$ (inclusive) that are beautiful.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case consists of one line, which contains a positive integer $n$ ($1 \le n \le 10^9$) β how many years Polycarp has turned.
-----Output-----
Print $t$ integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $1$ and $n$, inclusive.
-----Example-----
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
-----Note-----
In the first test case of the example beautiful years are $1$, $2$, $3$, $4$, $5$, $6$, $7$, $8$, $9$ and $11$.
|
for _ in range(int(input())):
n = int(input())
ans = 0
for i in range(1, 10):
s = ''
for j in range(10):
s += str(i)
if int(s) <= n: ans += 1
print(ans)
|
Hooray! Polycarp turned $n$ years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his $n$ birthdays: from the $1$-th to the $n$-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $1$, $77$, $777$, $44$ and $999999$. The following numbers are not beautiful: $12$, $11110$, $6969$ and $987654321$.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from $1$ to $n$ (inclusive) that are beautiful.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case consists of one line, which contains a positive integer $n$ ($1 \le n \le 10^9$) β how many years Polycarp has turned.
-----Output-----
Print $t$ integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $1$ and $n$, inclusive.
-----Example-----
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
-----Note-----
In the first test case of the example beautiful years are $1$, $2$, $3$, $4$, $5$, $6$, $7$, $8$, $9$ and $11$.
|
t = int(input())
for kkk in range(t):
n = int(input())
ans = 0
nn = len(str(n))
for i in range(1, 10):
ans += (nn - (1 if int(str(i) * nn) > n else 0))
print(ans)
|
Hooray! Polycarp turned $n$ years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his $n$ birthdays: from the $1$-th to the $n$-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $1$, $77$, $777$, $44$ and $999999$. The following numbers are not beautiful: $12$, $11110$, $6969$ and $987654321$.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from $1$ to $n$ (inclusive) that are beautiful.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case consists of one line, which contains a positive integer $n$ ($1 \le n \le 10^9$) β how many years Polycarp has turned.
-----Output-----
Print $t$ integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $1$ and $n$, inclusive.
-----Example-----
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
-----Note-----
In the first test case of the example beautiful years are $1$, $2$, $3$, $4$, $5$, $6$, $7$, $8$, $9$ and $11$.
|
t = int(input())
all = []
for i in range(1, 10):
for j in range(1, 10):
all.append(int(str(i) * j))
for i in range(t):
n = int(input())
ans = 0
for i in range(len(all)):
if all[i] <= n:
ans += 1
print(ans)
|
Hooray! Polycarp turned $n$ years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his $n$ birthdays: from the $1$-th to the $n$-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $1$, $77$, $777$, $44$ and $999999$. The following numbers are not beautiful: $12$, $11110$, $6969$ and $987654321$.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from $1$ to $n$ (inclusive) that are beautiful.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case consists of one line, which contains a positive integer $n$ ($1 \le n \le 10^9$) β how many years Polycarp has turned.
-----Output-----
Print $t$ integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $1$ and $n$, inclusive.
-----Example-----
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
-----Note-----
In the first test case of the example beautiful years are $1$, $2$, $3$, $4$, $5$, $6$, $7$, $8$, $9$ and $11$.
|
n = int(input())
for i in range(n):
t = int(input())
c = 0
for r in range(1, 10):
for k in range(1, 11):
if int(str(r) * k) <= t:
c += 1
print(c)
|
Hooray! Polycarp turned $n$ years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his $n$ birthdays: from the $1$-th to the $n$-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $1$, $77$, $777$, $44$ and $999999$. The following numbers are not beautiful: $12$, $11110$, $6969$ and $987654321$.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from $1$ to $n$ (inclusive) that are beautiful.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case consists of one line, which contains a positive integer $n$ ($1 \le n \le 10^9$) β how many years Polycarp has turned.
-----Output-----
Print $t$ integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $1$ and $n$, inclusive.
-----Example-----
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
-----Note-----
In the first test case of the example beautiful years are $1$, $2$, $3$, $4$, $5$, $6$, $7$, $8$, $9$ and $11$.
|
t = int(input())
ans = []
for j in range(t):
n = int(input())
s = ''
k = 0
for i in range(1, 10):
s = str(i)
while int(s) <= n:
k += 1
s += str(i)
ans.append(k)
for i in ans:
print(i)
|
Hooray! Polycarp turned $n$ years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his $n$ birthdays: from the $1$-th to the $n$-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $1$, $77$, $777$, $44$ and $999999$. The following numbers are not beautiful: $12$, $11110$, $6969$ and $987654321$.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from $1$ to $n$ (inclusive) that are beautiful.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case consists of one line, which contains a positive integer $n$ ($1 \le n \le 10^9$) β how many years Polycarp has turned.
-----Output-----
Print $t$ integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $1$ and $n$, inclusive.
-----Example-----
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
-----Note-----
In the first test case of the example beautiful years are $1$, $2$, $3$, $4$, $5$, $6$, $7$, $8$, $9$ and $11$.
|
t = int(input())
for i in range(t):
k = 0
n = input()
k += (len(n) - 1) * 9
if n[0] * len(n) > n:
k += int(n[0]) - 1
else:
k += int(n[0])
print(k)
|
Hooray! Polycarp turned $n$ years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his $n$ birthdays: from the $1$-th to the $n$-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $1$, $77$, $777$, $44$ and $999999$. The following numbers are not beautiful: $12$, $11110$, $6969$ and $987654321$.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from $1$ to $n$ (inclusive) that are beautiful.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case consists of one line, which contains a positive integer $n$ ($1 \le n \le 10^9$) β how many years Polycarp has turned.
-----Output-----
Print $t$ integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $1$ and $n$, inclusive.
-----Example-----
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
-----Note-----
In the first test case of the example beautiful years are $1$, $2$, $3$, $4$, $5$, $6$, $7$, $8$, $9$ and $11$.
|
k = int(input())
a = []
for i in range(1, 10):
for i1 in range(1, 10):
a.append(str(i) * i1)
for _ in range(k):
n = int(input())
ans = 0
for i1 in a:
if int(i1) <= n:
ans += 1
print(ans)
|
Hooray! Polycarp turned $n$ years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his $n$ birthdays: from the $1$-th to the $n$-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $1$, $77$, $777$, $44$ and $999999$. The following numbers are not beautiful: $12$, $11110$, $6969$ and $987654321$.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from $1$ to $n$ (inclusive) that are beautiful.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case consists of one line, which contains a positive integer $n$ ($1 \le n \le 10^9$) β how many years Polycarp has turned.
-----Output-----
Print $t$ integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $1$ and $n$, inclusive.
-----Example-----
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
-----Note-----
In the first test case of the example beautiful years are $1$, $2$, $3$, $4$, $5$, $6$, $7$, $8$, $9$ and $11$.
|
n = int(input())
for _ in range(n):
a = (input())
p = (len(a)-1)*9
p += int(a[0]) if int(a) >= int(a[0]*len(a)) else int(a[0])-1
print(p)
|
Hooray! Polycarp turned $n$ years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his $n$ birthdays: from the $1$-th to the $n$-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $1$, $77$, $777$, $44$ and $999999$. The following numbers are not beautiful: $12$, $11110$, $6969$ and $987654321$.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from $1$ to $n$ (inclusive) that are beautiful.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case consists of one line, which contains a positive integer $n$ ($1 \le n \le 10^9$) β how many years Polycarp has turned.
-----Output-----
Print $t$ integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $1$ and $n$, inclusive.
-----Example-----
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
-----Note-----
In the first test case of the example beautiful years are $1$, $2$, $3$, $4$, $5$, $6$, $7$, $8$, $9$ and $11$.
|
for i in range(int(input())):
x = int(input())
ans = 0
ans += 9 * (len(str(x)) - 1)
ans += (int(str(x)[0]) - 1)
if int(str(x)[0] * len(str(x))) <= x:
ans += 1
print(ans)
|
Hooray! Polycarp turned $n$ years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his $n$ birthdays: from the $1$-th to the $n$-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $1$, $77$, $777$, $44$ and $999999$. The following numbers are not beautiful: $12$, $11110$, $6969$ and $987654321$.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from $1$ to $n$ (inclusive) that are beautiful.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case consists of one line, which contains a positive integer $n$ ($1 \le n \le 10^9$) β how many years Polycarp has turned.
-----Output-----
Print $t$ integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $1$ and $n$, inclusive.
-----Example-----
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
-----Note-----
In the first test case of the example beautiful years are $1$, $2$, $3$, $4$, $5$, $6$, $7$, $8$, $9$ and $11$.
|
n = int(input())
for i in range(n):
t = int(input())
answer = 0
for i in range(1, 10):
k = i
while k <= t:
answer += 1
k = k * 10 + i
print(answer)
|
Hooray! Polycarp turned $n$ years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his $n$ birthdays: from the $1$-th to the $n$-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $1$, $77$, $777$, $44$ and $999999$. The following numbers are not beautiful: $12$, $11110$, $6969$ and $987654321$.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from $1$ to $n$ (inclusive) that are beautiful.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case consists of one line, which contains a positive integer $n$ ($1 \le n \le 10^9$) β how many years Polycarp has turned.
-----Output-----
Print $t$ integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $1$ and $n$, inclusive.
-----Example-----
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
-----Note-----
In the first test case of the example beautiful years are $1$, $2$, $3$, $4$, $5$, $6$, $7$, $8$, $9$ and $11$.
|
t = int(input())
for i in range(t):
n = int(input())
l = len(str(n))
ans = (l - 1) * 9
s = str(n)[0]
if n >= int(s * l):
ans += int(s)
else:
ans += int(s) - 1
print(ans)
|
Hooray! Polycarp turned $n$ years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his $n$ birthdays: from the $1$-th to the $n$-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $1$, $77$, $777$, $44$ and $999999$. The following numbers are not beautiful: $12$, $11110$, $6969$ and $987654321$.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from $1$ to $n$ (inclusive) that are beautiful.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case consists of one line, which contains a positive integer $n$ ($1 \le n \le 10^9$) β how many years Polycarp has turned.
-----Output-----
Print $t$ integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $1$ and $n$, inclusive.
-----Example-----
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
-----Note-----
In the first test case of the example beautiful years are $1$, $2$, $3$, $4$, $5$, $6$, $7$, $8$, $9$ and $11$.
|
t = int(input())
for _ in range(t):
n = input()
l = len(n)
n = int(n)
c = 0
for i in range(1, 10):
x = i
while x <= n:
c += 1
x = int(str(x) + str(i))
print(c)
|
Hooray! Polycarp turned $n$ years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his $n$ birthdays: from the $1$-th to the $n$-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $1$, $77$, $777$, $44$ and $999999$. The following numbers are not beautiful: $12$, $11110$, $6969$ and $987654321$.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from $1$ to $n$ (inclusive) that are beautiful.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case consists of one line, which contains a positive integer $n$ ($1 \le n \le 10^9$) β how many years Polycarp has turned.
-----Output-----
Print $t$ integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $1$ and $n$, inclusive.
-----Example-----
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
-----Note-----
In the first test case of the example beautiful years are $1$, $2$, $3$, $4$, $5$, $6$, $7$, $8$, $9$ and $11$.
|
for __ in range(int(input())):
n = int(input())
x = n
num = 0
while x >= 10:
x //= 10
num += 1
ans = num * 9
ans += (n // int('1' * (num + 1)))
print(ans)
|
Hooray! Polycarp turned $n$ years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his $n$ birthdays: from the $1$-th to the $n$-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $1$, $77$, $777$, $44$ and $999999$. The following numbers are not beautiful: $12$, $11110$, $6969$ and $987654321$.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from $1$ to $n$ (inclusive) that are beautiful.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case consists of one line, which contains a positive integer $n$ ($1 \le n \le 10^9$) β how many years Polycarp has turned.
-----Output-----
Print $t$ integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $1$ and $n$, inclusive.
-----Example-----
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
-----Note-----
In the first test case of the example beautiful years are $1$, $2$, $3$, $4$, $5$, $6$, $7$, $8$, $9$ and $11$.
|
g = int(input())
for i in range(g):
a = int(input())
ans = 0
if a >= 10:
ans += 9
else:
ans += a
print(ans)
continue
for i in range(2, 11):
if 10**i <= a:
ans += 9
else:
for j in range(1, 10):
if int(str(j) * i) <= a:
ans += 1
else:
break
break
print(ans)
|
Hooray! Polycarp turned $n$ years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his $n$ birthdays: from the $1$-th to the $n$-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $1$, $77$, $777$, $44$ and $999999$. The following numbers are not beautiful: $12$, $11110$, $6969$ and $987654321$.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from $1$ to $n$ (inclusive) that are beautiful.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case consists of one line, which contains a positive integer $n$ ($1 \le n \le 10^9$) β how many years Polycarp has turned.
-----Output-----
Print $t$ integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $1$ and $n$, inclusive.
-----Example-----
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
-----Note-----
In the first test case of the example beautiful years are $1$, $2$, $3$, $4$, $5$, $6$, $7$, $8$, $9$ and $11$.
|
t=int(input())
for i in range(t):
r=int(input())
a=[1,2,3,4,5,6,7,8,9]
ans=0
i=0
while True:
if i==9:
i=0
if a[i]<=r:
ans+=1
if a[i]>r:
break
a[i]=a[i]*10+(a[i]%10)
i+=1
print(ans)
|
Hooray! Polycarp turned $n$ years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his $n$ birthdays: from the $1$-th to the $n$-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $1$, $77$, $777$, $44$ and $999999$. The following numbers are not beautiful: $12$, $11110$, $6969$ and $987654321$.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from $1$ to $n$ (inclusive) that are beautiful.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case consists of one line, which contains a positive integer $n$ ($1 \le n \le 10^9$) β how many years Polycarp has turned.
-----Output-----
Print $t$ integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $1$ and $n$, inclusive.
-----Example-----
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
-----Note-----
In the first test case of the example beautiful years are $1$, $2$, $3$, $4$, $5$, $6$, $7$, $8$, $9$ and $11$.
|
t=int(input())
for i in range(t):
n=int(input())
a=9*(len(str(n))-1)
if n>=int(str(n)[0]*len(str(n))):
print(a+int(str(n)[0]))
else:
print(a+int(str(n)[0])-1)
|
Hooray! Polycarp turned $n$ years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his $n$ birthdays: from the $1$-th to the $n$-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $1$, $77$, $777$, $44$ and $999999$. The following numbers are not beautiful: $12$, $11110$, $6969$ and $987654321$.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from $1$ to $n$ (inclusive) that are beautiful.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case consists of one line, which contains a positive integer $n$ ($1 \le n \le 10^9$) β how many years Polycarp has turned.
-----Output-----
Print $t$ integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $1$ and $n$, inclusive.
-----Example-----
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
-----Note-----
In the first test case of the example beautiful years are $1$, $2$, $3$, $4$, $5$, $6$, $7$, $8$, $9$ and $11$.
|
t = int(input())
for i in range(t):
n = int(input())
s = str(n)
ans = (len(s) - 1) * 9
for j in range(1, 10):
if int(str(j) * len(s)) <= n:
ans += 1
else:
break
print(ans)
|
Hooray! Polycarp turned $n$ years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his $n$ birthdays: from the $1$-th to the $n$-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $1$, $77$, $777$, $44$ and $999999$. The following numbers are not beautiful: $12$, $11110$, $6969$ and $987654321$.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from $1$ to $n$ (inclusive) that are beautiful.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case consists of one line, which contains a positive integer $n$ ($1 \le n \le 10^9$) β how many years Polycarp has turned.
-----Output-----
Print $t$ integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $1$ and $n$, inclusive.
-----Example-----
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
-----Note-----
In the first test case of the example beautiful years are $1$, $2$, $3$, $4$, $5$, $6$, $7$, $8$, $9$ and $11$.
|
for i in range(int(input())):
n = int(input())
s = len(str(n)) - 1
ans = s * 9
if n >= int(str(n)[0] * (s + 1)):
ans += int(str(n)[0])
else:
ans += int(str(n)[0]) - 1
print(ans)
|
Hooray! Polycarp turned $n$ years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his $n$ birthdays: from the $1$-th to the $n$-th. At the moment, he is wondering: how many times he turned beautiful number of years?
According to Polycarp, a positive integer is beautiful if it consists of only one digit repeated one or more times. For example, the following numbers are beautiful: $1$, $77$, $777$, $44$ and $999999$. The following numbers are not beautiful: $12$, $11110$, $6969$ and $987654321$.
Of course, Polycarpus uses the decimal numeral system (i.e. radix is 10).
Help Polycarpus to find the number of numbers from $1$ to $n$ (inclusive) that are beautiful.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input. Then $t$ test cases follow.
Each test case consists of one line, which contains a positive integer $n$ ($1 \le n \le 10^9$) β how many years Polycarp has turned.
-----Output-----
Print $t$ integers β the answers to the given test cases in the order they are written in the test. Each answer is an integer: the number of beautiful years between $1$ and $n$, inclusive.
-----Example-----
Input
6
18
1
9
100500
33
1000000000
Output
10
1
9
45
12
81
-----Note-----
In the first test case of the example beautiful years are $1$, $2$, $3$, $4$, $5$, $6$, $7$, $8$, $9$ and $11$.
|
t = int(input())
for i in range(0, t):
n = input()
ans = 9 * (len(n) - 1)
if int(n) >= int(n[0] * len(n)):
ans += int(n[0])
else:
ans += int(n[0]) - 1
print(ans)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.