code
stringlengths 0
672k
| language
stringclasses 2
values | AST_depth
int64 -1
40
| alphanumeric_fraction
float64 0
1
| max_line_length
int64 0
672k
| avg_line_length
float64 0
267k
| num_lines
int64 0
4.06k
| task
stringlengths 7
14k
| source
stringclasses 2
values |
---|---|---|---|---|---|---|---|---|
def is_anagram(test, original):
if len(test) != len(original):
return False
test = sorted(test.lower())
original = sorted(original.lower())
for i in range(len(test)):
if test[i] != original[i]:
return False
return True
| python | 9 | 0.675325 | 36 | 24.666667 | 9 | An **anagram** is the result of rearranging the letters of a word to produce a new word.
**Note:** anagrams are case insensitive
Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise.
## Examples
* `"foefet"` is an anagram of `"toffee"`
* `"Buckethead"` is an anagram of `"DeathCubeK"` | taco |
def is_anagram(test, original):
result = True if len(test) == len(original) else False
for letter in test.upper():
result = False if letter not in original.upper() else result
return result
| python | 11 | 0.728205 | 62 | 38 | 5 | An **anagram** is the result of rearranging the letters of a word to produce a new word.
**Note:** anagrams are case insensitive
Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise.
## Examples
* `"foefet"` is an anagram of `"toffee"`
* `"Buckethead"` is an anagram of `"DeathCubeK"` | taco |
def is_anagram(test, original):
if len(original) != len(test):
return False
test = test.lower()
original = original.lower()
for letter in original:
if original.count(letter) != test.count(letter):
return False
return True
| python | 9 | 0.705128 | 50 | 25 | 9 | An **anagram** is the result of rearranging the letters of a word to produce a new word.
**Note:** anagrams are case insensitive
Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise.
## Examples
* `"foefet"` is an anagram of `"toffee"`
* `"Buckethead"` is an anagram of `"DeathCubeK"` | taco |
def is_anagram(test, original):
if sorted(test.lower()) == sorted(original.lower()):
return True
elif test != original:
return False
| python | 9 | 0.697842 | 53 | 26.8 | 5 | An **anagram** is the result of rearranging the letters of a word to produce a new word.
**Note:** anagrams are case insensitive
Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise.
## Examples
* `"foefet"` is an anagram of `"toffee"`
* `"Buckethead"` is an anagram of `"DeathCubeK"` | taco |
def is_anagram(test, original):
test_list = sorted(list(test.lower()))
original_list = sorted(list(original.lower()))
if test_list == original_list:
return True
if test_list != original_list:
return False
| python | 11 | 0.70892 | 47 | 29.428571 | 7 | An **anagram** is the result of rearranging the letters of a word to produce a new word.
**Note:** anagrams are case insensitive
Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise.
## Examples
* `"foefet"` is an anagram of `"toffee"`
* `"Buckethead"` is an anagram of `"DeathCubeK"` | taco |
def is_anagram(test, original):
test = test.lower()
original = original.lower()
t = list(test)
o = list(original)
t.sort()
o.sort()
return t == o
| python | 7 | 0.640523 | 31 | 18.125 | 8 | An **anagram** is the result of rearranging the letters of a word to produce a new word.
**Note:** anagrams are case insensitive
Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise.
## Examples
* `"foefet"` is an anagram of `"toffee"`
* `"Buckethead"` is an anagram of `"DeathCubeK"` | taco |
def is_anagram(test, original):
t = test.lower()
o = [*original.lower()]
if len(t) != len(o):
return False
for c in t:
if c in o:
o.remove(c)
else:
return False
return True
| python | 10 | 0.605263 | 31 | 16.272727 | 11 | An **anagram** is the result of rearranging the letters of a word to produce a new word.
**Note:** anagrams are case insensitive
Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise.
## Examples
* `"foefet"` is an anagram of `"toffee"`
* `"Buckethead"` is an anagram of `"DeathCubeK"` | taco |
def is_anagram(test, original):
if len(test) > len(original) or len(test) < len(original):
return False
res = ''
counter = 0
sortedTest = sorted(test.lower())
sortedOriginal = sorted(original.lower())
for i in range(0, len(sortedTest)):
if sortedTest[i] != sortedOriginal[i]:
res = False
break
else:
res = True
return res
| python | 10 | 0.668605 | 59 | 23.571429 | 14 | An **anagram** is the result of rearranging the letters of a word to produce a new word.
**Note:** anagrams are case insensitive
Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise.
## Examples
* `"foefet"` is an anagram of `"toffee"`
* `"Buckethead"` is an anagram of `"DeathCubeK"` | taco |
from collections import Counter as C
def is_anagram(test, original):
return C(test.lower()) == C(original.lower())
| python | 9 | 0.726496 | 46 | 28.25 | 4 | An **anagram** is the result of rearranging the letters of a word to produce a new word.
**Note:** anagrams are case insensitive
Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise.
## Examples
* `"foefet"` is an anagram of `"toffee"`
* `"Buckethead"` is an anagram of `"DeathCubeK"` | taco |
def is_anagram(test, original):
sort1 = sorted(test.lower())
sort2 = sorted(original.lower())
if ''.join(sort2) == ''.join(sort1):
return True
else:
return False
| python | 9 | 0.664706 | 37 | 23.285714 | 7 | An **anagram** is the result of rearranging the letters of a word to produce a new word.
**Note:** anagrams are case insensitive
Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise.
## Examples
* `"foefet"` is an anagram of `"toffee"`
* `"Buckethead"` is an anagram of `"DeathCubeK"` | taco |
def is_anagram(test, original):
theTest = test.lower()
theOriginal = original.lower()
if len(theTest) != len(theOriginal):
return False
else:
index = 0
lengthCheck = 0
array = [None] * len(theTest)
for i in theOriginal:
array[index] = i
index += 1
for j in theTest:
testLength = len(theTest)
if j in array:
lengthCheck += 1
else:
return False
if lengthCheck == testLength:
return True
| python | 12 | 0.65035 | 37 | 20.45 | 20 | An **anagram** is the result of rearranging the letters of a word to produce a new word.
**Note:** anagrams are case insensitive
Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise.
## Examples
* `"foefet"` is an anagram of `"toffee"`
* `"Buckethead"` is an anagram of `"DeathCubeK"` | taco |
def is_anagram(tst, org):
tst = tst.lower()
org = org.lower()
if len(tst) != len(org):
return False
for i in org:
if tst.count(i) != org.count(i):
return False
return True
| python | 9 | 0.625 | 34 | 19.444444 | 9 | An **anagram** is the result of rearranging the letters of a word to produce a new word.
**Note:** anagrams are case insensitive
Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise.
## Examples
* `"foefet"` is an anagram of `"toffee"`
* `"Buckethead"` is an anagram of `"DeathCubeK"` | taco |
def is_anagram(test, original):
if len(test) != len(original):
return False
elif sorted(test.casefold()) == sorted(original.casefold()):
return True
else:
return False
| python | 10 | 0.700565 | 61 | 24.285714 | 7 | An **anagram** is the result of rearranging the letters of a word to produce a new word.
**Note:** anagrams are case insensitive
Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise.
## Examples
* `"foefet"` is an anagram of `"toffee"`
* `"Buckethead"` is an anagram of `"DeathCubeK"` | taco |
def is_anagram(test, original):
letters_original = sorted(list(original.upper()))
letters_test = sorted(list(test.upper()))
return letters_original == letters_test
| python | 11 | 0.742515 | 50 | 40.75 | 4 | An **anagram** is the result of rearranging the letters of a word to produce a new word.
**Note:** anagrams are case insensitive
Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise.
## Examples
* `"foefet"` is an anagram of `"toffee"`
* `"Buckethead"` is an anagram of `"DeathCubeK"` | taco |
def is_anagram(test, original):
return len(test) == len(original) and all([i in original.lower() for i in test.lower()])
| python | 11 | 0.696721 | 89 | 60 | 2 | An **anagram** is the result of rearranging the letters of a word to produce a new word.
**Note:** anagrams are case insensitive
Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise.
## Examples
* `"foefet"` is an anagram of `"toffee"`
* `"Buckethead"` is an anagram of `"DeathCubeK"` | taco |
def is_anagram(test, original):
org1 = [x.lower() for x in original]
org2 = [y.lower() for y in test]
org1.sort()
org2.sort()
if org1 == org2:
return True
return False
| python | 8 | 0.653409 | 37 | 21 | 8 | An **anagram** is the result of rearranging the letters of a word to produce a new word.
**Note:** anagrams are case insensitive
Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise.
## Examples
* `"foefet"` is an anagram of `"toffee"`
* `"Buckethead"` is an anagram of `"DeathCubeK"` | taco |
def is_anagram(test, original):
original_list = list(original.lower())
test_list = list(test.lower())
original_list.sort()
test_list.sort()
a = ''.join(test_list)
b = ''.join(original_list)
return a == b
| python | 9 | 0.663507 | 39 | 25.375 | 8 | An **anagram** is the result of rearranging the letters of a word to produce a new word.
**Note:** anagrams are case insensitive
Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise.
## Examples
* `"foefet"` is an anagram of `"toffee"`
* `"Buckethead"` is an anagram of `"DeathCubeK"` | taco |
def is_anagram(test, original):
test = test.lower().replace(' ', '')
original = original.lower().replace(' ', '')
if len(test) != len(original):
return False
for letter in test:
if letter not in original:
return False
for letter in original:
if letter not in test:
return False
return True
| python | 9 | 0.672078 | 45 | 24.666667 | 12 | An **anagram** is the result of rearranging the letters of a word to produce a new word.
**Note:** anagrams are case insensitive
Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise.
## Examples
* `"foefet"` is an anagram of `"toffee"`
* `"Buckethead"` is an anagram of `"DeathCubeK"` | taco |
import sys
n = int(input())
a = [int(x) for x in input().split(' ')]
maxm = 0
idx = 0
ans = 0
b = [0] * n
for i in range(n):
if a[i] >= maxm:
maxm = a[i]
idx = i
for i in range(idx, n):
b[i] = maxm + 1
i = idx - 1
while i >= 0:
b[i] = max(a[i] + 1, b[i + 1] - 1)
i -= 1
for i in range(1, n):
if b[i] < b[i - 1]:
b[i] = b[i - 1]
ans += b[i] - 1 - a[i]
print(ans)
| python | 10 | 0.465241 | 40 | 16 | 22 | Arkady decides to observe a river for n consecutive days. The river's water level on each day is equal to some real value.
Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but if it coincides with a mark made before, no new mark is created. The water does not wash the marks away. Arkady writes down the number of marks strictly above the water level each day, on the i-th day this value is equal to mi.
Define di as the number of marks strictly under the water level on the i-th day. You are to find out the minimum possible sum of di over all days. There are no marks on the channel before the first day.
Input
The first line contains a single positive integer n (1 β€ n β€ 105) β the number of days.
The second line contains n space-separated integers m1, m2, ..., mn (0 β€ mi < i) β the number of marks strictly above the water on each day.
Output
Output one single integer β the minimum possible sum of the number of marks strictly below the water level among all days.
Examples
Input
6
0 1 0 3 0 2
Output
6
Input
5
0 1 2 1 2
Output
1
Input
5
0 1 1 2 2
Output
0
Note
In the first example, the following figure shows an optimal case.
<image>
Note that on day 3, a new mark should be created because if not, there cannot be 3 marks above water on day 4. The total number of marks underwater is 0 + 0 + 2 + 0 + 3 + 1 = 6.
In the second example, the following figure shows an optimal case.
<image> | taco |
n = int(input())
a = list(map(int, input().split()))
min_toptal = a.copy()
for i in range(1, n):
min_toptal[i] = max(min_toptal[i - 1], a[i] + 1)
min_toptal[0] = 1
for i in range(n - 1, 0, -1):
min_toptal[i - 1] = max(min_toptal[i] - 1, min_toptal[i - 1])
min_under = []
underwater = sum((max(0, min_toptal[i] - a[i] - 1) for i in range(n)))
print(underwater)
| python | 11 | 0.582873 | 70 | 31.909091 | 11 | Arkady decides to observe a river for n consecutive days. The river's water level on each day is equal to some real value.
Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but if it coincides with a mark made before, no new mark is created. The water does not wash the marks away. Arkady writes down the number of marks strictly above the water level each day, on the i-th day this value is equal to mi.
Define di as the number of marks strictly under the water level on the i-th day. You are to find out the minimum possible sum of di over all days. There are no marks on the channel before the first day.
Input
The first line contains a single positive integer n (1 β€ n β€ 105) β the number of days.
The second line contains n space-separated integers m1, m2, ..., mn (0 β€ mi < i) β the number of marks strictly above the water on each day.
Output
Output one single integer β the minimum possible sum of the number of marks strictly below the water level among all days.
Examples
Input
6
0 1 0 3 0 2
Output
6
Input
5
0 1 2 1 2
Output
1
Input
5
0 1 1 2 2
Output
0
Note
In the first example, the following figure shows an optimal case.
<image>
Note that on day 3, a new mark should be created because if not, there cannot be 3 marks above water on day 4. The total number of marks underwater is 0 + 0 + 2 + 0 + 3 + 1 = 6.
In the second example, the following figure shows an optimal case.
<image> | taco |
n = int(input())
a = list(map(int, input().split()))
ma = [1] * n
for i in range(1, n):
ma[i] = max(ma[i - 1], a[i] + 1)
for i in range(n - 2, -1, -1):
ma[i] = max(ma[i + 1] - 1, ma[i])
print(sum(ma) - sum(a) - n)
| python | 11 | 0.481481 | 35 | 26 | 8 | Arkady decides to observe a river for n consecutive days. The river's water level on each day is equal to some real value.
Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but if it coincides with a mark made before, no new mark is created. The water does not wash the marks away. Arkady writes down the number of marks strictly above the water level each day, on the i-th day this value is equal to mi.
Define di as the number of marks strictly under the water level on the i-th day. You are to find out the minimum possible sum of di over all days. There are no marks on the channel before the first day.
Input
The first line contains a single positive integer n (1 β€ n β€ 105) β the number of days.
The second line contains n space-separated integers m1, m2, ..., mn (0 β€ mi < i) β the number of marks strictly above the water on each day.
Output
Output one single integer β the minimum possible sum of the number of marks strictly below the water level among all days.
Examples
Input
6
0 1 0 3 0 2
Output
6
Input
5
0 1 2 1 2
Output
1
Input
5
0 1 1 2 2
Output
0
Note
In the first example, the following figure shows an optimal case.
<image>
Note that on day 3, a new mark should be created because if not, there cannot be 3 marks above water on day 4. The total number of marks underwater is 0 + 0 + 2 + 0 + 3 + 1 = 6.
In the second example, the following figure shows an optimal case.
<image> | taco |
n = int(input())
m = list(map(int, input().split()))
num = [0 for _ in range(n)]
cur = 0
for i in range(n - 1, -1, -1):
cur -= 1
alt = m[i] + 1
if cur < alt:
cur = alt
j = i
while j < n and num[j] < cur:
num[j] = cur
j += 1
else:
num[i] = cur
print(sum(num) - n - sum(m))
| python | 11 | 0.493103 | 35 | 17.125 | 16 | Arkady decides to observe a river for n consecutive days. The river's water level on each day is equal to some real value.
Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but if it coincides with a mark made before, no new mark is created. The water does not wash the marks away. Arkady writes down the number of marks strictly above the water level each day, on the i-th day this value is equal to mi.
Define di as the number of marks strictly under the water level on the i-th day. You are to find out the minimum possible sum of di over all days. There are no marks on the channel before the first day.
Input
The first line contains a single positive integer n (1 β€ n β€ 105) β the number of days.
The second line contains n space-separated integers m1, m2, ..., mn (0 β€ mi < i) β the number of marks strictly above the water on each day.
Output
Output one single integer β the minimum possible sum of the number of marks strictly below the water level among all days.
Examples
Input
6
0 1 0 3 0 2
Output
6
Input
5
0 1 2 1 2
Output
1
Input
5
0 1 1 2 2
Output
0
Note
In the first example, the following figure shows an optimal case.
<image>
Note that on day 3, a new mark should be created because if not, there cannot be 3 marks above water on day 4. The total number of marks underwater is 0 + 0 + 2 + 0 + 3 + 1 = 6.
In the second example, the following figure shows an optimal case.
<image> | taco |
N = int(input())
above = list(map(int, input().split()))
if N == 1:
print(0)
quit()
required_mark = [0] * N
required_mark[N - 2] = above[N - 1]
for i in reversed(range(N - 2)):
required_mark[i] = max(above[i + 1], required_mark[i + 1] - 1)
d = 0
mark = 1
for i in range(1, N):
if mark == above[i]:
mark += 1
elif mark >= required_mark[i]:
d += mark - above[i] - 1
else:
d += mark - above[i]
mark += 1
print(d)
| python | 11 | 0.561321 | 63 | 20.2 | 20 | Arkady decides to observe a river for n consecutive days. The river's water level on each day is equal to some real value.
Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but if it coincides with a mark made before, no new mark is created. The water does not wash the marks away. Arkady writes down the number of marks strictly above the water level each day, on the i-th day this value is equal to mi.
Define di as the number of marks strictly under the water level on the i-th day. You are to find out the minimum possible sum of di over all days. There are no marks on the channel before the first day.
Input
The first line contains a single positive integer n (1 β€ n β€ 105) β the number of days.
The second line contains n space-separated integers m1, m2, ..., mn (0 β€ mi < i) β the number of marks strictly above the water on each day.
Output
Output one single integer β the minimum possible sum of the number of marks strictly below the water level among all days.
Examples
Input
6
0 1 0 3 0 2
Output
6
Input
5
0 1 2 1 2
Output
1
Input
5
0 1 1 2 2
Output
0
Note
In the first example, the following figure shows an optimal case.
<image>
Note that on day 3, a new mark should be created because if not, there cannot be 3 marks above water on day 4. The total number of marks underwater is 0 + 0 + 2 + 0 + 3 + 1 = 6.
In the second example, the following figure shows an optimal case.
<image> | taco |
n = int(input())
a = list(map(int, input().strip().split()))
s = [0] * n
under = 0
for i in range(n):
s[i] = a[i]
for i in range(1, n):
s[i] = max(s[i], s[i - 1])
for i in range(n - 2, 0, -1):
if s[i + 1] - s[i] > 1:
s[i] = s[i + 1] - 1
for i in range(n):
under += max(0, s[i] - a[i])
print(under)
| python | 13 | 0.483553 | 43 | 20.714286 | 14 | Arkady decides to observe a river for n consecutive days. The river's water level on each day is equal to some real value.
Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but if it coincides with a mark made before, no new mark is created. The water does not wash the marks away. Arkady writes down the number of marks strictly above the water level each day, on the i-th day this value is equal to mi.
Define di as the number of marks strictly under the water level on the i-th day. You are to find out the minimum possible sum of di over all days. There are no marks on the channel before the first day.
Input
The first line contains a single positive integer n (1 β€ n β€ 105) β the number of days.
The second line contains n space-separated integers m1, m2, ..., mn (0 β€ mi < i) β the number of marks strictly above the water on each day.
Output
Output one single integer β the minimum possible sum of the number of marks strictly below the water level among all days.
Examples
Input
6
0 1 0 3 0 2
Output
6
Input
5
0 1 2 1 2
Output
1
Input
5
0 1 1 2 2
Output
0
Note
In the first example, the following figure shows an optimal case.
<image>
Note that on day 3, a new mark should be created because if not, there cannot be 3 marks above water on day 4. The total number of marks underwater is 0 + 0 + 2 + 0 + 3 + 1 = 6.
In the second example, the following figure shows an optimal case.
<image> | taco |
n = int(input())
A = [int(x) for x in input().split()]
n = len(A)
LB = [0] * n
lvl = 0
for i in reversed(range(n)):
lvl = max(A[i], lvl)
LB[i] = lvl + 1
lvl -= 1
poss = [[1, 1]]
for i in range(1, n):
(l, h) = poss[-1]
a = A[i]
l = max(a, l)
if a == h:
l += 1
poss.append([l, h + 1])
Level = []
for i in range(n):
if Level:
Level.append(max(Level[-1], LB[i], poss[i][0]))
else:
Level.append(max(LB[i], poss[i][0]))
count = 0
for i in range(n):
count += max(1, Level[i] - A[i]) - 1
print(count)
| python | 13 | 0.519608 | 49 | 17.888889 | 27 | Arkady decides to observe a river for n consecutive days. The river's water level on each day is equal to some real value.
Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but if it coincides with a mark made before, no new mark is created. The water does not wash the marks away. Arkady writes down the number of marks strictly above the water level each day, on the i-th day this value is equal to mi.
Define di as the number of marks strictly under the water level on the i-th day. You are to find out the minimum possible sum of di over all days. There are no marks on the channel before the first day.
Input
The first line contains a single positive integer n (1 β€ n β€ 105) β the number of days.
The second line contains n space-separated integers m1, m2, ..., mn (0 β€ mi < i) β the number of marks strictly above the water on each day.
Output
Output one single integer β the minimum possible sum of the number of marks strictly below the water level among all days.
Examples
Input
6
0 1 0 3 0 2
Output
6
Input
5
0 1 2 1 2
Output
1
Input
5
0 1 1 2 2
Output
0
Note
In the first example, the following figure shows an optimal case.
<image>
Note that on day 3, a new mark should be created because if not, there cannot be 3 marks above water on day 4. The total number of marks underwater is 0 + 0 + 2 + 0 + 3 + 1 = 6.
In the second example, the following figure shows an optimal case.
<image> | taco |
N = int(input())
M = list(map(int, input().split()))
T = [0] * N
for i in range(1, N):
T[i] = max(T[i - 1], M[i] + 1)
for i in range(N - 2, -1, -1):
T[i] = max(T[i], T[i + 1] - 1, 0)
res = sum([max(0, T[i] - M[i] - 1) for i in range(N)])
print(res)
| python | 11 | 0.474104 | 54 | 26.888889 | 9 | Arkady decides to observe a river for n consecutive days. The river's water level on each day is equal to some real value.
Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but if it coincides with a mark made before, no new mark is created. The water does not wash the marks away. Arkady writes down the number of marks strictly above the water level each day, on the i-th day this value is equal to mi.
Define di as the number of marks strictly under the water level on the i-th day. You are to find out the minimum possible sum of di over all days. There are no marks on the channel before the first day.
Input
The first line contains a single positive integer n (1 β€ n β€ 105) β the number of days.
The second line contains n space-separated integers m1, m2, ..., mn (0 β€ mi < i) β the number of marks strictly above the water on each day.
Output
Output one single integer β the minimum possible sum of the number of marks strictly below the water level among all days.
Examples
Input
6
0 1 0 3 0 2
Output
6
Input
5
0 1 2 1 2
Output
1
Input
5
0 1 1 2 2
Output
0
Note
In the first example, the following figure shows an optimal case.
<image>
Note that on day 3, a new mark should be created because if not, there cannot be 3 marks above water on day 4. The total number of marks underwater is 0 + 0 + 2 + 0 + 3 + 1 = 6.
In the second example, the following figure shows an optimal case.
<image> | taco |
n = int(input())
a = list(map(int, input().split()))
ne = n * [0]
ned = 1
for i in range(n - 1, -1, -1):
if a[i] + 1 > ned:
ned = a[i] + 1
ne[i] = ned
ned -= 1
ne.append(0)
le = 1
o = 0
for i in range(n):
o += le - a[i] - 1
if le < ne[i + 1]:
le += 1
print(o)
| python | 11 | 0.468401 | 35 | 14.823529 | 17 | Arkady decides to observe a river for n consecutive days. The river's water level on each day is equal to some real value.
Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but if it coincides with a mark made before, no new mark is created. The water does not wash the marks away. Arkady writes down the number of marks strictly above the water level each day, on the i-th day this value is equal to mi.
Define di as the number of marks strictly under the water level on the i-th day. You are to find out the minimum possible sum of di over all days. There are no marks on the channel before the first day.
Input
The first line contains a single positive integer n (1 β€ n β€ 105) β the number of days.
The second line contains n space-separated integers m1, m2, ..., mn (0 β€ mi < i) β the number of marks strictly above the water on each day.
Output
Output one single integer β the minimum possible sum of the number of marks strictly below the water level among all days.
Examples
Input
6
0 1 0 3 0 2
Output
6
Input
5
0 1 2 1 2
Output
1
Input
5
0 1 1 2 2
Output
0
Note
In the first example, the following figure shows an optimal case.
<image>
Note that on day 3, a new mark should be created because if not, there cannot be 3 marks above water on day 4. The total number of marks underwater is 0 + 0 + 2 + 0 + 3 + 1 = 6.
In the second example, the following figure shows an optimal case.
<image> | taco |
n = int(input())
above = list(map(int, input().split()))
total = [x + 1 for x in above]
for i in range(0, n - 1)[::-1]:
total[i] = max(total[i], total[i + 1] - 1)
for i in range(1, n):
total[i] = max(total[i], total[i - 1])
below = [t - a - 1 for (t, a) in zip(total, above)]
print(sum(below))
| python | 11 | 0.560811 | 51 | 31.888889 | 9 | Arkady decides to observe a river for n consecutive days. The river's water level on each day is equal to some real value.
Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but if it coincides with a mark made before, no new mark is created. The water does not wash the marks away. Arkady writes down the number of marks strictly above the water level each day, on the i-th day this value is equal to mi.
Define di as the number of marks strictly under the water level on the i-th day. You are to find out the minimum possible sum of di over all days. There are no marks on the channel before the first day.
Input
The first line contains a single positive integer n (1 β€ n β€ 105) β the number of days.
The second line contains n space-separated integers m1, m2, ..., mn (0 β€ mi < i) β the number of marks strictly above the water on each day.
Output
Output one single integer β the minimum possible sum of the number of marks strictly below the water level among all days.
Examples
Input
6
0 1 0 3 0 2
Output
6
Input
5
0 1 2 1 2
Output
1
Input
5
0 1 1 2 2
Output
0
Note
In the first example, the following figure shows an optimal case.
<image>
Note that on day 3, a new mark should be created because if not, there cannot be 3 marks above water on day 4. The total number of marks underwater is 0 + 0 + 2 + 0 + 3 + 1 = 6.
In the second example, the following figure shows an optimal case.
<image> | taco |
from sys import stdin, stdout
def rint():
return map(int, stdin.readline().split())
n = int(input())
u = list(rint())
u = [0] + u
mark = 0
b = [0]
for i in range(1, n + 1):
uu = u[i]
b.append(i)
if uu >= mark:
inc = uu - mark + 1
l = len(b)
for i in range(inc):
b.pop()
mark += inc
tot = [1 for i in range(n + 1)]
for bb in b:
tot[bb] = 0
for i in range(1, n + 1):
tot[i] = tot[i - 1] + tot[i]
ans = 0
for i in range(1, n + 1):
ans += tot[i] - u[i] - 1
print(ans)
| python | 10 | 0.532091 | 42 | 16.888889 | 27 | Arkady decides to observe a river for n consecutive days. The river's water level on each day is equal to some real value.
Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but if it coincides with a mark made before, no new mark is created. The water does not wash the marks away. Arkady writes down the number of marks strictly above the water level each day, on the i-th day this value is equal to mi.
Define di as the number of marks strictly under the water level on the i-th day. You are to find out the minimum possible sum of di over all days. There are no marks on the channel before the first day.
Input
The first line contains a single positive integer n (1 β€ n β€ 105) β the number of days.
The second line contains n space-separated integers m1, m2, ..., mn (0 β€ mi < i) β the number of marks strictly above the water on each day.
Output
Output one single integer β the minimum possible sum of the number of marks strictly below the water level among all days.
Examples
Input
6
0 1 0 3 0 2
Output
6
Input
5
0 1 2 1 2
Output
1
Input
5
0 1 1 2 2
Output
0
Note
In the first example, the following figure shows an optimal case.
<image>
Note that on day 3, a new mark should be created because if not, there cannot be 3 marks above water on day 4. The total number of marks underwater is 0 + 0 + 2 + 0 + 3 + 1 = 6.
In the second example, the following figure shows an optimal case.
<image> | taco |
n = int(input())
m = list(map(int, input().split()))
a = [0] * n
k = 0
for i in range(n):
k = max(k, m[i] + 1)
a[i] = k
for i in range(n - 1, 0, -1):
a[i - 1] = max(a[i] - 1, a[i - 1])
ans = 0
for i in range(n):
ans += a[i] - m[i] - 1
print(ans)
| python | 11 | 0.468 | 35 | 18.230769 | 13 | Arkady decides to observe a river for n consecutive days. The river's water level on each day is equal to some real value.
Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but if it coincides with a mark made before, no new mark is created. The water does not wash the marks away. Arkady writes down the number of marks strictly above the water level each day, on the i-th day this value is equal to mi.
Define di as the number of marks strictly under the water level on the i-th day. You are to find out the minimum possible sum of di over all days. There are no marks on the channel before the first day.
Input
The first line contains a single positive integer n (1 β€ n β€ 105) β the number of days.
The second line contains n space-separated integers m1, m2, ..., mn (0 β€ mi < i) β the number of marks strictly above the water on each day.
Output
Output one single integer β the minimum possible sum of the number of marks strictly below the water level among all days.
Examples
Input
6
0 1 0 3 0 2
Output
6
Input
5
0 1 2 1 2
Output
1
Input
5
0 1 1 2 2
Output
0
Note
In the first example, the following figure shows an optimal case.
<image>
Note that on day 3, a new mark should be created because if not, there cannot be 3 marks above water on day 4. The total number of marks underwater is 0 + 0 + 2 + 0 + 3 + 1 = 6.
In the second example, the following figure shows an optimal case.
<image> | taco |
s = input().lower()
vow = ['a', 'e', 'i', 'o', 'u', 'y']
ans = ''
for ch in s:
if ch in vow:
continue
if ch.isalpha():
ans += '.' + ch
print(ans)
| python | 9 | 0.473684 | 36 | 15.888889 | 9 | Tom has finally taken over the business empire and now looking for
a new Name of the business to make a new start.
Joe (Tom's dear friend) suggested a string $S$ consisting of
Uppercase and lowercase letters
Tom wants to make some changes as per the following criteria:
1) String should $not$ have any vowels .
2) Every other uppercase consonant(other characters except vowels) should
be in lowercase
For ex:
If the consonant character is Z then it should be z
3) There should be a character "." before each consonant.
Help Tom to make the required Changes.
-----Input:-----
- First line will contain string $S$,This string only consists of uppercase and lowercase letters.
-----Output:-----
Print the resulting string. It is guaranteed that this string is not empty.
-----Constraints-----
- Length of string is in [1 .. 100]
-----Sample Input:-----
$CodeSprInT$
-----Sample Output:-----
.c.d.s.p.r.n.t
-----EXPLANATION:-----
C is a consonant and it is in uppercase so turn it in lower case and add a β.β before it
o is a vowel so it is deleted
d is a consonant and in lowercase so just add a β.β before it
e is a vowel so it is deleted
S is a consonant and it is in uppercase so turn it in lower case and add a β.β before it
p is a consonant and in lowercase so just add a β.β before it
r is a consonant and in lowercase so just add a β.β before it
I is a vowel so it is deleted
n is a consonant and in lowercase so just add a β.β before it
T is a consonant and it is in uppercase so turn it in lower case and add a β.β before it | taco |
for i in range(0, int(input())):
n = int(input())
l = list(input())
t = 0
a = 0
b = 0
for j in range(0, n):
t = t + 1
if l[j] == '0':
a = a + 1
else:
b = b + 1
if b >= t / 2:
print('YES')
break
elif j == n - 1 and b < t / 2:
print('NO')
else:
continue
| python | 12 | 0.4375 | 32 | 14.157895 | 19 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
for _ in range(int(input())):
n = int(input())
s = input()
(c, c1) = (0, 0)
ans = 'NO'
for i in s:
if i == '1':
c1 += 1
c += 1
if c1 * 2 >= c:
ans = 'YES'
break
print(ans)
| python | 10 | 0.435233 | 29 | 13.846154 | 13 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
t = int(input())
for ni in range(t):
l = int(input())
s = input()
(s0, s1) = (0, 0)
pos = 'NO'
for i in range(len(s)):
if s[i] == '0':
s0 = s0 + 1
else:
s1 = s1 + 1
if s1 >= s0:
pos = 'YES'
break
print(pos)
| python | 11 | 0.463203 | 24 | 14.4 | 15 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
t = int(input())
while t:
l = int(input())
s = input()
if s.count('1') >= s.count('0'):
print('YES')
else:
a = 0
flag = False
for i in range(0, l):
if s[i] == '1':
a += 1
if a >= (i + 1) / 2:
flag = True
break
if flag == True:
print('YES')
else:
print('NO')
t -= 1
| python | 15 | 0.449838 | 33 | 14.45 | 20 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
a = int(input(''))
for i in range(a):
x = int(input(''))
t = input('')
c1 = 0
c0 = 0
flag = 0
for j in range(len(t)):
if t[j] == '1':
c1 = c1 + 1
else:
c0 = c0 + 1
if c1 >= c0:
flag = 1
print('YES' if flag else 'NO')
| python | 11 | 0.468619 | 31 | 14.933333 | 15 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
for _ in range(int(input())):
n = int(input())
s = input()
count1 = 0
count0 = 0
flag = 0
for i in range(len(s)):
if s[i] == '1':
count1 += 1
else:
count0 += 1
if count1 >= count0:
flag = 1
print('YES' if flag else 'NO')
| python | 10 | 0.530864 | 31 | 16.357143 | 14 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
t = int(input())
for i in range(t):
L = int(input())
S = input()
b = 0
g = 0
flag = 0
for j in range(L):
if S[j] == '0':
b = b + 1
elif S[j] == '1':
g = g + 1
if g >= b:
flag = 1
break
if flag == 0:
print('NO')
else:
print('YES')
| python | 11 | 0.442308 | 19 | 12.684211 | 19 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
t = int(input())
for t in range(t):
l = int(input())
s = input()
count_0 = 0
count_1 = 0
flag = 0
for i in range(len(s)):
if s[i] == '0':
count_0 += 1
else:
count_1 += 1
if count_1 >= count_0 and count_0 != 0 or (count_0 == 0 and count_1 > 0):
flag = 1
break
if flag == 0:
print('NO')
else:
print('YES')
| python | 10 | 0.51497 | 75 | 16.578947 | 19 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
for _ in range(int(input())):
L = int(input())
S = input().strip()
if S.count('1') >= L // 2 + (L % 2 > 0):
print('YES')
continue
count = 0
yrs = 0
for c in S:
count += c == '1'
yrs += 1
if count >= yrs // 2 + (yrs % 2 > 0):
print('YES')
break
else:
print('NO')
| python | 11 | 0.473868 | 41 | 16.9375 | 16 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
for tc in range(int(input())):
L = int(input())
S = input()
(g, t) = (0, 0)
ans = 'NO'
for i in S:
t += 1
if i == '1':
g += 1
if g / t >= 0.5:
ans = 'YES'
break
else:
ans = 'NO'
print(ans)
| python | 11 | 0.432558 | 30 | 13.333333 | 15 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
import re
for i in range(int(input())):
l = int(input())
str1 = input()
sum1 = 0
sum2 = 0
if str1[0] == '1':
print('YES')
else:
for i in str1:
if i == '0':
sum1 = sum1 + 1
else:
sum2 = sum2 + 1
if sum2 >= sum1:
print('YES')
break
elif sum2 + sum1 == len(str1):
print('NO')
| python | 15 | 0.507937 | 33 | 15.578947 | 19 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
t = int(input())
for i in range(t):
l = int(input())
s = input()
flag = 0
(count1, count2) = (0, 0)
for i in s:
if i == '0':
count1 += 1
else:
count2 += 1
if count2 >= count1:
flag = 1
break
if flag:
print('YES')
else:
print('NO')
| python | 10 | 0.511538 | 26 | 13.444444 | 18 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
t = int(input())
while t != 0:
n = int(input())
s = input()
c = 0
f = 0
for k in range(n):
if s[k] == '1':
c += 1
if c >= (k + 1) / 2:
f = 1
break
if f == 1:
print('YES')
else:
print('NO')
t -= 1
| python | 12 | 0.410714 | 23 | 12.176471 | 17 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
for _ in range(int(input())):
n = int(input())
s = input()
(o, z) = (0, 0)
c = 'NO'
for i in s:
if i == '0':
z += 1
else:
o += 1
if o >= z:
c = 'YES'
break
print(c)
| python | 13 | 0.40625 | 29 | 12.714286 | 14 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
for _ in range(int(input())):
l = int(input())
s = input()
z = 0
o = 0
ans = 'NO'
for c in s:
if c == '0':
z += 1
else:
o += 1
if o >= z:
ans = 'YES'
break
print(ans)
| python | 13 | 0.430769 | 29 | 12 | 15 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
for i in range(int(input())):
a = int(input())
s = input()
c = d = 0
for i in range(len(s)):
if s[i] == '1':
c += 1
if c * 100 / (i + 1) >= 50:
print('YES')
break
else:
print('NO')
| python | 11 | 0.462687 | 29 | 15.75 | 12 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
import math
for i in range(int(input())):
n = int(input())
s = input()
c = 0
if s.count('1') >= s.count('0'):
print('YES')
else:
o = 0
z = 0
for i in s:
if i == '1':
o += 1
else:
z += 1
if o == z:
c += 1
print('YES')
break
if c == 0:
print('NO')
| python | 14 | 0.433447 | 33 | 12.952381 | 21 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
t = int(input())
for _ in range(t):
l = int(input())
s = input()
cntz = 0
cnto = 0
t = True
for i in range(l):
if s[i] == '0':
cntz += 1
if s[i] == '1':
cnto += 1
if cntz == cnto:
t = False
break
if cntz < cnto or not t:
print('YES')
else:
print('NO')
| python | 10 | 0.489362 | 25 | 13.842105 | 19 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
T = int(input())
for _ in range(T):
L = int(input())
S = input()
zeros = 0
ones = 0
flag = False
for i in S:
if i == '1':
ones += 1
else:
zeros += 1
if ones >= zeros:
flag = True
break
print('YES' if flag else 'NO')
| python | 10 | 0.518672 | 31 | 14.0625 | 16 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
for i in range(int(input())):
a = int(input())
b = input()
ch = 0
bj = 0
for i in range(1, a + 1):
if b[i - 1] == '1':
ch += 1
if ch / i >= 0.5:
bj += 1
break
if bj == 1:
print('YES')
else:
print('NO')
| python | 10 | 0.451327 | 29 | 14.066667 | 15 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
t = int(input())
for k in range(t):
n = int(input())
a = str(input())
b = 0
c = 0
d = 0
while b != len(a):
if a[b] == '0':
c += 1
else:
d += 1
b += 1
if c <= d:
b = len(a)
if c <= d:
print('YES')
else:
print('NO')
| python | 11 | 0.419753 | 19 | 11.789474 | 19 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
T = int(input())
for i in range(T):
L = int(input())
S = input()
c = 0
li = []
for j in S:
li.append(j)
for i in range(L):
if li[i] == '1':
c = c + 1
if c * 100 / (i + 1) >= 50:
z = c * 100 / (i + 1)
break
else:
z = c * 100 / (i + 1)
print('YES' if z >= 50 else 'NO')
| python | 13 | 0.437288 | 34 | 16.352941 | 17 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
for _ in range(int(input())):
n = int(input())
s = input()
one = 0
chk = 0
for i in range(1, n + 1):
if s[i - 1] == '1':
one += 1
if one / i >= 0.5:
chk = 1
break
if chk == 1:
print('YES')
else:
print('NO')
| python | 10 | 0.463203 | 29 | 14.4 | 15 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
for i in range(int(input())):
l = int(input())
s = input()
good = s.count('1')
bad = s.count('0')
if good >= len(s) / 2:
print('YES')
else:
(cb, cg, flag) = (0, 0, False)
for i in s:
if i == '1':
cg += 1
else:
cb += 1
if cg >= cb:
print('YES')
flag = True
break
if flag == False:
print('NO')
| python | 14 | 0.470414 | 32 | 15.9 | 20 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
t = int(input())
for i in range(t):
l = int(input())
s = input()
c = 0
d = 0
ans = False
for i in s:
if i == '0':
c += 1
else:
d += 1
if c <= d:
ans = True
break
if ans:
print('YES')
else:
print('NO')
| python | 10 | 0.463203 | 18 | 11.157895 | 19 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
for _ in range(int(input())):
n = int(input())
s = input()
heaven = False
one = 0
total = 0
for i in s:
if i == '1':
one += 1
total += 1
if 2 * one >= total:
heaven = True
break
else:
total += 1
if heaven:
print('YES')
else:
print('NO')
| python | 11 | 0.505495 | 29 | 13.368421 | 19 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
t = int(input())
for i in range(t):
n = int(input())
st = input()
g = 0
b = 0
d = 0
for i in st:
if i == '0':
b = b + 1
else:
g = g + 1
if g >= b:
print('YES')
d = d + 1
break
if d == 0:
print('NO')
| python | 11 | 0.419214 | 18 | 11.722222 | 18 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
for _ in range(int(input())):
l = int(input())
s = input()
c = 0
c1 = 0
x = 0
for i in range(l):
if s[i] == '0':
c += 1
else:
c1 += 1
if c1 >= c:
x = i + 1
break
if x == 0:
print('NO')
else:
print('YES')
| python | 10 | 0.435897 | 29 | 12 | 18 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
q = int(input())
while q > 0:
q -= 1
n = int(input())
l = input()
count = 0
flag = 0
for i in range(0, n):
if l[i] == '1':
count += 1
if count / (i + 1) * 100 >= 50:
flag = 1
break
if flag == 0:
print('NO')
else:
print('YES')
| python | 11 | 0.47012 | 33 | 13.764706 | 17 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
for t in range(int(input())):
l = input()
s = input()
one = 0
zero = 0
c = 0
for i in s:
if i == '1':
one = one + 1
else:
zero = zero + 1
if one >= zero:
c = c + 1
print('YES')
break
if c == 0:
print('NO')
| python | 11 | 0.461864 | 29 | 12.882353 | 17 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
tests = int(input())
for i in range(tests):
length = int(input())
string = input()
ans = 'NO'
zeroes = 0
ones = 0
for j in string:
if j == '0':
zeroes += 1
else:
ones += 1
if ones >= zeroes:
ans = 'YES'
break
print(ans)
| python | 10 | 0.546939 | 22 | 14.3125 | 16 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
for _ in range(int(input())):
n = int(input())
s = input()
(x, y) = (0, 0)
for i in s:
if i == '1':
x += 1
else:
y += 1
if x >= y:
print('YES')
break
else:
print('NO')
| python | 11 | 0.435233 | 29 | 12.785714 | 14 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
for _ in range(int(input())):
n = int(input())
s = input()
(a, b) = (0, 0)
for i in s:
if i == '1':
a += 1
else:
b += 1
if a >= b:
print('YES')
break
else:
print('NO')
| python | 11 | 0.435233 | 29 | 12.785714 | 14 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
T = int(input())
def algo():
L = int(input())
S = input()
b = 0
g = 0
out = 0
for i in S:
if i == '0':
b += 1
else:
g += 1
if g >= b:
out = 1
break
if out == 1:
print('YES')
else:
print('NO')
for i in range(T):
algo()
| python | 12 | 0.442688 | 18 | 10.5 | 22 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
T = int(input())
for i in range(T):
n = int(input())
l = str(input())
bad = 0
good = 0
p = False
for z in l:
if z == '1':
good += 1
else:
bad += 1
if good >= bad:
p = True
if p:
print('YES')
else:
print('NO')
| python | 10 | 0.483051 | 18 | 12.111111 | 18 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
from sys import stdin
for _ in range(int(stdin.readline())):
n = int(stdin.readline())
s = stdin.readline().strip()
q = 0
for c in s:
q += -1 if c == '0' else 1
if q >= 0:
break
print('NO' if q < 0 else 'YES')
| python | 10 | 0.572072 | 38 | 21.2 | 10 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
for _ in range(int(input())):
n = int(input())
s = input()
(c1, c2, f) = (0, 0, 0)
for i in s:
if i == '0':
c1 += 1
else:
c2 += 1
if c2 >= c1:
print('YES')
f = 1
break
if f == 0:
print('NO')
| python | 11 | 0.429224 | 29 | 13.6 | 15 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
t = int(input())
while t:
t -= 1
n = int(input())
s = input()
count0 = 0
count1 = 0
f = 0
for i in s:
if i == '0':
count0 += 1
else:
count1 += 1
if count1 >= count0:
print('YES')
f = 1
break
if f == 0:
print('NO')
| python | 11 | 0.477551 | 22 | 11.894737 | 19 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
for i in range(int(input())):
L = int(input())
S = str(input())
Y = 0
flag = False
if S.count('1') >= L / 2:
flag = True
else:
for ii in range(L):
Y = Y + int(S[ii])
if Y / (ii + 1) >= 0.5:
flag = True
break
print('YES') if flag else print('NO')
| python | 14 | 0.509225 | 38 | 18.357143 | 14 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
for _ in range(int(input())):
N = int(input())
S = input()
(One, zero) = (0, 0)
flag = False
for i in range(N):
if S[i] == '0':
zero += 1
else:
One += 1
if One >= zero:
flag = True
break
if flag:
print('YES')
else:
print('NO')
| python | 10 | 0.5 | 29 | 14.058824 | 17 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
t = int(input())
for i in range(t):
l = int(input())
s = input()
h = []
hl = []
for j in s:
if j == '0':
hl.append(j)
else:
h.append(j)
if len(h) >= len(hl):
print('YES')
break
else:
print('NO')
| python | 11 | 0.479638 | 23 | 12.8125 | 16 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
t = int(input())
for i in range(t):
L = int(input())
S = input()
good = 0
bad = 0
poss = False
for i in range(L):
if S[i] == '1':
good += 1
else:
bad += 1
if good >= bad:
poss = True
if poss:
print('YES')
else:
print('NO')
| python | 10 | 0.504 | 19 | 12.888889 | 18 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
for i in range(int(input())):
l = int(input())
s = input()
x = 'NO'
g = 0
b = 0
if s.count('1') >= l / 2:
x = 'YES'
else:
for i in s:
if g >= b and g != 0:
x = 'YES'
break
elif i == '1':
g += 1
else:
b += 1
print(x)
| python | 13 | 0.41502 | 29 | 13.055556 | 18 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
t = int(input())
for _ in range(t):
n = int(input())
life = str(input())
count = 0
if life.count('1') >= life.count('0'):
print('YES')
else:
i = 0
while i < n:
if life[i] == '0':
count = count - 1
else:
count = count + 1
if count >= 0:
break
i = i + 1
if count >= 0:
print('YES')
else:
print('NO')
| python | 14 | 0.484058 | 39 | 15.428571 | 21 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
for i in range(int(input())):
L = int(input())
s = input()
ones = 0
zeros = 0
for j in range(len(s)):
if s[j] == '0':
zeros += 1
else:
ones += 1
if ones >= zeros:
print('YES')
break
else:
print('NO')
| python | 11 | 0.50885 | 29 | 14.066667 | 15 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
t = int(input())
while t > 0:
l = int(input())
s = input()
i = 0
flg = 0
c0 = 0
c1 = 0
while i < l:
if s[i] == '1':
c1 += 1
if c1 * 100 / (i + 1) >= 50:
flg = 1
print('YES')
break
i += 1
if flg == 0:
print('NO')
t -= 1
| python | 13 | 0.40873 | 31 | 12.263158 | 19 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
for _ in range(int(input())):
L = int(input())
S = input()
bad = 0
good = 0
for i in range(L):
if i != 0 and bad <= good:
break
if S[i] == '0':
bad += 1
else:
good += 1
if bad <= good:
print('YES')
else:
print('NO')
| python | 10 | 0.491736 | 29 | 14.125 | 16 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
import math
for _ in range(int(input())):
n = int(input())
s = input()
l = 0
c = 0
for i in range(n):
if i != 0 and l <= c:
break
elif s[i] == '0':
l += 1
else:
c += 1
if l <= c:
print('YES')
else:
print('NO')
| python | 10 | 0.470339 | 29 | 12.882353 | 17 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
t = int(input())
for i in range(t):
g = 0
b = 0
ded = True
l = int(input())
s = input()
for j in s:
ded = True
if j == '1':
g += 1
if g >= b:
print('YES')
ded = False
break
elif j == '0':
b += 1
if g >= b:
print('YES')
ded = False
break
if ded:
print('NO')
| python | 14 | 0.444805 | 18 | 12.391304 | 23 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
t = int(input())
while t > 0:
n = int(input())
strg = list(input())
count_zero = 0
for i in range(n):
var = 'NO'
if strg[i] == '0':
count_zero += 1
if i + 1 - count_zero >= count_zero:
var = 'YES'
break
print(var)
t -= 1
| python | 10 | 0.520661 | 38 | 16.285714 | 14 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
testcasenum = int(input())
def heaven(deeds):
good_deeds = 0
bad_deeds = 0
for i in range(len(deeds)):
if deeds[i] == 1:
good_deeds += 1
elif deeds[i] == 0:
bad_deeds += 1
if good_deeds >= bad_deeds:
return 'YES'
return 'NO'
for __ in range(testcasenum):
life = int(input())
deeds = list(map(int, list(input())))
result = heaven(deeds)
print(result)
| python | 13 | 0.617647 | 38 | 19.777778 | 18 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
n = int(input())
num = []
dt = []
for i in range(0, n):
num.append(int(input()))
dt.append(input())
for j in range(0, n):
pas = 0
gd = 0
bd = 0
lst = list(dt[j])
for k in range(0, num[j]):
if lst[k] == '0':
bd = bd + 1
else:
gd = gd + 1
if gd >= bd:
pas = pas + 1
if pas == 0:
print('NO')
else:
print('YES')
| python | 11 | 0.491071 | 27 | 14.272727 | 22 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
for i in range(int(input())):
l = 0
c = 0
j = int(input())
st = input()
for i in range(0, len(st)):
if i != 0 and l <= c:
break
elif st[i] == '0':
l = l + 1
else:
c = c + 1
if l <= c:
print('YES')
else:
print('NO')
| python | 11 | 0.460581 | 29 | 14.0625 | 16 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
for _ in range(int(input())):
a = int(input())
b = input()
g = 0
p = 0
k = 0
for i in b:
if i == '1':
g += 1
if i == '0':
p += 1
if g >= p:
print('YES')
k = 1
break
if k == 0:
print('NO')
| python | 11 | 0.40367 | 29 | 11.823529 | 17 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
T = int(input())
for i in range(T):
L = int(input())
S = input()
count = 0
count1 = 0
for j in S:
if int(j) == 1:
count += 1
else:
count1 += 1
if count >= count1:
print('YES')
break
if count1 > count:
print('NO')
| python | 11 | 0.527197 | 21 | 13.9375 | 16 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
t = int(input())
while t > 0:
l = int(input())
s = input()
countz = 0
counto = 0
for i in range(0, len(s)):
if s[i] == '0':
countz = countz + 1
else:
counto = counto + 1
if counto >= countz:
print('YES')
break
if countz > counto:
print('NO')
t = t - 1
| python | 11 | 0.526882 | 27 | 15.411765 | 17 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
def main():
for _ in range(int(input())):
L = int(input())
S = input()
(gy, by) = (0, 0)
ans = 'NO'
for i in range(L):
if S[i] == '1':
gy += 1
else:
by += 1
if gy >= by:
ans = 'YES'
break
print(ans)
main()
| python | 12 | 0.438525 | 30 | 14.25 | 16 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
t = int(input())
for i in range(t):
L = int(input())
S = input()
total1 = 0
total2 = 0
flag = 0
for i in range(L):
if S[i] == '0':
total1 += 1
else:
total2 += 1
if total2 >= total1:
flag = 1
print('YES')
break
if flag == 0:
print('NO')
| python | 14 | 0.503704 | 23 | 14 | 18 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
class Person:
def __init__(self, deed):
self.deed = deed
def good_deed(self):
self.deed += 1
def bad_deed(self):
self.deed -= 1
person = Person(1)
t = int(input())
while t:
t -= 1
n = int(input())
s = input()
person.deed = 1
for i in s:
if i == '0':
person.bad_deed()
else:
person.good_deed()
if person.deed > 0:
break
if person.deed > 0:
print('YES')
else:
print('NO')
| python | 11 | 0.571078 | 26 | 13.571429 | 28 | When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must spend at least $50\%$ of his life years doing good deeds. He also shows them his future using a string $S$ of length $L$ where $S_{i} = 0$ means the $i$-th year will be counted as bad as per the rule books of heaven and $S_{i} = 1$ means the $i$-th year will be counted as good.
Also, Strange can use his special powers to make Chef end his life earlier than that planned by god, i.e, he can choose some $L'$ ($1β€ L'β€ L$) and make him live for only $L' $ years. Strange wants Chef to succeed, so if there is any choice of $L'$ that allows Chef to go to heaven, he will do so.
Tell whether Chef can go to heaven.
------ Input ------
The first line contains an integer $T$, the number of test cases. Then the test cases follow.
Each test case contains two lines of input.
The first line contains a single integer $L$.
The second line contains a string $S$ of length $L$, consisting of symbols 0 and 1.
------ Output ------
For each test case, output the answer in a single line: "YES" if Chef can go to heaven and "NO" if not (without quotes).
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 β€ L β€ 10^{5}$
The sum of $L$ over all tests does not exceed $10^{6}$
------ Subtasks ------
Subtask #1 (100 points): original constraints
----- Sample Input 1 ------
3
2
10
3
001
4
0100
----- Sample Output 1 ------
YES
NO
YES
----- explanation 1 ------
Test case 1: If Chef lives for the complete $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven.
Test case 2: There's no way Chef can go to heaven.
Test case 3: If Chef lives for $2$ years, he will have a total of $1$ good year which is $\frac{1 * 100}{2} = 50\%$ of his life, and hence he will go to heaven. | taco |
class Solution:
def findSubString(self, str):
dict = {}
ans = float('inf')
j = 0
for i in str:
if i not in dict:
dict[i] = 0
length = len(dict)
for i in range(len(str)):
dict[str[i]] += 1
if dict[str[i]] == 1:
length -= 1
while length == 0:
ans = min(ans, i - j + 1)
dict[str[j]] -= 1
if dict[str[j]] == 0:
length += 1
j += 1
return ans
| python | 15 | 0.505076 | 30 | 17.761905 | 21 | Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time.
For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca.
Example 1:
Input : "AABBBCBBAC"
Output : 3
Explanation : Sub-string -> "BAC"
Example 2:
Input : "aaab"
Output : 2
Explanation : Sub-string -> "ab"
Example 3:
Input : "GEEKSGEEKSFOR"
Output : 8
Explanation : Sub-string -> "GEEKSFOR"
Your Task:
You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string.
Expected Time Complexity: O(256.N)
Expected Auxiliary Space: O(256)
Constraints:
1 β€ |S| β€ 10^{5}
String may contain both type of English Alphabets. | taco |
from collections import defaultdict
class Solution:
def findSubString(self, s):
n = len(s)
dist_count = len(set([x for x in s]))
m = defaultdict(int)
start = 0
min_len = float('inf')
count = 0
for j in range(n):
m[s[j]] += 1
if m[s[j]] == 1:
count += 1
if count == dist_count:
while m[s[start]] > 1:
if m[s[start]] > 1:
m[s[start]] -= 1
start += 1
len_window = j - start + 1
if min_len > len_window:
min_len = len_window
return min_len
| python | 17 | 0.550898 | 39 | 19.875 | 24 | Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time.
For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca.
Example 1:
Input : "AABBBCBBAC"
Output : 3
Explanation : Sub-string -> "BAC"
Example 2:
Input : "aaab"
Output : 2
Explanation : Sub-string -> "ab"
Example 3:
Input : "GEEKSGEEKSFOR"
Output : 8
Explanation : Sub-string -> "GEEKSFOR"
Your Task:
You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string.
Expected Time Complexity: O(256.N)
Expected Auxiliary Space: O(256)
Constraints:
1 β€ |S| β€ 10^{5}
String may contain both type of English Alphabets. | taco |
class Solution:
def findSubString(self, str):
from collections import defaultdict
n = len(str)
if n <= 1:
return 1
dist_count = len(set([x for x in str]))
curr_count = defaultdict(lambda : 0)
count = 0
start = 0
min_len = n
for j in range(n):
curr_count[str[j]] += 1
if curr_count[str[j]] == 1:
count += 1
if count == dist_count:
while curr_count[str[start]] > 1:
if curr_count[str[start]] > 1:
curr_count[str[start]] -= 1
start += 1
len_window = j - start + 1
min_len = min(min_len, len_window)
start_index = start
return min_len
| python | 17 | 0.590682 | 41 | 23.04 | 25 | Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time.
For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca.
Example 1:
Input : "AABBBCBBAC"
Output : 3
Explanation : Sub-string -> "BAC"
Example 2:
Input : "aaab"
Output : 2
Explanation : Sub-string -> "ab"
Example 3:
Input : "GEEKSGEEKSFOR"
Output : 8
Explanation : Sub-string -> "GEEKSFOR"
Your Task:
You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string.
Expected Time Complexity: O(256.N)
Expected Auxiliary Space: O(256)
Constraints:
1 β€ |S| β€ 10^{5}
String may contain both type of English Alphabets. | taco |
class Solution:
def findSubString(self, s):
D = {}
for i in s:
if i in D:
pass
else:
D[i] = 1
n = len(s)
(i, j) = (0, 0)
count = len(D)
mini = 9999
while j < n:
if s[j] in D:
D[s[j]] -= 1
if D[s[j]] == 0:
count -= 1
while count == 0:
mini = min(mini, j - i + 1)
if s[i] in D:
D[s[i]] += 1
if D[s[i]] > 0:
count += 1
i += 1
j += 1
return mini
| python | 15 | 0.417453 | 31 | 14.703704 | 27 | Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time.
For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca.
Example 1:
Input : "AABBBCBBAC"
Output : 3
Explanation : Sub-string -> "BAC"
Example 2:
Input : "aaab"
Output : 2
Explanation : Sub-string -> "ab"
Example 3:
Input : "GEEKSGEEKSFOR"
Output : 8
Explanation : Sub-string -> "GEEKSFOR"
Your Task:
You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string.
Expected Time Complexity: O(256.N)
Expected Auxiliary Space: O(256)
Constraints:
1 β€ |S| β€ 10^{5}
String may contain both type of English Alphabets. | taco |
class Solution:
def findSubString(self, str):
mp = {}
cnt = 0
for i in range(len(str)):
if str[i] not in mp:
mp[str[i]] = 0
cnt += 1
cnt1 = 0
j = 0
mn = len(str)
for i in range(len(str)):
if mp[str[i]] == 0:
mp[str[i]] += 1
cnt1 += 1
else:
mp[str[i]] += 1
while cnt == cnt1:
mn = min(mn, i - j + 1)
if mp[str[j]] == 1:
mp[str[j]] -= 1
cnt1 -= 1
j = j + 1
else:
mp[str[j]] -= 1
j = j + 1
return mn
| python | 16 | 0.444215 | 30 | 16.285714 | 28 | Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time.
For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca.
Example 1:
Input : "AABBBCBBAC"
Output : 3
Explanation : Sub-string -> "BAC"
Example 2:
Input : "aaab"
Output : 2
Explanation : Sub-string -> "ab"
Example 3:
Input : "GEEKSGEEKSFOR"
Output : 8
Explanation : Sub-string -> "GEEKSFOR"
Your Task:
You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string.
Expected Time Complexity: O(256.N)
Expected Auxiliary Space: O(256)
Constraints:
1 β€ |S| β€ 10^{5}
String may contain both type of English Alphabets. | taco |
class Solution:
def findSubString(self, str):
dict = {}
a = 1000000000.0
j = 0
for i in str:
if i not in dict:
dict[i] = 0
l = len(dict)
for i in range(len(str)):
dict[str[i]] += 1
if dict[str[i]] == 1:
l -= 1
while l == 0:
a = min(a, i - j + 1)
dict[str[j]] -= 1
if dict[str[j]] == 0:
l += 1
j += 1
return a
| python | 15 | 0.47541 | 30 | 16.428571 | 21 | Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time.
For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca.
Example 1:
Input : "AABBBCBBAC"
Output : 3
Explanation : Sub-string -> "BAC"
Example 2:
Input : "aaab"
Output : 2
Explanation : Sub-string -> "ab"
Example 3:
Input : "GEEKSGEEKSFOR"
Output : 8
Explanation : Sub-string -> "GEEKSFOR"
Your Task:
You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string.
Expected Time Complexity: O(256.N)
Expected Auxiliary Space: O(256)
Constraints:
1 β€ |S| β€ 10^{5}
String may contain both type of English Alphabets. | taco |
class Solution:
def findSubString(self, s):
distinct = len(set(s))
d = dict()
si = -1
Len = 100000.0
start = 0
for i in range(len(s)):
if s[i] not in d:
d[s[i]] = 1
else:
d[s[i]] += 1
if len(d) == distinct:
while d[s[start]] > 1:
d[s[start]] -= 1
start += 1
clen = i - start + 1
if Len > clen:
Len = clen
si = start
return len(s[si:si + Len])
| python | 15 | 0.495098 | 28 | 17.545455 | 22 | Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time.
For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca.
Example 1:
Input : "AABBBCBBAC"
Output : 3
Explanation : Sub-string -> "BAC"
Example 2:
Input : "aaab"
Output : 2
Explanation : Sub-string -> "ab"
Example 3:
Input : "GEEKSGEEKSFOR"
Output : 8
Explanation : Sub-string -> "GEEKSFOR"
Your Task:
You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string.
Expected Time Complexity: O(256.N)
Expected Auxiliary Space: O(256)
Constraints:
1 β€ |S| β€ 10^{5}
String may contain both type of English Alphabets. | taco |
from collections import defaultdict
class Solution:
def findSubString(self, str):
leng = len(str)
(start, end) = (0, leng - 1)
ct = 0
t_dist = len(set([e for e in str]))
chr_map = defaultdict(lambda : 0)
min_wind = leng
for i in range(leng):
x = str[i]
chr_map[x] += 1
if chr_map[x] == 1:
ct += 1
if ct == t_dist:
while chr_map[str[start]] > 1:
chr_map[str[start]] -= 1
start += 1
min_wind = min(i - start + 1, min_wind)
return min_wind
| python | 15 | 0.569388 | 43 | 21.272727 | 22 | Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time.
For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca.
Example 1:
Input : "AABBBCBBAC"
Output : 3
Explanation : Sub-string -> "BAC"
Example 2:
Input : "aaab"
Output : 2
Explanation : Sub-string -> "ab"
Example 3:
Input : "GEEKSGEEKSFOR"
Output : 8
Explanation : Sub-string -> "GEEKSFOR"
Your Task:
You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string.
Expected Time Complexity: O(256.N)
Expected Auxiliary Space: O(256)
Constraints:
1 β€ |S| β€ 10^{5}
String may contain both type of English Alphabets. | taco |
class Solution:
def findSubString(self, str):
n = len(str)
(dic, vic) = ({}, {})
for a in str:
if a not in dic:
dic[a] = 0
dic[a] += 1
(i, j, ans) = (0, 0, 10000000000)
while j < n:
if str[j] not in vic:
vic[str[j]] = 0
vic[str[j]] += 1
if len(vic) == len(dic):
while len(vic) == len(dic):
vic[str[i]] -= 1
if vic[str[i]] == 0:
del vic[str[i]]
i += 1
ans = min(ans, 2 + j - i)
j += 1
return ans
| python | 16 | 0.469828 | 35 | 19.173913 | 23 | Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time.
For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca.
Example 1:
Input : "AABBBCBBAC"
Output : 3
Explanation : Sub-string -> "BAC"
Example 2:
Input : "aaab"
Output : 2
Explanation : Sub-string -> "ab"
Example 3:
Input : "GEEKSGEEKSFOR"
Output : 8
Explanation : Sub-string -> "GEEKSFOR"
Your Task:
You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string.
Expected Time Complexity: O(256.N)
Expected Auxiliary Space: O(256)
Constraints:
1 β€ |S| β€ 10^{5}
String may contain both type of English Alphabets. | taco |
class Solution:
def findSubString(self, str):
dict = {}
ans = 1000000000.0
for i in str:
if i not in dict:
dict[i] = 0
length = len(dict)
count = 0
j = 0
for i in range(len(str)):
dict[str[i]] += 1
if dict[str[i]] == 1:
count += 1
while count == length:
ans = min(ans, i - j + 1)
dict[str[j]] -= 1
if dict[str[j]] == 0:
count -= 1
j += 1
return ans
| python | 15 | 0.514706 | 30 | 17.545455 | 22 | Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time.
For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca.
Example 1:
Input : "AABBBCBBAC"
Output : 3
Explanation : Sub-string -> "BAC"
Example 2:
Input : "aaab"
Output : 2
Explanation : Sub-string -> "ab"
Example 3:
Input : "GEEKSGEEKSFOR"
Output : 8
Explanation : Sub-string -> "GEEKSFOR"
Your Task:
You don't need to read input or print anything. Your task is to complete the function findSubString() which takes the string S as input and returns the length of the smallest such window of the string.
Expected Time Complexity: O(256.N)
Expected Auxiliary Space: O(256)
Constraints:
1 β€ |S| β€ 10^{5}
String may contain both type of English Alphabets. | taco |