description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
from sys import stdin, stdout def main(): from sys import stdin, stdout n, t = map(int, stdin.readline().split()) arr = list(map(int, stdin.readline().split())) maxim = 0 curr_sum = arr[0] i = 0 j = 1 if curr_sum <= t: count = 1 else: curr_sum = 0 count = 0...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR ...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
import sys n = 0 t = 0 A = [] def readInput(): global n global t global A i = 1 for line in sys.stdin: _d = line.split(" ") if i == 1: n = int(_d[0]) t = int(_d[1]) if i == 2: for x in _d: A.append(int(x)) i += 1 ...
IMPORT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASS...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
n, k = map(int, input().split()) b = list(map(int, input().split())) a = 0 bt = c = x = 0 for i in range(n): if bt + b[i] > k: a = max(a, x) bt = bt - b[c] c += 1 if b[i] == k: a = max(a, 1) bt = x = 0 c = i + 1 elif b[i] > k: b...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR ...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
import sys input = sys.stdin.readline n, t = list(map(int, input().split())) times = list(map(int, input().split())) left = 0 right = 0 maxLen = 0 sumTimes = 0 while right < n: sumTimes += times[right] while sumTimes > t: sumTimes -= times[left] left += 1 maxLen = max(right - left + 1, maxL...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
import sys n, t = map(int, sys.stdin.readline().split()) a = list(map(int, sys.stdin.readline().split())) s = 0 if min(a) > t: l = 0 else: l = 1 tmp_s = 0 for i in range(n): if i > 0: tmp_s -= a[i - 1] tmp_s += a[i + l - 1] for j in range(i + l, n): if tm...
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR ...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
n, t = map(int, input().split()) a = list(map(int, input().split())) prefix_sum = [0] for i in range(n): prefix_sum.append(prefix_sum[i] + a[i]) x, y = 0, 1 ans = 0 n += 1 while y < n: if prefix_sum[y] - prefix_sum[x] <= t: if ans < y - x: ans = y - x y += 1 else: x += 1 ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR VAR VAR IF ...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
n, t = map(int, input().split()) arr = list(map(int, input().split())) sum = 0 right = 0 while right < n: if sum + arr[right] <= t: sum += arr[right] right += 1 else: break left = 0 len = right maxlen = right while right < n: if right != left: sum -= arr[left] left +=...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER W...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
n = input() n = n.split() n = list(map(int, n)) t = n[1] n = n[0] ai = input() ai = ai.split() ai = list(map(int, ai)) leftI = 0 rightI = 0 totalTime = 0 count = 0 maxm = 0 while rightI < n: if totalTime + ai[rightI] <= t: totalTime += ai[rightI] rightI += 1 count += 1 if count > max...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
inp = list(map(int, input("").split(" "))) n, m = inp[0], inp[1] nums = list(map(int, input("").split(" "))) l = 0 total = 0 result = 0 for r in range(len(nums)): total += nums[r] if total > m: total -= nums[l] l += 1 result = max(result, r - l + 1) print(result)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING STRING ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR ...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
n, t = input().split() n, t = map(int, [n, t]) s = input() A = [] for i in s.split(): A.append(int(i)) Max = 0 time = 0 count = 0 x = 0 for j in range(0, n): time = time + A[j] count = count + 1 if time > t: time = time - A[x] x = x + 1 count = count - 1 elif time == t: ...
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR LIST VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR ...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
def book_(): n, t = map(int, input().split()) l = [] l = [int(num) for num in input().split()] m = len(l) max = 0 sum = 0 c = 0 i = 0 while i < len(l) and len(l) > 0: sum = sum + l[i] if sum <= t: c = c + 1 i = i + 1 if max <= c: ...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR V...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
n, t = map(int, input().split()) times = list(map(int, input().split())) left = 0 right = 0 maxbooks = 0 summa = times[0] cont = True while cont: if summa <= t: if right - left + 1 > maxbooks: maxbooks = right - left + 1 if right < n - 1: right = right + 1 summa =...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR IF VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VA...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
n, t = (int(x) for x in input().split()) a = [int(x) for x in input().split()] st = set() s = 0 ss = [] for i in range(n): s += a[i] ss.append(s) for i in range(n): lb, ub = i, n - 1 while lb <= ub: mid = int(lb + (ub - lb) / 2) v = ss[mid] - ss[i] + a[i] if v > t: ub...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIG...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
def main(): N, T = map(int, input().split()) books = list(map(int, input().split())) leftIndex = 0 rightIndex = 0 totalTime = 0 currentBooks = 0 maximumBooks = 0 while rightIndex < N: totalTime += books[rightIndex] currentBooks += 1 if totalTime > T: t...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSI...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
n, t = [int(i) for i in input().split(" ")] time = [int(i) for i in input().split(" ")] _sum = 0 cnt = 0 maxcnt = 0 for i in range(n): if _sum + time[i] <= t: _sum += time[i] cnt += 1 elif _sum != 0: _sum = _sum - time[i - cnt] + time[i] maxcnt = max(cnt, maxcnt) print(maxcnt)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR V...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
n, t = map(int, input().split()) A = [int(i) for i in input().split()] sum1 = 0 i, j = 0, 0 k = t - A[0] if k > 0: sum1 = 1 while i < n - 1 and j < n - 1: if A[j + 1] <= k: j += 1 k -= A[j] if sum1 < j - i + 1: sum1 = j - i + 1 else: i += 1 k += A[i - 1] p...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR ...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
n, t = map(int, input().split()) a = list(map(int, input().split()))[:n] res, time, count, j = 0, 0, 0, 0 for i in range(n): time += a[i] count += 1 while time > t: time -= a[j] j += 1 count -= 1 if res < count: res = count print(res)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
def solution(): n, t = map(int, input().split()) a = list(map(int, input().split())) l = len(a) if l < 2: if a[0] <= t: print(1) else: print(0) return result = [] firstIndex = 0 totalMinute = a[firstIndex] totalBook = 0 previousFirst = ...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUM...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
n, t = map(int, input().split()) a = list(map(int, input().split())) k = 0 su = 0 for i in range(n): if su + a[i] <= t: su += a[i] k += 1 else: break for i in range(n): try: su -= a[i] su += a[k + i] if su + a[i + k + 1] <= t: r = k for...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR BIN_OP...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
n, time_limit = map(int, input().split()) book = list(map(int, input().split())) readingTime = count = ans = i = j = 0 while i < n: if readingTime + book[i] <= time_limit: readingTime += book[i] count += 1 ans = max(ans, count) i += 1 else: readingTime -= book[j] ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VA...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
n, t = map(int, input().split()) a = list(map(int, input().split())) s = r = l = m = 0 for i in range(n): while r < n: if s + a[r] <= t: s += a[r] r += 1 else: break l += 1 if l > m: m = l if i != r: s -= a[i] l -= 1 els...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER VAR NU...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
from sys import stdin, stdout def solve(n, t, books): sam = 0 cnt = 0 time = 0 count = 0 i = 0 while i < n: if time + books[i] > t: time -= books[cnt] cnt += 1 i -= 1 sam -= 1 else: time += books[i] sam += ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL F...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
n, t = map(int, input().split()) ls = list(map(int, input().split())) mn = -1 s = 0 i = j = 0 while s + ls[i] <= t: s = s + ls[i] i = i + 1 if i == n: break if i > mn: mn = i while i < n: if s + ls[i] > t: s = s - ls[j] if i - j > mn: mn = i - j j = j + 1 ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR IF VAR VAR ASSIGN VAR VAR WHILE VAR VAR...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
n, t = map(int, input().split()) A = [int(x) for x in input().split()] a, b, j = 0, 0, 0 for i in range(n): while A[i] > t: t += A[j] j += 1 b -= 1 t -= A[i] b += 1 a = max(a, b) print(a)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
n, t = map(int, input().split()) arrMinutes = list(map(int, input().split())) amount = [] count = 0 sumMinute = 0 index = 0 for i in range(n): if sumMinute + arrMinutes[i] <= t: sumMinute = sumMinute + arrMinutes[i] count += 1 index = i else: break if count == n: print(count)...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR EXPR FU...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
n, t = map(int, input().split()) a = [int(i) for i in input().split()] m = 0 i, j = 0, 0 for j in range(n): m = m + a[j] if m > t: m = m - a[i] i += 1 print(len(a) - 1 - i + 1)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL V...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
n, t = map(int, input().split()) A = list(map(int, input().split())) l = 0 r = 0 lenght = 0 c = 0 S = 0 while r < len(A): if A[r] > t: r += 1 l += 1 continue while S <= t and r < len(A): S += A[r] r += 1 if r == len(A) and S <= t: r += 1 S = S - A[l] l...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR FUNC_CALL VAR VAR VAR V...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
n, t = [int(x) for x in input().split()] arr = [int(x) for x in input().split()] z, c = 0, 0 for i in range(n): if z + arr[i] <= t: z = z + arr[i] c += 1 else: break l = 0 r = c if c == n: print(c) exit() read = [] read.append(c) aa = 0 for i in range(1, n): z = z - arr[l] ...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CAL...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
n_books, total_time = [int(x) for x in input().split()] estimated_times = [int(x) for x in input().split()] max_len = 0 group = [] sum_time = 0 for t in estimated_times: group.append(t) sum_time += t if sum_time <= total_time: if len(group) > max_len: max_len = len(group) else: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR IF VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR NUMBER VAR NUMBER EX...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
n, t = map(int, input().split()) max_answer = 0 a = list(map(int, input().split())) answer = 0 reading = 0 for i in range(n): reading += a[i] if reading <= t: answer += 1 if max_answer < answer: max_answer = answer else: reading -= a[i - answer] print(max_answer)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
n, t = map(int, input().split()) a = list(map(int, input().split())) i, s, j, count, r = 0, 0, 0, 0, 0 while i < n and j < n: if s + a[j] > t: s -= a[i] i += 1 count -= 1 else: s += a[j] j += 1 count += 1 r = max(r, count) print(r)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER NUMBER WHILE VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CA...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
n, x = map(int, input().split()) a = map(int, input().split()) b = [] for i in a: b.append(i) h = 0 t = 0 c = 0 l = 0 ml = 0 for i in range(n): c = c + b[i] h = h + 1 l = l + 1 if c > x: l = l - 1 c = c - b[t] t = t + 1 if ml < l: ml = l print(ml)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BI...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
n, t = map(int, input().split()) a = list(map(int, input().split())) l = [0] j = 0 max = 0 for i in range(n): l.append(l[-1] + a[i]) if l[i + 1] - l[j] > t: j += 1 if i + 1 - j > max: max = i + 1 - j print(max)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER IF BIN_OP B...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
n, t = map(int, input().split()) a = list(map(int, input().split())) i_min, i_max = 0, 0 N, T = 0, 0 while (i_min < n) & (i_max < n): while T <= t - a[i_max]: T += a[i_max] i_max += 1 if i_max >= n: break if N < i_max - i_min: N = i_max - i_min T -= a[i_min] i...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE BIN_OP VAR VAR VAR VAR WHILE VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VA...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
n, t = list(map(int, input().split())) A = list(map(int, input().split())) ans = 0 ind = 0 best = 0 for i in range(n): if i >= ind: ind = i ans = 0 while ind < n and t >= A[ind]: ans += 1 t -= A[ind] ind += 1 if ans > best: best = ans if ind == n: ...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBE...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
books, minutes = map(int, input().split()) a_minutes = list(map(int, input().split())) c = 0 tmp_times = 0 tmp_c = 0 for i in range(books): if tmp_times + a_minutes[i] <= minutes: c += 1 tmp_times += a_minutes[i] else: break tmp_c = c for j in range(books): tmp_times -= a_minutes[j] ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR WHILE VAR VAR ...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
n, t = [int(i) for i in input().split()] arr = [int(i) for i in input().split()] pre = [] i = 0 j = 0 s = 0 while n > j >= i: flag = 0 if s + arr[j] <= t: s += arr[j] flag = 1 j = j + 1 else: pre.append(j - 1 - i + 1) if s > 0: s -= arr[i] if i == ...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_C...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
n, t = [int(i) for i in input().split()] books = [int(i) for i in input().split()] begin = end = tsum = ans = 0 while True: if tsum <= t: ans = max(ans, end - begin) if tsum <= t and end < n: tsum += books[end] end += 1 elif begin < end: tsum -= books[begin] begin += ...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER WHILE NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VA...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
nt = input().split() n, t = (int(x) for x in nt) line = input().split() times = [int(x) for x in line] total_time = 0 counter = 0 max_counter = 0 read_books = [] for time in times: if total_time + time <= t: total_time += time read_books.append(time) counter += 1 if counter > max_cou...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
n, t = map(int, input().split()) f = list(map(int, input().split())) sums = [0, f[0]] max_book = 0 for i in range(1, n): sums.append(sums[i] + f[i]) for start in range(1, n + 1): for end in range(start + max_book, n + 1): k = sums[end] - sums[start - 1] if k > t: break else: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR ...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
n, t = map(int, input().split()) s = input() a = s.split() summ = 0 k = 0 l = 0 maxim = 0 for i in range(len(a)): summ = summ + int(a[i]) k += 1 l += 1 if summ > t: while summ > t: summ = summ - int(a[i + 1 - k]) k -= 1 l -= 1 if l > maxim: maxim =...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR WHILE VAR VAR ASSIGN VAR...
When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs a_{i} minutes to read t...
import sys input = lambda: sys.stdin.readline().strip("\r\n") n, t = map(int, input().split()) a = list(map(int, input().split())) asum = 0 j = 0 ans = 0 for i in range(n): asum += a[i] if asum > t: asum -= a[j] j += 1 ans = max(ans, i - j + 1) print(ans)
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL ...
You are given an integer $n$. Find a sequence of $n$ distinct integers $a_1, a_2, \dots, a_n$ such that $1 \leq a_i \leq 10^9$ for all $i$ and $$\max(a_1, a_2, \dots, a_n) - \min(a_1, a_2, \dots, a_n)= \sqrt{a_1 + a_2 + \dots + a_n}.$$ It can be proven that there exists a sequence of distinct integers that satisfies a...
import sys input = sys.stdin.readline def readList(): return list(map(int, input().split())) def readInt(): return int(input()) def readInts(): return map(int, input().split()) def readStr(): return input().strip() def solve(): n = readInt() if n % 2: ans = [(i + 2) for i in r...
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ...
You are given an integer $n$. Find a sequence of $n$ distinct integers $a_1, a_2, \dots, a_n$ such that $1 \leq a_i \leq 10^9$ for all $i$ and $$\max(a_1, a_2, \dots, a_n) - \min(a_1, a_2, \dots, a_n)= \sqrt{a_1 + a_2 + \dots + a_n}.$$ It can be proven that there exists a sequence of distinct integers that satisfies a...
import sys input = sys.stdin.readline def inp(): return int(input()) def inlt(): return list(map(int, input().split())) def insr(): s = input() return list(s[: len(s) - 1]) def invr(): return map(int, input().split()) for passer in range(inp()): n = inp() if n % 2 == 0: ls...
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL V...
You are given an integer $n$. Find a sequence of $n$ distinct integers $a_1, a_2, \dots, a_n$ such that $1 \leq a_i \leq 10^9$ for all $i$ and $$\max(a_1, a_2, \dots, a_n) - \min(a_1, a_2, \dots, a_n)= \sqrt{a_1 + a_2 + \dots + a_n}.$$ It can be proven that there exists a sequence of distinct integers that satisfies a...
for _ in range(int(input())): n = int(input()) if n % 2 == 0: print(*[i for i in range(n // 2, n // 2 + n + 1) if i != n]) else: a = list(range(n // 2 + 3, n // 2 + 3 + n)) a[0] -= 1 a[-1] += 1 a[-2] += 1 print(*a)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP V...
You are given an integer $n$. Find a sequence of $n$ distinct integers $a_1, a_2, \dots, a_n$ such that $1 \leq a_i \leq 10^9$ for all $i$ and $$\max(a_1, a_2, \dots, a_n) - \min(a_1, a_2, \dots, a_n)= \sqrt{a_1 + a_2 + \dots + a_n}.$$ It can be proven that there exists a sequence of distinct integers that satisfies a...
for _ in range(int(input())): n = int(input()) if n % 2: ad = n - (n + 1) // 2 v = [(i + ad + 2) for i in range(1, n + 1)] v[0] -= 1 v[-1] += 1 v[-2] += 1 print(" ".join(map(str, v))) else: ad = (2 * n - 1 - (n + 1)) // 2 v = [(i + ad) for i in...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR ...
You are given an integer $n$. Find a sequence of $n$ distinct integers $a_1, a_2, \dots, a_n$ such that $1 \leq a_i \leq 10^9$ for all $i$ and $$\max(a_1, a_2, \dots, a_n) - \min(a_1, a_2, \dots, a_n)= \sqrt{a_1 + a_2 + \dots + a_n}.$$ It can be proven that there exists a sequence of distinct integers that satisfies a...
for i in range(int(input())): n = int(input()) a = [0] * n if n % 2 == 0: for j in range(n): a[j] = j + n // 2 for j in range((n + 1) // 2, n): a[j] += 1 else: for j in range(n): a[j] = j + n // 2 + 3 a[0] -= 1 a[n - 1] += 1 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ...
You are given an integer $n$. Find a sequence of $n$ distinct integers $a_1, a_2, \dots, a_n$ such that $1 \leq a_i \leq 10^9$ for all $i$ and $$\max(a_1, a_2, \dots, a_n) - \min(a_1, a_2, \dots, a_n)= \sqrt{a_1 + a_2 + \dots + a_n}.$$ It can be proven that there exists a sequence of distinct integers that satisfies a...
for _ in range(int(input())): n = int(input()) if n % 2 == 0: ans = [] val = n // 2 cnt = 0 while cnt < n: if val != n: ans.append(val) cnt += 1 val += 1 print(*ans) else: ans = [] cnt = 0 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR BI...
You are given an integer $n$. Find a sequence of $n$ distinct integers $a_1, a_2, \dots, a_n$ such that $1 \leq a_i \leq 10^9$ for all $i$ and $$\max(a_1, a_2, \dots, a_n) - \min(a_1, a_2, \dots, a_n)= \sqrt{a_1 + a_2 + \dots + a_n}.$$ It can be proven that there exists a sequence of distinct integers that satisfies a...
for _ in range(int(input())): n = int(input()) if n % 2 == 1: num = [(x + (n - 1) // 2 + 2) for x in range(1, n + 1)] num[-1] += 1 num[0] -= 1 num[-2] += 1 else: num = [] for i in range(n // 2, n // 2 + n): if i != n: num.append(i) ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR ...
You are given an integer $n$. Find a sequence of $n$ distinct integers $a_1, a_2, \dots, a_n$ such that $1 \leq a_i \leq 10^9$ for all $i$ and $$\max(a_1, a_2, \dots, a_n) - \min(a_1, a_2, \dots, a_n)= \sqrt{a_1 + a_2 + \dots + a_n}.$$ It can be proven that there exists a sequence of distinct integers that satisfies a...
t = int(input()) for it in range(t): n = int(input()) if n % 2: a = [i for i in range(n - n // 2, n + n // 2 + 1)] a = [(a[i] + 2) for i in range(n)] a[0] -= 1 a[n - 1] += 1 a[n - 2] += 1 a = [str(a[i]) for i in range(n)] print(" ".join(a)) else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR BIN_OP VAR NU...
You are given an integer $n$. Find a sequence of $n$ distinct integers $a_1, a_2, \dots, a_n$ such that $1 \leq a_i \leq 10^9$ for all $i$ and $$\max(a_1, a_2, \dots, a_n) - \min(a_1, a_2, \dots, a_n)= \sqrt{a_1 + a_2 + \dots + a_n}.$$ It can be proven that there exists a sequence of distinct integers that satisfies a...
for t in range(int(input())): n = int(input()) if n % 2 == 0: ans = list(range(int(n / 2), n)) + list(range(n + 1, int(3 * n / 2) + 1)) else: ans = list(range(n - int(n / 2) + 2, n + int(n / 2) + 3)) ans[0] -= 1 ans[-1] += 1 ans[-2] += 1 print(" ".join([str(x) for...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC...
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: def atMost(A: List[int], k: int) -> int: i = ret = 0 for j in range(len(A)): if A[j] & 1: k -= 1 while k < 0: k += A[i] & 1 ...
CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUM...
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: i = count = nice_count = odd_count = 0 for j in range(len(nums)): if nums[j] % 2 == 1: odd_count += 1 count = 0 while odd_count == k: odd_count -= num...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR RETURN VAR VAR
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: def AtMostK(k): left = 0 count = 0 currK = 0 for index in range(len(nums)): if nums[index] % 2 == 1: currK += 1 while currK > k: ...
CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR RETURN BIN_OP FUNC_CALL VAR VAR...
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: cnt = 0 accNum = {} ans = 0 accNum[0] = 1 for x in nums: if x % 2: cnt += 1 if cnt not in accNum: accNum[cnt] = 1 else: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR RETURN VAR VAR
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: cur = res = i = 0 for j in range(len(nums)): if nums[j] % 2 != 0: k -= 1 if k == 0: cur = 1 while nums[i] % 2 == 0: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR VAR RETURN VAR VAR
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, A: List[int], k: int) -> int: d = [] n = len(A) res = 0 count = 1 for i in range(n): if A[i] % 2: d.append(count) count = 1 else: count += 1 d.append(c...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR RETURN VAR VAR
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: return self.numberOfAtmostK(nums, k) - self.numberOfAtmostK(nums, k - 1) def numberOfAtmostK(self, nums, k): l, r, count, res = 0, 0, 0, 0 while r < len(nums): if nums[r] % 2 == 1: ...
CLASS_DEF FUNC_DEF VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP BIN...
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
def solve(A, k): count = [0, 0] lower = (x % 2 for x in A) ans = 0 for x in (x % 2 for x in A): count[x] += 1 while count[1] > k: count[next(lower)] -= 1 ans += sum(count) return ans class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> in...
FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER WHILE VAR NUMBER VAR VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR RETURN VAR CLASS_DEF FUNC_DEF VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VA...
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: memo = {(0): 1} count = 0 res = 0 for n in nums: if n % 2 == 1: count += 1 if count - k in memo: res += memo[count - k] memo[count] = memo...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR VAR
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: n = len(nums) def at_most_k(k: int) -> int: i, j, odds = 0, 0, 0 res = 0 while j < n: if nums[j] % 2: odds += 1 while i <= j and odds...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR RETURN VAR VAR RETURN BIN_OP FUNC_CALL V...
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: cnt = collections.Counter() cnt[0], odd, res = 1, 0, 0 for i in nums: if i % 2 == 1: odd += 1 cnt[odd] += 1 res += cnt[odd - k] return res
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR VAR NUMBER NUMBER NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR BIN_OP VAR VAR RETURN VAR VAR
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: num_odd = 0 start = 0 output = 0 for i in range(len(nums)): if nums[i] % 2 == 1: num_odd += 1 while num_odd > k: if nums[start] % 2 == 1: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER V...
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: l, r, oddsCounter, res = 0, 0, 0, 0 while r < len(nums): if nums[r] % 2 == 1: oddsCounter += 1 while oddsCounter > k: if nums[l] % 2 == 1: oddsCou...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ...
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: data = [] curr = 0 L = 0 count = 0 for num in nums: if num % 2 == 0: curr += 1 else: L += 1 data.append(curr) ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF BI...
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: for i in range(len(nums)): if nums[i] % 2 == 0: nums[i] = 0 else: nums[i] = 1 pre = [0] for c in nums: pre.append(pre[-1] + c) res = 0 ...
CLASS_DEF FUNC_DEF VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR IF VAR...
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: oddIdx = [] for i in range(len(nums)): if nums[i] % 2 == 1: oddIdx.append(i) if len(oddIdx) < k: return 0 print(oddIdx) arr = [oddIdx[0] + 1] for i in...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VA...
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: prefix, odd_cnt, ans = {(0): 1}, 0, 0 for num in nums: if num % 2 == 1: odd_cnt += 1 prefix[odd_cnt] = prefix.get(odd_cnt, 0) + 1 if odd_cnt - k in prefix: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR VAR DICT NUMBER NUMBER NUMBER NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR RETURN VAR VAR
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: result = 0 start, count = 0, 0 for i in range(len(nums)): if nums[i] % 2 != 0: count += 1 while start < i and count > k: if nums[start] % 2 != 0: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER WHILE VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR BIN_OP VAR VAR NUMBE...
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: num_nice = 0 i = 0 count = 0 for num in nums: if num & 1: k -= 1 count = 0 while k == 0: k += nums[i] & 1 count += 1 ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR RETURN VAR VAR
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: cnt = 0 d = {} d[0] = 1 for i in nums: if i % 2: cnt += 1 if cnt in d: d[cnt] += 1 else: d[cnt] = 1 ans = 0 ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR RETURN VAR VAR
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
def isOdd(num): return num % 2 == 1 class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: items = [-1] for i, num in enumerate(nums): if isOdd(num): items.append(i) cnt = 0 items.append(len(nums)) for i in range(1, len...
FUNC_DEF RETURN BIN_OP VAR NUMBER NUMBER CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER BIN...
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: cache = collections.Counter({(0): 1}) res, cnt_odd = 0, 0 for i in range(len(nums)): if nums[i] % 2 == 1: cnt_odd += 1 res += cache.get(cnt_odd - k, 0) cache[cnt_...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR DICT NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER RETURN VAR VAR
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: for i in range(len(nums)): nums[i] = nums[i] % 2 mp = defaultdict(int) mp[0] = 1 csum, ans = 0, 0 for i, num in enumerate(nums): csum += num ans += mp[csum - k] ...
CLASS_DEF FUNC_DEF VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR VAR
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: nums = [(i % 2) for i in nums] ans = 0 tmp = 0 n = len(nums) l = 0 for r in range(n): if nums[r] == 1: k -= 1 tmp = 0 while k == 0: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR RETURN VAR VAR
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: n = len(nums) noOfNiceSubArrays = 0 even = 0 oddList = [] for i in range(n): if nums[i] % 2 == 0: even += 1 else: oddList.append(even) ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VA...
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: nums = [(num % 2) for num in nums] count = 0 indexlist = deque() for i in range(len(nums)): if nums[i] == 1: indexlist.append(i) for i in range(len(indexlist)): ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF BIN_OP...
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: d = {(0): 1} s = 0 count = 0 for i in range(len(nums)): nums[i] %= 2 s += nums[i] if not s in d: d[s] = 0 d[s] += 1 if s - k in d:...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR RETURN VAR VAR
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: return self.sol1(nums, k) - self.sol1(nums, k - 1) def sol1(self, nums, k): start = 0 odds = 0 res = 0 for end in range(len(nums)): odds += nums[end] & 1 while odds > k:...
CLASS_DEF FUNC_DEF VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER ...
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: nums = [(n % 2) for n in nums] def atMost(k): ans, j = 0, 0 for i, n in enumerate(nums): k -= n while k < 0: k += nums[j] j +...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR WHILE VAR NUMBER VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: if not nums: return 0 return self.atMostK(nums, k) - self.atMostK(nums, k - 1) def atMostK(self, nums, k): count = 0 left = 0 for right, right_num in enumerate(nums): k ...
CLASS_DEF FUNC_DEF VAR VAR VAR IF VAR RETURN NUMBER RETURN BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN V...
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: occur = collections.defaultdict(int) occur[0] = 1 runsum = 0 count = 0 for i in range(len(nums)): if nums[i] % 2 == 0: nums[i] = 0 else: nums[...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR ...
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: num_odd_numbers = 0 foo = 0 left = 0 right = 0 count = 0 num_nice_arrays = 0 while right < len(nums): r_n = nums[right] if r_n % 2 == 1: count...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR N...
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: index_list = [] index_list.append(-1) for i in range(0, len(nums)): if nums[i] % 2 == 1: index_list.append(i) index_list.append(len(nums)) if len(index_list) == 0: ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR N...
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: positions = [-1] for i in range(len(nums)): if nums[i] % 2 == 1: positions.append(i) positions.append(len(nums)) total = 0 for i in range(1, len(positions) - k): ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR...
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: odds = [0] * len(nums) n = len(nums) d = {} if nums[0] % 2 == 1: odds[0] = 1 else: odds[0] = 0 odds = [0] + odds d[0] = d.setdefault(0, []) + [0] coun...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT IF BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER LIST LIST NUMBER ASSIGN VAR NUM...
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, A, k): @lru_cache(None) def atMost(k): res = i = 0 for j in range(len(A)): k -= A[j] % 2 while k < 0: k += A[i] % 2 i += 1 res += j - i + 1 ...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR FUNC_CALL VAR NONE RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums, k): return self.atMost(nums, k) - self.atMost(nums, k - 1) def atMost(self, nums, k): if k < 0: return 0 n = len(nums) right = 0 cnt = 0 res = 0 for left in range(n): while right <...
CLASS_DEF FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR...
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: n = len(nums) left_left = 0 left_right = 0 odds_left = 0 odds_right = 0 odds = 0 ret = 0 for right in range(n): odds_left += nums[right] % 2 odds_righ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER WHILE VAR VAR B...
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: prefix_sum = [0] * len(nums) start = {} prefix_sum[0] = 0 if nums[0] % 2 == 0 else 1 if prefix_sum[0] == 0: start[0] = 0 else: start[1] = 0 for i in range(1, len(nums...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER NUMBER...
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: if not nums: return 0 ans = 0 cnt = 0 lo = 0 hi = 0 cnt += nums[0] % 2 while lo <= hi and hi < len(nums): if cnt < k: hi += 1 ...
CLASS_DEF FUNC_DEF VAR VAR VAR IF VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER WHILE VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR VAR IF VAR VAR BIN_OP VAR VAR NUMBER VAR NUM...
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: j = i = count = ret = 0 for n in nums: if n % 2: count += 1 if count == k: i = j while count == k: count -= 1 if nums[j] % 2 else ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR NUMBER VAR BIN_OP VAR VAR RETURN VAR VAR
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: count = 0 dic = defaultdict(int) dic[0] = 1 ans = 0 for i in range(1, len(nums) + 1): count += nums[i - 1] % 2 if count - k in list(dic.keys()): ans += dic[co...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR VAR
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: edge = [] res = 0 count = 0 for i in nums: if i % 2: edge.append(count + 1) count = 0 else: count += 1 edge.append(count + 1) ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER VAR RETURN NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR V...
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: def atMost(K): b, e = 0, 0 ret = 0 while e < len(nums): K -= nums[e] % 2 while K < 0: K += nums[b] % 2 b += 1 ...
CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER RETURN VAR RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
def solve(A, k): count = [0, 0] front = iter(A) ans = 0 size = 0 for v in A: count[v % 2] += 1 size += 1 while count[1] > k: count[next(front) % 2] -= 1 size -= 1 ans += size return ans class Solution: def numberOfSubarrays(self, num...
FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER WHILE VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER VAR VAR RETURN VAR CLASS_DEF FUNC_DEF VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR FUN...
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: output = 0 count_odd = 0 l = 0 for r, n in enumerate(nums): count_odd += int(n % 2 == 1) if count_odd == k: n_even = 1 for j in range(r + 1, len(nums)...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR FUNC_C...
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: odds = [-1] for i in range(len(nums)): if nums[i] & 1: odds.append(i) odds.append(len(nums)) i, count = 1, 0 while i + k - 1 < len(odds) - 1: count += (odds[i...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER WHILE BIN_OP BIN_OP VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMB...
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: blocks = [1] for num in nums: if num % 2 == 1: blocks.append(1) continue blocks[-1] += 1 return sum(left * right for left, right in zip(blocks, blocks[k:]))
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR
Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Example 1: Input: nums = [1,1,2,1,1], k = 3 Output: 2 Explanation: The only sub-arrays with 3 odd numbers are [1,1,2,1] and [1,2,1,1]. Example 2: Input: nums ...
class Solution: def numberOfSubarrays(self, nums: List[int], k: int) -> int: odd_indeces = [] for i, elem in enumerate(nums): if elem % 2 != 0: odd_indeces.append(i) if len(odd_indeces) < k: return 0 output = 0 print(odd_indeces) ...
CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER...