description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1. Example 1: Input: A = "abcd" B = "cdabcdab" Output: 3 Explanation: Repeating A three times (“abcdabcdabcd”), B is a substring of it. B is not a substring of A wh...
class Solution: def minRepeats(self, A, B): s = A moves = 1 while len(A) < len(B): A += s moves += 1 if A.find(B) != -1: return moves A += s moves += 1 if A.find(B) != -1: return moves else: ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN VAR RETURN NUMBER
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1. Example 1: Input: A = "abcd" B = "cdabcdab" Output: 3 Explanation: Repeating A three times (“abcdabcdabcd”), B is a substring of it. B is not a substring of A wh...
class Solution: def minRepeats(self, A, B): n = len(B) m = len(A) count = n // m + 2 for i in range(1, count): if B in A * i: return i return -1
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR VAR RETURN VAR RETURN NUMBER
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1. Example 1: Input: A = "abcd" B = "cdabcdab" Output: 3 Explanation: Repeating A three times (“abcdabcdabcd”), B is a substring of it. B is not a substring of A wh...
class Solution: def minRepeats(self, A, B): if A == B: return 1 if len(A) > len(B): if B in A: return 1 else: return -1 i = 0 j = 0 while i < len(A) and j < len(B): if A[i] == B[j]: ...
CLASS_DEF FUNC_DEF IF VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER 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 ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUM...
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1. Example 1: Input: A = "abcd" B = "cdabcdab" Output: 3 Explanation: Repeating A three times (“abcdabcdabcd”), B is a substring of it. B is not a substring of A wh...
class Solution: def minRepeats(self, a, b): s = a for elm in a: if elm not in b: return -1 i = 0 j = len(b) - 1 count = 1 while len(s) < 2 * len(b): if len(s) < len(b): s += a count += 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR FOR VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL...
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1. Example 1: Input: A = "abcd" B = "cdabcdab" Output: 3 Explanation: Repeating A three times (“abcdabcdabcd”), B is a substring of it. B is not a substring of A wh...
class Solution: def minRepeats(self, A, B): if len(A) > len(B): return 2 a = int(len(B) / len(A)) if B in A * a: return a elif B in A * (a + 1): return a + 1 else: return -1
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR RETURN VAR IF VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER RETURN NUMBER
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1. Example 1: Input: A = "abcd" B = "cdabcdab" Output: 3 Explanation: Repeating A three times (“abcdabcdabcd”), B is a substring of it. B is not a substring of A wh...
class Solution: def minRepeats(self, A, B): t = len(B) // len(A) + 3 count = 0 ans = "" for i in range(t): if B in ans: return count ans += A count += 1 return -1
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR RETURN VAR VAR VAR VAR NUMBER RETURN NUMBER
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1. Example 1: Input: A = "abcd" B = "cdabcdab" Output: 3 Explanation: Repeating A three times (“abcdabcdabcd”), B is a substring of it. B is not a substring of A wh...
class Solution: def minRepeats(self, A, B): max = len(B) / len(A) + 1 min = 1 rep = A for i in range(int(max)): if B in A: return min A = str(A) + str(rep) min += 1 return -1
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR RETURN VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER RETURN NUMBER
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1. Example 1: Input: A = "abcd" B = "cdabcdab" Output: 3 Explanation: Repeating A three times (“abcdabcdabcd”), B is a substring of it. B is not a substring of A wh...
class Solution: def minRepeats(self, A, B): if set(A) != set(B): return -1 c = 1 temp = A while len(B) > len(A): A += temp c += 1 if B not in A: A += temp c += 1 if B in A: return c retur...
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR RETURN VAR RETURN NUMBER
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1. Example 1: Input: A = "abcd" B = "cdabcdab" Output: 3 Explanation: Repeating A three times (“abcdabcdabcd”), B is a substring of it. B is not a substring of A wh...
class Solution: def minRepeats(self, A, B): if set(B) != set(A): return -1 min_times = len(B) // len(A) for i in range(2): _A = A * (min_times + i) if _A.find(B) != -1: return min_times + i return -1
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN BIN_OP VAR VAR RETURN NUMBER
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1. Example 1: Input: A = "abcd" B = "cdabcdab" Output: 3 Explanation: Repeating A three times (“abcdabcdabcd”), B is a substring of it. B is not a substring of A wh...
class Solution: def minRepeats(self, a, b): len_a = len(a) len_b = len(b) for i in range(0, len_a): if a[i] == b[0]: k = i count = 1 for j in range(0, len_b): if k >= len_a: k = 0 ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR RETUR...
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1. Example 1: Input: A = "abcd" B = "cdabcdab" Output: 3 Explanation: Repeating A three times (“abcdabcdabcd”), B is a substring of it. B is not a substring of A wh...
class Solution: def minRepeats(self, a, b): repeat = 1 c = a while len(b) > len(c): c += a repeat += 1 if not b in c: c += a repeat += 1 if b in c: return repeat return -1
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR RETURN VAR RETURN NUMBER
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1. Example 1: Input: A = "abcd" B = "cdabcdab" Output: 3 Explanation: Repeating A three times (“abcdabcdabcd”), B is a substring of it. B is not a substring of A wh...
class Solution: def minRepeats(self, A, B): x = set(A) if set(A) != set(B): return -1 n = len(B) n1 = len(A) p = n // n1 y = A * p if y.find(B) != -1: return p elif (y + A).find(B) != -1: return p + 1 else: ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN VAR IF FUNC_CALL BIN_OP VAR VAR VAR NUMBER RETURN BIN_OP VAR NUMBER RETURN...
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1. Example 1: Input: A = "abcd" B = "cdabcdab" Output: 3 Explanation: Repeating A three times (“abcdabcdabcd”), B is a substring of it. B is not a substring of A wh...
class Solution: def minRepeats(self, a, b): n = len(a) m = len(b) tmp = "" c = 0 while len(tmp) < n + m: tmp += a c += 1 if b in tmp: return c return -1
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR VAR RETURN VAR RETURN NUMBER
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1. Example 1: Input: A = "abcd" B = "cdabcdab" Output: 3 Explanation: Repeating A three times (“abcdabcdabcd”), B is a substring of it. B is not a substring of A wh...
class Solution: def minRepeats(self, A, B): n = len(A) m = len(B) count = 0 for i in range(n): if A[i] == B[0]: k = i count = 1 for j in range(m): if k >= n: k = 0 ...
CLASS_DEF FUNC_DEF 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 NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER RETURN VAR RETURN NUMBER
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1. Example 1: Input: A = "abcd" B = "cdabcdab" Output: 3 Explanation: Repeating A three times (“abcdabcdabcd”), B is a substring of it. B is not a substring of A wh...
class Solution: def minRepeats(self, A, B): x = A * 10**3 if B not in x: return -1 else: x = A c = 1 while B not in x: x += A c += 1 return c
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR BIN_OP NUMBER NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER RETURN VAR
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1. Example 1: Input: A = "abcd" B = "cdabcdab" Output: 3 Explanation: Repeating A three times (“abcdabcdabcd”), B is a substring of it. B is not a substring of A wh...
class Solution: def minRepeats(self, A, B): i = c = 0 while True: a = A * i c = c + 1 if a.find(B) != -1: return c - 1 if len(a) > len(B): return -1 else: i = i + 1
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1. Example 1: Input: A = "abcd" B = "cdabcdab" Output: 3 Explanation: Repeating A three times (“abcdabcdabcd”), B is a substring of it. B is not a substring of A wh...
class Solution: def minRepeats(self, A, B): sup = A count = 1 if B in A: return count for i in range(len(B) // len(A)): sup += A count += 1 if B in sup: return count return -1
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR RETURN VAR RETURN NUMBER
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1. Example 1: Input: A = "abcd" B = "cdabcdab" Output: 3 Explanation: Repeating A three times (“abcdabcdabcd”), B is a substring of it. B is not a substring of A wh...
class Solution: def minRepeats(self, A, B): arr = [] for i in range(len(A)): if B[0] == A[i]: arr.append(i) for val in arr: i = val j = 1 neq = False res = 1 while j < len(B): if (i + 1) ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP BIN_OP VAR NU...
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1. Example 1: Input: A = "abcd" B = "cdabcdab" Output: 3 Explanation: Repeating A three times (“abcdabcdabcd”), B is a substring of it. B is not a substring of A wh...
class Solution: def minRepeats(self, A, B): S = "" c = 0 while B not in S: S += A c += 1 if len(S) >= len(B): break if B in S: return c elif B in S + A: return c + 1 else: return ...
CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR RETURN VAR IF VAR BIN_OP VAR VAR RETURN BIN_OP VAR NUMBER RETURN NUMBER
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1. Example 1: Input: A = "abcd" B = "cdabcdab" Output: 3 Explanation: Repeating A three times (“abcdabcdabcd”), B is a substring of it. B is not a substring of A wh...
class Solution: def minRepeats(self, A, B): n1 = len(A) n2 = len(B) n3 = n1 C = A while n3: if C != B[:n3]: C = C[1:] n3 -= 1 else: break count = 1 while n3 < n2: C += A ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR IF VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR NUMBER
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1. Example 1: Input: A = "abcd" B = "cdabcdab" Output: 3 Explanation: Repeating A three times (“abcdabcdabcd”), B is a substring of it. B is not a substring of A wh...
class Solution: def minRepeats(self, A, B): n1 = len(A) n2 = len(B) count = 1 k = 0 while k < n1: i = k j = 0 while B[j] == A[i] and j < n2: j += 1 if j == n2: return count ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR RETURN VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1. Example 1: Input: A = "abcd" B = "cdabcdab" Output: 3 Explanation: Repeating A three times (“abcdabcdabcd”), B is a substring of it. B is not a substring of A wh...
class Solution: def minRepeats(self, A, B): possibleStart = [i for i in range(len(A)) if B[0] == A[i]] alen = len(A) for i in possibleStart: start = i status = True count = 1 for j in B: if start == alen: st...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR RETURN VAR RETURN NUMBER
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1. Example 1: Input: A = "abcd" B = "cdabcdab" Output: 3 Explanation: Repeating A three times (“abcdabcdabcd”), B is a substring of it. B is not a substring of A wh...
class Solution: def minRepeats(self, A, B): str1 = A count = 1 while len(str1) < len(B): str1 = str1 + A count = count + 1 if str1.find(B) == -1: str1 = str1 + A count = count + 1 if str1.find(B) == -1: retu...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN VAR
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1. Example 1: Input: A = "abcd" B = "cdabcdab" Output: 3 Explanation: Repeating A three times (“abcdabcdabcd”), B is a substring of it. B is not a substring of A wh...
class Solution: def minRepeats(self, A, B): a = len(A) b = len(B) for i in range(0, a): if A[i : min(a, b + i)] != B[: min(a - i, b)]: continue cnt = 1 j = min(a - i, b) valid = True while j < b: if ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR FUNC_CALL VAR VAR BIN_OP VAR...
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1. Example 1: Input: A = "abcd" B = "cdabcdab" Output: 3 Explanation: Repeating A three times (“abcdabcdabcd”), B is a substring of it. B is not a substring of A wh...
class Solution: def minRepeats(self, A, B): n = len(A) m = len(B) c = 0 tmp = "" while len(tmp) < m: tmp += A c += 1 if B in tmp: return c tmp += A c += 1 if B in tmp: return c return -1
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR RETURN VAR VAR VAR VAR NUMBER IF VAR VAR RETURN VAR RETURN NUMBER
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1. Example 1: Input: A = "abcd" B = "cdabcdab" Output: 3 Explanation: Repeating A three times (“abcdabcdabcd”), B is a substring of it. B is not a substring of A wh...
class Solution: def minRepeats(self, A, B): a = len(A) b = len(B) for k in range(b): if B[k] not in A: return -1 i = 1 while i < 1000: c = A * i if B in c: return i i += 1 return -1
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR RETURN VAR VAR NUMBER RETURN NUMBER
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1. Example 1: Input: A = "abcd" B = "cdabcdab" Output: 3 Explanation: Repeating A three times (“abcdabcdabcd”), B is a substring of it. B is not a substring of A wh...
class Solution: def minRepeats(self, A, B): m = len(A) n = len(B) count = 0 found = False for i in range(m): j = i k = 0 count = 1 while k < n and A[j] == B[k]: if k == n - 1: found = True ...
CLASS_DEF 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 VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR NUMBER ASS...
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1. Example 1: Input: A = "abcd" B = "cdabcdab" Output: 3 Explanation: Repeating A three times (“abcdabcdabcd”), B is a substring of it. B is not a substring of A wh...
class Solution: def minRepeats(self, A, B): if len(A) > len(B): if B in A: return 1 elif B in A + A: return 2 else: return -1 else: ans = 1 temp = A while len(temp) < len(B): ...
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER IF VAR BIN_OP VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR IF VAR VAR RETURN VAR IF VAR BIN_OP VAR VAR RETURN BIN_OP VAR NUMBER RETURN NUMBER
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1. Example 1: Input: A = "abcd" B = "cdabcdab" Output: 3 Explanation: Repeating A three times (“abcdabcdabcd”), B is a substring of it. B is not a substring of A wh...
class Solution: def minRepeats(self, A, B): for i in B: if i not in A: return -1 if A == B: return 1 S = A c = 1 if A in B: while len(A) < len(B): A += S c += 1 if B in A: ...
CLASS_DEF FUNC_DEF FOR VAR VAR IF VAR VAR RETURN NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR RETURN VAR VAR VAR VAR NUMBER IF VAR VAR RETURN VAR RETURN NUMBER
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1. Example 1: Input: A = "abcd" B = "cdabcdab" Output: 3 Explanation: Repeating A three times (“abcdabcdabcd”), B is a substring of it. B is not a substring of A wh...
class Solution: def minRepeats(self, A, B): repeat = 0 backup = A if A == B: return 1 while B not in backup and len(backup) < len(B) * 1.5: repeat += 1 backup = A * repeat if repeat == 0 or B not in backup: repeat = -1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR VAR RETURN NUMBER WHILE VAR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR NUMBER RETURN VAR
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1. Example 1: Input: A = "abcd" B = "cdabcdab" Output: 3 Explanation: Repeating A three times (“abcdabcdabcd”), B is a substring of it. B is not a substring of A wh...
class Solution: def minRepeats(self, A, B): if B in A: return 1 set_b = set(c for c in B) for c in A: if c not in set_b: return -1 min_rep = len(B) // len(A) if len(B) % len(A) != 0 or A != B[: len(A)]: min_rep += 1 ...
CLASS_DEF FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF ...
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1. Example 1: Input: A = "abcd" B = "cdabcdab" Output: 3 Explanation: Repeating A three times (“abcdabcdabcd”), B is a substring of it. B is not a substring of A wh...
class Solution: def minRepeats(self, A, B): parent = str(A) ans = 1 while len(parent) < len(B): parent = parent + str(A) + "" ans += 1 if parent.find(B) == -1: parent = parent + str(A) + "" ans += 1 if parent.find(B) == -1:...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR STRING VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR STRING VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN VAR
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1. Example 1: Input: A = "abcd" B = "cdabcdab" Output: 3 Explanation: Repeating A three times (“abcdabcdabcd”), B is a substring of it. B is not a substring of A wh...
class Solution: def minRepeats(self, A, B): for i in B: if A.find(i) == -1: return -1 for i in range(1, len(B)): if (A * i).find(B) != -1: return i if len(A * i) >= len(A) + len(B): return -1
CLASS_DEF FUNC_DEF FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL BIN_OP VAR VAR VAR NUMBER RETURN VAR IF FUNC_CALL VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER
Given two strings A and B. Find minimum number of times A has to be repeated such that B is a Substring of it. If B can never be a substring then return -1. Example 1: Input: A = "abcd" B = "cdabcdab" Output: 3 Explanation: Repeating A three times (“abcdabcdabcd”), B is a substring of it. B is not a substring of A wh...
class Solution: def minRepeats(self, A, B): ans = 1 s = A while len(s) < len(B): s += A ans += 1 if s.__contains__(B): return ans s += A if s.__contains__(B): return ans + 1 return -1
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR RETURN VAR VAR VAR IF FUNC_CALL VAR VAR RETURN BIN_OP VAR NUMBER RETURN NUMBER
Given a matrix mat of size N x M where every element is either O or X. Replace all O with X that are surrounded by X. A O (or a set of O) is considered to be surrounded by X if there are X at locations just below, just above, just left and just right of it. Example 1: Input: n = 5, m = 4 mat = {{'X', 'X', 'X', 'X'}, ...
class Solution: def fill(self, n, m, mat): direction = [[0, 1], [1, 0], [0, -1], [-1, 0]] visited = [[(0) for i in range(m)] for j in range(n)] def dfs(row, col): visited[row][col] = 1 for dir in direction: r = row + dir[0] c = col + ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR NUMBER V...
Given a matrix mat of size N x M where every element is either O or X. Replace all O with X that are surrounded by X. A O (or a set of O) is considered to be surrounded by X if there are X at locations just below, just above, just left and just right of it. Example 1: Input: n = 5, m = 4 mat = {{'X', 'X', 'X', 'X'}, ...
class Solution: def fill(self, n, m, mat): directions = [[0, 1], [1, 0], [-1, 0], [0, -1]] def dfs(row, col): if row >= 0 and row < n and col >= 0 and col < m and mat[row][col] == "O": mat[row][col] = "NO" for dir in directions: newRo...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER FUNC_DEF IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR STRING ASSIGN VAR VAR VAR STRING FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR F...
Given a matrix mat of size N x M where every element is either O or X. Replace all O with X that are surrounded by X. A O (or a set of O) is considered to be surrounded by X if there are X at locations just below, just above, just left and just right of it. Example 1: Input: n = 5, m = 4 mat = {{'X', 'X', 'X', 'X'}, ...
class Solution: def fill(self, n, m, mat): vis = [[(False) for i in range(m)] for j in range(n)] res = [[(0) for i in range(m)] for j in range(n)] queue = [] for i in range(m): if mat[0][i] == "O": queue.append([0, i]) vis[0][i] = 1 ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR STRING EXPR FUNC_CALL VAR LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR STRING EXPR FUNC_CALL VAR LI...
Given a matrix mat of size N x M where every element is either O or X. Replace all O with X that are surrounded by X. A O (or a set of O) is considered to be surrounded by X if there are X at locations just below, just above, just left and just right of it. Example 1: Input: n = 5, m = 4 mat = {{'X', 'X', 'X', 'X'}, ...
class Solution: def fill(self, n, m, a): q = [] for i in range(n): if a[i][0] == "O": q.append((i, 0)) if a[i][m - 1] == "O": q.append((i, m - 1)) for j in range(m): if a[0][j] == "O": q.append((0, j)) ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER STRING EXPR FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR STRING EXPR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR STRING EXPR FUNC_...
Given a matrix mat of size N x M where every element is either O or X. Replace all O with X that are surrounded by X. A O (or a set of O) is considered to be surrounded by X if there are X at locations just below, just above, just left and just right of it. Example 1: Input: n = 5, m = 4 mat = {{'X', 'X', 'X', 'X'}, ...
class Solution: def DFS(self, row, col, mat, visited, n, m): visited[row][col] = True delta_col = [-1, 0, 1, 0] delta_row = [0, 1, 0, -1] for i in range(0, 4): nrow = row + delta_row[i] ncol = col + delta_col[i] if ( nrow >= 0 ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR ...
Given a matrix mat of size N x M where every element is either O or X. Replace all O with X that are surrounded by X. A O (or a set of O) is considered to be surrounded by X if there are X at locations just below, just above, just left and just right of it. Example 1: Input: n = 5, m = 4 mat = {{'X', 'X', 'X', 'X'}, ...
class Solution: def fill(self, n, m, mat): res = mat n = len(mat) m = len(mat[0]) if n == 1 or n == 2: return mat vis = [] for i in range(n): vis.append([0] * m) for i in range(n): for j in range(m): if i ==...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VA...
Given a matrix mat of size N x M where every element is either O or X. Replace all O with X that are surrounded by X. A O (or a set of O) is considered to be surrounded by X if there are X at locations just below, just above, just left and just right of it. Example 1: Input: n = 5, m = 4 mat = {{'X', 'X', 'X', 'X'}, ...
class Solution: def fill(self, n, m, mat): def cap(r, c): if r < 0 or c < 0 or r >= n or c >= m or mat[r][c] != "O": return mat[r][c] = "T" cap(r + 1, c) cap(r - 1, c) cap(r, c + 1) cap(r, c - 1) for i in rang...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR VAR VAR STRING RETURN ASSIGN VAR VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR F...
Given a matrix mat of size N x M where every element is either O or X. Replace all O with X that are surrounded by X. A O (or a set of O) is considered to be surrounded by X if there are X at locations just below, just above, just left and just right of it. Example 1: Input: n = 5, m = 4 mat = {{'X', 'X', 'X', 'X'}, ...
class Solution: def dfs(self, i, j, vis, mat): n, m = len(mat), len(mat[0]) vis[i][j] = 1 dx, dy = [-1, 0, 1, 0], [0, -1, 0, 1] for k in range(4): nx, ny = i + dx[k], j + dy[k] if ( nx >= 0 and nx < n and ny >= ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR N...
Given a matrix mat of size N x M where every element is either O or X. Replace all O with X that are surrounded by X. A O (or a set of O) is considered to be surrounded by X if there are X at locations just below, just above, just left and just right of it. Example 1: Input: n = 5, m = 4 mat = {{'X', 'X', 'X', 'X'}, ...
class Solution: def fill(self, M, N, mat): def floodFillUtil(mat, x, y, prevV, newV): if x < 0 or x >= M or y < 0 or y >= N: return if mat[x][y] != prevV: return mat[x][y] = newV floodFillUtil(mat, x + 1, y, prevV, newV) ...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR RETURN IF VAR VAR VAR VAR RETURN ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VA...
Given a matrix mat of size N x M where every element is either O or X. Replace all O with X that are surrounded by X. A O (or a set of O) is considered to be surrounded by X if there are X at locations just below, just above, just left and just right of it. Example 1: Input: n = 5, m = 4 mat = {{'X', 'X', 'X', 'X'}, ...
class Solution: def fill(self, n, m, mat): arr = [] neighbors = [[1, 0], [0, 1], [-1, 0], [0, -1]] for i in range(n): for j in range(m): if (i == 0 or j == 0 or i == n - 1 or j == m - 1) and mat[i][j] == "O": arr.append([i, j]) visited...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR STRING EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR BIN_OP LIS...
Given a matrix mat of size N x M where every element is either O or X. Replace all O with X that are surrounded by X. A O (or a set of O) is considered to be surrounded by X if there are X at locations just below, just above, just left and just right of it. Example 1: Input: n = 5, m = 4 mat = {{'X', 'X', 'X', 'X'}, ...
class Solution: def fill(self, n, m, mat): visited = [[(0) for i in range(m)] for j in range(n)] def dfs(visited, row, col, mat): row_del = [-1, 1, 0, 0] col_del = [0, 0, -1, 1] visited[row][col] = 1 for i in range(4): new_row = row +...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR VAR VAR VAR NUMB...
Given a matrix mat of size N x M where every element is either O or X. Replace all O with X that are surrounded by X. A O (or a set of O) is considered to be surrounded by X if there are X at locations just below, just above, just left and just right of it. Example 1: Input: n = 5, m = 4 mat = {{'X', 'X', 'X', 'X'}, ...
class Solution: ans = 1 def gen(self, i, j, n, m, mat, visited): visited[i][j] = 1 if i - 1 >= 0 and visited[i - 1][j] == 0 and mat[i - 1][j] == "O": visited[i - 1][j] = 1 self.gen(i - 1, j, n, m, mat, visited) if i + 1 < n and visited[i + 1][j] == 0 and mat[i + ...
CLASS_DEF ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR STRING ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_...
Given a matrix mat of size N x M where every element is either O or X. Replace all O with X that are surrounded by X. A O (or a set of O) is considered to be surrounded by X if there are X at locations just below, just above, just left and just right of it. Example 1: Input: n = 5, m = 4 mat = {{'X', 'X', 'X', 'X'}, ...
class Solution: def fill(self, n, m, mat): for i in range(n): for j in range(m): if mat[i][j] == "O": mat[i][j] = "-" for i in range(n): if mat[i][0] == "-": self.helper(mat, i, 0, "-", "O") for i in range(n): ...
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER STRING EXPR FUNC_CALL VAR VAR VAR NUMBER STRING STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NU...
Given a matrix mat of size N x M where every element is either O or X. Replace all O with X that are surrounded by X. A O (or a set of O) is considered to be surrounded by X if there are X at locations just below, just above, just left and just right of it. Example 1: Input: n = 5, m = 4 mat = {{'X', 'X', 'X', 'X'}, ...
class Solution: def __dfs__(self, visited, final_ans, root, row, col, rows, columns): visited[row][col] = True nodes_to_visit = [ (row - 1, col), (row + 1, col), (row, col + 1), (row, col - 1), ] for temp_row, temp_col in nodes_to_visi...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LIST BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR VAR VAR IF NUMBER VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR ASSIGN VAR N...
Given a matrix mat of size N x M where every element is either O or X. Replace all O with X that are surrounded by X. A O (or a set of O) is considered to be surrounded by X if there are X at locations just below, just above, just left and just right of it. Example 1: Input: n = 5, m = 4 mat = {{'X', 'X', 'X', 'X'}, ...
class Solution: def fill(self, n, m, mat): def dfs(row, col, visited, mat, r, c): visited[row][col] = 1 for i in range(4): nrow = row + r[i] ncol = col + c[i] if ( nrow >= 0 and nrow < n ...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR ...
Given a matrix mat of size N x M where every element is either O or X. Replace all O with X that are surrounded by X. A O (or a set of O) is considered to be surrounded by X if there are X at locations just below, just above, just left and just right of it. Example 1: Input: n = 5, m = 4 mat = {{'X', 'X', 'X', 'X'}, ...
class Solution: def fill(self, n, m, mat): visited = [[(0) for i in range(m)] for j in range(n)] ans = mat.copy() def dfs(row, col): visited[row][col] = 1 path = [(row + 1, col), (row - 1, col), (row, col + 1), (row, col - 1)] for nrow, ncol in path: ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LIST BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER...
Given a matrix mat of size N x M where every element is either O or X. Replace all O with X that are surrounded by X. A O (or a set of O) is considered to be surrounded by X if there are X at locations just below, just above, just left and just right of it. Example 1: Input: n = 5, m = 4 mat = {{'X', 'X', 'X', 'X'}, ...
class Solution: def fill(self, n, m, board): def dfs(m, n, delcol, delrow, board, vis, row, col): vis[row][col] = 1 for i in range(4): nrow = row + delrow[i] ncol = col + delcol[i] if ( nrow >= 0 ...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUN...
Barney lives in NYC. NYC has infinite number of intersections numbered with positive integers starting from 1. There exists a bidirectional road between intersections i and 2i and another road between i and 2i + 1 for every positive integer i. You can clearly see that there exists a unique shortest path between any two...
d = {} def pro(x, y, w): res = 0 while x != y: if x < y: x, y = y, x d[x] = d.get(x, 0) + w res += d[x] x //= 2 return res q = int(input()) while q > 0: q -= 1 s = list(map(int, input().split())) if s[0] == 1: pro(s[1], s[2], s[3]) else...
ASSIGN VAR DICT FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUM...
Barney lives in NYC. NYC has infinite number of intersections numbered with positive integers starting from 1. There exists a bidirectional road between intersections i and 2i and another road between i and 2i + 1 for every positive integer i. You can clearly see that there exists a unique shortest path between any two...
n = int(input()) t1 = {} t2 = {} for i in range(n): q = list(map(int, input().split())) if q[0] == 1: _, u, v, w = q while u != v: v, u = max(u, v), min(u, v) if v & 1 == 1: t2[v] = t2.get(v, 0) + w v = (v - 1) // 2 else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR WHILE VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN ...
Barney lives in NYC. NYC has infinite number of intersections numbered with positive integers starting from 1. There exists a bidirectional road between intersections i and 2i and another road between i and 2i + 1 for every positive integer i. You can clearly see that there exists a unique shortest path between any two...
q = int(input()) price = {} def get_price(u): if u in price: return price[u] else: return 0 for i in range(0, q): temp = str(input()).split(" ") u = int(temp[1]) v = int(temp[2]) if temp[0] == "2": res = 0 while u != v: if u > v: re...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FUNC_DEF IF VAR VAR RETURN VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR NUMBER WHILE VAR VAR IF...
Barney lives in NYC. NYC has infinite number of intersections numbered with positive integers starting from 1. There exists a bidirectional road between intersections i and 2i and another road between i and 2i + 1 for every positive integer i. You can clearly see that there exists a unique shortest path between any two...
q = int(input()) fee = {} for _ in range(q): s = input().split() if len(s) == 4: event_type, u, v, w = map(int, s) su = set() sv = set() while u > 1: su.add(u) u >>= 1 while v > 1: sv.add(v) v >>= 1 for i in su ^ sv:...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CAL...
Barney lives in NYC. NYC has infinite number of intersections numbered with positive integers starting from 1. There exists a bidirectional road between intersections i and 2i and another road between i and 2i + 1 for every positive integer i. You can clearly see that there exists a unique shortest path between any two...
def ter(a, b): if a > b: a, b = b, a c = "" for i in range(a.bit_length() + 2): if bin(a)[i] != bin(b)[i]: break c += bin(a)[i] c = int(c, 2) o = [] while a != c: o.append(a) a //= 2 while b != c: o.append(b) b //= 2 ret...
FUNC_DEF IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR...
Barney lives in NYC. NYC has infinite number of intersections numbered with positive integers starting from 1. There exists a bidirectional road between intersections i and 2i and another road between i and 2i + 1 for every positive integer i. You can clearly see that there exists a unique shortest path between any two...
q = int(input()) def get_path(u, v): u2 = u v2 = v u_visited = set() while u2 > 1: u_visited.add(u2) u2 = u2 // 2 u_visited.add(1) v2_path = [] while v2 not in u_visited: v2_path.append(v2) v2 = v2 // 2 path = v2_path + sorted([x for x in u_visited if x ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ...
Barney lives in NYC. NYC has infinite number of intersections numbered with positive integers starting from 1. There exists a bidirectional road between intersections i and 2i and another road between i and 2i + 1 for every positive integer i. You can clearly see that there exists a unique shortest path between any two...
tree = [] n = int(input()) dic = {} for i in range(n): line = list(input().split()) if line[0] == "1": a = int(line[1]) b = int(line[2]) line[3] = float(line[3]) old_a = a old_b = b while a != b: if a > b: a = a // 2 key...
ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VA...
Barney lives in NYC. NYC has infinite number of intersections numbered with positive integers starting from 1. There exists a bidirectional road between intersections i and 2i and another road between i and 2i + 1 for every positive integer i. You can clearly see that there exists a unique shortest path between any two...
q = int(input()) L = [list(map(int, input().split())) for _ in range(q)] T = {(1): 0} def binaire(n): if n <= 1: return [n] else: return binaire(n // 2) + [n % 2] def inserer2(T, A, w, i): if i in T: T[i] += w else: T[i] = w if A == []: return T return...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT NUMBER NUMBER FUNC_DEF IF VAR NUMBER RETURN LIST VAR RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER LIST BIN_OP VAR NUMBER FUNC_DEF IF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR IF ...
Barney lives in NYC. NYC has infinite number of intersections numbered with positive integers starting from 1. There exists a bidirectional road between intersections i and 2i and another road between i and 2i + 1 for every positive integer i. You can clearly see that there exists a unique shortest path between any two...
n = int(input()) d = {} def lca(u, v, w): res = 0 while u != v: if u < v: v, u = u, v d[u] = d.get(u, 0) + w res += d[u] u = u // 2 return res for i in range(n): l = list(map(int, input().split())) if l[0] == 1: lca(l[1], l[2], l[3]) else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CAL...
Barney lives in NYC. NYC has infinite number of intersections numbered with positive integers starting from 1. There exists a bidirectional road between intersections i and 2i and another road between i and 2i + 1 for every positive integer i. You can clearly see that there exists a unique shortest path between any two...
q = int(input()) ans = [] cost = {} def getn(v, k=1): res = [] while k <= v: res.append(v) v //= 2 return res def getp(arr): res = [] for i in range(len(arr) - 1): res.append((arr[i], arr[i + 1])) return res def gets(u, v): resu, resv = getn(u), getn(v) for ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT FUNC_DEF NUMBER ASSIGN VAR LIST WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR...
Barney lives in NYC. NYC has infinite number of intersections numbered with positive integers starting from 1. There exists a bidirectional road between intersections i and 2i and another road between i and 2i + 1 for every positive integer i. You can clearly see that there exists a unique shortest path between any two...
q = int(input()) d = {} for sfsdfdsg in range(q): L = [int(x) for x in input().split()] if L[0] == 1: a, b, w = L[1:] while a != b: if a < b: a, b = b, a c = a >> 1 if (c, a) not in d: d[c, a] = 0 d[c, a] += w ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR NUMBER WHILE VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR V...
Barney lives in NYC. NYC has infinite number of intersections numbered with positive integers starting from 1. There exists a bidirectional road between intersections i and 2i and another road between i and 2i + 1 for every positive integer i. You can clearly see that there exists a unique shortest path between any two...
import sys q = int(input()) fees = {} for i in range(q): event_type, v, u, *w = map(int, input().split()) if event_type == 1: w = w[0] u, v = min(u, v), max(u, v) while u != v: parent = v // 2 if v not in fees: fees[v] = 0 fees[v] += w...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUM...
Barney lives in NYC. NYC has infinite number of intersections numbered with positive integers starting from 1. There exists a bidirectional road between intersections i and 2i and another road between i and 2i + 1 for every positive integer i. You can clearly see that there exists a unique shortest path between any two...
q = int(input()) def full_way(u): res = set() while u >= 1: res.add(u) u //= 2 return res def get_way(u, v): res1 = full_way(u) res2 = full_way(v) m = max(res1 & res2) res = set() for x in res1 | res2: if x > m: res.add(x) return res d = {} f...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR ...
Barney lives in NYC. NYC has infinite number of intersections numbered with positive integers starting from 1. There exists a bidirectional road between intersections i and 2i and another road between i and 2i + 1 for every positive integer i. You can clearly see that there exists a unique shortest path between any two...
from sys import stdin, stdout n = int(stdin.readline()) prices = {} for i in range(n): s = stdin.readline().strip() if int(s[0]) == 1: ind, a, b, w = map(int, s.split()) while a != b: if a > b: if (a, a // 2) not in prices: prices[a, a // 2] = w ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR WHILE VAR VAR IF VAR VAR IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMB...
Barney lives in NYC. NYC has infinite number of intersections numbered with positive integers starting from 1. There exists a bidirectional road between intersections i and 2i and another road between i and 2i + 1 for every positive integer i. You can clearly see that there exists a unique shortest path between any two...
def IncreaseCost(x, y, z): a = min(x, y) b = max(x, y) while a != b: while b > a: if not str(b // 2) + " " + str(b) in d: d[str(b // 2) + " " + str(b)] = z else: d[str(b // 2) + " " + str(b)] = d[str(b // 2) + " " + str(b)] + z b = ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR WHILE VAR VAR WHILE VAR VAR IF BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUM...
Barney lives in NYC. NYC has infinite number of intersections numbered with positive integers starting from 1. There exists a bidirectional road between intersections i and 2i and another road between i and 2i + 1 for every positive integer i. You can clearly see that there exists a unique shortest path between any two...
we = {} q = int(input()) for i in range(q): l = list(map(int, input().split())) t = l[0] u = l[1] v = l[2] if len(l) == 4: w = l[3] p1 = [u] p2 = [v] while u != 1: u = u // 2 p1 += [u] while v != 1: v = v // 2 p2 += [v] p1 = p1[::-1] p2...
ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST VAR ASSIGN VAR LIST VAR WHILE VAR NUMBER...
Barney lives in NYC. NYC has infinite number of intersections numbered with positive integers starting from 1. There exists a bidirectional road between intersections i and 2i and another road between i and 2i + 1 for every positive integer i. You can clearly see that there exists a unique shortest path between any two...
def way(v): A = [] while v: A.append(v) v //= 2 return A[::-1] def edges_between(u, v): A = way(u) B = way(v) i = 0 while i < min(len(A), len(B)) and A[i] == B[i]: i += 1 C = A[i - 1 :][::-1] + B[i:] D = [] for i in range(len(C) - 1): D.append((C...
FUNC_DEF ASSIGN VAR LIST WHILE VAR EXPR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN...
There is a classroom with two rows of computers. There are $n$ computers in each row and each computer has its own grade. Computers in the first row has grades $a_1, a_2, \dots, a_n$ and in the second row — $b_1, b_2, \dots, b_n$. Initially, all pairs of neighboring computers in each row are connected by wire (pairs $...
t = eval(input()) for i in range(t): n = eval(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) p = [] k = 1000000000000.0 for i in range(n): k = min(abs(a[0] - b[i]), k) p.append(k) k = 1000000000000.0 for i in range(n): k = min(abs(a[-...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL V...
There is a classroom with two rows of computers. There are $n$ computers in each row and each computer has its own grade. Computers in the first row has grades $a_1, a_2, \dots, a_n$ and in the second row — $b_1, b_2, \dots, b_n$. Initially, all pairs of neighboring computers in each row are connected by wire (pairs $...
import sys input = sys.stdin.readline def yes(): print("YES") def no(): print("NO") for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) ans = 10**10 ans = min(ans, abs(a[0] - b[0]) + abs(a[-1] - b[-1])) ans = min(a...
IMPORT ASSIGN VAR VAR FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIG...
There is a classroom with two rows of computers. There are $n$ computers in each row and each computer has its own grade. Computers in the first row has grades $a_1, a_2, \dots, a_n$ and in the second row — $b_1, b_2, \dots, b_n$. Initially, all pairs of neighboring computers in each row are connected by wire (pairs $...
R = lambda: [*map(int, input().split())] for _ in [0] * R()[0]: R() a = R() b = R() print( min( sum( min( abs(x[0] - y[0]), sum(min(abs(u[0] - z) for z in v) for u, v in ((x, y), (y, x))), ) for x...
ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR BIN_OP LIST NUMBER FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR...
There is a classroom with two rows of computers. There are $n$ computers in each row and each computer has its own grade. Computers in the first row has grades $a_1, a_2, \dots, a_n$ and in the second row — $b_1, b_2, \dots, b_n$. Initially, all pairs of neighboring computers in each row are connected by wire (pairs $...
tc_n = int(input()) def read_int_ln(): return [int(x) for x in input().split()] def c(x, y): return abs(x - y) def mc(x, arr): return min(abs(x - y) for y in arr) for tc in range(tc_n): n = int(input()) a = read_int_ln() b = read_int_ln() c0 = c(a[0], b[0]) c1 = c(a[-1], b[-1]) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_C...
There is a classroom with two rows of computers. There are $n$ computers in each row and each computer has its own grade. Computers in the first row has grades $a_1, a_2, \dots, a_n$ and in the second row — $b_1, b_2, \dots, b_n$. Initially, all pairs of neighboring computers in each row are connected by wire (pairs $...
INF = pow(10, 9) def best(arr, val): bst = INF + 10 pos = -1 for i in range(n): if bst > abs(val - arr[i]): bst = abs(val - arr[i]) pos = i return pos t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) b = list(map(int...
ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR...
There is a classroom with two rows of computers. There are $n$ computers in each row and each computer has its own grade. Computers in the first row has grades $a_1, a_2, \dots, a_n$ and in the second row — $b_1, b_2, \dots, b_n$. Initially, all pairs of neighboring computers in each row are connected by wire (pairs $...
INF = 10**9 + 1 def main_tc(): n = int(input()) a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] min_a_left = INF min_a_right = INF min_b_left = INF min_b_right = INF for elem in b: min_a_left = min(min_a_left, abs(a[0] - elem)) min_a_right = ...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF 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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL V...
There is a classroom with two rows of computers. There are $n$ computers in each row and each computer has its own grade. Computers in the first row has grades $a_1, a_2, \dots, a_n$ and in the second row — $b_1, b_2, \dots, b_n$. Initially, all pairs of neighboring computers in each row are connected by wire (pairs $...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) p, q, r, s = [10**9] * 4 for i in range(n): p = min(p, abs(a[0] - b[i])) q = min(q, abs(a[-1] - b[i])) r = min(r, abs(b[0] - a[i])) s = min(s, abs(b[...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR BIN_OP LIST BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN V...
There is a classroom with two rows of computers. There are $n$ computers in each row and each computer has its own grade. Computers in the first row has grades $a_1, a_2, \dots, a_n$ and in the second row — $b_1, b_2, \dots, b_n$. Initially, all pairs of neighboring computers in each row are connected by wire (pairs $...
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) mna0 = 10**9 mnan = 10**9 mnb0 = 10**9 mnbn = 10**9 for i in range(n): if abs(a[0] - b[i]) < mna0: mna0 = abs(a[0] - b[i]) if abs(a[n -...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP ...
There is a classroom with two rows of computers. There are $n$ computers in each row and each computer has its own grade. Computers in the first row has grades $a_1, a_2, \dots, a_n$ and in the second row — $b_1, b_2, \dots, b_n$. Initially, all pairs of neighboring computers in each row are connected by wire (pairs $...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) c1 = abs(a[0] - b[0]) c2 = abs(a[-1] - b[-1]) d1, d2, d3, d4 = [10**18] * 4 for i in range(n): d1 = min(d1, abs(b[i] - a[0])) d2 = min(d2, abs(a[-1] - b[i]))...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ...
There is a classroom with two rows of computers. There are $n$ computers in each row and each computer has its own grade. Computers in the first row has grades $a_1, a_2, \dots, a_n$ and in the second row — $b_1, b_2, \dots, b_n$. Initially, all pairs of neighboring computers in each row are connected by wire (pairs $...
def findmin(x, seq): t = 1000000000 for i in seq: if abs(x - i) < t: t = abs(x - i) choose = i return choose, t t = int(input()) for i in range(t): n = int(input()) a = list(map(int, input().split(" "))) b = list(map(int, input().split(" "))) ca0, xa0 = find...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRI...
There is a classroom with two rows of computers. There are $n$ computers in each row and each computer has its own grade. Computers in the first row has grades $a_1, a_2, \dots, a_n$ and in the second row — $b_1, b_2, \dots, b_n$. Initially, all pairs of neighboring computers in each row are connected by wire (pairs $...
for _ in range(int(input())): n = int(input()) l1 = list(map(int, input().strip().split())) l2 = list(map(int, input().strip().split())) lans = min( abs(l1[0] - l2[0]) + abs(l1[-1] - l2[-1]), abs(l1[0] - l2[-1]) + abs(l1[-1] - l2[0]), ) p1 = abs(l1[0] - l2[0]) p2 = abs(l1[-1]...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FU...
There is a classroom with two rows of computers. There are $n$ computers in each row and each computer has its own grade. Computers in the first row has grades $a_1, a_2, \dots, a_n$ and in the second row — $b_1, b_2, \dots, b_n$. Initially, all pairs of neighboring computers in each row are connected by wire (pairs $...
def solve_problem(): n = int(input()) for _ in range(n): _ = input() row1 = [int(i) for i in input().split()] row2 = [int(i) for i in input().split()] left1 = min(abs(row1[0] - j) for j in row2) left2 = min(abs(row2[0] - j) for j in row1) right1 = min(abs(row1[-1]...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR 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 FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR...
There is a classroom with two rows of computers. There are $n$ computers in each row and each computer has its own grade. Computers in the first row has grades $a_1, a_2, \dots, a_n$ and in the second row — $b_1, b_2, \dots, b_n$. Initially, all pairs of neighboring computers in each row are connected by wire (pairs $...
t = int(input()) while t: t -= 1 n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) a1 = a[0] a2 = a[-1] b1 = b[0] b2 = b[-1] y1 = 10000000000 y2 = 10000000000 y3 = abs(a[0] - b[0]) y4 = abs(a[-1] - b[0]) y5 = abs(a[0] - b[-1]) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER...
There is a classroom with two rows of computers. There are $n$ computers in each row and each computer has its own grade. Computers in the first row has grades $a_1, a_2, \dots, a_n$ and in the second row — $b_1, b_2, \dots, b_n$. Initially, all pairs of neighboring computers in each row are connected by wire (pairs $...
def main(): results = [] number_of_test_cases = int(input()) for _ in range(number_of_test_cases): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) minimum = min( abs(a[0] - b[0]) + abs(a[-1] - b[-1]), abs(a[0] - b[-1]) + ab...
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR ...
There is a classroom with two rows of computers. There are $n$ computers in each row and each computer has its own grade. Computers in the first row has grades $a_1, a_2, \dots, a_n$ and in the second row — $b_1, b_2, \dots, b_n$. Initially, all pairs of neighboring computers in each row are connected by wire (pairs $...
def calculate(arr_a, arr_b): out_a_1 = min(abs(x - arr_a[0]) for x in arr_b) out_a_2 = min(abs(x - arr_b[0]) for x in arr_a) out_b_1 = min(abs(x - arr_a[-1]) for x in arr_b) out_b_2 = min(abs(x - arr_b[-1]) for x in arr_a) return min(abs(arr_a[0] - arr_b[0]), out_a_1 + out_a_2) + min( abs(ar...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR RETURN BIN_OP FUNC_CALL VAR FUNC_CA...
There is a classroom with two rows of computers. There are $n$ computers in each row and each computer has its own grade. Computers in the first row has grades $a_1, a_2, \dots, a_n$ and in the second row — $b_1, b_2, \dots, b_n$. Initially, all pairs of neighboring computers in each row are connected by wire (pairs $...
import sys readline = sys.stdin.readline T = int(readline()) while T: T -= 1 length = int(readline()) a = [int(i) for i in readline().split()] b = [int(i) for i in readline().split()] a_begin = min(abs(a[0] - element) for element in b) a_end = min(abs(a[-1] - element) for element in b) b_be...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_...
There is a classroom with two rows of computers. There are $n$ computers in each row and each computer has its own grade. Computers in the first row has grades $a_1, a_2, \dots, a_n$ and in the second row — $b_1, b_2, \dots, b_n$. Initially, all pairs of neighboring computers in each row are connected by wire (pairs $...
import sys input = sys.stdin.readline def solve(n, A, B): ans = min( abs(A[0] - B[0]) + abs(A[-1] - B[-1]), abs(A[0] - B[-1]) + abs(A[-1] - B[0]) ) minA1, minB1 = min([abs(A[0] - b) for b in B]), min([abs(a - B[0]) for a in A]) minA2, minB2 = min([abs(A[-1] - b) for b in B]), min([abs(a - B[-...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_...
There is a classroom with two rows of computers. There are $n$ computers in each row and each computer has its own grade. Computers in the first row has grades $a_1, a_2, \dots, a_n$ and in the second row — $b_1, b_2, \dots, b_n$. Initially, all pairs of neighboring computers in each row are connected by wire (pairs $...
t = int(input()) while t: t = t - 1 n = int(input()) arr = list(map(int, input().split())) brr = list(map(int, input().split())) a = abs(arr[0] - brr[n - 1]) b = abs(arr[0] - brr[0]) d = abs(brr[n - 1] - arr[n - 1]) c = abs(brr[0] - arr[n - 1]) ans = min(a + c, b + d) ans = min(a...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSI...
There is a classroom with two rows of computers. There are $n$ computers in each row and each computer has its own grade. Computers in the first row has grades $a_1, a_2, \dots, a_n$ and in the second row — $b_1, b_2, \dots, b_n$. Initially, all pairs of neighboring computers in each row are connected by wire (pairs $...
def minfault(a, b): ans = min( abs(a[0] - b[0]) + abs(a[-1] - b[-1]), abs(a[0] - b[-1]) + abs(a[-1] - b[0]) ) n = len(a) res = [] for num in [a[0], a[-1]]: tmp = float("inf") for bi in b: tmp = min(tmp, abs(num - bi)) res.append(tmp) for num in [b[0], ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR LIST VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL...
There is a classroom with two rows of computers. There are $n$ computers in each row and each computer has its own grade. Computers in the first row has grades $a_1, a_2, \dots, a_n$ and in the second row — $b_1, b_2, \dots, b_n$. Initially, all pairs of neighboring computers in each row are connected by wire (pairs $...
t = int(input()) for k in range(t): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) mi_a_1 = 1e18 mi_a_n = 1e18 mi_b_1 = 1e18 mi_b_n = 1e18 for i in range(n): mi_a_1 = min(abs(a[0] - b[i]), mi_a_1) mi_a_n = min(abs(a[-1] - b[i]), m...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FU...
There is a classroom with two rows of computers. There are $n$ computers in each row and each computer has its own grade. Computers in the first row has grades $a_1, a_2, \dots, a_n$ and in the second row — $b_1, b_2, \dots, b_n$. Initially, all pairs of neighboring computers in each row are connected by wire (pairs $...
for i in [0] * int(input()): n = int(input()) a = [*map(int, input().split())] b = [*map(int, input().split())] x = min(abs(a[0] - i) for i in b) y = min(abs(a[n - 1] - b[i]) for i in range(n - 1, -1, -1)) z = min(abs(b[0] - i) for i in a) t = min(abs(b[n - 1] - a[i]) for i in range(n - 1, -...
FOR VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BI...
There is a classroom with two rows of computers. There are $n$ computers in each row and each computer has its own grade. Computers in the first row has grades $a_1, a_2, \dots, a_n$ and in the second row — $b_1, b_2, \dots, b_n$. Initially, all pairs of neighboring computers in each row are connected by wire (pairs $...
def solve_problem(): n = int(input()) for _ in range(n): nb_computers = int(input()) tmp = nb_computers - 1 row1 = [int(i) for i in input().split()] row2 = [int(i) for i in input().split()] result = 10000000000 left1 = min(abs(row1[0] - j) for j in row2) l...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER 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 FUNC_CALL VAR FUNC_CALL VAR BIN_OP ...
There is a classroom with two rows of computers. There are $n$ computers in each row and each computer has its own grade. Computers in the first row has grades $a_1, a_2, \dots, a_n$ and in the second row — $b_1, b_2, \dots, b_n$. Initially, all pairs of neighboring computers in each row are connected by wire (pairs $...
def findmin(A1, B): ans = abs(A1 - B[0]) for i in B: ans = min(ans, abs(A1 - i)) return ans def join(j1, j2, l1, l2): ans = abs(j1[0] - j2[0]) extra = min(abs(l1[0] - l2[0]), l1[1] + l2[1]) ans += extra return ans for iters in range(int(input())): n = int(input()) A = [in...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR RETURN VAR FOR ...
There is a classroom with two rows of computers. There are $n$ computers in each row and each computer has its own grade. Computers in the first row has grades $a_1, a_2, \dots, a_n$ and in the second row — $b_1, b_2, \dots, b_n$. Initially, all pairs of neighboring computers in each row are connected by wire (pairs $...
t = int(input()) for case in range(t): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) af = at = bf = bt = 0 for i in range(n): if abs(a[0] - b[af]) > abs(a[0] - b[i]): af = i if abs(a[-1] - b[at]) > abs(a[-1] - b[i]): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VA...
There is a classroom with two rows of computers. There are $n$ computers in each row and each computer has its own grade. Computers in the first row has grades $a_1, a_2, \dots, a_n$ and in the second row — $b_1, b_2, \dots, b_n$. Initially, all pairs of neighboring computers in each row are connected by wire (pairs $...
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) bi = [float("inf"), float("inf")] ai = [float("inf"), float("inf")] for i, k in enumerate(a): bi[0] = min(bi[0], abs(k - b[0])) bi[1] = min(bi[1], abs(k - ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR LIST FUNC_CAL...
There is a classroom with two rows of computers. There are $n$ computers in each row and each computer has its own grade. Computers in the first row has grades $a_1, a_2, \dots, a_n$ and in the second row — $b_1, b_2, \dots, b_n$. Initially, all pairs of neighboring computers in each row are connected by wire (pairs $...
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) m1 = 10**9 m2 = 10**9 p = a[0] q = a[-1] for i in range(len(b)): m1 = min(m1, abs(p - b[i])) m2 = min(m2, abs(q - b[i])) m3 = 10**9 m4 = 10**9 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR ...
There is a classroom with two rows of computers. There are $n$ computers in each row and each computer has its own grade. Computers in the first row has grades $a_1, a_2, \dots, a_n$ and in the second row — $b_1, b_2, \dots, b_n$. Initially, all pairs of neighboring computers in each row are connected by wire (pairs $...
t = int(input()) for i in range(t): n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) a1 = 1000000000 a2 = 1000000000 a3 = 1000000000 a4 = 1000000000 for i in range(n): a1 = min(abs(a[0] - b[i]), a1) a2 = min(abs(a[n - 1] - b[i]), a2...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FU...
There is a classroom with two rows of computers. There are $n$ computers in each row and each computer has its own grade. Computers in the first row has grades $a_1, a_2, \dots, a_n$ and in the second row — $b_1, b_2, \dots, b_n$. Initially, all pairs of neighboring computers in each row are connected by wire (pairs $...
import sys input = sys.stdin.readline N = int(input()) for i in range(N): n = int(input()) a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] m1 = min_cost_a_1 = min([abs(a[0] - b[i]) for i in range(n)]) m2 = min_cost_b_1 = min([abs(b[0] - a[i]) for i in range(n)]) m3 =...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CA...
There is a classroom with two rows of computers. There are $n$ computers in each row and each computer has its own grade. Computers in the first row has grades $a_1, a_2, \dots, a_n$ and in the second row — $b_1, b_2, \dots, b_n$. Initially, all pairs of neighboring computers in each row are connected by wire (pairs $...
def solve_problem(): for _ in range(int(input())): _ = input() row1 = [int(i) for i in input().split()] row2 = [int(i) for i in input().split()] r10 = row1[0] r20 = row2[0] r11 = row1[-1] r21 = row2[-1] diff0 = abs(r10 - r20) diff1 = abs(r11 - ...
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR 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 NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VA...
There is a classroom with two rows of computers. There are $n$ computers in each row and each computer has its own grade. Computers in the first row has grades $a_1, a_2, \dots, a_n$ and in the second row — $b_1, b_2, \dots, b_n$. Initially, all pairs of neighboring computers in each row are connected by wire (pairs $...
def md(a, b): mn = 999999999 for el in b: if abs(el - a) < mn: mn = abs(el - a) return mn t = int(input()) for i in range(t): n = int(input()) a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] f = abs(a[0] - b[0]) + abs(a[-1] - b[-1]) p = (...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP 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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ...
There is a classroom with two rows of computers. There are $n$ computers in each row and each computer has its own grade. Computers in the first row has grades $a_1, a_2, \dots, a_n$ and in the second row — $b_1, b_2, \dots, b_n$. Initially, all pairs of neighboring computers in each row are connected by wire (pairs $...
def find_best_index(ai, b): summr = 10**30 for j in range(len(b)): if abs(ai - b[j]) < summr: summr = abs(ai - b[j]) index = j return index def func(a, b, n): result = 10**30 List_1 = [0, find_best_index(a[0], b), n - 1] List_2 = [0, find_best_index(a[n - 1], b)...
FUNC_DEF ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR LIST NUMBER FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR LIST NU...
There is a classroom with two rows of computers. There are $n$ computers in each row and each computer has its own grade. Computers in the first row has grades $a_1, a_2, \dots, a_n$ and in the second row — $b_1, b_2, \dots, b_n$. Initially, all pairs of neighboring computers in each row are connected by wire (pairs $...
def best(A, i): return min([abs(i - j) for j in A]) def solv(A, B): a1, an = A[0], A[-1] b1, bn = B[0], B[-1] a1b = best(B, a1) anb = best(B, an) b1b = best(A, b1) bnb = best(A, bn) d11 = min(abs(a1 - b1), a1b + b1b) dnn = min(abs(an - bn), anb + bnb) d1n = min(abs(a1 - bn), a1...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR...