description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Consider a rat placed at (0, 0) in a square matrix of order N * N. It has to reach the destination at (N - 1, N - 1). Find all possible paths that the rat can take to reach from source to destination. The directions in which the rat can move are 'U'(up), 'D'(down), 'L' (left), 'R' (right). Value 0 at a cell in the matr...
class Solution: def path(self, i, j, path, res, grid, n, cache): if i == n - 1 and j == n - 1: res.append(path) return cache[i][j] = 1 if i + 1 < n and grid[i + 1][j] != 0 and cache[i + 1][j] != 1: self.path(i + 1, j, path + "D", res, grid, n, cache) ...
CLASS_DEF FUNC_DEF IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR STRING VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR ...
Consider a rat placed at (0, 0) in a square matrix of order N * N. It has to reach the destination at (N - 1, N - 1). Find all possible paths that the rat can take to reach from source to destination. The directions in which the rat can move are 'U'(up), 'D'(down), 'L' (left), 'R' (right). Value 0 at a cell in the matr...
class Solution: def findPath(self, m, n): self.res = [] if m[0][0] == 0: return [-1] def check(ans, i, j, mat, N): if i < 0 or i >= N or j < 0 or j >= N: return False if mat[i][j] == 0 or mat[i][j] == 2: return False ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST IF VAR NUMBER NUMBER NUMBER RETURN LIST NUMBER FUNC_DEF IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL V...
Consider a rat placed at (0, 0) in a square matrix of order N * N. It has to reach the destination at (N - 1, N - 1). Find all possible paths that the rat can take to reach from source to destination. The directions in which the rat can move are 'U'(up), 'D'(down), 'L' (left), 'R' (right). Value 0 at a cell in the matr...
class Solution: def findPath(self, m, n): ans, dir, dl = [], [[1, 0], [0, -1], [0, 1], [-1, 0]], ["D", "L", "R", "U"] def dfs(node, path): i, j = node if m[i][j] != 1: return if i == n - 1 and j == n - 1: ans.append(path) ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR LIST LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST STRING STRING STRING STRING FUNC_DEF ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER RETURN IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR VAR VAR NUMBER FOR...
Consider a rat placed at (0, 0) in a square matrix of order N * N. It has to reach the destination at (N - 1, N - 1). Find all possible paths that the rat can take to reach from source to destination. The directions in which the rat can move are 'U'(up), 'D'(down), 'L' (left), 'R' (right). Value 0 at a cell in the matr...
class Solution: def findPath(self, m, n): paths = [] moves = {"U": (-1, 0), "D": (1, 0), "L": (0, -1), "R": (0, 1)} def is_valid(row, col, m, n): if row >= n or row < 0 or col >= n or col < 0: return False elif m[row][col] == 0: retur...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR DICT STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL ...
Consider a rat placed at (0, 0) in a square matrix of order N * N. It has to reach the destination at (N - 1, N - 1). Find all possible paths that the rat can take to reach from source to destination. The directions in which the rat can move are 'U'(up), 'D'(down), 'L' (left), 'R' (right). Value 0 at a cell in the matr...
class Solution: def path(self, i, j, m, n, db, str): if i < 0 or j < 0 or i >= n or j >= n or m[i][j] == 0: return if i == n - 1 and j == n - 1: db.append(str) return m[i][j] = 0 self.path(i + 1, j, m, n, db, str + "D") self.path(i, j + 1,...
CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR STRING EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP ...
Consider a rat placed at (0, 0) in a square matrix of order N * N. It has to reach the destination at (N - 1, N - 1). Find all possible paths that the rat can take to reach from source to destination. The directions in which the rat can move are 'U'(up), 'D'(down), 'L' (left), 'R' (right). Value 0 at a cell in the matr...
class Solution: def findPath(self, m, n): all_solutions = [] paths = {"U": (-1, 0), "D": (1, 0), "R": (0, 1), "L": (0, -1)} def solution(x, y, current_path): if m[x][y] == 0: return -1 if x < 0 or y < 0 or x > n - 1 or y > n - 1: retu...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR DICT STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF IF VAR VAR VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN NUMBER IF VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_...
Consider a rat placed at (0, 0) in a square matrix of order N * N. It has to reach the destination at (N - 1, N - 1). Find all possible paths that the rat can take to reach from source to destination. The directions in which the rat can move are 'U'(up), 'D'(down), 'L' (left), 'R' (right). Value 0 at a cell in the matr...
def sol(row, col, n, mat, path, ans): if col == n - 1 and row == n - 1: ans.append(path) return ans last = "" if len(path) != 0: last = path[-1] if row != n - 1 and mat[row + 1][col] != 0 and mat[row + 1][col] > 0: mat[row + 1][col] = -1 ans = sol(row + 1, col, n,...
FUNC_DEF IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP...
Consider a rat placed at (0, 0) in a square matrix of order N * N. It has to reach the destination at (N - 1, N - 1). Find all possible paths that the rat can take to reach from source to destination. The directions in which the rat can move are 'U'(up), 'D'(down), 'L' (left), 'R' (right). Value 0 at a cell in the matr...
class Solution: def findPath(self, m, n): vis = [([0] * n) for i in range(n)] def dfs(i, j, vis, s, m): if i == n - 1 and j == n - 1: if m[i][j] == 1: ans.append(s) return if 0 <= i < n and 0 <= j < n and vis[i][j] == 0 an...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN IF NUMBER VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR...
Consider a rat placed at (0, 0) in a square matrix of order N * N. It has to reach the destination at (N - 1, N - 1). Find all possible paths that the rat can take to reach from source to destination. The directions in which the rat can move are 'U'(up), 'D'(down), 'L' (left), 'R' (right). Value 0 at a cell in the matr...
class Solution: def setup(self): global v v = [[(0) for i in range(100)] for j in range(100)] global ans ans = [] def path(self, arr, x, y, pth, n): if x == n - 1 and y == n - 1: global ans ans.append(pth) return global v ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FUNC_DEF IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VA...
Consider a rat placed at (0, 0) in a square matrix of order N * N. It has to reach the destination at (N - 1, N - 1). Find all possible paths that the rat can take to reach from source to destination. The directions in which the rat can move are 'U'(up), 'D'(down), 'L' (left), 'R' (right). Value 0 at a cell in the matr...
class Solution: def findPath(self, m, n): res = [] vis = [([0] * n) for i in range(n)] s = "" if m[0][0] == 0 or m[n - 1][n - 1] == 0: return res def dfs(r, c, vis, s): if r == n - 1 and c == n - 1: res.append(s) retur...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING IF VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER RETURN VAR FUNC_DEF IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN IF VAR NUMBER VAR NUMBER VAR VAR VAR VA...
Consider a rat placed at (0, 0) in a square matrix of order N * N. It has to reach the destination at (N - 1, N - 1). Find all possible paths that the rat can take to reach from source to destination. The directions in which the rat can move are 'U'(up), 'D'(down), 'L' (left), 'R' (right). Value 0 at a cell in the matr...
class Solution: def findPath(self, m, n): res = [] path = "" visited = [[(0) for _ in range(n)] for _ in range(n)] if m[0][0] == 0 or m[n - 1][n - 1] == 0: return res def fp(i, j, path): if i == n - 1 and j == n - 1: res.append(path) ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER RETURN VAR FUNC_DEF IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN IF BIN_OP VAR NUMBER VAR VAR BIN_...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
s1, s2 = input(), input() len1, len2 = len(s1), len(s2) t, res = "", 0 for i, x in enumerate(s1): t += x if len1 % (i + 1) == 0 and len2 % (i + 1) == 0: x1, x2 = len1 // (i + 1), len2 // (i + 1) if t * x1 == s1 and t * x2 == s2: res += 1 print(res)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR STRING NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER IF BIN_OP V...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
s = input() t = input() m = len(s) n = len(t) ans = 0 for i in range(1, min(m, n) + 1): if m % i > 0 or n % i > 0: continue p = s[:i] if p * (m // i) == s and p * (n // i) == t: ans += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR ...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
s1, s2 = sorted([input() for i in range(2)], key=lambda x: len(x)) l1, l2, r = len(s1), len(s2), 0 for i in range(1, l1 + 1): if l1 % i == 0 and l2 % i == 0: c1, c2 = int(l1 / i), int(l2 / i) if c1 * s1[:i] == s1 and c2 * s1[:i] == s2: r += 1 print(r)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR IF BI...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
def fs(k): init = k if s1[:k] != s2[:k]: return False while init <= l1 - k: if s1[:k] != s1[init : init + k]: return False init += k init = k while init <= l2 - k: if s2[:k] != s2[init : init + k]: return False init += k return True...
FUNC_DEF ASSIGN VAR VAR IF VAR VAR VAR VAR RETURN NUMBER WHILE VAR BIN_OP VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR RETURN NUMBER VAR VAR ASSIGN VAR VAR WHILE VAR BIN_OP VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR RETURN NUMBER VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSI...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
s1 = input() s2 = input() a = [] b = [] s = "" for i in range(len(s1)): s += s1[i] x = len(s1) // (i + 1) if s * x == s1: a.append(s) s = "" for i in range(len(s2)): s += s2[i] x = len(s2) // (i + 1) if s * x == s2: b.append(s) cnt = 0 for i in range(len(a)): for j in range(l...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
def gcd(a, b): if b == 0: return a return gcd(b, a % b) s1 = input() s2 = input() c = 0 g = gcd(len(s1), len(s2)) i = 1 while i * i <= g: if g % i == 0: if s1[:i] == s2[:i]: if s1[:i] * (len(s1) // i) == s1: if s2[:i] * (len(s2) // i) == s2: ...
FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR IF BIN_OP VAR VAR BIN_OP FUNC_...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
s = input() s1 = input() if len(s) < len(s1): s1, s = s, s1 q = 499 p = int(100000000000.0 + 7) n = len(s) hs = [0] * (n + 1) pw = [1] * (n + 1) for i in range(n): hs[i + 1] = (hs[i] * q + ord(s[i])) % p pw[i + 1] = pw[i] * q % p def get_hash(a, b): return (hs[b] - hs[a] * pw[b - a] % p + p) % p h1 ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL V...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
def getDivs(s): n = len(s) ret = {s} size = 1 while size * size <= n: if n % size == 0: sub1 = s[:size] sub2 = s[: n // size] if sub1 * (n // size) == s: ret.add(sub1) if sub2 * size == s: ret.add(sub2) size ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR IF BIN_OP VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR AS...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
s1 = input() s2 = input() l1 = len(s1) l2 = len(s2) s = "" l = 0 ans = 0 for i in s1: s = s + i l = l + 1 if l1 % l == 0 and l2 % l == 0: if s * int(l1 / l) == s1: if s * int(l2 / l) == s2: ans += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR V...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
sa = input() sb = input() a = len(sa) b = len(sb) if a > b: sa, sb = sb, sa a, b = b, a l = 0 ss = "" s = set() for i in sa: ss += str(i) l += 1 if b % l == 0 and sb == ss * (b // l): if a % l == 0 and sa == ss * (a // l): s.add(ss) print(len(s))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VA...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
def Divisors(a, l1, l2): i = 1 while i <= min(l1, l2): if l1 % i == 0 and l2 % i == 0: a.append(i) i = i + 1 s1 = input() s2 = input() l1, l2 = len(s1), len(s2) a = [] Divisors(a, l1, l2) ss1, ss2, c = "", "", 0 for i in range(len(a)): ss1 = s1[: a[i]] * (l1 // a[i]) ss2 = ...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
s = input() s1 = input() n = len(s) m = len(s1) if n > m: a = m b = n p = s1 q = s else: a = n b = m p = s q = s1 s2 = "" d = 0 for x in range(0, a): s2 = s2 + p[x] if a % 2 != 0 and (x + 1) % 2 == 0: continue if a % (x + 1) != 0: continue if s2 * (a // (x...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR B...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
a = input().strip() b = input().strip() divisor = 0 temp = "" lena = len(a) lenb = len(b) for i in range(lena): temp += a[i] if temp == b[: i + 1]: if lenb // (i + 1) * temp == b and lena // (i + 1) * temp == a: divisor += 1 print(divisor)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VA...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
s1 = input() s2 = input() l1 = len(s1) l2 = len(s2) d = {} c = 0 if l1 <= l2: s = s1 a = s2 l = l1 k = l2 else: s = s2 a = s1 l = l2 k = l1 d[s] = l for i in range(1, l // 2 + 1): if s[0] == s[i]: if s[:i] * (l // i) == s: d[s[:i]] = i for i in d: if k % d[i] ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
def z_func(s): l = 0 r = 0 n = len(s) z = [0] * n z[0] = n for i in range(1, n): if i <= r: z[i] = min(r - i + 1, z[i - l]) while i + z[i] < n and s[z[i]] == s[i + z[i]]: z[i] += 1 if i + z[i] - 1 > r: l = i r = i + z[i] - 1...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR WHILE BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR V...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
s1 = input().strip() s2 = input().strip() n1 = len(s1) n2 = len(s2) res = 0 for i in range(1, min(n1, n2) + 1): if n1 % i == 0 and n2 % i == 0: check = True for j in range(i, n1): if s1[j % i] != s1[j]: check = False break for j in range(0, n2): ...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN 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 NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP ...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
def divisors(s): n = len(s) d = 1 res = set() while d * d <= n: if n % d == 0: ds = [d, n // d] if d * d < n else [d] for k in ds: ok = True for i in range(k, n): if s[i] != s[i % k]: ok = False ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR WHILE BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR LIST VAR BIN_OP VAR VAR LIST VAR FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_C...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
s1 = input() s2 = input() ss1 = set() ss2 = set() l1 = len(s1) l2 = len(s2) for i in range(l1): if l1 % (i + 1) == 0: x = l1 // (i + 1) str = s1[: i + 1] str = str * x if str == s1: ss1.add(s1[: i + 1]) for i in range(l2): if l2 % (i + 1) == 0: x = l2 // (i + ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VA...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
s1 = input() s2 = input() n1 = len(s1) n2 = len(s2) ans = 0 if n1 <= n2: for i in range(n1): if n1 % (i + 1) == 0 and s1[: i + 1] * (n1 // (i + 1)) == s1: if n2 % (i + 1) == 0 and s1[: i + 1] * (n2 // (i + 1)) == s2: ans = ans + 1 else: for i in range(n2): x = s2[0 : ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
def divisors(n): res = set() d = 1 while d * d <= n: if n % d == 0: res.add(d) res.add(n // d) d += 1 return res def common_divisors(s1, s2): divs = divisors(len(s1)) & divisors(len(s2)) res = 0 for d in divs: if all(s1[i] == s1[i % d] for i ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR V...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
MOD = 1000000007 ii = lambda: int(input()) si = lambda: input() dgl = lambda: list(map(int, input())) f = lambda: map(int, input().split()) il = lambda: list(map(int, input().split())) ls = lambda: list(input()) s1 = si() s2 = si() ls1 = len(s1) ls2 = len(s2) if ls1 > ls2: s1, s2 = s2, s1 ls1, ls2 = ls2, ls1 c ...
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN 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 ASSIGN VAR FUNC_CALL V...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
def gcd(a, b): c = a % b return gcd(b, c) if c else b a, b = input(), input() u, v = len(a), len(b) if u > v: a, b, u, v = b, a, v, u if a == a[0] * u: d = 1 else: for i in range(1, int(u**0.5) + 1): if u % i == 0: k = u // i if a == a[:i] * k: d = i...
FUNC_DEF ASSIGN VAR BIN_OP VAR VAR RETURN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP ...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
a = input() b = input() al, bl = len(a), len(b) l = min(al, bl) c = 0 for i in range(l): if al % (i + 1) == 0 and bl % (i + 1) == 0: if a[: i + 1] * (al // (i + 1)) == a and a[: i + 1] * (bl // (i + 1)) == b: c += 1 print(c)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BI...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
a, b = input(), input() n, m = len(a), len(b) s = "" k = c = 0 if m > n: a, b, n, m = b, a, m, n for ch in a: k += 1 s += ch if n // k * s == a and m // k * s == b: c += 1 print(c)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR VAR VAR NUMBER VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
s1 = input() s2 = input() def divisors(s): n = len(s) div = set() for i in range(1, n + 1): if n % i == 0 and all(s[:i] == s[j : j + i] for j in range(i, n, i)): div.add(s[:i]) return div a = divisors(s1) b = divisors(s2) print(len(a & b))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL V...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
def L(a, b): a, b = int(a), int(b) a, b = max(a, b), min(a, b) if b == 0: return a return L(a % b, b) a, b = input(), input() la, lb = len(a), len(b) c = L(la, lb) if a != la // c * a[:c] or b != lb // c * b[:c] or a[:c] != b[:c]: print("0") exit() else: s = a[:c] res = 0 f...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR BI...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
s1 = input() s2 = input() d1 = set([s1]) d2 = set([s2]) s = "" for c in s1[: len(s1) // 2]: s += c if len(s1) % len(s) == 0: if s * (len(s1) // len(s)) == s1: d1.add(s) else: pass s = "" for c in s2[: len(s2) // 2]: s += c if len(s2) % len(s) == 0: if s * (len(s2)...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR LIST VAR ASSIGN VAR FUNC_CALL VAR LIST VAR ASSIGN VAR STRING FOR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
s = input() r = input() n, m = len(s), len(r) if n > m: s, r = r, s n, m = m, n k = "" c = 0 l = 0 for i in range(1, n // 2 + 1): c = c + 1 k = s[:i] x = m // c y = n // c if n % c == 0 and m % c == 0: if k * x == r and k * y == s: l += 1 if m % n == 0 and s * (m // n) ==...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
s1 = input() s2 = input() sub1 = set() p = "" for i in s1: p += i if p * (len(s1) // len(p)) == s1: sub1.add(p) p = "" sub2 = set() for i in s2: p += i if p * (len(s2) // len(p)) == s2: sub2.add(p) print(len(sub1 & sub2))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR VAR VAR VAR IF BIN_OP VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR VAR IF BIN_OP VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
def z_func(s): l = 0 r = 0 n = len(s) z = [0] * n z[0] = n for i in range(1, n): if i <= r: z[i] = min(r - i + 1, z[i - l]) while i + z[i] < n and s[z[i]] == s[i + z[i]]: z[i] += 1 if i + z[i] - 1 > r: l = i r = i + z[i] - 1...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR WHILE BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR V...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
a = input() b = input() n = len(a) k = len(b) m = 0 if n > k: for i in range(1, k + 1): if n % i == 0 and k % i == 0: if b[:i] * (n // i) == a and b[:i] * (k // i) == b: m += 1 else: for i in range(1, n + 1): if n % i == 0 and k % i == 0: if a[:i] * (n // ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR NUMBER FOR VAR...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
def ii(): return int(input()) def si(): return input() def mi(): return map(int, input().split()) def li(): return list(mi()) a = si() b = si() n1 = len(a) n2 = len(b) ans = 0 for i in range(1, min(n1, n2) + 1): if n1 % i == 0 and n2 % i == 0: f = 1 f1 = 0 for j in ra...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL ...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
s1 = input() s2 = input() if len(s1) < len(s2): s3 = s1 s1 = s2 s2 = s3 n1 = len(s1) n2 = len(s2) divs = list() for i in range(1, n1 + 1): if n1 % i != 0: continue grps = n1 // i substring = s1[:i] if substring * grps == s1: if n2 % i == 0: grps2 = n2 // i ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIG...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
def no_of_div(s): n = len(s) divisors = [s] for i in range(2, n + 1): d = n // i if d * i == n and s[0:d] * i == s: divisors.append(s[0:d]) return divisors s1 = input() s2 = input() print(len(set(no_of_div(s1)).intersection(no_of_div(s2))))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
s = input() t = input() d = set() c = 0 for x in range(1, len(s) + 1): if len(s) % x == 0: if s == s[:x] * (len(s) // x): d.add(s[:x]) for x in range(1, len(t) + 1): if len(t) % x == 0: if t == t[:x] * (len(t) // x): if t[:x] in d: c += 1 print(c)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
def getDivisors(s, d): i = 1 n = len(s) while n / i >= 1: if n % i == 0: div = s[0:i] start = i while start < n: if div != s[start : start + i]: break start += i if start == n: d.add(d...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VA...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
def check(s, j): for i in range(j + 1): if s[i] != s[j + i]: return False return True s1 = input() s2 = input() x = [] i = 1 n = len(s1) n2 = len(s2) res = 0 while i <= n: if n % i == 0: if s1 == s1[:i] * (n // i) and s2 == s1[:i] * (n2 // i): res += 1 i += 1 pr...
FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP ...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
def gfg(s1, s2): count = 0 n = len(s1) ans = [] for i in range(n): if n % (i + 1) == 0: if s1.count(s1[: i + 1]) * (i + 1) == n: ans.append(s1[: i + 1]) m = len(s2) for i in range(m): if m % (i + 1) == 0: if s2.count(s2[: i + 1]) * (i + 1) ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_O...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
a = input() b = input() i = 1 count = 0 while i <= len(a): l = len(a) / len(a[:i]) if int(l) == l: if a[:i] * int(l) == a: l = len(b) / len(a[:i]) if int(l) == l: if a[:i] * int(l) == b: count += 1 i += 1 print(count)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR ...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
from sys import stdin, stdout def equalsubstr1(l1, r1, l2, r2): return first[l1 : r1 + 1] == first[l2 : r2 + 1] def equalsubstr2(l1, r1, l2, r2): return second[l1 : r1 + 1] == first[l2 : r2 + 1] first = stdin.readline().strip() second = stdin.readline().strip() if len(first) != len(second): first, sec...
FUNC_DEF RETURN VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER FUNC_DEF RETURN VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VA...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
str1 = input() str2 = input() found = {} for i in range(1, len(str1) + 1): if len(str1) % i == 0: times = len(str1) // i if times * str1[0:i] == str1: found[str1[0:i]] = 1 for elem in found: times = len(str2) // len(elem) if times * elem == str2: found[elem] += 1 suma = 0...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR ...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
a = input() b = input() l1 = len(a) l2 = len(b) if l1 > l2: a, b = b, a l1, l2 = l2, l1 ans = 0 for i in range(1, l1 + 1): if l1 % i == 0 and l2 % i == 0: div = a[:i] _a = div * (l1 // i) _b = div * (l2 // i) if _a == a and _b == b: ans += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR BI...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
s1, s2 = input(), input() m = min(len(s1), len(s2)) if s1[:m] != s2[:m]: print(0) else: if s1 < s2: s1, s2 = s2, s1 sm = s1[:m] ans = 0 for i in range(1, m + 1): if m % i == 0: x = len(s1) // i if sm[:i] * x == s1: ans += 1 print(ans)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL ...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
from sys import stdin, stdout def gethash(l, r, label): if not label: return (hsh1[r] - hsh1[l - 1] * power[r - l + 1]) % MOD else: return (hsh2[r] - hsh2[l - 1] * power[r - l + 1]) % MOD def equalsubstr1(l1, r1, l2, r2): return gethash(l1, r1, 0) == gethash(l2, r2, 0) def equalsubstr2...
FUNC_DEF IF VAR RETURN BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR RETURN BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR VAR NU...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
a = input() b = input() if len(b) <= len(a): a, b = b, a z = [] for j in range(1, len(a) + 1): if len(a) % j == 0 and len(b) % j == 0: z.append(j) c = "" d = 0 for i in z: c = a[0:i] if a.count(c) == len(a) / len(c) and b.count(c) == len(b) / len(c): d = d + 1 print(d)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMB...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
s1 = input() s2 = input() n = len(s1) m = len(s2) if n > m: s1, s2 = s2, s1 n, m = m, n l = [] ll = [] for i in range(1, n + 1): if n % i == 0: d = s1[:i] if d * (n // i) == s1: l.append(d) for i in range(len(l)): f = len(l[i]) if m % f == 0: if l[i] * (m // f) ==...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR BIN_OP VAR VAR VAR...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
s1 = input() s2 = input() ans = 0 if len(s1) > len(s2): temp = s1 s1 = s2 s2 = temp for i in range(len(s1)): if len(s2) % (i + 1) != 0 or len(s1) % (i + 1) != 0: continue x = len(s1) // (i + 1) y = len(s2) // (i + 1) if s1[: i + 1] * x == s1 and s1[: i + 1] * y == s2: ans += ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CA...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
str1 = input() str2 = input() set1 = set() set2 = set() m = len(str1) n = len(str2) for i in range(1, len(str1) + 1): if m % len(str1[:i]) == 0: k = m // len(str1[:i]) if str1 == k * str1[:i]: set1.add(str1[:i]) for i in range(1, len(str2) + 1): if n % len(str2[:i]) == 0: k =...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP ...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
a = input() b = input() al, bl = len(a), len(b) n = min(al, bl) ans = 0 lt = [] for i in range(1, n + 1): if al % i == 0 and bl % i == 0: lt.append(i) for c in lt: if a[:c] * (al // c) == a and b[:c] * (bl // c) == b and a[:c] == b[:c]: ans += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP VAR VAR BIN_O...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
def main(): s1 = input() s2 = input() m = max(len(s1), len(s2)) n = min(min(len(s1), len(s2)), m // 2) ans = 0 for i in range(0, n): x = len(s1) // len(s1[: i + 1]) y = len(s2) // len(s1[: i + 1]) if s1[: i + 1] * x == s1 and s1[: i + 1] * y == s2: ans = ans +...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR BI...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
s1, s2 = input(), input() L1, L2 = len(s1), len(s2) D = set() for d in range(1, int(L1**0.5) + 1): if L1 % d == 0: D |= {d, L1 // d} S = [s1[:d] for d in D if s1[:d] * (L1 // d) == s1] print(sum(s * (L2 // len(s)) == s2 for s in S))
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VA...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
a, b = input(), input() p, o, q, w, r, t = len(a), len(b), "", "", {0}, {0} for i in range(p): q += a[i] if q * (p // (i + 1)) == a: r.add(q) for i in range(o): w += b[i] if w * (o // (i + 1)) == b: t.add(w) print(len(t & r) - 1)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR STRING STRING NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR BIN_OP VAR BIN_OP VAR ...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
from sys import stdin, stdout def get(): return stdin.readline().strip() def getf(): return [int(i) for i in get().split()] def put(a, end="\n"): stdout.write(str(a) + end) def putf(a, sep=" ", end="\n"): stdout.write(sep.join(map(str, a)) + end) def divs(s, n): an = [] for x in range(...
FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_DEF STRING STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR ...
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String a is the divisor of string b if and only if there exists a positive integer x such that if we write out string a consecutively x times, we get string b. For example, string ...
def is_div(s1, s2): s = s2 while len(s) < len(s1): s += s2 if s == s1: return True else: return False a = input() b = input() for i in range(1, len(a) + 1): if len(a) % i != 0: continue if is_div(a, a[:i]): root_a = a[:i] break for i in range(1, ...
FUNC_DEF ASSIGN VAR VAR WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR F...
On a number line there are n balls. At time moment 0 for each ball the following data is known: its coordinate xi, speed vi (possibly, negative) and weight mi. The radius of the balls can be ignored. The balls collide elastically, i.e. if two balls weighing m1 and m2 and with speeds v1 and v2 collide, their new speeds...
n, t = map(int, input().split()) ar = [] for _ in range(n): ar.append(list(map(int, input().split()))) cur = 0 while True: T = float("inf") nums = [] for i in range(n): for j in range(i): vd = ar[i][1] - ar[j][1] xd = ar[i][0] - ar[j][0] xd = -xd i...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_...
On a number line there are n balls. At time moment 0 for each ball the following data is known: its coordinate xi, speed vi (possibly, negative) and weight mi. The radius of the balls can be ignored. The balls collide elastically, i.e. if two balls weighing m1 and m2 and with speeds v1 and v2 collide, their new speeds...
class Ball: def __init__(self, x, v, m): self.v = v self.x = x self.m = m def move(self, time): self.x += self.v * time def collisionTime(self, other): if self.v == other.v: return float("inf") t = -(self.x - other.x) / (self.v - other.v) ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF VAR BIN_OP VAR VAR FUNC_DEF IF VAR VAR RETURN FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR IF VAR NUMBER RETURN FUNC_CALL VAR STRING RETURN VAR FUNC_DEF RETURN FUNC_CALL STRING VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ...
Karen has just arrived at school, and she has a math test today! <image> The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. So, they just put one question in the test that is worth all the points. Th...
n = int(input()) p = list(map(int, input().split())) MOD = 10**9 + 7 mode = 0 if n % 4 == 3: n -= 1 new = [] for i in range(n): if mode == 0: new.append(p[i] + p[i + 1]) else: new.append(p[i] - p[i + 1]) mode = 1 - mode p = new def calc0(p): res = 0 ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER...
Karen has just arrived at school, and she has a math test today! <image> The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. So, they just put one question in the test that is worth all the points. Th...
from sys import stdin, stdout def main(): N = 400005 MOD = 10**9 + 7 fact = [1] + [(i + 1) for i in range(N)] for i in range(1, N + 1): fact[i] *= fact[i - 1] fact[i] %= MOD def inv(n): return pow(n, MOD - 2, MOD) def simplex(n, k): if n == 0: retu...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF IF VAR NUMBER RETURN NU...
We define the following: A subarray of array $a$ of length $n$ is a contiguous segment from $a[i]$ through $a[j]$ where $0\leq i\leq j<n.$. The sum of an array is the sum of its elements. Given an $n$ element array of integers, $a$, and an integer, $m$, determine the maximum value of the sum of any of its subarrays m...
import sys q = int(input()) for _ in range(q): n, m = [int(x) for x in input().split()] a_arr = [(int(x) % m) for x in input().split()] for i in range(1, len(a_arr)): a_arr[i] = (a_arr[i - 1] + a_arr[i]) % m a_arr = sorted([(x, i) for i, x in enumerate(a_arr)], key=lambda x: x[0]) max_sum =...
IMPORT 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 BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VA...
We define the following: A subarray of array $a$ of length $n$ is a contiguous segment from $a[i]$ through $a[j]$ where $0\leq i\leq j<n.$. The sum of an array is the sum of its elements. Given an $n$ element array of integers, $a$, and an integer, $m$, determine the maximum value of the sum of any of its subarrays m...
class MaximizeSum: def __init__(self): _, self.mod = get_int_list(input()) str_input = input() self.values = [] self.cum_sums = [] self.running_max = 0 for i, val in enumerate(str_input.strip().split()): val_int = int(val) % self.mod self.valu...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR V...
We define the following: A subarray of array $a$ of length $n$ is a contiguous segment from $a[i]$ through $a[j]$ where $0\leq i\leq j<n.$. The sum of an array is the sum of its elements. Given an $n$ element array of integers, $a$, and an integer, $m$, determine the maximum value of the sum of any of its subarrays m...
def fast_max(arr, m, arr_len): maxx = 0 cumu = 0 cumu_mo = [] for i in range(arr_len): cumu += arr[i] n = cumu % m cumu_mo.append(n) if n > maxx: maxx = n idx_arr = sorted(range(len(cumu_mo)), key=lambda k: cumu_mo[k]) min_diff = m for i in range(l...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR B...
We define the following: A subarray of array $a$ of length $n$ is a contiguous segment from $a[i]$ through $a[j]$ where $0\leq i\leq j<n.$. The sum of an array is the sum of its elements. Given an $n$ element array of integers, $a$, and an integer, $m$, determine the maximum value of the sum of any of its subarrays m...
t = int(input()) for _ in range(t): n, mod = map(int, input().split()) x = input().split() value = [] index = [] temp = 0 for i in range(n): temp += int(x[i]) value.append(temp % mod) index.append(i + 1) aa = [] for x in zip(*sorted(zip(value, index))): aa...
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 LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP V...
We define the following: A subarray of array $a$ of length $n$ is a contiguous segment from $a[i]$ through $a[j]$ where $0\leq i\leq j<n.$. The sum of an array is the sum of its elements. Given an $n$ element array of integers, $a$, and an integer, $m$, determine the maximum value of the sum of any of its subarrays m...
def f(array, m): partial_sums = [0] total = 0 for n in array: total = (total + n) % m partial_sums.append(total) partial_sums = [(x, i) for i, x in enumerate(partial_sums)] partial_sums.sort() last_n, last_i = partial_sums[0] maximum = 0 for x, i in partial_sums + partial...
FUNC_DEF ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BI...
We define the following: A subarray of array $a$ of length $n$ is a contiguous segment from $a[i]$ through $a[j]$ where $0\leq i\leq j<n.$. The sum of an array is the sum of its elements. Given an $n$ element array of integers, $a$, and an integer, $m$, determine the maximum value of the sum of any of its subarrays m...
T = int(input()) for T_i in range(T): n, m = [int(x) for x in input().split()] l = [(int(x) % m) for x in input().split()] sums = [l[0] % m] for i in range(1, n): sums.append((sums[i - 1] + l[i]) % m) result = max(sums) sumsx = {} for i in range(n): if not sumsx.__contains__(...
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 BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER ...
We define the following: A subarray of array $a$ of length $n$ is a contiguous segment from $a[i]$ through $a[j]$ where $0\leq i\leq j<n.$. The sum of an array is the sum of its elements. Given an $n$ element array of integers, $a$, and an integer, $m$, determine the maximum value of the sum of any of its subarrays m...
def smallest_bigger_int(A, x): low = 0 high = len(A) - 1 while low < high: mid = int((low + high) / 2) if A[mid] <= x: low = mid + 1 elif A[mid] > x: high = mid return A[low] def max_diff(B, N, M): if N == 1: return B[0] elif N <= 0: ...
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR RETURN VAR VAR FUNC_DEF IF VAR NUMBER RETURN VAR NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR...
We define the following: A subarray of array $a$ of length $n$ is a contiguous segment from $a[i]$ through $a[j]$ where $0\leq i\leq j<n.$. The sum of an array is the sum of its elements. Given an $n$ element array of integers, $a$, and an integer, $m$, determine the maximum value of the sum of any of its subarrays m...
def mod_M(x, M): return x - M * (x // M) t = int(input("")) for each in range(t): N, M = input("").split() N, M = int(N), int(M) s = [(0, 0) for i in range(N + 1)] inp = input("").split() inp = [int(num) for num in inp] for i in range(1, N + 1): s[i] = mod_M(s[i - 1][0] + inp[i - 1...
FUNC_DEF RETURN BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ST...
We define the following: A subarray of array $a$ of length $n$ is a contiguous segment from $a[i]$ through $a[j]$ where $0\leq i\leq j<n.$. The sum of an array is the sum of its elements. Given an $n$ element array of integers, $a$, and an integer, $m$, determine the maximum value of the sum of any of its subarrays m...
t = int(input()) for i in range(t): n, m = list(map(int, input().split())) ar = list(map(int, input().split())) prefix_sum = [] tem = 0 max_i = 0 l = len(ar) for j in range(l): prefix_sum.append(tem + ar[j]) tem = tem + ar[j] ps = [] for j in range(l): prefix_...
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 LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_...
We define the following: A subarray of array $a$ of length $n$ is a contiguous segment from $a[i]$ through $a[j]$ where $0\leq i\leq j<n.$. The sum of an array is the sum of its elements. Given an $n$ element array of integers, $a$, and an integer, $m$, determine the maximum value of the sum of any of its subarrays m...
T = int(input()) for _ in range(T): NM = [int(x) for x in input().split()] N, M = NM[0], NM[1] A = [int(x) for x in input().split()] prefixSums = [(0, 0)] * len(A) for i in range(len(A)): prefixSums[i] = (prefixSums[i - 1][0] + A[i]) % M, i prefixSums.append((0, -1)) prefixSums.appen...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VA...
We define the following: A subarray of array $a$ of length $n$ is a contiguous segment from $a[i]$ through $a[j]$ where $0\leq i\leq j<n.$. The sum of an array is the sum of its elements. Given an $n$ element array of integers, $a$, and an integer, $m$, determine the maximum value of the sum of any of its subarrays m...
for _ in range(int(input())): n, m = map(int, input().split()) raw = map(int, input().split()) prefix = [0] for num in raw: prefix.append((prefix[-1] + num % m) % m) res = max(prefix) increase = sorted((prefix[i], i) for i in range(1, n + 1)) for i in range(n - 1): if increas...
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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ...
We define the following: A subarray of array $a$ of length $n$ is a contiguous segment from $a[i]$ through $a[j]$ where $0\leq i\leq j<n.$. The sum of an array is the sum of its elements. Given an $n$ element array of integers, $a$, and an integer, $m$, determine the maximum value of the sum of any of its subarrays m...
from itertools import accumulate for q in range(int(input().strip())): n, m = (int(s) for s in input().strip().split(" ")) I = [int(s) for s in input().strip().split(" ")] A = [(x % m, i) for i, x in enumerate(accumulate(I))] A.sort() out = A[-1][0] for i in range(n - 1): j = 1 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMB...
We define the following: A subarray of array $a$ of length $n$ is a contiguous segment from $a[i]$ through $a[j]$ where $0\leq i\leq j<n.$. The sum of an array is the sum of its elements. Given an $n$ element array of integers, $a$, and an integer, $m$, determine the maximum value of the sum of any of its subarrays m...
import sys n = int(input().strip()) for _ in range(n): size, mod = [int(val) for val in input().strip().split(" ")] arr = [int(val) for val in input().strip().split(" ")] sums = [-1] * size temp = [-1] * 2 temp[0] = arr[0] % mod temp[1] = 0 sums[0] = temp for pos in range(1, size): ...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMB...
We define the following: A subarray of array $a$ of length $n$ is a contiguous segment from $a[i]$ through $a[j]$ where $0\leq i\leq j<n.$. The sum of an array is the sum of its elements. Given an $n$ element array of integers, $a$, and an integer, $m$, determine the maximum value of the sum of any of its subarrays m...
t = int(input()) size = [None] * t mod = [None] * t result = [None] * t for i in range(t): n_m = input() n_m = n_m.split() size[i] = int(n_m[0]) mod[i] = int(n_m[1]) arr = input() arr = arr.split() arr = [int(x) for x in arr] prefix_arr = [] current = result[i] = 0 for j, x in en...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSI...
We define the following: A subarray of array $a$ of length $n$ is a contiguous segment from $a[i]$ through $a[j]$ where $0\leq i\leq j<n.$. The sum of an array is the sum of its elements. Given an $n$ element array of integers, $a$, and an integer, $m$, determine the maximum value of the sum of any of its subarrays m...
def Solve(): N, M = map(int, input().split()) data = list(map(int, input().split())) computed = [] prevS = 0 for i in range(N): prevS = (prevS + data[i]) % M computed.append((prevS, i)) minS = -1 computed = sorted(computed) for i in range(N - 1): if computed[i][1]...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC...
We define the following: A subarray of array $a$ of length $n$ is a contiguous segment from $a[i]$ through $a[j]$ where $0\leq i\leq j<n.$. The sum of an array is the sum of its elements. Given an $n$ element array of integers, $a$, and an integer, $m$, determine the maximum value of the sum of any of its subarrays m...
def main_solve(): M = int(input().split()[1]) num = list(map(int, input().split())) prefix = [] sum = 0 for n in num: prefix.append((sum + n) % M) sum += n prefix_index = [(i, prefix[i]) for i in range(len(num))] prefix_index.sort(key=lambda x: x[1]) min_diff = M for ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ...
We define the following: A subarray of array $a$ of length $n$ is a contiguous segment from $a[i]$ through $a[j]$ where $0\leq i\leq j<n.$. The sum of an array is the sum of its elements. Given an $n$ element array of integers, $a$, and an integer, $m$, determine the maximum value of the sum of any of its subarrays m...
for _ in range(int(input())): N, M = map(int, input().split()) A = [int(a) for a in input().split()] b = 0 B = [b] for a in A: b = (a + b) % M B.append(b) order = sorted(range(len(B)), key=lambda i: B[i]) best = 0 lenB = len(B) for a, j in enumerate(order): if...
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 FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST VAR FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CA...
We define the following: A subarray of array $a$ of length $n$ is a contiguous segment from $a[i]$ through $a[j]$ where $0\leq i\leq j<n.$. The sum of an array is the sum of its elements. Given an $n$ element array of integers, $a$, and an integer, $m$, determine the maximum value of the sum of any of its subarrays m...
def solve(A, M): P = [(0, -1)] for i, a in enumerate(A): P.append(((P[-1][0] + a) % M, i)) P.sort() Pmin = [P[0]] for a in P: if a[0] == Pmin[-1][0]: continue else: Pmin.append(a) Pmax = [P[0]] for a in P: if a[0] == Pmax[-1][0]: ...
FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER NUMBER ASSI...
We define the following: A subarray of array $a$ of length $n$ is a contiguous segment from $a[i]$ through $a[j]$ where $0\leq i\leq j<n.$. The sum of an array is the sum of its elements. Given an $n$ element array of integers, $a$, and an integer, $m$, determine the maximum value of the sum of any of its subarrays m...
from itertools import accumulate t = int(input()) for i in range(t): n, m = map(int, input().split()) l = list(map(int, input().split())) pref = [0] * n pref[0] = l[0] % m mx = pref[0] for i in range(1, n): pref[i] = (l[i] + pref[i - 1]) % m mx = max(mx, pref[i]) tup = [] ...
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 BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR AS...
We have N persons sitting on a round table. Any person can do a handshake with any other person. 1 2 3 4 Handshake with 2-3 and 1-4 will cause cross. In how many ways these N people can make handshakes so that no two handshakes cross each other. N would be even. Example 1: Input: N = 2 Output: 1 ...
class Solution: def count(self, N): result = 0 if N % 2 == 1: return 0 elif N == 0: return 1 for i in range(0, N, 2): result += self.count(i) * self.count(N - 2 - i) return result
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN VAR
We have N persons sitting on a round table. Any person can do a handshake with any other person. 1 2 3 4 Handshake with 2-3 and 1-4 will cause cross. In how many ways these N people can make handshakes so that no two handshakes cross each other. N would be even. Example 1: Input: N = 2 Output: 1 ...
class Solution: def __init__(self): self.ans = 0 def count(self, n): if n == 0 or n == 2: return 1 else: a = n - 2 b = 0 ans = 0 while a >= 0: ans += self.count(a) * self.count(b) a -= 2 ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER RETURN VAR
We have N persons sitting on a round table. Any person can do a handshake with any other person. 1 2 3 4 Handshake with 2-3 and 1-4 will cause cross. In how many ways these N people can make handshakes so that no two handshakes cross each other. N would be even. Example 1: Input: N = 2 Output: 1 ...
class Solution: def count(self, N): def num_handshakes(n): if n % 2 == 1: return 0 elif n == 0: return 1 res = 0 for i in range(0, n, 2): res += num_handshakes(i) * num_handshakes(n - 2 - i) return ...
CLASS_DEF FUNC_DEF FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN VAR RETURN FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR...
We have N persons sitting on a round table. Any person can do a handshake with any other person. 1 2 3 4 Handshake with 2-3 and 1-4 will cause cross. In how many ways these N people can make handshakes so that no two handshakes cross each other. N would be even. Example 1: Input: N = 2 Output: 1 ...
class Solution: def count(self, n): if n == 0: return 1 ans = 0 for i in range(0, n, 2): ans += self.count(i) * self.count(n - 2 - i) return ans
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN VAR
We have N persons sitting on a round table. Any person can do a handshake with any other person. 1 2 3 4 Handshake with 2-3 and 1-4 will cause cross. In how many ways these N people can make handshakes so that no two handshakes cross each other. N would be even. Example 1: Input: N = 2 Output: 1 ...
class Solution: def count(self, N): if N % 2 == 1: return 0 elif N == 0: return 1 res = 0 i = 0 while i < N: res += self.count(i) * self.count(N - 2 - i) i += 2 return res
CLASS_DEF FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER RETURN VAR
We have N persons sitting on a round table. Any person can do a handshake with any other person. 1 2 3 4 Handshake with 2-3 and 1-4 will cause cross. In how many ways these N people can make handshakes so that no two handshakes cross each other. N would be even. Example 1: Input: N = 2 Output: 1 ...
class Solution: def count(self, N): memo = {} def dp(n): if n == 0: return 1 if n & 1: return 0 if n in memo: return memo[n] ans = 0 for i in range(2, n + 1): grp1 = i - 2 ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER RETURN NUMBER IF VAR VAR RETURN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VA...
We have N persons sitting on a round table. Any person can do a handshake with any other person. 1 2 3 4 Handshake with 2-3 and 1-4 will cause cross. In how many ways these N people can make handshakes so that no two handshakes cross each other. N would be even. Example 1: Input: N = 2 Output: 1 ...
class Solution: def count(self, N): if N & 1: return 0 if N == 0: return 1 total = 0 for i in range(N): total += self.count(i) * self.count(N - i - 2) return total
CLASS_DEF FUNC_DEF IF BIN_OP VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR
We have N persons sitting on a round table. Any person can do a handshake with any other person. 1 2 3 4 Handshake with 2-3 and 1-4 will cause cross. In how many ways these N people can make handshakes so that no two handshakes cross each other. N would be even. Example 1: Input: N = 2 Output: 1 ...
def rec(N, dp): if N == 0: return 1 if N % 2: return 0 if N in dp: return dp[N] ans = 0 for i in range(2, N + 1): ans += rec(i - 1 - 1, dp) * rec(N - i, dp) dp[N] = ans return ans class Solution: def count(self, N): dp = {} return rec(N,...
FUNC_DEF IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER RETURN NUMBER IF VAR VAR RETURN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR CLASS_DEF FUNC_DEF ASSIGN VAR DIC...
We have N persons sitting on a round table. Any person can do a handshake with any other person. 1 2 3 4 Handshake with 2-3 and 1-4 will cause cross. In how many ways these N people can make handshakes so that no two handshakes cross each other. N would be even. Example 1: Input: N = 2 Output: 1 ...
class Solution: def count(self, N): p = N // 2 arr = [0] * (p + 1) arr[0] = 1 arr[1] = 1 for i in range(2, p + 1): for j in range(0, p): arr[i] += arr[j] * arr[i - j - 1] return arr[p]
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR VAR
We have N persons sitting on a round table. Any person can do a handshake with any other person. 1 2 3 4 Handshake with 2-3 and 1-4 will cause cross. In how many ways these N people can make handshakes so that no two handshakes cross each other. N would be even. Example 1: Input: N = 2 Output: 1 ...
class Solution: def count(self, N): if N <= 2: return 1 i = N - 2 sum = 0 while i >= 0: sum += self.count(i) * self.count(N - 2 - i) i -= 2 return sum
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER RETURN VAR
We have N persons sitting on a round table. Any person can do a handshake with any other person. 1 2 3 4 Handshake with 2-3 and 1-4 will cause cross. In how many ways these N people can make handshakes so that no two handshakes cross each other. N would be even. Example 1: Input: N = 2 Output: 1 ...
class Solution: def count(self, N): if N % 2 != 0: return 0 n = N // 2 if n < 3: return n a = [1, 1, 2] for i in range(3, n + 1): p = 0 for j in range(i): p += a[j] * a[i - j - 1] a.append(p) ...
CLASS_DEF FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RE...
We have N persons sitting on a round table. Any person can do a handshake with any other person. 1 2 3 4 Handshake with 2-3 and 1-4 will cause cross. In how many ways these N people can make handshakes so that no two handshakes cross each other. N would be even. Example 1: Input: N = 2 Output: 1 ...
class Solution: def count(self, N): Dict = {} def findCount(n, Dict): if n == 0 or n == 1: return 1 count = 0 for i in range(n): if i not in Dict: Dict[i] = findCount(i, Dict) val1 = Dict[i] ...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASS...