description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
The next lecture in a high school requires two topics to be discussed. The $i$-th topic is interesting by $a_i$ units for the teacher and by $b_i$ units for the students.
The pair of topics $i$ and $j$ ($i < j$) is called good if $a_i + a_j > b_i + b_j$ (i.e. it is more interesting for the teacher).
Your task is to f... | def main():
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
new = []
for i in range(n):
new.append(a[i] - b[i])
new.sort()
j = 0
r = -1
ans = 0
if new[-1] <= 0:
print(0)
else:
while j < n and new[j] <= 0:
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN 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 LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER... |
The next lecture in a high school requires two topics to be discussed. The $i$-th topic is interesting by $a_i$ units for the teacher and by $b_i$ units for the students.
The pair of topics $i$ and $j$ ($i < j$) is called good if $a_i + a_j > b_i + b_j$ (i.e. it is more interesting for the teacher).
Your task is to f... | def dosearch(a: list, x: int) -> int:
n = len(a)
i = 0
j = n // 2
while j >= 1:
while i + j < n and a[i + j] <= x:
i += j
j //= 2
return i
def f(n: int) -> int:
return n * (n - 1) // 2
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().... | FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR VAR FUNC_DEF VAR RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL V... |
The next lecture in a high school requires two topics to be discussed. The $i$-th topic is interesting by $a_i$ units for the teacher and by $b_i$ units for the students.
The pair of topics $i$ and $j$ ($i < j$) is called good if $a_i + a_j > b_i + b_j$ (i.e. it is more interesting for the teacher).
Your task is to f... | n = int(input())
A = input().split()
B = input().split()
T = []
S = []
Z = 0
for i in range(n):
temp = int(A[i]) - int(B[i])
if temp < 0:
S.append(-temp)
elif temp > 0:
T.append(temp)
else:
Z += 1
ans = int(len(T) * (len(T) - 1) / 2)
if Z:
ans += len(T) * Z
T.sort(reverse=Tru... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR... |
The next lecture in a high school requires two topics to be discussed. The $i$-th topic is interesting by $a_i$ units for the teacher and by $b_i$ units for the students.
The pair of topics $i$ and $j$ ($i < j$) is called good if $a_i + a_j > b_i + b_j$ (i.e. it is more interesting for the teacher).
Your task is to f... | def Merge(diff1, diff2):
diff1 = sorted(diff1, reverse=True)
diff2 = sorted(diff2, reverse=True)
end = len(diff2)
res = 0
for d1 in range(len(diff1)):
for d2 in range(end):
if diff1[d1] + diff2[d2] > 0:
res += 1
else:
end = d2
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR RETURN VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIG... |
The next lecture in a high school requires two topics to be discussed. The $i$-th topic is interesting by $a_i$ units for the teacher and by $b_i$ units for the students.
The pair of topics $i$ and $j$ ($i < j$) is called good if $a_i + a_j > b_i + b_j$ (i.e. it is more interesting for the teacher).
Your task is to f... | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = sorted([(a[i] - b[i]) for i in range(len(a))])
ans = 0
def wo(i):
global c
if c[i] + c[i + 1] > 0:
return i + 1
if c[i] + c[-1] <= 0:
return -1
x1 = i + 1
x2 = len(c) - 1
while x2 - x1 ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN 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 FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_DEF IF BIN_OP VAR VAR VAR BIN_OP VAR NUM... |
The next lecture in a high school requires two topics to be discussed. The $i$-th topic is interesting by $a_i$ units for the teacher and by $b_i$ units for the students.
The pair of topics $i$ and $j$ ($i < j$) is called good if $a_i + a_j > b_i + b_j$ (i.e. it is more interesting for the teacher).
Your task is to f... | import sys
input = sys.stdin.readline
t = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [(a[i] - b[i]) for i in range(t)]
c.sort()
total = 0
last = t - 1
for i in range(t):
if c[i] < 1:
for j in range(last, -1, -1):
if c[j] + c[i] < 1:
... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN 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 BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR... |
The next lecture in a high school requires two topics to be discussed. The $i$-th topic is interesting by $a_i$ units for the teacher and by $b_i$ units for the students.
The pair of topics $i$ and $j$ ($i < j$) is called good if $a_i + a_j > b_i + b_j$ (i.e. it is more interesting for the teacher).
Your task is to f... | n = int(input())
t = list(map(int, input().split()))
b = list(map(int, input().split()))
diff = [(t[i] - b[i]) for i in range(n)]
neg = []
pos = []
for i in diff:
if i <= 0:
neg.append(abs(i))
else:
pos.append(i)
pos.sort()
neg.sort()
i = 0
j = 0
ans = len(pos) * (len(pos) - 1) // 2
while j < le... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN 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 BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR ... |
The next lecture in a high school requires two topics to be discussed. The $i$-th topic is interesting by $a_i$ units for the teacher and by $b_i$ units for the students.
The pair of topics $i$ and $j$ ($i < j$) is called good if $a_i + a_j > b_i + b_j$ (i.e. it is more interesting for the teacher).
Your task is to f... | def search(i):
l = 0
r = i - 1
best = 0
while l <= r:
m = (l + r) // 2
if c[m] + c[i] >= 1:
best = m + 1
l = m + 1
else:
r = m - 1
return best
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [(... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL V... |
The next lecture in a high school requires two topics to be discussed. The $i$-th topic is interesting by $a_i$ units for the teacher and by $b_i$ units for the students.
The pair of topics $i$ and $j$ ($i < j$) is called good if $a_i + a_j > b_i + b_j$ (i.e. it is more interesting for the teacher).
Your task is to f... | n = int(input())
a = [int(x) for x in input().split()]
diff = sorted((a[i] - int(x) for i, x in enumerate(input().split())), reverse=True)
cnt = 0
limit = diff[-1]
ans = 0
for i, val in enumerate(diff, 1):
if val > 0 and val + limit > 0:
ans += n - i - cnt
elif val > 0:
for j in range(n - cnt):
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER BIN_... |
The next lecture in a high school requires two topics to be discussed. The $i$-th topic is interesting by $a_i$ units for the teacher and by $b_i$ units for the students.
The pair of topics $i$ and $j$ ($i < j$) is called good if $a_i + a_j > b_i + b_j$ (i.e. it is more interesting for the teacher).
Your task is to f... | def binarysearch(arr, val):
l, r = 0, len(arr) - 1
pos = abs(val)
while l < r:
mid = (l + r) // 2
if arr[mid] > pos:
r = mid
else:
l = mid
if r - l == 1:
break
n = len(arr)
if arr[l] > pos:
return len(arr) - l
elif arr[r... | FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR IF VAR VAR VAR RETURN BI... |
The next lecture in a high school requires two topics to be discussed. The $i$-th topic is interesting by $a_i$ units for the teacher and by $b_i$ units for the students.
The pair of topics $i$ and $j$ ($i < j$) is called good if $a_i + a_j > b_i + b_j$ (i.e. it is more interesting for the teacher).
Your task is to f... | n = int(input())
ch = input()
L = [int(j) for j in ch.split()]
ch = input()
L2 = [int(j) for j in ch.split()]
L3 = [0] * n
for i in range(n):
L3[i] = L[i] - L2[i]
L3.sort()
i = 0
j = n - 1
nb = 0
while True:
if i == j:
break
if L3[j] > -L3[i]:
nb += j - i
j -= 1
else:
i +... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER AS... |
The next lecture in a high school requires two topics to be discussed. The $i$-th topic is interesting by $a_i$ units for the teacher and by $b_i$ units for the students.
The pair of topics $i$ and $j$ ($i < j$) is called good if $a_i + a_j > b_i + b_j$ (i.e. it is more interesting for the teacher).
Your task is to f... | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l = [(x - y) for x, y in zip(a, b)]
l.sort()
z = l.count(0)
p = sum(1 for x in l if x > 0)
m = n - z - p
idx = n
cnt = p * (p - 1) // 2 + z * p
for i in range(m):
while l[idx - 1] + l[i] > 0:
idx -= 1
cnt += n - idx... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN 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 BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR ... |
The next lecture in a high school requires two topics to be discussed. The $i$-th topic is interesting by $a_i$ units for the teacher and by $b_i$ units for the students.
The pair of topics $i$ and $j$ ($i < j$) is called good if $a_i + a_j > b_i + b_j$ (i.e. it is more interesting for the teacher).
Your task is to f... | def arr():
return [int(i) for i in input().split()]
n = int(input())
a = arr()
b = arr()
c = [(i - j) for i, j in zip(a, b)]
c.sort()
ans = 0
i, j = 0, n - 1
while i <= j:
while i < n and c[i] + c[j] <= 0:
i += 1
if j >= i:
ans += j - i
j -= 1
print(ans) | FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR WHILE VAR VAR BIN_OP V... |
The next lecture in a high school requires two topics to be discussed. The $i$-th topic is interesting by $a_i$ units for the teacher and by $b_i$ units for the students.
The pair of topics $i$ and $j$ ($i < j$) is called good if $a_i + a_j > b_i + b_j$ (i.e. it is more interesting for the teacher).
Your task is to f... | from sys import stdin
try:
n = int(stdin.readline())
a = list(map(int, stdin.readline().rstrip().split()))
b = list(map(int, stdin.readline().rstrip().split()))
arr = [(a[i] - b[i]) for i in range(n)]
arr.sort()
count, start = 0, 0
end = n - 1
while start < end:
if arr[start] + ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR N... |
The next lecture in a high school requires two topics to be discussed. The $i$-th topic is interesting by $a_i$ units for the teacher and by $b_i$ units for the students.
The pair of topics $i$ and $j$ ($i < j$) is called good if $a_i + a_j > b_i + b_j$ (i.e. it is more interesting for the teacher).
Your task is to f... | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s = sorted(list(map(lambda x: x[0] - x[1], zip(a, b))))
count = 0
for i in range(n - 1):
L, R, x = i + 1, n - 1, n
while L <= R:
M = (L + R) // 2
if s[i] + s[M] > 0:
x = M
R = M - 1
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN 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 FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN... |
The next lecture in a high school requires two topics to be discussed. The $i$-th topic is interesting by $a_i$ units for the teacher and by $b_i$ units for the students.
The pair of topics $i$ and $j$ ($i < j$) is called good if $a_i + a_j > b_i + b_j$ (i.e. it is more interesting for the teacher).
Your task is to f... | t = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [(i - j) for i, j in zip(a, b)]
c = sorted(c)
left = t - 1
ans = 0
for i in range(t - 1):
while c[i] + c[left] > 0 and i < left:
left -= 1
left = max(left, i)
ans += t - left - 1
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN 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 BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CA... |
The next lecture in a high school requires two topics to be discussed. The $i$-th topic is interesting by $a_i$ units for the teacher and by $b_i$ units for the students.
The pair of topics $i$ and $j$ ($i < j$) is called good if $a_i + a_j > b_i + b_j$ (i.e. it is more interesting for the teacher).
Your task is to f... | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0] * n
for i in range(n):
c[i] = a[i] - b[i]
c.sort()
lis = [0] * n
count = 0
for i in range(1, n):
r = lis[i - 1]
for j in range(lis[i - 1], -1, -1):
if c[j] + c[i] <= 0:
break
else:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN 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 BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER ... |
The next lecture in a high school requires two topics to be discussed. The $i$-th topic is interesting by $a_i$ units for the teacher and by $b_i$ units for the students.
The pair of topics $i$ and $j$ ($i < j$) is called good if $a_i + a_j > b_i + b_j$ (i.e. it is more interesting for the teacher).
Your task is to f... | def find(ar, x, n):
l = 0
h = n - 1
if ar[0] >= x + 1:
return 0
else:
while l <= h:
mid = (l + h) // 2
if ar[mid] >= x + 1 and ar[mid - 1] < x + 1:
return mid
elif ar[mid] < x + 1:
l = mid + 1
elif ar[mid - 1... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER RETURN NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER B... |
The next lecture in a high school requires two topics to be discussed. The $i$-th topic is interesting by $a_i$ units for the teacher and by $b_i$ units for the students.
The pair of topics $i$ and $j$ ($i < j$) is called good if $a_i + a_j > b_i + b_j$ (i.e. it is more interesting for the teacher).
Your task is to f... | import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
diffs = []
for i in range(n):
diffs.append(a[i] - b[i])
diffs.sort()
mp = {}
res = 0
for i in range(n):
lo = i + 1
hi = n - 1
best = n
while lo <= hi:
mid = lo + hi... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN 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 LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN... |
The next lecture in a high school requires two topics to be discussed. The $i$-th topic is interesting by $a_i$ units for the teacher and by $b_i$ units for the students.
The pair of topics $i$ and $j$ ($i < j$) is called good if $a_i + a_j > b_i + b_j$ (i.e. it is more interesting for the teacher).
Your task is to f... | n = int(input())
ab = []
for el1, el2 in zip(map(int, input().split()), map(int, input().split())):
ab.append(el1 - el2)
ans = 0
ab.sort()
l, r = 0, n - 1
while l < r:
if ab[l] > -ab[r]:
ans += r - l
r -= 1
else:
l += 1
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR BIN_OP ... |
The next lecture in a high school requires two topics to be discussed. The $i$-th topic is interesting by $a_i$ units for the teacher and by $b_i$ units for the students.
The pair of topics $i$ and $j$ ($i < j$) is called good if $a_i + a_j > b_i + b_j$ (i.e. it is more interesting for the teacher).
Your task is to f... | import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
n = int(input())
teach = list(map(int, input().split()))
stud = list(map(int, input().split()))
res = list(map(lambda x, y: x - y, teach, stud))
res.sort()
start, end = 0, n - 1
ans = 0
while start < end:
if res[start] + res[end] > 0:
... | IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN 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 FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR ... |
Polycarp started working at a bank. He was assigned to monitor the ATM. The ATM initially contains $s$ rubles.
A queue of $n$ students lined up to him. Each student wants to either withdraw a certain amount of money or deposit it into an account. If $a_i$ is positive, then the student credits that amount of money via ... | def solve(studentActivity, n, s):
maxContiguousLength = 0
firstIndex = -1
rangeList = [-1]
curActivitySum = s
for lastIndex, activity in enumerate(studentActivity):
curActivitySum += activity
while curActivitySum < 0 and firstIndex < lastIndex:
firstIndex += 1
... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR VAR WHILE VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FU... |
Polycarp started working at a bank. He was assigned to monitor the ATM. The ATM initially contains $s$ rubles.
A queue of $n$ students lined up to him. Each student wants to either withdraw a certain amount of money or deposit it into an account. If $a_i$ is positive, then the student credits that amount of money via ... | import sys
input = sys.stdin.readline
nn = int(input())
for _ in range(nn):
n, s = map(int, input().split())
nums = list(map(int, input().split()))
l, r, total, length = 0, 0, 0, [0, 0, 0]
for r in range(n):
total += nums[r]
while l <= r and total < -s:
total -= nums[l]
... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR 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 NUMBER NUMBER LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR W... |
Polycarp started working at a bank. He was assigned to monitor the ATM. The ATM initially contains $s$ rubles.
A queue of $n$ students lined up to him. Each student wants to either withdraw a certain amount of money or deposit it into an account. If $a_i$ is positive, then the student credits that amount of money via ... | import sys
sys.stdin.readline
tc = int(input())
for _ in range(tc):
n, k = map(int, input().split())
ar = list(map(int, input().split()))
ans = 0
l = 0
r = 0
sum = k
maxd = 0
resL = -1
resr = -1
while r <= len(ar) - 1:
sum += ar[r]
if sum < 0:
r += 1
... | IMPORT EXPR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR... |
Polycarp started working at a bank. He was assigned to monitor the ATM. The ATM initially contains $s$ rubles.
A queue of $n$ students lined up to him. Each student wants to either withdraw a certain amount of money or deposit it into an account. If $a_i$ is positive, then the student credits that amount of money via ... | tc = int(input())
for case in range(tc):
n, suma = (int(i) for i in input().split())
queries = [int(j) for j in input().split()]
indice = -1
final = -1
maximo = 0
for pos in range(n):
valor = queries[pos]
if suma + valor >= 0:
if indice == -1:
indice =... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR 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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR NUMBER... |
Polycarp started working at a bank. He was assigned to monitor the ATM. The ATM initially contains $s$ rubles.
A queue of $n$ students lined up to him. Each student wants to either withdraw a certain amount of money or deposit it into an account. If $a_i$ is positive, then the student credits that amount of money via ... | n = int(input().split()[0])
for i in range(n):
l, s = list(map(int, input().split()))
arr = list(map(int, input().split()))
ans = ""
_maxlen = -1
i = 0
j = i
curr = s
while i < len(arr) and j < len(arr):
if arr[j] >= 0:
curr += arr[j]
j += 1
elif a... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL 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 STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR FUNC_C... |
Polycarp started working at a bank. He was assigned to monitor the ATM. The ATM initially contains $s$ rubles.
A queue of $n$ students lined up to him. Each student wants to either withdraw a certain amount of money or deposit it into an account. If $a_i$ is positive, then the student credits that amount of money via ... | cases = int(input())
for _ in range(cases):
n, s = map(int, input().split())
lst = list(map(int, input().split()))
left = 0
end = -1
available = s
students = 0
for right, n in enumerate(lst):
available += n
while available < 0:
available -= lst[left]
l... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR 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 ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR WHILE VAR NUMBER VAR VAR... |
Polycarp started working at a bank. He was assigned to monitor the ATM. The ATM initially contains $s$ rubles.
A queue of $n$ students lined up to him. Each student wants to either withdraw a certain amount of money or deposit it into an account. If $a_i$ is positive, then the student credits that amount of money via ... | t = int(input())
for _ in range(t):
n, s = map(int, input().split())
a = list(map(int, input().split()))
left, right = 0, 0
for i in range(1, n):
a[i] += a[i - 1]
a = [0] + a
i, j = 0, 0
while j <= n:
if a[j] - a[i] + s >= 0:
if j - i > right - left:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR 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 FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIG... |
Polycarp started working at a bank. He was assigned to monitor the ATM. The ATM initially contains $s$ rubles.
A queue of $n$ students lined up to him. Each student wants to either withdraw a certain amount of money or deposit it into an account. If $a_i$ is positive, then the student credits that amount of money via ... | T = int(input())
for _ in range(T):
n, s = map(int, input().split())
a = list(map(int, input().split()))
l, r, m = 0, 0, 0
add = 0
interm = 0
while r < n:
if s + add >= 0 and s + add + a[r] >= 0:
add += a[r]
if m < r - l + 1:
ans = [l, r]
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR 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 NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VA... |
Polycarp started working at a bank. He was assigned to monitor the ATM. The ATM initially contains $s$ rubles.
A queue of $n$ students lined up to him. Each student wants to either withdraw a certain amount of money or deposit it into an account. If $a_i$ is positive, then the student credits that amount of money via ... | for _ in range(int(input())):
n, s = map(int, input().split())
arr = [-1] + list(map(int, input().split()))
maxSoFar = x = y = 0
left = 1
curr = s
for right in range(1, n + 1):
curr += arr[right]
while curr < 0:
curr -= arr[left]
left += 1
if right... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR WHILE VAR... |
Polycarp started working at a bank. He was assigned to monitor the ATM. The ATM initially contains $s$ rubles.
A queue of $n$ students lined up to him. Each student wants to either withdraw a certain amount of money or deposit it into an account. If $a_i$ is positive, then the student credits that amount of money via ... | def main():
t = int(input())
for i in range(t):
n, s = list(map(int, input().split()))
a = list(map(int, input().split()))
l1, l2, r_l1, r_l2 = 0, 0, 0, 0
summa = 0
while l1 < n:
if l2 < l1:
l2 = l1
summa = 0
while l... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL 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 VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR ASSIGN VAR VAR... |
Polycarp started working at a bank. He was assigned to monitor the ATM. The ATM initially contains $s$ rubles.
A queue of $n$ students lined up to him. Each student wants to either withdraw a certain amount of money or deposit it into an account. If $a_i$ is positive, then the student credits that amount of money via ... | t = int(input())
answers = []
for _ in range(t):
n, s = map(int, input().split())
a = [int(x) for x in input().split()]
l, r, lmax, rmax, cur_max = 0, 0, 0, -1, 0
for i in range(n):
s += a[i]
cur_max += 1
while s < 0:
s -= a[l]
l += 1
cur_max -... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR 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 VAR VAR NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER WHILE VAR NUMB... |
Polycarp started working at a bank. He was assigned to monitor the ATM. The ATM initially contains $s$ rubles.
A queue of $n$ students lined up to him. Each student wants to either withdraw a certain amount of money or deposit it into an account. If $a_i$ is positive, then the student credits that amount of money via ... | t = int(input())
for i in range(t):
n, s = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
if n == 1:
if s + a[0] >= 0:
print(1, 1)
else:
print(-1)
else:
curfp = 0
curlp = 0
curlength = 0
maxfp = 0
maxlp ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR N... |
Polycarp started working at a bank. He was assigned to monitor the ATM. The ATM initially contains $s$ rubles.
A queue of $n$ students lined up to him. Each student wants to either withdraw a certain amount of money or deposit it into an account. If $a_i$ is positive, then the student credits that amount of money via ... | def f():
n, t = map(int, input().split())
l = list(map(int, input().split()))
d = 0
x, y = 0, 0
p, q = -1, -1
for i in range(n):
if t + l[i] >= 0:
y += 1
t += l[i]
else:
if d < y - x:
d = y - x
p, q = x, y
... | 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 NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR ... |
Polycarp started working at a bank. He was assigned to monitor the ATM. The ATM initially contains $s$ rubles.
A queue of $n$ students lined up to him. Each student wants to either withdraw a certain amount of money or deposit it into an account. If $a_i$ is positive, then the student credits that amount of money via ... | import sys
printer = []
for _ in range(int(sys.stdin.readline())):
n, s = map(int, sys.stdin.readline().split())
a = list(map(int, sys.stdin.readline().split()))
i, j = 0, 0
atm = s
ans = -1
L, R = 0, 0
while j < n:
if a[j] + atm >= 0:
atm += a[j]
j += 1
... | IMPORT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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 ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR IF BIN_OP VAR VAR ... |
Polycarp started working at a bank. He was assigned to monitor the ATM. The ATM initially contains $s$ rubles.
A queue of $n$ students lined up to him. Each student wants to either withdraw a certain amount of money or deposit it into an account. If $a_i$ is positive, then the student credits that amount of money via ... | test = int(input())
for _ in range(test):
n, s = map(int, input().split())
arr = [int(x) for x in input().split()]
left, right = 0, 0
ans = [0, -1, -1]
while right < n:
if arr[right] >= 0:
s += arr[right]
right += 1
elif s + arr[right] >= 0:
s += a... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR 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 NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR VA... |
Polycarp started working at a bank. He was assigned to monitor the ATM. The ATM initially contains $s$ rubles.
A queue of $n$ students lined up to him. Each student wants to either withdraw a certain amount of money or deposit it into an account. If $a_i$ is positive, then the student credits that amount of money via ... | for _ in range(int(input())):
n, s = map(int, input().split())
arr = list(map(int, input().split()))
l = 0
ans = -1
temp = 0
res = []
for r, el in enumerate(arr):
temp += el
while l <= r and temp + s < 0:
temp -= arr[l]
l += 1
if l > r:
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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 LIST FOR VAR VAR FUNC_CALL VAR VAR VAR VAR WHILE VAR VAR BIN_OP VAR VAR NUMBER VA... |
Polycarp started working at a bank. He was assigned to monitor the ATM. The ATM initially contains $s$ rubles.
A queue of $n$ students lined up to him. Each student wants to either withdraw a certain amount of money or deposit it into an account. If $a_i$ is positive, then the student credits that amount of money via ... | f = lambda: [*map(int, input().split())]
for _ in [0] * f()[0]:
n, s = f()
a, x = f(), [-1]
l, b, e, t, w = [0] * 5
while 1:
if w >= -s:
if e - b > l:
l = e - b
x = [b + 1, e]
if e >= n:
print(*x)
break
... | ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR BIN_OP LIST NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR LIST NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP LIST NUMBER NUMBER WHILE NUMBER IF VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST BIN... |
Polycarp started working at a bank. He was assigned to monitor the ATM. The ATM initially contains $s$ rubles.
A queue of $n$ students lined up to him. Each student wants to either withdraw a certain amount of money or deposit it into an account. If $a_i$ is positive, then the student credits that amount of money via ... | for _ in range(int(input())):
n, k = map(int, input().split())
arr = list(map(int, input().split()))
s = [(-1 * i) for i in arr]
subarray_start = 0
subarray_end = 0
st = -1
e = -1
subarray_sum = 0
max_len = -1
for i in s:
subarray_sum += i
subarray_end += 1
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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 BIN_OP NUMBER VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER F... |
Polycarp started working at a bank. He was assigned to monitor the ATM. The ATM initially contains $s$ rubles.
A queue of $n$ students lined up to him. Each student wants to either withdraw a certain amount of money or deposit it into an account. If $a_i$ is positive, then the student credits that amount of money via ... | t = int(input())
for _ in range(t):
n, s = map(int, input().split())
a = list(map(int, input().split()))
ans = [-1]
mxlen, i, j, cs, w = [0] * 5
while 1:
if cs >= -s:
if j - i > mxlen:
mxlen = j - i
ans = [i + 1, j]
if j >= n:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR 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 VAR VAR VAR VAR BIN_OP LIST NUMBER NUMBER WHILE NUMBER IF VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VA... |
Polycarp started working at a bank. He was assigned to monitor the ATM. The ATM initially contains $s$ rubles.
A queue of $n$ students lined up to him. Each student wants to either withdraw a certain amount of money or deposit it into an account. If $a_i$ is positive, then the student credits that amount of money via ... | from sys import stdin
def sng_int():
return int(stdin.readline())
def sng_str():
return stdin.readline()
def int_list():
return list(map(int, stdin.readline().split()))
t = sng_int()
for _ in range(t):
n, s = map(int, sng_str().split())
arr = int_list()
i = 0
j = 0
l, r = 0, -1
... | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIG... |
There are several days left before the fiftieth birthday of a famous Berland's writer Berlbury. In this connection the local library decided to make an exposition of the works of this famous science-fiction writer. It was decided as well that it is necessary to include into the exposition only those books that were pub... | a, b = (int(i) for i in input().split())
c = list(map(int, input().split()))
d = 0
e = 0
g1, g2 = 0, 0
h1, h2 = 0, 0
length = []
f = c[0]
n = 0
for i in range(len(c)):
if f - c[i] >= e:
e = f - c[i]
h2 = h1
h1 = i
if c[i] - f >= d:
d = c[i] - f
g2 = g1
g1 = i
... | ASSIGN VAR VAR FUNC_CALL VAR 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 NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF... |
There are several days left before the fiftieth birthday of a famous Berland's writer Berlbury. In this connection the local library decided to make an exposition of the works of this famous science-fiction writer. It was decided as well that it is necessary to include into the exposition only those books that were pub... | f = lambda: map(int, input().split())
n, k = f()
l, h = [], list(f())
u, v = [0] * n, [0] * n
a = b = c = d = 0
q = i = 0
for j in range(n):
while a <= b and h[u[b]] <= h[j]:
b -= 1
while c <= d and h[v[d]] >= h[j]:
d -= 1
b += 1
d += 1
u[b] = v[d] = j
while h[u[a]] - h[v[c]] > k... | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR LIST FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR VAR NUMBER WHILE ... |
There are several days left before the fiftieth birthday of a famous Berland's writer Berlbury. In this connection the local library decided to make an exposition of the works of this famous science-fiction writer. It was decided as well that it is necessary to include into the exposition only those books that were pub... | n, k = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
a = 0
b = 0
l = []
m = []
ans = []
def f():
while l[0][0] < b:
l.pop(0)
while m[0][0] < b:
m.pop(0)
return l[0][1] - m[0][1] > k
for i in range(n):
while len(l) > 0 and l[-1][1] <= h[i]:
l.pop()
... | 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 NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF WHILE VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR NUMBER WHILE VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR NUMBER R... |
There are several days left before the fiftieth birthday of a famous Berland's writer Berlbury. In this connection the local library decided to make an exposition of the works of this famous science-fiction writer. It was decided as well that it is necessary to include into the exposition only those books that were pub... | numtrans = input()
num = numtrans.split()
n = int(num[0])
k = int(num[1])
htrans = input()
h = htrans.split()
record = []
time = 0
front = 0
end = 0
index1 = []
index2 = []
index3 = []
index4 = []
max = []
min = []
ht = len(h)
size = 0
recordmax = 0
max.append(0)
min.append(1000000)
for end in range(ht):
while max[... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIS... |
There are several days left before the fiftieth birthday of a famous Berland's writer Berlbury. In this connection the local library decided to make an exposition of the works of this famous science-fiction writer. It was decided as well that it is necessary to include into the exposition only those books that were pub... | n, m = map(int, input().split())
a = map(int, input().split())
minq = []
maxq = []
j = 0
k = 0
ans = 0
res = []
for i, x in enumerate(a):
while minq and minq[-1][1] > x:
minq.pop(-1)
minq.append((i, x))
j = min(j, len(minq) - 1)
while maxq and maxq[-1][1] < x:
maxq.pop(-1)
maxq.appen... | 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 ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR V... |
There are several days left before the fiftieth birthday of a famous Berland's writer Berlbury. In this connection the local library decided to make an exposition of the works of this famous science-fiction writer. It was decided as well that it is necessary to include into the exposition only those books that were pub... | n, k = (int(x) for x in input().split())
h = [int(x) for x in input().split()]
h1 = [None] * n
s = []
for i in reversed(range(n)):
while s and h[s[-1]] > h[i]:
s.pop()
h1[i] = s[-1] if s else None
s.append(i)
h2 = [None] * n
s = []
for i in reversed(range(n)):
while s and h[s[-1]] < h[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 BIN_OP LIST NONE VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NONE EXPR FUNC_CALL VAR VAR ASSI... |
There are several days left before the fiftieth birthday of a famous Berland's writer Berlbury. In this connection the local library decided to make an exposition of the works of this famous science-fiction writer. It was decided as well that it is necessary to include into the exposition only those books that were pub... | N, diff = [int(_) for _ in input().split()]
books = [int(_) for _ in input().split()]
dec = []
inc = []
ml = 0
res = []
j = 0
for i, h in enumerate(books):
while dec and books[dec[-1]] <= h:
dec.pop()
dec.append(i)
while inc and books[inc[-1]] >= h:
inc.pop()
inc.append(i)
while book... | 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 LIST ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR WHILE VAR VAR VAR... |
There are several days left before the fiftieth birthday of a famous Berland's writer Berlbury. In this connection the local library decided to make an exposition of the works of this famous science-fiction writer. It was decided as well that it is necessary to include into the exposition only those books that were pub... | n, k = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
i, a, j = 0, 0, 0
ma, mi = [], []
choice = [[1, 1]]
while i < n:
while len(ma) and h[i] > ma[-1][1]:
del ma[-1]
ma.append((i, h[i]))
while len(mi) and h[i] < mi[-1][1]:
del mi[-1]
mi.append((i, h[i]))
whil... | 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 NUMBER NUMBER NUMBER ASSIGN VAR VAR LIST LIST ASSIGN VAR LIST LIST NUMBER NUMBER WHILE VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ... |
Let's call two strings s and t anagrams of each other if it is possible to rearrange symbols in the string s to get a string, equal to t.
Let's consider two strings s and t which are anagrams of each other. We say that t is a reducible anagram of s if there exists an integer k β₯ 2 and 2k non-empty strings s_1, t_1, s_... | s = input()
mp = [[(0) for i in range(26)] for _ in range(len(s))]
for i in range(len(s)):
mp[i][ord(s[i]) - ord("a")] += 1
if i > 0:
for j in range(26):
mp[i][j] += mp[i - 1][j]
for _ in range(int(input())):
l, r = map(int, input().split())
sc = 0
for i in range(26):
t =... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CAL... |
Let's call two strings s and t anagrams of each other if it is possible to rearrange symbols in the string s to get a string, equal to t.
Let's consider two strings s and t which are anagrams of each other. We say that t is a reducible anagram of s if there exists an integer k β₯ 2 and 2k non-empty strings s_1, t_1, s_... | s = input()
m = []
for i in range(len(s) + 1):
m.append([])
for j in range(26):
m[-1].append(0)
for i in range(len(s)):
for j in range(26):
if j == ord(s[i]) - 97:
m[i + 1][j] = m[i][j] + 1
else:
m[i + 1][j] = m[i][j]
q = int(input())
for _ in range(q):
l,... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBE... |
Let's call two strings s and t anagrams of each other if it is possible to rearrange symbols in the string s to get a string, equal to t.
Let's consider two strings s and t which are anagrams of each other. We say that t is a reducible anagram of s if there exists an integer k β₯ 2 and 2k non-empty strings s_1, t_1, s_... | import sys
s = list(sys.stdin.readline())[:-1]
t = int(sys.stdin.readline())
dic = [[(0) for _ in range(26)]]
n = len(s)
for i in range(n):
temp = [i for i in dic[-1]]
temp[ord(s[i]) - 97] += 1
dic.append(temp)
for _ in range(t):
l, r = map(int, sys.stdin.readline().split())
if l == r:
prin... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR... |
Let's call two strings s and t anagrams of each other if it is possible to rearrange symbols in the string s to get a string, equal to t.
Let's consider two strings s and t which are anagrams of each other. We say that t is a reducible anagram of s if there exists an integer k β₯ 2 and 2k non-empty strings s_1, t_1, s_... | from sys import stdin
def main():
ss = input()
counts = [[0] * 26]
for s in ss:
counts.append(counts[-1].copy())
counts[-1][ord(s) - ord("a")] += 1
q = int(input())
for _ in range(q):
l, r = map(int, input().split())
cdifc = 0
for i in range(26):
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST BIN_OP LIST NUMBER NUMBER FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN... |
Let's call two strings s and t anagrams of each other if it is possible to rearrange symbols in the string s to get a string, equal to t.
Let's consider two strings s and t which are anagrams of each other. We say that t is a reducible anagram of s if there exists an integer k β₯ 2 and 2k non-empty strings s_1, t_1, s_... | s = input()
n = len(s)
prefix_letter_occurence = [[(0) for i in range(n + 1)] for i in range(26)]
for i in range(1, n + 1):
cur_letter = s[i - 1]
for l in range(26):
prefix_letter_occurence[l][i] = prefix_letter_occurence[l][i - 1] + int(
l == ord(cur_letter) - 97
)
def has_inreduc... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP F... |
Let's call two strings s and t anagrams of each other if it is possible to rearrange symbols in the string s to get a string, equal to t.
Let's consider two strings s and t which are anagrams of each other. We say that t is a reducible anagram of s if there exists an integer k β₯ 2 and 2k non-empty strings s_1, t_1, s_... | import sys
input = sys.stdin.readline
S = list(input().rstrip())
Q = int(input())
Query = []
for _ in range(Q):
l, r = map(int, input().split())
Query.append((l - 1, r - 1))
Alp = [chr(i) for i in range(97, 97 + 26)]
dic = {}
for alp in Alp:
dic[alp] = [0]
for i, s in enumerate(S):
for alp in Alp:
... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BI... |
Let's call two strings s and t anagrams of each other if it is possible to rearrange symbols in the string s to get a string, equal to t.
Let's consider two strings s and t which are anagrams of each other. We say that t is a reducible anagram of s if there exists an integer k β₯ 2 and 2k non-empty strings s_1, t_1, s_... | s = input()
n = len(s)
dp = [([0] * 26) for _ in range(n + 1)]
for i in range(1, n + 1):
dp[i] = dp[i - 1].copy()
dp[i][ord(s[i - 1]) - ord("a")] += 1
for _ in range(int(input())):
l, r = map(int, input().split())
l -= 1
k = [(dp[r][i] - dp[l][i]) for i in range(26)]
c = sum(p != 0 for p in k)
... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR STRING NUMBER FOR VAR FUNC_CALL VA... |
Let's call two strings s and t anagrams of each other if it is possible to rearrange symbols in the string s to get a string, equal to t.
Let's consider two strings s and t which are anagrams of each other. We say that t is a reducible anagram of s if there exists an integer k β₯ 2 and 2k non-empty strings s_1, t_1, s_... | s = input()
q = int(input())
N = len(s)
prefix_sum = []
for i in range(N + 1):
prefix_sum.append([0] * 26)
for i, ch in enumerate(s, start=1):
tmp = ord(ch) - ord("a")
for j in range(26):
if tmp == j:
prefix_sum[i][j] = prefix_sum[i - 1][j] + 1
else:
prefix_sum[i][j] ... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER IF ... |
Let's call two strings s and t anagrams of each other if it is possible to rearrange symbols in the string s to get a string, equal to t.
Let's consider two strings s and t which are anagrams of each other. We say that t is a reducible anagram of s if there exists an integer k β₯ 2 and 2k non-empty strings s_1, t_1, s_... | base = 97
def get(l, r):
cnt = 0
if l == 0:
for i in range(26):
if S[i][r] > 0:
cnt += 1
else:
for i in range(26):
if S[i][r] - S[i][l - 1] > 0:
cnt += 1
return cnt
s = input()
q = int(input())
ans = []
S = [([0] * len(s)) for _... | ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BI... |
Let's call two strings s and t anagrams of each other if it is possible to rearrange symbols in the string s to get a string, equal to t.
Let's consider two strings s and t which are anagrams of each other. We say that t is a reducible anagram of s if there exists an integer k β₯ 2 and 2k non-empty strings s_1, t_1, s_... | def Input():
tem = input().split()
ans = []
for it in tem:
ans.append(int(it))
return ans
s = input()
n = len(s)
suf = [([0] * 26) for i in range(n + 1)]
for i in range(n):
for j in range(26):
suf[i + 1][j] = suf[i][j]
suf[i + 1][ord(s[i]) - ord("a")] += 1
m = Input()[0]
for i ... | FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP ... |
Let's call two strings s and t anagrams of each other if it is possible to rearrange symbols in the string s to get a string, equal to t.
Let's consider two strings s and t which are anagrams of each other. We say that t is a reducible anagram of s if there exists an integer k β₯ 2 and 2k non-empty strings s_1, t_1, s_... | s = str(input())
q = int(input())
n = len(s)
sum_ = [([0] * 26) for _ in range(n + 1)]
for i in range(1, n + 1):
for j in range(26):
sum_[i][j] = sum_[i - 1][j]
sum_[i][ord(s[i - 1]) - ord("a")] += 1
for _ in range(q):
l, r = map(int, input().split())
l, r = l - 1, r - 1
if l == r:
p... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP FUNC... |
Let's call two strings s and t anagrams of each other if it is possible to rearrange symbols in the string s to get a string, equal to t.
Let's consider two strings s and t which are anagrams of each other. We say that t is a reducible anagram of s if there exists an integer k β₯ 2 and 2k non-empty strings s_1, t_1, s_... | def first():
s = input()
cases = int(input())
lastChange = [0] * len(s)
lastChange[0] = 0
lc = s[0]
for i in range(1, len(s)):
c = s[i]
if c != lc:
lastChange[i] = i
lc = c
else:
lastChange[i] = lastChange[i - 1]
for i in range(case... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR ... |
Let's call two strings s and t anagrams of each other if it is possible to rearrange symbols in the string s to get a string, equal to t.
Let's consider two strings s and t which are anagrams of each other. We say that t is a reducible anagram of s if there exists an integer k β₯ 2 and 2k non-empty strings s_1, t_1, s_... | import sys
from itertools import accumulate
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [([c] * b) for i in range(a)]
def list3d(a, b, c, d):
return [[([d] * c) for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[([e] * d) for j in range(c)... | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER RETURN FUNC_CALL ... |
Let's call two strings s and t anagrams of each other if it is possible to rearrange symbols in the string s to get a string, equal to t.
Let's consider two strings s and t which are anagrams of each other. We say that t is a reducible anagram of s if there exists an integer k β₯ 2 and 2k non-empty strings s_1, t_1, s_... | ALPHA = 26
def unique(cnt, l, r):
sum = 0
for a, b in zip(cnt[l - 1], cnt[r]):
sum += a < b
return sum
s = list(map(lambda c: ord(c) - ord("a"), list(input())))
cnt = [[] for i in range(len(s) + 1)]
cnt[0] = [(0) for j in range(ALPHA)]
for i in range(len(s)):
cnt[i + 1] = cnt[i].copy()
c... | ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER... |
Let's call two strings s and t anagrams of each other if it is possible to rearrange symbols in the string s to get a string, equal to t.
Let's consider two strings s and t which are anagrams of each other. We say that t is a reducible anagram of s if there exists an integer k β₯ 2 and 2k non-empty strings s_1, t_1, s_... | import sys
input = sys.stdin.readline
s = input().rstrip("\n")
l = len(s)
ref = [[0] * 26]
ref1 = [0] * 26
for i in range(l):
ref1[ord(s[i]) - 97] += 1
ref.append(ref1.copy())
q = int(input())
for i in range(q):
l, r = map(int, input().split())
if l == r or s[l - 1] != s[r - 1]:
print("Yes")
... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR... |
Let's call two strings s and t anagrams of each other if it is possible to rearrange symbols in the string s to get a string, equal to t.
Let's consider two strings s and t which are anagrams of each other. We say that t is a reducible anagram of s if there exists an integer k β₯ 2 and 2k non-empty strings s_1, t_1, s_... | s = input()
n = len(s)
memo = [None] * (n + 1)
count = [0] * 26
memo[0] = count.copy()
for i, char in enumerate(s):
count[ord(char) - 97] += 1
memo[i + 1] = count.copy()
def f():
l, r = [int(char) for char in input().split()]
if l == r:
return "Yes"
if s[r - 1] != s[l - 1]:
return ... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL V... |
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods... | n = int(input())
fm = 0
a = list(map(int, input().split()))
s = set()
ans = list()
for i in range(0, n):
if a[i] in s:
s.clear()
ans.append(fm + 1)
ans.append(i + 1)
fm = i + 1
continue
s.add(a[i])
if len(ans) == 0:
print(-1)
else:
ans[-1] = n
print(len(ans) /... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIG... |
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods... | import sys
inputNum = input()
inputTypes = input().split(" ")
map1 = set()
stack2 = []
stack3 = []
for i in range(len(inputTypes)):
if len(map1) == 0:
map1.add(inputTypes[i])
stack2.append(str(i + 1))
elif inputTypes[i] in map1:
stack2.append(str(i + 1))
stack3.append(" ".join(s... | IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL... |
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods... | n, k = list(map(int, input().split()))
lis = list(map(int, input().split()))
ins = [(0) for i in range(10**6)]
ins[lis[0]] += 1
zeroes = 10**6 - 1
mL = 0
pair = [0, 0]
r = 0
for l in range(n):
if l > 0:
ins[lis[l - 1]] -= 1
if ins[lis[l - 1]] == 0:
zeroes += 1
while 10**6 - zeroes <=... | 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 VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VA... |
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods... | n = int(input())
a = list(map(int, input().split()))
ans = []
l, s = 0, set()
for i in range(n):
if a[i] in s:
ans.append([l + 1, i + 1])
l = i + 1
s = set()
else:
s.add(a[i])
if not ans:
print(-1)
else:
ans[-1][1] = n
print(len(ans))
for ansi in ans:
prin... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FU... |
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods... | import sys
n = int(input())
a = list(map(int, input().split()))
b = set()
beg = 1
am = 0
aml = []
for i in range(n):
if a[i] in b:
aml.append([beg, i + 1])
am += 1
b = set()
beg = i + 2
else:
b.add(a[i])
if am == 0:
print(-1)
sys.exit(0)
if aml[am - 1][1] != n:
... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN ... |
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods... | import sys
n, k = map(int, input().split())
hash = [0] * 1000001
now = 0
a = list(map(int, input().split()))
ans = 0
l = 0
for r in range(n):
hash[a[r]] += 1
if hash[a[r]] == 1:
now += 1
while now > k:
hash[a[l]] -= 1
if hash[a[l]] == 0:
now -= 1
l += 1
if r ... | IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER 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 NUMBER IF VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VA... |
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods... | n = int(input())
a = list(map(int, input().strip().split()))
i = 0
d = dict()
res = []
s = 1
while i < n:
if a[i] in d.keys():
res.append([s, i + 1])
d = dict()
s = i + 2
else:
d[a[i]] = 1
i += 1
try:
res[-1][1] = n
except:
pass
if len(res) > 0:
print(len(res))
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP... |
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods... | import sys
n = int(sys.stdin.readline())
arr = [int(x) for x in input().split()]
sets = set()
result = []
ans = 0
l = 0
r = 0
for i in arr:
if i in sets:
ans = ans + 1
sets.clear()
result.append([l + 1, r + 1])
l = r + 1
else:
sets.add(i)
r = r + 1
if ans == 0:
p... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VA... |
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods... | n = int(input())
d = {}
b = []
e = 1
a = list(map(int, input().split()))
for i in range(n):
if a[i] in d:
b.append([e, i + 1])
e = i + 2
d.clear()
else:
d[a[i]] = i + 1
if len(b) == 0:
print(-1)
exit()
print(len(b))
k = b[-1]
b[-1] = [k[0], n]
for i in b:
print(*i) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP VAR... |
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods... | size = int(input())
myDic, capture, limit = {}, [], -1
for x, y in enumerate(map(int, input().split())):
if y in myDic:
check = x - myDic[y][-1]
if myDic[y][-1] > limit:
capture.append((myDic[y][-1] + 1, x + 1))
limit = x
del myDic[y]
else:
myD... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR DICT LIST NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR NUM... |
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods... | from sys import exit
n = int(input())
lst = list(map(int, input().split()))
d, res, result, j = {}, [], 0, 1
for i, x in enumerate(lst):
if d.get(x) == None:
d[x] = 1
else:
result += 1
res.append([j, i + 1])
j = i + 2
d = {}
if res == [] and result == 0:
print(-1)
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR DICT LIST NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASS... |
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods... | def add(elements, to_add):
if to_add not in elements:
elements[to_add] = 0
elements[to_add] += 1
def remove(elements, to_remove):
elements[to_remove] -= 1
if elements[to_remove] == 0:
del elements[to_remove]
_, limit = [int(i) for i in input().split()]
arr = [int(i) for i in input().... | FUNC_DEF IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER FUNC_DEF VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR 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 NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_... |
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods... | import sys
n, k = map(int, sys.stdin.buffer.readline().decode("utf-8").split())
a = list(map(int, sys.stdin.buffer.readline().decode("utf-8").split()))
ans_len, i, j = 0, 0, 0
ans_i, ans_j = 0, 0
kind = 0
cnt = [0] * (10**6 + 10)
for i in range(n):
while j < n and kind + (1 if cnt[a[j]] == 0 else 0) <= k:
... | IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR... |
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods... | from sys import stdin
input = stdin.readline
def longestK(arr, k):
cnt = [0] * (10**6 + 1)
cur = 0
l = 0
ans = 0
al = 0
ar = 0
for i in range(len(arr)):
cnt[arr[i]] += 1
if cnt[arr[i]] == 1:
cur += 1
while cur > k:
cnt[arr[l]] -= 1
... | ASSIGN VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR N... |
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods... | n = int(input())
ty = list(map(int, input().split()))
num = 0
x = 1
seg = []
a = 1
dic = {}
for i in range(n):
dic[ty[i]] = 0
dic[ty[0]] = 1
for i in range(1, n):
jud = 0
if dic[ty[i]] != num + 1:
dic[ty[i]] = num + 1
elif dic[ty[i]] == num + 1:
jud = 1
num += 1
b = i + 1... | ASSIGN VAR FUNC_CALL VAR 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 LIST ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUM... |
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods... | count = 0
N = int(input())
A = list(map(int, input().split())) + ["-1"]
D = {}
Ans = []
a, b = 1, 1
for val in A:
if val in D:
D[val] += 1
else:
D[val] = 1
if D[val] % 2 == 0:
Ans.append([str(a), str(b)])
a = b + 1
D = {}
b += 1
L = len(Ans)
if L == 0:
print(-... | ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST STRING ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST ... |
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods... | pearl_count = int(input())
pearls = [int(pearl) for pearl in input().split()]
recorded = set()
intervals = []
begin = 1
for i in range(pearl_count):
if pearls[i] in recorded:
intervals.append([begin, i + 1])
recorded = set()
begin = i + 2
else:
recorded.add(pearls[i])
if interval... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR V... |
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods... | n = int(input())
index = 1
memory = set()
counter = 0
segments = [[0, 0]]
for number in input().split():
if number not in memory:
memory.add(number)
else:
counter += 1
segments.append([segments[-1][1] + 1, index])
memory = set()
index += 1
segments[-1][1] = n
if counter != 0:... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST LIST NUMBER NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR N... |
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods... | s1 = input().split()
length = int(s1[0])
max_k = int(s1[1])
s2 = input()
arr = s2.split()
start = 0
end = 0
dist = dict()
s = start
max_l = 0
for i in range(length):
cur = arr[i]
if cur not in dist:
dist[cur] = 1
else:
dist[cur] += 1
k = len(dist)
l = i - s
if k > max_k:
... | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VA... |
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods... | n = int(input())
a = list(map(int, input().split()))
m = {}
start = 0
count = 0
x = []
y = []
for i in range(n):
num = a[i]
if num in m:
count += 1
x.append(start + 1)
y.append(i + 1)
start = i + 1
m = {}
else:
m[num] = 1
if len(x) == 0:
print(-1)
else:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP ... |
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods... | from sys import stdin
n = int(stdin.readline().strip())
a = list(map(int, stdin.readline().split()))
s = set()
flag = False
index = 1
res1 = []
res2 = []
for i, v in enumerate(a):
if not v in s:
s.add(v)
else:
s.clear()
res1.append(index)
res2.append(i + 1)
index = i + 2... | ASSIGN VAR FUNC_CALL 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR ... |
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods... | n = int(input())
d = {}
s = input()
s = s.split()
start = 0
ans = []
for i in range(n):
if s[i] not in d:
d[s[i]] = 1
else:
ans.append([start + 1, i + 1])
start = i + 1
d = {}
if ans == []:
print(-1)
else:
print(len(ans))
for i in range(len(ans)):
if i == len(... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR DICT IF VAR LI... |
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods... | n = int(input())
a = list(map(int, input().split()))
sub = set()
starts = list()
starts.append(1)
for i in range(n):
if a[i] in sub:
sub = set()
starts.append(i + 2)
else:
sub.add(a[i])
l = len(starts)
if l == 1:
print(-1)
else:
print(l - 1)
for i in range(l - 2):
pri... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN V... |
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods... | n, k = map(int, input().split())
a = list(map(int, input().split()))
cnt = [0] * 1000001
t = 0
left = 0
right = -1
l = 0
r = 0
while r < n:
if cnt[a[r]] > 0:
cnt[a[r]] += 1
r += 1
elif t < k:
cnt[a[r]] = 1
t += 1
r += 1
else:
if r - l > right - left + 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 BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER IF ... |
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods... | n, k = map(int, input().split())
a = list(map(int, input().split()))
b = [0] * (pow(10, 6) + 5)
ans = [1, 1]
l = -1
cnt = 0
j = 0
for i in range(n):
if b[a[i]] == 0:
cnt += 1
b[a[i]] += 1
if cnt > k:
while cnt > k:
b[a[j]] -= 1
if b[a[j]] == 0:
cnt -= ... | 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 BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR... |
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods... | n = int(input())
l = list(map(int, input().split()))
L = []
d = {}
ost = -1
for i in range(n):
e = d.get(l[i], -1)
if e == -1:
d[l[i]] = i
elif e < ost:
d[l[i]] = i
else:
L.append(i)
ost = i
d[l[i]] = -1
g = len(L)
if g == 0:
print(-1)
exit()
print(g)
p = ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSI... |
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods... | def main():
a = [int(x) for x in input().split()]
g = 1
mo = 0
w = 1
bigarray = [0] * 1000000
rmo = []
req = a[1]
seq = [int(x) for x in input().split()]
bigarray[seq[0]] += 1
first = 0
last = 0
if a[0] == req:
rmo = [1, a[0]]
else:
while first != len(... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUM... |
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods... | n = int(input())
a = [int(x) for x in input().split()]
i, j = 0, 0
seen = set()
segments = []
while j < n:
if a[j] in seen:
seen = set()
segments.append((i + 1, j + 1))
j += 1
i = j
else:
seen.add(a[j])
j += 1
if not segments:
print(-1)
else:
if i < n:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST WHILE VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR ... |
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods... | n = int(input())
a = list(map(int, input().split()))
d = {}
k = 0
ans = []
j = 0
for i in range(n):
if a[i] in d:
if d[a[i]] >= j:
ans.append([j + 1, i + 1])
j = i + 1
k += 1
d[a[i]] = i
print(k if not k == 0 else -1)
for i in range(k):
if not i == k - 1:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMB... |
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods... | ans = []
s = set()
l = 1
n = input()
for i, e in enumerate(map(int, input().split()), 1):
if e in s:
s = set()
ans += [(l, i)]
l = i + 1
else:
s.add(e)
if ans:
print(len(ans))
ans[-1] = ans[-1][0], n
for a, b in ans:
print(a, b)
else:
print(-1) | ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR LIST VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR N... |
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods... | n = int(input())
l = list(map(int, input().split()))
s = set()
ans = []
for i in range(n):
if l[i] in s:
if ans:
ans.append([ans[-1][1] + 1, i + 1])
else:
ans = [[1, i + 1]]
s = set()
else:
s.add(l[i])
if ans and s:
ans[-1][1] += len(s)
if ans:
pri... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST LIST NUMBER BIN_OP VAR NUMBER ASSIG... |
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods... | n = input()
p = input()
n = n.split(" ")
k = int(n[1])
n = int(n[0])
p = p.split(" ")
p = [int(q) for q in p]
cnt = [(0) for i in range(0, int(1000000.0 + 1))]
curcnt = 0
l = 0
r = -1
maxlen = -1
maxl = 0
maxr = 0
while r < n - 1 and l <= n:
while r < n - 1 and curcnt + (cnt[p[r + 1]] == 0) <= k:
curcnt = c... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER A... |
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods... | import sys
n, m = list(map(int, sys.stdin.readline().split()))
vis = [0] * 1000005
num = list(map(int, sys.stdin.readline().split()))
flag = 0
temp = num[0]
for i in range(n):
if num[i] != temp:
flag = 1
break
if flag == 0:
print("{0} {1}".format(1, n))
else:
l = 0
r = 0
al = 0
... | IMPORT ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_C... |
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods... | n, k = map(int, input().split())
d = dict()
lo = hi = ans1 = ans2 = 0
lst = list(map(int, input().split()))
for i in range(n):
if lst[i] not in d:
d[lst[i]] = 1
else:
d[lst[i]] += 1
hi += 1
if len(d) > k:
if ans2 - ans1 <= hi - 1 - lo:
ans2 = hi - 1
ans1 =... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR B... |
The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.
Find any longest k-good segment.
As the input/output can reach huge size it is recommended to use fast input/output methods... | n = int(input())
li = list(map(int, input().split()))
s = set()
otv = []
l = 0
r = -1
for i in range(n):
if li[i] in s:
otv.append([l + 1, i + 1])
s = set()
l = i + 1
r = 1
else:
s.add(li[i])
if r == -1:
print(-1)
else:
print(len(otv))
otv[len(otv) - 1][1] = n... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.