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 find the number of good pairs of topics. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of topics. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the interestingness of the $i$-th topic for the teacher. The third line of the input contains $n$ integers $b_1, b_2, \dots, b_n$ ($1 \le b_i \le 10^9$), where $b_i$ is the interestingness of the $i$-th topic for the students. -----Output----- Print one integer β€” the number of good pairs of topic. -----Examples----- Input 5 4 8 2 6 2 4 5 4 1 3 Output 7 Input 4 1 3 2 4 1 3 2 4 Output 0
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: while -r < n and new[r] + new[j] > 0: r -= 1 ans += -r - 1 j += 1 if n - j > 1: k = n - j - 1 ans += k * (k + 1) // 2 print(ans) main()
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 ASSIGN VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER WHILE VAR VAR VAR VAR NUMBER WHILE VAR VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR 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 find the number of good pairs of topics. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of topics. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the interestingness of the $i$-th topic for the teacher. The third line of the input contains $n$ integers $b_1, b_2, \dots, b_n$ ($1 \le b_i \le 10^9$), where $b_i$ is the interestingness of the $i$-th topic for the students. -----Output----- Print one integer β€” the number of good pairs of topic. -----Examples----- Input 5 4 8 2 6 2 4 5 4 1 3 Output 7 Input 4 1 3 2 4 1 3 2 4 Output 0
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().split())) d = [(a[i] - b[i]) for i in range(n)] d.sort() neg = [] z = 0 pos = [] for x in d: if x < 0: neg += (x,) elif x == 0: z += 1 else: pos += (x,) p = len(pos) if p == 0: exit(print(0)) ans = z * p pos.insert(0, 0) p += 1 for x in neg: t = -x i = dosearch(pos, t) ans += p - i - 1 print(ans + f(p - 1))
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 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 LIST ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER VAR VAR IF VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER VAR NUMBER FOR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR BIN_OP 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 find the number of good pairs of topics. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of topics. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the interestingness of the $i$-th topic for the teacher. The third line of the input contains $n$ integers $b_1, b_2, \dots, b_n$ ($1 \le b_i \le 10^9$), where $b_i$ is the interestingness of the $i$-th topic for the students. -----Output----- Print one integer β€” the number of good pairs of topic. -----Examples----- Input 5 4 8 2 6 2 4 5 4 1 3 Output 7 Input 4 1 3 2 4 1 3 2 4 Output 0
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=True) S.sort(reverse=True) i = 0 j = 0 while i < len(T) and j < len(S): while T[i] <= S[j]: j += 1 if j == len(S): break if j == len(S): break ans += len(S) - j i += 1 print(ans)
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 VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR 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 find the number of good pairs of topics. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of topics. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the interestingness of the $i$-th topic for the teacher. The third line of the input contains $n$ integers $b_1, b_2, \dots, b_n$ ($1 \le b_i \le 10^9$), where $b_i$ is the interestingness of the $i$-th topic for the students. -----Output----- Print one integer β€” the number of good pairs of topic. -----Examples----- Input 5 4 8 2 6 2 4 5 4 1 3 Output 7 Input 4 1 3 2 4 1 3 2 4 Output 0
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 break return res def Count(diff): if len(diff) <= 1: return 0 res = ( Count(diff[: len(diff) // 2]) + Count(diff[len(diff) // 2 :]) + Merge(diff[: len(diff) // 2], diff[len(diff) // 2 :]) ) return res n = int(input()) teachers = list(map(int, input().split())) students = list(map(int, input().split())) diff = [(teachers[i] - students[i]) for i in range(n)] positive = [] pos_numbers = 0 nagetive = [] nag_numbers = 0 zero = 0 for d in diff: if d > 0: positive.append(d) pos_numbers += 1 elif d < 0: nagetive.append(d) nag_numbers += 1 else: zero += 1 res = pos_numbers * (pos_numbers - 1) // 2 + pos_numbers * zero positive = sorted(positive, reverse=False) nagetive = sorted(nagetive, reverse=True) start = 0 for d1 in range(pos_numbers): for d2 in range(start, nag_numbers): if positive[d1] + nagetive[d2] <= 0: res += d2 start = d2 break else: res += nag_numbers print(res)
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 ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN 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 ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR 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 find the number of good pairs of topics. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of topics. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the interestingness of the $i$-th topic for the teacher. The third line of the input contains $n$ integers $b_1, b_2, \dots, b_n$ ($1 \le b_i \le 10^9$), where $b_i$ is the interestingness of the $i$-th topic for the students. -----Output----- Print one integer β€” the number of good pairs of topic. -----Examples----- Input 5 4 8 2 6 2 4 5 4 1 3 Output 7 Input 4 1 3 2 4 1 3 2 4 Output 0
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 > 1: m = (x2 + x1) // 2 if c[i] + c[m] > 0: x2 = m else: x1 = m return x2 for i in range(len(a) - 1): q = wo(i) if q > 0: ans = ans + len(a) - wo(i) 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 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 NUMBER NUMBER RETURN BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR 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 find the number of good pairs of topics. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of topics. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the interestingness of the $i$-th topic for the teacher. The third line of the input contains $n$ integers $b_1, b_2, \dots, b_n$ ($1 \le b_i \le 10^9$), where $b_i$ is the interestingness of the $i$-th topic for the students. -----Output----- Print one integer β€” the number of good pairs of topic. -----Examples----- Input 5 4 8 2 6 2 4 5 4 1 3 Output 7 Input 4 1 3 2 4 1 3 2 4 Output 0
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: last = j + 1 break total += max(0, t - last) last = min(last, t - 1) else: total += t - i - 1 print(total)
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 VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR 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 find the number of good pairs of topics. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of topics. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the interestingness of the $i$-th topic for the teacher. The third line of the input contains $n$ integers $b_1, b_2, \dots, b_n$ ($1 \le b_i \le 10^9$), where $b_i$ is the interestingness of the $i$-th topic for the students. -----Output----- Print one integer β€” the number of good pairs of topic. -----Examples----- Input 5 4 8 2 6 2 4 5 4 1 3 Output 7 Input 4 1 3 2 4 1 3 2 4 Output 0
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 < len(pos) and i < len(neg): if neg[i] < pos[j]: i += 1 else: ans += i j += 1 if j < len(pos): ans += (len(pos) - j) * len(neg) 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 VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR 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 find the number of good pairs of topics. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of topics. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the interestingness of the $i$-th topic for the teacher. The third line of the input contains $n$ integers $b_1, b_2, \dots, b_n$ ($1 \le b_i \le 10^9$), where $b_i$ is the interestingness of the $i$-th topic for the students. -----Output----- Print one integer β€” the number of good pairs of topic. -----Examples----- Input 5 4 8 2 6 2 4 5 4 1 3 Output 7 Input 4 1 3 2 4 1 3 2 4 Output 0
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 = [(a[i] - b[i]) for i in range(n)] c.sort(reverse=True) ans = 0 for i in range(1, n): ans += search(i) print(ans)
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 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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR VAR 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 find the number of good pairs of topics. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of topics. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the interestingness of the $i$-th topic for the teacher. The third line of the input contains $n$ integers $b_1, b_2, \dots, b_n$ ($1 \le b_i \le 10^9$), where $b_i$ is the interestingness of the $i$-th topic for the students. -----Output----- Print one integer β€” the number of good pairs of topic. -----Examples----- Input 5 4 8 2 6 2 4 5 4 1 3 Output 7 Input 4 1 3 2 4 1 3 2 4 Output 0
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): if diff[-1 - j - cnt] < 0 and diff[-1 - j - cnt] + val <= 0: limit = diff[-1 - j - cnt] else: cnt += j break ans += n - i - cnt else: break print(ans)
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_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR BIN_OP BIN_OP NUMBER VAR VAR NUMBER BIN_OP VAR BIN_OP BIN_OP NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR 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 find the number of good pairs of topics. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of topics. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the interestingness of the $i$-th topic for the teacher. The third line of the input contains $n$ integers $b_1, b_2, \dots, b_n$ ($1 \le b_i \le 10^9$), where $b_i$ is the interestingness of the $i$-th topic for the students. -----Output----- Print one integer β€” the number of good pairs of topic. -----Examples----- Input 5 4 8 2 6 2 4 5 4 1 3 Output 7 Input 4 1 3 2 4 1 3 2 4 Output 0
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] > pos: return len(arr) - r else: return 0 n = int(input()) arr = list(map(int, input().split())) brr = list(map(int, input().split())) diff = [] for i in range(n): diff.append(arr[i] - brr[i]) diff.sort() ans = 0 cnt = 0 for i in diff: if i > 0: cnt += 1 for i in range(n): if diff[i] < 0: val = binarysearch(diff, diff[i]) ans += val elif diff[i] == 0: ans += cnt print(ans + cnt * (cnt - 1) // 2)
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 BIN_OP FUNC_CALL VAR VAR VAR RETURN NUMBER 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 FOR VAR VAR IF VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER 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 find the number of good pairs of topics. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of topics. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the interestingness of the $i$-th topic for the teacher. The third line of the input contains $n$ integers $b_1, b_2, \dots, b_n$ ($1 \le b_i \le 10^9$), where $b_i$ is the interestingness of the $i$-th topic for the students. -----Output----- Print one integer β€” the number of good pairs of topic. -----Examples----- Input 5 4 8 2 6 2 4 5 4 1 3 Output 7 Input 4 1 3 2 4 1 3 2 4 Output 0
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 += 1 print(nb)
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 ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER 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 find the number of good pairs of topics. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of topics. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the interestingness of the $i$-th topic for the teacher. The third line of the input contains $n$ integers $b_1, b_2, \dots, b_n$ ($1 \le b_i \le 10^9$), where $b_i$ is the interestingness of the $i$-th topic for the students. -----Output----- Print one integer β€” the number of good pairs of topic. -----Examples----- Input 5 4 8 2 6 2 4 5 4 1 3 Output 7 Input 4 1 3 2 4 1 3 2 4 Output 0
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 print(cnt)
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 VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR 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 find the number of good pairs of topics. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of topics. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the interestingness of the $i$-th topic for the teacher. The third line of the input contains $n$ integers $b_1, b_2, \dots, b_n$ ($1 \le b_i \le 10^9$), where $b_i$ is the interestingness of the $i$-th topic for the students. -----Output----- Print one integer β€” the number of good pairs of topic. -----Examples----- Input 5 4 8 2 6 2 4 5 4 1 3 Output 7 Input 4 1 3 2 4 1 3 2 4 Output 0
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 VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR 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 find the number of good pairs of topics. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of topics. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the interestingness of the $i$-th topic for the teacher. The third line of the input contains $n$ integers $b_1, b_2, \dots, b_n$ ($1 \le b_i \le 10^9$), where $b_i$ is the interestingness of the $i$-th topic for the students. -----Output----- Print one integer β€” the number of good pairs of topic. -----Examples----- Input 5 4 8 2 6 2 4 5 4 1 3 Output 7 Input 4 1 3 2 4 1 3 2 4 Output 0
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] + arr[end] <= 0: start += 1 else: count += end - start end -= 1 print(count) except: pass
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 NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR 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 find the number of good pairs of topics. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of topics. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the interestingness of the $i$-th topic for the teacher. The third line of the input contains $n$ integers $b_1, b_2, \dots, b_n$ ($1 \le b_i \le 10^9$), where $b_i$ is the interestingness of the $i$-th topic for the students. -----Output----- Print one integer β€” the number of good pairs of topic. -----Examples----- Input 5 4 8 2 6 2 4 5 4 1 3 Output 7 Input 4 1 3 2 4 1 3 2 4 Output 0
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 else: L = M + 1 count += n - x print(count)
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_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR 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 find the number of good pairs of topics. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of topics. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the interestingness of the $i$-th topic for the teacher. The third line of the input contains $n$ integers $b_1, b_2, \dots, b_n$ ($1 \le b_i \le 10^9$), where $b_i$ is the interestingness of the $i$-th topic for the students. -----Output----- Print one integer β€” the number of good pairs of topic. -----Examples----- Input 5 4 8 2 6 2 4 5 4 1 3 Output 7 Input 4 1 3 2 4 1 3 2 4 Output 0
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_CALL VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR 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 find the number of good pairs of topics. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of topics. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the interestingness of the $i$-th topic for the teacher. The third line of the input contains $n$ integers $b_1, b_2, \dots, b_n$ ($1 \le b_i \le 10^9$), where $b_i$ is the interestingness of the $i$-th topic for the students. -----Output----- Print one integer β€” the number of good pairs of topic. -----Examples----- Input 5 4 8 2 6 2 4 5 4 1 3 Output 7 Input 4 1 3 2 4 1 3 2 4 Output 0
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: r -= 1 lis[i] = r + 1 count += i - lis[i] print(count)
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 VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR 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 find the number of good pairs of topics. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of topics. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the interestingness of the $i$-th topic for the teacher. The third line of the input contains $n$ integers $b_1, b_2, \dots, b_n$ ($1 \le b_i \le 10^9$), where $b_i$ is the interestingness of the $i$-th topic for the students. -----Output----- Print one integer β€” the number of good pairs of topic. -----Examples----- Input 5 4 8 2 6 2 4 5 4 1 3 Output 7 Input 4 1 3 2 4 1 3 2 4 Output 0
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] >= x + 1: h = mid - 1 n = int(input()) a = input() A = list(map(int, list(a.split()))) b = input() B = list(map(int, list(b.split()))) c = [0] * n for i in range(n): c[i] = A[i] - B[i] c.sort() if c[n - 1] <= 0: print(0) else: ans = 0 for i in range(n - 1, -1, -1): if c[i] <= 0: break else: y = find(c, -1 * c[i], n) ans = ans + i - y print(ans)
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 BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL 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 IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR 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 find the number of good pairs of topics. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of topics. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the interestingness of the $i$-th topic for the teacher. The third line of the input contains $n$ integers $b_1, b_2, \dots, b_n$ ($1 \le b_i \le 10^9$), where $b_i$ is the interestingness of the $i$-th topic for the students. -----Output----- Print one integer β€” the number of good pairs of topic. -----Examples----- Input 5 4 8 2 6 2 4 5 4 1 3 Output 7 Input 4 1 3 2 4 1 3 2 4 Output 0
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 >> 1 if diffs[i] + diffs[mid] > 0: best = min(best, mid) hi = mid - 1 else: lo = mid + 1 res += n - best print(res)
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 VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR 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 find the number of good pairs of topics. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of topics. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the interestingness of the $i$-th topic for the teacher. The third line of the input contains $n$ integers $b_1, b_2, \dots, b_n$ ($1 \le b_i \le 10^9$), where $b_i$ is the interestingness of the $i$-th topic for the students. -----Output----- Print one integer β€” the number of good pairs of topic. -----Examples----- Input 5 4 8 2 6 2 4 5 4 1 3 Output 7 Input 4 1 3 2 4 1 3 2 4 Output 0
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 VAR VAR VAR NUMBER 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 find the number of good pairs of topics. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) β€” the number of topics. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the interestingness of the $i$-th topic for the teacher. The third line of the input contains $n$ integers $b_1, b_2, \dots, b_n$ ($1 \le b_i \le 10^9$), where $b_i$ is the interestingness of the $i$-th topic for the students. -----Output----- Print one integer β€” the number of good pairs of topic. -----Examples----- Input 5 4 8 2 6 2 4 5 4 1 3 Output 7 Input 4 1 3 2 4 1 3 2 4 Output 0
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: ans += end - start end -= 1 else: start += 1 print(ans)
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 VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL 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 ATM. Otherwise, the student withdraws $|a_i|$ rubles. In the beginning, the ATM is turned off and an arbitrary number of students are not served. At some point, Polycarp turns on the ATM, which has an initial amount of $s$ rubles. Then, the remaining students start queueing at the ATM. If at some point in time there is less money in the ATM than the student wants to withdraw, then the student is not served and Polycarp turns off the ATM and does not turn it on anymore. More formally, the students that are served are forming a contiguous subsequence. Polycarp wants the ATM to serve the maximum number of students. Help him in this matter. Print the numbers of the first and last student, or determine that he will not be able to serve anyone. In other words, find such a longest continuous segment of students that, starting with the sum of $s$ at the ATM, all these students will be served. ATM serves students consistently (i.e. one after another in the order of the queue). -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) β€” the number of test cases. Each test case consists of two lines. The first one contains integers $n$ and $s$ ($1 \le n \le 2\cdot10^5$; $0 \le s \le 10^9$) β€” the length of the $a$ array and the initial amount of rubles in the ATM. The second contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$) β€” elements of the $a$ array. Note that $a_i$ can be zero. It is guaranteed that the sum of the values $n$ over all test cases does not exceed $2\cdot10^5$. -----Output----- Print $t$ lines, each line must contain the answer to the corresponding set of input data: if the answer exists, print the numbers of the first and last served student. If there is no solution, then print -1 on the line. If there are several possible answers, print any. -----Examples----- Input 3 4 10 -16 2 -6 8 3 1000 -100000 -100000 -100000 6 0 2 6 -164 1 -1 -6543 Output 2 4 -1 1 2 -----Note----- In the first test case, the only correct answer is 2 4, since when serving students, the number of rubles at the ATM does not become negative, and this is the maximum number of students that can be served. In the second test case, the answer is -1, as there is not enough money for any student at the ATM. In the third test case, the answer can be either 1 2 or 4 5.
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 curActivitySum -= studentActivity[firstIndex] curActivityLength = lastIndex - firstIndex if curActivityLength > maxContiguousLength: rangeList = [firstIndex + 2, lastIndex + 1] maxContiguousLength = curActivityLength print(*rangeList) for case in range(int(input())): n, s = map(int, input().split()) studentActivity = list(map(int, input().split())) solve(studentActivity, n, s)
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 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 EXPR FUNC_CALL VAR VAR 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 ATM. Otherwise, the student withdraws $|a_i|$ rubles. In the beginning, the ATM is turned off and an arbitrary number of students are not served. At some point, Polycarp turns on the ATM, which has an initial amount of $s$ rubles. Then, the remaining students start queueing at the ATM. If at some point in time there is less money in the ATM than the student wants to withdraw, then the student is not served and Polycarp turns off the ATM and does not turn it on anymore. More formally, the students that are served are forming a contiguous subsequence. Polycarp wants the ATM to serve the maximum number of students. Help him in this matter. Print the numbers of the first and last student, or determine that he will not be able to serve anyone. In other words, find such a longest continuous segment of students that, starting with the sum of $s$ at the ATM, all these students will be served. ATM serves students consistently (i.e. one after another in the order of the queue). -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) β€” the number of test cases. Each test case consists of two lines. The first one contains integers $n$ and $s$ ($1 \le n \le 2\cdot10^5$; $0 \le s \le 10^9$) β€” the length of the $a$ array and the initial amount of rubles in the ATM. The second contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$) β€” elements of the $a$ array. Note that $a_i$ can be zero. It is guaranteed that the sum of the values $n$ over all test cases does not exceed $2\cdot10^5$. -----Output----- Print $t$ lines, each line must contain the answer to the corresponding set of input data: if the answer exists, print the numbers of the first and last served student. If there is no solution, then print -1 on the line. If there are several possible answers, print any. -----Examples----- Input 3 4 10 -16 2 -6 8 3 1000 -100000 -100000 -100000 6 0 2 6 -164 1 -1 -6543 Output 2 4 -1 1 2 -----Note----- In the first test case, the only correct answer is 2 4, since when serving students, the number of rubles at the ATM does not become negative, and this is the maximum number of students that can be served. In the second test case, the answer is -1, as there is not enough money for any student at the ATM. In the third test case, the answer can be either 1 2 or 4 5.
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] l += 1 if r - l + 1 > length[0]: length = [r - l + 1, l + 1, r + 1] print(*length[1:]) if length[0] > 0 else print(-1)
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 WHILE VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL 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 ATM. Otherwise, the student withdraws $|a_i|$ rubles. In the beginning, the ATM is turned off and an arbitrary number of students are not served. At some point, Polycarp turns on the ATM, which has an initial amount of $s$ rubles. Then, the remaining students start queueing at the ATM. If at some point in time there is less money in the ATM than the student wants to withdraw, then the student is not served and Polycarp turns off the ATM and does not turn it on anymore. More formally, the students that are served are forming a contiguous subsequence. Polycarp wants the ATM to serve the maximum number of students. Help him in this matter. Print the numbers of the first and last student, or determine that he will not be able to serve anyone. In other words, find such a longest continuous segment of students that, starting with the sum of $s$ at the ATM, all these students will be served. ATM serves students consistently (i.e. one after another in the order of the queue). -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) β€” the number of test cases. Each test case consists of two lines. The first one contains integers $n$ and $s$ ($1 \le n \le 2\cdot10^5$; $0 \le s \le 10^9$) β€” the length of the $a$ array and the initial amount of rubles in the ATM. The second contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$) β€” elements of the $a$ array. Note that $a_i$ can be zero. It is guaranteed that the sum of the values $n$ over all test cases does not exceed $2\cdot10^5$. -----Output----- Print $t$ lines, each line must contain the answer to the corresponding set of input data: if the answer exists, print the numbers of the first and last served student. If there is no solution, then print -1 on the line. If there are several possible answers, print any. -----Examples----- Input 3 4 10 -16 2 -6 8 3 1000 -100000 -100000 -100000 6 0 2 6 -164 1 -1 -6543 Output 2 4 -1 1 2 -----Note----- In the first test case, the only correct answer is 2 4, since when serving students, the number of rubles at the ATM does not become negative, and this is the maximum number of students that can be served. In the second test case, the answer is -1, as there is not enough money for any student at the ATM. In the third test case, the answer can be either 1 2 or 4 5.
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 while l < r and sum < 0: sum -= ar[l] l += 1 else: dist = r - l + 1 if maxd < dist: resL = l + 1 resr = r + 1 maxd = max(maxd, dist) r += 1 if resL == -1: print(-1) else: print(resL, resr)
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 NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR IF VAR NUMBER VAR NUMBER WHILE VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR 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 ATM. Otherwise, the student withdraws $|a_i|$ rubles. In the beginning, the ATM is turned off and an arbitrary number of students are not served. At some point, Polycarp turns on the ATM, which has an initial amount of $s$ rubles. Then, the remaining students start queueing at the ATM. If at some point in time there is less money in the ATM than the student wants to withdraw, then the student is not served and Polycarp turns off the ATM and does not turn it on anymore. More formally, the students that are served are forming a contiguous subsequence. Polycarp wants the ATM to serve the maximum number of students. Help him in this matter. Print the numbers of the first and last student, or determine that he will not be able to serve anyone. In other words, find such a longest continuous segment of students that, starting with the sum of $s$ at the ATM, all these students will be served. ATM serves students consistently (i.e. one after another in the order of the queue). -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) β€” the number of test cases. Each test case consists of two lines. The first one contains integers $n$ and $s$ ($1 \le n \le 2\cdot10^5$; $0 \le s \le 10^9$) β€” the length of the $a$ array and the initial amount of rubles in the ATM. The second contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$) β€” elements of the $a$ array. Note that $a_i$ can be zero. It is guaranteed that the sum of the values $n$ over all test cases does not exceed $2\cdot10^5$. -----Output----- Print $t$ lines, each line must contain the answer to the corresponding set of input data: if the answer exists, print the numbers of the first and last served student. If there is no solution, then print -1 on the line. If there are several possible answers, print any. -----Examples----- Input 3 4 10 -16 2 -6 8 3 1000 -100000 -100000 -100000 6 0 2 6 -164 1 -1 -6543 Output 2 4 -1 1 2 -----Note----- In the first test case, the only correct answer is 2 4, since when serving students, the number of rubles at the ATM does not become negative, and this is the maximum number of students that can be served. In the second test case, the answer is -1, as there is not enough money for any student at the ATM. In the third test case, the answer can be either 1 2 or 4 5.
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 = pos final = pos suma += valor else: suma += valor final = pos longitud = final - indice + 1 if longitud > maximo: last_indice = indice last_final = final maximo = max(maximo, longitud) elif indice != -1: suma += queries[pos] for j in range(indice, pos + 1): suma -= queries[j] if suma >= 0: indice = j + 1 break if indice == -1: print(-1) else: print(last_indice + 1, last_final + 1)
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 ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP 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 ATM. Otherwise, the student withdraws $|a_i|$ rubles. In the beginning, the ATM is turned off and an arbitrary number of students are not served. At some point, Polycarp turns on the ATM, which has an initial amount of $s$ rubles. Then, the remaining students start queueing at the ATM. If at some point in time there is less money in the ATM than the student wants to withdraw, then the student is not served and Polycarp turns off the ATM and does not turn it on anymore. More formally, the students that are served are forming a contiguous subsequence. Polycarp wants the ATM to serve the maximum number of students. Help him in this matter. Print the numbers of the first and last student, or determine that he will not be able to serve anyone. In other words, find such a longest continuous segment of students that, starting with the sum of $s$ at the ATM, all these students will be served. ATM serves students consistently (i.e. one after another in the order of the queue). -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) β€” the number of test cases. Each test case consists of two lines. The first one contains integers $n$ and $s$ ($1 \le n \le 2\cdot10^5$; $0 \le s \le 10^9$) β€” the length of the $a$ array and the initial amount of rubles in the ATM. The second contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$) β€” elements of the $a$ array. Note that $a_i$ can be zero. It is guaranteed that the sum of the values $n$ over all test cases does not exceed $2\cdot10^5$. -----Output----- Print $t$ lines, each line must contain the answer to the corresponding set of input data: if the answer exists, print the numbers of the first and last served student. If there is no solution, then print -1 on the line. If there are several possible answers, print any. -----Examples----- Input 3 4 10 -16 2 -6 8 3 1000 -100000 -100000 -100000 6 0 2 6 -164 1 -1 -6543 Output 2 4 -1 1 2 -----Note----- In the first test case, the only correct answer is 2 4, since when serving students, the number of rubles at the ATM does not become negative, and this is the maximum number of students that can be served. In the second test case, the answer is -1, as there is not enough money for any student at the ATM. In the third test case, the answer can be either 1 2 or 4 5.
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 arr[j] < 0: if curr >= abs(arr[j]): curr -= abs(arr[j]) j += 1 elif curr < abs(arr[j]): a = i + 1 b = j if b - a > _maxlen: ans = str(a) + " " + str(b) _maxlen = b - a curr -= arr[i] i += 1 a = i + 1 b = j if b - a > _maxlen: ans = str(a) + " " + str(b) _maxlen = b - a if len(ans) > 0: print(ans) else: print(-1)
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_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL 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 ATM. Otherwise, the student withdraws $|a_i|$ rubles. In the beginning, the ATM is turned off and an arbitrary number of students are not served. At some point, Polycarp turns on the ATM, which has an initial amount of $s$ rubles. Then, the remaining students start queueing at the ATM. If at some point in time there is less money in the ATM than the student wants to withdraw, then the student is not served and Polycarp turns off the ATM and does not turn it on anymore. More formally, the students that are served are forming a contiguous subsequence. Polycarp wants the ATM to serve the maximum number of students. Help him in this matter. Print the numbers of the first and last student, or determine that he will not be able to serve anyone. In other words, find such a longest continuous segment of students that, starting with the sum of $s$ at the ATM, all these students will be served. ATM serves students consistently (i.e. one after another in the order of the queue). -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) β€” the number of test cases. Each test case consists of two lines. The first one contains integers $n$ and $s$ ($1 \le n \le 2\cdot10^5$; $0 \le s \le 10^9$) β€” the length of the $a$ array and the initial amount of rubles in the ATM. The second contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$) β€” elements of the $a$ array. Note that $a_i$ can be zero. It is guaranteed that the sum of the values $n$ over all test cases does not exceed $2\cdot10^5$. -----Output----- Print $t$ lines, each line must contain the answer to the corresponding set of input data: if the answer exists, print the numbers of the first and last served student. If there is no solution, then print -1 on the line. If there are several possible answers, print any. -----Examples----- Input 3 4 10 -16 2 -6 8 3 1000 -100000 -100000 -100000 6 0 2 6 -164 1 -1 -6543 Output 2 4 -1 1 2 -----Note----- In the first test case, the only correct answer is 2 4, since when serving students, the number of rubles at the ATM does not become negative, and this is the maximum number of students that can be served. In the second test case, the answer is -1, as there is not enough money for any student at the ATM. In the third test case, the answer can be either 1 2 or 4 5.
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] left += 1 student_window = right - left + 1 if student_window > students: students = student_window end = right if end == -1: print(-1) else: end += 1 print(end - students + 1, end)
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 VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER 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 ATM. Otherwise, the student withdraws $|a_i|$ rubles. In the beginning, the ATM is turned off and an arbitrary number of students are not served. At some point, Polycarp turns on the ATM, which has an initial amount of $s$ rubles. Then, the remaining students start queueing at the ATM. If at some point in time there is less money in the ATM than the student wants to withdraw, then the student is not served and Polycarp turns off the ATM and does not turn it on anymore. More formally, the students that are served are forming a contiguous subsequence. Polycarp wants the ATM to serve the maximum number of students. Help him in this matter. Print the numbers of the first and last student, or determine that he will not be able to serve anyone. In other words, find such a longest continuous segment of students that, starting with the sum of $s$ at the ATM, all these students will be served. ATM serves students consistently (i.e. one after another in the order of the queue). -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) β€” the number of test cases. Each test case consists of two lines. The first one contains integers $n$ and $s$ ($1 \le n \le 2\cdot10^5$; $0 \le s \le 10^9$) β€” the length of the $a$ array and the initial amount of rubles in the ATM. The second contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$) β€” elements of the $a$ array. Note that $a_i$ can be zero. It is guaranteed that the sum of the values $n$ over all test cases does not exceed $2\cdot10^5$. -----Output----- Print $t$ lines, each line must contain the answer to the corresponding set of input data: if the answer exists, print the numbers of the first and last served student. If there is no solution, then print -1 on the line. If there are several possible answers, print any. -----Examples----- Input 3 4 10 -16 2 -6 8 3 1000 -100000 -100000 -100000 6 0 2 6 -164 1 -1 -6543 Output 2 4 -1 1 2 -----Note----- In the first test case, the only correct answer is 2 4, since when serving students, the number of rubles at the ATM does not become negative, and this is the maximum number of students that can be served. In the second test case, the answer is -1, as there is not enough money for any student at the ATM. In the third test case, the answer can be either 1 2 or 4 5.
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: left, right = i, j j += 1 else: i += 1 if left == right: print(-1) else: print(left + 1, right)
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 ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER 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 ATM. Otherwise, the student withdraws $|a_i|$ rubles. In the beginning, the ATM is turned off and an arbitrary number of students are not served. At some point, Polycarp turns on the ATM, which has an initial amount of $s$ rubles. Then, the remaining students start queueing at the ATM. If at some point in time there is less money in the ATM than the student wants to withdraw, then the student is not served and Polycarp turns off the ATM and does not turn it on anymore. More formally, the students that are served are forming a contiguous subsequence. Polycarp wants the ATM to serve the maximum number of students. Help him in this matter. Print the numbers of the first and last student, or determine that he will not be able to serve anyone. In other words, find such a longest continuous segment of students that, starting with the sum of $s$ at the ATM, all these students will be served. ATM serves students consistently (i.e. one after another in the order of the queue). -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) β€” the number of test cases. Each test case consists of two lines. The first one contains integers $n$ and $s$ ($1 \le n \le 2\cdot10^5$; $0 \le s \le 10^9$) β€” the length of the $a$ array and the initial amount of rubles in the ATM. The second contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$) β€” elements of the $a$ array. Note that $a_i$ can be zero. It is guaranteed that the sum of the values $n$ over all test cases does not exceed $2\cdot10^5$. -----Output----- Print $t$ lines, each line must contain the answer to the corresponding set of input data: if the answer exists, print the numbers of the first and last served student. If there is no solution, then print -1 on the line. If there are several possible answers, print any. -----Examples----- Input 3 4 10 -16 2 -6 8 3 1000 -100000 -100000 -100000 6 0 2 6 -164 1 -1 -6543 Output 2 4 -1 1 2 -----Note----- In the first test case, the only correct answer is 2 4, since when serving students, the number of rubles at the ATM does not become negative, and this is the maximum number of students that can be served. In the second test case, the answer is -1, as there is not enough money for any student at the ATM. In the third test case, the answer can be either 1 2 or 4 5.
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] m = r - l + 1 r += 1 elif l == r: add = 0 l += 1 r += 1 else: add -= a[l] l += 1 if m == 0: print("-1") else: print(f"{ans[0] + 1} {ans[1] + 1}")
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 VAR VAR VAR VAR NUMBER VAR VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR LIST VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER STRING BIN_OP VAR NUMBER 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 ATM. Otherwise, the student withdraws $|a_i|$ rubles. In the beginning, the ATM is turned off and an arbitrary number of students are not served. At some point, Polycarp turns on the ATM, which has an initial amount of $s$ rubles. Then, the remaining students start queueing at the ATM. If at some point in time there is less money in the ATM than the student wants to withdraw, then the student is not served and Polycarp turns off the ATM and does not turn it on anymore. More formally, the students that are served are forming a contiguous subsequence. Polycarp wants the ATM to serve the maximum number of students. Help him in this matter. Print the numbers of the first and last student, or determine that he will not be able to serve anyone. In other words, find such a longest continuous segment of students that, starting with the sum of $s$ at the ATM, all these students will be served. ATM serves students consistently (i.e. one after another in the order of the queue). -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) β€” the number of test cases. Each test case consists of two lines. The first one contains integers $n$ and $s$ ($1 \le n \le 2\cdot10^5$; $0 \le s \le 10^9$) β€” the length of the $a$ array and the initial amount of rubles in the ATM. The second contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$) β€” elements of the $a$ array. Note that $a_i$ can be zero. It is guaranteed that the sum of the values $n$ over all test cases does not exceed $2\cdot10^5$. -----Output----- Print $t$ lines, each line must contain the answer to the corresponding set of input data: if the answer exists, print the numbers of the first and last served student. If there is no solution, then print -1 on the line. If there are several possible answers, print any. -----Examples----- Input 3 4 10 -16 2 -6 8 3 1000 -100000 -100000 -100000 6 0 2 6 -164 1 -1 -6543 Output 2 4 -1 1 2 -----Note----- In the first test case, the only correct answer is 2 4, since when serving students, the number of rubles at the ATM does not become negative, and this is the maximum number of students that can be served. In the second test case, the answer is -1, as there is not enough money for any student at the ATM. In the third test case, the answer can be either 1 2 or 4 5.
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 - left + 1 > maxSoFar: maxSoFar = right - left + 1 x = left y = right print(f"{x} {y}" if maxSoFar else -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 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 NUMBER VAR VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING 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 ATM. Otherwise, the student withdraws $|a_i|$ rubles. In the beginning, the ATM is turned off and an arbitrary number of students are not served. At some point, Polycarp turns on the ATM, which has an initial amount of $s$ rubles. Then, the remaining students start queueing at the ATM. If at some point in time there is less money in the ATM than the student wants to withdraw, then the student is not served and Polycarp turns off the ATM and does not turn it on anymore. More formally, the students that are served are forming a contiguous subsequence. Polycarp wants the ATM to serve the maximum number of students. Help him in this matter. Print the numbers of the first and last student, or determine that he will not be able to serve anyone. In other words, find such a longest continuous segment of students that, starting with the sum of $s$ at the ATM, all these students will be served. ATM serves students consistently (i.e. one after another in the order of the queue). -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) β€” the number of test cases. Each test case consists of two lines. The first one contains integers $n$ and $s$ ($1 \le n \le 2\cdot10^5$; $0 \le s \le 10^9$) β€” the length of the $a$ array and the initial amount of rubles in the ATM. The second contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$) β€” elements of the $a$ array. Note that $a_i$ can be zero. It is guaranteed that the sum of the values $n$ over all test cases does not exceed $2\cdot10^5$. -----Output----- Print $t$ lines, each line must contain the answer to the corresponding set of input data: if the answer exists, print the numbers of the first and last served student. If there is no solution, then print -1 on the line. If there are several possible answers, print any. -----Examples----- Input 3 4 10 -16 2 -6 8 3 1000 -100000 -100000 -100000 6 0 2 6 -164 1 -1 -6543 Output 2 4 -1 1 2 -----Note----- In the first test case, the only correct answer is 2 4, since when serving students, the number of rubles at the ATM does not become negative, and this is the maximum number of students that can be served. In the second test case, the answer is -1, as there is not enough money for any student at the ATM. In the third test case, the answer can be either 1 2 or 4 5.
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 l2 < n and summa + a[l2] + s >= 0: summa += a[l2] l2 += 1 if r_l2 - r_l1 < l2 - l1: r_l2, r_l1 = l2, l1 summa -= a[l1] l1 += 1 print(r_l1 + 1, r_l2) if r_l1 < r_l2 else print(-1) main()
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 ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL 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 ATM. Otherwise, the student withdraws $|a_i|$ rubles. In the beginning, the ATM is turned off and an arbitrary number of students are not served. At some point, Polycarp turns on the ATM, which has an initial amount of $s$ rubles. Then, the remaining students start queueing at the ATM. If at some point in time there is less money in the ATM than the student wants to withdraw, then the student is not served and Polycarp turns off the ATM and does not turn it on anymore. More formally, the students that are served are forming a contiguous subsequence. Polycarp wants the ATM to serve the maximum number of students. Help him in this matter. Print the numbers of the first and last student, or determine that he will not be able to serve anyone. In other words, find such a longest continuous segment of students that, starting with the sum of $s$ at the ATM, all these students will be served. ATM serves students consistently (i.e. one after another in the order of the queue). -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) β€” the number of test cases. Each test case consists of two lines. The first one contains integers $n$ and $s$ ($1 \le n \le 2\cdot10^5$; $0 \le s \le 10^9$) β€” the length of the $a$ array and the initial amount of rubles in the ATM. The second contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$) β€” elements of the $a$ array. Note that $a_i$ can be zero. It is guaranteed that the sum of the values $n$ over all test cases does not exceed $2\cdot10^5$. -----Output----- Print $t$ lines, each line must contain the answer to the corresponding set of input data: if the answer exists, print the numbers of the first and last served student. If there is no solution, then print -1 on the line. If there are several possible answers, print any. -----Examples----- Input 3 4 10 -16 2 -6 8 3 1000 -100000 -100000 -100000 6 0 2 6 -164 1 -1 -6543 Output 2 4 -1 1 2 -----Note----- In the first test case, the only correct answer is 2 4, since when serving students, the number of rubles at the ATM does not become negative, and this is the maximum number of students that can be served. In the second test case, the answer is -1, as there is not enough money for any student at the ATM. In the third test case, the answer can be either 1 2 or 4 5.
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 -= 1 if rmax - lmax + 1 < cur_max: lmax = l rmax = r r += 1 if rmax == -1: print(-1) else: print(str(lmax + 1) + " " + str(rmax + 1))
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 NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP 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 ATM. Otherwise, the student withdraws $|a_i|$ rubles. In the beginning, the ATM is turned off and an arbitrary number of students are not served. At some point, Polycarp turns on the ATM, which has an initial amount of $s$ rubles. Then, the remaining students start queueing at the ATM. If at some point in time there is less money in the ATM than the student wants to withdraw, then the student is not served and Polycarp turns off the ATM and does not turn it on anymore. More formally, the students that are served are forming a contiguous subsequence. Polycarp wants the ATM to serve the maximum number of students. Help him in this matter. Print the numbers of the first and last student, or determine that he will not be able to serve anyone. In other words, find such a longest continuous segment of students that, starting with the sum of $s$ at the ATM, all these students will be served. ATM serves students consistently (i.e. one after another in the order of the queue). -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) β€” the number of test cases. Each test case consists of two lines. The first one contains integers $n$ and $s$ ($1 \le n \le 2\cdot10^5$; $0 \le s \le 10^9$) β€” the length of the $a$ array and the initial amount of rubles in the ATM. The second contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$) β€” elements of the $a$ array. Note that $a_i$ can be zero. It is guaranteed that the sum of the values $n$ over all test cases does not exceed $2\cdot10^5$. -----Output----- Print $t$ lines, each line must contain the answer to the corresponding set of input data: if the answer exists, print the numbers of the first and last served student. If there is no solution, then print -1 on the line. If there are several possible answers, print any. -----Examples----- Input 3 4 10 -16 2 -6 8 3 1000 -100000 -100000 -100000 6 0 2 6 -164 1 -1 -6543 Output 2 4 -1 1 2 -----Note----- In the first test case, the only correct answer is 2 4, since when serving students, the number of rubles at the ATM does not become negative, and this is the maximum number of students that can be served. In the second test case, the answer is -1, as there is not enough money for any student at the ATM. In the third test case, the answer can be either 1 2 or 4 5.
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 = 0 maxlength = 0 temp_sum = a[0] while curlp != n - 1: if temp_sum + s >= 0: temp_sum += a[curlp + 1] curlength += 1 curlp += 1 elif curfp == curlp: temp_sum = a[curlp + 1] curfp += 1 curlp += 1 else: if curlength > maxlength: maxlength = curlength maxfp = curfp maxlp = curlp - 1 temp_sum -= a[curfp] curfp += 1 curlength -= 1 if curlp - curfp + 1 > maxlength and temp_sum + s >= 0: maxlength = curlp - curfp + 1 maxfp = curfp maxlp = curlp elif curlength > maxlength: maxlength = curlength maxfp = curfp maxlp = curlp - 1 if maxlength > 0: print(maxfp + 1, maxlp + 1) else: print(-1)
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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL 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 ATM. Otherwise, the student withdraws $|a_i|$ rubles. In the beginning, the ATM is turned off and an arbitrary number of students are not served. At some point, Polycarp turns on the ATM, which has an initial amount of $s$ rubles. Then, the remaining students start queueing at the ATM. If at some point in time there is less money in the ATM than the student wants to withdraw, then the student is not served and Polycarp turns off the ATM and does not turn it on anymore. More formally, the students that are served are forming a contiguous subsequence. Polycarp wants the ATM to serve the maximum number of students. Help him in this matter. Print the numbers of the first and last student, or determine that he will not be able to serve anyone. In other words, find such a longest continuous segment of students that, starting with the sum of $s$ at the ATM, all these students will be served. ATM serves students consistently (i.e. one after another in the order of the queue). -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) β€” the number of test cases. Each test case consists of two lines. The first one contains integers $n$ and $s$ ($1 \le n \le 2\cdot10^5$; $0 \le s \le 10^9$) β€” the length of the $a$ array and the initial amount of rubles in the ATM. The second contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$) β€” elements of the $a$ array. Note that $a_i$ can be zero. It is guaranteed that the sum of the values $n$ over all test cases does not exceed $2\cdot10^5$. -----Output----- Print $t$ lines, each line must contain the answer to the corresponding set of input data: if the answer exists, print the numbers of the first and last served student. If there is no solution, then print -1 on the line. If there are several possible answers, print any. -----Examples----- Input 3 4 10 -16 2 -6 8 3 1000 -100000 -100000 -100000 6 0 2 6 -164 1 -1 -6543 Output 2 4 -1 1 2 -----Note----- In the first test case, the only correct answer is 2 4, since when serving students, the number of rubles at the ATM does not become negative, and this is the maximum number of students that can be served. In the second test case, the answer is -1, as there is not enough money for any student at the ATM. In the third test case, the answer can be either 1 2 or 4 5.
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 while t + l[i] < 0 and x != y: t -= l[x] x += 1 y += 1 if t + l[i] < 0: x += 1 else: t += l[i] if d < y - x: d = y - x p, q = x, y if d: return [p + 1, q] else: return [-1] for _ in range(int(input())): print(*f())
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 BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR WHILE BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR IF VAR RETURN LIST BIN_OP VAR NUMBER VAR RETURN LIST NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL 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 ATM. Otherwise, the student withdraws $|a_i|$ rubles. In the beginning, the ATM is turned off and an arbitrary number of students are not served. At some point, Polycarp turns on the ATM, which has an initial amount of $s$ rubles. Then, the remaining students start queueing at the ATM. If at some point in time there is less money in the ATM than the student wants to withdraw, then the student is not served and Polycarp turns off the ATM and does not turn it on anymore. More formally, the students that are served are forming a contiguous subsequence. Polycarp wants the ATM to serve the maximum number of students. Help him in this matter. Print the numbers of the first and last student, or determine that he will not be able to serve anyone. In other words, find such a longest continuous segment of students that, starting with the sum of $s$ at the ATM, all these students will be served. ATM serves students consistently (i.e. one after another in the order of the queue). -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) β€” the number of test cases. Each test case consists of two lines. The first one contains integers $n$ and $s$ ($1 \le n \le 2\cdot10^5$; $0 \le s \le 10^9$) β€” the length of the $a$ array and the initial amount of rubles in the ATM. The second contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$) β€” elements of the $a$ array. Note that $a_i$ can be zero. It is guaranteed that the sum of the values $n$ over all test cases does not exceed $2\cdot10^5$. -----Output----- Print $t$ lines, each line must contain the answer to the corresponding set of input data: if the answer exists, print the numbers of the first and last served student. If there is no solution, then print -1 on the line. If there are several possible answers, print any. -----Examples----- Input 3 4 10 -16 2 -6 8 3 1000 -100000 -100000 -100000 6 0 2 6 -164 1 -1 -6543 Output 2 4 -1 1 2 -----Note----- In the first test case, the only correct answer is 2 4, since when serving students, the number of rubles at the ATM does not become negative, and this is the maximum number of students that can be served. In the second test case, the answer is -1, as there is not enough money for any student at the ATM. In the third test case, the answer can be either 1 2 or 4 5.
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 else: atm -= a[i] i += 1 if ans < j - i: ans = j - i L, R = i + 1, j if L > R: printer.append("-1") else: printer.append(str(L) + " " + str(R)) print("\n".join(printer))
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 VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING 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 ATM. Otherwise, the student withdraws $|a_i|$ rubles. In the beginning, the ATM is turned off and an arbitrary number of students are not served. At some point, Polycarp turns on the ATM, which has an initial amount of $s$ rubles. Then, the remaining students start queueing at the ATM. If at some point in time there is less money in the ATM than the student wants to withdraw, then the student is not served and Polycarp turns off the ATM and does not turn it on anymore. More formally, the students that are served are forming a contiguous subsequence. Polycarp wants the ATM to serve the maximum number of students. Help him in this matter. Print the numbers of the first and last student, or determine that he will not be able to serve anyone. In other words, find such a longest continuous segment of students that, starting with the sum of $s$ at the ATM, all these students will be served. ATM serves students consistently (i.e. one after another in the order of the queue). -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) β€” the number of test cases. Each test case consists of two lines. The first one contains integers $n$ and $s$ ($1 \le n \le 2\cdot10^5$; $0 \le s \le 10^9$) β€” the length of the $a$ array and the initial amount of rubles in the ATM. The second contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$) β€” elements of the $a$ array. Note that $a_i$ can be zero. It is guaranteed that the sum of the values $n$ over all test cases does not exceed $2\cdot10^5$. -----Output----- Print $t$ lines, each line must contain the answer to the corresponding set of input data: if the answer exists, print the numbers of the first and last served student. If there is no solution, then print -1 on the line. If there are several possible answers, print any. -----Examples----- Input 3 4 10 -16 2 -6 8 3 1000 -100000 -100000 -100000 6 0 2 6 -164 1 -1 -6543 Output 2 4 -1 1 2 -----Note----- In the first test case, the only correct answer is 2 4, since when serving students, the number of rubles at the ATM does not become negative, and this is the maximum number of students that can be served. In the second test case, the answer is -1, as there is not enough money for any student at the ATM. In the third test case, the answer can be either 1 2 or 4 5.
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 += arr[right] right += 1 else: if right - left > ans[0]: ans[0] = right - left ans[1] = left ans[2] = right - 1 if left < right: s -= arr[left] left += 1 else: left += 1 right += 1 while left < right: if right - left > ans[0]: ans[0] = right - left ans[1] = left ans[2] = right - 1 if left < right: s -= arr[left] left += 1 else: left += 1 right += 1 if ans[0]: print(ans[1] + 1, ans[2] + 1) else: print(-1)
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 VAR NUMBER VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL 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 ATM. Otherwise, the student withdraws $|a_i|$ rubles. In the beginning, the ATM is turned off and an arbitrary number of students are not served. At some point, Polycarp turns on the ATM, which has an initial amount of $s$ rubles. Then, the remaining students start queueing at the ATM. If at some point in time there is less money in the ATM than the student wants to withdraw, then the student is not served and Polycarp turns off the ATM and does not turn it on anymore. More formally, the students that are served are forming a contiguous subsequence. Polycarp wants the ATM to serve the maximum number of students. Help him in this matter. Print the numbers of the first and last student, or determine that he will not be able to serve anyone. In other words, find such a longest continuous segment of students that, starting with the sum of $s$ at the ATM, all these students will be served. ATM serves students consistently (i.e. one after another in the order of the queue). -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) β€” the number of test cases. Each test case consists of two lines. The first one contains integers $n$ and $s$ ($1 \le n \le 2\cdot10^5$; $0 \le s \le 10^9$) β€” the length of the $a$ array and the initial amount of rubles in the ATM. The second contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$) β€” elements of the $a$ array. Note that $a_i$ can be zero. It is guaranteed that the sum of the values $n$ over all test cases does not exceed $2\cdot10^5$. -----Output----- Print $t$ lines, each line must contain the answer to the corresponding set of input data: if the answer exists, print the numbers of the first and last served student. If there is no solution, then print -1 on the line. If there are several possible answers, print any. -----Examples----- Input 3 4 10 -16 2 -6 8 3 1000 -100000 -100000 -100000 6 0 2 6 -164 1 -1 -6543 Output 2 4 -1 1 2 -----Note----- In the first test case, the only correct answer is 2 4, since when serving students, the number of rubles at the ATM does not become negative, and this is the maximum number of students that can be served. In the second test case, the answer is -1, as there is not enough money for any student at the ATM. In the third test case, the answer can be either 1 2 or 4 5.
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: pass elif ans < r - l + 1: ans = r - l + 1 res = [l, r] if ans == -1: print(ans) else: print(res[0] + 1, res[1] + 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 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 VAR VAR VAR VAR NUMBER IF VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR LIST VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER 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 ATM. Otherwise, the student withdraws $|a_i|$ rubles. In the beginning, the ATM is turned off and an arbitrary number of students are not served. At some point, Polycarp turns on the ATM, which has an initial amount of $s$ rubles. Then, the remaining students start queueing at the ATM. If at some point in time there is less money in the ATM than the student wants to withdraw, then the student is not served and Polycarp turns off the ATM and does not turn it on anymore. More formally, the students that are served are forming a contiguous subsequence. Polycarp wants the ATM to serve the maximum number of students. Help him in this matter. Print the numbers of the first and last student, or determine that he will not be able to serve anyone. In other words, find such a longest continuous segment of students that, starting with the sum of $s$ at the ATM, all these students will be served. ATM serves students consistently (i.e. one after another in the order of the queue). -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) β€” the number of test cases. Each test case consists of two lines. The first one contains integers $n$ and $s$ ($1 \le n \le 2\cdot10^5$; $0 \le s \le 10^9$) β€” the length of the $a$ array and the initial amount of rubles in the ATM. The second contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$) β€” elements of the $a$ array. Note that $a_i$ can be zero. It is guaranteed that the sum of the values $n$ over all test cases does not exceed $2\cdot10^5$. -----Output----- Print $t$ lines, each line must contain the answer to the corresponding set of input data: if the answer exists, print the numbers of the first and last served student. If there is no solution, then print -1 on the line. If there are several possible answers, print any. -----Examples----- Input 3 4 10 -16 2 -6 8 3 1000 -100000 -100000 -100000 6 0 2 6 -164 1 -1 -6543 Output 2 4 -1 1 2 -----Note----- In the first test case, the only correct answer is 2 4, since when serving students, the number of rubles at the ATM does not become negative, and this is the maximum number of students that can be served. In the second test case, the answer is -1, as there is not enough money for any student at the ATM. In the third test case, the answer can be either 1 2 or 4 5.
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 t += a[e] w = min(w, t) e += 1 else: w = t = t - a[b] b += 1
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_OP VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR 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 ATM. Otherwise, the student withdraws $|a_i|$ rubles. In the beginning, the ATM is turned off and an arbitrary number of students are not served. At some point, Polycarp turns on the ATM, which has an initial amount of $s$ rubles. Then, the remaining students start queueing at the ATM. If at some point in time there is less money in the ATM than the student wants to withdraw, then the student is not served and Polycarp turns off the ATM and does not turn it on anymore. More formally, the students that are served are forming a contiguous subsequence. Polycarp wants the ATM to serve the maximum number of students. Help him in this matter. Print the numbers of the first and last student, or determine that he will not be able to serve anyone. In other words, find such a longest continuous segment of students that, starting with the sum of $s$ at the ATM, all these students will be served. ATM serves students consistently (i.e. one after another in the order of the queue). -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) β€” the number of test cases. Each test case consists of two lines. The first one contains integers $n$ and $s$ ($1 \le n \le 2\cdot10^5$; $0 \le s \le 10^9$) β€” the length of the $a$ array and the initial amount of rubles in the ATM. The second contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$) β€” elements of the $a$ array. Note that $a_i$ can be zero. It is guaranteed that the sum of the values $n$ over all test cases does not exceed $2\cdot10^5$. -----Output----- Print $t$ lines, each line must contain the answer to the corresponding set of input data: if the answer exists, print the numbers of the first and last served student. If there is no solution, then print -1 on the line. If there are several possible answers, print any. -----Examples----- Input 3 4 10 -16 2 -6 8 3 1000 -100000 -100000 -100000 6 0 2 6 -164 1 -1 -6543 Output 2 4 -1 1 2 -----Note----- In the first test case, the only correct answer is 2 4, since when serving students, the number of rubles at the ATM does not become negative, and this is the maximum number of students that can be served. In the second test case, the answer is -1, as there is not enough money for any student at the ATM. In the third test case, the answer can be either 1 2 or 4 5.
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 while subarray_sum > k: subarray_sum -= s[subarray_start] subarray_start += 1 if subarray_end - subarray_start > max_len: max_len = subarray_end - subarray_start st = subarray_start e = subarray_end if st == 1 and e == 1: print(-1) else: print(st + 1, e)
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 FOR VAR VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER 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 ATM. Otherwise, the student withdraws $|a_i|$ rubles. In the beginning, the ATM is turned off and an arbitrary number of students are not served. At some point, Polycarp turns on the ATM, which has an initial amount of $s$ rubles. Then, the remaining students start queueing at the ATM. If at some point in time there is less money in the ATM than the student wants to withdraw, then the student is not served and Polycarp turns off the ATM and does not turn it on anymore. More formally, the students that are served are forming a contiguous subsequence. Polycarp wants the ATM to serve the maximum number of students. Help him in this matter. Print the numbers of the first and last student, or determine that he will not be able to serve anyone. In other words, find such a longest continuous segment of students that, starting with the sum of $s$ at the ATM, all these students will be served. ATM serves students consistently (i.e. one after another in the order of the queue). -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) β€” the number of test cases. Each test case consists of two lines. The first one contains integers $n$ and $s$ ($1 \le n \le 2\cdot10^5$; $0 \le s \le 10^9$) β€” the length of the $a$ array and the initial amount of rubles in the ATM. The second contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$) β€” elements of the $a$ array. Note that $a_i$ can be zero. It is guaranteed that the sum of the values $n$ over all test cases does not exceed $2\cdot10^5$. -----Output----- Print $t$ lines, each line must contain the answer to the corresponding set of input data: if the answer exists, print the numbers of the first and last served student. If there is no solution, then print -1 on the line. If there are several possible answers, print any. -----Examples----- Input 3 4 10 -16 2 -6 8 3 1000 -100000 -100000 -100000 6 0 2 6 -164 1 -1 -6543 Output 2 4 -1 1 2 -----Note----- In the first test case, the only correct answer is 2 4, since when serving students, the number of rubles at the ATM does not become negative, and this is the maximum number of students that can be served. In the second test case, the answer is -1, as there is not enough money for any student at the ATM. In the third test case, the answer can be either 1 2 or 4 5.
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: break cs += a[j] j += 1 continue cs = cs - a[i] i += 1 print(*ans)
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 VAR BIN_OP VAR VAR ASSIGN VAR LIST BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL 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 ATM. Otherwise, the student withdraws $|a_i|$ rubles. In the beginning, the ATM is turned off and an arbitrary number of students are not served. At some point, Polycarp turns on the ATM, which has an initial amount of $s$ rubles. Then, the remaining students start queueing at the ATM. If at some point in time there is less money in the ATM than the student wants to withdraw, then the student is not served and Polycarp turns off the ATM and does not turn it on anymore. More formally, the students that are served are forming a contiguous subsequence. Polycarp wants the ATM to serve the maximum number of students. Help him in this matter. Print the numbers of the first and last student, or determine that he will not be able to serve anyone. In other words, find such a longest continuous segment of students that, starting with the sum of $s$ at the ATM, all these students will be served. ATM serves students consistently (i.e. one after another in the order of the queue). -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) β€” the number of test cases. Each test case consists of two lines. The first one contains integers $n$ and $s$ ($1 \le n \le 2\cdot10^5$; $0 \le s \le 10^9$) β€” the length of the $a$ array and the initial amount of rubles in the ATM. The second contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$) β€” elements of the $a$ array. Note that $a_i$ can be zero. It is guaranteed that the sum of the values $n$ over all test cases does not exceed $2\cdot10^5$. -----Output----- Print $t$ lines, each line must contain the answer to the corresponding set of input data: if the answer exists, print the numbers of the first and last served student. If there is no solution, then print -1 on the line. If there are several possible answers, print any. -----Examples----- Input 3 4 10 -16 2 -6 8 3 1000 -100000 -100000 -100000 6 0 2 6 -164 1 -1 -6543 Output 2 4 -1 1 2 -----Note----- In the first test case, the only correct answer is 2 4, since when serving students, the number of rubles at the ATM does not become negative, and this is the maximum number of students that can be served. In the second test case, the answer is -1, as there is not enough money for any student at the ATM. In the third test case, the answer can be either 1 2 or 4 5.
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 while j < n: while j < n and s + arr[j] >= 0: s += arr[j] j += 1 if j - i > r - l: l = i r = j if j < n: while i <= j and s + arr[j] < 0: s -= arr[i] i += 1 if l + 1 <= r: print(l + 1, r) else: print("-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 ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR WHILE VAR VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR WHILE VAR VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING
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 published during a particular time period. It is obvious that if the books differ much in size, the visitors will not like it. That was why the organizers came to the opinion, that the difference between the highest and the lowest books in the exposition should be not more than k millimeters. The library has n volumes of books by Berlbury, arranged in chronological order of their appearance. The height of each book in millimeters is know, it is hi. As Berlbury is highly respected in the city, the organizers want to include into the exposition as many books as possible, and to find out what periods of his creative work they will manage to cover. You are asked to help the organizers cope with this hard task. Input The first line of the input data contains two integer numbers separated by a space n (1 ≀ n ≀ 105) and k (0 ≀ k ≀ 106) β€” the amount of books by Berlbury in the library, and the maximum allowed height difference between the lowest and the highest books. The second line contains n integer numbers separated by a space. Each number hi (1 ≀ hi ≀ 106) is the height of the i-th book in millimeters. Output In the first line of the output data print two numbers a and b (separate them by a space), where a is the maximum amount of books the organizers can include into the exposition, and b β€” the amount of the time periods, during which Berlbury published a books, and the height difference between the lowest and the highest among these books is not more than k milllimeters. In each of the following b lines print two integer numbers separated by a space β€” indexes of the first and the last volumes from each of the required time periods of Berlbury's creative work. Examples Input 3 3 14 12 10 Output 2 2 1 2 2 3 Input 2 0 10 10 Output 2 1 1 2 Input 4 5 8 19 10 13 Output 2 1 3 4
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 k = 0 while d + e > b: k = k + 1 if k == 1: if len(length) > 0 and i - n > length[0][1]: length.clear() length.append([n, i - n]) if len(length) > 0 and i - n < length[0][1]: del length[-1] if c[i] > c[g2] and k == 1: n = h1 h1 = n f = c[n] e = 0 d = c[i] - c[n] g2 = g1 if c[i] < c[h2] and k == 1: n = g1 g1 = n f = c[n] d = 0 e = c[n] - c[i] h2 = h1 if k > 1: n = n + 1 f = c[n] h1 = max(h1, n) g1 = max(g1, n) d = c[g1] - f e = f - c[h1] if not d + e > b: if len(length) > 0 and len(c) - n > length[0][1]: length.clear() length.append([n, len(c) - n]) if len(length) > 0 and len(c) - n < length[0][1]: del length[-1] print(length[0][1], len(length)) k = length[0][1] for i in range(len(length)): print(length[i][0] + 1, length[i][0] + k)
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 BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER IF FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR BIN_OP FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER 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 published during a particular time period. It is obvious that if the books differ much in size, the visitors will not like it. That was why the organizers came to the opinion, that the difference between the highest and the lowest books in the exposition should be not more than k millimeters. The library has n volumes of books by Berlbury, arranged in chronological order of their appearance. The height of each book in millimeters is know, it is hi. As Berlbury is highly respected in the city, the organizers want to include into the exposition as many books as possible, and to find out what periods of his creative work they will manage to cover. You are asked to help the organizers cope with this hard task. Input The first line of the input data contains two integer numbers separated by a space n (1 ≀ n ≀ 105) and k (0 ≀ k ≀ 106) β€” the amount of books by Berlbury in the library, and the maximum allowed height difference between the lowest and the highest books. The second line contains n integer numbers separated by a space. Each number hi (1 ≀ hi ≀ 106) is the height of the i-th book in millimeters. Output In the first line of the output data print two numbers a and b (separate them by a space), where a is the maximum amount of books the organizers can include into the exposition, and b β€” the amount of the time periods, during which Berlbury published a books, and the height difference between the lowest and the highest among these books is not more than k milllimeters. In each of the following b lines print two integer numbers separated by a space β€” indexes of the first and the last volumes from each of the required time periods of Berlbury's creative work. Examples Input 3 3 14 12 10 Output 2 2 1 2 2 3 Input 2 0 10 10 Output 2 1 1 2 Input 4 5 8 19 10 13 Output 2 1 3 4
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: i = min(u[a], v[c]) + 1 if u[a] < v[c]: a += 1 else: c += 1 p = j - i if q < p: q, l = p, [i] elif q == p: l.append(i) print(q + 1, len(l)) for i in l: print(i + 1, i + q + 1)
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 VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR WHILE BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR VAR LIST VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER
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 published during a particular time period. It is obvious that if the books differ much in size, the visitors will not like it. That was why the organizers came to the opinion, that the difference between the highest and the lowest books in the exposition should be not more than k millimeters. The library has n volumes of books by Berlbury, arranged in chronological order of their appearance. The height of each book in millimeters is know, it is hi. As Berlbury is highly respected in the city, the organizers want to include into the exposition as many books as possible, and to find out what periods of his creative work they will manage to cover. You are asked to help the organizers cope with this hard task. Input The first line of the input data contains two integer numbers separated by a space n (1 ≀ n ≀ 105) and k (0 ≀ k ≀ 106) β€” the amount of books by Berlbury in the library, and the maximum allowed height difference between the lowest and the highest books. The second line contains n integer numbers separated by a space. Each number hi (1 ≀ hi ≀ 106) is the height of the i-th book in millimeters. Output In the first line of the output data print two numbers a and b (separate them by a space), where a is the maximum amount of books the organizers can include into the exposition, and b β€” the amount of the time periods, during which Berlbury published a books, and the height difference between the lowest and the highest among these books is not more than k milllimeters. In each of the following b lines print two integer numbers separated by a space β€” indexes of the first and the last volumes from each of the required time periods of Berlbury's creative work. Examples Input 3 3 14 12 10 Output 2 2 1 2 2 3 Input 2 0 10 10 Output 2 1 1 2 Input 4 5 8 19 10 13 Output 2 1 3 4
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() l.append([i, h[i]]) while len(m) > 0 and m[-1][1] >= h[i]: m.pop() m.append([i, h[i]]) while f(): b += 1 if i - b + 1 > a: a = i - b + 1 ans = [i] elif i - b + 1 == a: ans.append(i) print(a, len(ans)) for i in ans: print(i - a + 2, i + 1)
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 RETURN BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR WHILE FUNC_CALL VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR LIST VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER
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 published during a particular time period. It is obvious that if the books differ much in size, the visitors will not like it. That was why the organizers came to the opinion, that the difference between the highest and the lowest books in the exposition should be not more than k millimeters. The library has n volumes of books by Berlbury, arranged in chronological order of their appearance. The height of each book in millimeters is know, it is hi. As Berlbury is highly respected in the city, the organizers want to include into the exposition as many books as possible, and to find out what periods of his creative work they will manage to cover. You are asked to help the organizers cope with this hard task. Input The first line of the input data contains two integer numbers separated by a space n (1 ≀ n ≀ 105) and k (0 ≀ k ≀ 106) β€” the amount of books by Berlbury in the library, and the maximum allowed height difference between the lowest and the highest books. The second line contains n integer numbers separated by a space. Each number hi (1 ≀ hi ≀ 106) is the height of the i-th book in millimeters. Output In the first line of the output data print two numbers a and b (separate them by a space), where a is the maximum amount of books the organizers can include into the exposition, and b β€” the amount of the time periods, during which Berlbury published a books, and the height difference between the lowest and the highest among these books is not more than k milllimeters. In each of the following b lines print two integer numbers separated by a space β€” indexes of the first and the last volumes from each of the required time periods of Berlbury's creative work. Examples Input 3 3 14 12 10 Output 2 2 1 2 2 3 Input 2 0 10 10 Output 2 1 1 2 Input 4 5 8 19 10 13 Output 2 1 3 4
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[-1] < int(h[end]): max.pop() if len(max) == 0: break max.append(int(h[end])) while min[-1] > int(h[end]): min.pop() if len(min) == 0: break min.append(int(h[end])) while max[0] - min[0] > k: if max[0] == int(h[front]): max.pop(0) if min[0] == int(h[front]): min.pop(0) front += 1 if max[0] - min[0] <= k: if end - front + 1 >= size: size = end - front + 1 record.append(size) index1.append(end) index2.append(front) for j in range(len(record)): if record[j] == size: time += 1 index3.append(index1[j]) index4.append(index2[j]) print(size, time) lent3 = len(index3) for zz in range(lent3): print(index4[zz] + 1, index3[zz] + 1)
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 LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR WHILE VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR WHILE BIN_OP VAR NUMBER VAR NUMBER VAR IF VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER
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 published during a particular time period. It is obvious that if the books differ much in size, the visitors will not like it. That was why the organizers came to the opinion, that the difference between the highest and the lowest books in the exposition should be not more than k millimeters. The library has n volumes of books by Berlbury, arranged in chronological order of their appearance. The height of each book in millimeters is know, it is hi. As Berlbury is highly respected in the city, the organizers want to include into the exposition as many books as possible, and to find out what periods of his creative work they will manage to cover. You are asked to help the organizers cope with this hard task. Input The first line of the input data contains two integer numbers separated by a space n (1 ≀ n ≀ 105) and k (0 ≀ k ≀ 106) β€” the amount of books by Berlbury in the library, and the maximum allowed height difference between the lowest and the highest books. The second line contains n integer numbers separated by a space. Each number hi (1 ≀ hi ≀ 106) is the height of the i-th book in millimeters. Output In the first line of the output data print two numbers a and b (separate them by a space), where a is the maximum amount of books the organizers can include into the exposition, and b β€” the amount of the time periods, during which Berlbury published a books, and the height difference between the lowest and the highest among these books is not more than k milllimeters. In each of the following b lines print two integer numbers separated by a space β€” indexes of the first and the last volumes from each of the required time periods of Berlbury's creative work. Examples Input 3 3 14 12 10 Output 2 2 1 2 2 3 Input 2 0 10 10 Output 2 1 1 2 Input 4 5 8 19 10 13 Output 2 1 3 4
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.append((i, x)) k = min(k, len(maxq) - 1) while maxq[k][1] - minq[j][1] > m: y, z = minq[j][0], maxq[k][0] if y <= z: j += 1 if z <= y: k += 1 l = max(0 if j == 0 else minq[j - 1][0] + 1, 0 if k == 0 else maxq[k - 1][0] + 1) if i - l + 1 > ans: ans = i - l + 1 res = [(l + 1, i + 1)] elif i - l + 1 == ans: res.append((l + 1, i + 1)) print(ans, len(res)) for r in res: print(" ".join(map(str, r)))
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 VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL 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 published during a particular time period. It is obvious that if the books differ much in size, the visitors will not like it. That was why the organizers came to the opinion, that the difference between the highest and the lowest books in the exposition should be not more than k millimeters. The library has n volumes of books by Berlbury, arranged in chronological order of their appearance. The height of each book in millimeters is know, it is hi. As Berlbury is highly respected in the city, the organizers want to include into the exposition as many books as possible, and to find out what periods of his creative work they will manage to cover. You are asked to help the organizers cope with this hard task. Input The first line of the input data contains two integer numbers separated by a space n (1 ≀ n ≀ 105) and k (0 ≀ k ≀ 106) β€” the amount of books by Berlbury in the library, and the maximum allowed height difference between the lowest and the highest books. The second line contains n integer numbers separated by a space. Each number hi (1 ≀ hi ≀ 106) is the height of the i-th book in millimeters. Output In the first line of the output data print two numbers a and b (separate them by a space), where a is the maximum amount of books the organizers can include into the exposition, and b β€” the amount of the time periods, during which Berlbury published a books, and the height difference between the lowest and the highest among these books is not more than k milllimeters. In each of the following b lines print two integer numbers separated by a space β€” indexes of the first and the last volumes from each of the required time periods of Berlbury's creative work. Examples Input 3 3 14 12 10 Output 2 2 1 2 2 3 Input 2 0 10 10 Output 2 1 1 2 Input 4 5 8 19 10 13 Output 2 1 3 4
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]: s.pop() h2[i] = s[-1] if s else None s.append(i) z = [] a, b = 0, 0 mn, mx = 0, 0 while b < n: if h[b] < h[mn]: mn = b if h[b] > h[mx]: mx = b while h[mx] - h[mn] > k: if a == mn: mn += 1 while h1[mn] and h1[mn] <= b: mn = h1[mn] if a == mx: mx += 1 while h2[mx] and h2[mx] <= b: mx = h2[mx] a += 1 if not z or b - a > z[0][1] - z[0][0]: z = [(a, b)] elif b - a == z[0][1] - z[0][0]: z.append((a, b)) b += 1 print(z[0][1] - z[0][0] + 1, len(z)) for x in z: print(x[0] + 1, x[1] + 1)
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 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 ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR WHILE BIN_OP VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR LIST VAR VAR IF BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER
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 published during a particular time period. It is obvious that if the books differ much in size, the visitors will not like it. That was why the organizers came to the opinion, that the difference between the highest and the lowest books in the exposition should be not more than k millimeters. The library has n volumes of books by Berlbury, arranged in chronological order of their appearance. The height of each book in millimeters is know, it is hi. As Berlbury is highly respected in the city, the organizers want to include into the exposition as many books as possible, and to find out what periods of his creative work they will manage to cover. You are asked to help the organizers cope with this hard task. Input The first line of the input data contains two integer numbers separated by a space n (1 ≀ n ≀ 105) and k (0 ≀ k ≀ 106) β€” the amount of books by Berlbury in the library, and the maximum allowed height difference between the lowest and the highest books. The second line contains n integer numbers separated by a space. Each number hi (1 ≀ hi ≀ 106) is the height of the i-th book in millimeters. Output In the first line of the output data print two numbers a and b (separate them by a space), where a is the maximum amount of books the organizers can include into the exposition, and b β€” the amount of the time periods, during which Berlbury published a books, and the height difference between the lowest and the highest among these books is not more than k milllimeters. In each of the following b lines print two integer numbers separated by a space β€” indexes of the first and the last volumes from each of the required time periods of Berlbury's creative work. Examples Input 3 3 14 12 10 Output 2 2 1 2 2 3 Input 2 0 10 10 Output 2 1 1 2 Input 4 5 8 19 10 13 Output 2 1 3 4
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 books[dec[0]] - books[inc[0]] > diff: if dec[0] < inc[0]: j = dec.pop(0) + 1 else: j = inc.pop(0) + 1 if i - j + 1 > ml: ml = i - j + 1 res = [] if i - j + 1 == ml: res.append((j, i)) print(ml, len(res)) for i, j in res: print(i + 1, j + 1)
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 NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR LIST IF BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER
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 published during a particular time period. It is obvious that if the books differ much in size, the visitors will not like it. That was why the organizers came to the opinion, that the difference between the highest and the lowest books in the exposition should be not more than k millimeters. The library has n volumes of books by Berlbury, arranged in chronological order of their appearance. The height of each book in millimeters is know, it is hi. As Berlbury is highly respected in the city, the organizers want to include into the exposition as many books as possible, and to find out what periods of his creative work they will manage to cover. You are asked to help the organizers cope with this hard task. Input The first line of the input data contains two integer numbers separated by a space n (1 ≀ n ≀ 105) and k (0 ≀ k ≀ 106) β€” the amount of books by Berlbury in the library, and the maximum allowed height difference between the lowest and the highest books. The second line contains n integer numbers separated by a space. Each number hi (1 ≀ hi ≀ 106) is the height of the i-th book in millimeters. Output In the first line of the output data print two numbers a and b (separate them by a space), where a is the maximum amount of books the organizers can include into the exposition, and b β€” the amount of the time periods, during which Berlbury published a books, and the height difference between the lowest and the highest among these books is not more than k milllimeters. In each of the following b lines print two integer numbers separated by a space β€” indexes of the first and the last volumes from each of the required time periods of Berlbury's creative work. Examples Input 3 3 14 12 10 Output 2 2 1 2 2 3 Input 2 0 10 10 Output 2 1 1 2 Input 4 5 8 19 10 13 Output 2 1 3 4
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])) while ma[0][1] - mi[0][1] > k: j += 1 if ma[0][0] < j: del ma[0] if mi[0][0] < j: del mi[0] if i - j + 1 > a: a = i - j + 1 choice = [[j + 1, i + 1]] elif i - j + 1 == a: choice.append([j + 1, i + 1]) i += 1 print(a, len(choice)) for i in range(len(choice)): print(choice[i][0], choice[i][1])
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 VAR WHILE FUNC_CALL VAR VAR VAR VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER VAR VAR NUMBER IF VAR NUMBER NUMBER VAR VAR NUMBER IF VAR NUMBER NUMBER VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR LIST LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR 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_2, t_2, ..., s_k, t_k that satisfy the following conditions: 1. If we write the strings s_1, s_2, ..., s_k in order, the resulting string will be equal to s; 2. If we write the strings t_1, t_2, ..., t_k in order, the resulting string will be equal to t; 3. For all integers i between 1 and k inclusive, s_i and t_i are anagrams of each other. If such strings don't exist, then t is said to be an irreducible anagram of s. Note that these notions are only defined when s and t are anagrams of each other. For example, consider the string s = "gamegame". Then the string t = "megamage" is a reducible anagram of s, we may choose for example s_1 = "game", s_2 = "gam", s_3 = "e" and t_1 = "mega", t_2 = "mag", t_3 = "e": <image> On the other hand, we can prove that t = "memegaga" is an irreducible anagram of s. You will be given a string s and q queries, represented by two integers 1 ≀ l ≀ r ≀ |s| (where |s| is equal to the length of the string s). For each query, you should find if the substring of s formed by characters from the l-th to the r-th has at least one irreducible anagram. Input The first line contains a string s, consisting of lowercase English characters (1 ≀ |s| ≀ 2 β‹… 10^5). The second line contains a single integer q (1 ≀ q ≀ 10^5) β€” the number of queries. Each of the following q lines contain two integers l and r (1 ≀ l ≀ r ≀ |s|), representing a query for the substring of s formed by characters from the l-th to the r-th. Output For each query, print a single line containing "Yes" (without quotes) if the corresponding substring has at least one irreducible anagram, and a single line containing "No" (without quotes) otherwise. Examples Input aaaaa 3 1 1 2 4 5 5 Output Yes No Yes Input aabbbbbbc 6 1 2 2 4 2 2 1 9 5 7 3 5 Output No Yes Yes Yes No No Note In the first sample, in the first and third queries, the substring is "a", which has itself as an irreducible anagram since two or more non-empty strings cannot be put together to obtain "a". On the other hand, in the second query, the substring is "aaa", which has no irreducible anagrams: its only anagram is itself, and we may choose s_1 = "a", s_2 = "aa", t_1 = "a", t_2 = "aa" to show that it is a reducible anagram. In the second query of the second sample, the substring is "abb", which has, for example, "bba" as an irreducible anagram.
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 = mp[r - 1][i] if l > 1: t -= mp[l - 2][i] if t: sc += 1 if s[l - 1] != s[r - 1] or l == r or sc >= 3: print("Yes") else: print("No")
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_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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_2, t_2, ..., s_k, t_k that satisfy the following conditions: 1. If we write the strings s_1, s_2, ..., s_k in order, the resulting string will be equal to s; 2. If we write the strings t_1, t_2, ..., t_k in order, the resulting string will be equal to t; 3. For all integers i between 1 and k inclusive, s_i and t_i are anagrams of each other. If such strings don't exist, then t is said to be an irreducible anagram of s. Note that these notions are only defined when s and t are anagrams of each other. For example, consider the string s = "gamegame". Then the string t = "megamage" is a reducible anagram of s, we may choose for example s_1 = "game", s_2 = "gam", s_3 = "e" and t_1 = "mega", t_2 = "mag", t_3 = "e": <image> On the other hand, we can prove that t = "memegaga" is an irreducible anagram of s. You will be given a string s and q queries, represented by two integers 1 ≀ l ≀ r ≀ |s| (where |s| is equal to the length of the string s). For each query, you should find if the substring of s formed by characters from the l-th to the r-th has at least one irreducible anagram. Input The first line contains a string s, consisting of lowercase English characters (1 ≀ |s| ≀ 2 β‹… 10^5). The second line contains a single integer q (1 ≀ q ≀ 10^5) β€” the number of queries. Each of the following q lines contain two integers l and r (1 ≀ l ≀ r ≀ |s|), representing a query for the substring of s formed by characters from the l-th to the r-th. Output For each query, print a single line containing "Yes" (without quotes) if the corresponding substring has at least one irreducible anagram, and a single line containing "No" (without quotes) otherwise. Examples Input aaaaa 3 1 1 2 4 5 5 Output Yes No Yes Input aabbbbbbc 6 1 2 2 4 2 2 1 9 5 7 3 5 Output No Yes Yes Yes No No Note In the first sample, in the first and third queries, the substring is "a", which has itself as an irreducible anagram since two or more non-empty strings cannot be put together to obtain "a". On the other hand, in the second query, the substring is "aaa", which has no irreducible anagrams: its only anagram is itself, and we may choose s_1 = "a", s_2 = "aa", t_1 = "a", t_2 = "aa" to show that it is a reducible anagram. In the second query of the second sample, the substring is "abb", which has, for example, "bba" as an irreducible anagram.
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, r = map(int, input().split()) if l == r: print("Yes") continue count = 0 for i in range(26): if m[l - 1][i] != m[r][i]: count += 1 if count == 1: print("No") elif count >= 3: print("Yes") elif s[l - 1] == s[r - 1]: print("No") else: print("Yes")
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 NUMBER VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR 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 IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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_2, t_2, ..., s_k, t_k that satisfy the following conditions: 1. If we write the strings s_1, s_2, ..., s_k in order, the resulting string will be equal to s; 2. If we write the strings t_1, t_2, ..., t_k in order, the resulting string will be equal to t; 3. For all integers i between 1 and k inclusive, s_i and t_i are anagrams of each other. If such strings don't exist, then t is said to be an irreducible anagram of s. Note that these notions are only defined when s and t are anagrams of each other. For example, consider the string s = "gamegame". Then the string t = "megamage" is a reducible anagram of s, we may choose for example s_1 = "game", s_2 = "gam", s_3 = "e" and t_1 = "mega", t_2 = "mag", t_3 = "e": <image> On the other hand, we can prove that t = "memegaga" is an irreducible anagram of s. You will be given a string s and q queries, represented by two integers 1 ≀ l ≀ r ≀ |s| (where |s| is equal to the length of the string s). For each query, you should find if the substring of s formed by characters from the l-th to the r-th has at least one irreducible anagram. Input The first line contains a string s, consisting of lowercase English characters (1 ≀ |s| ≀ 2 β‹… 10^5). The second line contains a single integer q (1 ≀ q ≀ 10^5) β€” the number of queries. Each of the following q lines contain two integers l and r (1 ≀ l ≀ r ≀ |s|), representing a query for the substring of s formed by characters from the l-th to the r-th. Output For each query, print a single line containing "Yes" (without quotes) if the corresponding substring has at least one irreducible anagram, and a single line containing "No" (without quotes) otherwise. Examples Input aaaaa 3 1 1 2 4 5 5 Output Yes No Yes Input aabbbbbbc 6 1 2 2 4 2 2 1 9 5 7 3 5 Output No Yes Yes Yes No No Note In the first sample, in the first and third queries, the substring is "a", which has itself as an irreducible anagram since two or more non-empty strings cannot be put together to obtain "a". On the other hand, in the second query, the substring is "aaa", which has no irreducible anagrams: its only anagram is itself, and we may choose s_1 = "a", s_2 = "aa", t_1 = "a", t_2 = "aa" to show that it is a reducible anagram. In the second query of the second sample, the substring is "abb", which has, for example, "bba" as an irreducible anagram.
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: print("Yes") elif s[l - 1] != s[r - 1]: print("Yes") else: x, y = dic[l - 1], dic[r] a = [(0) for _ in range(26)] for i in range(26): a[i] = y[i] - x[i] count = 0 for i in range(26): if a[i] > 0: count += 1 if count >= 3: print("Yes") else: print("No")
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 ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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_2, t_2, ..., s_k, t_k that satisfy the following conditions: 1. If we write the strings s_1, s_2, ..., s_k in order, the resulting string will be equal to s; 2. If we write the strings t_1, t_2, ..., t_k in order, the resulting string will be equal to t; 3. For all integers i between 1 and k inclusive, s_i and t_i are anagrams of each other. If such strings don't exist, then t is said to be an irreducible anagram of s. Note that these notions are only defined when s and t are anagrams of each other. For example, consider the string s = "gamegame". Then the string t = "megamage" is a reducible anagram of s, we may choose for example s_1 = "game", s_2 = "gam", s_3 = "e" and t_1 = "mega", t_2 = "mag", t_3 = "e": <image> On the other hand, we can prove that t = "memegaga" is an irreducible anagram of s. You will be given a string s and q queries, represented by two integers 1 ≀ l ≀ r ≀ |s| (where |s| is equal to the length of the string s). For each query, you should find if the substring of s formed by characters from the l-th to the r-th has at least one irreducible anagram. Input The first line contains a string s, consisting of lowercase English characters (1 ≀ |s| ≀ 2 β‹… 10^5). The second line contains a single integer q (1 ≀ q ≀ 10^5) β€” the number of queries. Each of the following q lines contain two integers l and r (1 ≀ l ≀ r ≀ |s|), representing a query for the substring of s formed by characters from the l-th to the r-th. Output For each query, print a single line containing "Yes" (without quotes) if the corresponding substring has at least one irreducible anagram, and a single line containing "No" (without quotes) otherwise. Examples Input aaaaa 3 1 1 2 4 5 5 Output Yes No Yes Input aabbbbbbc 6 1 2 2 4 2 2 1 9 5 7 3 5 Output No Yes Yes Yes No No Note In the first sample, in the first and third queries, the substring is "a", which has itself as an irreducible anagram since two or more non-empty strings cannot be put together to obtain "a". On the other hand, in the second query, the substring is "aaa", which has no irreducible anagrams: its only anagram is itself, and we may choose s_1 = "a", s_2 = "aa", t_1 = "a", t_2 = "aa" to show that it is a reducible anagram. In the second query of the second sample, the substring is "abb", which has, for example, "bba" as an irreducible anagram.
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): if counts[l - 1][i] != counts[r][i]: cdifc += 1 if l == r: print("Yes") elif ss[l - 1] == ss[r - 1] and cdifc < 3: print("No") else: print("Yes") main()
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 VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL 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_2, t_2, ..., s_k, t_k that satisfy the following conditions: 1. If we write the strings s_1, s_2, ..., s_k in order, the resulting string will be equal to s; 2. If we write the strings t_1, t_2, ..., t_k in order, the resulting string will be equal to t; 3. For all integers i between 1 and k inclusive, s_i and t_i are anagrams of each other. If such strings don't exist, then t is said to be an irreducible anagram of s. Note that these notions are only defined when s and t are anagrams of each other. For example, consider the string s = "gamegame". Then the string t = "megamage" is a reducible anagram of s, we may choose for example s_1 = "game", s_2 = "gam", s_3 = "e" and t_1 = "mega", t_2 = "mag", t_3 = "e": <image> On the other hand, we can prove that t = "memegaga" is an irreducible anagram of s. You will be given a string s and q queries, represented by two integers 1 ≀ l ≀ r ≀ |s| (where |s| is equal to the length of the string s). For each query, you should find if the substring of s formed by characters from the l-th to the r-th has at least one irreducible anagram. Input The first line contains a string s, consisting of lowercase English characters (1 ≀ |s| ≀ 2 β‹… 10^5). The second line contains a single integer q (1 ≀ q ≀ 10^5) β€” the number of queries. Each of the following q lines contain two integers l and r (1 ≀ l ≀ r ≀ |s|), representing a query for the substring of s formed by characters from the l-th to the r-th. Output For each query, print a single line containing "Yes" (without quotes) if the corresponding substring has at least one irreducible anagram, and a single line containing "No" (without quotes) otherwise. Examples Input aaaaa 3 1 1 2 4 5 5 Output Yes No Yes Input aabbbbbbc 6 1 2 2 4 2 2 1 9 5 7 3 5 Output No Yes Yes Yes No No Note In the first sample, in the first and third queries, the substring is "a", which has itself as an irreducible anagram since two or more non-empty strings cannot be put together to obtain "a". On the other hand, in the second query, the substring is "aaa", which has no irreducible anagrams: its only anagram is itself, and we may choose s_1 = "a", s_2 = "aa", t_1 = "a", t_2 = "aa" to show that it is a reducible anagram. In the second query of the second sample, the substring is "abb", which has, for example, "bba" as an irreducible anagram.
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_inreducible(l, r): if l == r: return "Yes" non_zeroes = 0 for letter in range(26): let_count = ( prefix_letter_occurence[letter][r] - prefix_letter_occurence[letter][l - 1] ) non_zeroes += int(let_count > 0) if non_zeroes == 1: return "No" elif non_zeroes >= 3: return "Yes" elif s[l - 1] != s[r - 1]: return "Yes" else: return "No" q = int(input()) for _ in range(q): l, r = map(int, input().split()) print(has_inreducible(l, r))
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 FUNC_CALL VAR VAR NUMBER FUNC_DEF IF VAR VAR RETURN STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER RETURN STRING IF VAR NUMBER RETURN STRING IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN STRING RETURN STRING 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 EXPR FUNC_CALL VAR 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_2, t_2, ..., s_k, t_k that satisfy the following conditions: 1. If we write the strings s_1, s_2, ..., s_k in order, the resulting string will be equal to s; 2. If we write the strings t_1, t_2, ..., t_k in order, the resulting string will be equal to t; 3. For all integers i between 1 and k inclusive, s_i and t_i are anagrams of each other. If such strings don't exist, then t is said to be an irreducible anagram of s. Note that these notions are only defined when s and t are anagrams of each other. For example, consider the string s = "gamegame". Then the string t = "megamage" is a reducible anagram of s, we may choose for example s_1 = "game", s_2 = "gam", s_3 = "e" and t_1 = "mega", t_2 = "mag", t_3 = "e": <image> On the other hand, we can prove that t = "memegaga" is an irreducible anagram of s. You will be given a string s and q queries, represented by two integers 1 ≀ l ≀ r ≀ |s| (where |s| is equal to the length of the string s). For each query, you should find if the substring of s formed by characters from the l-th to the r-th has at least one irreducible anagram. Input The first line contains a string s, consisting of lowercase English characters (1 ≀ |s| ≀ 2 β‹… 10^5). The second line contains a single integer q (1 ≀ q ≀ 10^5) β€” the number of queries. Each of the following q lines contain two integers l and r (1 ≀ l ≀ r ≀ |s|), representing a query for the substring of s formed by characters from the l-th to the r-th. Output For each query, print a single line containing "Yes" (without quotes) if the corresponding substring has at least one irreducible anagram, and a single line containing "No" (without quotes) otherwise. Examples Input aaaaa 3 1 1 2 4 5 5 Output Yes No Yes Input aabbbbbbc 6 1 2 2 4 2 2 1 9 5 7 3 5 Output No Yes Yes Yes No No Note In the first sample, in the first and third queries, the substring is "a", which has itself as an irreducible anagram since two or more non-empty strings cannot be put together to obtain "a". On the other hand, in the second query, the substring is "aaa", which has no irreducible anagrams: its only anagram is itself, and we may choose s_1 = "a", s_2 = "aa", t_1 = "a", t_2 = "aa" to show that it is a reducible anagram. In the second query of the second sample, the substring is "abb", which has, for example, "bba" as an irreducible anagram.
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: if s == alp: dic[alp].append(dic[alp][-1] + 1) else: dic[alp].append(dic[alp][-1]) for l, r in Query: P = [] for alp in Alp: d = dic[alp][r + 1] - dic[alp][l] if d > 0: P.append(alp) if len(P) == 1: ok = True if l == r else False elif len(P) > 2: ok = True else: ok = True if S[l] != S[r] else False print("Yes" if ok else "No")
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 BIN_OP NUMBER NUMBER ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR LIST NUMBER FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR STRING STRING
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_2, t_2, ..., s_k, t_k that satisfy the following conditions: 1. If we write the strings s_1, s_2, ..., s_k in order, the resulting string will be equal to s; 2. If we write the strings t_1, t_2, ..., t_k in order, the resulting string will be equal to t; 3. For all integers i between 1 and k inclusive, s_i and t_i are anagrams of each other. If such strings don't exist, then t is said to be an irreducible anagram of s. Note that these notions are only defined when s and t are anagrams of each other. For example, consider the string s = "gamegame". Then the string t = "megamage" is a reducible anagram of s, we may choose for example s_1 = "game", s_2 = "gam", s_3 = "e" and t_1 = "mega", t_2 = "mag", t_3 = "e": <image> On the other hand, we can prove that t = "memegaga" is an irreducible anagram of s. You will be given a string s and q queries, represented by two integers 1 ≀ l ≀ r ≀ |s| (where |s| is equal to the length of the string s). For each query, you should find if the substring of s formed by characters from the l-th to the r-th has at least one irreducible anagram. Input The first line contains a string s, consisting of lowercase English characters (1 ≀ |s| ≀ 2 β‹… 10^5). The second line contains a single integer q (1 ≀ q ≀ 10^5) β€” the number of queries. Each of the following q lines contain two integers l and r (1 ≀ l ≀ r ≀ |s|), representing a query for the substring of s formed by characters from the l-th to the r-th. Output For each query, print a single line containing "Yes" (without quotes) if the corresponding substring has at least one irreducible anagram, and a single line containing "No" (without quotes) otherwise. Examples Input aaaaa 3 1 1 2 4 5 5 Output Yes No Yes Input aabbbbbbc 6 1 2 2 4 2 2 1 9 5 7 3 5 Output No Yes Yes Yes No No Note In the first sample, in the first and third queries, the substring is "a", which has itself as an irreducible anagram since two or more non-empty strings cannot be put together to obtain "a". On the other hand, in the second query, the substring is "aaa", which has no irreducible anagrams: its only anagram is itself, and we may choose s_1 = "a", s_2 = "aa", t_1 = "a", t_2 = "aa" to show that it is a reducible anagram. In the second query of the second sample, the substring is "abb", which has, for example, "bba" as an irreducible anagram.
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) k1 = 0 k2 = 0 for j in k: if j: k1 = j k2 += j if c > 2 or l + 1 == r or c == 2 and s[l] != s[r - 1]: print("Yes") else: print("No")
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 VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR ASSIGN VAR VAR VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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_2, t_2, ..., s_k, t_k that satisfy the following conditions: 1. If we write the strings s_1, s_2, ..., s_k in order, the resulting string will be equal to s; 2. If we write the strings t_1, t_2, ..., t_k in order, the resulting string will be equal to t; 3. For all integers i between 1 and k inclusive, s_i and t_i are anagrams of each other. If such strings don't exist, then t is said to be an irreducible anagram of s. Note that these notions are only defined when s and t are anagrams of each other. For example, consider the string s = "gamegame". Then the string t = "megamage" is a reducible anagram of s, we may choose for example s_1 = "game", s_2 = "gam", s_3 = "e" and t_1 = "mega", t_2 = "mag", t_3 = "e": <image> On the other hand, we can prove that t = "memegaga" is an irreducible anagram of s. You will be given a string s and q queries, represented by two integers 1 ≀ l ≀ r ≀ |s| (where |s| is equal to the length of the string s). For each query, you should find if the substring of s formed by characters from the l-th to the r-th has at least one irreducible anagram. Input The first line contains a string s, consisting of lowercase English characters (1 ≀ |s| ≀ 2 β‹… 10^5). The second line contains a single integer q (1 ≀ q ≀ 10^5) β€” the number of queries. Each of the following q lines contain two integers l and r (1 ≀ l ≀ r ≀ |s|), representing a query for the substring of s formed by characters from the l-th to the r-th. Output For each query, print a single line containing "Yes" (without quotes) if the corresponding substring has at least one irreducible anagram, and a single line containing "No" (without quotes) otherwise. Examples Input aaaaa 3 1 1 2 4 5 5 Output Yes No Yes Input aabbbbbbc 6 1 2 2 4 2 2 1 9 5 7 3 5 Output No Yes Yes Yes No No Note In the first sample, in the first and third queries, the substring is "a", which has itself as an irreducible anagram since two or more non-empty strings cannot be put together to obtain "a". On the other hand, in the second query, the substring is "aaa", which has no irreducible anagrams: its only anagram is itself, and we may choose s_1 = "a", s_2 = "aa", t_1 = "a", t_2 = "aa" to show that it is a reducible anagram. In the second query of the second sample, the substring is "abb", which has, for example, "bba" as an irreducible anagram.
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] = prefix_sum[i - 1][j] for case in range(q): l, r = list(map(int, input().split())) if l == r: print("Yes") continue if s[l - 1] != s[r - 1]: print("Yes") else: sum_ch = 0 for i in range(26): if prefix_sum[r][i] - prefix_sum[l - 1][i] > 0: sum_ch += 1 print("Yes" if sum_ch > 2 else "No")
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 VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER STRING STRING
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_2, t_2, ..., s_k, t_k that satisfy the following conditions: 1. If we write the strings s_1, s_2, ..., s_k in order, the resulting string will be equal to s; 2. If we write the strings t_1, t_2, ..., t_k in order, the resulting string will be equal to t; 3. For all integers i between 1 and k inclusive, s_i and t_i are anagrams of each other. If such strings don't exist, then t is said to be an irreducible anagram of s. Note that these notions are only defined when s and t are anagrams of each other. For example, consider the string s = "gamegame". Then the string t = "megamage" is a reducible anagram of s, we may choose for example s_1 = "game", s_2 = "gam", s_3 = "e" and t_1 = "mega", t_2 = "mag", t_3 = "e": <image> On the other hand, we can prove that t = "memegaga" is an irreducible anagram of s. You will be given a string s and q queries, represented by two integers 1 ≀ l ≀ r ≀ |s| (where |s| is equal to the length of the string s). For each query, you should find if the substring of s formed by characters from the l-th to the r-th has at least one irreducible anagram. Input The first line contains a string s, consisting of lowercase English characters (1 ≀ |s| ≀ 2 β‹… 10^5). The second line contains a single integer q (1 ≀ q ≀ 10^5) β€” the number of queries. Each of the following q lines contain two integers l and r (1 ≀ l ≀ r ≀ |s|), representing a query for the substring of s formed by characters from the l-th to the r-th. Output For each query, print a single line containing "Yes" (without quotes) if the corresponding substring has at least one irreducible anagram, and a single line containing "No" (without quotes) otherwise. Examples Input aaaaa 3 1 1 2 4 5 5 Output Yes No Yes Input aabbbbbbc 6 1 2 2 4 2 2 1 9 5 7 3 5 Output No Yes Yes Yes No No Note In the first sample, in the first and third queries, the substring is "a", which has itself as an irreducible anagram since two or more non-empty strings cannot be put together to obtain "a". On the other hand, in the second query, the substring is "aaa", which has no irreducible anagrams: its only anagram is itself, and we may choose s_1 = "a", s_2 = "aa", t_1 = "a", t_2 = "aa" to show that it is a reducible anagram. In the second query of the second sample, the substring is "abb", which has, for example, "bba" as an irreducible anagram.
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 _ in range(26)] for i, c in enumerate(s): pos = ord(c) - base S[pos][i] += 1 for _ in range(1, len(s)): for i in range(26): S[i][_] = S[i][_] + S[i][_ - 1] for _ in range(q): l, r = map(int, input().split()) l -= 1 r -= 1 if l == r: ans.append("Yes") elif s[r] != s[l]: ans.append("Yes") else: cnt = get(l, r) if cnt >= 3: ans.append("Yes") else: ans.append("No") print("\n".join(ans))
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 BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING 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_2, t_2, ..., s_k, t_k that satisfy the following conditions: 1. If we write the strings s_1, s_2, ..., s_k in order, the resulting string will be equal to s; 2. If we write the strings t_1, t_2, ..., t_k in order, the resulting string will be equal to t; 3. For all integers i between 1 and k inclusive, s_i and t_i are anagrams of each other. If such strings don't exist, then t is said to be an irreducible anagram of s. Note that these notions are only defined when s and t are anagrams of each other. For example, consider the string s = "gamegame". Then the string t = "megamage" is a reducible anagram of s, we may choose for example s_1 = "game", s_2 = "gam", s_3 = "e" and t_1 = "mega", t_2 = "mag", t_3 = "e": <image> On the other hand, we can prove that t = "memegaga" is an irreducible anagram of s. You will be given a string s and q queries, represented by two integers 1 ≀ l ≀ r ≀ |s| (where |s| is equal to the length of the string s). For each query, you should find if the substring of s formed by characters from the l-th to the r-th has at least one irreducible anagram. Input The first line contains a string s, consisting of lowercase English characters (1 ≀ |s| ≀ 2 β‹… 10^5). The second line contains a single integer q (1 ≀ q ≀ 10^5) β€” the number of queries. Each of the following q lines contain two integers l and r (1 ≀ l ≀ r ≀ |s|), representing a query for the substring of s formed by characters from the l-th to the r-th. Output For each query, print a single line containing "Yes" (without quotes) if the corresponding substring has at least one irreducible anagram, and a single line containing "No" (without quotes) otherwise. Examples Input aaaaa 3 1 1 2 4 5 5 Output Yes No Yes Input aabbbbbbc 6 1 2 2 4 2 2 1 9 5 7 3 5 Output No Yes Yes Yes No No Note In the first sample, in the first and third queries, the substring is "a", which has itself as an irreducible anagram since two or more non-empty strings cannot be put together to obtain "a". On the other hand, in the second query, the substring is "aaa", which has no irreducible anagrams: its only anagram is itself, and we may choose s_1 = "a", s_2 = "aa", t_1 = "a", t_2 = "aa" to show that it is a reducible anagram. In the second query of the second sample, the substring is "abb", which has, for example, "bba" as an irreducible anagram.
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 in range(m): l, r = Input() if l == r: print("Yes") else: cnt = 0 for j in range(26): if suf[r][j] - suf[l - 1][j] > 0: cnt += 1 if s[r - 1] == s[l - 1] and cnt <= 2: print("No") else: print("Yes")
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 VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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_2, t_2, ..., s_k, t_k that satisfy the following conditions: 1. If we write the strings s_1, s_2, ..., s_k in order, the resulting string will be equal to s; 2. If we write the strings t_1, t_2, ..., t_k in order, the resulting string will be equal to t; 3. For all integers i between 1 and k inclusive, s_i and t_i are anagrams of each other. If such strings don't exist, then t is said to be an irreducible anagram of s. Note that these notions are only defined when s and t are anagrams of each other. For example, consider the string s = "gamegame". Then the string t = "megamage" is a reducible anagram of s, we may choose for example s_1 = "game", s_2 = "gam", s_3 = "e" and t_1 = "mega", t_2 = "mag", t_3 = "e": <image> On the other hand, we can prove that t = "memegaga" is an irreducible anagram of s. You will be given a string s and q queries, represented by two integers 1 ≀ l ≀ r ≀ |s| (where |s| is equal to the length of the string s). For each query, you should find if the substring of s formed by characters from the l-th to the r-th has at least one irreducible anagram. Input The first line contains a string s, consisting of lowercase English characters (1 ≀ |s| ≀ 2 β‹… 10^5). The second line contains a single integer q (1 ≀ q ≀ 10^5) β€” the number of queries. Each of the following q lines contain two integers l and r (1 ≀ l ≀ r ≀ |s|), representing a query for the substring of s formed by characters from the l-th to the r-th. Output For each query, print a single line containing "Yes" (without quotes) if the corresponding substring has at least one irreducible anagram, and a single line containing "No" (without quotes) otherwise. Examples Input aaaaa 3 1 1 2 4 5 5 Output Yes No Yes Input aabbbbbbc 6 1 2 2 4 2 2 1 9 5 7 3 5 Output No Yes Yes Yes No No Note In the first sample, in the first and third queries, the substring is "a", which has itself as an irreducible anagram since two or more non-empty strings cannot be put together to obtain "a". On the other hand, in the second query, the substring is "aaa", which has no irreducible anagrams: its only anagram is itself, and we may choose s_1 = "a", s_2 = "aa", t_1 = "a", t_2 = "aa" to show that it is a reducible anagram. In the second query of the second sample, the substring is "abb", which has, for example, "bba" as an irreducible anagram.
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: print("Yes") continue else: cnt = 0 for i in range(26): if sum_[r + 1][i] - sum_[l][i] > 0: cnt += 1 if cnt >= 3: print("Yes") elif cnt == 1: print("No") elif s[r] != s[l]: print("Yes") else: print("No")
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_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR STRING NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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_2, t_2, ..., s_k, t_k that satisfy the following conditions: 1. If we write the strings s_1, s_2, ..., s_k in order, the resulting string will be equal to s; 2. If we write the strings t_1, t_2, ..., t_k in order, the resulting string will be equal to t; 3. For all integers i between 1 and k inclusive, s_i and t_i are anagrams of each other. If such strings don't exist, then t is said to be an irreducible anagram of s. Note that these notions are only defined when s and t are anagrams of each other. For example, consider the string s = "gamegame". Then the string t = "megamage" is a reducible anagram of s, we may choose for example s_1 = "game", s_2 = "gam", s_3 = "e" and t_1 = "mega", t_2 = "mag", t_3 = "e": <image> On the other hand, we can prove that t = "memegaga" is an irreducible anagram of s. You will be given a string s and q queries, represented by two integers 1 ≀ l ≀ r ≀ |s| (where |s| is equal to the length of the string s). For each query, you should find if the substring of s formed by characters from the l-th to the r-th has at least one irreducible anagram. Input The first line contains a string s, consisting of lowercase English characters (1 ≀ |s| ≀ 2 β‹… 10^5). The second line contains a single integer q (1 ≀ q ≀ 10^5) β€” the number of queries. Each of the following q lines contain two integers l and r (1 ≀ l ≀ r ≀ |s|), representing a query for the substring of s formed by characters from the l-th to the r-th. Output For each query, print a single line containing "Yes" (without quotes) if the corresponding substring has at least one irreducible anagram, and a single line containing "No" (without quotes) otherwise. Examples Input aaaaa 3 1 1 2 4 5 5 Output Yes No Yes Input aabbbbbbc 6 1 2 2 4 2 2 1 9 5 7 3 5 Output No Yes Yes Yes No No Note In the first sample, in the first and third queries, the substring is "a", which has itself as an irreducible anagram since two or more non-empty strings cannot be put together to obtain "a". On the other hand, in the second query, the substring is "aaa", which has no irreducible anagrams: its only anagram is itself, and we may choose s_1 = "a", s_2 = "aa", t_1 = "a", t_2 = "aa" to show that it is a reducible anagram. In the second query of the second sample, the substring is "abb", which has, for example, "bba" as an irreducible anagram.
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(cases): l, r = map(int, input().split()) l -= 1 if r - l == 1: print("Yes") continue if s[l] != s[r - 1]: print("Yes") continue answer = "No" p = lastChange[r - 1] c1 = s[r - 1] if p > l: c2 = s[p - 1] while p > l: print("-", p) if s[p - 1] != c1 and s[p - 1] != c2: answer = "Yes" break p = lastChange[p - 1] print(answer) s = input() cases = int(input()) if len(s) > 1: char3 = [] next3 = [None] * len(s) p1 = 0 c1 = s[0] p2 = None for i in range(1, len(s)): if s[i] != c1: p2 = i c2 = s[i] break if p2 != None: for i in range(p2, len(s)): if s[i] == c1: p1 = i elif s[i] == c2: p2 = i else: if p1 > p2: p1, c1, p2, c2 = p2, c2, p1, c1 char3.append((p1, i)) p1, c1, p2, c2 = p2, c2, i, s[i] if char3 != []: i = 0 for j in range(len(s)): while i < len(char3) and j > char3[i][0]: i += 1 if i < len(char3): next3[j] = i for i in range(cases): l, r = map(int, input().split()) l -= 1 if r - l == 1: print("Yes") continue if s[l] != s[r - 1]: print("Yes") continue if next3[l] != None and char3[next3[l]][1] <= r - 1: print("Yes") continue print("No")
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 VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR STRING VAR IF VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR STRING ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NONE FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NONE FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR IF VAR NONE FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR NONE VAR VAR VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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_2, t_2, ..., s_k, t_k that satisfy the following conditions: 1. If we write the strings s_1, s_2, ..., s_k in order, the resulting string will be equal to s; 2. If we write the strings t_1, t_2, ..., t_k in order, the resulting string will be equal to t; 3. For all integers i between 1 and k inclusive, s_i and t_i are anagrams of each other. If such strings don't exist, then t is said to be an irreducible anagram of s. Note that these notions are only defined when s and t are anagrams of each other. For example, consider the string s = "gamegame". Then the string t = "megamage" is a reducible anagram of s, we may choose for example s_1 = "game", s_2 = "gam", s_3 = "e" and t_1 = "mega", t_2 = "mag", t_3 = "e": <image> On the other hand, we can prove that t = "memegaga" is an irreducible anagram of s. You will be given a string s and q queries, represented by two integers 1 ≀ l ≀ r ≀ |s| (where |s| is equal to the length of the string s). For each query, you should find if the substring of s formed by characters from the l-th to the r-th has at least one irreducible anagram. Input The first line contains a string s, consisting of lowercase English characters (1 ≀ |s| ≀ 2 β‹… 10^5). The second line contains a single integer q (1 ≀ q ≀ 10^5) β€” the number of queries. Each of the following q lines contain two integers l and r (1 ≀ l ≀ r ≀ |s|), representing a query for the substring of s formed by characters from the l-th to the r-th. Output For each query, print a single line containing "Yes" (without quotes) if the corresponding substring has at least one irreducible anagram, and a single line containing "No" (without quotes) otherwise. Examples Input aaaaa 3 1 1 2 4 5 5 Output Yes No Yes Input aabbbbbbc 6 1 2 2 4 2 2 1 9 5 7 3 5 Output No Yes Yes Yes No No Note In the first sample, in the first and third queries, the substring is "a", which has itself as an irreducible anagram since two or more non-empty strings cannot be put together to obtain "a". On the other hand, in the second query, the substring is "aaa", which has no irreducible anagrams: its only anagram is itself, and we may choose s_1 = "a", s_2 = "aa", t_1 = "a", t_2 = "aa" to show that it is a reducible anagram. In the second query of the second sample, the substring is "abb", which has, for example, "bba" as an irreducible anagram.
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)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") INF = 10**18 MOD = 10**9 + 7 S = [(ord(c) - 97) for c in input()] N = len(S) acc = list2d(26, N + 1, 0) for i, c in enumerate(S): acc[c][i + 1] += 1 for c in range(26): acc[c] = list(accumulate(acc[c])) for _ in range(INT()): l, r = MAP() l -= 1 ln = r - l if ln == 1: Yes() continue cnt = 0 for c in range(26): if acc[c][r] - acc[c][l] >= 1: cnt += 1 if cnt >= 3: Yes() continue if S[l] != S[r - 1]: Yes() else: No()
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 VAR BIN_OP VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF NONE RETURN VAR NONE FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL 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_2, t_2, ..., s_k, t_k that satisfy the following conditions: 1. If we write the strings s_1, s_2, ..., s_k in order, the resulting string will be equal to s; 2. If we write the strings t_1, t_2, ..., t_k in order, the resulting string will be equal to t; 3. For all integers i between 1 and k inclusive, s_i and t_i are anagrams of each other. If such strings don't exist, then t is said to be an irreducible anagram of s. Note that these notions are only defined when s and t are anagrams of each other. For example, consider the string s = "gamegame". Then the string t = "megamage" is a reducible anagram of s, we may choose for example s_1 = "game", s_2 = "gam", s_3 = "e" and t_1 = "mega", t_2 = "mag", t_3 = "e": <image> On the other hand, we can prove that t = "memegaga" is an irreducible anagram of s. You will be given a string s and q queries, represented by two integers 1 ≀ l ≀ r ≀ |s| (where |s| is equal to the length of the string s). For each query, you should find if the substring of s formed by characters from the l-th to the r-th has at least one irreducible anagram. Input The first line contains a string s, consisting of lowercase English characters (1 ≀ |s| ≀ 2 β‹… 10^5). The second line contains a single integer q (1 ≀ q ≀ 10^5) β€” the number of queries. Each of the following q lines contain two integers l and r (1 ≀ l ≀ r ≀ |s|), representing a query for the substring of s formed by characters from the l-th to the r-th. Output For each query, print a single line containing "Yes" (without quotes) if the corresponding substring has at least one irreducible anagram, and a single line containing "No" (without quotes) otherwise. Examples Input aaaaa 3 1 1 2 4 5 5 Output Yes No Yes Input aabbbbbbc 6 1 2 2 4 2 2 1 9 5 7 3 5 Output No Yes Yes Yes No No Note In the first sample, in the first and third queries, the substring is "a", which has itself as an irreducible anagram since two or more non-empty strings cannot be put together to obtain "a". On the other hand, in the second query, the substring is "aaa", which has no irreducible anagrams: its only anagram is itself, and we may choose s_1 = "a", s_2 = "aa", t_1 = "a", t_2 = "aa" to show that it is a reducible anagram. In the second query of the second sample, the substring is "abb", which has, for example, "bba" as an irreducible anagram.
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() cnt[i + 1][s[i]] += 1 n = int(input()) for i in range(n): l, r = map(int, input().split()) if l == r or s[l - 1] != s[r - 1] or unique(cnt, l, r) >= 3: print("Yes") else: print("No")
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 NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR 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 IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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_2, t_2, ..., s_k, t_k that satisfy the following conditions: 1. If we write the strings s_1, s_2, ..., s_k in order, the resulting string will be equal to s; 2. If we write the strings t_1, t_2, ..., t_k in order, the resulting string will be equal to t; 3. For all integers i between 1 and k inclusive, s_i and t_i are anagrams of each other. If such strings don't exist, then t is said to be an irreducible anagram of s. Note that these notions are only defined when s and t are anagrams of each other. For example, consider the string s = "gamegame". Then the string t = "megamage" is a reducible anagram of s, we may choose for example s_1 = "game", s_2 = "gam", s_3 = "e" and t_1 = "mega", t_2 = "mag", t_3 = "e": <image> On the other hand, we can prove that t = "memegaga" is an irreducible anagram of s. You will be given a string s and q queries, represented by two integers 1 ≀ l ≀ r ≀ |s| (where |s| is equal to the length of the string s). For each query, you should find if the substring of s formed by characters from the l-th to the r-th has at least one irreducible anagram. Input The first line contains a string s, consisting of lowercase English characters (1 ≀ |s| ≀ 2 β‹… 10^5). The second line contains a single integer q (1 ≀ q ≀ 10^5) β€” the number of queries. Each of the following q lines contain two integers l and r (1 ≀ l ≀ r ≀ |s|), representing a query for the substring of s formed by characters from the l-th to the r-th. Output For each query, print a single line containing "Yes" (without quotes) if the corresponding substring has at least one irreducible anagram, and a single line containing "No" (without quotes) otherwise. Examples Input aaaaa 3 1 1 2 4 5 5 Output Yes No Yes Input aabbbbbbc 6 1 2 2 4 2 2 1 9 5 7 3 5 Output No Yes Yes Yes No No Note In the first sample, in the first and third queries, the substring is "a", which has itself as an irreducible anagram since two or more non-empty strings cannot be put together to obtain "a". On the other hand, in the second query, the substring is "aaa", which has no irreducible anagrams: its only anagram is itself, and we may choose s_1 = "a", s_2 = "aa", t_1 = "a", t_2 = "aa" to show that it is a reducible anagram. In the second query of the second sample, the substring is "abb", which has, for example, "bba" as an irreducible anagram.
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") continue p = 0 f = [(ref[r][k] - ref[l - 1][k]) for k in range(26)] for i in f: if i > 0: p += 1 if p >= 3: print("Yes") else: print("No")
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 VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
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_2, t_2, ..., s_k, t_k that satisfy the following conditions: 1. If we write the strings s_1, s_2, ..., s_k in order, the resulting string will be equal to s; 2. If we write the strings t_1, t_2, ..., t_k in order, the resulting string will be equal to t; 3. For all integers i between 1 and k inclusive, s_i and t_i are anagrams of each other. If such strings don't exist, then t is said to be an irreducible anagram of s. Note that these notions are only defined when s and t are anagrams of each other. For example, consider the string s = "gamegame". Then the string t = "megamage" is a reducible anagram of s, we may choose for example s_1 = "game", s_2 = "gam", s_3 = "e" and t_1 = "mega", t_2 = "mag", t_3 = "e": <image> On the other hand, we can prove that t = "memegaga" is an irreducible anagram of s. You will be given a string s and q queries, represented by two integers 1 ≀ l ≀ r ≀ |s| (where |s| is equal to the length of the string s). For each query, you should find if the substring of s formed by characters from the l-th to the r-th has at least one irreducible anagram. Input The first line contains a string s, consisting of lowercase English characters (1 ≀ |s| ≀ 2 β‹… 10^5). The second line contains a single integer q (1 ≀ q ≀ 10^5) β€” the number of queries. Each of the following q lines contain two integers l and r (1 ≀ l ≀ r ≀ |s|), representing a query for the substring of s formed by characters from the l-th to the r-th. Output For each query, print a single line containing "Yes" (without quotes) if the corresponding substring has at least one irreducible anagram, and a single line containing "No" (without quotes) otherwise. Examples Input aaaaa 3 1 1 2 4 5 5 Output Yes No Yes Input aabbbbbbc 6 1 2 2 4 2 2 1 9 5 7 3 5 Output No Yes Yes Yes No No Note In the first sample, in the first and third queries, the substring is "a", which has itself as an irreducible anagram since two or more non-empty strings cannot be put together to obtain "a". On the other hand, in the second query, the substring is "aaa", which has no irreducible anagrams: its only anagram is itself, and we may choose s_1 = "a", s_2 = "aa", t_1 = "a", t_2 = "aa" to show that it is a reducible anagram. In the second query of the second sample, the substring is "abb", which has, for example, "bba" as an irreducible anagram.
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 "Yes" kinds = 0 seg = [(memo[r][k] - memo[l - 1][k]) for k in range(26)] for c in seg: if c: kinds += 1 if kinds >= 3: return "Yes" return "No" T = int(input()) for t in range(T): print(f())
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 VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR RETURN STRING IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER IF VAR NUMBER RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR 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: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. -----Input----- The first line contains two integers n, k (1 ≀ k ≀ n ≀ 5Β·10^5) β€” the number of elements in a and the parameter k. The second line contains n integers a_{i} (0 ≀ a_{i} ≀ 10^6) β€” the elements of the array a. -----Output----- Print two integers l, r (1 ≀ l ≀ r ≀ n) β€” the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right. -----Examples----- Input 5 5 1 2 3 4 5 Output 1 5 Input 9 3 6 5 1 2 3 2 1 4 5 Output 3 7 Input 3 1 1 2 3 Output 1 1
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) // 2) for i in range(0, len(ans), 2): print(ans[i], ans[i + 1])
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 ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER
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: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. -----Input----- The first line contains two integers n, k (1 ≀ k ≀ n ≀ 5Β·10^5) β€” the number of elements in a and the parameter k. The second line contains n integers a_{i} (0 ≀ a_{i} ≀ 10^6) β€” the elements of the array a. -----Output----- Print two integers l, r (1 ≀ l ≀ r ≀ n) β€” the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right. -----Examples----- Input 5 5 1 2 3 4 5 Output 1 5 Input 9 3 6 5 1 2 3 2 1 4 5 Output 3 7 Input 3 1 1 2 3 Output 1 1
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(stack2)) map1.clear() stack2.clear() else: map1.add(inputTypes[i]) if len(stack3) == 0: print(-1) sys.exit() if len(map1) == 0: print(len(stack3)) for x in stack3: print(x) else: print(len(stack3)) lastitem = str(stack3[-1].split()[-1]) for x in stack3: print(x.replace(lastitem, str(len(inputTypes))))
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 VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL 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: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. -----Input----- The first line contains two integers n, k (1 ≀ k ≀ n ≀ 5Β·10^5) β€” the number of elements in a and the parameter k. The second line contains n integers a_{i} (0 ≀ a_{i} ≀ 10^6) β€” the elements of the array a. -----Output----- Print two integers l, r (1 ≀ l ≀ r ≀ n) β€” the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right. -----Examples----- Input 5 5 1 2 3 4 5 Output 1 5 Input 9 3 6 5 1 2 3 2 1 4 5 Output 3 7 Input 3 1 1 2 3 Output 1 1
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 <= k and r < n - 1: r += 1 ins[lis[r]] += 1 if ins[lis[r]] == 1: zeroes -= 1 if 10**6 - zeroes == k + 1: ins[lis[r]] -= 1 zeroes += 1 r -= 1 break if mL < r - l: mL = r - l pair = [l, r] print(pair[0] + 1, pair[1] + 1)
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 VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER WHILE BIN_OP BIN_OP NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER
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: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. -----Input----- The first line contains two integers n, k (1 ≀ k ≀ n ≀ 5Β·10^5) β€” the number of elements in a and the parameter k. The second line contains n integers a_{i} (0 ≀ a_{i} ≀ 10^6) β€” the elements of the array a. -----Output----- Print two integers l, r (1 ≀ l ≀ r ≀ n) β€” the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right. -----Examples----- Input 5 5 1 2 3 4 5 Output 1 5 Input 9 3 6 5 1 2 3 2 1 4 5 Output 3 7 Input 3 1 1 2 3 Output 1 1
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: print(*ansi)
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 FUNC_CALL VAR VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL 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: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. -----Input----- The first line contains two integers n, k (1 ≀ k ≀ n ≀ 5Β·10^5) β€” the number of elements in a and the parameter k. The second line contains n integers a_{i} (0 ≀ a_{i} ≀ 10^6) β€” the elements of the array a. -----Output----- Print two integers l, r (1 ≀ l ≀ r ≀ n) β€” the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right. -----Examples----- Input 5 5 1 2 3 4 5 Output 1 5 Input 9 3 6 5 1 2 3 2 1 4 5 Output 3 7 Input 3 1 1 2 3 Output 1 1
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: aml[am - 1][1] = n print(am) for i in range(am): print(aml[i][0], aml[i][1])
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 VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER
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: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. -----Input----- The first line contains two integers n, k (1 ≀ k ≀ n ≀ 5Β·10^5) β€” the number of elements in a and the parameter k. The second line contains n integers a_{i} (0 ≀ a_{i} ≀ 10^6) β€” the elements of the array a. -----Output----- Print two integers l, r (1 ≀ l ≀ r ≀ n) β€” the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right. -----Examples----- Input 5 5 1 2 3 4 5 Output 1 5 Input 9 3 6 5 1 2 3 2 1 4 5 Output 3 7 Input 3 1 1 2 3 Output 1 1
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 - l + 1 > ans: al = l ar = r ans = r - l + 1 print(al + 1, ar + 1)
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 VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER
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: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. -----Input----- The first line contains two integers n, k (1 ≀ k ≀ n ≀ 5Β·10^5) β€” the number of elements in a and the parameter k. The second line contains n integers a_{i} (0 ≀ a_{i} ≀ 10^6) β€” the elements of the array a. -----Output----- Print two integers l, r (1 ≀ l ≀ r ≀ n) β€” the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right. -----Examples----- Input 5 5 1 2 3 4 5 Output 1 5 Input 9 3 6 5 1 2 3 2 1 4 5 Output 3 7 Input 3 1 1 2 3 Output 1 1
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)) for i in res: print(" ".join(map(str, i))) else: print(-1)
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 VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
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: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. -----Input----- The first line contains two integers n, k (1 ≀ k ≀ n ≀ 5Β·10^5) β€” the number of elements in a and the parameter k. The second line contains n integers a_{i} (0 ≀ a_{i} ≀ 10^6) β€” the elements of the array a. -----Output----- Print two integers l, r (1 ≀ l ≀ r ≀ n) β€” the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right. -----Examples----- Input 5 5 1 2 3 4 5 Output 1 5 Input 9 3 6 5 1 2 3 2 1 4 5 Output 3 7 Input 3 1 1 2 3 Output 1 1
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: print(-1) else: result[len(result) - 1] = [result[len(result) - 1][0], n] print(ans) print("\n".join("{0} {1}".format(p, q) for p, q in result))
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 VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER LIST VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL STRING VAR VAR 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: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. -----Input----- The first line contains two integers n, k (1 ≀ k ≀ n ≀ 5Β·10^5) β€” the number of elements in a and the parameter k. The second line contains n integers a_{i} (0 ≀ a_{i} ≀ 10^6) β€” the elements of the array a. -----Output----- Print two integers l, r (1 ≀ l ≀ r ≀ n) β€” the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right. -----Examples----- Input 5 5 1 2 3 4 5 Output 1 5 Input 9 3 6 5 1 2 3 2 1 4 5 Output 3 7 Input 3 1 1 2 3 Output 1 1
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 NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER LIST VAR NUMBER VAR FOR VAR VAR EXPR FUNC_CALL 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: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. -----Input----- The first line contains two integers n, k (1 ≀ k ≀ n ≀ 5Β·10^5) β€” the number of elements in a and the parameter k. The second line contains n integers a_{i} (0 ≀ a_{i} ≀ 10^6) β€” the elements of the array a. -----Output----- Print two integers l, r (1 ≀ l ≀ r ≀ n) β€” the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right. -----Examples----- Input 5 5 1 2 3 4 5 Output 1 5 Input 9 3 6 5 1 2 3 2 1 4 5 Output 3 7 Input 3 1 1 2 3 Output 1 1
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: myDic[y][-1] = x else: myDic.update({y: [x]}) if capture: res = len(capture) if res == 1: print(res) print(1, size) else: print(res) print(1, capture[0][1]) start = capture[0][1] + 1 for c in range(1, res): print(start, capture[c][1] if c + 1 < res else size) start = capture[c][1] + 1 else: print(-1)
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 NUMBER VAR EXPR FUNC_CALL VAR DICT VAR LIST VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER
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: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. -----Input----- The first line contains two integers n, k (1 ≀ k ≀ n ≀ 5Β·10^5) β€” the number of elements in a and the parameter k. The second line contains n integers a_{i} (0 ≀ a_{i} ≀ 10^6) β€” the elements of the array a. -----Output----- Print two integers l, r (1 ≀ l ≀ r ≀ n) β€” the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right. -----Examples----- Input 5 5 1 2 3 4 5 Output 1 5 Input 9 3 6 5 1 2 3 2 1 4 5 Output 3 7 Input 3 1 1 2 3 Output 1 1
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) from sys import exit exit() if res[result - 1][1] != n: res[result - 1][1] = n print(result) for i, x in enumerate(res): print(*x)
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 ASSIGN VAR DICT IF VAR LIST VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL 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: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. -----Input----- The first line contains two integers n, k (1 ≀ k ≀ n ≀ 5Β·10^5) β€” the number of elements in a and the parameter k. The second line contains n integers a_{i} (0 ≀ a_{i} ≀ 10^6) β€” the elements of the array a. -----Output----- Print two integers l, r (1 ≀ l ≀ r ≀ n) β€” the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right. -----Examples----- Input 5 5 1 2 3 4 5 Output 1 5 Input 9 3 6 5 1 2 3 2 1 4 5 Output 3 7 Input 3 1 1 2 3 Output 1 1
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().split()] longest_good = 0 good_seg = [-1, -1] left = 0 elements = {} for right in range(len(arr)): add(elements, arr[right]) while len(elements) > limit: remove(elements, arr[left]) left += 1 if right - left + 1 > longest_good: longest_good = right - left + 1 good_seg = [left + 1, right + 1] print(good_seg[0], good_seg[1])
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_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR WHILE FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER
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: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. -----Input----- The first line contains two integers n, k (1 ≀ k ≀ n ≀ 5Β·10^5) β€” the number of elements in a and the parameter k. The second line contains n integers a_{i} (0 ≀ a_{i} ≀ 10^6) β€” the elements of the array a. -----Output----- Print two integers l, r (1 ≀ l ≀ r ≀ n) β€” the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right. -----Examples----- Input 5 5 1 2 3 4 5 Output 1 5 Input 9 3 6 5 1 2 3 2 1 4 5 Output 3 7 Input 3 1 1 2 3 Output 1 1
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: kind += 1 if cnt[a[j]] == 0 else 0 cnt[a[j]] += 1 j += 1 if ans_len < j - i: ans_len = j - i ans_i, ans_j = i + 1, j cnt[a[i]] -= 1 kind -= 1 if cnt[a[i]] == 0 else 0 print(ans_i, ans_j)
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 VAR FUNC_CALL VAR VAR WHILE VAR VAR BIN_OP VAR VAR VAR VAR NUMBER NUMBER NUMBER VAR VAR VAR VAR VAR NUMBER NUMBER NUMBER VAR VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL 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: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. -----Input----- The first line contains two integers n, k (1 ≀ k ≀ n ≀ 5Β·10^5) β€” the number of elements in a and the parameter k. The second line contains n integers a_{i} (0 ≀ a_{i} ≀ 10^6) β€” the elements of the array a. -----Output----- Print two integers l, r (1 ≀ l ≀ r ≀ n) β€” the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right. -----Examples----- Input 5 5 1 2 3 4 5 Output 1 5 Input 9 3 6 5 1 2 3 2 1 4 5 Output 3 7 Input 3 1 1 2 3 Output 1 1
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 if cnt[arr[l]] == 0: cur -= 1 l += 1 if i - l + 1 > ans: al = l ar = i ans = i - l + 1 print(al + 1, ar + 1) return "" a, b = map(int, input().strip().split()) lst = list(map(int, input().strip().split())) print(longestK(lst, b))
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 NUMBER VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN STRING ASSIGN VAR 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 EXPR FUNC_CALL VAR FUNC_CALL 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: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. -----Input----- The first line contains two integers n, k (1 ≀ k ≀ n ≀ 5Β·10^5) β€” the number of elements in a and the parameter k. The second line contains n integers a_{i} (0 ≀ a_{i} ≀ 10^6) β€” the elements of the array a. -----Output----- Print two integers l, r (1 ≀ l ≀ r ≀ n) β€” the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right. -----Examples----- Input 5 5 1 2 3 4 5 Output 1 5 Input 9 3 6 5 1 2 3 2 1 4 5 Output 3 7 Input 3 1 1 2 3 Output 1 1
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 ls = [str(a), str(b)] seg.append(ls) a = i + 2 if len(seg) == 0: print(-1) else: if jud == 0: seg[-1][1] = str(n) print(num) for i in range(len(seg)): print(" ".join(seg[i]))
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 NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING 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: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. -----Input----- The first line contains two integers n, k (1 ≀ k ≀ n ≀ 5Β·10^5) β€” the number of elements in a and the parameter k. The second line contains n integers a_{i} (0 ≀ a_{i} ≀ 10^6) β€” the elements of the array a. -----Output----- Print two integers l, r (1 ≀ l ≀ r ≀ n) β€” the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right. -----Examples----- Input 5 5 1 2 3 4 5 Output 1 5 Input 9 3 6 5 1 2 3 2 1 4 5 Output 3 7 Input 3 1 1 2 3 Output 1 1
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(-1) else: Ans[-1][1] = str(N) print(L) for val in Ans: print(" ".join(val))
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 FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR DICT VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING 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: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. -----Input----- The first line contains two integers n, k (1 ≀ k ≀ n ≀ 5Β·10^5) β€” the number of elements in a and the parameter k. The second line contains n integers a_{i} (0 ≀ a_{i} ≀ 10^6) β€” the elements of the array a. -----Output----- Print two integers l, r (1 ≀ l ≀ r ≀ n) β€” the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right. -----Examples----- Input 5 5 1 2 3 4 5 Output 1 5 Input 9 3 6 5 1 2 3 2 1 4 5 Output 3 7 Input 3 1 1 2 3 Output 1 1
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 intervals: intervals[-1][-1] = pearl_count print(len(intervals)) [print(" ".join(map(str, interval))) for interval in intervals] else: print(-1)
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 VAR IF VAR ASSIGN VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
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: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. -----Input----- The first line contains two integers n, k (1 ≀ k ≀ n ≀ 5Β·10^5) β€” the number of elements in a and the parameter k. The second line contains n integers a_{i} (0 ≀ a_{i} ≀ 10^6) β€” the elements of the array a. -----Output----- Print two integers l, r (1 ≀ l ≀ r ≀ n) β€” the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right. -----Examples----- Input 5 5 1 2 3 4 5 Output 1 5 Input 9 3 6 5 1 2 3 2 1 4 5 Output 3 7 Input 3 1 1 2 3 Output 1 1
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: print(counter) segments.remove([0, 0]) print("\n".join("{0} {1}".format(p, q) for p, q in segments)) else: print(-1)
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 NUMBER NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL STRING VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
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: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. -----Input----- The first line contains two integers n, k (1 ≀ k ≀ n ≀ 5Β·10^5) β€” the number of elements in a and the parameter k. The second line contains n integers a_{i} (0 ≀ a_{i} ≀ 10^6) β€” the elements of the array a. -----Output----- Print two integers l, r (1 ≀ l ≀ r ≀ n) β€” the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right. -----Examples----- Input 5 5 1 2 3 4 5 Output 1 5 Input 9 3 6 5 1 2 3 2 1 4 5 Output 3 7 Input 3 1 1 2 3 Output 1 1
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: to_remove = arr[s] if dist[to_remove] == 1: dist.pop(to_remove) else: dist[to_remove] -= 1 l -= 1 s += 1 if l > max_l: start = s max_l = l end = i print(start + 1, end + 1)
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 VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER
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: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. -----Input----- The first line contains two integers n, k (1 ≀ k ≀ n ≀ 5Β·10^5) β€” the number of elements in a and the parameter k. The second line contains n integers a_{i} (0 ≀ a_{i} ≀ 10^6) β€” the elements of the array a. -----Output----- Print two integers l, r (1 ≀ l ≀ r ≀ n) β€” the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right. -----Examples----- Input 5 5 1 2 3 4 5 Output 1 5 Input 9 3 6 5 1 2 3 2 1 4 5 Output 3 7 Input 3 1 1 2 3 Output 1 1
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: print(len(x)) y[len(y) - 1] = n for i in range(len(x)): print(x[i], y[i])
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 VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR DICT ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR 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: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. -----Input----- The first line contains two integers n, k (1 ≀ k ≀ n ≀ 5Β·10^5) β€” the number of elements in a and the parameter k. The second line contains n integers a_{i} (0 ≀ a_{i} ≀ 10^6) β€” the elements of the array a. -----Output----- Print two integers l, r (1 ≀ l ≀ r ≀ n) β€” the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right. -----Examples----- Input 5 5 1 2 3 4 5 Output 1 5 Input 9 3 6 5 1 2 3 2 1 4 5 Output 3 7 Input 3 1 1 2 3 Output 1 1
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 flag = True if flag: if not res2[-1] == n: res2[-1] = n print(len(res1)) for i, j in zip(res1, res2): print(i, j) else: print(-1)
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 FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR IF VAR NUMBER VAR ASSIGN VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
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: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. -----Input----- The first line contains two integers n, k (1 ≀ k ≀ n ≀ 5Β·10^5) β€” the number of elements in a and the parameter k. The second line contains n integers a_{i} (0 ≀ a_{i} ≀ 10^6) β€” the elements of the array a. -----Output----- Print two integers l, r (1 ≀ l ≀ r ≀ n) β€” the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right. -----Examples----- Input 5 5 1 2 3 4 5 Output 1 5 Input 9 3 6 5 1 2 3 2 1 4 5 Output 3 7 Input 3 1 1 2 3 Output 1 1
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(ans) - 1: print(ans[i][0], n) else: print(ans[i][0], ans[i][1])
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 LIST EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER
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: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. -----Input----- The first line contains two integers n, k (1 ≀ k ≀ n ≀ 5Β·10^5) β€” the number of elements in a and the parameter k. The second line contains n integers a_{i} (0 ≀ a_{i} ≀ 10^6) β€” the elements of the array a. -----Output----- Print two integers l, r (1 ≀ l ≀ r ≀ n) β€” the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right. -----Examples----- Input 5 5 1 2 3 4 5 Output 1 5 Input 9 3 6 5 1 2 3 2 1 4 5 Output 3 7 Input 3 1 1 2 3 Output 1 1
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): print(starts[i], starts[i + 1] - 1) print(starts[l - 2], 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 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 VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER 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: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. -----Input----- The first line contains two integers n, k (1 ≀ k ≀ n ≀ 5Β·10^5) β€” the number of elements in a and the parameter k. The second line contains n integers a_{i} (0 ≀ a_{i} ≀ 10^6) β€” the elements of the array a. -----Output----- Print two integers l, r (1 ≀ l ≀ r ≀ n) β€” the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right. -----Examples----- Input 5 5 1 2 3 4 5 Output 1 5 Input 9 3 6 5 1 2 3 2 1 4 5 Output 3 7 Input 3 1 1 2 3 Output 1 1
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: left = l right = r - 1 cnt[a[l]] -= 1 if cnt[a[l]] == 0: t -= 1 l += 1 if r - l > right - left + 1: left = l right = r - 1 print(left + 1, right + 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 VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER
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: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. -----Input----- The first line contains two integers n, k (1 ≀ k ≀ n ≀ 5Β·10^5) β€” the number of elements in a and the parameter k. The second line contains n integers a_{i} (0 ≀ a_{i} ≀ 10^6) β€” the elements of the array a. -----Output----- Print two integers l, r (1 ≀ l ≀ r ≀ n) β€” the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right. -----Examples----- Input 5 5 1 2 3 4 5 Output 1 5 Input 9 3 6 5 1 2 3 2 1 4 5 Output 3 7 Input 3 1 1 2 3 Output 1 1
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 -= 1 j += 1 if i - j > l: ans = [j + 1, i + 1] l = i - j print(*ans)
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 NUMBER VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL 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: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. -----Input----- The first line contains two integers n, k (1 ≀ k ≀ n ≀ 5Β·10^5) β€” the number of elements in a and the parameter k. The second line contains n integers a_{i} (0 ≀ a_{i} ≀ 10^6) β€” the elements of the array a. -----Output----- Print two integers l, r (1 ≀ l ≀ r ≀ n) β€” the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right. -----Examples----- Input 5 5 1 2 3 4 5 Output 1 5 Input 9 3 6 5 1 2 3 2 1 4 5 Output 3 7 Input 3 1 1 2 3 Output 1 1
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 = 1 for i in range(g - 1): print(p, L[i] + 1) p = L[i] + 2 print(p, 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 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 ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL 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: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. -----Input----- The first line contains two integers n, k (1 ≀ k ≀ n ≀ 5Β·10^5) β€” the number of elements in a and the parameter k. The second line contains n integers a_{i} (0 ≀ a_{i} ≀ 10^6) β€” the elements of the array a. -----Output----- Print two integers l, r (1 ≀ l ≀ r ≀ n) β€” the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right. -----Examples----- Input 5 5 1 2 3 4 5 Output 1 5 Input 9 3 6 5 1 2 3 2 1 4 5 Output 3 7 Input 3 1 1 2 3 Output 1 1
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(seq) - 1: if w < req: if bigarray[seq[first + 1]] == 0: first += 1 bigarray[seq[first]] += 1 g = g + 1 w = w + 1 elif bigarray[seq[first + 1]] != 0: bigarray[seq[first + 1]] += 1 first = first + 1 g = g + 1 if mo < g: mo = g rmo = [last + 1, first + 1] elif w >= req: if bigarray[seq[first + 1]] == 0: bigarray[seq[last]] -= 1 if bigarray[seq[last]] == 0: w = w - 1 if g > mo: mo = g rmo = [last + 1, first + 1] g = g - 1 last = last + 1 else: g = g + 1 first += 1 bigarray[seq[first]] += 1 if mo < g: mo = g rmo = [last + 1, first + 1] for x in rmo: print(x, end=" ") main()
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 NUMBER VAR ASSIGN VAR LIST NUMBER VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR IF VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR IF VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING 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: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. -----Input----- The first line contains two integers n, k (1 ≀ k ≀ n ≀ 5Β·10^5) β€” the number of elements in a and the parameter k. The second line contains n integers a_{i} (0 ≀ a_{i} ≀ 10^6) β€” the elements of the array a. -----Output----- Print two integers l, r (1 ≀ l ≀ r ≀ n) β€” the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right. -----Examples----- Input 5 5 1 2 3 4 5 Output 1 5 Input 9 3 6 5 1 2 3 2 1 4 5 Output 3 7 Input 3 1 1 2 3 Output 1 1
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: segments[-1] = segments[-1][0], n print(len(segments)) for s in segments: print(s[0], s[1])
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 VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER
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: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. -----Input----- The first line contains two integers n, k (1 ≀ k ≀ n ≀ 5Β·10^5) β€” the number of elements in a and the parameter k. The second line contains n integers a_{i} (0 ≀ a_{i} ≀ 10^6) β€” the elements of the array a. -----Output----- Print two integers l, r (1 ≀ l ≀ r ≀ n) β€” the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right. -----Examples----- Input 5 5 1 2 3 4 5 Output 1 5 Input 9 3 6 5 1 2 3 2 1 4 5 Output 3 7 Input 3 1 1 2 3 Output 1 1
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: print(ans[i][0], ans[i][1]) else: print(ans[i][0], 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 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 NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER 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: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. -----Input----- The first line contains two integers n, k (1 ≀ k ≀ n ≀ 5Β·10^5) β€” the number of elements in a and the parameter k. The second line contains n integers a_{i} (0 ≀ a_{i} ≀ 10^6) β€” the elements of the array a. -----Output----- Print two integers l, r (1 ≀ l ≀ r ≀ n) β€” the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right. -----Examples----- Input 5 5 1 2 3 4 5 Output 1 5 Input 9 3 6 5 1 2 3 2 1 4 5 Output 3 7 Input 3 1 1 2 3 Output 1 1
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 NUMBER VAR NUMBER NUMBER VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
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: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. -----Input----- The first line contains two integers n, k (1 ≀ k ≀ n ≀ 5Β·10^5) β€” the number of elements in a and the parameter k. The second line contains n integers a_{i} (0 ≀ a_{i} ≀ 10^6) β€” the elements of the array a. -----Output----- Print two integers l, r (1 ≀ l ≀ r ≀ n) β€” the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right. -----Examples----- Input 5 5 1 2 3 4 5 Output 1 5 Input 9 3 6 5 1 2 3 2 1 4 5 Output 3 7 Input 3 1 1 2 3 Output 1 1
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: print(len(ans)) for i in ans: print(i[0], i[1]) else: 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 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 ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER
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: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. -----Input----- The first line contains two integers n, k (1 ≀ k ≀ n ≀ 5Β·10^5) β€” the number of elements in a and the parameter k. The second line contains n integers a_{i} (0 ≀ a_{i} ≀ 10^6) β€” the elements of the array a. -----Output----- Print two integers l, r (1 ≀ l ≀ r ≀ n) β€” the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right. -----Examples----- Input 5 5 1 2 3 4 5 Output 1 5 Input 9 3 6 5 1 2 3 2 1 4 5 Output 3 7 Input 3 1 1 2 3 Output 1 1
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 = curcnt + (cnt[p[r + 1]] == 0) cnt[p[r + 1]] += 1 r += 1 if maxlen < r - l: maxlen = r - l maxr = r maxl = l cnt[p[l]] -= 1 curcnt -= cnt[p[l]] == 0 l += 1 print(str(maxl + 1) + " " + str(maxr + 1))
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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR WHILE VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER
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: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. -----Input----- The first line contains two integers n, k (1 ≀ k ≀ n ≀ 5Β·10^5) β€” the number of elements in a and the parameter k. The second line contains n integers a_{i} (0 ≀ a_{i} ≀ 10^6) β€” the elements of the array a. -----Output----- Print two integers l, r (1 ≀ l ≀ r ≀ n) β€” the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right. -----Examples----- Input 5 5 1 2 3 4 5 Output 1 5 Input 9 3 6 5 1 2 3 2 1 4 5 Output 3 7 Input 3 1 1 2 3 Output 1 1
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 ar = 0 ans = 0 now = 0 for i in range(n): vis[num[i]] += 1 if vis[num[i]] == 1: now += 1 while now > m: vis[num[l]] -= 1 if vis[num[l]] == 0: now -= 1 l += 1 if i - l + 1 > ar - al + 1: ar = i al = l print("{0} {1}".format(al + 1, ar + 1))
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_CALL STRING NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP VAR NUMBER BIN_OP VAR NUMBER
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: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. -----Input----- The first line contains two integers n, k (1 ≀ k ≀ n ≀ 5Β·10^5) β€” the number of elements in a and the parameter k. The second line contains n integers a_{i} (0 ≀ a_{i} ≀ 10^6) β€” the elements of the array a. -----Output----- Print two integers l, r (1 ≀ l ≀ r ≀ n) β€” the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right. -----Examples----- Input 5 5 1 2 3 4 5 Output 1 5 Input 9 3 6 5 1 2 3 2 1 4 5 Output 3 7 Input 3 1 1 2 3 Output 1 1
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 = lo while len(d) == k + 1: d[lst[lo]] -= 1 if d[lst[lo]] == 0: del d[lst[lo]] lo += 1 if ans2 - ans1 <= hi - 1 - lo: ans2 = hi ans1 = lo print(ans1 + 1, ans2)
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 BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER 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: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. -----Input----- The first line contains two integers n, k (1 ≀ k ≀ n ≀ 5Β·10^5) β€” the number of elements in a and the parameter k. The second line contains n integers a_{i} (0 ≀ a_{i} ≀ 10^6) β€” the elements of the array a. -----Output----- Print two integers l, r (1 ≀ l ≀ r ≀ n) β€” the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right. -----Examples----- Input 5 5 1 2 3 4 5 Output 1 5 Input 9 3 6 5 1 2 3 2 1 4 5 Output 3 7 Input 3 1 1 2 3 Output 1 1
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 for i in otv: print(*i)
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 BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR