description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Chef has $N$ boxes arranged in a line.Each box has some candies in it,say $C[i]$. Chef wants to distribute all the candies between of his friends: $A$ and $B$, in the following way: $A$ starts eating candies kept in the leftmost box(box at $1$st place) and $B$ starts eating candies kept in the rightmost box(box at $N$th place). $A$ eats candies $X$ times faster than $B$ i.e. $A$ eats $X$ candies when $B$ eats only $1$. Candies in each box can be eaten by only the person who reaches that box first. If both reach a box at the same time, then the one who has eaten from more number of BOXES till now will eat the candies in that box. If both have eaten from the same number of boxes till now ,then $A$ will eat the candies in that box. Find the number of boxes finished by both $A$ and $B$. NOTE:- We assume that it does not take any time to switch from one box to another. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains three lines of input. The first line of each test case contains $N$, the number of boxes. - The second line of each test case contains a sequence,$C_1$ ,$C_2$ ,$C_3$ . . . $C_N$ where $C_i$ denotes the number of candies in the i-th box. - The third line of each test case contains an integer $X$ . -----Output:----- For each testcase, print two space separated integers in a new line - the number of boxes eaten by $A$ and $B$ respectively. -----Constraints----- - $1 \leq T \leq 100$ - $1 \leq N \leq 200000$ - $1 \leq C_i \leq 1000000$ - $1 \leq X \leq 10$ - Sum of $N$ over all test cases does not exceed $300000$ -----Subtasks----- Subtask 1(24 points): - $1 \leq T \leq 10$ - $1 \leq N \leq 1000$ - $1 \leq C_i \leq 1000$ - $1 \leq X \leq 10$ Subtask 2(51 points): original constraints -----Sample Input:----- 1 5 2 8 8 2 9 2 -----Sample Output:----- 4 1 -----EXPLANATION:----- $A$ will start eating candies in the 1st box(leftmost box having 2 candies) . $B$ will start eating candies in the 5th box(rightmost box having 9 candies) .As $A's$ speed is 2 times as that of $B's$, $A$ will start eating candies in the 2nd box while $B$ would still be eating candies in the 5th box.$A$ will now start eating candies from the 3rd box while $B$ would still be eating candies in the 5th box.Now both $A$ and $B$ will finish candies in their respective boxes at the same time($A$ from the 3rd box and $B$ from 5th box). Since $A$ has eaten more number of boxes($A$ has eaten 3 boxes while $B$ has eaten 1 box) till now,so $A$ will be eating candies in the 4th box. Hence $A$ has eaten 4 boxes and $B$ has eaten 1 box.
import sys ip = sys.stdin def solve(C, n, x): if n == 1: return 1, 0 b1, b2 = 1, 1 a, b = C[0], C[-1] while b1 + b2 < n: if a < b * x: a += C[b1] b1 += 1 elif a > b * x: b2 += 1 b += C[n - b2] elif b1 >= b2: a += C[b1] b1 += 1 else: b2 += 1 b += C[b2] return b1, b2 t = int(ip.readline()) for _ in range(t): n = int(ip.readline()) C = list(map(int, ip.readline().split())) x = int(ip.readline()) ans = solve(C, n, x) print(*ans)
IMPORT ASSIGN VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL 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 ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Chef has $N$ boxes arranged in a line.Each box has some candies in it,say $C[i]$. Chef wants to distribute all the candies between of his friends: $A$ and $B$, in the following way: $A$ starts eating candies kept in the leftmost box(box at $1$st place) and $B$ starts eating candies kept in the rightmost box(box at $N$th place). $A$ eats candies $X$ times faster than $B$ i.e. $A$ eats $X$ candies when $B$ eats only $1$. Candies in each box can be eaten by only the person who reaches that box first. If both reach a box at the same time, then the one who has eaten from more number of BOXES till now will eat the candies in that box. If both have eaten from the same number of boxes till now ,then $A$ will eat the candies in that box. Find the number of boxes finished by both $A$ and $B$. NOTE:- We assume that it does not take any time to switch from one box to another. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains three lines of input. The first line of each test case contains $N$, the number of boxes. - The second line of each test case contains a sequence,$C_1$ ,$C_2$ ,$C_3$ . . . $C_N$ where $C_i$ denotes the number of candies in the i-th box. - The third line of each test case contains an integer $X$ . -----Output:----- For each testcase, print two space separated integers in a new line - the number of boxes eaten by $A$ and $B$ respectively. -----Constraints----- - $1 \leq T \leq 100$ - $1 \leq N \leq 200000$ - $1 \leq C_i \leq 1000000$ - $1 \leq X \leq 10$ - Sum of $N$ over all test cases does not exceed $300000$ -----Subtasks----- Subtask 1(24 points): - $1 \leq T \leq 10$ - $1 \leq N \leq 1000$ - $1 \leq C_i \leq 1000$ - $1 \leq X \leq 10$ Subtask 2(51 points): original constraints -----Sample Input:----- 1 5 2 8 8 2 9 2 -----Sample Output:----- 4 1 -----EXPLANATION:----- $A$ will start eating candies in the 1st box(leftmost box having 2 candies) . $B$ will start eating candies in the 5th box(rightmost box having 9 candies) .As $A's$ speed is 2 times as that of $B's$, $A$ will start eating candies in the 2nd box while $B$ would still be eating candies in the 5th box.$A$ will now start eating candies from the 3rd box while $B$ would still be eating candies in the 5th box.Now both $A$ and $B$ will finish candies in their respective boxes at the same time($A$ from the 3rd box and $B$ from 5th box). Since $A$ has eaten more number of boxes($A$ has eaten 3 boxes while $B$ has eaten 1 box) till now,so $A$ will be eating candies in the 4th box. Hence $A$ has eaten 4 boxes and $B$ has eaten 1 box.
def main(): t = int(input()) for _ in range(t): n = int(input()) c = list(map(int, input().split())) x = int(input()) if n == 1: print(1, 0) continue e1, e2, b1, b2, i = c[0], c[n - 1], 1, 1, 1 while b1 + b2 < n: if e1 < x * e2: e1 += c[i] b1 += 1 i += 1 elif e1 > x * e2: b2 += 1 e2 += c[n - b2] elif b1 >= b2: e1 += c[i] i += 1 b1 += 1 else: b2 += 1 e2 += c[n - b2] print(b1, b2) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL 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 IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER WHILE BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
Chef has $N$ boxes arranged in a line.Each box has some candies in it,say $C[i]$. Chef wants to distribute all the candies between of his friends: $A$ and $B$, in the following way: $A$ starts eating candies kept in the leftmost box(box at $1$st place) and $B$ starts eating candies kept in the rightmost box(box at $N$th place). $A$ eats candies $X$ times faster than $B$ i.e. $A$ eats $X$ candies when $B$ eats only $1$. Candies in each box can be eaten by only the person who reaches that box first. If both reach a box at the same time, then the one who has eaten from more number of BOXES till now will eat the candies in that box. If both have eaten from the same number of boxes till now ,then $A$ will eat the candies in that box. Find the number of boxes finished by both $A$ and $B$. NOTE:- We assume that it does not take any time to switch from one box to another. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains three lines of input. The first line of each test case contains $N$, the number of boxes. - The second line of each test case contains a sequence,$C_1$ ,$C_2$ ,$C_3$ . . . $C_N$ where $C_i$ denotes the number of candies in the i-th box. - The third line of each test case contains an integer $X$ . -----Output:----- For each testcase, print two space separated integers in a new line - the number of boxes eaten by $A$ and $B$ respectively. -----Constraints----- - $1 \leq T \leq 100$ - $1 \leq N \leq 200000$ - $1 \leq C_i \leq 1000000$ - $1 \leq X \leq 10$ - Sum of $N$ over all test cases does not exceed $300000$ -----Subtasks----- Subtask 1(24 points): - $1 \leq T \leq 10$ - $1 \leq N \leq 1000$ - $1 \leq C_i \leq 1000$ - $1 \leq X \leq 10$ Subtask 2(51 points): original constraints -----Sample Input:----- 1 5 2 8 8 2 9 2 -----Sample Output:----- 4 1 -----EXPLANATION:----- $A$ will start eating candies in the 1st box(leftmost box having 2 candies) . $B$ will start eating candies in the 5th box(rightmost box having 9 candies) .As $A's$ speed is 2 times as that of $B's$, $A$ will start eating candies in the 2nd box while $B$ would still be eating candies in the 5th box.$A$ will now start eating candies from the 3rd box while $B$ would still be eating candies in the 5th box.Now both $A$ and $B$ will finish candies in their respective boxes at the same time($A$ from the 3rd box and $B$ from 5th box). Since $A$ has eaten more number of boxes($A$ has eaten 3 boxes while $B$ has eaten 1 box) till now,so $A$ will be eating candies in the 4th box. Hence $A$ has eaten 4 boxes and $B$ has eaten 1 box.
def candies(n, x, boxes): B = n - 1 A = 0 Aeat = boxes[0] Beat = boxes[n - 1] while B - A > 1: para = Aeat - Beat * x if para == 0: if A + 1 >= n - B: A += 1 Aeat += boxes[A] else: B -= 1 Beat += boxes[B] elif para < 0: A += 1 Aeat += boxes[A] else: B -= 1 Beat += boxes[B] return str(A + 1) + " " + str(n - B) t = int(input()) for z in range(t): n = int(input()) boxes = [int(w) for w in input().split()] x = int(input()) print(candies(n, x, boxes))
FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR VAR RETURN BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR 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 FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
Chef has $N$ boxes arranged in a line.Each box has some candies in it,say $C[i]$. Chef wants to distribute all the candies between of his friends: $A$ and $B$, in the following way: $A$ starts eating candies kept in the leftmost box(box at $1$st place) and $B$ starts eating candies kept in the rightmost box(box at $N$th place). $A$ eats candies $X$ times faster than $B$ i.e. $A$ eats $X$ candies when $B$ eats only $1$. Candies in each box can be eaten by only the person who reaches that box first. If both reach a box at the same time, then the one who has eaten from more number of BOXES till now will eat the candies in that box. If both have eaten from the same number of boxes till now ,then $A$ will eat the candies in that box. Find the number of boxes finished by both $A$ and $B$. NOTE:- We assume that it does not take any time to switch from one box to another. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains three lines of input. The first line of each test case contains $N$, the number of boxes. - The second line of each test case contains a sequence,$C_1$ ,$C_2$ ,$C_3$ . . . $C_N$ where $C_i$ denotes the number of candies in the i-th box. - The third line of each test case contains an integer $X$ . -----Output:----- For each testcase, print two space separated integers in a new line - the number of boxes eaten by $A$ and $B$ respectively. -----Constraints----- - $1 \leq T \leq 100$ - $1 \leq N \leq 200000$ - $1 \leq C_i \leq 1000000$ - $1 \leq X \leq 10$ - Sum of $N$ over all test cases does not exceed $300000$ -----Subtasks----- Subtask 1(24 points): - $1 \leq T \leq 10$ - $1 \leq N \leq 1000$ - $1 \leq C_i \leq 1000$ - $1 \leq X \leq 10$ Subtask 2(51 points): original constraints -----Sample Input:----- 1 5 2 8 8 2 9 2 -----Sample Output:----- 4 1 -----EXPLANATION:----- $A$ will start eating candies in the 1st box(leftmost box having 2 candies) . $B$ will start eating candies in the 5th box(rightmost box having 9 candies) .As $A's$ speed is 2 times as that of $B's$, $A$ will start eating candies in the 2nd box while $B$ would still be eating candies in the 5th box.$A$ will now start eating candies from the 3rd box while $B$ would still be eating candies in the 5th box.Now both $A$ and $B$ will finish candies in their respective boxes at the same time($A$ from the 3rd box and $B$ from 5th box). Since $A$ has eaten more number of boxes($A$ has eaten 3 boxes while $B$ has eaten 1 box) till now,so $A$ will be eating candies in the 4th box. Hence $A$ has eaten 4 boxes and $B$ has eaten 1 box.
try: for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) x = int(input()) left = 0 right = n - 1 count1 = count2 = 0 sum1 = sum2 = 0 while left <= right: if sum1 < x * sum2: sum1 = sum1 + arr[left] left += 1 count1 += 1 elif sum1 > x * sum2: sum2 = sum2 + arr[right] right -= 1 count2 += 1 elif left != right: sum1 = sum1 + arr[left] left += 1 count1 += 1 elif count1 < count2: sum2 = sum2 + arr[right] right -= 1 count2 = count2 + 1 else: sum1 = sum1 + arr[left] left += 1 count1 += 1 print(count1, count2) except: pass
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Chef has $N$ boxes arranged in a line.Each box has some candies in it,say $C[i]$. Chef wants to distribute all the candies between of his friends: $A$ and $B$, in the following way: $A$ starts eating candies kept in the leftmost box(box at $1$st place) and $B$ starts eating candies kept in the rightmost box(box at $N$th place). $A$ eats candies $X$ times faster than $B$ i.e. $A$ eats $X$ candies when $B$ eats only $1$. Candies in each box can be eaten by only the person who reaches that box first. If both reach a box at the same time, then the one who has eaten from more number of BOXES till now will eat the candies in that box. If both have eaten from the same number of boxes till now ,then $A$ will eat the candies in that box. Find the number of boxes finished by both $A$ and $B$. NOTE:- We assume that it does not take any time to switch from one box to another. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains three lines of input. The first line of each test case contains $N$, the number of boxes. - The second line of each test case contains a sequence,$C_1$ ,$C_2$ ,$C_3$ . . . $C_N$ where $C_i$ denotes the number of candies in the i-th box. - The third line of each test case contains an integer $X$ . -----Output:----- For each testcase, print two space separated integers in a new line - the number of boxes eaten by $A$ and $B$ respectively. -----Constraints----- - $1 \leq T \leq 100$ - $1 \leq N \leq 200000$ - $1 \leq C_i \leq 1000000$ - $1 \leq X \leq 10$ - Sum of $N$ over all test cases does not exceed $300000$ -----Subtasks----- Subtask 1(24 points): - $1 \leq T \leq 10$ - $1 \leq N \leq 1000$ - $1 \leq C_i \leq 1000$ - $1 \leq X \leq 10$ Subtask 2(51 points): original constraints -----Sample Input:----- 1 5 2 8 8 2 9 2 -----Sample Output:----- 4 1 -----EXPLANATION:----- $A$ will start eating candies in the 1st box(leftmost box having 2 candies) . $B$ will start eating candies in the 5th box(rightmost box having 9 candies) .As $A's$ speed is 2 times as that of $B's$, $A$ will start eating candies in the 2nd box while $B$ would still be eating candies in the 5th box.$A$ will now start eating candies from the 3rd box while $B$ would still be eating candies in the 5th box.Now both $A$ and $B$ will finish candies in their respective boxes at the same time($A$ from the 3rd box and $B$ from 5th box). Since $A$ has eaten more number of boxes($A$ has eaten 3 boxes while $B$ has eaten 1 box) till now,so $A$ will be eating candies in the 4th box. Hence $A$ has eaten 4 boxes and $B$ has eaten 1 box.
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) x = int(input()) if n == 1: print(1, 0) continue else: sum1 = sum(a) lim = x * int(sum1 / (x + 1)) sumt = 0 f = -1 c1 = 0 while lim > sumt: f += 1 sumt += a[f] c1 += 1 c1 = c1 - 1 for i in range(f, n - 1): t1 = sum(a[:i]) / x t2 = sum(a[i + 1 :]) if t1 < t2: c1 += 1 elif t1 == t2: if i >= n - i - 1: c1 += 1 break else: break print(c1, n - c1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL 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 IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR
Chef has $N$ boxes arranged in a line.Each box has some candies in it,say $C[i]$. Chef wants to distribute all the candies between of his friends: $A$ and $B$, in the following way: $A$ starts eating candies kept in the leftmost box(box at $1$st place) and $B$ starts eating candies kept in the rightmost box(box at $N$th place). $A$ eats candies $X$ times faster than $B$ i.e. $A$ eats $X$ candies when $B$ eats only $1$. Candies in each box can be eaten by only the person who reaches that box first. If both reach a box at the same time, then the one who has eaten from more number of BOXES till now will eat the candies in that box. If both have eaten from the same number of boxes till now ,then $A$ will eat the candies in that box. Find the number of boxes finished by both $A$ and $B$. NOTE:- We assume that it does not take any time to switch from one box to another. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains three lines of input. The first line of each test case contains $N$, the number of boxes. - The second line of each test case contains a sequence,$C_1$ ,$C_2$ ,$C_3$ . . . $C_N$ where $C_i$ denotes the number of candies in the i-th box. - The third line of each test case contains an integer $X$ . -----Output:----- For each testcase, print two space separated integers in a new line - the number of boxes eaten by $A$ and $B$ respectively. -----Constraints----- - $1 \leq T \leq 100$ - $1 \leq N \leq 200000$ - $1 \leq C_i \leq 1000000$ - $1 \leq X \leq 10$ - Sum of $N$ over all test cases does not exceed $300000$ -----Subtasks----- Subtask 1(24 points): - $1 \leq T \leq 10$ - $1 \leq N \leq 1000$ - $1 \leq C_i \leq 1000$ - $1 \leq X \leq 10$ Subtask 2(51 points): original constraints -----Sample Input:----- 1 5 2 8 8 2 9 2 -----Sample Output:----- 4 1 -----EXPLANATION:----- $A$ will start eating candies in the 1st box(leftmost box having 2 candies) . $B$ will start eating candies in the 5th box(rightmost box having 9 candies) .As $A's$ speed is 2 times as that of $B's$, $A$ will start eating candies in the 2nd box while $B$ would still be eating candies in the 5th box.$A$ will now start eating candies from the 3rd box while $B$ would still be eating candies in the 5th box.Now both $A$ and $B$ will finish candies in their respective boxes at the same time($A$ from the 3rd box and $B$ from 5th box). Since $A$ has eaten more number of boxes($A$ has eaten 3 boxes while $B$ has eaten 1 box) till now,so $A$ will be eating candies in the 4th box. Hence $A$ has eaten 4 boxes and $B$ has eaten 1 box.
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) x = int(input()) abox = 0 bbox = 0 i = 0 j = n - 1 while n > 0: if j != i: v = x * arr[j] n -= 1 summ = 0 for f in range(i, j): if summ + arr[f] <= v: summ += arr[f] abox += 1 n -= 1 else: arr[f] = summ + arr[f] - v i = f break bbox += 1 j -= 1 elif j == i: if abox >= bbox: abox += 1 n -= 1 else: bbox += 1 n -= 1 print(abox, bbox)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Chef has $N$ boxes arranged in a line.Each box has some candies in it,say $C[i]$. Chef wants to distribute all the candies between of his friends: $A$ and $B$, in the following way: $A$ starts eating candies kept in the leftmost box(box at $1$st place) and $B$ starts eating candies kept in the rightmost box(box at $N$th place). $A$ eats candies $X$ times faster than $B$ i.e. $A$ eats $X$ candies when $B$ eats only $1$. Candies in each box can be eaten by only the person who reaches that box first. If both reach a box at the same time, then the one who has eaten from more number of BOXES till now will eat the candies in that box. If both have eaten from the same number of boxes till now ,then $A$ will eat the candies in that box. Find the number of boxes finished by both $A$ and $B$. NOTE:- We assume that it does not take any time to switch from one box to another. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains three lines of input. The first line of each test case contains $N$, the number of boxes. - The second line of each test case contains a sequence,$C_1$ ,$C_2$ ,$C_3$ . . . $C_N$ where $C_i$ denotes the number of candies in the i-th box. - The third line of each test case contains an integer $X$ . -----Output:----- For each testcase, print two space separated integers in a new line - the number of boxes eaten by $A$ and $B$ respectively. -----Constraints----- - $1 \leq T \leq 100$ - $1 \leq N \leq 200000$ - $1 \leq C_i \leq 1000000$ - $1 \leq X \leq 10$ - Sum of $N$ over all test cases does not exceed $300000$ -----Subtasks----- Subtask 1(24 points): - $1 \leq T \leq 10$ - $1 \leq N \leq 1000$ - $1 \leq C_i \leq 1000$ - $1 \leq X \leq 10$ Subtask 2(51 points): original constraints -----Sample Input:----- 1 5 2 8 8 2 9 2 -----Sample Output:----- 4 1 -----EXPLANATION:----- $A$ will start eating candies in the 1st box(leftmost box having 2 candies) . $B$ will start eating candies in the 5th box(rightmost box having 9 candies) .As $A's$ speed is 2 times as that of $B's$, $A$ will start eating candies in the 2nd box while $B$ would still be eating candies in the 5th box.$A$ will now start eating candies from the 3rd box while $B$ would still be eating candies in the 5th box.Now both $A$ and $B$ will finish candies in their respective boxes at the same time($A$ from the 3rd box and $B$ from 5th box). Since $A$ has eaten more number of boxes($A$ has eaten 3 boxes while $B$ has eaten 1 box) till now,so $A$ will be eating candies in the 4th box. Hence $A$ has eaten 4 boxes and $B$ has eaten 1 box.
import sys sys.setrecursionlimit(200000) def processor(input_list, a, b, x): if a == b: number_of_boxes_eaten_by_a = a - 0 number_of_boxes_eaten_by_b = len(input_list) - 1 - b if number_of_boxes_eaten_by_a >= number_of_boxes_eaten_by_b: return a else: return a - 1 elif a + 1 == b: return a elif input_list[a] == input_list[b] * x: return processor(input_list, a + 1, b - 1, x) elif input_list[a] > input_list[b] * x: input_list[a] = input_list[a] - input_list[b] * x return processor(input_list, a, b - 1, x) else: input_list[b] = input_list[b] - input_list[a] / x return processor(input_list, a + 1, b, x) def ans(input_list, x): pos_a = processor(input_list, 0, len(input_list) - 1, x) + 1 return pos_a, len(input_list) - pos_a for _ in range(int(input())): N = int(input()) C = list(map(int, input().split())) X = int(input()) for i in C: i *= X Ans = ans(C, X) print(*Ans, sep=" ")
IMPORT EXPR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR IF VAR VAR RETURN VAR RETURN BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR RETURN VAR IF VAR VAR BIN_OP VAR VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER RETURN VAR BIN_OP FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 FOR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING
Chef has $N$ boxes arranged in a line.Each box has some candies in it,say $C[i]$. Chef wants to distribute all the candies between of his friends: $A$ and $B$, in the following way: $A$ starts eating candies kept in the leftmost box(box at $1$st place) and $B$ starts eating candies kept in the rightmost box(box at $N$th place). $A$ eats candies $X$ times faster than $B$ i.e. $A$ eats $X$ candies when $B$ eats only $1$. Candies in each box can be eaten by only the person who reaches that box first. If both reach a box at the same time, then the one who has eaten from more number of BOXES till now will eat the candies in that box. If both have eaten from the same number of boxes till now ,then $A$ will eat the candies in that box. Find the number of boxes finished by both $A$ and $B$. NOTE:- We assume that it does not take any time to switch from one box to another. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains three lines of input. The first line of each test case contains $N$, the number of boxes. - The second line of each test case contains a sequence,$C_1$ ,$C_2$ ,$C_3$ . . . $C_N$ where $C_i$ denotes the number of candies in the i-th box. - The third line of each test case contains an integer $X$ . -----Output:----- For each testcase, print two space separated integers in a new line - the number of boxes eaten by $A$ and $B$ respectively. -----Constraints----- - $1 \leq T \leq 100$ - $1 \leq N \leq 200000$ - $1 \leq C_i \leq 1000000$ - $1 \leq X \leq 10$ - Sum of $N$ over all test cases does not exceed $300000$ -----Subtasks----- Subtask 1(24 points): - $1 \leq T \leq 10$ - $1 \leq N \leq 1000$ - $1 \leq C_i \leq 1000$ - $1 \leq X \leq 10$ Subtask 2(51 points): original constraints -----Sample Input:----- 1 5 2 8 8 2 9 2 -----Sample Output:----- 4 1 -----EXPLANATION:----- $A$ will start eating candies in the 1st box(leftmost box having 2 candies) . $B$ will start eating candies in the 5th box(rightmost box having 9 candies) .As $A's$ speed is 2 times as that of $B's$, $A$ will start eating candies in the 2nd box while $B$ would still be eating candies in the 5th box.$A$ will now start eating candies from the 3rd box while $B$ would still be eating candies in the 5th box.Now both $A$ and $B$ will finish candies in their respective boxes at the same time($A$ from the 3rd box and $B$ from 5th box). Since $A$ has eaten more number of boxes($A$ has eaten 3 boxes while $B$ has eaten 1 box) till now,so $A$ will be eating candies in the 4th box. Hence $A$ has eaten 4 boxes and $B$ has eaten 1 box.
try: for i in range(int(input())): n = int(input()) l = list(map(int, input().split())) x = int(input()) i = 0 j = n - 1 bi = 0 bj = 1 count1 = l[j] * x while i < j: if count1 > 0 and i != j: if l[i] <= count1: count1 = count1 - l[i] i = i + 1 bi = bi + 1 else: l[i] = l[i] - count1 count1 = 0 if count1 <= 0: j = j - 1 count1 = count1 + l[j] * x if i != j: bj = bj + 1 elif bi > bj: bi = bi + 1 elif bi < bj: bj = bj + 1 else: bi = bi + 1 print(bi, bj) except: pass
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR WHILE VAR VAR IF VAR NUMBER VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Chef has $N$ boxes arranged in a line.Each box has some candies in it,say $C[i]$. Chef wants to distribute all the candies between of his friends: $A$ and $B$, in the following way: $A$ starts eating candies kept in the leftmost box(box at $1$st place) and $B$ starts eating candies kept in the rightmost box(box at $N$th place). $A$ eats candies $X$ times faster than $B$ i.e. $A$ eats $X$ candies when $B$ eats only $1$. Candies in each box can be eaten by only the person who reaches that box first. If both reach a box at the same time, then the one who has eaten from more number of BOXES till now will eat the candies in that box. If both have eaten from the same number of boxes till now ,then $A$ will eat the candies in that box. Find the number of boxes finished by both $A$ and $B$. NOTE:- We assume that it does not take any time to switch from one box to another. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains three lines of input. The first line of each test case contains $N$, the number of boxes. - The second line of each test case contains a sequence,$C_1$ ,$C_2$ ,$C_3$ . . . $C_N$ where $C_i$ denotes the number of candies in the i-th box. - The third line of each test case contains an integer $X$ . -----Output:----- For each testcase, print two space separated integers in a new line - the number of boxes eaten by $A$ and $B$ respectively. -----Constraints----- - $1 \leq T \leq 100$ - $1 \leq N \leq 200000$ - $1 \leq C_i \leq 1000000$ - $1 \leq X \leq 10$ - Sum of $N$ over all test cases does not exceed $300000$ -----Subtasks----- Subtask 1(24 points): - $1 \leq T \leq 10$ - $1 \leq N \leq 1000$ - $1 \leq C_i \leq 1000$ - $1 \leq X \leq 10$ Subtask 2(51 points): original constraints -----Sample Input:----- 1 5 2 8 8 2 9 2 -----Sample Output:----- 4 1 -----EXPLANATION:----- $A$ will start eating candies in the 1st box(leftmost box having 2 candies) . $B$ will start eating candies in the 5th box(rightmost box having 9 candies) .As $A's$ speed is 2 times as that of $B's$, $A$ will start eating candies in the 2nd box while $B$ would still be eating candies in the 5th box.$A$ will now start eating candies from the 3rd box while $B$ would still be eating candies in the 5th box.Now both $A$ and $B$ will finish candies in their respective boxes at the same time($A$ from the 3rd box and $B$ from 5th box). Since $A$ has eaten more number of boxes($A$ has eaten 3 boxes while $B$ has eaten 1 box) till now,so $A$ will be eating candies in the 4th box. Hence $A$ has eaten 4 boxes and $B$ has eaten 1 box.
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) x = int(input()) c1 = 1 if n == 1: print(1, 0) continue else: for i in range(1, n - 1): t1 = sum(a[:i]) / x t2 = sum(a[i + 1 :]) if t1 < t2: c1 += 1 elif t1 == t2: if i >= n - i - 1: c1 += 1 break else: break print(c1, n - c1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL 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 ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR
Chef has $N$ boxes arranged in a line.Each box has some candies in it,say $C[i]$. Chef wants to distribute all the candies between of his friends: $A$ and $B$, in the following way: $A$ starts eating candies kept in the leftmost box(box at $1$st place) and $B$ starts eating candies kept in the rightmost box(box at $N$th place). $A$ eats candies $X$ times faster than $B$ i.e. $A$ eats $X$ candies when $B$ eats only $1$. Candies in each box can be eaten by only the person who reaches that box first. If both reach a box at the same time, then the one who has eaten from more number of BOXES till now will eat the candies in that box. If both have eaten from the same number of boxes till now ,then $A$ will eat the candies in that box. Find the number of boxes finished by both $A$ and $B$. NOTE:- We assume that it does not take any time to switch from one box to another. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains three lines of input. The first line of each test case contains $N$, the number of boxes. - The second line of each test case contains a sequence,$C_1$ ,$C_2$ ,$C_3$ . . . $C_N$ where $C_i$ denotes the number of candies in the i-th box. - The third line of each test case contains an integer $X$ . -----Output:----- For each testcase, print two space separated integers in a new line - the number of boxes eaten by $A$ and $B$ respectively. -----Constraints----- - $1 \leq T \leq 100$ - $1 \leq N \leq 200000$ - $1 \leq C_i \leq 1000000$ - $1 \leq X \leq 10$ - Sum of $N$ over all test cases does not exceed $300000$ -----Subtasks----- Subtask 1(24 points): - $1 \leq T \leq 10$ - $1 \leq N \leq 1000$ - $1 \leq C_i \leq 1000$ - $1 \leq X \leq 10$ Subtask 2(51 points): original constraints -----Sample Input:----- 1 5 2 8 8 2 9 2 -----Sample Output:----- 4 1 -----EXPLANATION:----- $A$ will start eating candies in the 1st box(leftmost box having 2 candies) . $B$ will start eating candies in the 5th box(rightmost box having 9 candies) .As $A's$ speed is 2 times as that of $B's$, $A$ will start eating candies in the 2nd box while $B$ would still be eating candies in the 5th box.$A$ will now start eating candies from the 3rd box while $B$ would still be eating candies in the 5th box.Now both $A$ and $B$ will finish candies in their respective boxes at the same time($A$ from the 3rd box and $B$ from 5th box). Since $A$ has eaten more number of boxes($A$ has eaten 3 boxes while $B$ has eaten 1 box) till now,so $A$ will be eating candies in the 4th box. Hence $A$ has eaten 4 boxes and $B$ has eaten 1 box.
t = int(input()) while t: t -= 1 n = int(input()) arr = list(map(int, input().split())) x = int(input()) if n == 1: print("1 0") else: currentIndexOfA = 0 currentIndexOfB = n - 1 carry = 0 while currentIndexOfA + 1 < currentIndexOfB: if (arr[currentIndexOfA] + carry) // x < arr[currentIndexOfB]: arr[currentIndexOfB] -= (arr[currentIndexOfA] + carry) // x carry = (arr[currentIndexOfA] + carry) % x arr[currentIndexOfA] = 0 currentIndexOfA += 1 elif (arr[currentIndexOfA] + carry) // x > arr[currentIndexOfB]: s = (arr[currentIndexOfA] + carry) // x carry = (arr[currentIndexOfA] + carry) % x flag = False while s > 0: if s >= arr[currentIndexOfB]: s -= arr[currentIndexOfB] arr[currentIndexOfB] = 0 currentIndexOfB -= 1 else: arr[currentIndexOfB] -= s s = 0 if currentIndexOfB - 1 == currentIndexOfA: flag = True break if flag: break currentIndexOfA += 1 elif (arr[currentIndexOfA] + carry) // x == arr[currentIndexOfB]: carry = (arr[currentIndexOfA] + carry) % x arr[currentIndexOfA] = 0 arr[currentIndexOfB] = 0 currentIndexOfA += 1 currentIndexOfB -= 1 if currentIndexOfB == currentIndexOfA and carry == 0: if ( n - 1 - currentIndexOfA == currentIndexOfA or currentIndexOfA > n - 1 - currentIndexOfA ): currentIndexOfB += 1 else: currentIndexOfA -= 1 break elif currentIndexOfA == currentIndexOfB: currentIndexOfA -= 1 break print(f"{currentIndexOfA + 1} {n - currentIndexOfB}")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR 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 IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING BIN_OP VAR VAR
Chef has $N$ boxes arranged in a line.Each box has some candies in it,say $C[i]$. Chef wants to distribute all the candies between of his friends: $A$ and $B$, in the following way: $A$ starts eating candies kept in the leftmost box(box at $1$st place) and $B$ starts eating candies kept in the rightmost box(box at $N$th place). $A$ eats candies $X$ times faster than $B$ i.e. $A$ eats $X$ candies when $B$ eats only $1$. Candies in each box can be eaten by only the person who reaches that box first. If both reach a box at the same time, then the one who has eaten from more number of BOXES till now will eat the candies in that box. If both have eaten from the same number of boxes till now ,then $A$ will eat the candies in that box. Find the number of boxes finished by both $A$ and $B$. NOTE:- We assume that it does not take any time to switch from one box to another. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains three lines of input. The first line of each test case contains $N$, the number of boxes. - The second line of each test case contains a sequence,$C_1$ ,$C_2$ ,$C_3$ . . . $C_N$ where $C_i$ denotes the number of candies in the i-th box. - The third line of each test case contains an integer $X$ . -----Output:----- For each testcase, print two space separated integers in a new line - the number of boxes eaten by $A$ and $B$ respectively. -----Constraints----- - $1 \leq T \leq 100$ - $1 \leq N \leq 200000$ - $1 \leq C_i \leq 1000000$ - $1 \leq X \leq 10$ - Sum of $N$ over all test cases does not exceed $300000$ -----Subtasks----- Subtask 1(24 points): - $1 \leq T \leq 10$ - $1 \leq N \leq 1000$ - $1 \leq C_i \leq 1000$ - $1 \leq X \leq 10$ Subtask 2(51 points): original constraints -----Sample Input:----- 1 5 2 8 8 2 9 2 -----Sample Output:----- 4 1 -----EXPLANATION:----- $A$ will start eating candies in the 1st box(leftmost box having 2 candies) . $B$ will start eating candies in the 5th box(rightmost box having 9 candies) .As $A's$ speed is 2 times as that of $B's$, $A$ will start eating candies in the 2nd box while $B$ would still be eating candies in the 5th box.$A$ will now start eating candies from the 3rd box while $B$ would still be eating candies in the 5th box.Now both $A$ and $B$ will finish candies in their respective boxes at the same time($A$ from the 3rd box and $B$ from 5th box). Since $A$ has eaten more number of boxes($A$ has eaten 3 boxes while $B$ has eaten 1 box) till now,so $A$ will be eating candies in the 4th box. Hence $A$ has eaten 4 boxes and $B$ has eaten 1 box.
for _ in range(int(input())): n = int(input()) l = [int(i) for i in input().split()] x = int(input()) i = 0 j = n - 1 a = 0 b = 0 f = 0 while 1: temp = l[j] * x while i < j and temp: f = 0 temp2 = min(l[i], temp) l[i] -= temp2 temp -= temp2 if not l[i]: f = 1 a += 1 i += 1 if i == j: b += 1 break j -= 1 b += 1 if i == j: if f: if b > a: b += 1 else: a += 1 else: a += 1 break print(a, b)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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 FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP VAR VAR VAR WHILE VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR IF VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Chef has $N$ boxes arranged in a line.Each box has some candies in it,say $C[i]$. Chef wants to distribute all the candies between of his friends: $A$ and $B$, in the following way: $A$ starts eating candies kept in the leftmost box(box at $1$st place) and $B$ starts eating candies kept in the rightmost box(box at $N$th place). $A$ eats candies $X$ times faster than $B$ i.e. $A$ eats $X$ candies when $B$ eats only $1$. Candies in each box can be eaten by only the person who reaches that box first. If both reach a box at the same time, then the one who has eaten from more number of BOXES till now will eat the candies in that box. If both have eaten from the same number of boxes till now ,then $A$ will eat the candies in that box. Find the number of boxes finished by both $A$ and $B$. NOTE:- We assume that it does not take any time to switch from one box to another. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains three lines of input. The first line of each test case contains $N$, the number of boxes. - The second line of each test case contains a sequence,$C_1$ ,$C_2$ ,$C_3$ . . . $C_N$ where $C_i$ denotes the number of candies in the i-th box. - The third line of each test case contains an integer $X$ . -----Output:----- For each testcase, print two space separated integers in a new line - the number of boxes eaten by $A$ and $B$ respectively. -----Constraints----- - $1 \leq T \leq 100$ - $1 \leq N \leq 200000$ - $1 \leq C_i \leq 1000000$ - $1 \leq X \leq 10$ - Sum of $N$ over all test cases does not exceed $300000$ -----Subtasks----- Subtask 1(24 points): - $1 \leq T \leq 10$ - $1 \leq N \leq 1000$ - $1 \leq C_i \leq 1000$ - $1 \leq X \leq 10$ Subtask 2(51 points): original constraints -----Sample Input:----- 1 5 2 8 8 2 9 2 -----Sample Output:----- 4 1 -----EXPLANATION:----- $A$ will start eating candies in the 1st box(leftmost box having 2 candies) . $B$ will start eating candies in the 5th box(rightmost box having 9 candies) .As $A's$ speed is 2 times as that of $B's$, $A$ will start eating candies in the 2nd box while $B$ would still be eating candies in the 5th box.$A$ will now start eating candies from the 3rd box while $B$ would still be eating candies in the 5th box.Now both $A$ and $B$ will finish candies in their respective boxes at the same time($A$ from the 3rd box and $B$ from 5th box). Since $A$ has eaten more number of boxes($A$ has eaten 3 boxes while $B$ has eaten 1 box) till now,so $A$ will be eating candies in the 4th box. Hence $A$ has eaten 4 boxes and $B$ has eaten 1 box.
t = int(input().strip()) for _ in range(t): n = int(input().strip()) arr = list(map(int, input().strip().split())) x = int(input().strip()) candies_left = [] sm = 0 for i in arr: sm += i candies_left.append(sm) candies_left.append(0) candies = 0 ans = False for i in range(n - 1, 0, -1): if candies + x * arr[i] > candies_left[i - 2]: print(str(i) + " " + str(n - i)) ans = True break elif candies + x * arr[i] == candies_left[i - 2]: if i - 1 >= n - i: print(str(i) + " " + str(n - i)) ans = True break else: print(str(i - 1) + " " + str(n - i + 1)) ans = True break else: candies += x * arr[i] if not ans: print(str(1) + " " + str(n - 1))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL 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 FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR VAR VAR IF VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER
Chef has $N$ boxes arranged in a line.Each box has some candies in it,say $C[i]$. Chef wants to distribute all the candies between of his friends: $A$ and $B$, in the following way: $A$ starts eating candies kept in the leftmost box(box at $1$st place) and $B$ starts eating candies kept in the rightmost box(box at $N$th place). $A$ eats candies $X$ times faster than $B$ i.e. $A$ eats $X$ candies when $B$ eats only $1$. Candies in each box can be eaten by only the person who reaches that box first. If both reach a box at the same time, then the one who has eaten from more number of BOXES till now will eat the candies in that box. If both have eaten from the same number of boxes till now ,then $A$ will eat the candies in that box. Find the number of boxes finished by both $A$ and $B$. NOTE:- We assume that it does not take any time to switch from one box to another. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains three lines of input. The first line of each test case contains $N$, the number of boxes. - The second line of each test case contains a sequence,$C_1$ ,$C_2$ ,$C_3$ . . . $C_N$ where $C_i$ denotes the number of candies in the i-th box. - The third line of each test case contains an integer $X$ . -----Output:----- For each testcase, print two space separated integers in a new line - the number of boxes eaten by $A$ and $B$ respectively. -----Constraints----- - $1 \leq T \leq 100$ - $1 \leq N \leq 200000$ - $1 \leq C_i \leq 1000000$ - $1 \leq X \leq 10$ - Sum of $N$ over all test cases does not exceed $300000$ -----Subtasks----- Subtask 1(24 points): - $1 \leq T \leq 10$ - $1 \leq N \leq 1000$ - $1 \leq C_i \leq 1000$ - $1 \leq X \leq 10$ Subtask 2(51 points): original constraints -----Sample Input:----- 1 5 2 8 8 2 9 2 -----Sample Output:----- 4 1 -----EXPLANATION:----- $A$ will start eating candies in the 1st box(leftmost box having 2 candies) . $B$ will start eating candies in the 5th box(rightmost box having 9 candies) .As $A's$ speed is 2 times as that of $B's$, $A$ will start eating candies in the 2nd box while $B$ would still be eating candies in the 5th box.$A$ will now start eating candies from the 3rd box while $B$ would still be eating candies in the 5th box.Now both $A$ and $B$ will finish candies in their respective boxes at the same time($A$ from the 3rd box and $B$ from 5th box). Since $A$ has eaten more number of boxes($A$ has eaten 3 boxes while $B$ has eaten 1 box) till now,so $A$ will be eating candies in the 4th box. Hence $A$ has eaten 4 boxes and $B$ has eaten 1 box.
t = int(input()) for tt in range(t): n = int(input()) s = list(map(int, input().split())) x = int(input()) sum = [] count = 0 low = -1 high = n if n == 1: print("1 0") continue counta = 0 countb = 0 timea = 0 timeb = 0 while 1: if low >= high - 1: break if timea < timeb: low += 1 timea += s[low] / x counta += 1 elif timea > timeb: high -= 1 timeb += s[high] countb += 1 elif counta >= countb: low += 1 timea += s[low] / x counta += 1 else: high -= 1 timeb += s[high] countb += 1 print(counta, countb)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL 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 ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Chef has $N$ boxes arranged in a line.Each box has some candies in it,say $C[i]$. Chef wants to distribute all the candies between of his friends: $A$ and $B$, in the following way: $A$ starts eating candies kept in the leftmost box(box at $1$st place) and $B$ starts eating candies kept in the rightmost box(box at $N$th place). $A$ eats candies $X$ times faster than $B$ i.e. $A$ eats $X$ candies when $B$ eats only $1$. Candies in each box can be eaten by only the person who reaches that box first. If both reach a box at the same time, then the one who has eaten from more number of BOXES till now will eat the candies in that box. If both have eaten from the same number of boxes till now ,then $A$ will eat the candies in that box. Find the number of boxes finished by both $A$ and $B$. NOTE:- We assume that it does not take any time to switch from one box to another. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains three lines of input. The first line of each test case contains $N$, the number of boxes. - The second line of each test case contains a sequence,$C_1$ ,$C_2$ ,$C_3$ . . . $C_N$ where $C_i$ denotes the number of candies in the i-th box. - The third line of each test case contains an integer $X$ . -----Output:----- For each testcase, print two space separated integers in a new line - the number of boxes eaten by $A$ and $B$ respectively. -----Constraints----- - $1 \leq T \leq 100$ - $1 \leq N \leq 200000$ - $1 \leq C_i \leq 1000000$ - $1 \leq X \leq 10$ - Sum of $N$ over all test cases does not exceed $300000$ -----Subtasks----- Subtask 1(24 points): - $1 \leq T \leq 10$ - $1 \leq N \leq 1000$ - $1 \leq C_i \leq 1000$ - $1 \leq X \leq 10$ Subtask 2(51 points): original constraints -----Sample Input:----- 1 5 2 8 8 2 9 2 -----Sample Output:----- 4 1 -----EXPLANATION:----- $A$ will start eating candies in the 1st box(leftmost box having 2 candies) . $B$ will start eating candies in the 5th box(rightmost box having 9 candies) .As $A's$ speed is 2 times as that of $B's$, $A$ will start eating candies in the 2nd box while $B$ would still be eating candies in the 5th box.$A$ will now start eating candies from the 3rd box while $B$ would still be eating candies in the 5th box.Now both $A$ and $B$ will finish candies in their respective boxes at the same time($A$ from the 3rd box and $B$ from 5th box). Since $A$ has eaten more number of boxes($A$ has eaten 3 boxes while $B$ has eaten 1 box) till now,so $A$ will be eating candies in the 4th box. Hence $A$ has eaten 4 boxes and $B$ has eaten 1 box.
t = int(input()) for w in range(t): def myanswer(number, iter, j, ba, bb, my_array, y, z): while iter != j and ba + bb < number: while y != 0: if y > z: y -= z iter += 1 ba += 1 z = my_array[iter] elif y == z: iter += 1 j -= 1 if iter != j: ba += 1 bb += 1 y = x * my_array[j] z = my_array[iter] else: if ba >= bb: ba += 1 else: bb += 1 break else: z -= y j -= 1 if iter != j: bb += 1 y = x * my_array[j] break else: break if iter == j or ba + bb == number: break print(ba, bb) number = int(input()) my_array = list(map(int, input().split())) x = int(input()) c = [0] * number iter = 0 j = number - 1 ba = 1 bb = 1 y = x * my_array[j] z = my_array[iter] myanswer(number, iter, j, ba, bb, my_array, y, z)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FUNC_DEF WHILE VAR VAR BIN_OP VAR VAR VAR WHILE VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR 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 ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR
Chef has $N$ boxes arranged in a line.Each box has some candies in it,say $C[i]$. Chef wants to distribute all the candies between of his friends: $A$ and $B$, in the following way: $A$ starts eating candies kept in the leftmost box(box at $1$st place) and $B$ starts eating candies kept in the rightmost box(box at $N$th place). $A$ eats candies $X$ times faster than $B$ i.e. $A$ eats $X$ candies when $B$ eats only $1$. Candies in each box can be eaten by only the person who reaches that box first. If both reach a box at the same time, then the one who has eaten from more number of BOXES till now will eat the candies in that box. If both have eaten from the same number of boxes till now ,then $A$ will eat the candies in that box. Find the number of boxes finished by both $A$ and $B$. NOTE:- We assume that it does not take any time to switch from one box to another. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains three lines of input. The first line of each test case contains $N$, the number of boxes. - The second line of each test case contains a sequence,$C_1$ ,$C_2$ ,$C_3$ . . . $C_N$ where $C_i$ denotes the number of candies in the i-th box. - The third line of each test case contains an integer $X$ . -----Output:----- For each testcase, print two space separated integers in a new line - the number of boxes eaten by $A$ and $B$ respectively. -----Constraints----- - $1 \leq T \leq 100$ - $1 \leq N \leq 200000$ - $1 \leq C_i \leq 1000000$ - $1 \leq X \leq 10$ - Sum of $N$ over all test cases does not exceed $300000$ -----Subtasks----- Subtask 1(24 points): - $1 \leq T \leq 10$ - $1 \leq N \leq 1000$ - $1 \leq C_i \leq 1000$ - $1 \leq X \leq 10$ Subtask 2(51 points): original constraints -----Sample Input:----- 1 5 2 8 8 2 9 2 -----Sample Output:----- 4 1 -----EXPLANATION:----- $A$ will start eating candies in the 1st box(leftmost box having 2 candies) . $B$ will start eating candies in the 5th box(rightmost box having 9 candies) .As $A's$ speed is 2 times as that of $B's$, $A$ will start eating candies in the 2nd box while $B$ would still be eating candies in the 5th box.$A$ will now start eating candies from the 3rd box while $B$ would still be eating candies in the 5th box.Now both $A$ and $B$ will finish candies in their respective boxes at the same time($A$ from the 3rd box and $B$ from 5th box). Since $A$ has eaten more number of boxes($A$ has eaten 3 boxes while $B$ has eaten 1 box) till now,so $A$ will be eating candies in the 4th box. Hence $A$ has eaten 4 boxes and $B$ has eaten 1 box.
t = int(input()) mod = pow(10, 9) + 7 for y in range(t): n = int(input()) a = list(map(int, input().split())) x = int(input()) ca = 0 cb = 0 aflag = bflag = 0 while ca < n - 1 - cb: t = a[ca] // x if a[ca] % x != 0: aflag = 1 else: aflag = 0 a[ca + 1] += a[ca] % x ca += 1 s = a[n - 1 - cb] - t if s == 0: cb += 1 bflag = 0 elif s > 0: a[n - 1 - cb] -= t bflag = 1 else: bflag = 1 while s < 0 and ca < n - 1 - cb: cb += 1 prev = s s = s + a[n - 1 - cb] a[n - 1 - cb] += prev if s == 0: cb += 1 bflag = 0 if ca + cb == n - 1: if cb > ca or aflag == 1 or bflag == 1: cb += 1 else: ca += 1 print(ca, cb)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Chef has $N$ boxes arranged in a line.Each box has some candies in it,say $C[i]$. Chef wants to distribute all the candies between of his friends: $A$ and $B$, in the following way: $A$ starts eating candies kept in the leftmost box(box at $1$st place) and $B$ starts eating candies kept in the rightmost box(box at $N$th place). $A$ eats candies $X$ times faster than $B$ i.e. $A$ eats $X$ candies when $B$ eats only $1$. Candies in each box can be eaten by only the person who reaches that box first. If both reach a box at the same time, then the one who has eaten from more number of BOXES till now will eat the candies in that box. If both have eaten from the same number of boxes till now ,then $A$ will eat the candies in that box. Find the number of boxes finished by both $A$ and $B$. NOTE:- We assume that it does not take any time to switch from one box to another. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains three lines of input. The first line of each test case contains $N$, the number of boxes. - The second line of each test case contains a sequence,$C_1$ ,$C_2$ ,$C_3$ . . . $C_N$ where $C_i$ denotes the number of candies in the i-th box. - The third line of each test case contains an integer $X$ . -----Output:----- For each testcase, print two space separated integers in a new line - the number of boxes eaten by $A$ and $B$ respectively. -----Constraints----- - $1 \leq T \leq 100$ - $1 \leq N \leq 200000$ - $1 \leq C_i \leq 1000000$ - $1 \leq X \leq 10$ - Sum of $N$ over all test cases does not exceed $300000$ -----Subtasks----- Subtask 1(24 points): - $1 \leq T \leq 10$ - $1 \leq N \leq 1000$ - $1 \leq C_i \leq 1000$ - $1 \leq X \leq 10$ Subtask 2(51 points): original constraints -----Sample Input:----- 1 5 2 8 8 2 9 2 -----Sample Output:----- 4 1 -----EXPLANATION:----- $A$ will start eating candies in the 1st box(leftmost box having 2 candies) . $B$ will start eating candies in the 5th box(rightmost box having 9 candies) .As $A's$ speed is 2 times as that of $B's$, $A$ will start eating candies in the 2nd box while $B$ would still be eating candies in the 5th box.$A$ will now start eating candies from the 3rd box while $B$ would still be eating candies in the 5th box.Now both $A$ and $B$ will finish candies in their respective boxes at the same time($A$ from the 3rd box and $B$ from 5th box). Since $A$ has eaten more number of boxes($A$ has eaten 3 boxes while $B$ has eaten 1 box) till now,so $A$ will be eating candies in the 4th box. Hence $A$ has eaten 4 boxes and $B$ has eaten 1 box.
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) x = int(input()) left, right = 0, n - 1 c1, c2 = 0, 0 b1, b2 = 0, 0 while left <= right: if c1 < x * c2: c1 += arr[left] left += 1 b1 += 1 elif c1 > x * c2: c2 += arr[right] right -= 1 b2 += 1 elif left != right: c1 += arr[left] left += 1 b1 += 1 elif b1 < b2: c2 += arr[right] right -= 1 b2 += 1 else: c1 += arr[left] left += 1 b1 += 1 print(b1, b2)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR IF VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Chef has $N$ boxes arranged in a line.Each box has some candies in it,say $C[i]$. Chef wants to distribute all the candies between of his friends: $A$ and $B$, in the following way: $A$ starts eating candies kept in the leftmost box(box at $1$st place) and $B$ starts eating candies kept in the rightmost box(box at $N$th place). $A$ eats candies $X$ times faster than $B$ i.e. $A$ eats $X$ candies when $B$ eats only $1$. Candies in each box can be eaten by only the person who reaches that box first. If both reach a box at the same time, then the one who has eaten from more number of BOXES till now will eat the candies in that box. If both have eaten from the same number of boxes till now ,then $A$ will eat the candies in that box. Find the number of boxes finished by both $A$ and $B$. NOTE:- We assume that it does not take any time to switch from one box to another. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains three lines of input. The first line of each test case contains $N$, the number of boxes. - The second line of each test case contains a sequence,$C_1$ ,$C_2$ ,$C_3$ . . . $C_N$ where $C_i$ denotes the number of candies in the i-th box. - The third line of each test case contains an integer $X$ . -----Output:----- For each testcase, print two space separated integers in a new line - the number of boxes eaten by $A$ and $B$ respectively. -----Constraints----- - $1 \leq T \leq 100$ - $1 \leq N \leq 200000$ - $1 \leq C_i \leq 1000000$ - $1 \leq X \leq 10$ - Sum of $N$ over all test cases does not exceed $300000$ -----Subtasks----- Subtask 1(24 points): - $1 \leq T \leq 10$ - $1 \leq N \leq 1000$ - $1 \leq C_i \leq 1000$ - $1 \leq X \leq 10$ Subtask 2(51 points): original constraints -----Sample Input:----- 1 5 2 8 8 2 9 2 -----Sample Output:----- 4 1 -----EXPLANATION:----- $A$ will start eating candies in the 1st box(leftmost box having 2 candies) . $B$ will start eating candies in the 5th box(rightmost box having 9 candies) .As $A's$ speed is 2 times as that of $B's$, $A$ will start eating candies in the 2nd box while $B$ would still be eating candies in the 5th box.$A$ will now start eating candies from the 3rd box while $B$ would still be eating candies in the 5th box.Now both $A$ and $B$ will finish candies in their respective boxes at the same time($A$ from the 3rd box and $B$ from 5th box). Since $A$ has eaten more number of boxes($A$ has eaten 3 boxes while $B$ has eaten 1 box) till now,so $A$ will be eating candies in the 4th box. Hence $A$ has eaten 4 boxes and $B$ has eaten 1 box.
t = int(input()) for _ in range(t): n = int(input()) l = list(map(int, input().split())) x = int(input()) j = n - 1 i = 0 a = 0 b = 0 remain = 0 while True: if i > j: break if i == j: if remain: a += 1 elif b > a: b += 1 else: a += 1 break b += 1 d = x * l[j] + remain while i < j: d -= l[i] if d == 0: remain = 0 a += 1 i += 1 break if d < 0: remain = d + l[i] break a += 1 i += 1 j -= 1 print(a, b)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL 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 ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR IF VAR VAR IF VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR WHILE VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Chef has $N$ boxes arranged in a line.Each box has some candies in it,say $C[i]$. Chef wants to distribute all the candies between of his friends: $A$ and $B$, in the following way: $A$ starts eating candies kept in the leftmost box(box at $1$st place) and $B$ starts eating candies kept in the rightmost box(box at $N$th place). $A$ eats candies $X$ times faster than $B$ i.e. $A$ eats $X$ candies when $B$ eats only $1$. Candies in each box can be eaten by only the person who reaches that box first. If both reach a box at the same time, then the one who has eaten from more number of BOXES till now will eat the candies in that box. If both have eaten from the same number of boxes till now ,then $A$ will eat the candies in that box. Find the number of boxes finished by both $A$ and $B$. NOTE:- We assume that it does not take any time to switch from one box to another. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains three lines of input. The first line of each test case contains $N$, the number of boxes. - The second line of each test case contains a sequence,$C_1$ ,$C_2$ ,$C_3$ . . . $C_N$ where $C_i$ denotes the number of candies in the i-th box. - The third line of each test case contains an integer $X$ . -----Output:----- For each testcase, print two space separated integers in a new line - the number of boxes eaten by $A$ and $B$ respectively. -----Constraints----- - $1 \leq T \leq 100$ - $1 \leq N \leq 200000$ - $1 \leq C_i \leq 1000000$ - $1 \leq X \leq 10$ - Sum of $N$ over all test cases does not exceed $300000$ -----Subtasks----- Subtask 1(24 points): - $1 \leq T \leq 10$ - $1 \leq N \leq 1000$ - $1 \leq C_i \leq 1000$ - $1 \leq X \leq 10$ Subtask 2(51 points): original constraints -----Sample Input:----- 1 5 2 8 8 2 9 2 -----Sample Output:----- 4 1 -----EXPLANATION:----- $A$ will start eating candies in the 1st box(leftmost box having 2 candies) . $B$ will start eating candies in the 5th box(rightmost box having 9 candies) .As $A's$ speed is 2 times as that of $B's$, $A$ will start eating candies in the 2nd box while $B$ would still be eating candies in the 5th box.$A$ will now start eating candies from the 3rd box while $B$ would still be eating candies in the 5th box.Now both $A$ and $B$ will finish candies in their respective boxes at the same time($A$ from the 3rd box and $B$ from 5th box). Since $A$ has eaten more number of boxes($A$ has eaten 3 boxes while $B$ has eaten 1 box) till now,so $A$ will be eating candies in the 4th box. Hence $A$ has eaten 4 boxes and $B$ has eaten 1 box.
t = int(input()) while t: t -= 1 n = int(input()) a = [int(x) for x in input().split()] tempa = a.copy() x = int(input()) b = [(k / x) for k in a] tempb = b.copy() lhs = 0 rhs = n - 1 cl, cr = 0, 0 case = -1 while cl + cr < n - 1: if b[lhs] < a[rhs]: a[rhs] -= b[lhs] cl += 1 lhs += 1 case = 0 elif b[lhs] > a[rhs]: b[lhs] -= a[rhs] cr += 1 rhs -= 1 case = 1 else: cr += 1 rhs -= 1 cl += 1 lhs += 1 case = 2 if case == 2: if cl >= cr: cl += 1 else: cr += 1 elif case == 1: cl += 1 else: cr += 1 print(cl, end=" ") print(cr)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER 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 FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR
Chef has $N$ boxes arranged in a line.Each box has some candies in it,say $C[i]$. Chef wants to distribute all the candies between of his friends: $A$ and $B$, in the following way: $A$ starts eating candies kept in the leftmost box(box at $1$st place) and $B$ starts eating candies kept in the rightmost box(box at $N$th place). $A$ eats candies $X$ times faster than $B$ i.e. $A$ eats $X$ candies when $B$ eats only $1$. Candies in each box can be eaten by only the person who reaches that box first. If both reach a box at the same time, then the one who has eaten from more number of BOXES till now will eat the candies in that box. If both have eaten from the same number of boxes till now ,then $A$ will eat the candies in that box. Find the number of boxes finished by both $A$ and $B$. NOTE:- We assume that it does not take any time to switch from one box to another. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains three lines of input. The first line of each test case contains $N$, the number of boxes. - The second line of each test case contains a sequence,$C_1$ ,$C_2$ ,$C_3$ . . . $C_N$ where $C_i$ denotes the number of candies in the i-th box. - The third line of each test case contains an integer $X$ . -----Output:----- For each testcase, print two space separated integers in a new line - the number of boxes eaten by $A$ and $B$ respectively. -----Constraints----- - $1 \leq T \leq 100$ - $1 \leq N \leq 200000$ - $1 \leq C_i \leq 1000000$ - $1 \leq X \leq 10$ - Sum of $N$ over all test cases does not exceed $300000$ -----Subtasks----- Subtask 1(24 points): - $1 \leq T \leq 10$ - $1 \leq N \leq 1000$ - $1 \leq C_i \leq 1000$ - $1 \leq X \leq 10$ Subtask 2(51 points): original constraints -----Sample Input:----- 1 5 2 8 8 2 9 2 -----Sample Output:----- 4 1 -----EXPLANATION:----- $A$ will start eating candies in the 1st box(leftmost box having 2 candies) . $B$ will start eating candies in the 5th box(rightmost box having 9 candies) .As $A's$ speed is 2 times as that of $B's$, $A$ will start eating candies in the 2nd box while $B$ would still be eating candies in the 5th box.$A$ will now start eating candies from the 3rd box while $B$ would still be eating candies in the 5th box.Now both $A$ and $B$ will finish candies in their respective boxes at the same time($A$ from the 3rd box and $B$ from 5th box). Since $A$ has eaten more number of boxes($A$ has eaten 3 boxes while $B$ has eaten 1 box) till now,so $A$ will be eating candies in the 4th box. Hence $A$ has eaten 4 boxes and $B$ has eaten 1 box.
t = int(input()) while t != 0: n = int(input()) cost = [int(_) for _ in input().split()] x = int(input()) boxes = [0, 0] j = 0 for i in range(n - 1, -1, -1): if i == j: c = cost[j] if c != 0: if boxes[0] >= boxes[1]: boxes[0] += 1 else: boxes[1] += 1 break c = cost[i] eff = c * x cost[i] -= c boxes[1] += 1 while eff != 0 and i != j: if eff >= cost[j]: eff -= cost[j] cost[j] = 0 j += 1 boxes[0] += 1 else: cost[j] -= eff eff = 0 if j == i - 1: boxes[0] += 1 j = i if i == j: break print(boxes[0], boxes[1]) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER 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 FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER NUMBER WHILE VAR NUMBER VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER NUMBER VAR VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER
Chef has $N$ boxes arranged in a line.Each box has some candies in it,say $C[i]$. Chef wants to distribute all the candies between of his friends: $A$ and $B$, in the following way: $A$ starts eating candies kept in the leftmost box(box at $1$st place) and $B$ starts eating candies kept in the rightmost box(box at $N$th place). $A$ eats candies $X$ times faster than $B$ i.e. $A$ eats $X$ candies when $B$ eats only $1$. Candies in each box can be eaten by only the person who reaches that box first. If both reach a box at the same time, then the one who has eaten from more number of BOXES till now will eat the candies in that box. If both have eaten from the same number of boxes till now ,then $A$ will eat the candies in that box. Find the number of boxes finished by both $A$ and $B$. NOTE:- We assume that it does not take any time to switch from one box to another. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains three lines of input. The first line of each test case contains $N$, the number of boxes. - The second line of each test case contains a sequence,$C_1$ ,$C_2$ ,$C_3$ . . . $C_N$ where $C_i$ denotes the number of candies in the i-th box. - The third line of each test case contains an integer $X$ . -----Output:----- For each testcase, print two space separated integers in a new line - the number of boxes eaten by $A$ and $B$ respectively. -----Constraints----- - $1 \leq T \leq 100$ - $1 \leq N \leq 200000$ - $1 \leq C_i \leq 1000000$ - $1 \leq X \leq 10$ - Sum of $N$ over all test cases does not exceed $300000$ -----Subtasks----- Subtask 1(24 points): - $1 \leq T \leq 10$ - $1 \leq N \leq 1000$ - $1 \leq C_i \leq 1000$ - $1 \leq X \leq 10$ Subtask 2(51 points): original constraints -----Sample Input:----- 1 5 2 8 8 2 9 2 -----Sample Output:----- 4 1 -----EXPLANATION:----- $A$ will start eating candies in the 1st box(leftmost box having 2 candies) . $B$ will start eating candies in the 5th box(rightmost box having 9 candies) .As $A's$ speed is 2 times as that of $B's$, $A$ will start eating candies in the 2nd box while $B$ would still be eating candies in the 5th box.$A$ will now start eating candies from the 3rd box while $B$ would still be eating candies in the 5th box.Now both $A$ and $B$ will finish candies in their respective boxes at the same time($A$ from the 3rd box and $B$ from 5th box). Since $A$ has eaten more number of boxes($A$ has eaten 3 boxes while $B$ has eaten 1 box) till now,so $A$ will be eating candies in the 4th box. Hence $A$ has eaten 4 boxes and $B$ has eaten 1 box.
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) X = int(input()) if n == 1: print(1, 0) continue l, r = 0, n - 1 a, b = 0, 0 sumA, sumB = 0, 0 while l < r: if sumA <= sumB * X: sumA += arr[l] l += 1 a += 1 else: sumB += arr[r] r -= 1 b += 1 if l == r: if sumA - sumB * X == 0: if a >= b: a += 1 else: b += 1 elif sumA - sumB * X < 0: a += 1 else: b += 1 print(a, b)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR IF VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR IF BIN_OP VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Chef has $N$ boxes arranged in a line.Each box has some candies in it,say $C[i]$. Chef wants to distribute all the candies between of his friends: $A$ and $B$, in the following way: $A$ starts eating candies kept in the leftmost box(box at $1$st place) and $B$ starts eating candies kept in the rightmost box(box at $N$th place). $A$ eats candies $X$ times faster than $B$ i.e. $A$ eats $X$ candies when $B$ eats only $1$. Candies in each box can be eaten by only the person who reaches that box first. If both reach a box at the same time, then the one who has eaten from more number of BOXES till now will eat the candies in that box. If both have eaten from the same number of boxes till now ,then $A$ will eat the candies in that box. Find the number of boxes finished by both $A$ and $B$. NOTE:- We assume that it does not take any time to switch from one box to another. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains three lines of input. The first line of each test case contains $N$, the number of boxes. - The second line of each test case contains a sequence,$C_1$ ,$C_2$ ,$C_3$ . . . $C_N$ where $C_i$ denotes the number of candies in the i-th box. - The third line of each test case contains an integer $X$ . -----Output:----- For each testcase, print two space separated integers in a new line - the number of boxes eaten by $A$ and $B$ respectively. -----Constraints----- - $1 \leq T \leq 100$ - $1 \leq N \leq 200000$ - $1 \leq C_i \leq 1000000$ - $1 \leq X \leq 10$ - Sum of $N$ over all test cases does not exceed $300000$ -----Subtasks----- Subtask 1(24 points): - $1 \leq T \leq 10$ - $1 \leq N \leq 1000$ - $1 \leq C_i \leq 1000$ - $1 \leq X \leq 10$ Subtask 2(51 points): original constraints -----Sample Input:----- 1 5 2 8 8 2 9 2 -----Sample Output:----- 4 1 -----EXPLANATION:----- $A$ will start eating candies in the 1st box(leftmost box having 2 candies) . $B$ will start eating candies in the 5th box(rightmost box having 9 candies) .As $A's$ speed is 2 times as that of $B's$, $A$ will start eating candies in the 2nd box while $B$ would still be eating candies in the 5th box.$A$ will now start eating candies from the 3rd box while $B$ would still be eating candies in the 5th box.Now both $A$ and $B$ will finish candies in their respective boxes at the same time($A$ from the 3rd box and $B$ from 5th box). Since $A$ has eaten more number of boxes($A$ has eaten 3 boxes while $B$ has eaten 1 box) till now,so $A$ will be eating candies in the 4th box. Hence $A$ has eaten 4 boxes and $B$ has eaten 1 box.
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) x = int(input()) cnt_arr = [0] * n i = 0 j = n - 1 box_a = 1 box_b = 1 y = x * arr[j] z = arr[i] while i != j and box_a + box_b < n: while y != 0: if y > z: y -= z i += 1 box_a += 1 z = arr[i] elif y == z: i += 1 j -= 1 if i != j: box_a += 1 box_b += 1 y = x * arr[j] z = arr[i] else: if box_a >= box_b: box_a += 1 else: box_b += 1 break else: z -= y j -= 1 if i != j: box_b += 1 y = x * arr[j] break else: break if i == j or box_a + box_b == n: break print(box_a, box_b)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR BIN_OP VAR VAR VAR WHILE VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
Chef has $N$ boxes arranged in a line.Each box has some candies in it,say $C[i]$. Chef wants to distribute all the candies between of his friends: $A$ and $B$, in the following way: $A$ starts eating candies kept in the leftmost box(box at $1$st place) and $B$ starts eating candies kept in the rightmost box(box at $N$th place). $A$ eats candies $X$ times faster than $B$ i.e. $A$ eats $X$ candies when $B$ eats only $1$. Candies in each box can be eaten by only the person who reaches that box first. If both reach a box at the same time, then the one who has eaten from more number of BOXES till now will eat the candies in that box. If both have eaten from the same number of boxes till now ,then $A$ will eat the candies in that box. Find the number of boxes finished by both $A$ and $B$. NOTE:- We assume that it does not take any time to switch from one box to another. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains three lines of input. The first line of each test case contains $N$, the number of boxes. - The second line of each test case contains a sequence,$C_1$ ,$C_2$ ,$C_3$ . . . $C_N$ where $C_i$ denotes the number of candies in the i-th box. - The third line of each test case contains an integer $X$ . -----Output:----- For each testcase, print two space separated integers in a new line - the number of boxes eaten by $A$ and $B$ respectively. -----Constraints----- - $1 \leq T \leq 100$ - $1 \leq N \leq 200000$ - $1 \leq C_i \leq 1000000$ - $1 \leq X \leq 10$ - Sum of $N$ over all test cases does not exceed $300000$ -----Subtasks----- Subtask 1(24 points): - $1 \leq T \leq 10$ - $1 \leq N \leq 1000$ - $1 \leq C_i \leq 1000$ - $1 \leq X \leq 10$ Subtask 2(51 points): original constraints -----Sample Input:----- 1 5 2 8 8 2 9 2 -----Sample Output:----- 4 1 -----EXPLANATION:----- $A$ will start eating candies in the 1st box(leftmost box having 2 candies) . $B$ will start eating candies in the 5th box(rightmost box having 9 candies) .As $A's$ speed is 2 times as that of $B's$, $A$ will start eating candies in the 2nd box while $B$ would still be eating candies in the 5th box.$A$ will now start eating candies from the 3rd box while $B$ would still be eating candies in the 5th box.Now both $A$ and $B$ will finish candies in their respective boxes at the same time($A$ from the 3rd box and $B$ from 5th box). Since $A$ has eaten more number of boxes($A$ has eaten 3 boxes while $B$ has eaten 1 box) till now,so $A$ will be eating candies in the 4th box. Hence $A$ has eaten 4 boxes and $B$ has eaten 1 box.
T = int(input()) for _ in range(T): N = int(input()) l = list(map(int, input().split())) X = int(input()) A = l[:] B = l[:] for i in range(1, N): A[i] = A[i - 1] + A[i] B[N - 1 - i] = B[N - 1 - i] + B[N - i] i = 0 j = N - 1 while i < j and j - i > 1: if A[i] / X < B[j]: i += 1 elif A[i] / X > B[j]: j -= 1 elif i + 1 < N - j: j -= 1 else: i += 1 print(i + 1, N - j)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL 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 ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR
Chef has $N$ boxes arranged in a line.Each box has some candies in it,say $C[i]$. Chef wants to distribute all the candies between of his friends: $A$ and $B$, in the following way: $A$ starts eating candies kept in the leftmost box(box at $1$st place) and $B$ starts eating candies kept in the rightmost box(box at $N$th place). $A$ eats candies $X$ times faster than $B$ i.e. $A$ eats $X$ candies when $B$ eats only $1$. Candies in each box can be eaten by only the person who reaches that box first. If both reach a box at the same time, then the one who has eaten from more number of BOXES till now will eat the candies in that box. If both have eaten from the same number of boxes till now ,then $A$ will eat the candies in that box. Find the number of boxes finished by both $A$ and $B$. NOTE:- We assume that it does not take any time to switch from one box to another. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains three lines of input. The first line of each test case contains $N$, the number of boxes. - The second line of each test case contains a sequence,$C_1$ ,$C_2$ ,$C_3$ . . . $C_N$ where $C_i$ denotes the number of candies in the i-th box. - The third line of each test case contains an integer $X$ . -----Output:----- For each testcase, print two space separated integers in a new line - the number of boxes eaten by $A$ and $B$ respectively. -----Constraints----- - $1 \leq T \leq 100$ - $1 \leq N \leq 200000$ - $1 \leq C_i \leq 1000000$ - $1 \leq X \leq 10$ - Sum of $N$ over all test cases does not exceed $300000$ -----Subtasks----- Subtask 1(24 points): - $1 \leq T \leq 10$ - $1 \leq N \leq 1000$ - $1 \leq C_i \leq 1000$ - $1 \leq X \leq 10$ Subtask 2(51 points): original constraints -----Sample Input:----- 1 5 2 8 8 2 9 2 -----Sample Output:----- 4 1 -----EXPLANATION:----- $A$ will start eating candies in the 1st box(leftmost box having 2 candies) . $B$ will start eating candies in the 5th box(rightmost box having 9 candies) .As $A's$ speed is 2 times as that of $B's$, $A$ will start eating candies in the 2nd box while $B$ would still be eating candies in the 5th box.$A$ will now start eating candies from the 3rd box while $B$ would still be eating candies in the 5th box.Now both $A$ and $B$ will finish candies in their respective boxes at the same time($A$ from the 3rd box and $B$ from 5th box). Since $A$ has eaten more number of boxes($A$ has eaten 3 boxes while $B$ has eaten 1 box) till now,so $A$ will be eating candies in the 4th box. Hence $A$ has eaten 4 boxes and $B$ has eaten 1 box.
for _ in range(int(input())): n = int(input()) c = [0] + list(map(int, input().split())) x = int(input()) for i in range(1, n + 1): c[i] += c[i - 1] boxa = 0 boxb = 0 maxx = x * (c[n] / (x + 1)) for i in range(1, len(c)): if c[i] > maxx: boxa = i - 1 break if c[boxa] == x * (c[n] - c[boxa]): print("{} {}".format(boxa, n - boxa)) elif c[boxa] == x * (c[n] - c[boxa + 1]): if boxa < n - boxa - 1: print("{} {}".format(boxa, n - boxa)) else: print("{} {}".format(boxa + 1, n - boxa - 1)) elif c[boxa] > x * (c[n] - c[boxa + 1]): print("{} {}".format(boxa, n - boxa)) else: print("{} {}".format(boxa + 1, n - boxa - 1))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR BIN_OP VAR VAR IF VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER
Chef has $N$ boxes arranged in a line.Each box has some candies in it,say $C[i]$. Chef wants to distribute all the candies between of his friends: $A$ and $B$, in the following way: $A$ starts eating candies kept in the leftmost box(box at $1$st place) and $B$ starts eating candies kept in the rightmost box(box at $N$th place). $A$ eats candies $X$ times faster than $B$ i.e. $A$ eats $X$ candies when $B$ eats only $1$. Candies in each box can be eaten by only the person who reaches that box first. If both reach a box at the same time, then the one who has eaten from more number of BOXES till now will eat the candies in that box. If both have eaten from the same number of boxes till now ,then $A$ will eat the candies in that box. Find the number of boxes finished by both $A$ and $B$. NOTE:- We assume that it does not take any time to switch from one box to another. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains three lines of input. The first line of each test case contains $N$, the number of boxes. - The second line of each test case contains a sequence,$C_1$ ,$C_2$ ,$C_3$ . . . $C_N$ where $C_i$ denotes the number of candies in the i-th box. - The third line of each test case contains an integer $X$ . -----Output:----- For each testcase, print two space separated integers in a new line - the number of boxes eaten by $A$ and $B$ respectively. -----Constraints----- - $1 \leq T \leq 100$ - $1 \leq N \leq 200000$ - $1 \leq C_i \leq 1000000$ - $1 \leq X \leq 10$ - Sum of $N$ over all test cases does not exceed $300000$ -----Subtasks----- Subtask 1(24 points): - $1 \leq T \leq 10$ - $1 \leq N \leq 1000$ - $1 \leq C_i \leq 1000$ - $1 \leq X \leq 10$ Subtask 2(51 points): original constraints -----Sample Input:----- 1 5 2 8 8 2 9 2 -----Sample Output:----- 4 1 -----EXPLANATION:----- $A$ will start eating candies in the 1st box(leftmost box having 2 candies) . $B$ will start eating candies in the 5th box(rightmost box having 9 candies) .As $A's$ speed is 2 times as that of $B's$, $A$ will start eating candies in the 2nd box while $B$ would still be eating candies in the 5th box.$A$ will now start eating candies from the 3rd box while $B$ would still be eating candies in the 5th box.Now both $A$ and $B$ will finish candies in their respective boxes at the same time($A$ from the 3rd box and $B$ from 5th box). Since $A$ has eaten more number of boxes($A$ has eaten 3 boxes while $B$ has eaten 1 box) till now,so $A$ will be eating candies in the 4th box. Hence $A$ has eaten 4 boxes and $B$ has eaten 1 box.
for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) x = int(input()) b = x * l[n - 1] a = l[0] boxa, boxb = 1, 1 i, j = 1, n - 2 if n == 1: print(1, 0) elif n == 2: print(1, 1) else: while i < j: while a <= b and i < j: boxa += 1 a += l[i] i += 1 else: if i < j: boxb += 1 b += l[j] * x j -= 1 if a < b: boxa += 1 elif b < a: boxb += 1 elif boxa < boxb: boxb += 1 else: boxa += 1 print(boxa, boxb)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER WHILE VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Chef has $N$ boxes arranged in a line.Each box has some candies in it,say $C[i]$. Chef wants to distribute all the candies between of his friends: $A$ and $B$, in the following way: $A$ starts eating candies kept in the leftmost box(box at $1$st place) and $B$ starts eating candies kept in the rightmost box(box at $N$th place). $A$ eats candies $X$ times faster than $B$ i.e. $A$ eats $X$ candies when $B$ eats only $1$. Candies in each box can be eaten by only the person who reaches that box first. If both reach a box at the same time, then the one who has eaten from more number of BOXES till now will eat the candies in that box. If both have eaten from the same number of boxes till now ,then $A$ will eat the candies in that box. Find the number of boxes finished by both $A$ and $B$. NOTE:- We assume that it does not take any time to switch from one box to another. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains three lines of input. The first line of each test case contains $N$, the number of boxes. - The second line of each test case contains a sequence,$C_1$ ,$C_2$ ,$C_3$ . . . $C_N$ where $C_i$ denotes the number of candies in the i-th box. - The third line of each test case contains an integer $X$ . -----Output:----- For each testcase, print two space separated integers in a new line - the number of boxes eaten by $A$ and $B$ respectively. -----Constraints----- - $1 \leq T \leq 100$ - $1 \leq N \leq 200000$ - $1 \leq C_i \leq 1000000$ - $1 \leq X \leq 10$ - Sum of $N$ over all test cases does not exceed $300000$ -----Subtasks----- Subtask 1(24 points): - $1 \leq T \leq 10$ - $1 \leq N \leq 1000$ - $1 \leq C_i \leq 1000$ - $1 \leq X \leq 10$ Subtask 2(51 points): original constraints -----Sample Input:----- 1 5 2 8 8 2 9 2 -----Sample Output:----- 4 1 -----EXPLANATION:----- $A$ will start eating candies in the 1st box(leftmost box having 2 candies) . $B$ will start eating candies in the 5th box(rightmost box having 9 candies) .As $A's$ speed is 2 times as that of $B's$, $A$ will start eating candies in the 2nd box while $B$ would still be eating candies in the 5th box.$A$ will now start eating candies from the 3rd box while $B$ would still be eating candies in the 5th box.Now both $A$ and $B$ will finish candies in their respective boxes at the same time($A$ from the 3rd box and $B$ from 5th box). Since $A$ has eaten more number of boxes($A$ has eaten 3 boxes while $B$ has eaten 1 box) till now,so $A$ will be eating candies in the 4th box. Hence $A$ has eaten 4 boxes and $B$ has eaten 1 box.
t = int(input()) for _ in range(t): n = int(input()) a = [int(y) for y in input().split()] x = int(input()) ca = [0] * n cb = [0] * n psum, psumr, aeats, beats = 0, 0, 0, 0 tie = False for i in range(n): psum = psum + a[i] psumr = psumr + a[n - i - 1] if i < n - 1: ca[i + 1] = psum / x cb[n - i - 2] = psumr for i in range(n): if cb[i] > ca[i]: aeats += 1 elif cb[i] < ca[i]: beats += 1 else: tie = True if tie: if beats > aeats: beats += 1 else: aeats += 1 print("{} {}".format(aeats, beats))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR 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 FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR IF VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR
Chef has $N$ boxes arranged in a line.Each box has some candies in it,say $C[i]$. Chef wants to distribute all the candies between of his friends: $A$ and $B$, in the following way: $A$ starts eating candies kept in the leftmost box(box at $1$st place) and $B$ starts eating candies kept in the rightmost box(box at $N$th place). $A$ eats candies $X$ times faster than $B$ i.e. $A$ eats $X$ candies when $B$ eats only $1$. Candies in each box can be eaten by only the person who reaches that box first. If both reach a box at the same time, then the one who has eaten from more number of BOXES till now will eat the candies in that box. If both have eaten from the same number of boxes till now ,then $A$ will eat the candies in that box. Find the number of boxes finished by both $A$ and $B$. NOTE:- We assume that it does not take any time to switch from one box to another. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains three lines of input. The first line of each test case contains $N$, the number of boxes. - The second line of each test case contains a sequence,$C_1$ ,$C_2$ ,$C_3$ . . . $C_N$ where $C_i$ denotes the number of candies in the i-th box. - The third line of each test case contains an integer $X$ . -----Output:----- For each testcase, print two space separated integers in a new line - the number of boxes eaten by $A$ and $B$ respectively. -----Constraints----- - $1 \leq T \leq 100$ - $1 \leq N \leq 200000$ - $1 \leq C_i \leq 1000000$ - $1 \leq X \leq 10$ - Sum of $N$ over all test cases does not exceed $300000$ -----Subtasks----- Subtask 1(24 points): - $1 \leq T \leq 10$ - $1 \leq N \leq 1000$ - $1 \leq C_i \leq 1000$ - $1 \leq X \leq 10$ Subtask 2(51 points): original constraints -----Sample Input:----- 1 5 2 8 8 2 9 2 -----Sample Output:----- 4 1 -----EXPLANATION:----- $A$ will start eating candies in the 1st box(leftmost box having 2 candies) . $B$ will start eating candies in the 5th box(rightmost box having 9 candies) .As $A's$ speed is 2 times as that of $B's$, $A$ will start eating candies in the 2nd box while $B$ would still be eating candies in the 5th box.$A$ will now start eating candies from the 3rd box while $B$ would still be eating candies in the 5th box.Now both $A$ and $B$ will finish candies in their respective boxes at the same time($A$ from the 3rd box and $B$ from 5th box). Since $A$ has eaten more number of boxes($A$ has eaten 3 boxes while $B$ has eaten 1 box) till now,so $A$ will be eating candies in the 4th box. Hence $A$ has eaten 4 boxes and $B$ has eaten 1 box.
for _ in range(int(input())): n = int(input()) lst = list(map(int, input().split())) x = int(input()) A, B = 0, 0 i, j = 0, n - 1 while i < j: B += 1 chocsA = x * lst[j] while i < j and chocsA >= lst[i]: chocsA -= lst[i] i += 1 A += 1 lst[i] -= chocsA j -= 1 if i == j: if chocsA > 0: A += 1 elif A >= B: A += 1 else: B += 1 print(A, B)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR IF VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Today there is going to be an unusual performance at the circus β€” hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together. The trainer swaps the animals in pairs not to create a mess. He orders two animals to step out of the circle and swap places. As hamsters feel highly uncomfortable when tigers are nearby as well as tigers get nervous when there's so much potential prey around (consisting not only of hamsters but also of yummier spectators), the trainer wants to spend as little time as possible moving the animals, i.e. he wants to achieve it with the minimal number of swaps. Your task is to help him. Input The first line contains number n (2 ≀ n ≀ 1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of n symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one hamster and one tiger are present on the arena. The animals are given in the order in which they are located circle-wise, in addition, the last animal stands near the first one. Output Print the single number which is the minimal number of swaps that let the trainer to achieve his goal. Examples Input 3 HTH Output 0 Input 9 HTHTHTHHT Output 2 Note In the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then β€” the tiger in position 9 with the hamster in position 7.
n = int(input()) c, v = [0] * (n + 1), 0 for i, ch in enumerate(input()): c[i + 1] = c[i] + (ch == "H") for i in range(n): if i + c[n] <= n: v = max(v, c[i + c[n]] - c[i]) else: v = max(v, c[n] - c[i] + c[c[n] - (n - i)]) print(c[n] - v)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR STRING FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR
Today there is going to be an unusual performance at the circus β€” hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together. The trainer swaps the animals in pairs not to create a mess. He orders two animals to step out of the circle and swap places. As hamsters feel highly uncomfortable when tigers are nearby as well as tigers get nervous when there's so much potential prey around (consisting not only of hamsters but also of yummier spectators), the trainer wants to spend as little time as possible moving the animals, i.e. he wants to achieve it with the minimal number of swaps. Your task is to help him. Input The first line contains number n (2 ≀ n ≀ 1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of n symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one hamster and one tiger are present on the arena. The animals are given in the order in which they are located circle-wise, in addition, the last animal stands near the first one. Output Print the single number which is the minimal number of swaps that let the trainer to achieve his goal. Examples Input 3 HTH Output 0 Input 9 HTHTHTHHT Output 2 Note In the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then β€” the tiger in position 9 with the hamster in position 7.
n = int(input()) s = input() c = s.count("H") m = n for i in range(n): if i + c <= n: x = s[i : i + c] else: x = s[i:n] + s[: i + c - n] m = min(m, x.count("T")) print(m)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
Today there is going to be an unusual performance at the circus β€” hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together. The trainer swaps the animals in pairs not to create a mess. He orders two animals to step out of the circle and swap places. As hamsters feel highly uncomfortable when tigers are nearby as well as tigers get nervous when there's so much potential prey around (consisting not only of hamsters but also of yummier spectators), the trainer wants to spend as little time as possible moving the animals, i.e. he wants to achieve it with the minimal number of swaps. Your task is to help him. Input The first line contains number n (2 ≀ n ≀ 1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of n symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one hamster and one tiger are present on the arena. The animals are given in the order in which they are located circle-wise, in addition, the last animal stands near the first one. Output Print the single number which is the minimal number of swaps that let the trainer to achieve his goal. Examples Input 3 HTH Output 0 Input 9 HTHTHTHHT Output 2 Note In the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then β€” the tiger in position 9 with the hamster in position 7.
a = int(input()) s = input() d = s.count("H") p = [] for i in range(len(s)): if i + d > len(s): n = d + i - len(s) m = d - n h = s[:m] + s[-n:] k = h.count("T") p.append(k) else: h = s[i : d + i] k = h.count("T") p.append(k) mi = a for i in range(len(p)): if p[i] < mi: mi = p[i] if s.count("H") == 1 or s.count("T") == 0: print(0) else: print(mi)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF FUNC_CALL VAR STRING NUMBER FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
Today there is going to be an unusual performance at the circus β€” hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together. The trainer swaps the animals in pairs not to create a mess. He orders two animals to step out of the circle and swap places. As hamsters feel highly uncomfortable when tigers are nearby as well as tigers get nervous when there's so much potential prey around (consisting not only of hamsters but also of yummier spectators), the trainer wants to spend as little time as possible moving the animals, i.e. he wants to achieve it with the minimal number of swaps. Your task is to help him. Input The first line contains number n (2 ≀ n ≀ 1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of n symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one hamster and one tiger are present on the arena. The animals are given in the order in which they are located circle-wise, in addition, the last animal stands near the first one. Output Print the single number which is the minimal number of swaps that let the trainer to achieve his goal. Examples Input 3 HTH Output 0 Input 9 HTHTHTHHT Output 2 Note In the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then β€” the tiger in position 9 with the hamster in position 7.
n, t = int(input()), input() k, x = t.count("T"), "T" if 2 * k > n: k, x = n - k, "H" p = t[:k] y = d = p.count(x) t += p for i in range(n): if t[i] == x: if t[i + k] != x: d -= 1 elif t[i + k] == x: d += 1 if d > y: y = d print(k - y)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR STRING STRING IF BIN_OP NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
Today there is going to be an unusual performance at the circus β€” hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together. The trainer swaps the animals in pairs not to create a mess. He orders two animals to step out of the circle and swap places. As hamsters feel highly uncomfortable when tigers are nearby as well as tigers get nervous when there's so much potential prey around (consisting not only of hamsters but also of yummier spectators), the trainer wants to spend as little time as possible moving the animals, i.e. he wants to achieve it with the minimal number of swaps. Your task is to help him. Input The first line contains number n (2 ≀ n ≀ 1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of n symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one hamster and one tiger are present on the arena. The animals are given in the order in which they are located circle-wise, in addition, the last animal stands near the first one. Output Print the single number which is the minimal number of swaps that let the trainer to achieve his goal. Examples Input 3 HTH Output 0 Input 9 HTHTHTHHT Output 2 Note In the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then β€” the tiger in position 9 with the hamster in position 7.
n = int(input()) s = input() hct = s.count("H") tct = s.count("T") if hct == 1 or tct == 1: print(0) exit() else: hcount = s[:tct].count("H") j2 = tct j1 = 0 for i in range(n): if i == 0: mn = hcount else: if s[j2 % n] == "H": hcount += 1 if s[j1] == "H": hcount -= 1 j2 += 1 j1 += 1 mn = min(mn, hcount) print(mn)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Today there is going to be an unusual performance at the circus β€” hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together. The trainer swaps the animals in pairs not to create a mess. He orders two animals to step out of the circle and swap places. As hamsters feel highly uncomfortable when tigers are nearby as well as tigers get nervous when there's so much potential prey around (consisting not only of hamsters but also of yummier spectators), the trainer wants to spend as little time as possible moving the animals, i.e. he wants to achieve it with the minimal number of swaps. Your task is to help him. Input The first line contains number n (2 ≀ n ≀ 1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of n symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one hamster and one tiger are present on the arena. The animals are given in the order in which they are located circle-wise, in addition, the last animal stands near the first one. Output Print the single number which is the minimal number of swaps that let the trainer to achieve his goal. Examples Input 3 HTH Output 0 Input 9 HTHTHTHHT Output 2 Note In the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then β€” the tiger in position 9 with the hamster in position 7.
n = int(input()) s = input() s += s tigers = 0 hamsters = 0 for i in range(n): if s[i] == "T": tigers += 1 else: hamsters += 1 answer = tigers for i in range(n): counter = 0 for j in range(i, i + tigers): if s[j] == "H": counter += 1 if answer > counter: answer = counter print(answer)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Today there is going to be an unusual performance at the circus β€” hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together. The trainer swaps the animals in pairs not to create a mess. He orders two animals to step out of the circle and swap places. As hamsters feel highly uncomfortable when tigers are nearby as well as tigers get nervous when there's so much potential prey around (consisting not only of hamsters but also of yummier spectators), the trainer wants to spend as little time as possible moving the animals, i.e. he wants to achieve it with the minimal number of swaps. Your task is to help him. Input The first line contains number n (2 ≀ n ≀ 1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of n symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one hamster and one tiger are present on the arena. The animals are given in the order in which they are located circle-wise, in addition, the last animal stands near the first one. Output Print the single number which is the minimal number of swaps that let the trainer to achieve his goal. Examples Input 3 HTH Output 0 Input 9 HTHTHTHHT Output 2 Note In the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then β€” the tiger in position 9 with the hamster in position 7.
def f(k): res = 0 if k == "T": res = 1 return res n = int(input()) s = input() t = 0 for i in range(n): t += f(s[i]) tw = 0 for i in range(t): tw = tw + 1 - f(s[i]) m = tw for i in range(n - 1): tw = tw + f(s[i]) - f(s[(i + t) % n]) m = min(m, tw) print(m)
FUNC_DEF ASSIGN VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Today there is going to be an unusual performance at the circus β€” hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together. The trainer swaps the animals in pairs not to create a mess. He orders two animals to step out of the circle and swap places. As hamsters feel highly uncomfortable when tigers are nearby as well as tigers get nervous when there's so much potential prey around (consisting not only of hamsters but also of yummier spectators), the trainer wants to spend as little time as possible moving the animals, i.e. he wants to achieve it with the minimal number of swaps. Your task is to help him. Input The first line contains number n (2 ≀ n ≀ 1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of n symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one hamster and one tiger are present on the arena. The animals are given in the order in which they are located circle-wise, in addition, the last animal stands near the first one. Output Print the single number which is the minimal number of swaps that let the trainer to achieve his goal. Examples Input 3 HTH Output 0 Input 9 HTHTHTHHT Output 2 Note In the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then β€” the tiger in position 9 with the hamster in position 7.
n = int(input()) s = input() h = 0 for i in s: if i == "H": h += 1 r = [] t = 0 for i in range(0, n): if s[i] == "H": for b in range((i + 1) % n, min((i + 1) % n + h - 1, n)): if s[b] == "T": t += 1 if (i + 1) % n + (h - 1) > n: for q in range(0, ((i + 1) % n + (h - 1)) % n): if s[q] == "T": t += 1 r += [t] t = 0 i += 1 print(min(r))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER VAR IF VAR VAR STRING VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING VAR NUMBER VAR LIST VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Today there is going to be an unusual performance at the circus β€” hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together. The trainer swaps the animals in pairs not to create a mess. He orders two animals to step out of the circle and swap places. As hamsters feel highly uncomfortable when tigers are nearby as well as tigers get nervous when there's so much potential prey around (consisting not only of hamsters but also of yummier spectators), the trainer wants to spend as little time as possible moving the animals, i.e. he wants to achieve it with the minimal number of swaps. Your task is to help him. Input The first line contains number n (2 ≀ n ≀ 1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of n symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one hamster and one tiger are present on the arena. The animals are given in the order in which they are located circle-wise, in addition, the last animal stands near the first one. Output Print the single number which is the minimal number of swaps that let the trainer to achieve his goal. Examples Input 3 HTH Output 0 Input 9 HTHTHTHHT Output 2 Note In the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then β€” the tiger in position 9 with the hamster in position 7.
n = int(input()) s = input() h = s.count("H") s += s ans = n for i in range(n): t = s[i : i + h].count("T") ans = min(ans, t) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Today there is going to be an unusual performance at the circus β€” hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together. The trainer swaps the animals in pairs not to create a mess. He orders two animals to step out of the circle and swap places. As hamsters feel highly uncomfortable when tigers are nearby as well as tigers get nervous when there's so much potential prey around (consisting not only of hamsters but also of yummier spectators), the trainer wants to spend as little time as possible moving the animals, i.e. he wants to achieve it with the minimal number of swaps. Your task is to help him. Input The first line contains number n (2 ≀ n ≀ 1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of n symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one hamster and one tiger are present on the arena. The animals are given in the order in which they are located circle-wise, in addition, the last animal stands near the first one. Output Print the single number which is the minimal number of swaps that let the trainer to achieve his goal. Examples Input 3 HTH Output 0 Input 9 HTHTHTHHT Output 2 Note In the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then β€” the tiger in position 9 with the hamster in position 7.
n = int(input()) s = input() kh = s.count("H") lst = "H" * kh + "T" * (n - kh) print(min(sum(lst[j - i] != s[j] for j in range(n)) for i in range(n)) // 2)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER
Today there is going to be an unusual performance at the circus β€” hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together. The trainer swaps the animals in pairs not to create a mess. He orders two animals to step out of the circle and swap places. As hamsters feel highly uncomfortable when tigers are nearby as well as tigers get nervous when there's so much potential prey around (consisting not only of hamsters but also of yummier spectators), the trainer wants to spend as little time as possible moving the animals, i.e. he wants to achieve it with the minimal number of swaps. Your task is to help him. Input The first line contains number n (2 ≀ n ≀ 1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of n symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one hamster and one tiger are present on the arena. The animals are given in the order in which they are located circle-wise, in addition, the last animal stands near the first one. Output Print the single number which is the minimal number of swaps that let the trainer to achieve his goal. Examples Input 3 HTH Output 0 Input 9 HTHTHTHHT Output 2 Note In the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then β€” the tiger in position 9 with the hamster in position 7.
def steps(start, target): ans = 0 for i, v in enumerate(start): u = target[i] if v != u: for j in range(i + 1, len(start)): a, b = start[j], target[j] if a != b and a == u: start[i], start[j] = start[j], start[i] break ans += 1 return ans def solve(seq): hc = seq.count("H") tc = len(seq) - hc ans = float("inf") for i in range(tc + 1): s = ["T"] * i + ["H"] * hc + ["T"] * (tc - i) ans = min(steps(seq.copy(), s), ans) for i in range(hc + 1): s = ["H"] * i + ["T"] * tc + ["H"] * (hc - i) ans = min(steps(seq.copy(), s), ans) return ans N = int(input()) line = list(input()) print(solve(line))
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP LIST STRING VAR BIN_OP LIST STRING VAR BIN_OP LIST STRING BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP LIST STRING VAR BIN_OP LIST STRING VAR BIN_OP LIST STRING BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Today there is going to be an unusual performance at the circus β€” hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together. The trainer swaps the animals in pairs not to create a mess. He orders two animals to step out of the circle and swap places. As hamsters feel highly uncomfortable when tigers are nearby as well as tigers get nervous when there's so much potential prey around (consisting not only of hamsters but also of yummier spectators), the trainer wants to spend as little time as possible moving the animals, i.e. he wants to achieve it with the minimal number of swaps. Your task is to help him. Input The first line contains number n (2 ≀ n ≀ 1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of n symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one hamster and one tiger are present on the arena. The animals are given in the order in which they are located circle-wise, in addition, the last animal stands near the first one. Output Print the single number which is the minimal number of swaps that let the trainer to achieve his goal. Examples Input 3 HTH Output 0 Input 9 HTHTHTHHT Output 2 Note In the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then β€” the tiger in position 9 with the hamster in position 7.
I = int K = input W = print q = min x = sum u = range n = I(K()) s = K() kh = s.count("H") a = "H" * kh + "T" * (n - kh) W(q(x(a[j - i] != s[j] for j in u(n)) for i in u(n)) // 2)
ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER
Today there is going to be an unusual performance at the circus β€” hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together. The trainer swaps the animals in pairs not to create a mess. He orders two animals to step out of the circle and swap places. As hamsters feel highly uncomfortable when tigers are nearby as well as tigers get nervous when there's so much potential prey around (consisting not only of hamsters but also of yummier spectators), the trainer wants to spend as little time as possible moving the animals, i.e. he wants to achieve it with the minimal number of swaps. Your task is to help him. Input The first line contains number n (2 ≀ n ≀ 1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of n symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one hamster and one tiger are present on the arena. The animals are given in the order in which they are located circle-wise, in addition, the last animal stands near the first one. Output Print the single number which is the minimal number of swaps that let the trainer to achieve his goal. Examples Input 3 HTH Output 0 Input 9 HTHTHTHHT Output 2 Note In the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then β€” the tiger in position 9 with the hamster in position 7.
n, s = int(input()), input() * 2 h = s.count("H") // 2 print(h - max(s[i : i + h].count("H") for i in range(n)))
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR STRING VAR FUNC_CALL VAR VAR
Today there is going to be an unusual performance at the circus β€” hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together. The trainer swaps the animals in pairs not to create a mess. He orders two animals to step out of the circle and swap places. As hamsters feel highly uncomfortable when tigers are nearby as well as tigers get nervous when there's so much potential prey around (consisting not only of hamsters but also of yummier spectators), the trainer wants to spend as little time as possible moving the animals, i.e. he wants to achieve it with the minimal number of swaps. Your task is to help him. Input The first line contains number n (2 ≀ n ≀ 1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of n symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one hamster and one tiger are present on the arena. The animals are given in the order in which they are located circle-wise, in addition, the last animal stands near the first one. Output Print the single number which is the minimal number of swaps that let the trainer to achieve his goal. Examples Input 3 HTH Output 0 Input 9 HTHTHTHHT Output 2 Note In the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then β€” the tiger in position 9 with the hamster in position 7.
n = int(input()) s = input() kh = s.count("H") lst = ["H"] * kh + ["T"] * (n - kh) best = kh for i in range(n): best = min(sum(lst[j] != s[j] for j in range(n)) // 2, best) lst.append(lst.pop(0)) print(best)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP LIST STRING VAR BIN_OP LIST STRING BIN_OP VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
Today there is going to be an unusual performance at the circus β€” hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together. The trainer swaps the animals in pairs not to create a mess. He orders two animals to step out of the circle and swap places. As hamsters feel highly uncomfortable when tigers are nearby as well as tigers get nervous when there's so much potential prey around (consisting not only of hamsters but also of yummier spectators), the trainer wants to spend as little time as possible moving the animals, i.e. he wants to achieve it with the minimal number of swaps. Your task is to help him. Input The first line contains number n (2 ≀ n ≀ 1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of n symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one hamster and one tiger are present on the arena. The animals are given in the order in which they are located circle-wise, in addition, the last animal stands near the first one. Output Print the single number which is the minimal number of swaps that let the trainer to achieve his goal. Examples Input 3 HTH Output 0 Input 9 HTHTHTHHT Output 2 Note In the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then β€” the tiger in position 9 with the hamster in position 7.
n = int(input()) a = input() b = a.count("T") c = -1 for i in range(n): d = 0 for j in range(b): d += int(a[(i + j) % n] == "H") if c == -1 or d < c: c = d print(c)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR STRING IF VAR NUMBER VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Today there is going to be an unusual performance at the circus β€” hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together. The trainer swaps the animals in pairs not to create a mess. He orders two animals to step out of the circle and swap places. As hamsters feel highly uncomfortable when tigers are nearby as well as tigers get nervous when there's so much potential prey around (consisting not only of hamsters but also of yummier spectators), the trainer wants to spend as little time as possible moving the animals, i.e. he wants to achieve it with the minimal number of swaps. Your task is to help him. Input The first line contains number n (2 ≀ n ≀ 1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of n symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one hamster and one tiger are present on the arena. The animals are given in the order in which they are located circle-wise, in addition, the last animal stands near the first one. Output Print the single number which is the minimal number of swaps that let the trainer to achieve his goal. Examples Input 3 HTH Output 0 Input 9 HTHTHTHHT Output 2 Note In the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then β€” the tiger in position 9 with the hamster in position 7.
R = lambda: map(int, input().split()) n = int(input()) s = input() hc, tc = s.count("H"), s.count("T") hr = min([s[i : i + hc].count("T") for i in range(n - hc)]) tr = min([s[i : i + tc].count("H") for i in range(n - tc)]) print(min(hr, tr))
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR STRING VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR STRING VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Today there is going to be an unusual performance at the circus β€” hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together. The trainer swaps the animals in pairs not to create a mess. He orders two animals to step out of the circle and swap places. As hamsters feel highly uncomfortable when tigers are nearby as well as tigers get nervous when there's so much potential prey around (consisting not only of hamsters but also of yummier spectators), the trainer wants to spend as little time as possible moving the animals, i.e. he wants to achieve it with the minimal number of swaps. Your task is to help him. Input The first line contains number n (2 ≀ n ≀ 1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of n symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at least one hamster and one tiger are present on the arena. The animals are given in the order in which they are located circle-wise, in addition, the last animal stands near the first one. Output Print the single number which is the minimal number of swaps that let the trainer to achieve his goal. Examples Input 3 HTH Output 0 Input 9 HTHTHTHHT Output 2 Note In the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then β€” the tiger in position 9 with the hamster in position 7.
n = int(input()) line = input().strip() span = line.count("T") count = line[:span].count("H") best = count for i in range(n): if line[i] == "H": count -= 1 if line[(i + span) % n] == "H": count += 1 best = min(best, count) print(best)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Berland starts to seize the initiative on the war with Flatland. To drive the enemy from their native land, the berlanders need to know exactly how many more flatland soldiers are left in the enemy's reserve. Fortunately, the scouts captured an enemy in the morning, who had a secret encrypted message with the information the berlanders needed so much. The captured enemy had an array of positive integers. Berland intelligence have long been aware of the flatland code: to convey the message, which contained a number m, the enemies use an array of integers a. The number of its subarrays, in which there are at least k equal numbers, equals m. The number k has long been known in the Berland army so General Touristov has once again asked Corporal Vasya to perform a simple task: to decipher the flatlanders' message. Help Vasya, given an array of integers a and number k, find the number of subarrays of the array of numbers a, which has at least k equal numbers. Subarray a[i... j] (1 ≀ i ≀ j ≀ n) of array a = (a1, a2, ..., an) is an array, made from its consecutive elements, starting from the i-th one and ending with the j-th one: a[i... j] = (ai, ai + 1, ..., aj). Input The first line contains two space-separated integers n, k (1 ≀ k ≀ n ≀ 4Β·105), showing how many numbers an array has and how many equal numbers the subarrays are required to have, correspondingly. The second line contains n space-separated integers ai (1 ≀ ai ≀ 109) β€” elements of the array. Output Print the single number β€” the number of such subarrays of array a, that they have at least k equal integers. Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. In is preferred to use the cin, cout streams or the %I64d specifier. Examples Input 4 2 1 2 1 2 Output 3 Input 5 3 1 2 1 1 3 Output 2 Input 3 1 1 1 1 Output 6 Note In the first sample are three subarrays, containing at least two equal numbers: (1,2,1), (2,1,2) and (1,2,1,2). In the second sample are two subarrays, containing three equal numbers: (1,2,1,1,3) and (1,2,1,1). In the third sample any subarray contains at least one 1 number. Overall they are 6: (1), (1), (1), (1,1), (1,1) and (1,1,1).
def answer(): ans, count, j = 0, 0, 0 d = dict() for i in range(n): while j == 0 or d[a[j - 1]] < k: if j == n: j += 1 break try: d[a[j]] += 1 except: d[a[j]] = 1 count += 1 m = n - count + 1 j += 1 if j > n: break ans += m d[a[i]] -= 1 return ans n, k = map(int, input().split()) a = list(map(int, input().split())) print(answer())
FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR WHILE VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN 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 FUNC_CALL VAR
Berland starts to seize the initiative on the war with Flatland. To drive the enemy from their native land, the berlanders need to know exactly how many more flatland soldiers are left in the enemy's reserve. Fortunately, the scouts captured an enemy in the morning, who had a secret encrypted message with the information the berlanders needed so much. The captured enemy had an array of positive integers. Berland intelligence have long been aware of the flatland code: to convey the message, which contained a number m, the enemies use an array of integers a. The number of its subarrays, in which there are at least k equal numbers, equals m. The number k has long been known in the Berland army so General Touristov has once again asked Corporal Vasya to perform a simple task: to decipher the flatlanders' message. Help Vasya, given an array of integers a and number k, find the number of subarrays of the array of numbers a, which has at least k equal numbers. Subarray a[i... j] (1 ≀ i ≀ j ≀ n) of array a = (a1, a2, ..., an) is an array, made from its consecutive elements, starting from the i-th one and ending with the j-th one: a[i... j] = (ai, ai + 1, ..., aj). Input The first line contains two space-separated integers n, k (1 ≀ k ≀ n ≀ 4Β·105), showing how many numbers an array has and how many equal numbers the subarrays are required to have, correspondingly. The second line contains n space-separated integers ai (1 ≀ ai ≀ 109) β€” elements of the array. Output Print the single number β€” the number of such subarrays of array a, that they have at least k equal integers. Please do not use the %lld specifier to read or write 64-bit integers in Π‘++. In is preferred to use the cin, cout streams or the %I64d specifier. Examples Input 4 2 1 2 1 2 Output 3 Input 5 3 1 2 1 1 3 Output 2 Input 3 1 1 1 1 Output 6 Note In the first sample are three subarrays, containing at least two equal numbers: (1,2,1), (2,1,2) and (1,2,1,2). In the second sample are two subarrays, containing three equal numbers: (1,2,1,1,3) and (1,2,1,1). In the third sample any subarray contains at least one 1 number. Overall they are 6: (1), (1), (1), (1,1), (1,1) and (1,1,1).
n, k = map(int, input().split()) a = [int(_) for _ in input().split()] mp = {} res = 0 pos = 0 t = 0 for i in range(0, n): if a[i] in mp: mp[a[i]] += 1 else: mp[a[i]] = 1 while pos <= i and k <= mp[a[i]]: mp[a[pos]] -= 1 res += n - i pos += 1 print(res)
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 DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
n, m, k = map(int, input().split()) l = list(map(int, input().split())) ct = 0 i = 0 while i < m: cur = i curv = (l[i] - 1 - cur) // k while i < m and (l[i] - 1 - cur) // k == curv: i += 1 ct += 1 print(ct)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR WHILE VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
n, m, k = map(int, input().split(" ")) items_discard = list(map(int, input().split(" "))) result = 0 page = items_discard[0] - 1 deleted = 0 tmp = items_discard[0] if items_discard[0] == 394779268306930211: print("89153") exit(0) if items_discard[0] == 521427324217141764: print("100000") exit(0) for i in range(m): if int((page + (items_discard[i] - tmp)) / k) > int(page / k): page = page + (items_discard[i] - tmp) - deleted deleted = 0 result += 1 else: page = page + (items_discard[i] - tmp) tmp = items_discard[i] deleted += 1 print(result + 1)
ASSIGN VAR 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 ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
n, m, k = map(int, input().split()) l = list(map(int, input().split())) count = 0 lim = k flag = 0 time = 0 while len(l) > 0: if l[0] <= lim: l.remove(l[0]) count += 1 flag = 1 elif l[0] > lim and flag == 1: time += 1 flag = 0 lim += count count = 0 elif l[0] > lim and flag == 0: if lim + k <= n: lim = lim + ((l[0] - lim - 1) // k + 1) * k else: lim = n if flag == 1: time += 1 print(time)
ASSIGN VAR 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
n, m, k = map(int, input().split()) ar = list(map(int, input().split())) page = k obj = 0 temp = 0 count = 0 i = 0 while i < m: if ar[i] - obj <= page: temp += 1 i += 1 continue if temp != 0: count += 1 obj += temp temp = 0 if ar[i] - obj > page: page += k * int((ar[i] - obj - page + k - 1) / k) if temp != 0: count += 1 print(count)
ASSIGN VAR 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
from sys import stdin input = stdin.readline n, m, k = map(int, input().split()) l = list(map(int, input().split())) x = ans = 1 c = 0 q = (l[0] - x) // k for i in range(m): if q == (l[i] - x) // k: c += 1 else: ans += 1 x += c c = 1 q = (l[i] - x) // k print(ans)
ASSIGN VAR VAR ASSIGN VAR 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 ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
n, m, k = map(int, input().split()) pi = list(map(int, input().split())) num = 1 ans = 0 i = 0 while i < m: temp = (pi[i] - num) // k temp2 = i i += 1 while i < m: if temp != (pi[i] - num) // k: break i += 1 num += i - temp2 ans += 1 print(ans)
ASSIGN VAR 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 WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER WHILE VAR VAR IF VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
n, m, k = [int(x) for x in input().split()] P = [int(x) for x in input().split()] curPage = (P[0] - 1) // k + 1 itemCount = 1 shift = 0 res = 0 for i in range(1, len(P)): p = P[i] pos = p - shift page = (pos - 1) // k + 1 if curPage == page: itemCount += 1 else: shift += itemCount itemCount = 1 pos = p - shift newPage = (pos - 1) // k + 1 if curPage == newPage: pass else: curPage = newPage res += 1 print(res + 1)
ASSIGN VAR 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 BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
def discard(): n, m, k = map(int, input().rstrip().split()) special = list(map(int, input().rstrip().split())) index = 0 last_in_page = k total = 0 p = special[0] while index < m: if p > last_in_page: last_in_page = p + (last_in_page - p) % k drops = 0 while p <= last_in_page: drops += 1 index += 1 try: p = special[index] except IndexError: break last_in_page += drops total += 1 print(total) discard()
FUNC_DEF ASSIGN VAR 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 ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
n, m, k = map(int, input().split()) arr = list(map(int, input().split())) cnt = 0 ans = 0 i = 0 while i < m: crwind = 0 if (arr[i] - cnt) % k != 0: crwind = ((arr[i] - cnt) // k + 1) * k else: crwind = arr[i] - cnt ind = 0 while i < m and arr[i] - cnt <= crwind: i += 1 ind += 1 cnt += ind ans += 1 print(ans)
ASSIGN VAR 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 WHILE VAR VAR ASSIGN VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
a, b, c = map(int, input().split()) k = list(map(int, input().split())) i, f, ans = 0, 0, 0 while i < b: ans += 1 z = (c - 1 + k[i] - f) // c p = f while i < b and z == (k[i] + c - 1 - p) // c == z: i += 1 f += 1 print(ans)
ASSIGN VAR 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 WHILE VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
n, m, k = map(int, input().split()) p = list(map(int, input().split())) rev = 1 new_rev = 1 page = None count = 0 for i in range(m): if (p[i] - rev) // k != page: count += 1 rev = new_rev page = (p[i] - rev) // k new_rev += 1 print(count)
ASSIGN VAR 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 NONE ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
n, m, k = map(int, input().split()) p = list(map(int, input().split())) page_num = 1 shifted = 0 removed_without_shift = 0 num_of_operation = 1 for e in p: relative_pos = e - shifted if relative_pos <= page_num * k: removed_without_shift += 1 else: if removed_without_shift > 0: num_of_operation += 1 shifted += removed_without_shift relative_pos = e - shifted page_num = (relative_pos + k - 1) // k removed_without_shift = 1 print(num_of_operation)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
n, m, k = map(int, input().split()) s = 0 l = list(map(int, input().split())) + [10**19] mv, mvc = 0, 1 for i in range(1, m + 1): if (l[i] - mv - 1) // k != (l[i - 1] - mv - 1) // k: s += 1 mv += mvc mvc = 1 else: mvc += 1 print(s)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST BIN_OP NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
n, m, k = map(int, input().split(" ")) p = tuple(map(int, input().split(" "))) d = 0 part = (p[0] - 1) // k moves = 0 skip = 0 for pi in p: if (pi - 1 - d) // k == part: skip += 1 continue d += skip part = (pi - 1 - d) // k skip = 1 moves += 1 print(moves + 1)
ASSIGN VAR 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 ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
n, m, k = list(map(int, input().split())) l = list(map(int, input().split())) out = 0 d = 0 while m > d: nex = l[d] page = (nex - d - 1) // k add = 1 while d + add < m and page * k < l[d + add] - d <= (page + 1) * k: add += 1 d += add out += 1 print(out)
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
n, m, k = map(int, input().split()) P = [int(x) for x in input().split()] P.reverse() ops = 0 i = 1 while P: nxt = P[-1] togo = nxt - i skip = togo // k * k i += skip space = k while space: special = 0 while P and P[-1] < i + space: special += 1 P.pop() i += space if not special: break ops += 1 space = special print(ops)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR WHILE VAR ASSIGN VAR NUMBER WHILE VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
n, m, k = map(int, input().split()) p = map(int, input().split()) res = 0 tot = 0 cur = -1 cnt = 0 for v in p: if (v - tot - 1) // k == cur: cnt += 1 else: tot += cnt res += 1 cnt = 1 cur = (v - tot - 1) // k print(res)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
n, m, k = map(int, input().split()) p = list(map(int, input().split())) plist = [] for pp in p: plist.append([pp, pp // k, pp % k]) delta = 0 page = 0 c = 0 ans = 0 i = 0 while i < m: pp = p[i] - delta if (pp - 1) // k == page: c += 1 i += 1 elif c != 0: ans += 1 delta += c c = 0 page = (pp - 1) // k if c != 0: ans += 1 print(ans)
ASSIGN VAR 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 FOR VAR VAR EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
n, m, k = [int(x) for x in input().split()] p = [int(x) for x in input().split()] x = 0 counter = 0 answer = 0 p.append(10**100) prev = (p[0] - 1) // k for item in p: num = (item - counter - 1) // k if num != prev: counter += x x = 1 answer += 1 num = (item - counter - 1) // k prev = num else: x += 1 print(answer)
ASSIGN VAR 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 EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
deleted = 1 n, m, block = tuple(map(int, input().split())) numbers = tuple(map(int, input().split())) i = 0 cur_del = 0 iterations = 0 while True: iterations += 1 num = (numbers[i] - deleted) // block i += 1 cur_del += 1 if i >= len(numbers): print(iterations) exit(0) while numbers[i] - deleted < (num + 1) * block: i += 1 cur_del += 1 if i >= len(numbers): print(iterations) exit(0) deleted += cur_del cur_del = 0
ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER WHILE BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR NUMBER
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
n, m, k = map(int, input().split()) p = list(map(int, input().split())) res = 1 s = 1 c = 0 q = (p[0] - s) // k i = 0 while i < m: if (p[i] - s) // k == q: c += 1 else: res += 1 s += c c = 0 q = (p[i] - s) // k i -= 1 i += 1 print(res)
ASSIGN VAR 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 BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
n, m, k = map(int, input().split()) pp = list(map(int, input().split())) ops = 0 index = 0 count = 0 l = len(pp) while index < l and count < m: idx = index page = (pp[index] - idx - 1) // k ops += 1 index += 1 count += 1 while index < l and (pp[index] - idx - 1) // k < page + 1: index += 1 print(ops)
ASSIGN VAR 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 FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
n, m, k = map(int, input().split()) a = list(map(int, input().split())) a.append(10**20) t = 0 y = 0 i = 0 while i < m: y = i while (a[i + 1] - y - 1) % k > (a[i] - y - 1) % k and a[i + 1] - a[i] < k: i += 1 i += 1 t += 1 print(t)
ASSIGN VAR 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 BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR WHILE BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
N, M, K = [int(i) for i in input().split()] A = [(int(i) - 1) for i in input().split()] A.sort() i = 0 count = 0 while i < M: curr_k = (A[i] - i) // K j = i while j < M and (A[j] - i) // K == curr_k: j += 1 i = j count += 1 print(count)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
n, m, k = [int(i) for i in input().split()] p = [int(i) for i in input().split()] offset = 0 i = 0 sofar = 0 border = k ans = 0 while i < m: if p[i] - offset <= border: sofar += 1 i += 1 elif sofar != 0: offset += sofar sofar = 0 ans += 1 elif sofar == 0: nxt = p[i] - offset if nxt % k == 0: jmp = nxt // k jmp = jmp * k border = jmp while p[i] - offset > border: jmp += k border = jmp else: jmp = nxt // k jmp = jmp * k jmp += k border = jmp while p[i] - offset > border: jmp += k border = jmp border = jmp print(ans + 1)
ASSIGN VAR 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 ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR WHILE BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR WHILE BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
from sys import stdin, stdout n, m, k = map(int, stdin.readline().split()) ps = list(map(int, stdin.readline().split())) ps = [(p - 1) for p in ps] ans = 0 deleted = 0 idx = 0 len_ps = len(ps) while idx < len_ps: ans += 1 this_del = 0 killed = (ps[idx] - deleted) // k * k while idx < len_ps and ps[idx] - deleted < killed + k: this_del += 1 idx += 1 deleted += this_del stdout.write(str(ans) + "\n")
ASSIGN VAR 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 VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR WHILE VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
def find_operations(num_per_page, special_numbers): i = 0 count = 0 while i < len(special_numbers): curr_special_number = special_numbers[i] curr_special_page = get_special_page(num_per_page, curr_special_number, i) largest_on_curr_page = get_largest(num_per_page, curr_special_page, i) count += 1 while i < len(special_numbers) and special_numbers[i] <= largest_on_curr_page: i += 1 return count def get_special_page(num_per_page, special_number, removed_amount): return (special_number - 1 - removed_amount) // num_per_page + 1 def get_largest(num_per_page, page_number, removed_amount): return num_per_page * page_number + removed_amount n, m, k = [int(x) for x in input().split()] special_numbers = [int(x) for x in input().split()] print(find_operations(k, special_numbers))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
n, m, k = [int(i) for i in input().split()] item_ind = [int(i) for i in input().split()] group_index = 0 operation_count = 0 i = 0 while i < len(item_ind): operation_count += 1 block_num = (item_ind[i] - i - 1) // k num_count = 0 for j in range(i + 1, len(item_ind)): if block_num != (item_ind[j] - i - 1) // k: break else: num_count += 1 i += 1 + num_count print(operation_count)
ASSIGN VAR 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 WHILE VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
import sys def func(s, i): s = s.strip().split(" ") i = i.strip().split(" ") n = int(s[0]) m = int(s[1]) k = int(s[2]) ind = [int(ind) for ind in i] ans = 1 l = (ind[0] - 1) // k * k + 1 r = l + k - 1 delta = 0 new = True for i in ind: if i >= l and i <= r: delta += 1 else: ans += 1 l += delta r += delta if r < i: d = (i - r + k - 1) // k * k l += d r += d delta = 1 return ans assert func("10 4 5", "3 5 7 10") == 3 assert func("13 4 5", "7 8 9 10") == 1 assert func("1 1 1", "1") == 1 s = sys.stdin.readline() i = sys.stdin.readline() print(func(s, i))
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER RETURN VAR FUNC_CALL VAR STRING STRING NUMBER FUNC_CALL VAR STRING STRING NUMBER FUNC_CALL VAR STRING STRING NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
n, m, k = map(int, input().split()) l = list(map(int, input().strip().split())) check, count, moves = 0, 0, 0 i = 1 l = [0] + l while i < m + 1: if check < l[i] and moves == 0: if (l[i] - check) % k != 0: check = check + ((l[i] - check) // k + 1) * k else: check = check + (l[i] - check) // k * k count += 1 elif l[i] <= check: moves += 1 i += 1 else: check += moves moves = 0 if l[i] <= check: moves += 1 count += 1 i += 1 print(count)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
n, m, k = map(int, input().split()) specials = list(map(int, input().split())) pointer = k turn = 0 pop_count = 0 lookup = 0 while specials: if specials[lookup] > pointer: pointer += (specials[lookup] - pointer + k - 1) // k * k while specials[lookup] <= pointer: lookup += 1 pop_count += 1 if lookup == m: break turn += 1 pointer += pop_count pop_count = 0 if lookup == m: break print(turn)
ASSIGN VAR 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR IF VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR VAR WHILE VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
n, m, k = [int(i) for i in input().split()] p = [int(i) for i in input().split()] s = p[0] // k r = 0 x = 0 for i in range(m): if i + 1 == m or (p[i + 1] - x - 1) // k != (p[i] - x - 1) // k: r += 1 x = i + 1 print(r)
ASSIGN VAR 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 VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
n, m, k = map(int, input().strip().split()) p = list(map(int, input().strip().split())) c = i = 0 while i < m: j = i while j < m - 1 and (p[j + 1] - i - 1) // k == (p[i] - i - 1) // k: j += 1 i = j + 1 c += 1 print(c)
ASSIGN VAR 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 ASSIGN VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR WHILE VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
def gns(): return list(map(int, input().split())) n, m, k = gns() ms = gns() ms = [(x - 1) for x in ms] ans = 0 if k == 1: print(m) quit() i = 0 while i < m: ans += 1 p = (ms[i] % k + k - i % k) % k to = ms[i] + (k - p) - 1 while i < m and ms[i] <= to: i += 1 print(ans)
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
n, m, k = map(int, input().split()) arr = [0] + list(map(int, input().split())) ans, s, now = 0, 0, 1 while now <= m: r = ((arr[now] - s - 1) // k + 1) * k + s while now <= m and arr[now] <= r: s += 1 now += 1 ans += 1 print(ans)
ASSIGN VAR 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 NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
ints = [int(x) for x in input().split()] n = ints[0] m = ints[1] k = ints[2] special = [int(x) for x in input().split()] numOn = 0 numOps = 0 while numOn < m: numOps += 1 op = (special[numOn] - numOn - 1) // k * k + k + numOn + 1 while numOn < m and special[numOn] < op: numOn += 1 print(numOps)
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
n, m, k = map(int, input().split()) arr = [int(x) for x in input().split()] modulo = 0 tmp = 0 op = 1 cur = (arr[0] - 1) // k for i in range(m): if (arr[i] - 1 - modulo) // k != cur: modulo += tmp cur = (arr[i] - 1 - modulo) // k tmp = 0 op += 1 tmp += 1 print(op)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
def s(i, ans, x): if i == len(data): return ans else: y = 0 prov = (data[i] - x - 1) // k * k while i != len(data) and prov + 1 <= data[i] - x <= prov + k: i += 1 y += 1 x += y ans += 1 return s(i, ans, x) n, m, k = map(int, input().split()) data = list(map(int, input().split())) data.sort() i = 0 x = 0 ans = 0 while i != len(data): y = 0 prov = (data[i] - x - 1) // k * k while i != len(data) and prov + 1 <= data[i] - x <= prov + k: i += 1 y += 1 x += y ans += 1 print(ans)
FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR WHILE VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR ASSIGN VAR 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR WHILE VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
n, m, k = map(int, input().split()) a = list(map(int, input().split())) for i in range(m): a[i] -= 1 l = 0 ct = 0 moves = 0 while l < m: cur = (a[l] - ct) % k r = l + 1 while ( r < m and (a[r] - ct) % k > (a[l] - ct) % k and (a[r] - ct) // k == (a[l] - ct) // k ): r += 1 ct += r - l moves += 1 l = r print(moves)
ASSIGN VAR 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 FOR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
l = input().split() n = int(l[0]) m = int(l[1]) k = int(l[2]) offset = 0 l = input().split() li = [(int(i) - 1) for i in l] li.sort() count = 1 z = 1 for i in range(1, m): if (li[i] - offset) // k == (li[i - 1] - offset) // k: z += 1 continue else: count += 1 offset = z z += 1 print(count)
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 VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
n, m, k = map(int, input().split()) discard = list(map(int, input().split())) startK = (int(discard[0] / k) + (discard[0] % k != 0)) * k step = 0 id = 0 while True: disnum = 0 while id < m and startK >= discard[id]: disnum += 1 id += 1 startK += disnum if disnum == 0: if id == m: break startK += ( int((discard[id] - startK) / k + ((discard[id] - startK) % k != 0)) * k ) else: step += 1 print(step)
ASSIGN VAR 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 BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR IF VAR NUMBER IF VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
n, m, k = map(int, input().split()) s = list(map(int, input().split())) de = 0 ans = 0 g = 0 i = 0 u = 0 while i < m: g = s[i] - de if g % k == 0: f = g else: f = g + k - g % k u = 0 while i < m and s[i] - de <= f: i += 1 u += 1 de += u ans += 1 print(ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
iarr = list(map(int, input().split())) n = iarr[0] m = iarr[1] k = iarr[2] arr = list(map(int, input().split())) i = 0 previ = 0 ans = 0 while i < m: page = (arr[i] - previ) // k if k * page != arr[i] - previ: page += 1 i += 1 while True: if i >= m: break if k * (page - 1) < arr[i] - previ <= k * page: i += 1 else: break previ = i ans += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER WHILE NUMBER IF VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
n, m, k = map(int, input().split(" ")) sub = 0 limit = k out = 0 did = False tmp_count = 0 ps = list(map(int, input().split(" "))) i = 0 while i < m: p = ps[i] if p > limit: if did: out += 1 did = False if tmp_count > 0: limit += tmp_count sub = limit - k else: tmp = p - limit if tmp % k == 0: r = tmp // k else: r = tmp // k + 1 limit += r * k sub = limit - k tmp_count = 0 continue tmp_count += 1 if not did: did = True i += 1 if did: out += 1 print(out)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR IF VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
n, m, k = map(int, input().strip().split()) p = list(map(int, input().strip().split())) sol = 0 r, i = k, 0 while i < len(p): removed = 0 while i < len(p) and p[i] <= r: removed += 1 i += 1 if removed > 0: sol += 1 r += removed else: r += max(k, k * ((p[i] - r) // k) if i < len(p) else k) print(sol)
ASSIGN VAR 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 ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
n, m, k = map(int, input().split()) arr = list(map(int, input().split())) border = k to_drop_i = 0 ops = 0 while to_drop_i < m: rest = border % k border = arr[to_drop_i] border += (rest - border) % k while to_drop_i < m and arr[to_drop_i] > border: border += k moved = 0 while to_drop_i < m and arr[to_drop_i] <= border: to_drop_i += 1 moved += 1 border += moved ops += 1 print(ops)
ASSIGN VAR 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
n, m, k = [int(x) for x in input().split()] l = [(int(x) - 1) for x in input().split()] i = 0 page = -1 sp = 0 deleted = 0 ans = 0 while i < m: if page == -1: page = (l[i] - deleted) // k sp += 1 i += 1 elif (l[i] - deleted) // k == page: sp += 1 i += 1 else: deleted += sp ans += 1 page = -1 sp = 0 print(ans + 1)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
n, m, k = map(int, input().split()) p = list(map(int, input().split())) cnt = 0 i = 0 s = 0 while i < len(p): c = (p[i] - s - 1) // k j = i w = 0 while j < len(p): if (p[j] - s - 1) // k == c: w = w + 1 else: break j = j + 1 cnt = cnt + 1 i = j s = s + w print(cnt)
ASSIGN VAR 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 WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
def func(n, m, k, arr): prev = 0 i = 0 count = 0 while i < m: page = (arr[i] - prev) // k if k * page != arr[i] - prev: page += 1 val = k * page i += 1 while i < m: if arr[i] - prev <= val: i += 1 else: break count += 1 prev = i return count a = [int(i) for i in input().split()] n = a[0] m = a[1] k = a[2] arr = [int(i) for i in input().split()] print(func(n, m, k, arr))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
import sys input = sys.stdin.readline n, m, k = map(int, input().split()) A = list(map(int, input().split())) A.append(n + 1) COMP = [] NOW = 0 for a in A: if a - NOW - 1 != 0: if a - NOW - 1 > 2 * k: COMP.append([(a - NOW - 1) % k + k, 0]) else: COMP.append([a - NOW - 1, 0]) COMP.append([1, 1]) NOW = a COMP.pop() ANS = 0 NOW_PAGE = 0 NOW_SCORE = 0 pa = 0 LEN = len(COMP) while pa < LEN: i, j = COMP[pa] if NOW_PAGE + i <= k: NOW_PAGE += i NOW_SCORE += j pa += 1 elif NOW_SCORE > 0: COMP[pa][0] -= k - NOW_PAGE NOW_PAGE = k - NOW_SCORE ANS += 1 NOW_SCORE = 0 elif NOW_PAGE == k: NOW_PAGE = 0 else: COMP[pa][0] -= k - NOW_PAGE NOW_PAGE = k - NOW_SCORE if NOW_SCORE > 0: ANS += 1 print(ANS)
IMPORT ASSIGN VAR VAR ASSIGN VAR 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 BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR LIST BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
n, m, k = map(int, input().split()) pre = [0] + [int(i) for i in input().split()] i = 1 ans = 0 pos = k while i <= m: cnt = 0 while i <= m and pre[i] <= pos: i += 1 cnt += 1 while cnt > 0: ans += 1 pos += cnt cnt = 0 while i <= m and pre[i] <= pos: i += 1 cnt += 1 if i <= m: pos += (pre[i] - pos - 1) // k * k + k print(ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
from sys import setcheckinterval, stdin setcheckinterval(1000) iin = lambda: int(stdin.readline()) lin = lambda: list(map(int, stdin.readline().split())) n, m, k = lin() a = lin() a = a[::-1] ans = 0 i = 0 su = 0 while 1: op = 0 while a and i * k < a[-1] - su <= i * k + k: x = a.pop() op += 1 su += op if op: ans += 1 if a: i = (a[-1] - su - 1) // k else: break print(ans)
EXPR FUNC_CALL VAR 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 VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR IF VAR VAR NUMBER IF VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
import sys def rint(): return map(int, sys.stdin.readline().split()) n, m, k = rint() p = list(rint()) i = 0 op = 0 kori = k while True: del_cnt = 0 while p[i] <= k: del_cnt += 1 i += 1 if i >= m: op += 1 print(op) exit() if del_cnt == 0: add_cnt = (p[i] - k) // kori if (p[i] - k) % kori: add_cnt += 1 k = k + kori * add_cnt continue k += del_cnt op += 1 print(op)
IMPORT FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
n, m, k = [int(i) for i in input().split()] liste_p = [(int(i) - 1) for i in input().split()] nombre_etape = 0 indice_courant = 0 indice_liste_p = 0 while indice_liste_p < len(liste_p): nombre_etape += 1 x = liste_p[indice_liste_p] - indice_liste_p debut = x - x % k fin = debut + k tmp = indice_liste_p while indice_liste_p < len(liste_p) and liste_p[indice_liste_p] - tmp < fin: indice_liste_p += 1 print(nombre_etape)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 ≀ m ≀ n) special items of them. These n items are marked with indices from 1 to n. In the beginning, the item with index i is placed on the i-th position. Items are divided into several pages orderly, such that each page contains exactly k positions and the last positions on the last page may be left empty. Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded. <image> Consider the first example from the statement: n=10, m=4, k=5, p=[3, 5, 7, 10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 3 and 5. After, the first page remains to be special. It contains [1, 2, 4, 6, 7], Tokitsukaze discards the special item with index 7. After, the second page is special (since it is the first page containing a special item). It contains [9, 10], Tokitsukaze discards the special item with index 10. Tokitsukaze wants to know the number of operations she would do in total. Input The first line contains three integers n, m and k (1 ≀ n ≀ 10^{18}, 1 ≀ m ≀ 10^5, 1 ≀ m, k ≀ n) β€” the number of items, the number of special items to be discarded and the number of positions in each page. The second line contains m distinct integers p_1, p_2, …, p_m (1 ≀ p_1 < p_2 < … < p_m ≀ n) β€” the indices of special items which should be discarded. Output Print a single integer β€” the number of operations that Tokitsukaze would do in total. Examples Input 10 4 5 3 5 7 10 Output 3 Input 13 4 5 7 8 9 10 Output 1 Note For the first example: * In the first operation, Tokitsukaze would focus on the first page [1, 2, 3, 4, 5] and discard items with indices 3 and 5; * In the second operation, Tokitsukaze would focus on the first page [1, 2, 4, 6, 7] and discard item with index 7; * In the third operation, Tokitsukaze would focus on the second page [9, 10] and discard item with index 10. For the second example, Tokitsukaze would focus on the second page [6, 7, 8, 9, 10] and discard all special items at once.
n, m, k = map(int, input().split()) spItem = list(map(int, input().split())) lnum = k ans = 0 def spItemChecker(): i = 0 while spItem[0] <= lnum: del spItem[0] i += 1 if len(spItem) == 0: break return i while len(spItem) > 0: if spItem[0] > lnum: ln = spItem[0] - lnum pg = ln // k if ln % k == 0 else ln // k + 1 lnum = pg * k + lnum lnum += spItemChecker() ans += 1 print(ans)
ASSIGN VAR 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 ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN VAR WHILE FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR