description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0.
Return the minimum number of K-bit flips required so that there is no 0 in the array. If it is not possible, return ... | class Solution:
def minKBitFlips(self, A: List[int], K: int) -> int:
flipped = deque()
count = 0
flips = 0
for i in range(len(A)):
if i > 0:
x = flipped.popleft() if i >= K else 0
count -= x
if (A[i] + count) % 2 == 0:
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN FU... |
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0.
Return the minimum number of K-bit flips required so that there is no 0 in the array. If it is not possible, return ... | class Solution:
def minKBitFlips(self, A: List[int], K: int) -> int:
win = collections.deque()
ans = 0
for i, x in enumerate(A):
while len(win) > 0 and win[0] < i - K + 1:
win.popleft()
if x ^ len(win) % 2 == 0:
if i + K - 1 <= len(A) ... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR IF BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBE... |
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0.
Return the minimum number of K-bit flips required so that there is no 0 in the array. If it is not possible, return ... | class Solution:
def minKBitFlips(self, A, K: int) -> int:
flipped, res = 0, 0
length = len(A)
isFlipped = [0] * length
for i, v in enumerate(A):
if i >= K:
flipped ^= isFlipped[i - K]
if flipped == v:
if i + K > length:
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR IF BIN_OP VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR VAR |
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0.
Return the minimum number of K-bit flips required so that there is no 0 in the array. If it is not possible, return ... | class Solution:
def minKBitFlips(self, A: List[int], K: int) -> int:
count = 0
flippings = [(False) for _ in A]
flipped = False
for i in range(len(A)):
if flippings[i]:
flipped = not flipped
if not flipped and A[i] == 0 or flipped and A[i] == ... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR VAR RETURN NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN V... |
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0.
Return the minimum number of K-bit flips required so that there is no 0 in the array. If it is not possible, return ... | class Solution:
def minKBitFlips(self, A: List[int], K: int) -> int:
i = 0
c = 0
q = collections.deque()
sign = 0
for i in range(len(A)):
if q and i == q[0]:
sign = 1 - sign
q.popleft()
if A[i] != sign:
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR IF VAR VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR A... |
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0.
Return the minimum number of K-bit flips required so that there is no 0 in the array. If it is not possible, return ... | class Solution:
def minKBitFlips(self, A: List[int], K: int) -> int:
interval_status = [0] * (len(A) + 1)
counter = 0
prev = 0
for i in range(len(A)):
prev ^= interval_status[i]
curr_status = prev ^ A[i]
if curr_status == 0:
if i +... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMB... |
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0.
Return the minimum number of K-bit flips required so that there is no 0 in the array. If it is not possible, return ... | class Solution:
def minKBitFlips(self, A: List[int], k: int) -> int:
q = collections.deque()
res = 0
for i in range(len(A)):
if len(q) % 2 == 0:
if A[i] == 0:
res += 1
q.append(i + k - 1)
elif A[i] == 1:
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR... |
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0.
Return the minimum number of K-bit flips required so that there is no 0 in the array. If it is not possible, return ... | class Solution:
def minKBitFlips(self, A: List[int], K: int) -> int:
n = len(A)
flip_count = 0
hint = [0] * n
min_flip = 0
for i in range(n):
if i >= K and hint[i - K] == 1:
flip_count -= 1
if flip_count % 2 == A[i]:
if... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR IF BIN_OP VAR VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER RETURN ... |
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0.
Return the minimum number of K-bit flips required so that there is no 0 in the array. If it is not possible, return ... | class Solution:
def minKBitFlips(self, A: List[int], K: int) -> int:
count = 0
stack = []
for i in range(len(A)):
if stack and i == stack[0]:
stack.pop(0)
if A[i] == len(stack) % 2:
if i + K > len(A):
return -1
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR RETURN NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR RETURN VAR VAR |
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0.
Return the minimum number of K-bit flips required so that there is no 0 in the array. If it is not possible, return ... | class Solution:
def minKBitFlips(self, A: List[int], K: int) -> int:
start = 0
count = 0
res = 0
for end, a in enumerate(A):
if count ^ A[end] == 0:
A[end] -= 2
res += 1
count ^= 1
if end >= start + K - 1:
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER V... |
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0.
Return the minimum number of K-bit flips required so that there is no 0 in the array. If it is not possible, return ... | class Solution:
def minKBitFlips(self, A: "List[int]", K: "int") -> "int":
idx = 0
num_digits = len(A)
A_bitrep = int("1" + "".join([str(i) for i in A]), 2)
K_bitrep = 2**K - 1
num_flips = 0
while A_bitrep > K_bitrep:
if A_bitrep & 1 == 0:
... | CLASS_DEF FUNC_DEF STRING STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR VAR VAR NUMBER RETURN VAR VAR VAR... |
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0.
Return the minimum number of K-bit flips required so that there is no 0 in the array. If it is not possible, return ... | class Solution:
def minKBitFlips(self, A: List[int], K: int) -> int:
N = len(A)
hint = [0] * N
counter = 0
flip = 0
for i, x in enumerate(A):
flip = (flip + hint[i]) % 2
if x == 1 and flip == 1 or x == 0 and flip == 0:
counter += 1
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP NUMB... |
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0.
Return the minimum number of K-bit flips required so that there is no 0 in the array. If it is not possible, return ... | class Solution:
def minKBitFlips(self, A: List[int], K: int) -> int:
l = len(A)
rem = l % K
prev = 1
change_list = [[] for i in range(K)]
for ind, num in enumerate(A):
if prev != num:
prev = num
change_list[ind % K].append(ind)
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR... |
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0.
Return the minimum number of K-bit flips required so that there is no 0 in the array. If it is not possible, return ... | class Solution:
def minKBitFlips(self, A, K):
cur = res = 0
for i in range(len(A)):
if i >= K and A[i - K] == 2:
cur -= 1
if cur % 2 == A[i]:
if i + K > len(A):
return -1
A[i] = 2
cur, res = ... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN VAR |
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0.
Return the minimum number of K-bit flips required so that there is no 0 in the array. If it is not possible, return ... | class Solution:
def minKBitFlips(self, A: List[int], K: int) -> int:
n = len(A)
D = [0] * n
D[0] = A[0]
for i in range(n - 1):
D[i + 1] = A[i + 1] ^ A[i]
D.append(0)
cnt = 0
if D[0] == 0:
cnt += 1
D[0] ^= 1
D[K]... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER VAR NUMBER NUMB... |
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0.
Return the minimum number of K-bit flips required so that there is no 0 in the array. If it is not possible, return ... | class Solution:
def minKBitFlips(self, A: List[int], K: int) -> int:
flips = 0
carry = 10
result = 0
valid = True
for i, num in enumerate(A):
if A[i] & 1 == flips & 1:
result += 1
flips += 1
if i < len(A) - K + 1:
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER... |
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0.
Return the minimum number of K-bit flips required so that there is no 0 in the array. If it is not possible, return ... | class Solution:
def minKBitFlips(self, A: List[int], K: int) -> int:
flip_pos = 0
flip_inds = []
for i in range(len(A)):
while flip_pos < len(flip_inds) and i - K + 1 > flip_inds[flip_pos]:
flip_pos += 1
cur_bit = A[i] ^ ((len(flip_inds) - flip_pos) %... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR VAR IF VAR NUMBER RETURN NUMBER... |
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0.
Return the minimum number of K-bit flips required so that there is no 0 in the array. If it is not possible, return ... | class Solution:
def minKBitFlips(self, A: List[int], K: int) -> int:
tot = 0
flips = []
mask = 0
for i in range(len(A) - (K - 1)):
if flips and i == flips[0]:
flips.pop(0)
mask ^= 1
if A[i] == mask:
flips.append... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR... |
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0.
Return the minimum number of K-bit flips required so that there is no 0 in the array. If it is not possible, return ... | class Solution:
def minKBitFlips(self, A: List[int], K: int) -> int:
res = 0
flip = 0
for i in range(len(A)):
if flip % 2 != 0:
if A[i] % 10:
res += 1
flip += 1
if i + K - 1 >= len(A):
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR RETURN NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER VAR NUMBE... |
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0.
Return the minimum number of K-bit flips required so that there is no 0 in the array. If it is not possible, return ... | class Solution:
def minKBitFlips(self, A: List[int], K: int) -> int:
N = len(A)
flips = []
res, total = 0, 0
for i, v in enumerate(A):
if i < N - K + 1:
if v == 1:
if total & 1:
total += 1
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ... |
In an array A containing only 0s and 1s, a K-bit flip consists of choosing a (contiguous) subarray of length K and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0.
Return the minimum number of K-bit flips required so that there is no 0 in the array. If it is not possible, return ... | class Solution:
def minKBitFlips(self, A: List[int], K: int) -> int:
res = 0
flip = 0
na = [0] * len(A)
for i, x in enumerate(A):
flip ^= na[i]
if flip ^ x == 0:
res += 1
flip ^= 1
if i + K > len(A):
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR RETURN NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER RETU... |
Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, find the duplicate one.
Example 1:
Input: [1,3,4,2,2]
Output: 2
Example 2:
Input: [3,1,3,4,2]
Output: 3
Note:
... | class Solution:
def findDuplicate(self, nums):
left, right = 0, len(nums) - 1
mid = (left + right) // 2
while right - left > 1:
count = 0
for num in nums:
if mid < num <= right:
count += 1
if count > right - mid:
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR |
Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, find the duplicate one.
Example 1:
Input: [1,3,4,2,2]
Output: 2
Example 2:
Input: [3,1,3,4,2]
Output: 3
Note:
... | class Solution:
def findDuplicate(self, nums):
if len(nums) == 0:
return None
slow = fast = nums[0]
while True:
slow = nums[slow]
fast = nums[nums[fast]]
if slow == fast:
break
fast = nums[0]
while slow != fast:... | CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NONE ASSIGN VAR VAR VAR NUMBER WHILE NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR |
Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, find the duplicate one.
Example 1:
Input: [1,3,4,2,2]
Output: 2
Example 2:
Input: [3,1,3,4,2]
Output: 3
Note:
... | class Solution:
def findDuplicate(self, nums):
low, high = 1, len(nums) - 1
while low < high:
mid = (low + high) // 2
count = 0
for i in nums:
if i <= mid:
count += 1
if count <= mid:
low = mid + 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR |
Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, find the duplicate one.
Example 1:
Input: [1,3,4,2,2]
Output: 2
Example 2:
Input: [3,1,3,4,2]
Output: 3
Note:
... | class Solution:
def findDuplicate(self, nums):
fast, slow = nums[0], nums[0]
while True:
slow = nums[slow]
fast = nums[fast]
fast = nums[fast]
if slow == fast:
break
ptr1 = nums[0]
ptr2 = fast
while ptr1 != ptr2... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR NUMBER VAR NUMBER WHILE NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR |
Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, find the duplicate one.
Example 1:
Input: [1,3,4,2,2]
Output: 2
Example 2:
Input: [3,1,3,4,2]
Output: 3
Note:
... | class Solution:
def findDuplicate(self, nums):
st = set()
for i in range(len(nums)):
n = nums[i]
if n not in st:
st.add(n)
else:
return n | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR |
Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, find the duplicate one.
Example 1:
Input: [1,3,4,2,2]
Output: 2
Example 2:
Input: [3,1,3,4,2]
Output: 3
Note:
... | class Solution:
def findDuplicate(self, nums):
n = len(nums) - 1
a = 1
b = n
while a < b:
m = (a + b) // 2
lCount = 0
hCount = 0
for k in nums:
if a <= k <= m:
lCount += 1
elif m < k ... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VA... |
Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, find the duplicate one.
Example 1:
Input: [1,3,4,2,2]
Output: 2
Example 2:
Input: [3,1,3,4,2]
Output: 3
Note:
... | class Solution:
def findDuplicate(self, nums):
for n in nums:
if n < 0:
i = -n
else:
i = n
ind = i - 1
if nums[ind] < 0:
return i
else:
nums[ind] = -nums[ind]
return extra | CLASS_DEF FUNC_DEF FOR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR VAR VAR RETURN VAR |
Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, find the duplicate one.
Example 1:
Input: [1,3,4,2,2]
Output: 2
Example 2:
Input: [3,1,3,4,2]
Output: 3
Note:
... | class Solution:
def findDuplicate(self, nums):
nums.sort()
i = 0
while i < len(nums):
if nums[i] == nums[i + 1]:
return nums[i]
i += 1 | CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR VAR NUMBER |
This is the easy version of the problem. The only difference is that in this version $q = 1$.
You are given an array of integers $a_1, a_2, \ldots, a_n$.
The cost of a subsegment of the array $[l, r]$, $1 \leq l \leq r \leq n$, is the value $f(l, r) = \operatorname{sum}(l, r) - \operatorname{xor}(l, r)$, where $\oper... | test = int(input())
for testtest in range(test):
n, q = map(int, input().split())
L = list(map(int, input().split()))
l, r = map(int, input().split())
s = 0
x = 0
S = [0] * n
X = [0] * n
for i in range(n):
s += L[i]
x ^= L[i]
S[i] = s
X[i] = x
S += [0]... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSI... |
This is the easy version of the problem. The only difference is that in this version $q = 1$.
You are given an array of integers $a_1, a_2, \ldots, a_n$.
The cost of a subsegment of the array $[l, r]$, $1 \leq l \leq r \leq n$, is the value $f(l, r) = \operatorname{sum}(l, r) - \operatorname{xor}(l, r)$, where $\oper... | t = int(input())
for _ in range(t):
n, q = map(int, input().split())
vals = list(map(int, input().split()))
L, R = map(int, input().split())
L -= 1
R -= 1
s = 0
xr = 0
for i in range(L, R + 1):
s += vals[i]
xr ^= vals[i]
f = s - xr
l, r = L, L
ml, mr = L, R
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CAL... |
This is the easy version of the problem. The only difference is that in this version $q = 1$.
You are given an array of integers $a_1, a_2, \ldots, a_n$.
The cost of a subsegment of the array $[l, r]$, $1 \leq l \leq r \leq n$, is the value $f(l, r) = \operatorname{sum}(l, r) - \operatorname{xor}(l, r)$, where $\oper... | def compute(prefixS, prefixXor, l, r):
if l == 0:
return prefixS[r] - prefixXor[r]
return prefixS[r] - prefixS[l - 1] - (prefixXor[r] ^ prefixXor[l - 1])
t = int(input())
while t:
n, q = list(map(int, input().split()))
nums = list(map(int, input().split()))
l, r = list(map(int, input().spl... | FUNC_DEF IF VAR NUMBER RETURN BIN_OP VAR VAR VAR VAR RETURN BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_C... |
You are given a table consisting of n rows and m columns. Each cell of the table contains a number, 0 or 1. In one move we can choose some row of the table and cyclically shift its values either one cell to the left, or one cell to the right.
To cyclically shift a table row one cell to the right means to move the valu... | n, m = map(int, input().split())
memo = [[int(2000000000.0) for j in range(m)] for i in range(n)]
for i in range(n):
s = input()
if s.find("1") == -1:
print(-1)
exit()
memo[i][0] = s[::-1].find("1") + 1
memo[i][m - 1] = s.find("1") + 1
for j in range(m):
if s[j] == "1":
... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER STRING NUM... |
You are given a table consisting of n rows and m columns. Each cell of the table contains a number, 0 or 1. In one move we can choose some row of the table and cyclically shift its values either one cell to the left, or one cell to the right.
To cyclically shift a table row one cell to the right means to move the valu... | x = int(input().split(" ")[0])
y = []
for i in range(x):
y.append(input())
for x in y:
if "1" not in x:
print("-1")
exit()
s = "00010100"
s = "000100110"
def row_cost_cal(string):
arrL = [""] * len(string)
initPosL = 0
if string[0] != "1":
initPosL = -(len(string) - string.... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR IF STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING FUNC_DEF ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR ASSIGN VAR NUMBER ... |
You are given a table consisting of n rows and m columns. Each cell of the table contains a number, 0 or 1. In one move we can choose some row of the table and cyclically shift its values either one cell to the left, or one cell to the right.
To cyclically shift a table row one cell to the right means to move the valu... | def calc_shift_cost(row):
starts = [i for i, x in enumerate(row) if x]
for start in starts:
d = 2
pos = start + 1
if pos == len(row):
pos = 0
while row[pos] != 1:
if row[pos]:
row[pos] = min(row[pos], d)
else:
ro... | FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN ... |
You are given a table consisting of n rows and m columns. Each cell of the table contains a number, 0 or 1. In one move we can choose some row of the table and cyclically shift its values either one cell to the left, or one cell to the right.
To cyclically shift a table row one cell to the right means to move the valu... | def calculate_row_distance(row, rows_len):
init_i = row.index(1)
dist = 0
dists = [(-1) for i in range(rows_len)]
i = init_i
for x in range(rows_len):
if i == rows_len:
i = 0
if row[i] == 1:
dist = 0
dists[i] = 0
elif dists[i] == -1 or dist... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER... |
You are given a table consisting of n rows and m columns. Each cell of the table contains a number, 0 or 1. In one move we can choose some row of the table and cyclically shift its values either one cell to the left, or one cell to the right.
To cyclically shift a table row one cell to the right means to move the valu... | import sys
n, m = map(int, input().split())
mp = ["" for i in range(n)]
f = [[(0) for j in range(m)] for i in range(n)]
for i in range(n):
mp[i] = input()
if mp[i].find("1") == -1:
print(-1)
sys.exit()
tmp = mp[i][::-1].find("1") + 1
for j in range(m):
if mp[i][j] == "1":
... | IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR STRING NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP F... |
You are given a table consisting of n rows and m columns. Each cell of the table contains a number, 0 or 1. In one move we can choose some row of the table and cyclically shift its values either one cell to the left, or one cell to the right.
To cyclically shift a table row one cell to the right means to move the valu... | def binS(a, x, n):
l, r = -1, n
while l + 1 < r:
m = (l + r) // 2
if a[m] >= x:
r = m
else:
l = m
return min(abs(a[r] - x), abs(a[r - 1] - x))
def main():
n, m = [int(i) for i in input().split()]
q = [0] * m
for i in range(n):
s = input()... | FUNC_DEF ASSIGN VAR VAR NUMBER VAR WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR A... |
You are given a table consisting of n rows and m columns. Each cell of the table contains a number, 0 or 1. In one move we can choose some row of the table and cyclically shift its values either one cell to the left, or one cell to the right.
To cyclically shift a table row one cell to the right means to move the valu... | G = [[], [1], [1, 1], [1, 2, 1], [1, 2, 2, 1], [1, 2, 3, 2, 1]]
def g(k):
global G
if k < 6:
return G[k]
return list(range(1, (k + 1) // 2 + 1)) + list(range(k // 2, 0, -1))
def f():
n, m = map(int, input().split())
s, p = [0] * m, [0] * m
for i in range(n):
q = [j for j, x i... | ASSIGN VAR LIST LIST LIST NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF IF VAR NUMBER RETURN VAR VAR RETURN BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR BIN_OP V... |
Toad Rash has a binary string s. A binary string consists only of zeros and ones.
Let n be the length of s.
Rash needs to find the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Find th... | s = input()
n = len(s)
ans = 0
X = []
for x in range(n):
k = 1
while x + 2 * k < n and (s[x] != s[x + k] or s[x] != s[x + 2 * k]):
k += 1
if x + 2 * k < n:
X += [(x, x + 2 * k)]
for i in range(len(X) - 2, -1, -1):
X[i] = X[i][0], min(X[i][1], X[i + 1][1])
I = 0
if len(X):
for l in ra... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR BIN_OP NUMBER VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR LIST VAR BIN_OP VAR BIN_OP NUM... |
Toad Rash has a binary string s. A binary string consists only of zeros and ones.
Let n be the length of s.
Rash needs to find the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Find th... | from sys import stdin
s = stdin.readline().strip()
x = -1
ans = 0
for i in range(len(s)):
for j in range(1, 10):
if i - 2 * j >= 0 and s[i] == s[i - j] and s[i - j] == s[i - 2 * j]:
if i - 2 * j > x:
ans += (i - 2 * j - x) * (len(s) - i)
x = i - 2 * j
print(ans) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP NUMBER VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR BIN_OP BIN_OP B... |
Toad Rash has a binary string s. A binary string consists only of zeros and ones.
Let n be the length of s.
Rash needs to find the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Find th... | X = [
[],
["0", "1"],
["00", "01", "10", "11"],
["001", "010", "011", "100", "101", "110"],
["0010", "0011", "0100", "0101", "0110", "1001", "1010", "1011", "1100", "1101"],
[
"00100",
"00101",
"00110",
"01001",
"01011",
"01100",
"01101",
... | ASSIGN VAR LIST LIST LIST STRING STRING LIST STRING STRING STRING STRING LIST STRING STRING STRING STRING STRING STRING LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING LIST STRING STRING STR... |
Toad Rash has a binary string s. A binary string consists only of zeros and ones.
Let n be the length of s.
Rash needs to find the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Find th... | def good(l, r):
for x in range(l, r):
for k in range(1, 10):
if x + (k << 1) <= r:
if s[x] == s[x + k] and s[x + k] == s[x + (k << 1)]:
return False
else:
break
return True
s = input()
n = len(s)
answer = 0
for l in range(n):
... | FUNC_DEF FOR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR A... |
Toad Rash has a binary string s. A binary string consists only of zeros and ones.
Let n be the length of s.
Rash needs to find the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Find th... | s = input()
n = len(s)
l = 0
ans = 0
for i in range(n):
for j in range(i - 1, l, -1):
if 2 * j - i < l:
break
if s[i] == s[j] == s[j + j - i]:
ans += (2 * j - i - l + 1) * (n - i)
l = 2 * j - i + 1
print(ans) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR VAR IF VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR NUMBER BIN... |
Toad Rash has a binary string s. A binary string consists only of zeros and ones.
Let n be the length of s.
Rash needs to find the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Find th... | import sys
data_string = input()
total_seq = 0
current_end_seq = 0
step = 0
while step < len(data_string) - 1:
step += 1
total_seq = total_seq + current_end_seq
min_d = 1
while step - 2 * min_d + 1 > current_end_seq:
if (
data_string[step]
== data_string[step - min_d]
... | IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN... |
Toad Rash has a binary string s. A binary string consists only of zeros and ones.
Let n be the length of s.
Rash needs to find the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Find th... | import sys
S = sys.stdin.readline()
S = S.strip()
n = len(S)
ans = 0
def check(i, j):
if j - i < 3:
return False
for x in range(i, j):
for k in range(1, j - i):
if x + 2 * k >= j:
break
if S[x] == S[x + k] == S[x + 2 * k]:
return True
... | IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_DEF IF BIN_OP VAR VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP NUMBER... |
Toad Rash has a binary string s. A binary string consists only of zeros and ones.
Let n be the length of s.
Rash needs to find the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Find th... | s = input()
def pri(l, r):
k = 1
while r - 2 * k >= l:
if s[r] != s[r - k] or s[r - k] != s[r - 2 * k]:
k += 1
continue
return False
return True
ans = 0
for i in range(len(s)):
j = i
while j < len(s) and pri(i, j):
j += 1
ans += len(s) - j
prin... | ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR BIN_OP NUMBER VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR FUNC_CA... |
Toad Rash has a binary string s. A binary string consists only of zeros and ones.
Let n be the length of s.
Rash needs to find the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Find th... | s = input()
len = len(s)
r = len
ans = 0
for l in range(len)[::-1]:
r = min(r, l + 9)
k = 1
while l + 2 * k < r:
if s[l] == s[l + k] and s[l] == s[l + 2 * k]:
r = min(r, l + 2 * k)
break
k += 1
ans += len - r
print(ans) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR BIN_OP NUMBER VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR ... |
Toad Rash has a binary string s. A binary string consists only of zeros and ones.
Let n be the length of s.
Rash needs to find the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such that 1 ≤ x, k ≤ n, l ≤ x < x + 2k ≤ r, and s_x = s_{x+k} = s_{x+2k}.
Find th... | def parse(c, n):
l = [-1] * n
for x in c:
se = set(x)
for i in range(len(x) - 1):
for j in range(i + 1, len(x)):
k = x[j] - x[i]
if x[i] + k + k >= n:
break
if x[i] + k + k in se:
l[x[i] + k + k] ... | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_O... |
You are given an array A of N integers. You must perform some (possibly zero) operations to make the elements of A distinct.
In one operation, you can either:
Remove one element from the beginning of the array A and append any positive integer to the end.
Or remove one element from the end of the array A and prepend a... | t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
ans, j = n, 0
index = dict()
for i in range(n):
if a[i] in index.keys():
j = max(j, index[a[i]])
index[a[i]] = i + 1
else:
index[a[i]] = i + 1
ans = mi... | 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 VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN... |
You are given an array A of N integers. You must perform some (possibly zero) operations to make the elements of A distinct.
In one operation, you can either:
Remove one element from the beginning of the array A and append any positive integer to the end.
Or remove one element from the end of the array A and prepend a... | ans = ""
for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
l, r = 0, 0
maxLen = 0
maxL, maxR = -1, -1
candi = []
st = set()
while r < n:
while r < n and arr[r] not in st:
st.add(arr[r])
r += 1
if maxLen <= r - l:
... | ASSIGN VAR STRING 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 VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR WHILE VAR VAR WHILE VAR VAR V... |
You are given an array A of N integers. You must perform some (possibly zero) operations to make the elements of A distinct.
In one operation, you can either:
Remove one element from the beginning of the array A and append any positive integer to the end.
Or remove one element from the end of the array A and prepend a... | for _ in range(int(input())):
N = int(input())
A = [int(i) for i in input().split()]
dict = {}
ans = 4 * N
front = 0
back = 0
while back < N:
if A[back] in dict:
for i in range(front, dict[A[back]]):
if A[i] in dict:
del dict[A[i]]
... | 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 DICT ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR... |
You are given an array A of N integers. You must perform some (possibly zero) operations to make the elements of A distinct.
In one operation, you can either:
Remove one element from the beginning of the array A and append any positive integer to the end.
Or remove one element from the end of the array A and prepend a... | def gcd(a, b):
if b == 0:
return a
return gcd(a % b, a)
def solve(arr, n):
a = {}
temp, ans, j = n - 1, n, 0
i = 0
while i < n:
temp = n - i - 1
if arr[i] in a:
j = max(a[arr[i]], j)
else:
j = max(0, j)
a[arr[i]] = 1 + i
a... | FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR DICT ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VA... |
You are given an array A of N integers. You must perform some (possibly zero) operations to make the elements of A distinct.
In one operation, you can either:
Remove one element from the beginning of the array A and append any positive integer to the end.
Or remove one element from the end of the array A and prepend a... | result = []
t = int(input())
for _ in range(t):
n = int(input())
arr = list(map(int, input().strip().split()))
mapIndex = dict()
st, ed = 0, n - 1
res = []
for i in range(n):
if arr[i] not in mapIndex:
mapIndex[arr[i]] = i
ed = i
else:
ind = ma... | ASSIGN VAR LIST 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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR A... |
You are given an array A of N integers. You must perform some (possibly zero) operations to make the elements of A distinct.
In one operation, you can either:
Remove one element from the beginning of the array A and append any positive integer to the end.
Or remove one element from the end of the array A and prepend a... | T = int(input())
def int_arr_input():
return [int(x) for x in input().split()]
def compute_next_idx(A, N):
next_idx = [(N - 1) for i in range(N)]
i = j = 0
cnt = dict()
while j < N:
j_key = str(A[j])
prev = cnt.get(j_key, 0)
cnt[j_key] = prev + 1
if prev == 1:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUM... |
You are given an array A of N integers. You must perform some (possibly zero) operations to make the elements of A distinct.
In one operation, you can either:
Remove one element from the beginning of the array A and append any positive integer to the end.
Or remove one element from the end of the array A and prepend a... | t = int(input())
def solve(ar):
mp = {}
n = len(ar)
ans = float("inf")
i, j = 0, 0
while j < n:
if ar[j] not in mp or mp[ar[j]] == 0:
mp[ar[j]] = 1
elif mp[ar[j]] == 1:
while ar[i] != ar[j]:
mp[ar[i]] -= 1
i += 1
i... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN ... |
You are given an array A of N integers. You must perform some (possibly zero) operations to make the elements of A distinct.
In one operation, you can either:
Remove one element from the beginning of the array A and append any positive integer to the end.
Or remove one element from the end of the array A and prepend a... | for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
mp = {}
j = 0
ans = 10000000000
for i in range(0, n):
if a[i] in mp:
mp[a[i]] += 1
else:
mp[a[i]] = 1
while mp[a[i]] > 1:
mp[a[j]] -= 1
j += ... | 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 DICT 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 N... |
You are given an array A of N integers. You must perform some (possibly zero) operations to make the elements of A distinct.
In one operation, you can either:
Remove one element from the beginning of the array A and append any positive integer to the end.
Or remove one element from the end of the array A and prepend a... | def fun(i, j, n):
left = i
right = n - j - 1
if left == right:
return 3 * left
elif left > right:
return 2 * right + left
else:
return 2 * left + right
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
d = {}
j = 0
ans = ... | FUNC_DEF ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR RETURN BIN_OP NUMBER VAR IF VAR VAR RETURN BIN_OP BIN_OP NUMBER VAR VAR RETURN BIN_OP BIN_OP NUMBER 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_... |
You are given an array A of N integers. You must perform some (possibly zero) operations to make the elements of A distinct.
In one operation, you can either:
Remove one element from the beginning of the array A and append any positive integer to the end.
Or remove one element from the end of the array A and prepend a... | t = int(input())
while t:
a = int(input())
b = list(map(int, input().split(" ")))
s, check, index = len(b) - 1, 0, a
p = 0
local = {}
while p < a:
k = s - p
c = local[b[p]] if b[p] in local.keys() else 0
check = max(c, check)
local[b[p]] = p + 1
mk = k + c... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR DICT WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR FUN... |
You are given an array A of N integers. You must perform some (possibly zero) operations to make the elements of A distinct.
In one operation, you can either:
Remove one element from the beginning of the array A and append any positive integer to the end.
Or remove one element from the end of the array A and prepend a... | t = int(input())
for _ in range(t):
n = int(input())
l1 = [int(i) for i in input().split()]
d1 = {}
for i in l1:
d1[i] = -1
j = 0
ans = -1
for i in range(n):
while j < n and d1[l1[j]] == -1:
d1[l1[j]] = 1
j += 1
if ans == -1:
ans = ... | 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 DICT FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR... |
You are given an array A of N integers. You must perform some (possibly zero) operations to make the elements of A distinct.
In one operation, you can either:
Remove one element from the beginning of the array A and append any positive integer to the end.
Or remove one element from the end of the array A and prepend a... | import sys
from itertools import islice
for s in islice(sys.stdin, 2, None, 2):
a = s.split()
n = len(a)
k = 0
r = 200000.0
d = {}
for i, x in enumerate(a):
m = i - d.get(x, -1)
d[x] = i
if m <= k:
k = m
else:
k += 1
r = min(r, n -... | IMPORT FOR VAR FUNC_CALL VAR VAR NUMBER NONE NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ... |
You are given an array A of N integers. You must perform some (possibly zero) operations to make the elements of A distinct.
In one operation, you can either:
Remove one element from the beginning of the array A and append any positive integer to the end.
Or remove one element from the end of the array A and prepend a... | for _ in range(int(input())):
s = int(input())
inp = list(map(int, input().split()))
dic = {}
j = 0
res = 10**10
for i in range(s):
if inp[i] not in dic.keys():
dic[inp[i]] = 1
else:
dic[inp[i]] += 1
while dic[inp[i]] > 1:
dic[inp[j]] -... | 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 DICT ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER WH... |
You are given an array A of N integers. You must perform some (possibly zero) operations to make the elements of A distinct.
In one operation, you can either:
Remove one element from the beginning of the array A and append any positive integer to the end.
Or remove one element from the end of the array A and prepend a... | for _ in range(int(input())):
n = int(input())
nums = list(map(int, input().split()))
unique, maxUnique, ind, s, queue = 0, 0, 0, set(), []
ans = float("inf")
for i in range(n):
if nums[i] not in s:
unique += 1
else:
if unique >= maxUnique:
max... | 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 VAR VAR VAR VAR NUMBER NUMBER NUMBER FUNC_CALL VAR LIST ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR AS... |
You are given an array A of N integers. You must perform some (possibly zero) operations to make the elements of A distinct.
In one operation, you can either:
Remove one element from the beginning of the array A and append any positive integer to the end.
Or remove one element from the end of the array A and prepend a... | def help(a):
map = dict()
n = len(a)
res = n
j = 0
for i in range(n):
r = n - i - 1
temp = 0
if a[i] in map:
temp = map[a[i]]
j = max(j, temp)
map[a[i]] = 1 + i
res = min(res, min(j, r) + j + r)
return res
for _ in range(int(input()))... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN... |
You are given an array A of N integers. You must perform some (possibly zero) operations to make the elements of A distinct.
In one operation, you can either:
Remove one element from the beginning of the array A and append any positive integer to the end.
Or remove one element from the end of the array A and prepend a... | t = int(input())
for i in range(t):
n = int(input())
ar = list(map(int, input().strip().split()))[:n]
dic = {}
r = n - 1
ans = n
j = 0
for i in range(n):
r = n - i - 1
if ar[i] in dic:
x = dic[ar[i]]
else:
x = 0
j = max(x, j)
di... | 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 FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VA... |
You are given an array A of N integers. You must perform some (possibly zero) operations to make the elements of A distinct.
In one operation, you can either:
Remove one element from the beginning of the array A and append any positive integer to the end.
Or remove one element from the end of the array A and prepend a... | for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
dic = {}
sample = []
max_l = start = 0
for i, key in enumerate(a):
if key in dic and start <= dic[key]:
start = dic[key] + 1
elif i - start + 1 > max_l:
max_l = i - start + ... | 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 DICT ASSIGN VAR LIST ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR... |
You are given an array A of N integers. You must perform some (possibly zero) operations to make the elements of A distinct.
In one operation, you can either:
Remove one element from the beginning of the array A and append any positive integer to the end.
Or remove one element from the end of the array A and prepend a... | import sys
from itertools import islice
for s in islice(sys.stdin, 2, None, 2):
a = s.split()
n = len(a)
d = {}
r = 200000.0
k = 0
for i, x in enumerate(map(int, a), 1):
k = min(i - d.get(x, 0), k + 1)
d[x] = i
r = min(r, n - k + min(i - k, n - i))
print(r) | IMPORT FOR VAR FUNC_CALL VAR VAR NUMBER NONE NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VA... |
You are given an array A of N integers. You must perform some (possibly zero) operations to make the elements of A distinct.
In one operation, you can either:
Remove one element from the beginning of the array A and append any positive integer to the end.
Or remove one element from the end of the array A and prepend a... | for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
a = {arr[0]}
i = 0
j = 1
ans = float("inf")
while j < n:
if arr[j] in a:
while arr[j] in a:
a.remove(arr[i])
i += 1
a.add(arr[j])
ans = min... | 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 VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING WHILE VAR VAR IF VAR VAR VAR WHILE VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ... |
You are given an array A of N integers. You must perform some (possibly zero) operations to make the elements of A distinct.
In one operation, you can either:
Remove one element from the beginning of the array A and append any positive integer to the end.
Or remove one element from the end of the array A and prepend a... | import sys
def printArr(a):
s = ""
for i in a:
s += str(i) + " "
print(s[0:-1])
sys.setrecursionlimit(10**5)
def topop(l, h, n):
x = n - h - 1
if x < l:
return 2 * x + l
else:
return 2 * l + x
t = int(input())
for _ in range(t):
n = int(input())
a = [int(_... | IMPORT FUNC_DEF ASSIGN VAR STRING FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR RETURN BIN_OP BIN_OP NUMBER VAR VAR RETURN BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC... |
You are given an array A of N integers. You must perform some (possibly zero) operations to make the elements of A distinct.
In one operation, you can either:
Remove one element from the beginning of the array A and append any positive integer to the end.
Or remove one element from the end of the array A and prepend a... | test = int(input())
while test:
n = int(input())
a = [int(x) for x in input().split()]
f = dict()
i = j = 0
ans = 1000000.0
while j < n:
if a[j] in f.keys():
f[a[j]] += 1
else:
f[a[j]] = 1
if f[a[j]] > 1:
while a[i] != a[j]:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE 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 ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER WHIL... |
You are given an array A of N integers. You must perform some (possibly zero) operations to make the elements of A distinct.
In one operation, you can either:
Remove one element from the beginning of the array A and append any positive integer to the end.
Or remove one element from the end of the array A and prepend a... | for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
dic = {}
for i in range(n):
dic[arr[i]] = 0
l = 0
h = n - 1
ans = n
for i in range(n):
temp = 0
h = n - 1 - i
l = max(dic[arr[i]], l)
dic[arr[i]] = 1 + i
a... | 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 DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN V... |
You are given an array A of N integers. You must perform some (possibly zero) operations to make the elements of A distinct.
In one operation, you can either:
Remove one element from the beginning of the array A and append any positive integer to the end.
Or remove one element from the end of the array A and prepend a... | t = int(input())
for _ in range(t):
n = int(input())
arr = list(map(int, input().split()))
ans = n
start = 0
x = 0
d = {arr[0]: 1}
for i in range(1, n):
d[arr[i]] = d.get(arr[i], 0) + 1
if d[arr[i]] > 1:
x = start
y = n - i
temp1 = 2 * x + ... | 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 VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP FUNC_... |
You are given an array A of N integers. You must perform some (possibly zero) operations to make the elements of A distinct.
In one operation, you can either:
Remove one element from the beginning of the array A and append any positive integer to the end.
Or remove one element from the end of the array A and prepend a... | for _ in range(int(input())):
n = int(input())
lis = list(map(int, input().split()))
coll = {}
for i in lis:
if i not in coll:
coll[i] = 0
p1 = 0
p2 = 0
ans = n - 1
l, r = -1, -1
while p2 < n:
if coll[lis[p2]] == 0:
coll[lis[p2]] = 1
... | 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 DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER WHILE VAR... |
You are given an array A of N integers. You must perform some (possibly zero) operations to make the elements of A distinct.
In one operation, you can either:
Remove one element from the beginning of the array A and append any positive integer to the end.
Or remove one element from the end of the array A and prepend a... | def func():
n = int(input())
arr = list(map(int, input().split()))
dic = {}
i = j = 0
ans = n
while i < n:
r = n - 1 - i
present = dic.get(arr[i], 0)
j = max(j, present)
dic[arr[i]] = i + 1
ans = min(min(j, r) + j + r, ans)
i += 1
print(ans)
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP... |
You are given an array A of N integers. You must perform some (possibly zero) operations to make the elements of A distinct.
In one operation, you can either:
Remove one element from the beginning of the array A and append any positive integer to the end.
Or remove one element from the end of the array A and prepend a... | def solve(n, arr):
i = 0
seen = set()
maxLen = 0
left = right = -1
res = float("inf")
for j in range(n):
while arr[j] in seen:
seen.remove(arr[i])
i += 1
seen.add(arr[j])
if j - i + 1 >= maxLen:
maxLen = j - i + 1
left = i
... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR ... |
You are given an array A of N integers. You must perform some (possibly zero) operations to make the elements of A distinct.
In one operation, you can either:
Remove one element from the beginning of the array A and append any positive integer to the end.
Or remove one element from the end of the array A and prepend a... | for i in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
l1 = []
s = {}
start = -1
mx = 0
l1 = []
for i in range(n):
if l[i] in s and s[l[i]] > start:
start = s[l[i]]
s[l[i]] = i
if i == n - 1:
l1.appen... | 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 LIST ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ... |
You are given an array A of N integers. You must perform some (possibly zero) operations to make the elements of A distinct.
In one operation, you can either:
Remove one element from the beginning of the array A and append any positive integer to the end.
Or remove one element from the end of the array A and prepend a... | inf = 10**6
for tcase in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
d = {}
l = 0
ans = inf
for i, x in enumerate(a):
if x in d:
v = d[x]
while l <= v:
del d[a[l]]
l += 1
d[x] = i
r = n ... | ASSIGN VAR BIN_OP NUMBER NUMBER 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 DICT ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR VAR VAR V... |
Toad Rash has a binary string $s$. A binary string consists only of zeros and ones.
Let $n$ be the length of $s$.
Rash needs to find the number of such pairs of integers $l$, $r$ that $1 \leq l \leq r \leq n$ and there is at least one pair of integers $x$, $k$ such that $1 \leq x, k \leq n$, $l \leq x < x + 2k \leq r... | def get_arr(v):
ans = []
while v != 0:
ans.append(v % 2)
v //= 2
return ans[::-1]
def check_arr(arr):
for i in range(len(arr)):
for di in range(1, (len(arr) - i) // 2 + 1):
if i + 2 * di >= len(arr):
continue
if arr[i] == arr[i + di] == a... | FUNC_DEF ASSIGN VAR LIST WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR V... |
Toad Rash has a binary string $s$. A binary string consists only of zeros and ones.
Let $n$ be the length of $s$.
Rash needs to find the number of such pairs of integers $l$, $r$ that $1 \leq l \leq r \leq n$ and there is at least one pair of integers $x$, $k$ such that $1 \leq x, k \leq n$, $l \leq x < x + 2k \leq r... | s = input()
n = len(s)
ans = 0
l = 0
for i in range(0, n):
for j in range(i - 1, l, -1):
if 2 * j - i < l:
break
if s[i] == s[j] == s[j + j - i]:
ans += (2 * j - i - l + 1) * (n - i)
l = 2 * j - i + 1
print(ans) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR VAR IF VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR NUM... |
Toad Rash has a binary string $s$. A binary string consists only of zeros and ones.
Let $n$ be the length of $s$.
Rash needs to find the number of such pairs of integers $l$, $r$ that $1 \leq l \leq r \leq n$ and there is at least one pair of integers $x$, $k$ such that $1 \leq x, k \leq n$, $l \leq x < x + 2k \leq r... | import sys
input = sys.stdin.readline
s = list(input().rstrip())
n = len(s)
for i in range(n):
s[i] = int(s[i])
ans = n * (n - 1) // 2
if n >= 2:
ans -= n - 1
for d in range(3, 13):
for i in range(n):
if i + d > n:
break
s1 = s[i : i + d]
flg = False
for k in ran... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF BI... |
Toad Rash has a binary string $s$. A binary string consists only of zeros and ones.
Let $n$ be the length of $s$.
Rash needs to find the number of such pairs of integers $l$, $r$ that $1 \leq l \leq r \leq n$ and there is at least one pair of integers $x$, $k$ such that $1 \leq x, k \leq n$, $l \leq x < x + 2k \leq r... | s = input()
cur, ans = -1, 0
for i in range(len(s)):
for j in range(cur + 1, i - 1):
if (i + j) % 2 == 0 and s[i] == s[j] and s[i] == s[(i + j) // 2]:
cur = j
ans += cur + 1
print(ans) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
Toad Rash has a binary string $s$. A binary string consists only of zeros and ones.
Let $n$ be the length of $s$.
Rash needs to find the number of such pairs of integers $l$, $r$ that $1 \leq l \leq r \leq n$ and there is at least one pair of integers $x$, $k$ such that $1 \leq x, k \leq n$, $l \leq x < x + 2k \leq r... | s = input()
n = len(s)
sml = n * (n + 1) // 2
for i in range(8):
sml -= max(n - i, 0)
good3 = set()
good4 = set()
good5 = set()
good6 = set()
good7 = set()
for i in range(n - 2):
if s[i] == s[i + 1] == s[i + 2]:
good3.add(i)
sml += 1
for i in range(n - 3):
if i in good3 or i + 1 in good3:
... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL ... |
Toad Rash has a binary string $s$. A binary string consists only of zeros and ones.
Let $n$ be the length of $s$.
Rash needs to find the number of such pairs of integers $l$, $r$ that $1 \leq l \leq r \leq n$ and there is at least one pair of integers $x$, $k$ such that $1 \leq x, k \leq n$, $l \leq x < x + 2k \leq r... | def parse(c, n):
l = [-1] * n
for x in c:
se = set(x)
for i in range(len(x) - 1):
for j in range(i + 1, len(x)):
k = x[j] - x[i]
if k > 20:
break
if x[i] + k + k >= n:
break
if x[i... | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR AS... |
Toad Rash has a binary string $s$. A binary string consists only of zeros and ones.
Let $n$ be the length of $s$.
Rash needs to find the number of such pairs of integers $l$, $r$ that $1 \leq l \leq r \leq n$ and there is at least one pair of integers $x$, $k$ such that $1 \leq x, k \leq n$, $l \leq x < x + 2k \leq r... | s = input()
le = len(s)
m = [le] * (le + 1)
ans = 0
for i in range(le - 1, -1, -1):
m[i] = m[i + 1]
k = 1
while k * 2 + i < m[i]:
if s[i] == s[i + k] and s[i] == s[i + 2 * k]:
m[i] = i + 2 * k
k += 1
ans += le - m[i]
print(ans) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VA... |
Toad Rash has a binary string $s$. A binary string consists only of zeros and ones.
Let $n$ be the length of $s$.
Rash needs to find the number of such pairs of integers $l$, $r$ that $1 \leq l \leq r \leq n$ and there is at least one pair of integers $x$, $k$ such that $1 \leq x, k \leq n$, $l \leq x < x + 2k \leq r... | import sys
input = sys.stdin.readline
S = input().strip()
L = len(S)
ANS1 = [0] * (L + 10)
ANS2 = [0] * (L + 10)
ANS3 = [0] * (L + 10)
for i in range(L - 2):
if S[i] == S[i + 1] == S[i + 2]:
ANS1[i] = 1
for i in range(L - 4):
if S[i] == S[i + 2] == S[i + 4]:
ANS2[i] = 1
for i in range(L - 6):
... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NU... |
Toad Rash has a binary string $s$. A binary string consists only of zeros and ones.
Let $n$ be the length of $s$.
Rash needs to find the number of such pairs of integers $l$, $r$ that $1 \leq l \leq r \leq n$ and there is at least one pair of integers $x$, $k$ such that $1 \leq x, k \leq n$, $l \leq x < x + 2k \leq r... | def func(st, en):
for i in range(st, en + 1):
for j in range(i + 1, en + 1):
if (j - i + 1) % 2 == 1:
if s[(i + j) // 2] == s[i] == s[j]:
return False
return True
s = input().strip()
c = 0
n = len(s)
for i in range(2, 9):
for j in range(len(s)):
... | FUNC_DEF FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VA... |
You are given an array $a$ consisting of $n$ integers. For each $i$ ($1 \le i \le n$) the following inequality is true: $-2 \le a_i \le 2$.
You can remove any number (possibly $0$) of elements from the beginning of the array and any number (possibly $0$) of elements from the end of the array. You are allowed to delete... | for _ in range(int(input())):
n = int(input())
a = [int(x) for x in input().split()]
best = 1, 0, n, 0
best_pow_neg = 1, 0, 0
best_pow_pos = 1, 0, 0
prefix_pow = 0
prefix_sign = 1
for i in range(n):
if a[i] == 0:
best_pow_neg = 1, 0, i + 1
best_pow_pos = 1... | 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 NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR N... |
You are given an array $a$ consisting of $n$ integers. For each $i$ ($1 \le i \le n$) the following inequality is true: $-2 \le a_i \le 2$.
You can remove any number (possibly $0$) of elements from the beginning of the array and any number (possibly $0$) of elements from the end of the array. You are allowed to delete... | def main():
for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
l_ind, r_ind = 0, n
res = 0
pl = 0
pr = 0
nl = None
nv = None
temp = 1
c = 0
for i, el in enumerate(arr):
if el > 0:
... | FUNC_DEF 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 VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR... |
You are given an array $a$ consisting of $n$ integers. For each $i$ ($1 \le i \le n$) the following inequality is true: $-2 \le a_i \le 2$.
You can remove any number (possibly $0$) of elements from the beginning of the array and any number (possibly $0$) of elements from the end of the array. You are allowed to delete... | t = int(input())
for _ in range(t):
n = int(input())
numbers = [int(num) for num in input().split()]
max_pow_2 = 0
remove_from_start = n
remove_from_end = 0
idx = 0
j = 0
pow_2 = 0
sign = True
while idx < n:
if numbers[idx] == 0:
idx += 1
j = idx
... | 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 NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER VAR ... |
You are given an array $a$ consisting of $n$ integers. For each $i$ ($1 \le i \le n$) the following inequality is true: $-2 \le a_i \le 2$.
You can remove any number (possibly $0$) of elements from the beginning of the array and any number (possibly $0$) of elements from the end of the array. You are allowed to delete... | def count(nums):
total = {(-2): 0, (-1): 0, (1): 0, (2): 0}
for i in nums:
total[i] += 1
return total
def solution():
n = int(input())
a = [int(i) for i in input().split()]
ans = 0
x, y = n, 0
zero_pos = [-1] + [i for i in range(n) if a[i] == 0] + [n]
for i in range(len(zer... | FUNC_DEF ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR VAR FUNC_CA... |
You are given an array $a$ consisting of $n$ integers. For each $i$ ($1 \le i \le n$) the following inequality is true: $-2 \le a_i \le 2$.
You can remove any number (possibly $0$) of elements from the beginning of the array and any number (possibly $0$) of elements from the end of the array. You are allowed to delete... | for _ in range(int(input())):
n = int(input())
nums = list(map(int, input().split()))
ans = 0
ansl, ansr = n, 0
l = -1
for i in range(n + 1):
if i == n or nums[i] == 0:
count = 0
left = -1
right = -1
neg = 1
zr = 0
z... | 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 NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ... |
You are given an array $a$ consisting of $n$ integers. For each $i$ ($1 \le i \le n$) the following inequality is true: $-2 \le a_i \le 2$.
You can remove any number (possibly $0$) of elements from the beginning of the array and any number (possibly $0$) of elements from the end of the array. You are allowed to delete... | tests = int(input())
for _ in range(tests):
num_len = int(input())
n = num_len
all_num = input()
a = [int(i) for i in all_num.split(" ")]
a = [1] + a + [0]
m = 0
lef = 0
rig = num_len
num_len = len(a)
op = [0] * num_len
ex = [0] * num_len
j = 0
l = 0
for i in rang... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CA... |
You are given an array $a$ consisting of $n$ integers. For each $i$ ($1 \le i \le n$) the following inequality is true: $-2 \le a_i \le 2$.
You can remove any number (possibly $0$) of elements from the beginning of the array and any number (possibly $0$) of elements from the end of the array. You are allowed to delete... | t = int(input())
for i in range(t):
_ = int(input())
nums = list(map(int, input().split()))
start = 0
end = 0
count_2 = 0
neg = 1
max_prod = 0
max_range = [0, 0]
while start <= end and start < len(nums):
if end == len(nums) or nums[end] == 0:
if start == end:
... | 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER WHILE VAR VAR VAR FUNC_CALL V... |
You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction [Image] whose denominator is no more than n.
Formally, you should find such pair of integers a, b (1 ≤ b ≤ n; 0 ≤ a) that the value $|\frac{x}{y} - \frac{a}{b}|$ is as minimal as possible.
If there are multiple "near... | def s():
[x, y, n] = list(map(int, input().split()))
res = 0, 1
for b in range(1, n + 1):
a = int(round(b * x / y, 0) + 0.1)
if abs(x * res[1] - y * res[0]) * b > abs(x * b - y * (a - 1)) * res[1]:
res = a - 1, b
if abs(x * res[1] - y * res[0]) * b > abs(x * b - y * a) * ... | FUNC_DEF ASSIGN LIST VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER IF BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBE... |
You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction [Image] whose denominator is no more than n.
Formally, you should find such pair of integers a, b (1 ≤ b ≤ n; 0 ≤ a) that the value $|\frac{x}{y} - \frac{a}{b}|$ is as minimal as possible.
If there are multiple "near... | x, y, n = map(int, input().split())
best, mn, eps = [0, 0], 10**9, 1e-15
for i in range(1, n + 1):
m1 = i * x // y
m2 = (i * x + y - 1) // y
a = abs(x / y - m1 / i)
b = abs(x / y - m2 / i)
if a < mn - eps:
mn = a
best = [m1, i]
if b < mn - eps:
mn = b
best = [m2, ... | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR LIST NUMBER NUMBER BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR ... |
You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction [Image] whose denominator is no more than n.
Formally, you should find such pair of integers a, b (1 ≤ b ≤ n; 0 ≤ a) that the value $|\frac{x}{y} - \frac{a}{b}|$ is as minimal as possible.
If there are multiple "near... | class Fraction:
def __init__(self, x, y):
self.x = x
self.y = y
def __sub__(self, a):
return Fraction(self.x * a.y - a.x * self.y, self.y * a.y)
def __lt__(self, a):
return self.x * a.y < self.y * a.x
def __abs__(self):
if self.x < 0:
return Fracti... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR FUNC_DEF RETURN BIN_OP VAR VAR BIN_OP VAR VAR FUNC_DEF IF VAR NUMBER RETURN FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR ASSIGN ... |
You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction [Image] whose denominator is no more than n.
Formally, you should find such pair of integers a, b (1 ≤ b ≤ n; 0 ≤ a) that the value $|\frac{x}{y} - \frac{a}{b}|$ is as minimal as possible.
If there are multiple "near... | def gcd(a, b):
return gcd(b % a, a) if a else b
x, y, n = map(int, input().split())
z = gcd(x, y)
x, y = x // z, y // z
if n < y:
d = [min(i, y - i) for i in (x * i % y for i in range(0, n + 1))]
for i in range(n - 1, 0, -1):
if d[i] < d[n] and n * d[i] <= i * d[n]:
n = i
print(str... | FUNC_DEF RETURN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUM... |
You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction [Image] whose denominator is no more than n.
Formally, you should find such pair of integers a, b (1 ≤ b ≤ n; 0 ≤ a) that the value $|\frac{x}{y} - \frac{a}{b}|$ is as minimal as possible.
If there are multiple "near... | x, y, n = map(int, input().split())
ansNum = -1
ansDenom = -1
for b in range(1, n + 1):
a = x * b // y
if x * b % y * 2 > y:
a += 1
if ansNum == -1 or abs(x / y - ansNum / ansDenom) > abs(x / y - a / b):
ansNum = a
ansDenom = b
print(ansNum, ansDenom, sep="/") | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR FUNC_CALL VAR BI... |
You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction [Image] whose denominator is no more than n.
Formally, you should find such pair of integers a, b (1 ≤ b ≤ n; 0 ≤ a) that the value $|\frac{x}{y} - \frac{a}{b}|$ is as minimal as possible.
If there are multiple "near... | import sys
s = input()
all = s.split()
ans = "lol"
n = int(all[2])
x = float(all[0])
y = float(all[1])
a = 0
b = 1
dif = x / y
for i in range(1, n + 1):
na = int(x * i / y)
if dif > abs(x * i - na * y) / (y * i):
a = na
b = i
dif = abs(x * i - na * y) / (y * i)
na = na + 1
if di... | IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN... |
You are given an array $a_1, a_2 \dots a_n$. Calculate the number of tuples $(i, j, k, l)$ such that: $1 \le i < j < k < l \le n$; $a_i = a_k$ and $a_j = a_l$;
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 100$) — the number of test cases.
The first line of each test case contains a... | import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
n = int(input())
arr = list(map(int, input().split()))
m = max(arr)
look = [[(0) for _ in range(m + 1)] for _ in range(n)]
for i in range(len(arr)):
for j in range(m + 1):
look[i][j] = look[i - 1][j]
... | IMPORT ASSIGN 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 VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.