description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N. You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind. In a single operation, you can increase or decrease any of the elements of array A by 1. Find out the maximum value of interaction of the arrays that you can get. ------ Input ------ The first line of input contains a single integer T denoting number of test cases. For each test case: First line contains two space separated integers N, K. Second line contains N space separated integers denoting array A. Third line contains N space separated integers denoting array B. ------ Output ------ For each test case, output a single integer denoting the answer of the problem. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ N ≤ 10^{5}$ $0 ≤ |A[i]|, |B[i]| ≤ 10^{5}$ $0 ≤ K ≤ 10^{9}$ ------ Subtasks ------ Subtask #1 : (25 points) $1 ≤ N ≤ 10$ $0 ≤ |A[i]|, |B[i]| ≤ 10$ $0 ≤ K ≤ 10$ Subtask #2 : (35 points) $1 ≤ N ≤ 1000$ $0 ≤ |A[i]|, |B[i]| ≤ 1000$ $0 ≤ K ≤ 10^{5}$ Subtask #3 : (40 points) $No additional constraints$ ----- Sample Input 1 ------ 2 2 2 1 2 -2 3 3 5 1 2 -3 -2 3 -5 ----- Sample Output 1 ------ 10 44 ----- explanation 1 ------ In the first example, you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
t = int(input()) for j in range(t): n, k = map(int, input().split()) a = input().split() b = input().split() a = [int(i) for i in a] b = [int(i) for i in b] sumn = 0 temp = 0 for i in range(len(a)): sumn += a[i] * b[i] temp2 = sumn for i in range(len(b)): if a[i] >= 0 and b[i] >= 0 or a[i] < 0 and b[i] < 0: temp = sumn + k * abs(b[i]) else: temp1 = sumn - k * b[i] temp3 = sumn + k * b[i] temp = max(temp1, temp3) if temp > temp2: temp2 = temp print(temp2)
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N. You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind. In a single operation, you can increase or decrease any of the elements of array A by 1. Find out the maximum value of interaction of the arrays that you can get. ------ Input ------ The first line of input contains a single integer T denoting number of test cases. For each test case: First line contains two space separated integers N, K. Second line contains N space separated integers denoting array A. Third line contains N space separated integers denoting array B. ------ Output ------ For each test case, output a single integer denoting the answer of the problem. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ N ≤ 10^{5}$ $0 ≤ |A[i]|, |B[i]| ≤ 10^{5}$ $0 ≤ K ≤ 10^{9}$ ------ Subtasks ------ Subtask #1 : (25 points) $1 ≤ N ≤ 10$ $0 ≤ |A[i]|, |B[i]| ≤ 10$ $0 ≤ K ≤ 10$ Subtask #2 : (35 points) $1 ≤ N ≤ 1000$ $0 ≤ |A[i]|, |B[i]| ≤ 1000$ $0 ≤ K ≤ 10^{5}$ Subtask #3 : (40 points) $No additional constraints$ ----- Sample Input 1 ------ 2 2 2 1 2 -2 3 3 5 1 2 -3 -2 3 -5 ----- Sample Output 1 ------ 10 44 ----- explanation 1 ------ In the first example, you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
def interaction(a, b): sum = 0 for i in range(len(a)): sum += a[i] * b[i] return sum t = int(input()) while t: t -= 1 n, k = map(int, input().split()) a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] l = [abs(x) for x in b] if b[l.index(max(l))] > 0: a[l.index(max(l))] += k elif b[l.index(max(l))] < 0: a[l.index(max(l))] -= k print(interaction(a, b))
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER 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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N. You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind. In a single operation, you can increase or decrease any of the elements of array A by 1. Find out the maximum value of interaction of the arrays that you can get. ------ Input ------ The first line of input contains a single integer T denoting number of test cases. For each test case: First line contains two space separated integers N, K. Second line contains N space separated integers denoting array A. Third line contains N space separated integers denoting array B. ------ Output ------ For each test case, output a single integer denoting the answer of the problem. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ N ≤ 10^{5}$ $0 ≤ |A[i]|, |B[i]| ≤ 10^{5}$ $0 ≤ K ≤ 10^{9}$ ------ Subtasks ------ Subtask #1 : (25 points) $1 ≤ N ≤ 10$ $0 ≤ |A[i]|, |B[i]| ≤ 10$ $0 ≤ K ≤ 10$ Subtask #2 : (35 points) $1 ≤ N ≤ 1000$ $0 ≤ |A[i]|, |B[i]| ≤ 1000$ $0 ≤ K ≤ 10^{5}$ Subtask #3 : (40 points) $No additional constraints$ ----- Sample Input 1 ------ 2 2 2 1 2 -2 3 3 5 1 2 -3 -2 3 -5 ----- Sample Output 1 ------ 10 44 ----- explanation 1 ------ In the first example, you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
from sys import stdin input = stdin.readline t = int(input()) for _ in range(t): n, k = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) orig = 0 for i in range(n): orig += A[i] * B[i] a = max(B) b = min(B) c = max(abs(a), abs(b)) print(orig + k * c)
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N. You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind. In a single operation, you can increase or decrease any of the elements of array A by 1. Find out the maximum value of interaction of the arrays that you can get. ------ Input ------ The first line of input contains a single integer T denoting number of test cases. For each test case: First line contains two space separated integers N, K. Second line contains N space separated integers denoting array A. Third line contains N space separated integers denoting array B. ------ Output ------ For each test case, output a single integer denoting the answer of the problem. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ N ≤ 10^{5}$ $0 ≤ |A[i]|, |B[i]| ≤ 10^{5}$ $0 ≤ K ≤ 10^{9}$ ------ Subtasks ------ Subtask #1 : (25 points) $1 ≤ N ≤ 10$ $0 ≤ |A[i]|, |B[i]| ≤ 10$ $0 ≤ K ≤ 10$ Subtask #2 : (35 points) $1 ≤ N ≤ 1000$ $0 ≤ |A[i]|, |B[i]| ≤ 1000$ $0 ≤ K ≤ 10^{5}$ Subtask #3 : (40 points) $No additional constraints$ ----- Sample Input 1 ------ 2 2 2 1 2 -2 3 3 5 1 2 -3 -2 3 -5 ----- Sample Output 1 ------ 10 44 ----- explanation 1 ------ In the first example, you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
t = int(input()) for t in range(t): n, k = [int(i) for i in input().split()] a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] print(sum(x * y for x, y in zip(a, b)) + k * max(map(abs, b)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N. You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind. In a single operation, you can increase or decrease any of the elements of array A by 1. Find out the maximum value of interaction of the arrays that you can get. ------ Input ------ The first line of input contains a single integer T denoting number of test cases. For each test case: First line contains two space separated integers N, K. Second line contains N space separated integers denoting array A. Third line contains N space separated integers denoting array B. ------ Output ------ For each test case, output a single integer denoting the answer of the problem. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ N ≤ 10^{5}$ $0 ≤ |A[i]|, |B[i]| ≤ 10^{5}$ $0 ≤ K ≤ 10^{9}$ ------ Subtasks ------ Subtask #1 : (25 points) $1 ≤ N ≤ 10$ $0 ≤ |A[i]|, |B[i]| ≤ 10$ $0 ≤ K ≤ 10$ Subtask #2 : (35 points) $1 ≤ N ≤ 1000$ $0 ≤ |A[i]|, |B[i]| ≤ 1000$ $0 ≤ K ≤ 10^{5}$ Subtask #3 : (40 points) $No additional constraints$ ----- Sample Input 1 ------ 2 2 2 1 2 -2 3 3 5 1 2 -3 -2 3 -5 ----- Sample Output 1 ------ 10 44 ----- explanation 1 ------ In the first example, you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
Test = int(input()) while Test != 0: maxi = 0 N, K = map(int, input().split()) A = [] B = [] A = input().split() B = input().split() for j in range(N): A[j] = int(A[j]) B[j] = int(B[j]) if maxi < abs(B[j]): maxi = abs(B[j]) loc = j prod = 0 for j in range(len(B)): prod = prod + A[j] * B[j] prod = prod + maxi * K print(prod) Test = Test - 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N. You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind. In a single operation, you can increase or decrease any of the elements of array A by 1. Find out the maximum value of interaction of the arrays that you can get. ------ Input ------ The first line of input contains a single integer T denoting number of test cases. For each test case: First line contains two space separated integers N, K. Second line contains N space separated integers denoting array A. Third line contains N space separated integers denoting array B. ------ Output ------ For each test case, output a single integer denoting the answer of the problem. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ N ≤ 10^{5}$ $0 ≤ |A[i]|, |B[i]| ≤ 10^{5}$ $0 ≤ K ≤ 10^{9}$ ------ Subtasks ------ Subtask #1 : (25 points) $1 ≤ N ≤ 10$ $0 ≤ |A[i]|, |B[i]| ≤ 10$ $0 ≤ K ≤ 10$ Subtask #2 : (35 points) $1 ≤ N ≤ 1000$ $0 ≤ |A[i]|, |B[i]| ≤ 1000$ $0 ≤ K ≤ 10^{5}$ Subtask #3 : (40 points) $No additional constraints$ ----- Sample Input 1 ------ 2 2 2 1 2 -2 3 3 5 1 2 -3 -2 3 -5 ----- Sample Output 1 ------ 10 44 ----- explanation 1 ------ In the first example, you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
for _ in range(int(input())): maxx = -100005 summ = 0 n, k = map(int, input().split()) arr = list(map(int, input().split())) brr = list(map(int, input().split())) for i in range(n): if maxx < abs(brr[i]): maxx = abs(brr[i]) index = i for i in range(n): if i == index: if brr[i] < 0: arr[i] -= k else: arr[i] += k summ += arr[i] * brr[i] print(summ)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N. You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind. In a single operation, you can increase or decrease any of the elements of array A by 1. Find out the maximum value of interaction of the arrays that you can get. ------ Input ------ The first line of input contains a single integer T denoting number of test cases. For each test case: First line contains two space separated integers N, K. Second line contains N space separated integers denoting array A. Third line contains N space separated integers denoting array B. ------ Output ------ For each test case, output a single integer denoting the answer of the problem. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ N ≤ 10^{5}$ $0 ≤ |A[i]|, |B[i]| ≤ 10^{5}$ $0 ≤ K ≤ 10^{9}$ ------ Subtasks ------ Subtask #1 : (25 points) $1 ≤ N ≤ 10$ $0 ≤ |A[i]|, |B[i]| ≤ 10$ $0 ≤ K ≤ 10$ Subtask #2 : (35 points) $1 ≤ N ≤ 1000$ $0 ≤ |A[i]|, |B[i]| ≤ 1000$ $0 ≤ K ≤ 10^{5}$ Subtask #3 : (40 points) $No additional constraints$ ----- Sample Input 1 ------ 2 2 2 1 2 -2 3 3 5 1 2 -3 -2 3 -5 ----- Sample Output 1 ------ 10 44 ----- explanation 1 ------ In the first example, you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
t = int(input()) for _ in range(t): n, k = map(int, input().split()) l1 = [int(x) for x in input().split()] l2 = [int(x) for x in input().split()] a, b = [], [] ans = [] mx = 0 for i in range(n): if mx < abs(l2[i]): mx = abs(l2[i]) ans = [l1[i], l2[i], i] res = 0 if ans: if ans[0] >= 0 and ans[1] >= 0: res = (ans[0] + k) * ans[1] elif ans[0] < 0 and ans[1] < 0: res = (ans[0] - k) * ans[1] elif ans[0] < 0: res = (ans[0] + k) * ans[1] else: res = (ans[0] - k) * ans[1] for i in range(n): if ans and i == ans[2]: continue else: res += l1[i] * l2[i] print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N. You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind. In a single operation, you can increase or decrease any of the elements of array A by 1. Find out the maximum value of interaction of the arrays that you can get. ------ Input ------ The first line of input contains a single integer T denoting number of test cases. For each test case: First line contains two space separated integers N, K. Second line contains N space separated integers denoting array A. Third line contains N space separated integers denoting array B. ------ Output ------ For each test case, output a single integer denoting the answer of the problem. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ N ≤ 10^{5}$ $0 ≤ |A[i]|, |B[i]| ≤ 10^{5}$ $0 ≤ K ≤ 10^{9}$ ------ Subtasks ------ Subtask #1 : (25 points) $1 ≤ N ≤ 10$ $0 ≤ |A[i]|, |B[i]| ≤ 10$ $0 ≤ K ≤ 10$ Subtask #2 : (35 points) $1 ≤ N ≤ 1000$ $0 ≤ |A[i]|, |B[i]| ≤ 1000$ $0 ≤ K ≤ 10^{5}$ Subtask #3 : (40 points) $No additional constraints$ ----- Sample Input 1 ------ 2 2 2 1 2 -2 3 3 5 1 2 -3 -2 3 -5 ----- Sample Output 1 ------ 10 44 ----- explanation 1 ------ In the first example, you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
for _ in range(int(input())): n, k = list(map(int, input().split(" "))) a = list(map(int, input().split(" "))) b = list(map(int, input().split(" "))) data = [] sum_data = sum(x * y for x, y in zip(a, b)) for i in range(n): data.append(sum_data + k * b[i]) data.append(sum_data - k * b[i]) print(max(data))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N. You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind. In a single operation, you can increase or decrease any of the elements of array A by 1. Find out the maximum value of interaction of the arrays that you can get. ------ Input ------ The first line of input contains a single integer T denoting number of test cases. For each test case: First line contains two space separated integers N, K. Second line contains N space separated integers denoting array A. Third line contains N space separated integers denoting array B. ------ Output ------ For each test case, output a single integer denoting the answer of the problem. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ N ≤ 10^{5}$ $0 ≤ |A[i]|, |B[i]| ≤ 10^{5}$ $0 ≤ K ≤ 10^{9}$ ------ Subtasks ------ Subtask #1 : (25 points) $1 ≤ N ≤ 10$ $0 ≤ |A[i]|, |B[i]| ≤ 10$ $0 ≤ K ≤ 10$ Subtask #2 : (35 points) $1 ≤ N ≤ 1000$ $0 ≤ |A[i]|, |B[i]| ≤ 1000$ $0 ≤ K ≤ 10^{5}$ Subtask #3 : (40 points) $No additional constraints$ ----- Sample Input 1 ------ 2 2 2 1 2 -2 3 3 5 1 2 -3 -2 3 -5 ----- Sample Output 1 ------ 10 44 ----- explanation 1 ------ In the first example, you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
t = int(input()) for _ in range(t): n, k = map(int, input().split()) a = list(map(int, input().lstrip().split())) b = list(map(int, input().lstrip().split())) total = 0 for i in range(n): total += a[i] * b[i] maxi = total for i in range(n): val1 = maxi val2 = maxi val1 -= a[i] * b[i] val1 += (a[i] + k) * b[i] val2 -= a[i] * b[i] val2 += (a[i] - k) * b[i] total = max(total, val1, val2) print(total)
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N. You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind. In a single operation, you can increase or decrease any of the elements of array A by 1. Find out the maximum value of interaction of the arrays that you can get. ------ Input ------ The first line of input contains a single integer T denoting number of test cases. For each test case: First line contains two space separated integers N, K. Second line contains N space separated integers denoting array A. Third line contains N space separated integers denoting array B. ------ Output ------ For each test case, output a single integer denoting the answer of the problem. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ N ≤ 10^{5}$ $0 ≤ |A[i]|, |B[i]| ≤ 10^{5}$ $0 ≤ K ≤ 10^{9}$ ------ Subtasks ------ Subtask #1 : (25 points) $1 ≤ N ≤ 10$ $0 ≤ |A[i]|, |B[i]| ≤ 10$ $0 ≤ K ≤ 10$ Subtask #2 : (35 points) $1 ≤ N ≤ 1000$ $0 ≤ |A[i]|, |B[i]| ≤ 1000$ $0 ≤ K ≤ 10^{5}$ Subtask #3 : (40 points) $No additional constraints$ ----- Sample Input 1 ------ 2 2 2 1 2 -2 3 3 5 1 2 -3 -2 3 -5 ----- Sample Output 1 ------ 10 44 ----- explanation 1 ------ In the first example, you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
t = int(input()) while t > 0: n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) max = 0 m = 0 for i in range(0, n): e = b[i] if e < 0: e = e * -1 if max < e: m = i max = e if b[m] < 0: a[m] = a[m] - k else: a[m] = a[m] + k s = 0 for i in range(0, n): s = s + a[i] * b[i] print(s) t = t - 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N. You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind. In a single operation, you can increase or decrease any of the elements of array A by 1. Find out the maximum value of interaction of the arrays that you can get. ------ Input ------ The first line of input contains a single integer T denoting number of test cases. For each test case: First line contains two space separated integers N, K. Second line contains N space separated integers denoting array A. Third line contains N space separated integers denoting array B. ------ Output ------ For each test case, output a single integer denoting the answer of the problem. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ N ≤ 10^{5}$ $0 ≤ |A[i]|, |B[i]| ≤ 10^{5}$ $0 ≤ K ≤ 10^{9}$ ------ Subtasks ------ Subtask #1 : (25 points) $1 ≤ N ≤ 10$ $0 ≤ |A[i]|, |B[i]| ≤ 10$ $0 ≤ K ≤ 10$ Subtask #2 : (35 points) $1 ≤ N ≤ 1000$ $0 ≤ |A[i]|, |B[i]| ≤ 1000$ $0 ≤ K ≤ 10^{5}$ Subtask #3 : (40 points) $No additional constraints$ ----- Sample Input 1 ------ 2 2 2 1 2 -2 3 3 5 1 2 -3 -2 3 -5 ----- Sample Output 1 ------ 10 44 ----- explanation 1 ------ In the first example, you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
for _ in range(int(input())): N, K = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) sum1 = sum(list(n1 * n2 for n1, n2 in zip(a, b))) max_b = max(b) min_b = min(b) if -min_b > max_b: sum1 = sum1 - K * min_b else: sum1 = sum1 + K * max_b print(sum1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N. You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind. In a single operation, you can increase or decrease any of the elements of array A by 1. Find out the maximum value of interaction of the arrays that you can get. ------ Input ------ The first line of input contains a single integer T denoting number of test cases. For each test case: First line contains two space separated integers N, K. Second line contains N space separated integers denoting array A. Third line contains N space separated integers denoting array B. ------ Output ------ For each test case, output a single integer denoting the answer of the problem. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ N ≤ 10^{5}$ $0 ≤ |A[i]|, |B[i]| ≤ 10^{5}$ $0 ≤ K ≤ 10^{9}$ ------ Subtasks ------ Subtask #1 : (25 points) $1 ≤ N ≤ 10$ $0 ≤ |A[i]|, |B[i]| ≤ 10$ $0 ≤ K ≤ 10$ Subtask #2 : (35 points) $1 ≤ N ≤ 1000$ $0 ≤ |A[i]|, |B[i]| ≤ 1000$ $0 ≤ K ≤ 10^{5}$ Subtask #3 : (40 points) $No additional constraints$ ----- Sample Input 1 ------ 2 2 2 1 2 -2 3 3 5 1 2 -3 -2 3 -5 ----- Sample Output 1 ------ 10 44 ----- explanation 1 ------ In the first example, you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
t = int(input()) for tc in range(t): n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) mx = -99999999 for i in b: mx = max(mx, abs(i)) ii = 0 for i in range(n): ii = ii + a[i] * b[i] ii = ii + mx * k print(ii)
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N. You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind. In a single operation, you can increase or decrease any of the elements of array A by 1. Find out the maximum value of interaction of the arrays that you can get. ------ Input ------ The first line of input contains a single integer T denoting number of test cases. For each test case: First line contains two space separated integers N, K. Second line contains N space separated integers denoting array A. Third line contains N space separated integers denoting array B. ------ Output ------ For each test case, output a single integer denoting the answer of the problem. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ N ≤ 10^{5}$ $0 ≤ |A[i]|, |B[i]| ≤ 10^{5}$ $0 ≤ K ≤ 10^{9}$ ------ Subtasks ------ Subtask #1 : (25 points) $1 ≤ N ≤ 10$ $0 ≤ |A[i]|, |B[i]| ≤ 10$ $0 ≤ K ≤ 10$ Subtask #2 : (35 points) $1 ≤ N ≤ 1000$ $0 ≤ |A[i]|, |B[i]| ≤ 1000$ $0 ≤ K ≤ 10^{5}$ Subtask #3 : (40 points) $No additional constraints$ ----- Sample Input 1 ------ 2 2 2 1 2 -2 3 3 5 1 2 -3 -2 3 -5 ----- Sample Output 1 ------ 10 44 ----- explanation 1 ------ In the first example, you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
t = int(input()) while t > 0: n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = 0 for i in range(0, n): c += a[i] * b[i] mx = b[0] for i in range(1, n): mx = max(mx, abs(b[i])) c += k * mx print(c) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N. You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind. In a single operation, you can increase or decrease any of the elements of array A by 1. Find out the maximum value of interaction of the arrays that you can get. ------ Input ------ The first line of input contains a single integer T denoting number of test cases. For each test case: First line contains two space separated integers N, K. Second line contains N space separated integers denoting array A. Third line contains N space separated integers denoting array B. ------ Output ------ For each test case, output a single integer denoting the answer of the problem. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ N ≤ 10^{5}$ $0 ≤ |A[i]|, |B[i]| ≤ 10^{5}$ $0 ≤ K ≤ 10^{9}$ ------ Subtasks ------ Subtask #1 : (25 points) $1 ≤ N ≤ 10$ $0 ≤ |A[i]|, |B[i]| ≤ 10$ $0 ≤ K ≤ 10$ Subtask #2 : (35 points) $1 ≤ N ≤ 1000$ $0 ≤ |A[i]|, |B[i]| ≤ 1000$ $0 ≤ K ≤ 10^{5}$ Subtask #3 : (40 points) $No additional constraints$ ----- Sample Input 1 ------ 2 2 2 1 2 -2 3 3 5 1 2 -3 -2 3 -5 ----- Sample Output 1 ------ 10 44 ----- explanation 1 ------ In the first example, you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
for _ in range(int(input())): n, k = map(int, input().split()) a, b = list(map(int, input().split())), list(map(int, input().split())) res = 0 for i in range(n): res += a[i] * b[i] m = 0 for i in range(n): if abs(b[i]) > m: m = abs(b[i]) pos = i res = max(res, res - k * b[pos], res + k * b[pos]) print(res)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N. You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind. In a single operation, you can increase or decrease any of the elements of array A by 1. Find out the maximum value of interaction of the arrays that you can get. ------ Input ------ The first line of input contains a single integer T denoting number of test cases. For each test case: First line contains two space separated integers N, K. Second line contains N space separated integers denoting array A. Third line contains N space separated integers denoting array B. ------ Output ------ For each test case, output a single integer denoting the answer of the problem. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ N ≤ 10^{5}$ $0 ≤ |A[i]|, |B[i]| ≤ 10^{5}$ $0 ≤ K ≤ 10^{9}$ ------ Subtasks ------ Subtask #1 : (25 points) $1 ≤ N ≤ 10$ $0 ≤ |A[i]|, |B[i]| ≤ 10$ $0 ≤ K ≤ 10$ Subtask #2 : (35 points) $1 ≤ N ≤ 1000$ $0 ≤ |A[i]|, |B[i]| ≤ 1000$ $0 ≤ K ≤ 10^{5}$ Subtask #3 : (40 points) $No additional constraints$ ----- Sample Input 1 ------ 2 2 2 1 2 -2 3 3 5 1 2 -3 -2 3 -5 ----- Sample Output 1 ------ 10 44 ----- explanation 1 ------ In the first example, you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
t = int(input()) for i in range(t): length, operations = map(int, input().split()) arr = [] total = 0 arr1 = list(map(int, input().split())) arr2 = list(map(int, input().split())) for j in range(length): arr.append([arr1[j], arr2[j]]) total += arr1[j] * arr2[j] arr.sort(key=lambda x: x[1], reverse=True) if arr[0][1] > arr[-1][1] * -1: total += operations * arr[0][1] else: total += -operations * arr[-1][1] print(total)
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 LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N. You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind. In a single operation, you can increase or decrease any of the elements of array A by 1. Find out the maximum value of interaction of the arrays that you can get. ------ Input ------ The first line of input contains a single integer T denoting number of test cases. For each test case: First line contains two space separated integers N, K. Second line contains N space separated integers denoting array A. Third line contains N space separated integers denoting array B. ------ Output ------ For each test case, output a single integer denoting the answer of the problem. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ N ≤ 10^{5}$ $0 ≤ |A[i]|, |B[i]| ≤ 10^{5}$ $0 ≤ K ≤ 10^{9}$ ------ Subtasks ------ Subtask #1 : (25 points) $1 ≤ N ≤ 10$ $0 ≤ |A[i]|, |B[i]| ≤ 10$ $0 ≤ K ≤ 10$ Subtask #2 : (35 points) $1 ≤ N ≤ 1000$ $0 ≤ |A[i]|, |B[i]| ≤ 1000$ $0 ≤ K ≤ 10^{5}$ Subtask #3 : (40 points) $No additional constraints$ ----- Sample Input 1 ------ 2 2 2 1 2 -2 3 3 5 1 2 -3 -2 3 -5 ----- Sample Output 1 ------ 10 44 ----- explanation 1 ------ In the first example, you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
t = int(input()) for i in range(t): n, k = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) mb = b[0], 0 for i in range(len(b)): if abs(b[i]) > abs(mb[0]): mb = b[i], i if mb[0] >= 0: a[mb[1]] += k else: a[mb[1]] -= k s = 0 for i in range(n): s += a[i] * b[i] print(s)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N. You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind. In a single operation, you can increase or decrease any of the elements of array A by 1. Find out the maximum value of interaction of the arrays that you can get. ------ Input ------ The first line of input contains a single integer T denoting number of test cases. For each test case: First line contains two space separated integers N, K. Second line contains N space separated integers denoting array A. Third line contains N space separated integers denoting array B. ------ Output ------ For each test case, output a single integer denoting the answer of the problem. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ N ≤ 10^{5}$ $0 ≤ |A[i]|, |B[i]| ≤ 10^{5}$ $0 ≤ K ≤ 10^{9}$ ------ Subtasks ------ Subtask #1 : (25 points) $1 ≤ N ≤ 10$ $0 ≤ |A[i]|, |B[i]| ≤ 10$ $0 ≤ K ≤ 10$ Subtask #2 : (35 points) $1 ≤ N ≤ 1000$ $0 ≤ |A[i]|, |B[i]| ≤ 1000$ $0 ≤ K ≤ 10^{5}$ Subtask #3 : (40 points) $No additional constraints$ ----- Sample Input 1 ------ 2 2 2 1 2 -2 3 3 5 1 2 -3 -2 3 -5 ----- Sample Output 1 ------ 10 44 ----- explanation 1 ------ In the first example, you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
for t in range(int(input())): ans = 0 n, k = map(int, input().split()) arrA = list(map(int, input().split())) arrB = list(map(int, input().split())) for i in range(len(arrA)): ans += arrA[i] * arrB[i] if arrB[i] < 0: arrB[i] *= -1 print(ans + k * max(arrB))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR FUNC_CALL VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N. You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind. In a single operation, you can increase or decrease any of the elements of array A by 1. Find out the maximum value of interaction of the arrays that you can get. ------ Input ------ The first line of input contains a single integer T denoting number of test cases. For each test case: First line contains two space separated integers N, K. Second line contains N space separated integers denoting array A. Third line contains N space separated integers denoting array B. ------ Output ------ For each test case, output a single integer denoting the answer of the problem. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ N ≤ 10^{5}$ $0 ≤ |A[i]|, |B[i]| ≤ 10^{5}$ $0 ≤ K ≤ 10^{9}$ ------ Subtasks ------ Subtask #1 : (25 points) $1 ≤ N ≤ 10$ $0 ≤ |A[i]|, |B[i]| ≤ 10$ $0 ≤ K ≤ 10$ Subtask #2 : (35 points) $1 ≤ N ≤ 1000$ $0 ≤ |A[i]|, |B[i]| ≤ 1000$ $0 ≤ K ≤ 10^{5}$ Subtask #3 : (40 points) $No additional constraints$ ----- Sample Input 1 ------ 2 2 2 1 2 -2 3 3 5 1 2 -3 -2 3 -5 ----- Sample Output 1 ------ 10 44 ----- explanation 1 ------ In the first example, you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
T = int(input()) while T > 0: N, K = map(int, input().split()) A = [int(n) for n in input().split()] B = [int(n) for n in input().split()] result = 0 inter = 0 for i in range(N): result += A[i] * B[i] inter = result for i in range(N): if A[i] >= 0 and B[i] >= 0 or A[i] < 0 and B[i] < 0: temp = result + K * abs(B[i]) else: temp1 = result - K * abs(B[i]) temp2 = result + K * abs(B[i]) temp = max(temp1, temp2) inter = max(inter, temp) print(inter) T = T - 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER 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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N. You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind. In a single operation, you can increase or decrease any of the elements of array A by 1. Find out the maximum value of interaction of the arrays that you can get. ------ Input ------ The first line of input contains a single integer T denoting number of test cases. For each test case: First line contains two space separated integers N, K. Second line contains N space separated integers denoting array A. Third line contains N space separated integers denoting array B. ------ Output ------ For each test case, output a single integer denoting the answer of the problem. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ N ≤ 10^{5}$ $0 ≤ |A[i]|, |B[i]| ≤ 10^{5}$ $0 ≤ K ≤ 10^{9}$ ------ Subtasks ------ Subtask #1 : (25 points) $1 ≤ N ≤ 10$ $0 ≤ |A[i]|, |B[i]| ≤ 10$ $0 ≤ K ≤ 10$ Subtask #2 : (35 points) $1 ≤ N ≤ 1000$ $0 ≤ |A[i]|, |B[i]| ≤ 1000$ $0 ≤ K ≤ 10^{5}$ Subtask #3 : (40 points) $No additional constraints$ ----- Sample Input 1 ------ 2 2 2 1 2 -2 3 3 5 1 2 -3 -2 3 -5 ----- Sample Output 1 ------ 10 44 ----- explanation 1 ------ In the first example, you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
for _ in range(int(input())): n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) f = max(b) r = min(b) sum = 0 for i in range(n): sum += a[i] * b[i] b[i] = abs(b[i]) sum += k * max(b) print(sum)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N. You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind. In a single operation, you can increase or decrease any of the elements of array A by 1. Find out the maximum value of interaction of the arrays that you can get. ------ Input ------ The first line of input contains a single integer T denoting number of test cases. For each test case: First line contains two space separated integers N, K. Second line contains N space separated integers denoting array A. Third line contains N space separated integers denoting array B. ------ Output ------ For each test case, output a single integer denoting the answer of the problem. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ N ≤ 10^{5}$ $0 ≤ |A[i]|, |B[i]| ≤ 10^{5}$ $0 ≤ K ≤ 10^{9}$ ------ Subtasks ------ Subtask #1 : (25 points) $1 ≤ N ≤ 10$ $0 ≤ |A[i]|, |B[i]| ≤ 10$ $0 ≤ K ≤ 10$ Subtask #2 : (35 points) $1 ≤ N ≤ 1000$ $0 ≤ |A[i]|, |B[i]| ≤ 1000$ $0 ≤ K ≤ 10^{5}$ Subtask #3 : (40 points) $No additional constraints$ ----- Sample Input 1 ------ 2 2 2 1 2 -2 3 3 5 1 2 -3 -2 3 -5 ----- Sample Output 1 ------ 10 44 ----- explanation 1 ------ In the first example, you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
def soln(n, k, a, b): res = 0 orig = 0 maxm = 0 for i in range(n): res += a[i] * b[i] res += k * max(abs(max(b)), abs(min(b))) return res for _ in range(int(input())): n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) print(soln(n, k, a, b))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N. You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind. In a single operation, you can increase or decrease any of the elements of array A by 1. Find out the maximum value of interaction of the arrays that you can get. ------ Input ------ The first line of input contains a single integer T denoting number of test cases. For each test case: First line contains two space separated integers N, K. Second line contains N space separated integers denoting array A. Third line contains N space separated integers denoting array B. ------ Output ------ For each test case, output a single integer denoting the answer of the problem. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ N ≤ 10^{5}$ $0 ≤ |A[i]|, |B[i]| ≤ 10^{5}$ $0 ≤ K ≤ 10^{9}$ ------ Subtasks ------ Subtask #1 : (25 points) $1 ≤ N ≤ 10$ $0 ≤ |A[i]|, |B[i]| ≤ 10$ $0 ≤ K ≤ 10$ Subtask #2 : (35 points) $1 ≤ N ≤ 1000$ $0 ≤ |A[i]|, |B[i]| ≤ 1000$ $0 ≤ K ≤ 10^{5}$ Subtask #3 : (40 points) $No additional constraints$ ----- Sample Input 1 ------ 2 2 2 1 2 -2 3 3 5 1 2 -3 -2 3 -5 ----- Sample Output 1 ------ 10 44 ----- explanation 1 ------ In the first example, you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
for _ in range(int(input())): n, k = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) M = 0 ans = 0 for i in range(n): ans += A[i] * B[i] if B[i] < 0: B[i] *= -1 if B[i] > M: M = B[i] ans += k * M print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N. You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind. In a single operation, you can increase or decrease any of the elements of array A by 1. Find out the maximum value of interaction of the arrays that you can get. ------ Input ------ The first line of input contains a single integer T denoting number of test cases. For each test case: First line contains two space separated integers N, K. Second line contains N space separated integers denoting array A. Third line contains N space separated integers denoting array B. ------ Output ------ For each test case, output a single integer denoting the answer of the problem. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ N ≤ 10^{5}$ $0 ≤ |A[i]|, |B[i]| ≤ 10^{5}$ $0 ≤ K ≤ 10^{9}$ ------ Subtasks ------ Subtask #1 : (25 points) $1 ≤ N ≤ 10$ $0 ≤ |A[i]|, |B[i]| ≤ 10$ $0 ≤ K ≤ 10$ Subtask #2 : (35 points) $1 ≤ N ≤ 1000$ $0 ≤ |A[i]|, |B[i]| ≤ 1000$ $0 ≤ K ≤ 10^{5}$ Subtask #3 : (40 points) $No additional constraints$ ----- Sample Input 1 ------ 2 2 2 1 2 -2 3 3 5 1 2 -3 -2 3 -5 ----- Sample Output 1 ------ 10 44 ----- explanation 1 ------ In the first example, you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
tc = int(input()) for _ in range(tc): n, k = map(int, input().split(" ")) list_A = list(map(int, input().split(" "))) list_B = list(map(int, input().split(" "))) mx = 0 sumall = 0 for i in range(n): c = list_A[i] * list_B[i] sumall += c if list_B[i] > 0: d = list_A[i] + k else: d = list_A[i] - k if list_B[i] * d - c > mx: mx = list_B[i] * d - c print(sumall + mx)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N. You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind. In a single operation, you can increase or decrease any of the elements of array A by 1. Find out the maximum value of interaction of the arrays that you can get. ------ Input ------ The first line of input contains a single integer T denoting number of test cases. For each test case: First line contains two space separated integers N, K. Second line contains N space separated integers denoting array A. Third line contains N space separated integers denoting array B. ------ Output ------ For each test case, output a single integer denoting the answer of the problem. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ N ≤ 10^{5}$ $0 ≤ |A[i]|, |B[i]| ≤ 10^{5}$ $0 ≤ K ≤ 10^{9}$ ------ Subtasks ------ Subtask #1 : (25 points) $1 ≤ N ≤ 10$ $0 ≤ |A[i]|, |B[i]| ≤ 10$ $0 ≤ K ≤ 10$ Subtask #2 : (35 points) $1 ≤ N ≤ 1000$ $0 ≤ |A[i]|, |B[i]| ≤ 1000$ $0 ≤ K ≤ 10^{5}$ Subtask #3 : (40 points) $No additional constraints$ ----- Sample Input 1 ------ 2 2 2 1 2 -2 3 3 5 1 2 -3 -2 3 -5 ----- Sample Output 1 ------ 10 44 ----- explanation 1 ------ In the first example, you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
q = int(input()) for i in range(0, q): temp = list(map(int, input().split(" ", 2)[:2])) n = temp[0] k = temp[1] listA = list(map(int, input().split(" ", n)[:n])) listB = list(map(int, input().split(" ", n)[:n])) sum1 = 0 for j in range(0, n): sum1 = sum1 + listA[j] * listB[j] max1 = sum1 for j in range(0, n): sum2 = sum1 sum2 -= listA[j] * listB[j] if listA[j] < 0 and listB[j] < 0: listA[j] -= k elif listA[j] < 0 and listB[j] >= 0: listA[j] += k elif listA[j] >= 0 and listB[j] < 0: listA[j] -= k else: listA[j] += k sum2 += listA[j] * listB[j] if max1 < sum2: max1 = sum2 print(max1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N. You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind. In a single operation, you can increase or decrease any of the elements of array A by 1. Find out the maximum value of interaction of the arrays that you can get. ------ Input ------ The first line of input contains a single integer T denoting number of test cases. For each test case: First line contains two space separated integers N, K. Second line contains N space separated integers denoting array A. Third line contains N space separated integers denoting array B. ------ Output ------ For each test case, output a single integer denoting the answer of the problem. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ N ≤ 10^{5}$ $0 ≤ |A[i]|, |B[i]| ≤ 10^{5}$ $0 ≤ K ≤ 10^{9}$ ------ Subtasks ------ Subtask #1 : (25 points) $1 ≤ N ≤ 10$ $0 ≤ |A[i]|, |B[i]| ≤ 10$ $0 ≤ K ≤ 10$ Subtask #2 : (35 points) $1 ≤ N ≤ 1000$ $0 ≤ |A[i]|, |B[i]| ≤ 1000$ $0 ≤ K ≤ 10^{5}$ Subtask #3 : (40 points) $No additional constraints$ ----- Sample Input 1 ------ 2 2 2 1 2 -2 3 3 5 1 2 -3 -2 3 -5 ----- Sample Output 1 ------ 10 44 ----- explanation 1 ------ In the first example, you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
t = int(input()) for _ in range(t): n, k = [int(x) for x in input().split()] a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] for i in range(n): if a[i] <= 0 and b[i] <= 0: a[i], b[i] = -a[i], -b[i] x = 0 for i in range(n): if abs(b[i]) > abs(b[x]): x = i if b[x] < 0: a[x] -= k else: a[x] += k ans = 0 for i in range(n): ans += a[i] * b[i] print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N. You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind. In a single operation, you can increase or decrease any of the elements of array A by 1. Find out the maximum value of interaction of the arrays that you can get. ------ Input ------ The first line of input contains a single integer T denoting number of test cases. For each test case: First line contains two space separated integers N, K. Second line contains N space separated integers denoting array A. Third line contains N space separated integers denoting array B. ------ Output ------ For each test case, output a single integer denoting the answer of the problem. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ N ≤ 10^{5}$ $0 ≤ |A[i]|, |B[i]| ≤ 10^{5}$ $0 ≤ K ≤ 10^{9}$ ------ Subtasks ------ Subtask #1 : (25 points) $1 ≤ N ≤ 10$ $0 ≤ |A[i]|, |B[i]| ≤ 10$ $0 ≤ K ≤ 10$ Subtask #2 : (35 points) $1 ≤ N ≤ 1000$ $0 ≤ |A[i]|, |B[i]| ≤ 1000$ $0 ≤ K ≤ 10^{5}$ Subtask #3 : (40 points) $No additional constraints$ ----- Sample Input 1 ------ 2 2 2 1 2 -2 3 3 5 1 2 -3 -2 3 -5 ----- Sample Output 1 ------ 10 44 ----- explanation 1 ------ In the first example, you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
t = int(input()) for i in range(0, t): n, k = map(int, input().split()) res = 0 a = list(map(int, input().split())) b = list(map(int, input().split())) B = [] for j in range(0, n): res = res + a[j] * b[j] B.append(abs(b[j])) res = res + k * abs(b[B.index(max(B))]) print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N. You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind. In a single operation, you can increase or decrease any of the elements of array A by 1. Find out the maximum value of interaction of the arrays that you can get. ------ Input ------ The first line of input contains a single integer T denoting number of test cases. For each test case: First line contains two space separated integers N, K. Second line contains N space separated integers denoting array A. Third line contains N space separated integers denoting array B. ------ Output ------ For each test case, output a single integer denoting the answer of the problem. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ N ≤ 10^{5}$ $0 ≤ |A[i]|, |B[i]| ≤ 10^{5}$ $0 ≤ K ≤ 10^{9}$ ------ Subtasks ------ Subtask #1 : (25 points) $1 ≤ N ≤ 10$ $0 ≤ |A[i]|, |B[i]| ≤ 10$ $0 ≤ K ≤ 10$ Subtask #2 : (35 points) $1 ≤ N ≤ 1000$ $0 ≤ |A[i]|, |B[i]| ≤ 1000$ $0 ≤ K ≤ 10^{5}$ Subtask #3 : (40 points) $No additional constraints$ ----- Sample Input 1 ------ 2 2 2 1 2 -2 3 3 5 1 2 -3 -2 3 -5 ----- Sample Output 1 ------ 10 44 ----- explanation 1 ------ In the first example, you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
n = int(input()) for i in range(n): p = input() n, k = p.split() n, k = int(n), int(k) a = input() b = input() la = [int(s) for s in a.strip().split(" ")] lb = [int(s) for s in b.strip().split(" ")] maxb = 0 mai = -1 ms = 1 for i in range(n): temp = abs(lb[i]) if temp > maxb: maxb = temp mai = i if la[mai] * lb[mai] >= 0: if la[mai] > 0: la[mai] = la[mai] + k else: la[mai] = la[mai] - k elif la[mai] > 0: la[mai] = la[mai] - k else: la[mai] = la[mai] + k multia = [(la[i] * lb[i]) for i in range(n)] res = sum(multia) print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N. You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind. In a single operation, you can increase or decrease any of the elements of array A by 1. Find out the maximum value of interaction of the arrays that you can get. ------ Input ------ The first line of input contains a single integer T denoting number of test cases. For each test case: First line contains two space separated integers N, K. Second line contains N space separated integers denoting array A. Third line contains N space separated integers denoting array B. ------ Output ------ For each test case, output a single integer denoting the answer of the problem. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ N ≤ 10^{5}$ $0 ≤ |A[i]|, |B[i]| ≤ 10^{5}$ $0 ≤ K ≤ 10^{9}$ ------ Subtasks ------ Subtask #1 : (25 points) $1 ≤ N ≤ 10$ $0 ≤ |A[i]|, |B[i]| ≤ 10$ $0 ≤ K ≤ 10$ Subtask #2 : (35 points) $1 ≤ N ≤ 1000$ $0 ≤ |A[i]|, |B[i]| ≤ 1000$ $0 ≤ K ≤ 10^{5}$ Subtask #3 : (40 points) $No additional constraints$ ----- Sample Input 1 ------ 2 2 2 1 2 -2 3 3 5 1 2 -3 -2 3 -5 ----- Sample Output 1 ------ 10 44 ----- explanation 1 ------ In the first example, you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
t = int(input()) for _ in range(t): n, k = map(int, input().split()) a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] x = 0 m = 0 sum = 0 for i in range(n): r = a[i] * b[i] sum = sum + r p = (a[i] + 1) * b[i] q = (a[i] - 1) * b[i] y = max(p, q) y = y - r if y > m: m = y sum = sum + k * m print(sum)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N. You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind. In a single operation, you can increase or decrease any of the elements of array A by 1. Find out the maximum value of interaction of the arrays that you can get. ------ Input ------ The first line of input contains a single integer T denoting number of test cases. For each test case: First line contains two space separated integers N, K. Second line contains N space separated integers denoting array A. Third line contains N space separated integers denoting array B. ------ Output ------ For each test case, output a single integer denoting the answer of the problem. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ N ≤ 10^{5}$ $0 ≤ |A[i]|, |B[i]| ≤ 10^{5}$ $0 ≤ K ≤ 10^{9}$ ------ Subtasks ------ Subtask #1 : (25 points) $1 ≤ N ≤ 10$ $0 ≤ |A[i]|, |B[i]| ≤ 10$ $0 ≤ K ≤ 10$ Subtask #2 : (35 points) $1 ≤ N ≤ 1000$ $0 ≤ |A[i]|, |B[i]| ≤ 1000$ $0 ≤ K ≤ 10^{5}$ Subtask #3 : (40 points) $No additional constraints$ ----- Sample Input 1 ------ 2 2 2 1 2 -2 3 3 5 1 2 -3 -2 3 -5 ----- Sample Output 1 ------ 10 44 ----- explanation 1 ------ In the first example, you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
t = int(input()) for _ in range(t): n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) mb, mbi = 0, 0 for i in range(n): if b[i] < 0: if mb < -1 * b[i]: mb = -1 * b[i] mbi = i elif mb < b[i]: mb = b[i] mbi = i if b[mbi] < 0: a[mbi] -= k else: a[mbi] += k ans = 0 for i in range(n): ans += a[i] * b[i] print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP NUMBER VAR VAR ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N. You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind. In a single operation, you can increase or decrease any of the elements of array A by 1. Find out the maximum value of interaction of the arrays that you can get. ------ Input ------ The first line of input contains a single integer T denoting number of test cases. For each test case: First line contains two space separated integers N, K. Second line contains N space separated integers denoting array A. Third line contains N space separated integers denoting array B. ------ Output ------ For each test case, output a single integer denoting the answer of the problem. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ N ≤ 10^{5}$ $0 ≤ |A[i]|, |B[i]| ≤ 10^{5}$ $0 ≤ K ≤ 10^{9}$ ------ Subtasks ------ Subtask #1 : (25 points) $1 ≤ N ≤ 10$ $0 ≤ |A[i]|, |B[i]| ≤ 10$ $0 ≤ K ≤ 10$ Subtask #2 : (35 points) $1 ≤ N ≤ 1000$ $0 ≤ |A[i]|, |B[i]| ≤ 1000$ $0 ≤ K ≤ 10^{5}$ Subtask #3 : (40 points) $No additional constraints$ ----- Sample Input 1 ------ 2 2 2 1 2 -2 3 3 5 1 2 -3 -2 3 -5 ----- Sample Output 1 ------ 10 44 ----- explanation 1 ------ In the first example, you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
def solution(a, b, k): s = sum(x * y for x, y in zip(a, b)) maxi = s + 0 for i in range(len(b)): if s + k * b[i] > maxi: maxi = s + k * b[i] if s - k * b[i] > maxi: maxi = s - k * b[i] return maxi T = int(input()) for t in range(T): N, K = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) print(solution(a, b, K))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR IF BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N. You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind. In a single operation, you can increase or decrease any of the elements of array A by 1. Find out the maximum value of interaction of the arrays that you can get. ------ Input ------ The first line of input contains a single integer T denoting number of test cases. For each test case: First line contains two space separated integers N, K. Second line contains N space separated integers denoting array A. Third line contains N space separated integers denoting array B. ------ Output ------ For each test case, output a single integer denoting the answer of the problem. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ N ≤ 10^{5}$ $0 ≤ |A[i]|, |B[i]| ≤ 10^{5}$ $0 ≤ K ≤ 10^{9}$ ------ Subtasks ------ Subtask #1 : (25 points) $1 ≤ N ≤ 10$ $0 ≤ |A[i]|, |B[i]| ≤ 10$ $0 ≤ K ≤ 10$ Subtask #2 : (35 points) $1 ≤ N ≤ 1000$ $0 ≤ |A[i]|, |B[i]| ≤ 1000$ $0 ≤ K ≤ 10^{5}$ Subtask #3 : (40 points) $No additional constraints$ ----- Sample Input 1 ------ 2 2 2 1 2 -2 3 3 5 1 2 -3 -2 3 -5 ----- Sample Output 1 ------ 10 44 ----- explanation 1 ------ In the first example, you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
t = int(input()) for i in range(t): n, k = input().split(" ") n = int(n) k = int(k) a = input().split(" ") b = input().split(" ") maxi = 0 ind = 0 for z in range(n): val = int(b[z]) if abs(val) > maxi: maxi = abs(val) ind = z s = int(val / abs(val)) a[ind] = int(a[ind]) + s * k sumo = 0 for z in range(n): sumo += int(a[z]) * int(b[z]) print(sumo)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N. You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind. In a single operation, you can increase or decrease any of the elements of array A by 1. Find out the maximum value of interaction of the arrays that you can get. ------ Input ------ The first line of input contains a single integer T denoting number of test cases. For each test case: First line contains two space separated integers N, K. Second line contains N space separated integers denoting array A. Third line contains N space separated integers denoting array B. ------ Output ------ For each test case, output a single integer denoting the answer of the problem. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ N ≤ 10^{5}$ $0 ≤ |A[i]|, |B[i]| ≤ 10^{5}$ $0 ≤ K ≤ 10^{9}$ ------ Subtasks ------ Subtask #1 : (25 points) $1 ≤ N ≤ 10$ $0 ≤ |A[i]|, |B[i]| ≤ 10$ $0 ≤ K ≤ 10$ Subtask #2 : (35 points) $1 ≤ N ≤ 1000$ $0 ≤ |A[i]|, |B[i]| ≤ 1000$ $0 ≤ K ≤ 10^{5}$ Subtask #3 : (40 points) $No additional constraints$ ----- Sample Input 1 ------ 2 2 2 1 2 -2 3 3 5 1 2 -3 -2 3 -5 ----- Sample Output 1 ------ 10 44 ----- explanation 1 ------ In the first example, you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
t = int(input()) for i in range(t): a = [] b = [] n, k = map(int, input().split()) a = list(map(int, input().strip().split()))[:n] b = list(map(int, input().strip().split()))[:n] max = abs(b[0]) ind = 0 sum = 0 for j in range(n): if abs(b[j]) > max: max = abs(b[j]) ind = j for j in range(n): sum = sum + a[j] * b[j] print(sum + k * abs(b[ind]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST 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 FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR FUNC_CALL VAR VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N. You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind. In a single operation, you can increase or decrease any of the elements of array A by 1. Find out the maximum value of interaction of the arrays that you can get. ------ Input ------ The first line of input contains a single integer T denoting number of test cases. For each test case: First line contains two space separated integers N, K. Second line contains N space separated integers denoting array A. Third line contains N space separated integers denoting array B. ------ Output ------ For each test case, output a single integer denoting the answer of the problem. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ N ≤ 10^{5}$ $0 ≤ |A[i]|, |B[i]| ≤ 10^{5}$ $0 ≤ K ≤ 10^{9}$ ------ Subtasks ------ Subtask #1 : (25 points) $1 ≤ N ≤ 10$ $0 ≤ |A[i]|, |B[i]| ≤ 10$ $0 ≤ K ≤ 10$ Subtask #2 : (35 points) $1 ≤ N ≤ 1000$ $0 ≤ |A[i]|, |B[i]| ≤ 1000$ $0 ≤ K ≤ 10^{5}$ Subtask #3 : (40 points) $No additional constraints$ ----- Sample Input 1 ------ 2 2 2 1 2 -2 3 3 5 1 2 -3 -2 3 -5 ----- Sample Output 1 ------ 10 44 ----- explanation 1 ------ In the first example, you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
for t in range(int(input())): n, k = map(int, input().split()) a = sorted( (bi, ai) for ai, bi in zip(map(int, input().split()), map(int, input().split())) ) v = sum(bi * ai for bi, ai in a) if a[-1][0] > 0 and a[-1][0] >= -a[0][0]: v += k * a[-1][0] elif a[0][0] < 0: v += k * -a[0][0] print(v)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR IF VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N. You want to maximize the value of interaction of the arrays. You are allowed to make at most K (possibly zero) operations of following kind. In a single operation, you can increase or decrease any of the elements of array A by 1. Find out the maximum value of interaction of the arrays that you can get. ------ Input ------ The first line of input contains a single integer T denoting number of test cases. For each test case: First line contains two space separated integers N, K. Second line contains N space separated integers denoting array A. Third line contains N space separated integers denoting array B. ------ Output ------ For each test case, output a single integer denoting the answer of the problem. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ N ≤ 10^{5}$ $0 ≤ |A[i]|, |B[i]| ≤ 10^{5}$ $0 ≤ K ≤ 10^{9}$ ------ Subtasks ------ Subtask #1 : (25 points) $1 ≤ N ≤ 10$ $0 ≤ |A[i]|, |B[i]| ≤ 10$ $0 ≤ K ≤ 10$ Subtask #2 : (35 points) $1 ≤ N ≤ 1000$ $0 ≤ |A[i]|, |B[i]| ≤ 1000$ $0 ≤ K ≤ 10^{5}$ Subtask #3 : (40 points) $No additional constraints$ ----- Sample Input 1 ------ 2 2 2 1 2 -2 3 3 5 1 2 -3 -2 3 -5 ----- Sample Output 1 ------ 10 44 ----- explanation 1 ------ In the first example, you can increase value A[2] using two two operations. Now, A would be [1, 4]. The value of interaction will be 1 * -2 + 4 * 3 = -2 + 12 = 10.
for i in range(int(input())): n, k = list(map(int, input().split())) x = list(map(int, input().split())) y = list(map(int, input().split())) s = 0 for j in range(n): s = s + x[j] * y[j] a = s + max(y) * k b = s + min(y) * -k print(max(a, b))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
An array A of size N is called *good* if the following conditions hold: For every pair (l, r) (1 ≤ l ≤ r ≤ N), A_{l} \oplus A_{l+1} \oplus ... \oplus A_{r} \ne 0. (where \oplus denotes the [bitwise XOR operation].) JJ has an array A of size N. He wants to convert the array to a good array. To do so he can perform the following operation multiple times: Pick an index i such that (1 ≤ i ≤ N) and set A_{i} := X where 0 ≤ X < 10^{10^{10}}. Find the minimum number of operations required to convert A into a *good* array. ------ Input Format ------ - The first line contains T - the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N - the size of the array A. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the minimum number of operations required to convert the array A into a good array. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $0 ≤ A_{i} < 2^{30}$ - Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 5 1 2 3 4 4 3 0 0 0 6 2 3 5 7 11 13 ----- Sample Output 1 ------ 2 3 0 ----- explanation 1 ------ Test Case 1: We can set $A_{2} = 4$ and $A_{4} = 5$. Thereby $A$ will become $[1, 4, 3, 5, 4]$ which is *good*. We can prove that we can not make $A$ good in $< 2$ operations. Test Case 2: We can set $A_{1} = 1$, $A_{2} = 10$ and $A_{3} = 100$. Thereby $A$ will become $[1, 10, 100]$ which is *good*. We can prove that we can not make $A$ good in $< 3$ operations. Test Case 3: The given array $A$ is already *good*.
t = int(input()) for i in range(t): n = int(input()) l = list(map(int, input().split())) s = {0} c = 0 p = 0 for i in l: p ^= i if p in s: c += 1 p = i s = {i} else: s.add(p) print(c)
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 FOR VAR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
An array A of size N is called *good* if the following conditions hold: For every pair (l, r) (1 ≤ l ≤ r ≤ N), A_{l} \oplus A_{l+1} \oplus ... \oplus A_{r} \ne 0. (where \oplus denotes the [bitwise XOR operation].) JJ has an array A of size N. He wants to convert the array to a good array. To do so he can perform the following operation multiple times: Pick an index i such that (1 ≤ i ≤ N) and set A_{i} := X where 0 ≤ X < 10^{10^{10}}. Find the minimum number of operations required to convert A into a *good* array. ------ Input Format ------ - The first line contains T - the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N - the size of the array A. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the minimum number of operations required to convert the array A into a good array. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $0 ≤ A_{i} < 2^{30}$ - Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 5 1 2 3 4 4 3 0 0 0 6 2 3 5 7 11 13 ----- Sample Output 1 ------ 2 3 0 ----- explanation 1 ------ Test Case 1: We can set $A_{2} = 4$ and $A_{4} = 5$. Thereby $A$ will become $[1, 4, 3, 5, 4]$ which is *good*. We can prove that we can not make $A$ good in $< 2$ operations. Test Case 2: We can set $A_{1} = 1$, $A_{2} = 10$ and $A_{3} = 100$. Thereby $A$ will become $[1, 10, 100]$ which is *good*. We can prove that we can not make $A$ good in $< 3$ operations. Test Case 3: The given array $A$ is already *good*.
T = int(input()) for _ in range(T): st = set([]) st.add(0) flag = 0 N = int(input()) arr = list(map(int, input().split())) xor1 = 0 marker = 5000 c = 0 bool = True marker = flag for i in range(N): flag += 1 xor1 ^= arr[i] marker -= flag * 2 if xor1 in st: bool = False st.clear() c += 1 st.add(0) marker -= 1 xor1 = 0 bool = False st.add(xor1) bool = True marker += flag print(str(c))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR LIST EXPR FUNC_CALL VAR NUMBER ASSIGN 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
An array A of size N is called *good* if the following conditions hold: For every pair (l, r) (1 ≤ l ≤ r ≤ N), A_{l} \oplus A_{l+1} \oplus ... \oplus A_{r} \ne 0. (where \oplus denotes the [bitwise XOR operation].) JJ has an array A of size N. He wants to convert the array to a good array. To do so he can perform the following operation multiple times: Pick an index i such that (1 ≤ i ≤ N) and set A_{i} := X where 0 ≤ X < 10^{10^{10}}. Find the minimum number of operations required to convert A into a *good* array. ------ Input Format ------ - The first line contains T - the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N - the size of the array A. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the minimum number of operations required to convert the array A into a good array. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $0 ≤ A_{i} < 2^{30}$ - Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 5 1 2 3 4 4 3 0 0 0 6 2 3 5 7 11 13 ----- Sample Output 1 ------ 2 3 0 ----- explanation 1 ------ Test Case 1: We can set $A_{2} = 4$ and $A_{4} = 5$. Thereby $A$ will become $[1, 4, 3, 5, 4]$ which is *good*. We can prove that we can not make $A$ good in $< 2$ operations. Test Case 2: We can set $A_{1} = 1$, $A_{2} = 10$ and $A_{3} = 100$. Thereby $A$ will become $[1, 10, 100]$ which is *good*. We can prove that we can not make $A$ good in $< 3$ operations. Test Case 3: The given array $A$ is already *good*.
t = int(input()) for i in range(t): n = int(input()) arr = list(map(int, input().split())) d = {} res = 0 d[0] = 1 curr = 0 for i in range(len(arr)): curr = curr ^ arr[i] if curr in d: res += 1 d = {} curr = 0 d[curr] = 0 print(res)
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 DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
An array A of size N is called *good* if the following conditions hold: For every pair (l, r) (1 ≤ l ≤ r ≤ N), A_{l} \oplus A_{l+1} \oplus ... \oplus A_{r} \ne 0. (where \oplus denotes the [bitwise XOR operation].) JJ has an array A of size N. He wants to convert the array to a good array. To do so he can perform the following operation multiple times: Pick an index i such that (1 ≤ i ≤ N) and set A_{i} := X where 0 ≤ X < 10^{10^{10}}. Find the minimum number of operations required to convert A into a *good* array. ------ Input Format ------ - The first line contains T - the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N - the size of the array A. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the minimum number of operations required to convert the array A into a good array. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $0 ≤ A_{i} < 2^{30}$ - Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 5 1 2 3 4 4 3 0 0 0 6 2 3 5 7 11 13 ----- Sample Output 1 ------ 2 3 0 ----- explanation 1 ------ Test Case 1: We can set $A_{2} = 4$ and $A_{4} = 5$. Thereby $A$ will become $[1, 4, 3, 5, 4]$ which is *good*. We can prove that we can not make $A$ good in $< 2$ operations. Test Case 2: We can set $A_{1} = 1$, $A_{2} = 10$ and $A_{3} = 100$. Thereby $A$ will become $[1, 10, 100]$ which is *good*. We can prove that we can not make $A$ good in $< 3$ operations. Test Case 3: The given array $A$ is already *good*.
T = int(input()) for i in range(T): N = int(input()) A = list(map(int, input().split())) ans, xor = 0, 0 xorSums = set([0]) for i in A: if xor ^ i in xorSums: ans += 1 xor = 0 xorSums = set([0]) else: xor = xor ^ i xorSums.add(xor) print(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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR LIST NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
An array A of size N is called *good* if the following conditions hold: For every pair (l, r) (1 ≤ l ≤ r ≤ N), A_{l} \oplus A_{l+1} \oplus ... \oplus A_{r} \ne 0. (where \oplus denotes the [bitwise XOR operation].) JJ has an array A of size N. He wants to convert the array to a good array. To do so he can perform the following operation multiple times: Pick an index i such that (1 ≤ i ≤ N) and set A_{i} := X where 0 ≤ X < 10^{10^{10}}. Find the minimum number of operations required to convert A into a *good* array. ------ Input Format ------ - The first line contains T - the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N - the size of the array A. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the minimum number of operations required to convert the array A into a good array. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $0 ≤ A_{i} < 2^{30}$ - Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 5 1 2 3 4 4 3 0 0 0 6 2 3 5 7 11 13 ----- Sample Output 1 ------ 2 3 0 ----- explanation 1 ------ Test Case 1: We can set $A_{2} = 4$ and $A_{4} = 5$. Thereby $A$ will become $[1, 4, 3, 5, 4]$ which is *good*. We can prove that we can not make $A$ good in $< 2$ operations. Test Case 2: We can set $A_{1} = 1$, $A_{2} = 10$ and $A_{3} = 100$. Thereby $A$ will become $[1, 10, 100]$ which is *good*. We can prove that we can not make $A$ good in $< 3$ operations. Test Case 3: The given array $A$ is already *good*.
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) s = set() s.add(0) x = 0 ans = 0 for i in range(n): x = x ^ a[i] if x in s: ans += 1 x = a[i] s = set() s.add(x) else: s.add(x) print(ans)
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 EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
An array A of size N is called *good* if the following conditions hold: For every pair (l, r) (1 ≤ l ≤ r ≤ N), A_{l} \oplus A_{l+1} \oplus ... \oplus A_{r} \ne 0. (where \oplus denotes the [bitwise XOR operation].) JJ has an array A of size N. He wants to convert the array to a good array. To do so he can perform the following operation multiple times: Pick an index i such that (1 ≤ i ≤ N) and set A_{i} := X where 0 ≤ X < 10^{10^{10}}. Find the minimum number of operations required to convert A into a *good* array. ------ Input Format ------ - The first line contains T - the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N - the size of the array A. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the minimum number of operations required to convert the array A into a good array. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $0 ≤ A_{i} < 2^{30}$ - Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 5 1 2 3 4 4 3 0 0 0 6 2 3 5 7 11 13 ----- Sample Output 1 ------ 2 3 0 ----- explanation 1 ------ Test Case 1: We can set $A_{2} = 4$ and $A_{4} = 5$. Thereby $A$ will become $[1, 4, 3, 5, 4]$ which is *good*. We can prove that we can not make $A$ good in $< 2$ operations. Test Case 2: We can set $A_{1} = 1$, $A_{2} = 10$ and $A_{3} = 100$. Thereby $A$ will become $[1, 10, 100]$ which is *good*. We can prove that we can not make $A$ good in $< 3$ operations. Test Case 3: The given array $A$ is already *good*.
import sys from itertools import islice for s in islice(sys.stdin, 2, None, 2): r = t = 0 a = {0} for x in s.split(): t ^= int(x) if t in a: r += 1 t = 0 a = {0} a.add(t) print(r)
IMPORT FOR VAR FUNC_CALL VAR VAR NUMBER NONE NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
An array A of size N is called *good* if the following conditions hold: For every pair (l, r) (1 ≤ l ≤ r ≤ N), A_{l} \oplus A_{l+1} \oplus ... \oplus A_{r} \ne 0. (where \oplus denotes the [bitwise XOR operation].) JJ has an array A of size N. He wants to convert the array to a good array. To do so he can perform the following operation multiple times: Pick an index i such that (1 ≤ i ≤ N) and set A_{i} := X where 0 ≤ X < 10^{10^{10}}. Find the minimum number of operations required to convert A into a *good* array. ------ Input Format ------ - The first line contains T - the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N - the size of the array A. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the minimum number of operations required to convert the array A into a good array. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $0 ≤ A_{i} < 2^{30}$ - Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 5 1 2 3 4 4 3 0 0 0 6 2 3 5 7 11 13 ----- Sample Output 1 ------ 2 3 0 ----- explanation 1 ------ Test Case 1: We can set $A_{2} = 4$ and $A_{4} = 5$. Thereby $A$ will become $[1, 4, 3, 5, 4]$ which is *good*. We can prove that we can not make $A$ good in $< 2$ operations. Test Case 2: We can set $A_{1} = 1$, $A_{2} = 10$ and $A_{3} = 100$. Thereby $A$ will become $[1, 10, 100]$ which is *good*. We can prove that we can not make $A$ good in $< 3$ operations. Test Case 3: The given array $A$ is already *good*.
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) count = 0 iop = 0 st = set() st.add(0) for i in range(n): iop ^= a[i] if list(st).count(iop) >= 1: st = set() count += 1 st.add(0) iop = 0 set(st) st.add(iop) print(count)
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 NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
An array A of size N is called *good* if the following conditions hold: For every pair (l, r) (1 ≤ l ≤ r ≤ N), A_{l} \oplus A_{l+1} \oplus ... \oplus A_{r} \ne 0. (where \oplus denotes the [bitwise XOR operation].) JJ has an array A of size N. He wants to convert the array to a good array. To do so he can perform the following operation multiple times: Pick an index i such that (1 ≤ i ≤ N) and set A_{i} := X where 0 ≤ X < 10^{10^{10}}. Find the minimum number of operations required to convert A into a *good* array. ------ Input Format ------ - The first line contains T - the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N - the size of the array A. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the minimum number of operations required to convert the array A into a good array. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $0 ≤ A_{i} < 2^{30}$ - Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 5 1 2 3 4 4 3 0 0 0 6 2 3 5 7 11 13 ----- Sample Output 1 ------ 2 3 0 ----- explanation 1 ------ Test Case 1: We can set $A_{2} = 4$ and $A_{4} = 5$. Thereby $A$ will become $[1, 4, 3, 5, 4]$ which is *good*. We can prove that we can not make $A$ good in $< 2$ operations. Test Case 2: We can set $A_{1} = 1$, $A_{2} = 10$ and $A_{3} = 100$. Thereby $A$ will become $[1, 10, 100]$ which is *good*. We can prove that we can not make $A$ good in $< 3$ operations. Test Case 3: The given array $A$ is already *good*.
for i in range(int(input())): n = int(input()) l = list(map(int, input().split())) k, t = 0, 0 m = {} m[0] = 1 for j in l: t ^= j if t in m and m[t] == 1: k += 1 m.clear() m[t] = 1 print(k)
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 DICT ASSIGN VAR NUMBER NUMBER FOR VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
An array A of size N is called *good* if the following conditions hold: For every pair (l, r) (1 ≤ l ≤ r ≤ N), A_{l} \oplus A_{l+1} \oplus ... \oplus A_{r} \ne 0. (where \oplus denotes the [bitwise XOR operation].) JJ has an array A of size N. He wants to convert the array to a good array. To do so he can perform the following operation multiple times: Pick an index i such that (1 ≤ i ≤ N) and set A_{i} := X where 0 ≤ X < 10^{10^{10}}. Find the minimum number of operations required to convert A into a *good* array. ------ Input Format ------ - The first line contains T - the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N - the size of the array A. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the minimum number of operations required to convert the array A into a good array. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $0 ≤ A_{i} < 2^{30}$ - Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 5 1 2 3 4 4 3 0 0 0 6 2 3 5 7 11 13 ----- Sample Output 1 ------ 2 3 0 ----- explanation 1 ------ Test Case 1: We can set $A_{2} = 4$ and $A_{4} = 5$. Thereby $A$ will become $[1, 4, 3, 5, 4]$ which is *good*. We can prove that we can not make $A$ good in $< 2$ operations. Test Case 2: We can set $A_{1} = 1$, $A_{2} = 10$ and $A_{3} = 100$. Thereby $A$ will become $[1, 10, 100]$ which is *good*. We can prove that we can not make $A$ good in $< 3$ operations. Test Case 3: The given array $A$ is already *good*.
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) count = 0 xor = 0 set1 = set() set1.add(0) for i in arr: xor = xor ^ i if xor in set1: count += 1 xor = 0 set1.clear() set1.add(xor) print(count)
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 NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
An array A of size N is called *good* if the following conditions hold: For every pair (l, r) (1 ≤ l ≤ r ≤ N), A_{l} \oplus A_{l+1} \oplus ... \oplus A_{r} \ne 0. (where \oplus denotes the [bitwise XOR operation].) JJ has an array A of size N. He wants to convert the array to a good array. To do so he can perform the following operation multiple times: Pick an index i such that (1 ≤ i ≤ N) and set A_{i} := X where 0 ≤ X < 10^{10^{10}}. Find the minimum number of operations required to convert A into a *good* array. ------ Input Format ------ - The first line contains T - the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N - the size of the array A. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the minimum number of operations required to convert the array A into a good array. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $0 ≤ A_{i} < 2^{30}$ - Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 5 1 2 3 4 4 3 0 0 0 6 2 3 5 7 11 13 ----- Sample Output 1 ------ 2 3 0 ----- explanation 1 ------ Test Case 1: We can set $A_{2} = 4$ and $A_{4} = 5$. Thereby $A$ will become $[1, 4, 3, 5, 4]$ which is *good*. We can prove that we can not make $A$ good in $< 2$ operations. Test Case 2: We can set $A_{1} = 1$, $A_{2} = 10$ and $A_{3} = 100$. Thereby $A$ will become $[1, 10, 100]$ which is *good*. We can prove that we can not make $A$ good in $< 3$ operations. Test Case 3: The given array $A$ is already *good*.
def solve(n, arr): lookup = {0} curr = 0 res = 0 for num in arr: curr ^= num if num == 0 or curr in lookup: lookup = {0} curr = 0 res += 1 continue lookup.add(curr) return res for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) print(solve(n, arr))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN 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 EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
An array A of size N is called *good* if the following conditions hold: For every pair (l, r) (1 ≤ l ≤ r ≤ N), A_{l} \oplus A_{l+1} \oplus ... \oplus A_{r} \ne 0. (where \oplus denotes the [bitwise XOR operation].) JJ has an array A of size N. He wants to convert the array to a good array. To do so he can perform the following operation multiple times: Pick an index i such that (1 ≤ i ≤ N) and set A_{i} := X where 0 ≤ X < 10^{10^{10}}. Find the minimum number of operations required to convert A into a *good* array. ------ Input Format ------ - The first line contains T - the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N - the size of the array A. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the minimum number of operations required to convert the array A into a good array. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $0 ≤ A_{i} < 2^{30}$ - Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 5 1 2 3 4 4 3 0 0 0 6 2 3 5 7 11 13 ----- Sample Output 1 ------ 2 3 0 ----- explanation 1 ------ Test Case 1: We can set $A_{2} = 4$ and $A_{4} = 5$. Thereby $A$ will become $[1, 4, 3, 5, 4]$ which is *good*. We can prove that we can not make $A$ good in $< 2$ operations. Test Case 2: We can set $A_{1} = 1$, $A_{2} = 10$ and $A_{3} = 100$. Thereby $A$ will become $[1, 10, 100]$ which is *good*. We can prove that we can not make $A$ good in $< 3$ operations. Test Case 3: The given array $A$ is already *good*.
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) s = set([0]) ans = 0 count = 0 for i in range(n): count = count ^ a[i] if count in s: ans += 1 s = set([0]) count = 0 s.add(count) print(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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
An array A of size N is called *good* if the following conditions hold: For every pair (l, r) (1 ≤ l ≤ r ≤ N), A_{l} \oplus A_{l+1} \oplus ... \oplus A_{r} \ne 0. (where \oplus denotes the [bitwise XOR operation].) JJ has an array A of size N. He wants to convert the array to a good array. To do so he can perform the following operation multiple times: Pick an index i such that (1 ≤ i ≤ N) and set A_{i} := X where 0 ≤ X < 10^{10^{10}}. Find the minimum number of operations required to convert A into a *good* array. ------ Input Format ------ - The first line contains T - the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N - the size of the array A. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the minimum number of operations required to convert the array A into a good array. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $0 ≤ A_{i} < 2^{30}$ - Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 5 1 2 3 4 4 3 0 0 0 6 2 3 5 7 11 13 ----- Sample Output 1 ------ 2 3 0 ----- explanation 1 ------ Test Case 1: We can set $A_{2} = 4$ and $A_{4} = 5$. Thereby $A$ will become $[1, 4, 3, 5, 4]$ which is *good*. We can prove that we can not make $A$ good in $< 2$ operations. Test Case 2: We can set $A_{1} = 1$, $A_{2} = 10$ and $A_{3} = 100$. Thereby $A$ will become $[1, 10, 100]$ which is *good*. We can prove that we can not make $A$ good in $< 3$ operations. Test Case 3: The given array $A$ is already *good*.
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) occs = set() occs.add(0) res = xorofone = 0 for i in range(n): xorofone ^= arr[i] if xorofone in occs: occs.clear() res += 1 occs.add(0) xorofone = 0 occs.add(xorofone) print(res)
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 EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
An array A of size N is called *good* if the following conditions hold: For every pair (l, r) (1 ≤ l ≤ r ≤ N), A_{l} \oplus A_{l+1} \oplus ... \oplus A_{r} \ne 0. (where \oplus denotes the [bitwise XOR operation].) JJ has an array A of size N. He wants to convert the array to a good array. To do so he can perform the following operation multiple times: Pick an index i such that (1 ≤ i ≤ N) and set A_{i} := X where 0 ≤ X < 10^{10^{10}}. Find the minimum number of operations required to convert A into a *good* array. ------ Input Format ------ - The first line contains T - the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N - the size of the array A. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the minimum number of operations required to convert the array A into a good array. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $0 ≤ A_{i} < 2^{30}$ - Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 5 1 2 3 4 4 3 0 0 0 6 2 3 5 7 11 13 ----- Sample Output 1 ------ 2 3 0 ----- explanation 1 ------ Test Case 1: We can set $A_{2} = 4$ and $A_{4} = 5$. Thereby $A$ will become $[1, 4, 3, 5, 4]$ which is *good*. We can prove that we can not make $A$ good in $< 2$ operations. Test Case 2: We can set $A_{1} = 1$, $A_{2} = 10$ and $A_{3} = 100$. Thereby $A$ will become $[1, 10, 100]$ which is *good*. We can prove that we can not make $A$ good in $< 3$ operations. Test Case 3: The given array $A$ is already *good*.
for i in range(int(input())): n = int(input()) a = list(map(int, input().split())) x = 0 dic = {} c = 0 for i in range(n): x = x ^ a[i] if x in dic or a[i] == 0 or x == 0: c += 1 dic = {} x = 0 else: dic[x] = 1 print(c)
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 DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
An array A of size N is called *good* if the following conditions hold: For every pair (l, r) (1 ≤ l ≤ r ≤ N), A_{l} \oplus A_{l+1} \oplus ... \oplus A_{r} \ne 0. (where \oplus denotes the [bitwise XOR operation].) JJ has an array A of size N. He wants to convert the array to a good array. To do so he can perform the following operation multiple times: Pick an index i such that (1 ≤ i ≤ N) and set A_{i} := X where 0 ≤ X < 10^{10^{10}}. Find the minimum number of operations required to convert A into a *good* array. ------ Input Format ------ - The first line contains T - the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N - the size of the array A. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the minimum number of operations required to convert the array A into a good array. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $0 ≤ A_{i} < 2^{30}$ - Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 5 1 2 3 4 4 3 0 0 0 6 2 3 5 7 11 13 ----- Sample Output 1 ------ 2 3 0 ----- explanation 1 ------ Test Case 1: We can set $A_{2} = 4$ and $A_{4} = 5$. Thereby $A$ will become $[1, 4, 3, 5, 4]$ which is *good*. We can prove that we can not make $A$ good in $< 2$ operations. Test Case 2: We can set $A_{1} = 1$, $A_{2} = 10$ and $A_{3} = 100$. Thereby $A$ will become $[1, 10, 100]$ which is *good*. We can prove that we can not make $A$ good in $< 3$ operations. Test Case 3: The given array $A$ is already *good*.
t = int(input()) def fn(arr): l = len(arr) stack = [] operations = 0 for i in range(l): if arr[i] == 0: operations += 1 stack = [] elif arr[i] in stack: operations += 1 stack = [] else: for j in range(len(stack)): stack[j] = stack[j] ^ arr[i] stack.append(arr[i]) print(operations) for _ in range(t): n = int(input()) arr1 = list(map(int, input().split())) fn(arr1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST IF VAR VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR 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 EXPR FUNC_CALL VAR VAR
An array A of size N is called *good* if the following conditions hold: For every pair (l, r) (1 ≤ l ≤ r ≤ N), A_{l} \oplus A_{l+1} \oplus ... \oplus A_{r} \ne 0. (where \oplus denotes the [bitwise XOR operation].) JJ has an array A of size N. He wants to convert the array to a good array. To do so he can perform the following operation multiple times: Pick an index i such that (1 ≤ i ≤ N) and set A_{i} := X where 0 ≤ X < 10^{10^{10}}. Find the minimum number of operations required to convert A into a *good* array. ------ Input Format ------ - The first line contains T - the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N - the size of the array A. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the minimum number of operations required to convert the array A into a good array. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $0 ≤ A_{i} < 2^{30}$ - Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 5 1 2 3 4 4 3 0 0 0 6 2 3 5 7 11 13 ----- Sample Output 1 ------ 2 3 0 ----- explanation 1 ------ Test Case 1: We can set $A_{2} = 4$ and $A_{4} = 5$. Thereby $A$ will become $[1, 4, 3, 5, 4]$ which is *good*. We can prove that we can not make $A$ good in $< 2$ operations. Test Case 2: We can set $A_{1} = 1$, $A_{2} = 10$ and $A_{3} = 100$. Thereby $A$ will become $[1, 10, 100]$ which is *good*. We can prove that we can not make $A$ good in $< 3$ operations. Test Case 3: The given array $A$ is already *good*.
import sys input = sys.stdin.readline for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) s = {0} x, ans = 0, 0 for i in range(n): x = x ^ l[i] if x in s: ans += 1 s = {l[i]} x = l[i] else: s.add(x) print(ans)
IMPORT ASSIGN 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 NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
An array A of size N is called *good* if the following conditions hold: For every pair (l, r) (1 ≤ l ≤ r ≤ N), A_{l} \oplus A_{l+1} \oplus ... \oplus A_{r} \ne 0. (where \oplus denotes the [bitwise XOR operation].) JJ has an array A of size N. He wants to convert the array to a good array. To do so he can perform the following operation multiple times: Pick an index i such that (1 ≤ i ≤ N) and set A_{i} := X where 0 ≤ X < 10^{10^{10}}. Find the minimum number of operations required to convert A into a *good* array. ------ Input Format ------ - The first line contains T - the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N - the size of the array A. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the minimum number of operations required to convert the array A into a good array. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $0 ≤ A_{i} < 2^{30}$ - Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 5 1 2 3 4 4 3 0 0 0 6 2 3 5 7 11 13 ----- Sample Output 1 ------ 2 3 0 ----- explanation 1 ------ Test Case 1: We can set $A_{2} = 4$ and $A_{4} = 5$. Thereby $A$ will become $[1, 4, 3, 5, 4]$ which is *good*. We can prove that we can not make $A$ good in $< 2$ operations. Test Case 2: We can set $A_{1} = 1$, $A_{2} = 10$ and $A_{3} = 100$. Thereby $A$ will become $[1, 10, 100]$ which is *good*. We can prove that we can not make $A$ good in $< 3$ operations. Test Case 3: The given array $A$ is already *good*.
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) for i in range(1, n): arr[i] ^= arr[i - 1] s = {0} res = 0 for e in arr: if e in s: res += 1 s = {e} else: s.add(e) print(res)
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 FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
An array A of size N is called *good* if the following conditions hold: For every pair (l, r) (1 ≤ l ≤ r ≤ N), A_{l} \oplus A_{l+1} \oplus ... \oplus A_{r} \ne 0. (where \oplus denotes the [bitwise XOR operation].) JJ has an array A of size N. He wants to convert the array to a good array. To do so he can perform the following operation multiple times: Pick an index i such that (1 ≤ i ≤ N) and set A_{i} := X where 0 ≤ X < 10^{10^{10}}. Find the minimum number of operations required to convert A into a *good* array. ------ Input Format ------ - The first line contains T - the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N - the size of the array A. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the minimum number of operations required to convert the array A into a good array. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $0 ≤ A_{i} < 2^{30}$ - Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 5 1 2 3 4 4 3 0 0 0 6 2 3 5 7 11 13 ----- Sample Output 1 ------ 2 3 0 ----- explanation 1 ------ Test Case 1: We can set $A_{2} = 4$ and $A_{4} = 5$. Thereby $A$ will become $[1, 4, 3, 5, 4]$ which is *good*. We can prove that we can not make $A$ good in $< 2$ operations. Test Case 2: We can set $A_{1} = 1$, $A_{2} = 10$ and $A_{3} = 100$. Thereby $A$ will become $[1, 10, 100]$ which is *good*. We can prove that we can not make $A$ good in $< 3$ operations. Test Case 3: The given array $A$ is already *good*.
t = int(input()) for _ in range(t): n = int(input()) a = [int(x) for x in input().split()] xor = 0 set_ = set() set_ = {xor} count = 0 for i in range(0, n): xor = a[i] ^ xor if xor in set_: xor = 0 count += 1 set_.clear() set_.add(xor) else: set_.add(xor) print(count)
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 FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
An array A of size N is called *good* if the following conditions hold: For every pair (l, r) (1 ≤ l ≤ r ≤ N), A_{l} \oplus A_{l+1} \oplus ... \oplus A_{r} \ne 0. (where \oplus denotes the [bitwise XOR operation].) JJ has an array A of size N. He wants to convert the array to a good array. To do so he can perform the following operation multiple times: Pick an index i such that (1 ≤ i ≤ N) and set A_{i} := X where 0 ≤ X < 10^{10^{10}}. Find the minimum number of operations required to convert A into a *good* array. ------ Input Format ------ - The first line contains T - the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N - the size of the array A. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the minimum number of operations required to convert the array A into a good array. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $0 ≤ A_{i} < 2^{30}$ - Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 5 1 2 3 4 4 3 0 0 0 6 2 3 5 7 11 13 ----- Sample Output 1 ------ 2 3 0 ----- explanation 1 ------ Test Case 1: We can set $A_{2} = 4$ and $A_{4} = 5$. Thereby $A$ will become $[1, 4, 3, 5, 4]$ which is *good*. We can prove that we can not make $A$ good in $< 2$ operations. Test Case 2: We can set $A_{1} = 1$, $A_{2} = 10$ and $A_{3} = 100$. Thereby $A$ will become $[1, 10, 100]$ which is *good*. We can prove that we can not make $A$ good in $< 3$ operations. Test Case 3: The given array $A$ is already *good*.
def haxorzro(A, lstart, r): xor = 0 for l in range(r, lstart - 1, -1): xor ^= A[l] if not xor: return True else: return False def minops(A, N): lstart = 0 ops = 0 while True: for r in range(lstart, N): if haxorzro(A, lstart, r): break else: break lstart = r + 1 ops += 1 return ops T = int(input()) for i in range(T): N = int(input()) A = tuple(map(int, input().split())) print(minops(A, N))
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR IF VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER RETURN 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 EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
An array A of size N is called *good* if the following conditions hold: For every pair (l, r) (1 ≤ l ≤ r ≤ N), A_{l} \oplus A_{l+1} \oplus ... \oplus A_{r} \ne 0. (where \oplus denotes the [bitwise XOR operation].) JJ has an array A of size N. He wants to convert the array to a good array. To do so he can perform the following operation multiple times: Pick an index i such that (1 ≤ i ≤ N) and set A_{i} := X where 0 ≤ X < 10^{10^{10}}. Find the minimum number of operations required to convert A into a *good* array. ------ Input Format ------ - The first line contains T - the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N - the size of the array A. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the minimum number of operations required to convert the array A into a good array. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $0 ≤ A_{i} < 2^{30}$ - Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 5 1 2 3 4 4 3 0 0 0 6 2 3 5 7 11 13 ----- Sample Output 1 ------ 2 3 0 ----- explanation 1 ------ Test Case 1: We can set $A_{2} = 4$ and $A_{4} = 5$. Thereby $A$ will become $[1, 4, 3, 5, 4]$ which is *good*. We can prove that we can not make $A$ good in $< 2$ operations. Test Case 2: We can set $A_{1} = 1$, $A_{2} = 10$ and $A_{3} = 100$. Thereby $A$ will become $[1, 10, 100]$ which is *good*. We can prove that we can not make $A$ good in $< 3$ operations. Test Case 3: The given array $A$ is already *good*.
for _ in range(int(input())): size = int(input()) array = list(map(int, input().split())) maps = set() ans = 0 xors = 0 for i in array: xors ^= i if xors == 0 or xors in maps: ans = ans + 1 maps = set() xors = 0 else: maps.add(xors) print(ans)
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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
An array A of size N is called *good* if the following conditions hold: For every pair (l, r) (1 ≤ l ≤ r ≤ N), A_{l} \oplus A_{l+1} \oplus ... \oplus A_{r} \ne 0. (where \oplus denotes the [bitwise XOR operation].) JJ has an array A of size N. He wants to convert the array to a good array. To do so he can perform the following operation multiple times: Pick an index i such that (1 ≤ i ≤ N) and set A_{i} := X where 0 ≤ X < 10^{10^{10}}. Find the minimum number of operations required to convert A into a *good* array. ------ Input Format ------ - The first line contains T - the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N - the size of the array A. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the minimum number of operations required to convert the array A into a good array. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $0 ≤ A_{i} < 2^{30}$ - Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 5 1 2 3 4 4 3 0 0 0 6 2 3 5 7 11 13 ----- Sample Output 1 ------ 2 3 0 ----- explanation 1 ------ Test Case 1: We can set $A_{2} = 4$ and $A_{4} = 5$. Thereby $A$ will become $[1, 4, 3, 5, 4]$ which is *good*. We can prove that we can not make $A$ good in $< 2$ operations. Test Case 2: We can set $A_{1} = 1$, $A_{2} = 10$ and $A_{3} = 100$. Thereby $A$ will become $[1, 10, 100]$ which is *good*. We can prove that we can not make $A$ good in $< 3$ operations. Test Case 3: The given array $A$ is already *good*.
def Solution(n, a): count = 0 temp = {0} p = 0 for i in range(n): p = p ^ a[i] if p not in temp: temp.add(p) else: count += 1 temp = {p} return count test = int(input()) for t in range(test): n = int(input()) a = tuple(map(int, input().split())) print(Solution(n, a))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR RETURN 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 EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
An array A of size N is called *good* if the following conditions hold: For every pair (l, r) (1 ≤ l ≤ r ≤ N), A_{l} \oplus A_{l+1} \oplus ... \oplus A_{r} \ne 0. (where \oplus denotes the [bitwise XOR operation].) JJ has an array A of size N. He wants to convert the array to a good array. To do so he can perform the following operation multiple times: Pick an index i such that (1 ≤ i ≤ N) and set A_{i} := X where 0 ≤ X < 10^{10^{10}}. Find the minimum number of operations required to convert A into a *good* array. ------ Input Format ------ - The first line contains T - the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N - the size of the array A. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the minimum number of operations required to convert the array A into a good array. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $0 ≤ A_{i} < 2^{30}$ - Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 5 1 2 3 4 4 3 0 0 0 6 2 3 5 7 11 13 ----- Sample Output 1 ------ 2 3 0 ----- explanation 1 ------ Test Case 1: We can set $A_{2} = 4$ and $A_{4} = 5$. Thereby $A$ will become $[1, 4, 3, 5, 4]$ which is *good*. We can prove that we can not make $A$ good in $< 2$ operations. Test Case 2: We can set $A_{1} = 1$, $A_{2} = 10$ and $A_{3} = 100$. Thereby $A$ will become $[1, 10, 100]$ which is *good*. We can prove that we can not make $A$ good in $< 3$ operations. Test Case 3: The given array $A$ is already *good*.
def ans(arr): k = {0} current = 0 c = 0 for y in arr: xored = current ^ y if xored in k: c += 1 k = {y} current = y else: current = xored k.add(xored) return c test_cases = int(input()) while test_cases != 0: d_ = input() d = list(map(int, input().split())) print(ans(d)) test_cases -= 1
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER
An array A of size N is called *good* if the following conditions hold: For every pair (l, r) (1 ≤ l ≤ r ≤ N), A_{l} \oplus A_{l+1} \oplus ... \oplus A_{r} \ne 0. (where \oplus denotes the [bitwise XOR operation].) JJ has an array A of size N. He wants to convert the array to a good array. To do so he can perform the following operation multiple times: Pick an index i such that (1 ≤ i ≤ N) and set A_{i} := X where 0 ≤ X < 10^{10^{10}}. Find the minimum number of operations required to convert A into a *good* array. ------ Input Format ------ - The first line contains T - the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N - the size of the array A. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the minimum number of operations required to convert the array A into a good array. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $0 ≤ A_{i} < 2^{30}$ - Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 5 1 2 3 4 4 3 0 0 0 6 2 3 5 7 11 13 ----- Sample Output 1 ------ 2 3 0 ----- explanation 1 ------ Test Case 1: We can set $A_{2} = 4$ and $A_{4} = 5$. Thereby $A$ will become $[1, 4, 3, 5, 4]$ which is *good*. We can prove that we can not make $A$ good in $< 2$ operations. Test Case 2: We can set $A_{1} = 1$, $A_{2} = 10$ and $A_{3} = 100$. Thereby $A$ will become $[1, 10, 100]$ which is *good*. We can prove that we can not make $A$ good in $< 3$ operations. Test Case 3: The given array $A$ is already *good*.
t = int(input()) for s in range(t): a = int(input()) arr = [int(i) for i in input().split()] s = set() s.add(0) x = 0 ans = 0 for i in arr: x = x ^ i if x in s: ans += 1 s.clear() s.add(x) print(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 FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
An array A of size N is called *good* if the following conditions hold: For every pair (l, r) (1 ≤ l ≤ r ≤ N), A_{l} \oplus A_{l+1} \oplus ... \oplus A_{r} \ne 0. (where \oplus denotes the [bitwise XOR operation].) JJ has an array A of size N. He wants to convert the array to a good array. To do so he can perform the following operation multiple times: Pick an index i such that (1 ≤ i ≤ N) and set A_{i} := X where 0 ≤ X < 10^{10^{10}}. Find the minimum number of operations required to convert A into a *good* array. ------ Input Format ------ - The first line contains T - the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N - the size of the array A. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the minimum number of operations required to convert the array A into a good array. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $0 ≤ A_{i} < 2^{30}$ - Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 5 1 2 3 4 4 3 0 0 0 6 2 3 5 7 11 13 ----- Sample Output 1 ------ 2 3 0 ----- explanation 1 ------ Test Case 1: We can set $A_{2} = 4$ and $A_{4} = 5$. Thereby $A$ will become $[1, 4, 3, 5, 4]$ which is *good*. We can prove that we can not make $A$ good in $< 2$ operations. Test Case 2: We can set $A_{1} = 1$, $A_{2} = 10$ and $A_{3} = 100$. Thereby $A$ will become $[1, 10, 100]$ which is *good*. We can prove that we can not make $A$ good in $< 3$ operations. Test Case 3: The given array $A$ is already *good*.
for _ in range(int(input())): xrs = set([0]) n = int(input()) a = [int(i) for i in input().split()] prv = 0 ct = 0 for i in range(n): xr = prv ^ a[i] if xr in xrs: ct += 1 xrs = set([xr]) else: xrs.add(xr) prv = xr print(ct)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR LIST NUMBER 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 NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
An array A of size N is called *good* if the following conditions hold: For every pair (l, r) (1 ≤ l ≤ r ≤ N), A_{l} \oplus A_{l+1} \oplus ... \oplus A_{r} \ne 0. (where \oplus denotes the [bitwise XOR operation].) JJ has an array A of size N. He wants to convert the array to a good array. To do so he can perform the following operation multiple times: Pick an index i such that (1 ≤ i ≤ N) and set A_{i} := X where 0 ≤ X < 10^{10^{10}}. Find the minimum number of operations required to convert A into a *good* array. ------ Input Format ------ - The first line contains T - the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N - the size of the array A. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N} denoting the array A. ------ Output Format ------ For each test case, output the minimum number of operations required to convert the array A into a good array. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ N ≤ 10^{5}$ $0 ≤ A_{i} < 2^{30}$ - Sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$. ----- Sample Input 1 ------ 3 5 1 2 3 4 4 3 0 0 0 6 2 3 5 7 11 13 ----- Sample Output 1 ------ 2 3 0 ----- explanation 1 ------ Test Case 1: We can set $A_{2} = 4$ and $A_{4} = 5$. Thereby $A$ will become $[1, 4, 3, 5, 4]$ which is *good*. We can prove that we can not make $A$ good in $< 2$ operations. Test Case 2: We can set $A_{1} = 1$, $A_{2} = 10$ and $A_{3} = 100$. Thereby $A$ will become $[1, 10, 100]$ which is *good*. We can prove that we can not make $A$ good in $< 3$ operations. Test Case 3: The given array $A$ is already *good*.
t = int(input()) while t > 0: t = t - 1 n = int(input()) arr = list(map(int, input().split())) ans = 0 x = 0 s = set() s.add(0) for i in range(n): x = x ^ arr[i] if x in s: s = set() ans += 1 s.add(0) x = 0 s.add(x) print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Given a string num representing the digits of a very large integer and an integer k. You are allowed to swap any two adjacent digits of the integer at most k times. Return the minimum integer you can obtain also as a string.   Example 1: Input: num = "4321", k = 4 Output: "1342" Explanation: The steps to obtain the minimum integer from 4321 with 4 adjacent swaps are shown. Example 2: Input: num = "100", k = 1 Output: "010" Explanation: It's ok for the output to have leading zeros, but the input is guaranteed not to have any leading zeros. Example 3: Input: num = "36789", k = 1000 Output: "36789" Explanation: We can keep the number without any swaps. Example 4: Input: num = "22", k = 22 Output: "22" Example 5: Input: num = "9438957234785635408", k = 23 Output: "0345989723478563548"   Constraints: 1 <= num.length <= 30000 num contains digits only and doesn't have leading zeros. 1 <= k <= 10^9
class Solution: def minInteger(self, num: str, k: int) -> str: rest = num move = 0 s = "" for dig in range(10): count = 0 digC = str(dig) for i, c in enumerate(rest): if c == digC: if k < move + i - count: rest = rest.replace(digC, "", count) s += digC * count remain = k - move mid = rest[0 : remain + 1] while remain: tmp = min(mid) for ti, tc in enumerate(mid): if tc == tmp: remain -= ti s += tc rest = rest.replace(tc, "", 1) mid = rest[0 : remain + 1] break return s + rest move += i - count count += 1 rest = rest.replace(digC, "") s += digC * count return s
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR STRING VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR STRING NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER RETURN BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING VAR BIN_OP VAR VAR RETURN VAR VAR
Given a string num representing the digits of a very large integer and an integer k. You are allowed to swap any two adjacent digits of the integer at most k times. Return the minimum integer you can obtain also as a string.   Example 1: Input: num = "4321", k = 4 Output: "1342" Explanation: The steps to obtain the minimum integer from 4321 with 4 adjacent swaps are shown. Example 2: Input: num = "100", k = 1 Output: "010" Explanation: It's ok for the output to have leading zeros, but the input is guaranteed not to have any leading zeros. Example 3: Input: num = "36789", k = 1000 Output: "36789" Explanation: We can keep the number without any swaps. Example 4: Input: num = "22", k = 22 Output: "22" Example 5: Input: num = "9438957234785635408", k = 23 Output: "0345989723478563548"   Constraints: 1 <= num.length <= 30000 num contains digits only and doesn't have leading zeros. 1 <= k <= 10^9
class Solution: def minInteger(self, num: str, k: int) -> str: if k <= 0: return num for i in range(10): ind = num.find(str(i)) if 0 <= ind <= k: return str(num[ind]) + self.minInteger( num[0:ind] + num[ind + 1 :], k - ind ) return num
CLASS_DEF FUNC_DEF VAR VAR IF VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF NUMBER VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR RETURN VAR VAR
Given a string num representing the digits of a very large integer and an integer k. You are allowed to swap any two adjacent digits of the integer at most k times. Return the minimum integer you can obtain also as a string.   Example 1: Input: num = "4321", k = 4 Output: "1342" Explanation: The steps to obtain the minimum integer from 4321 with 4 adjacent swaps are shown. Example 2: Input: num = "100", k = 1 Output: "010" Explanation: It's ok for the output to have leading zeros, but the input is guaranteed not to have any leading zeros. Example 3: Input: num = "36789", k = 1000 Output: "36789" Explanation: We can keep the number without any swaps. Example 4: Input: num = "22", k = 22 Output: "22" Example 5: Input: num = "9438957234785635408", k = 23 Output: "0345989723478563548"   Constraints: 1 <= num.length <= 30000 num contains digits only and doesn't have leading zeros. 1 <= k <= 10^9
class Solution: def minInteger(self, num: str, k: int) -> str: n = len(num) if k >= (n - 1) * n // 2: return "".join(sorted(num)) ans = [] while k and num: for d in "0123456789": i = num.find(d) if 0 <= i <= k: ans.append(d) num = num[:i] + num[i + 1 :] k -= i break return "".join(ans) + num
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER RETURN FUNC_CALL STRING FUNC_CALL VAR VAR ASSIGN VAR LIST WHILE VAR VAR FOR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF NUMBER VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR RETURN BIN_OP FUNC_CALL STRING VAR VAR VAR
Given a string num representing the digits of a very large integer and an integer k. You are allowed to swap any two adjacent digits of the integer at most k times. Return the minimum integer you can obtain also as a string.   Example 1: Input: num = "4321", k = 4 Output: "1342" Explanation: The steps to obtain the minimum integer from 4321 with 4 adjacent swaps are shown. Example 2: Input: num = "100", k = 1 Output: "010" Explanation: It's ok for the output to have leading zeros, but the input is guaranteed not to have any leading zeros. Example 3: Input: num = "36789", k = 1000 Output: "36789" Explanation: We can keep the number without any swaps. Example 4: Input: num = "22", k = 22 Output: "22" Example 5: Input: num = "9438957234785635408", k = 23 Output: "0345989723478563548"   Constraints: 1 <= num.length <= 30000 num contains digits only and doesn't have leading zeros. 1 <= k <= 10^9
class Solution: def minInteger(self, num: str, k: int) -> str: min_num = "".join(sorted(list(num))) i = 0 to_find = 0 while num != min_num and k > 0 and i < len(num): index = num.find(str(to_find), i) while index != -1: if index - i <= k: num = num[:i] + num[index] + num[i:index] + num[index + 1 :] k -= index - i i += 1 to_find = 0 index = num.find(str(to_find), i) else: break to_find += 1 return num
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR WHILE VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN VAR VAR
Given a string num representing the digits of a very large integer and an integer k. You are allowed to swap any two adjacent digits of the integer at most k times. Return the minimum integer you can obtain also as a string.   Example 1: Input: num = "4321", k = 4 Output: "1342" Explanation: The steps to obtain the minimum integer from 4321 with 4 adjacent swaps are shown. Example 2: Input: num = "100", k = 1 Output: "010" Explanation: It's ok for the output to have leading zeros, but the input is guaranteed not to have any leading zeros. Example 3: Input: num = "36789", k = 1000 Output: "36789" Explanation: We can keep the number without any swaps. Example 4: Input: num = "22", k = 22 Output: "22" Example 5: Input: num = "9438957234785635408", k = 23 Output: "0345989723478563548"   Constraints: 1 <= num.length <= 30000 num contains digits only and doesn't have leading zeros. 1 <= k <= 10^9
class Solution: def minInteger(self, num: str, k: int) -> str: n = len(num) if k <= 0: return num if k > n * (n - 1) // 2: return "".join(sorted(list(num))) for i in range(10): idx = num.find(str(i)) if idx >= 0 and idx <= k: return num[idx] + self.minInteger(num[:idx] + num[idx + 1 :], k - idx)
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN VAR IF VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR RETURN BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR
Given a string num representing the digits of a very large integer and an integer k. You are allowed to swap any two adjacent digits of the integer at most k times. Return the minimum integer you can obtain also as a string.   Example 1: Input: num = "4321", k = 4 Output: "1342" Explanation: The steps to obtain the minimum integer from 4321 with 4 adjacent swaps are shown. Example 2: Input: num = "100", k = 1 Output: "010" Explanation: It's ok for the output to have leading zeros, but the input is guaranteed not to have any leading zeros. Example 3: Input: num = "36789", k = 1000 Output: "36789" Explanation: We can keep the number without any swaps. Example 4: Input: num = "22", k = 22 Output: "22" Example 5: Input: num = "9438957234785635408", k = 23 Output: "0345989723478563548"   Constraints: 1 <= num.length <= 30000 num contains digits only and doesn't have leading zeros. 1 <= k <= 10^9
class Solution: def minInteger(self, num: str, k: int) -> str: D = 10 ans = num for d in range(D): i = num.find(str(d)) if i < 0: continue cost = i if cost > k: continue if i == 0: return num[i] + self.minInteger(num[i + 1 :], k) return num[i] + self.minInteger(num[:i] + num[i + 1 :], k - cost) return num
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR VAR IF VAR NUMBER RETURN BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR RETURN VAR VAR
Let's call an array consisting of n integer numbers a_1, a_2, ..., a_{n}, beautiful if it has the following property: consider all pairs of numbers x, y (x ≠ y), such that number x occurs in the array a and number y occurs in the array a; for each pair x, y must exist some position j (1 ≤ j < n), such that at least one of the two conditions are met, either a_{j} = x, a_{j} + 1 = y, or a_{j} = y, a_{j} + 1 = x. Sereja wants to build a beautiful array a, consisting of n integers. But not everything is so easy, Sereja's friend Dima has m coupons, each contains two integers q_{i}, w_{i}. Coupon i costs w_{i} and allows you to use as many numbers q_{i} as you want when constructing the array a. Values q_{i} are distinct. Sereja has no coupons, so Dima and Sereja have made the following deal. Dima builds some beautiful array a of n elements. After that he takes w_{i} rubles from Sereja for each q_{i}, which occurs in the array a. Sereja believed his friend and agreed to the contract, and now he is wondering, what is the maximum amount of money he can pay. Help Sereja, find the maximum amount of money he can pay to Dima. -----Input----- The first line contains two integers n and m (1 ≤ n ≤ 2·10^6, 1 ≤ m ≤ 10^5). Next m lines contain pairs of integers. The i-th line contains numbers q_{i}, w_{i} (1 ≤ q_{i}, w_{i} ≤ 10^5). It is guaranteed that all q_{i} are distinct. -----Output----- In a single line print maximum amount of money (in rubles) Sereja can pay. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. -----Examples----- Input 5 2 1 2 2 3 Output 5 Input 100 3 1 2 2 1 3 1 Output 4 Input 1 2 1 1 2 100 Output 100 -----Note----- In the first sample Sereja can pay 5 rubles, for example, if Dima constructs the following array: [1, 2, 1, 2, 2]. There are another optimal arrays for this test. In the third sample Sereja can pay 100 rubles, if Dima constructs the following array: [2].
n, m = map(int, input().split()) q = [0] * m w = [0] * m for i in range(m): q[i], w[i] = [int(x) for x in input().split()] w.sort(reverse=True) s = 0 v = 0 for i in range(m): i = i + 1 if i % 2 == 1: v = i * (i - 1) // 2 + 1 else: v = i * i // 2 i = i - 1 if v > n: break s += w[i] print(s)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Let's call an array consisting of n integer numbers a_1, a_2, ..., a_{n}, beautiful if it has the following property: consider all pairs of numbers x, y (x ≠ y), such that number x occurs in the array a and number y occurs in the array a; for each pair x, y must exist some position j (1 ≤ j < n), such that at least one of the two conditions are met, either a_{j} = x, a_{j} + 1 = y, or a_{j} = y, a_{j} + 1 = x. Sereja wants to build a beautiful array a, consisting of n integers. But not everything is so easy, Sereja's friend Dima has m coupons, each contains two integers q_{i}, w_{i}. Coupon i costs w_{i} and allows you to use as many numbers q_{i} as you want when constructing the array a. Values q_{i} are distinct. Sereja has no coupons, so Dima and Sereja have made the following deal. Dima builds some beautiful array a of n elements. After that he takes w_{i} rubles from Sereja for each q_{i}, which occurs in the array a. Sereja believed his friend and agreed to the contract, and now he is wondering, what is the maximum amount of money he can pay. Help Sereja, find the maximum amount of money he can pay to Dima. -----Input----- The first line contains two integers n and m (1 ≤ n ≤ 2·10^6, 1 ≤ m ≤ 10^5). Next m lines contain pairs of integers. The i-th line contains numbers q_{i}, w_{i} (1 ≤ q_{i}, w_{i} ≤ 10^5). It is guaranteed that all q_{i} are distinct. -----Output----- In a single line print maximum amount of money (in rubles) Sereja can pay. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. -----Examples----- Input 5 2 1 2 2 3 Output 5 Input 100 3 1 2 2 1 3 1 Output 4 Input 1 2 1 1 2 100 Output 100 -----Note----- In the first sample Sereja can pay 5 rubles, for example, if Dima constructs the following array: [1, 2, 1, 2, 2]. There are another optimal arrays for this test. In the third sample Sereja can pay 100 rubles, if Dima constructs the following array: [2].
def Fun(n): if n % 2: return n * (n - 1) // 2 + 1 return n * n // 2 n, m = list(map(int, input().split())) q = [0] * m w = [0] * m for i in range(m): q[i], w[i] = [int(x) for x in input().split()] w.sort(reverse=True) s = 0 v = 0 for i in range(m): if Fun(i + 1) > n: break s += w[i] print(s)
FUNC_DEF IF BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER RETURN BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Let's call an array consisting of n integer numbers a_1, a_2, ..., a_{n}, beautiful if it has the following property: consider all pairs of numbers x, y (x ≠ y), such that number x occurs in the array a and number y occurs in the array a; for each pair x, y must exist some position j (1 ≤ j < n), such that at least one of the two conditions are met, either a_{j} = x, a_{j} + 1 = y, or a_{j} = y, a_{j} + 1 = x. Sereja wants to build a beautiful array a, consisting of n integers. But not everything is so easy, Sereja's friend Dima has m coupons, each contains two integers q_{i}, w_{i}. Coupon i costs w_{i} and allows you to use as many numbers q_{i} as you want when constructing the array a. Values q_{i} are distinct. Sereja has no coupons, so Dima and Sereja have made the following deal. Dima builds some beautiful array a of n elements. After that he takes w_{i} rubles from Sereja for each q_{i}, which occurs in the array a. Sereja believed his friend and agreed to the contract, and now he is wondering, what is the maximum amount of money he can pay. Help Sereja, find the maximum amount of money he can pay to Dima. -----Input----- The first line contains two integers n and m (1 ≤ n ≤ 2·10^6, 1 ≤ m ≤ 10^5). Next m lines contain pairs of integers. The i-th line contains numbers q_{i}, w_{i} (1 ≤ q_{i}, w_{i} ≤ 10^5). It is guaranteed that all q_{i} are distinct. -----Output----- In a single line print maximum amount of money (in rubles) Sereja can pay. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. -----Examples----- Input 5 2 1 2 2 3 Output 5 Input 100 3 1 2 2 1 3 1 Output 4 Input 1 2 1 1 2 100 Output 100 -----Note----- In the first sample Sereja can pay 5 rubles, for example, if Dima constructs the following array: [1, 2, 1, 2, 2]. There are another optimal arrays for this test. In the third sample Sereja can pay 100 rubles, if Dima constructs the following array: [2].
def readdata(): global n, m, w, q n, m = [int(x) for x in input().split()] q = [0] * m w = [0] * m for i in range(m): q[i], w[i] = [int(x) for x in input().split()] def podg(): global summ w.sort(reverse=True) summ = [w[0]] * m for i in range(1, m): summ[i] = summ[i - 1] + w[i] def may(k): if k % 2 == 1: return n > k * (k - 1) // 2 return n > k * (k - 1) // 2 + (k - 2) // 2 def solve(): for i in range(1, m + 1): if may(i) and not may(i + 1): print(summ[i - 1]) return print(sum(w)) readdata() podg() solve()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
Let's call an array consisting of n integer numbers a_1, a_2, ..., a_{n}, beautiful if it has the following property: consider all pairs of numbers x, y (x ≠ y), such that number x occurs in the array a and number y occurs in the array a; for each pair x, y must exist some position j (1 ≤ j < n), such that at least one of the two conditions are met, either a_{j} = x, a_{j} + 1 = y, or a_{j} = y, a_{j} + 1 = x. Sereja wants to build a beautiful array a, consisting of n integers. But not everything is so easy, Sereja's friend Dima has m coupons, each contains two integers q_{i}, w_{i}. Coupon i costs w_{i} and allows you to use as many numbers q_{i} as you want when constructing the array a. Values q_{i} are distinct. Sereja has no coupons, so Dima and Sereja have made the following deal. Dima builds some beautiful array a of n elements. After that he takes w_{i} rubles from Sereja for each q_{i}, which occurs in the array a. Sereja believed his friend and agreed to the contract, and now he is wondering, what is the maximum amount of money he can pay. Help Sereja, find the maximum amount of money he can pay to Dima. -----Input----- The first line contains two integers n and m (1 ≤ n ≤ 2·10^6, 1 ≤ m ≤ 10^5). Next m lines contain pairs of integers. The i-th line contains numbers q_{i}, w_{i} (1 ≤ q_{i}, w_{i} ≤ 10^5). It is guaranteed that all q_{i} are distinct. -----Output----- In a single line print maximum amount of money (in rubles) Sereja can pay. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. -----Examples----- Input 5 2 1 2 2 3 Output 5 Input 100 3 1 2 2 1 3 1 Output 4 Input 1 2 1 1 2 100 Output 100 -----Note----- In the first sample Sereja can pay 5 rubles, for example, if Dima constructs the following array: [1, 2, 1, 2, 2]. There are another optimal arrays for this test. In the third sample Sereja can pay 100 rubles, if Dima constructs the following array: [2].
import itertools def f(n): return n * (n - 1) / 2 + 1 if n % 2 else n * (n - 1) / 2 + n / 2 n, m = list(map(int, input().split())) table = sorted([int(input().split()[1]) for _ in range(m)], reverse=True) ans = 1 while f(ans) <= n: ans += 1 ans -= 1 print(list(itertools.accumulate(table))[min(ans - 1, m - 1)])
IMPORT FUNC_DEF RETURN BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a_1... a_{|}t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word p can be obtained by removing the letters from word t. -----Input----- The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t. Next line contains a permutation a_1, a_2, ..., a_{|}t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ a_{i} ≤ |t|, all a_{i} are distinct). -----Output----- Print a single integer number, the maximum number of letters that Nastya can remove. -----Examples----- Input ababcba abb 5 3 4 1 7 6 2 Output 3 Input bbbabb bb 1 6 3 4 2 5 Output 4 -----Note----- In the first sample test sequence of removing made by Nastya looks like this: "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba". So, Nastya will remove only three letters.
s = input() t = input() a = [(int(x) - 1) for x in input().split()] def ok(n): bad = set(a[:n]) it = (a for i, a in enumerate(s) if i not in bad) return all(c in it for c in t) low = 0 high = len(s) while low < high: mid = (high + low + 1) // 2 if ok(mid): low = mid else: high = mid - 1 print(high)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a_1... a_{|}t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word p can be obtained by removing the letters from word t. -----Input----- The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t. Next line contains a permutation a_1, a_2, ..., a_{|}t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ a_{i} ≤ |t|, all a_{i} are distinct). -----Output----- Print a single integer number, the maximum number of letters that Nastya can remove. -----Examples----- Input ababcba abb 5 3 4 1 7 6 2 Output 3 Input bbbabb bb 1 6 3 4 2 5 Output 4 -----Note----- In the first sample test sequence of removing made by Nastya looks like this: "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba". So, Nastya will remove only three letters.
def canFind(ss, t, arr, mid): s = ss.copy() for i in range(mid): s[arr[i] - 1] = "#" k = 0 for i in range(len(t)): flag = False for j in range(k, len(s)): if t[i] == s[j]: flag = True k = j + 1 break if not flag: return False return True s = list(input()) t = list(input()) arr = list(map(int, input().split())) n = len(arr) l = 0 r = n ans = 0 while l <= r: mid = (l + r) // 2 if canFind(s, t, arr, mid): ans = mid l = mid + 1 else: r = mid - 1 print(ans)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR RETURN NUMBER RETURN NUMBER ASSIGN 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 VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a_1... a_{|}t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word p can be obtained by removing the letters from word t. -----Input----- The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t. Next line contains a permutation a_1, a_2, ..., a_{|}t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ a_{i} ≤ |t|, all a_{i} are distinct). -----Output----- Print a single integer number, the maximum number of letters that Nastya can remove. -----Examples----- Input ababcba abb 5 3 4 1 7 6 2 Output 3 Input bbbabb bb 1 6 3 4 2 5 Output 4 -----Note----- In the first sample test sequence of removing made by Nastya looks like this: "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba". So, Nastya will remove only three letters.
def isSubSequence(str1, str2, m, n): j = 0 i = 0 while j < m and i < n: if str1[j] == str2[i]: j = j + 1 i = i + 1 return j == m t = list(input()) p = input() a = list(map(int, input().split())) def check(x): count = 0 y = t.copy() for i in range(x): y[a[i] - 1] = "" b = "".join(y) return isSubSequence(p, b, len(p), len(b)) l = 0 r = len(t) m = (l + r) // 2 while r - l > 1: if check(m): l = m else: r = m m = (r + l) // 2 print(m)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER STRING ASSIGN VAR FUNC_CALL STRING VAR RETURN FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a_1... a_{|}t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word p can be obtained by removing the letters from word t. -----Input----- The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t. Next line contains a permutation a_1, a_2, ..., a_{|}t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ a_{i} ≤ |t|, all a_{i} are distinct). -----Output----- Print a single integer number, the maximum number of letters that Nastya can remove. -----Examples----- Input ababcba abb 5 3 4 1 7 6 2 Output 3 Input bbbabb bb 1 6 3 4 2 5 Output 4 -----Note----- In the first sample test sequence of removing made by Nastya looks like this: "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba". So, Nastya will remove only three letters.
def main(): t = input() p = input() n = len(t) pos = list(map(lambda x: int(x) - 1, input().split())) def f(ind): was = [(0) for _ in range(n)] for i in range(ind + 1): was[pos[i]] = 1 pattern_pos = 0 for i, ch in enumerate(t): if was[i] == 0 and pattern_pos < len(p) and ch == p[pattern_pos]: pattern_pos += 1 return pattern_pos == len(p) l, r = 0, n while l < r - 1: mid = (l + r) // 2 if f(mid): l = mid else: r = mid while l >= 0 and not f(l): l -= 1 while l + 1 < n and f(l + 1): l += 1 print(l + 1) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER WHILE BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a_1... a_{|}t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word p can be obtained by removing the letters from word t. -----Input----- The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t. Next line contains a permutation a_1, a_2, ..., a_{|}t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ a_{i} ≤ |t|, all a_{i} are distinct). -----Output----- Print a single integer number, the maximum number of letters that Nastya can remove. -----Examples----- Input ababcba abb 5 3 4 1 7 6 2 Output 3 Input bbbabb bb 1 6 3 4 2 5 Output 4 -----Note----- In the first sample test sequence of removing made by Nastya looks like this: "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba". So, Nastya will remove only three letters.
def check(i): k = 0 for c, n in zip(s, ns): if n <= i: continue if s2[k] == c: k += 1 if k == len(s2): return True return False s = input() s2 = input() ns = [(i + 1, int(x)) for i, x in enumerate(input().split())] ns.sort(key=lambda x: x[1]) ns = [x[0] for x in ns] l = 0 r = len(s) + 1 while r - l > 1: i = (r + l) // 2 if check(i): l = i else: r = i print(l)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a_1... a_{|}t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word p can be obtained by removing the letters from word t. -----Input----- The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t. Next line contains a permutation a_1, a_2, ..., a_{|}t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ a_{i} ≤ |t|, all a_{i} are distinct). -----Output----- Print a single integer number, the maximum number of letters that Nastya can remove. -----Examples----- Input ababcba abb 5 3 4 1 7 6 2 Output 3 Input bbbabb bb 1 6 3 4 2 5 Output 4 -----Note----- In the first sample test sequence of removing made by Nastya looks like this: "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba". So, Nastya will remove only three letters.
def can(m): u = sorted(a[:m]) inp = 0 inu = 0 for i in range(len(t)): if inu < len(u) and i == u[inu] - 1: inu += 1 elif t[i] == p[inp]: inp += 1 if inp == len(p): return True return False t = input() p = input() a = list(map(int, input().split())) l = 0 r = len(t) while r - l > 1: m = (r + l) // 2 if can(m): l = m else: r = m print(l)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a_1... a_{|}t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word p can be obtained by removing the letters from word t. -----Input----- The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t. Next line contains a permutation a_1, a_2, ..., a_{|}t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ a_{i} ≤ |t|, all a_{i} are distinct). -----Output----- Print a single integer number, the maximum number of letters that Nastya can remove. -----Examples----- Input ababcba abb 5 3 4 1 7 6 2 Output 3 Input bbbabb bb 1 6 3 4 2 5 Output 4 -----Note----- In the first sample test sequence of removing made by Nastya looks like this: "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba". So, Nastya will remove only three letters.
def solution(a, b, c): def check(x): temp = list(a) for i in range(x): temp[c[i] - 1] = "$" j = 0 for i in range(len(temp)): if temp[i] == b[j]: j += 1 if j == len(b): return True return False low = 0 high = len(a) - 1 ans = 0 while low <= high: mid = low + (high - low) // 2 if check(mid) == True: low = mid + 1 ans = mid else: high = mid - 1 return ans a = input() b = input() c = [int(x) for x in input().split(" ")] print(solution(a, b, c))
FUNC_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a_1... a_{|}t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word p can be obtained by removing the letters from word t. -----Input----- The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t. Next line contains a permutation a_1, a_2, ..., a_{|}t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ a_{i} ≤ |t|, all a_{i} are distinct). -----Output----- Print a single integer number, the maximum number of letters that Nastya can remove. -----Examples----- Input ababcba abb 5 3 4 1 7 6 2 Output 3 Input bbbabb bb 1 6 3 4 2 5 Output 4 -----Note----- In the first sample test sequence of removing made by Nastya looks like this: "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba". So, Nastya will remove only three letters.
t = input() p = input() a = list(map(int, input().split())) for i in range(len(a)): a[i] -= 1 step = 0 mark = [0] * len(t) def check(index): global step step += 1 for j in range(index + 1): mark[a[j]] = step temp_index = 0 for j in range(len(t)): if mark[j] == step: continue if t[j] == p[temp_index]: temp_index += 1 if temp_index == len(p): return True return False left = 0 right = len(a) - 1 while left <= right: mid = (left + right + 1) // 2 if check(mid): left = mid + 1 else: right = mid - 1 while check(mid): mid += 1 while not check(mid): mid -= 1 print(mid + 1)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FUNC_DEF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE FUNC_CALL VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a_1... a_{|}t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word p can be obtained by removing the letters from word t. -----Input----- The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t. Next line contains a permutation a_1, a_2, ..., a_{|}t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ a_{i} ≤ |t|, all a_{i} are distinct). -----Output----- Print a single integer number, the maximum number of letters that Nastya can remove. -----Examples----- Input ababcba abb 5 3 4 1 7 6 2 Output 3 Input bbbabb bb 1 6 3 4 2 5 Output 4 -----Note----- In the first sample test sequence of removing made by Nastya looks like this: "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba". So, Nastya will remove only three letters.
t = input().strip() p = input().strip() A = list(map(int, input().strip().split())) def fn(c): s = set(A[:c]) st = [] for i in range(len(t)): if (i + 1 in s) == False: st.append(t[i]) p1 = 0 p2 = 0 while p1 != len(st) and p2 != len(p): if st[p1] == p[p2]: p2 += 1 p1 += 1 if p2 == len(p): return True else: return False r = 0 l = len(A) while l - r > 1: c = int((r + l) // 2) if fn(c) == True: r = c else: l = c print(r)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a_1... a_{|}t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word p can be obtained by removing the letters from word t. -----Input----- The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t. Next line contains a permutation a_1, a_2, ..., a_{|}t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ a_{i} ≤ |t|, all a_{i} are distinct). -----Output----- Print a single integer number, the maximum number of letters that Nastya can remove. -----Examples----- Input ababcba abb 5 3 4 1 7 6 2 Output 3 Input bbbabb bb 1 6 3 4 2 5 Output 4 -----Note----- In the first sample test sequence of removing made by Nastya looks like this: "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba". So, Nastya will remove only three letters.
t = input() p = input() a = list(map(int, input().split())) def can(s, p): i = 0 for ch in s: if ch == p[i]: i += 1 if i == len(p): return True return False def binary_search(l, r): while l < r - 1: s = list(t) mid = (l + r) // 2 for index in range(mid): s[a[index] - 1] = " " ok = False i = 0 for ch in s: if ch == p[i]: i += 1 if i == len(p): ok = True break if ok: l = mid else: r = mid return l print(binary_search(0, len(a) + 1))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a_1... a_{|}t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word p can be obtained by removing the letters from word t. -----Input----- The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t. Next line contains a permutation a_1, a_2, ..., a_{|}t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ a_{i} ≤ |t|, all a_{i} are distinct). -----Output----- Print a single integer number, the maximum number of letters that Nastya can remove. -----Examples----- Input ababcba abb 5 3 4 1 7 6 2 Output 3 Input bbbabb bb 1 6 3 4 2 5 Output 4 -----Note----- In the first sample test sequence of removing made by Nastya looks like this: "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba". So, Nastya will remove only three letters.
import sys def removeat(string, indexes): return [c for i, c in enumerate(string) if i not in indexes] def contains(string, what): if not len(what): return True if not len(string): return False checked = 0 for c in string: if what[checked] == c: checked += 1 if checked == len(what): break return checked == len(what) string = list(input()) what = list(input()) indexes = [(i - 1) for i in map(int, input().split())] first = 0 last = len(indexes) - 1 while first < last: midpoint = first + (last - first) // 2 + (last - first) % 2 if contains(removeat(string, set(indexes[:midpoint])), what): first = midpoint else: last = midpoint - 1 print(first)
IMPORT FUNC_DEF RETURN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a_1... a_{|}t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word p can be obtained by removing the letters from word t. -----Input----- The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t. Next line contains a permutation a_1, a_2, ..., a_{|}t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ a_{i} ≤ |t|, all a_{i} are distinct). -----Output----- Print a single integer number, the maximum number of letters that Nastya can remove. -----Examples----- Input ababcba abb 5 3 4 1 7 6 2 Output 3 Input bbbabb bb 1 6 3 4 2 5 Output 4 -----Note----- In the first sample test sequence of removing made by Nastya looks like this: "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba". So, Nastya will remove only three letters.
import sys def debug(x, table): for name, val in table.items(): if x is val: print("DEBUG:{} -> {}".format(name, val), file=sys.stderr) return None def solve(): t = input() p = input() A = [(int(i) - 1) for i in input().split()] ans = nibutan(t, p, A) print(ans) def nibutan(t, p, A): top = len(A) btm = 0 while top - btm > 1: mid = (top + btm) // 2 if ex_subs(t, p, A, mid): btm = mid else: top = mid return btm def ex_subs(t, p, A, mid): tc = list(t) p = list(p) for i in range(mid): tc[A[i]] = "#" k = 0 cnt = 0 for c in p: if k == len(tc): return False for j in range(k, len(tc)): k += 1 if c == tc[j]: cnt += 1 break return cnt == len(p) solve()
IMPORT FUNC_DEF FOR VAR VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR RETURN NONE FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR FUNC_CALL VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER RETURN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a_1... a_{|}t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word p can be obtained by removing the letters from word t. -----Input----- The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t. Next line contains a permutation a_1, a_2, ..., a_{|}t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ a_{i} ≤ |t|, all a_{i} are distinct). -----Output----- Print a single integer number, the maximum number of letters that Nastya can remove. -----Examples----- Input ababcba abb 5 3 4 1 7 6 2 Output 3 Input bbbabb bb 1 6 3 4 2 5 Output 4 -----Note----- In the first sample test sequence of removing made by Nastya looks like this: "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba". So, Nastya will remove only three letters.
def possible(t, p, a, n): s = "" check = [True] * len(t) for i in range(n): check[a[i]] = False for i in range(len(check)): if check[i]: s += t[i] m = len(s) lp = len(p) c = 0 for i in range(m): if s[i] == p[c]: c += 1 if c == lp: return True return False t = input() p = input() a = list(map(int, input().split())) for i in range(len(a)): a[i] -= 1 low = 0 high = len(a) ans = 0 while low <= high: mid = (low + high) // 2 if possible(t, p, a, mid): ans = mid low = mid + 1 else: high = mid - 1 print(ans)
FUNC_DEF ASSIGN VAR STRING ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a_1... a_{|}t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word p can be obtained by removing the letters from word t. -----Input----- The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t. Next line contains a permutation a_1, a_2, ..., a_{|}t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ a_{i} ≤ |t|, all a_{i} are distinct). -----Output----- Print a single integer number, the maximum number of letters that Nastya can remove. -----Examples----- Input ababcba abb 5 3 4 1 7 6 2 Output 3 Input bbbabb bb 1 6 3 4 2 5 Output 4 -----Note----- In the first sample test sequence of removing made by Nastya looks like this: "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba". So, Nastya will remove only three letters.
a = input() b = input() c = [(int(i) - 1) for i in input().split()] l = 0 r = len(a) while r - l > 1: m = l + (r - l) // 2 d = list(a) j = 0 for i in range(m): d[c[i]] = "" for i in range(len(a)): if d[i] == b[j]: j += 1 if j == len(b): l = m break if j != len(b): r = m print(l)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a_1... a_{|}t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word p can be obtained by removing the letters from word t. -----Input----- The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t. Next line contains a permutation a_1, a_2, ..., a_{|}t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ a_{i} ≤ |t|, all a_{i} are distinct). -----Output----- Print a single integer number, the maximum number of letters that Nastya can remove. -----Examples----- Input ababcba abb 5 3 4 1 7 6 2 Output 3 Input bbbabb bb 1 6 3 4 2 5 Output 4 -----Note----- In the first sample test sequence of removing made by Nastya looks like this: "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba". So, Nastya will remove only three letters.
b = input() s = input() i = [(int(x) - 1) for x in input().split()] def viable(x): ind = 0 ok = [0] * len(b) for j in range(0, x): ok[i[j]] = 1 for j in range(0, len(b)): if s[ind] == b[j] and ok[j] != 1: ind += 1 if ind == len(s): break if ind == len(s): return True else: return False low = 0 high = len(b) while low < high: mid = (low + high) // 2 if viable(mid): ans = mid low = mid + 1 else: high = mid print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a_1... a_{|}t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word p can be obtained by removing the letters from word t. -----Input----- The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t. Next line contains a permutation a_1, a_2, ..., a_{|}t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ a_{i} ≤ |t|, all a_{i} are distinct). -----Output----- Print a single integer number, the maximum number of letters that Nastya can remove. -----Examples----- Input ababcba abb 5 3 4 1 7 6 2 Output 3 Input bbbabb bb 1 6 3 4 2 5 Output 4 -----Note----- In the first sample test sequence of removing made by Nastya looks like this: "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba". So, Nastya will remove only three letters.
def subset(S, s): i = 0 j = 0 while i < len(S) and j < len(s): if S[i] == s[j]: i += 1 j += 1 else: i += 1 if j == len(s): return True return False n = input() a = input() arr = [(int(x) - 1) for x in input().split()] new = [] l = 0 r = len(n) while l < r: mid = (l + r + 1) // 2 sa = arr[:mid] new = list(n) for i in sa: new[i] = "" if subset("".join(new), a): l = mid else: r = mid - 1 print(r)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR STRING IF FUNC_CALL VAR FUNC_CALL STRING VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a_1... a_{|}t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word p can be obtained by removing the letters from word t. -----Input----- The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t. Next line contains a permutation a_1, a_2, ..., a_{|}t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ a_{i} ≤ |t|, all a_{i} are distinct). -----Output----- Print a single integer number, the maximum number of letters that Nastya can remove. -----Examples----- Input ababcba abb 5 3 4 1 7 6 2 Output 3 Input bbbabb bb 1 6 3 4 2 5 Output 4 -----Note----- In the first sample test sequence of removing made by Nastya looks like this: "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba". So, Nastya will remove only three letters.
def check(tt, p): i, j = 0, 0 while i < len(t): if tt[i] == p[j]: j += 1 i += 1 if j == len(p): break if j == len(p): return 1 else: return 0 t = list(input()) p = list(input()) n = len(t) a = list(map(int, input().split())) l, r, ans = 0, n - 1, 0 while l <= r: m = (l + r) // 2 tt = t.copy() for i in range(m + 1): tt[a[i] - 1] = "" if check(tt, p): l = m + 1 ans = m + 1 else: r = m - 1 print(ans)
FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER STRING IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a_1... a_{|}t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word p can be obtained by removing the letters from word t. -----Input----- The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t. Next line contains a permutation a_1, a_2, ..., a_{|}t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ a_{i} ≤ |t|, all a_{i} are distinct). -----Output----- Print a single integer number, the maximum number of letters that Nastya can remove. -----Examples----- Input ababcba abb 5 3 4 1 7 6 2 Output 3 Input bbbabb bb 1 6 3 4 2 5 Output 4 -----Note----- In the first sample test sequence of removing made by Nastya looks like this: "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba". So, Nastya will remove only three letters.
s = input() t = input() arr = list(map(int, input().split())) l = 0 r = len(arr) - len(t) while l <= r: mid = (l + r) // 2 var = [0] * len(arr) for i in range(mid): var[arr[i] - 1] = 1 f = 0 for i in range(len(s)): if var[i]: continue if f == len(t): break if s[i] == t[f]: f += 1 if f == len(t): cnt = mid l = mid + 1 else: r = mid - 1 print(cnt)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a_1... a_{|}t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word p can be obtained by removing the letters from word t. -----Input----- The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t. Next line contains a permutation a_1, a_2, ..., a_{|}t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ a_{i} ≤ |t|, all a_{i} are distinct). -----Output----- Print a single integer number, the maximum number of letters that Nastya can remove. -----Examples----- Input ababcba abb 5 3 4 1 7 6 2 Output 3 Input bbbabb bb 1 6 3 4 2 5 Output 4 -----Note----- In the first sample test sequence of removing made by Nastya looks like this: "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba". So, Nastya will remove only three letters.
import sys input = sys.stdin.readline t = input().rstrip() p = input().rstrip() a = list(map(int, input().split())) l = 0 r = len(a) while r - l > 1: mid = (r + l) // 2 s = set(a[:mid]) j = 0 for i in range(len(t)): if j < len(p) and t[i] == p[j] and i + 1 not in s: j += 1 if j == len(p): l = mid else: r = mid print(l)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN 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 FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a_1... a_{|}t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word p can be obtained by removing the letters from word t. -----Input----- The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t. Next line contains a permutation a_1, a_2, ..., a_{|}t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ a_{i} ≤ |t|, all a_{i} are distinct). -----Output----- Print a single integer number, the maximum number of letters that Nastya can remove. -----Examples----- Input ababcba abb 5 3 4 1 7 6 2 Output 3 Input bbbabb bb 1 6 3 4 2 5 Output 4 -----Note----- In the first sample test sequence of removing made by Nastya looks like this: "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba". So, Nastya will remove only three letters.
def mi(): return map(int, input().split()) s = list(input()) t = input() a = list(map(int, input().split())) def isSubSequence(str1, str2, m, n): j = 0 i = 0 while j < m and i < n: if str1[j] == str2[i]: j = j + 1 i = i + 1 return j == m l = len(a) high = l low = 0 bestans = -1 while low <= high: mid = (low + high) // 2 b = a.copy() s1 = s.copy() for i in range(mid): s1[b[i] - 1] = "" s1 = "".join(s1) if isSubSequence(t, s1, len(t), len(s1)): low = mid + 1 bestans = max(bestans, mid) else: high = mid - 1 print(bestans)
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER STRING ASSIGN VAR FUNC_CALL STRING VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a_1... a_{|}t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word p can be obtained by removing the letters from word t. -----Input----- The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t. Next line contains a permutation a_1, a_2, ..., a_{|}t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ a_{i} ≤ |t|, all a_{i} are distinct). -----Output----- Print a single integer number, the maximum number of letters that Nastya can remove. -----Examples----- Input ababcba abb 5 3 4 1 7 6 2 Output 3 Input bbbabb bb 1 6 3 4 2 5 Output 4 -----Note----- In the first sample test sequence of removing made by Nastya looks like this: "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba". So, Nastya will remove only three letters.
s1 = input() s2 = input() rs = list(map(int, input().split())) def is_in(big, little): i, j = 0, 0 matched = 0 while i < len(big) and j < len(little): if big[i] == little[j]: matched += 1 i += 1 j += 1 else: i += 1 if matched < len(little): return False return True def gen_st(mid): global s1, s2, rs cs = set(rs[:mid]) n = [] for i in range(len(s1)): if i + 1 in cs: continue n.append(s1[i]) return is_in("".join(n), s2) start = 0 end = len(rs) weird = False while start < end: mid = (start + end) // 2 if gen_st(mid): start = mid if start == end - 1: weird = True if gen_st(end): print(end) break else: print(start) break else: end = mid - 1 if not weird and start == end: print(start)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR FUNC_CALL STRING VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a_1... a_{|}t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word p can be obtained by removing the letters from word t. -----Input----- The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t. Next line contains a permutation a_1, a_2, ..., a_{|}t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ a_{i} ≤ |t|, all a_{i} are distinct). -----Output----- Print a single integer number, the maximum number of letters that Nastya can remove. -----Examples----- Input ababcba abb 5 3 4 1 7 6 2 Output 3 Input bbbabb bb 1 6 3 4 2 5 Output 4 -----Note----- In the first sample test sequence of removing made by Nastya looks like this: "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba". So, Nastya will remove only three letters.
def findPossible(str1, str2): str1length = len(str1) str2length = len(str2) str1Flag = 0 str2Flag = 0 for x in range(0, str1length): if str1[x] == str2[str2Flag]: str2Flag += 1 if str2Flag == str2length: return True return False def delChr(oldStr, permutation, flag): newStr = list(oldStr) subPer = permutation[0:flag] subPer.sort(reverse=True) for x in range(0, flag): newStr.pop(subPer[x] - 1) return newStr def check_middle(m, permutation, input, target): banned_set = set(permutation[:m]) target_len = len(target) target_pointer = 0 input_len = len(input) for x in range(input_len): if not x + 1 in banned_set: if input[x] == target[target_pointer]: target_pointer += 1 if target_pointer == target_len: return True return False s1 = list(input()) s2 = list(input()) permutation = list(map(int, input().split())) flag = 0 newStr = s1 left = 0 right = len(s1) while left + 1 < right: m = (left + right) // 2 if check_middle(m, permutation, s1, s2): left = m pass else: right = m print(left)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN 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 ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a_1... a_{|}t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word p can be obtained by removing the letters from word t. -----Input----- The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t. Next line contains a permutation a_1, a_2, ..., a_{|}t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ a_{i} ≤ |t|, all a_{i} are distinct). -----Output----- Print a single integer number, the maximum number of letters that Nastya can remove. -----Examples----- Input ababcba abb 5 3 4 1 7 6 2 Output 3 Input bbbabb bb 1 6 3 4 2 5 Output 4 -----Note----- In the first sample test sequence of removing made by Nastya looks like this: "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba". So, Nastya will remove only three letters.
def pred(s1, s2, arr, mid): n = len(s1) m = len(s2) marked = [(0) for x in range(n)] for i in range(mid + 1): marked[arr[i] - 1] = 1 i = 0 j = 0 while i < n and j < m: if not marked[i] and s1[i] == s2[j]: j += 1 i += 1 return j != m s1 = input() s2 = input() arr = [int(x) for x in input().split(" ")] n = len(arr) l = 0 r = n - 1 while l < r: mid = l + (r - l) // 2 if pred(s1, s2, arr, mid): r = mid else: l = mid + 1 print(l)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a_1... a_{|}t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word p can be obtained by removing the letters from word t. -----Input----- The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t. Next line contains a permutation a_1, a_2, ..., a_{|}t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ a_{i} ≤ |t|, all a_{i} are distinct). -----Output----- Print a single integer number, the maximum number of letters that Nastya can remove. -----Examples----- Input ababcba abb 5 3 4 1 7 6 2 Output 3 Input bbbabb bb 1 6 3 4 2 5 Output 4 -----Note----- In the first sample test sequence of removing made by Nastya looks like this: "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba". So, Nastya will remove only three letters.
import sys Ri = lambda: [int(x) for x in sys.stdin.readline().split()] ri = lambda: sys.stdin.readline().strip() def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [([c] * b) for i in range(a)] def list3d(a, b, c, d): return [[([d] * c) for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[([e] * d) for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") INF = 10**18 MOD = 10**8 N = 5 * 10**6 def solve(no): se = set(a[:no]) flag = False ite = 0 for i in range(len(s)): if i in se: continue if s[i] == t[ite]: ite += 1 if ite == len(t): flag = True break return flag s = ri() t = ri() a = Ri() a = [(i - 1) for i in a] l = 0 h = len(a) maxx = 0 while l <= h: mid = (l + h) // 2 if solve(mid): maxx = max(maxx, mid) l = mid + 1 else: h = mid - 1 print(maxx)
IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF NONE RETURN VAR NONE FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a_1... a_{|}t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word p can be obtained by removing the letters from word t. -----Input----- The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t. Next line contains a permutation a_1, a_2, ..., a_{|}t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ a_{i} ≤ |t|, all a_{i} are distinct). -----Output----- Print a single integer number, the maximum number of letters that Nastya can remove. -----Examples----- Input ababcba abb 5 3 4 1 7 6 2 Output 3 Input bbbabb bb 1 6 3 4 2 5 Output 4 -----Note----- In the first sample test sequence of removing made by Nastya looks like this: "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba". So, Nastya will remove only three letters.
def is_obtained(p, t, K): i = 0 for ch in p: i = t.find(ch, i) + 1 if i == 0: return False while i in K: i = t.find(ch, i) + 1 if i == 0: return False return True I = input t, p, A = I(), I(), list(map(int, I().split())) L, R = 0, len(A) - 1 while L < R: x = (L + R + 1) // 2 if is_obtained(p, t, set(A[:x])): L = x else: R = x - 1 print(L)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a_1... a_{|}t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word p can be obtained by removing the letters from word t. -----Input----- The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t. Next line contains a permutation a_1, a_2, ..., a_{|}t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ a_{i} ≤ |t|, all a_{i} are distinct). -----Output----- Print a single integer number, the maximum number of letters that Nastya can remove. -----Examples----- Input ababcba abb 5 3 4 1 7 6 2 Output 3 Input bbbabb bb 1 6 3 4 2 5 Output 4 -----Note----- In the first sample test sequence of removing made by Nastya looks like this: "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba". So, Nastya will remove only three letters.
def binary_search(lis, l, r, txt, txt2): if r >= l: mid = l + (r - l) // 2 templis = lis[0 : mid + 1] if is_sub(txt, txt2, templis): return binary_search(lis, mid + 1, r, txt1, txt2) else: return binary_search(lis, l, mid - 1, txt1, txt2) else: return l - 1 def remove(txt, index): index = index - 1 try: return txt[0:index] + txt[index + 1 :] except IndexError: return txt[0:index] def is_sub(txt, txts, limit): s = set(limit) cur = 0 for i in range(len(txt)): if txt[i] == txts[cur] and i + 1 not in s: cur += 1 if cur == len(txts): return True return False txt1 = input() txt2 = input() lis = [int(x) for x in input().split()] print(binary_search(lis, 0, len(lis) - 1, txt1, txt2) + 1)
FUNC_DEF IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR RETURN BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR RETURN VAR NUMBER VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a_1... a_{|}t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word p can be obtained by removing the letters from word t. -----Input----- The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t. Next line contains a permutation a_1, a_2, ..., a_{|}t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ a_{i} ≤ |t|, all a_{i} are distinct). -----Output----- Print a single integer number, the maximum number of letters that Nastya can remove. -----Examples----- Input ababcba abb 5 3 4 1 7 6 2 Output 3 Input bbbabb bb 1 6 3 4 2 5 Output 4 -----Note----- In the first sample test sequence of removing made by Nastya looks like this: "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba". So, Nastya will remove only three letters.
t = input() p = input() block = [(int(i) - 1) for i in input().split()] ind = {} for i in range(len(block)): ind[block[i]] = i def is_part_and_parcel(s1, s2, mid): n = len(s2) m = len(s1) i = 0 c = 0 j = 0 while i < n and j < m: if ind[j] < mid: j += 1 continue if s2[i] == s1[j]: i += 1 j += 1 c += 1 else: j += 1 return c == n n = len(t) m = len(p) lo = 0 hi = len(block) - 1 while lo <= hi: mi = lo + hi >> 1 if is_part_and_parcel(t, p, mi): ans = mi lo = mi + 1 else: hi = mi - 1 print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a_1... a_{|}t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word p can be obtained by removing the letters from word t. -----Input----- The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t. Next line contains a permutation a_1, a_2, ..., a_{|}t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ a_{i} ≤ |t|, all a_{i} are distinct). -----Output----- Print a single integer number, the maximum number of letters that Nastya can remove. -----Examples----- Input ababcba abb 5 3 4 1 7 6 2 Output 3 Input bbbabb bb 1 6 3 4 2 5 Output 4 -----Note----- In the first sample test sequence of removing made by Nastya looks like this: "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba". So, Nastya will remove only three letters.
def isValid(t, t1, l, mid): temp = [] for i in range(len(l)): temp.append(t[i]) for i in range(mid): temp[l[i] - 1] = " " m = len(t1) n = len(temp) i = 0 j = 0 while j < m and i < n: if temp[i] == t1[j]: j = j + 1 i = i + 1 if j == m: return True return False t = list(input()) t1 = list(input()) l = list(map(int, input().split())) n = len(t) s = 0 e = n r = 0 while s <= e: mid = s + int((e - s) / 2) if isValid(t, t1, l, mid) == True: s = mid + 1 r = mid else: e = mid - 1 print(r)
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN 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 VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a_1... a_{|}t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word p can be obtained by removing the letters from word t. -----Input----- The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t. Next line contains a permutation a_1, a_2, ..., a_{|}t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ a_{i} ≤ |t|, all a_{i} are distinct). -----Output----- Print a single integer number, the maximum number of letters that Nastya can remove. -----Examples----- Input ababcba abb 5 3 4 1 7 6 2 Output 3 Input bbbabb bb 1 6 3 4 2 5 Output 4 -----Note----- In the first sample test sequence of removing made by Nastya looks like this: "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba". So, Nastya will remove only three letters.
t = input() p = input() a = list(map(int, input().split())) n = len(a) low = 0 high = n - 1 last = 0 while low <= high: mid = (high + low) // 2 i = 0 j = 0 usable = [False] * n for ai in a[mid:]: usable[ai - 1] = True while i < n and j < len(p): if usable[i] and t[i] == p[j]: i += 1 j += 1 else: i += 1 if j == len(p): low = mid + 1 last = mid else: high = mid - 1 if mid == (high + low) // 2: break print(last)
ASSIGN VAR FUNC_CALL VAR ASSIGN 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 ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER WHILE VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a_1... a_{|}t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word p can be obtained by removing the letters from word t. -----Input----- The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t. Next line contains a permutation a_1, a_2, ..., a_{|}t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ a_{i} ≤ |t|, all a_{i} are distinct). -----Output----- Print a single integer number, the maximum number of letters that Nastya can remove. -----Examples----- Input ababcba abb 5 3 4 1 7 6 2 Output 3 Input bbbabb bb 1 6 3 4 2 5 Output 4 -----Note----- In the first sample test sequence of removing made by Nastya looks like this: "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba". So, Nastya will remove only three letters.
from sys import stdin, stdout def ri(): return map(int, input().split()) def subset(S, s): i = 0 j = 0 while i < len(S) and j < len(s): if S[i] == s[j]: i += 1 j += 1 else: i += 1 if j == len(s): return True return False t = list(input()) p = input() a = list(ri()) tt = t[:] tt[a[0] - 1] = "" if not subset("".join(tt), p): print(0) exit() s = 0 e = len(a) - 1 while True: m = s + (e - s) // 2 ii = [0] * len(t) tt = t[:] for i in range(m + 1): tt[a[i] - 1] = "" if subset("".join(tt), p): s = m else: e = m if e - s == 1: print(s + 1) exit()
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER STRING IF FUNC_CALL VAR FUNC_CALL STRING VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER STRING IF FUNC_CALL VAR FUNC_CALL STRING VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a_1... a_{|}t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word p can be obtained by removing the letters from word t. -----Input----- The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t. Next line contains a permutation a_1, a_2, ..., a_{|}t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ a_{i} ≤ |t|, all a_{i} are distinct). -----Output----- Print a single integer number, the maximum number of letters that Nastya can remove. -----Examples----- Input ababcba abb 5 3 4 1 7 6 2 Output 3 Input bbbabb bb 1 6 3 4 2 5 Output 4 -----Note----- In the first sample test sequence of removing made by Nastya looks like this: "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba". So, Nastya will remove only three letters.
import sys def bits(n: int): return list(bin(n)).count("1") def main(test_case=False): n = int(input()) if test_case else 1 for _ in range(n): test() def flush(): sys.stdout.flush() def parr(arr): print(*arr, sep=" ") def gcd(a, b): while b: if b % a == 0: break tmp = a a = b % a b = tmp return a t = "" p = "" a = [] step = 0 mark = [] def ok(s): global p t = s i = 0 j = 0 n = len(t) m = len(p) while i < n: if t[i] == p[j]: j += 1 i += 1 if j == m: return True return False def fun(index): global step global t r = "" step += 1 for i in range(index + 1): mark[a[i] - 1] = step n = len(t) for i in range(n): if mark[i] == step: continue else: r += t[i] return r def test(): global t global p global a global mark t = input() p = input() a = list(map(int, input().split())) n = len(t) mark = [0] * n left = 0 right = n - 1 ans = 0 while left <= right: mid = (left + right) // 2 if ok(fun(mid)): ans = mid + 1 left = mid + 1 else: right = mid - 1 print(ans) main(False)
IMPORT FUNC_DEF VAR RETURN FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR STRING FUNC_DEF NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR VAR STRING FUNC_DEF WHILE VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN 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 BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a_1... a_{|}t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word p can be obtained by removing the letters from word t. -----Input----- The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t. Next line contains a permutation a_1, a_2, ..., a_{|}t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ a_{i} ≤ |t|, all a_{i} are distinct). -----Output----- Print a single integer number, the maximum number of letters that Nastya can remove. -----Examples----- Input ababcba abb 5 3 4 1 7 6 2 Output 3 Input bbbabb bb 1 6 3 4 2 5 Output 4 -----Note----- In the first sample test sequence of removing made by Nastya looks like this: "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba". So, Nastya will remove only three letters.
def binaryFind(): c = [0] * lenp maxlen = 0 for i in range(0, mid): c[a[i] - 1] = 1 for i in range(0, lenp): if c[i] == 0: if p[i] == t[maxlen]: maxlen += 1 if maxlen == lent: return True return False p = input() t = input() a = list(map(int, input().split())) lenp = len(p) lent = len(t) l = 0 r = lenp while l <= r: mid = (l + r) // 2 isok = binaryFind() if isok == True: l = mid + 1 else: r = mid - 1 print(l - 1)
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN 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 FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word t: a_1... a_{|}t|. We denote the length of word x as |x|. Note that after removing one letter, the indices of other letters don't change. For example, if t = "nastya" and a = [4, 1, 5, 3, 2, 6] then removals make the following sequence of words "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya" $\rightarrow$ "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word p. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word p can be obtained by removing the letters from word t. -----Input----- The first and second lines of the input contain the words t and p, respectively. Words are composed of lowercase letters of the Latin alphabet (1 ≤ |p| < |t| ≤ 200 000). It is guaranteed that the word p can be obtained by removing the letters from word t. Next line contains a permutation a_1, a_2, ..., a_{|}t| of letter indices that specifies the order in which Nastya removes letters of t (1 ≤ a_{i} ≤ |t|, all a_{i} are distinct). -----Output----- Print a single integer number, the maximum number of letters that Nastya can remove. -----Examples----- Input ababcba abb 5 3 4 1 7 6 2 Output 3 Input bbbabb bb 1 6 3 4 2 5 Output 4 -----Note----- In the first sample test sequence of removing made by Nastya looks like this: "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" $\rightarrow$ "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba". So, Nastya will remove only three letters.
p = input() t = input() arr = [(int(i) - 1) for i in input().split(" ")] def check(mid): l = list(p) for i in range(mid + 1): l[arr[i]] = " " found = 0 i = 0 while found < len(t) and i < len(arr): if l[i] is t[found]: found += 1 i += 1 return found == len(t) l, r = -1, len(arr) - 1 while l < r: mid = (l + r + 1) // 2 if check(mid): l = mid else: r = mid - 1 print(l + 1)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER