description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Given a number (n) and no. of digits (m) to represent the number, we have to check if we can represent n using exactly m digits in any base from 2 to 32. Example 1: Input: n = 8, m = 2 Output: Yes Explanation: Possible in base 3 as 8 in base 3 is 22. Example 2: Input: n = 8, m = 3 Output: No Explanation: Not possibl...
class Solution: def baseEquiv(self, n, m): def chkpos(num, digit, base): if digit == 1 and num < base: return True if digit > 1 and num >= base: return chkpos(int(num / base), digit - 1, base) return False for i in range(2, 33): ...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER VAR VAR RETURN NUMBER IF VAR NUMBER VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR RETURN STRING RETURN STRING
Given a number (n) and no. of digits (m) to represent the number, we have to check if we can represent n using exactly m digits in any base from 2 to 32. Example 1: Input: n = 8, m = 2 Output: Yes Explanation: Possible in base 3 as 8 in base 3 is 22. Example 2: Input: n = 8, m = 3 Output: No Explanation: Not possibl...
class Solution: def baseEquiv(self, n, m): def getRep(num, base): count = 0 while num: num //= base count += 1 return count l = 2 r = 32 while l <= r: b = (l + r) // 2 rep = getRep(n, b) ...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR RETURN STRING IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN STRING
Given a number (n) and no. of digits (m) to represent the number, we have to check if we can represent n using exactly m digits in any base from 2 to 32. Example 1: Input: n = 8, m = 2 Output: Yes Explanation: Possible in base 3 as 8 in base 3 is 22. Example 2: Input: n = 8, m = 3 Output: No Explanation: Not possibl...
class Solution: def baseEquiv(self, n, m): if n <= 32 and m == 1: return "Yes" for i in range(32): cnt = 0 x = 1 while n > x: x *= i cnt += 1 if cnt > m: break if cnt == m...
CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER IF VAR VAR IF VAR VAR RETURN STRING RETURN STRING
Given a number (n) and no. of digits (m) to represent the number, we have to check if we can represent n using exactly m digits in any base from 2 to 32. Example 1: Input: n = 8, m = 2 Output: Yes Explanation: Possible in base 3 as 8 in base 3 is 22. Example 2: Input: n = 8, m = 3 Output: No Explanation: Not possibl...
class Solution: def baseEquiv(self, n, m): l = [] if m == 1: for i in range(2, 33): l.append(i - 1) else: for i in range(2, 33): l.append(i ** (m - 1)) ans = -1 low = 0 high = len(l) for i in range(len(l...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VA...
Given a number (n) and no. of digits (m) to represent the number, we have to check if we can represent n using exactly m digits in any base from 2 to 32. Example 1: Input: n = 8, m = 2 Output: Yes Explanation: Possible in base 3 as 8 in base 3 is 22. Example 2: Input: n = 8, m = 3 Output: No Explanation: Not possibl...
class Solution: def solve(self, num, base): if num == 0: return 0 d = [] while num: d.append(num % base) num = num // base return len(d) def baseEquiv(self, n, m): for i in range(2, 33): a = self.solve(n, i) if...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR LIST WHILE VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN FUNC_CALL VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR RETURN STRING RETURN STRING
Given a number (n) and no. of digits (m) to represent the number, we have to check if we can represent n using exactly m digits in any base from 2 to 32. Example 1: Input: n = 8, m = 2 Output: Yes Explanation: Possible in base 3 as 8 in base 3 is 22. Example 2: Input: n = 8, m = 3 Output: No Explanation: Not possibl...
class Solution: def baseEquiv(self, n, m): for i in range(2, 32 + 1): temp = n count = 0 while temp != 0: count += 1 temp //= i if count == m: return "Yes" return "No"
CLASS_DEF FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR VAR IF VAR VAR RETURN STRING RETURN STRING
Given a number (n) and no. of digits (m) to represent the number, we have to check if we can represent n using exactly m digits in any base from 2 to 32. Example 1: Input: n = 8, m = 2 Output: Yes Explanation: Possible in base 3 as 8 in base 3 is 22. Example 2: Input: n = 8, m = 3 Output: No Explanation: Not possibl...
class Solution: def baseEquiv(self, n, m): def check(n, i): s = [] while n >= i: s.append(n % i) n = n // i s.append(n) return len(s) if m == 1: if n <= 32: return "Yes" else: ...
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR LIST WHILE VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER RETURN STRING RETURN STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR RETURN STRING RETURN STRING
Given a number (n) and no. of digits (m) to represent the number, we have to check if we can represent n using exactly m digits in any base from 2 to 32. Example 1: Input: n = 8, m = 2 Output: Yes Explanation: Possible in base 3 as 8 in base 3 is 22. Example 2: Input: n = 8, m = 3 Output: No Explanation: Not possibl...
class Solution: def baseEquiv(self, n, m): def solve(n, a): ans = 0 while n > 0: n //= a ans += 1 return ans for i in range(2, 33): if solve(n, i) == m: return "Yes" return "No"
CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR RETURN STRING RETURN STRING
Given a number (n) and no. of digits (m) to represent the number, we have to check if we can represent n using exactly m digits in any base from 2 to 32. Example 1: Input: n = 8, m = 2 Output: Yes Explanation: Possible in base 3 as 8 in base 3 is 22. Example 2: Input: n = 8, m = 3 Output: No Explanation: Not possibl...
class Solution: def baseEquiv(self, n, m): def get(num, b, t): if num < b: if t + 1 == m: return True else: return False elif t >= m: return False else: return get(nu...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR IF BIN_OP VAR NUMBER VAR RETURN NUMBER RETURN NUMBER IF VAR VAR RETURN NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR NUMBER RETURN STRING RETURN STRING
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef is playing a card game called Blackjack. He starts with a deck of $N$ cards (numbered $1$ through $N$), where for each valid $i$, the $i$-th card has an integer $A_{i}$ written on it. Then he starts dealing the...
def solveCase(N, X, Y, a): left_cur, left_next = [0] * (N + 1), [0] * (N + 1) right_cur, right_next = [0] * (N + 1), [0] * (N + 1) left_cur[0] = 1 right_cur[N] = (2 << Y) - (1 << X) max_mask = (2 << Y) - 1 for missed in range(N // 2 + 1): for i in range(N): left_cur[i + 1] |=...
FUNC_DEF ASSIGN VAR VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef is playing a card game called Blackjack. He starts with a deck of $N$ cards (numbered $1$ through $N$), where for each valid $i$, the $i$-th card has an integer $A_{i}$ written on it. Then he starts dealing the...
left = [([0] * 1024) for _ in range(1024)] right = [([0] * 1024) for _ in range(1024)] def solveCase(N, X, Y, a): for i in range(N + 2): left[0][i] = right[0][i] = 0 left[0][0] = 1 right[0][N] = (1 << Y + 1) - (1 << X) max_mask = (1 << Y + 1) - 1 for missed in range(N // 2 + 1): le...
ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP NUM...
Read problems statements in mandarin chinese, russian and vietnamese as well. You are given N integers: A_{1}, A_{2}, ..., A_{N}. You need to count the number of pairs of indices (i, j) such that 1 ≤ i < j ≤ N and A_{i} | A_{j} ≤ max(A_{i}, A_{j}). Note: A_{i} | A_{j} refers to bitwise OR. ------ Input ------ The...
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().strip().split())) d = {} for i in range(n): if arr[i] not in d: d[arr[i]] = 1 else: d[arr[i]] += 1 ans = 0 for A1 in d.keys(): ans += d[A1] * (d[A1] - 1) for A2 in d...
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 DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP V...
Count the number of distinct sequences a_1, a_2, ..., a_{n} (1 ≤ a_{i}) consisting of positive integers such that gcd(a_1, a_2, ..., a_{n}) = x and $\sum_{i = 1}^{n} a_{i} = y$. As this number could be large, print the answer modulo 10^9 + 7. gcd here means the greatest common divisor. -----Input----- The only line...
import sys mod = 1000000007 def modpow(a, x): if x == 0: return 1 if x == 1: return a b = modpow(a, x // 2) return b * b * a ** (x % 2) % mod n, m = map(int, input().split()) if m % n != 0: print(0) sys.exit(0) if n == m: print(1) sys.exit(0) ans = m // n arr = [] i ...
IMPORT ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC...
Count the number of distinct sequences a_1, a_2, ..., a_{n} (1 ≤ a_{i}) consisting of positive integers such that gcd(a_1, a_2, ..., a_{n}) = x and $\sum_{i = 1}^{n} a_{i} = y$. As this number could be large, print the answer modulo 10^9 + 7. gcd here means the greatest common divisor. -----Input----- The only line...
def bin_pow(num, degree, module): if degree == 0: return 1 if degree == 1: return num % module if degree % 2 == 0: val = bin_pow(num, degree // 2, module) return val * val % module return num * bin_pow(num, degree - 1, module) % module x, y = map(int, input().split()) i...
FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP BIN_OP VAR VAR VAR RETURN BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP...
Count the number of distinct sequences a_1, a_2, ..., a_{n} (1 ≤ a_{i}) consisting of positive integers such that gcd(a_1, a_2, ..., a_{n}) = x and $\sum_{i = 1}^{n} a_{i} = y$. As this number could be large, print the answer modulo 10^9 + 7. gcd here means the greatest common divisor. -----Input----- The only line...
import sys x, y = list(map(int, input().strip().split())) if y % x != 0: print(0) return MOD = 10**9 + 7 K = y // x def multiply(A, b, MOD): n, m = len(A), len(b[0]) matrika = [[(0) for _ in range(m)] for _ in range(n)] for i in range(n): for j in range(m): vsota = 0 ...
IMPORT ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR...
Count the number of distinct sequences a_1, a_2, ..., a_{n} (1 ≤ a_{i}) consisting of positive integers such that gcd(a_1, a_2, ..., a_{n}) = x and $\sum_{i = 1}^{n} a_{i} = y$. As this number could be large, print the answer modulo 10^9 + 7. gcd here means the greatest common divisor. -----Input----- The only line...
modulo = 10**9 + 7 num1, num2 = list(map(int, input().split())) if num2 % num1: print("0") else: num2 = num2 // num1 arr = set() for i in range(1, int(pow(num2, 0.5) + 1)): if num2 % i == 0: arr.add(i) arr.add(num2 // i) arr = sorted(list(arr)) cop2 = arr[:] f...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER E...
Count the number of distinct sequences a_1, a_2, ..., a_{n} (1 ≤ a_{i}) consisting of positive integers such that gcd(a_1, a_2, ..., a_{n}) = x and $\sum_{i = 1}^{n} a_{i} = y$. As this number could be large, print the answer modulo 10^9 + 7. gcd here means the greatest common divisor. -----Input----- The only line...
import sys mod = 1000000007 def mul(x, y): res = 1 while y > 0: if y % 2 == 1: res = res * x % mod x = x * x % mod y //= 2 return res x, y = map(int, sys.stdin.readline().split()) if y % x != 0: print(0) else: y /= x d = set([]) i = 1 while i * i ...
IMPORT ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR ...
Count the number of distinct sequences a_1, a_2, ..., a_{n} (1 ≤ a_{i}) consisting of positive integers such that gcd(a_1, a_2, ..., a_{n}) = x and $\sum_{i = 1}^{n} a_{i} = y$. As this number could be large, print the answer modulo 10^9 + 7. gcd here means the greatest common divisor. -----Input----- The only line...
lista = input().split(" ") def prueba(f, *params): i = 1 for a in params: if f(a[0], a[1]) != a[2]: print( "El caso", i, "es incorrecto se respondio", f(a[0], a[1]), "y se esperaba", a[2], ...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING VAR STRING FUNC_CALL VAR VAR NUMBER VAR NUMBER STRING VAR NUMBER EXPR FUNC_CALL VAR STRING VAR STRING VAR NUMBER FUNC_DEF FOR VAR VAR EXPR FUNC_CALL VAR STRING FUN...
Count the number of distinct sequences a_1, a_2, ..., a_{n} (1 ≤ a_{i}) consisting of positive integers such that gcd(a_1, a_2, ..., a_{n}) = x and $\sum_{i = 1}^{n} a_{i} = y$. As this number could be large, print the answer modulo 10^9 + 7. gcd here means the greatest common divisor. -----Input----- The only line...
mod = 1000000007 x, y = map(int, input().split()) if y % x: print(0) exit(0) y //= x f = {(1): 1} def quick_power(a, b): r = 1 while b: if b & 1: r = r * a % mod a = a * a % mod b >>= 1 return r def dfs(s): if s in f.keys(): return f[s] r = qui...
ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR DICT NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR N...
Count the number of distinct sequences a_1, a_2, ..., a_{n} (1 ≤ a_{i}) consisting of positive integers such that gcd(a_1, a_2, ..., a_{n}) = x and $\sum_{i = 1}^{n} a_{i} = y$. As this number could be large, print the answer modulo 10^9 + 7. gcd here means the greatest common divisor. -----Input----- The only line...
x, y = map(int, input().split()) b = y // x if y % x != 0: print(0) return ds = set() M = 10**9 + 7 for i in range(1, int(pow(b, 0.5) + 1)): if b % i == 0: ds.add(i) ds.add(b // i) ds = sorted(list(ds)) ans = pow(2, b - 1, M) f = ds[:] for i in range(len(ds)): f[i] = pow(2, ds[i] - 1, M)...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER E...
You are given a boolean function of three variables which is defined by its truth table. You need to find an expression of minimum length that equals to this function. The expression may consist of: Operation AND ('&', ASCII code 38) Operation OR ('|', ASCII code 124) Operation NOT ('!', ASCII code 33) Variables x...
x = int("00001111", 2) y = int("00110011", 2) z = int("01010101", 2) E = set() T = set() F = {("x", x), ("y", y), ("z", z)} prv = set(), set(), set() fam = 2**8 tmpl = "#" * 99 ans = [tmpl] * fam def cmpr(E): nonlocal ans ans = [tmpl] * fam for e in E: if ( len(ans[e[1]]) > len(e[0]) ...
ASSIGN VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING VAR STRING VAR STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP STRING...
You are given a boolean function of three variables which is defined by its truth table. You need to find an expression of minimum length that equals to this function. The expression may consist of: Operation AND ('&', ASCII code 38) Operation OR ('|', ASCII code 124) Operation NOT ('!', ASCII code 33) Variables x...
val = """!x&x x&y&z !z&x&y x&y !y&x&z x&z !y&x&z|!z&x&y (y|z)&x !y&!z&x !y&!z&x|x&y&z !z&x !z&x|x&y !y&x !y&x|x&z !(y&z)&x x !x&y&z y&z !x&y&z|!z&x&y (x|z)&y !x&y&z|!y&x&z (x|y)&z !x&y&z|!y&x&z|!z&x&y (x|y)&z|x&y !x&y&z|!y&!z&x !y&!z&x|y&z !x&y&z|!z&x !z&x|y&z !x&y&z|!y&x !y&x|y&z !(y&z)&x|!x&y&z x|y&z !x&!z&y !x&!z&y|...
ASSIGN VAR FUNC_CALL STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
You are given a boolean function of three variables which is defined by its truth table. You need to find an expression of minimum length that equals to this function. The expression may consist of: Operation AND ('&', ASCII code 38) Operation OR ('|', ASCII code 124) Operation NOT ('!', ASCII code 33) Variables x...
table = "!x&x x&y&z !z&x&y x&y !y&x&z x&z !y&x&z|!z&x&y (y|z)&x !y&!z&x !y&!z&x|x&y&z !z&x !z&x|x&y !y&x !y&x|x&z !(y&z)&x x !x&y&z y&z !x&y&z|!z&x&y (x|z)&y !x&y&z|!y&x&z (x|y)&z !x&y&z|!y&x&z|!z&x&y (x|y)&z|x&y !x&y&z|!y&!z&x !y&!z&x|y&z !x&y&z|!z&x !z&x|y&z !x&y&z|!y&x !y&x|y&z !(y&z)&x|!x&y&z x|y&z !x&!z&y !x&!z&y|...
ASSIGN VAR FUNC_CALL STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VA...
You have a password which you often type — a string s of length n. Every character of this string is one of the first m lowercase Latin letters. Since you spend a lot of time typing it, you want to buy a new keyboard. A keyboard is a permutation of the first m Latin letters. For example, if m = 3, then there are six ...
n, m = map(int, input().split()) a = list(map(str, input().strip())) dp = [10**10] * (1 << 20) cnt = [0] * (1 << 20) def get(x): return 1 << ord(x) - ord("a") for i, v in enumerate(a): if i: cnt[get(a[i]) | get(a[i - 1])] += 1 for i in range(m): for j in range(1 << m): if 1 << i & j: ...
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 BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER FUNC_DEF RETURN BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FOR ...
You have a password which you often type — a string s of length n. Every character of this string is one of the first m lowercase Latin letters. Since you spend a lot of time typing it, you want to buy a new keyboard. A keyboard is a permutation of the first m Latin letters. For example, if m = 3, then there are six ...
import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline INF = 10**9 n, m = [int(item) for item in input().split()] s = input().rstrip() count = [([0] * m) for _ in range(m)] ord_a = ord("a") for c1, c2 in zip(s, s[1:]): c1 = ord(c1) - ord_a c2 = ord(c2) - ord_a if c1 != c2: count[c1][c2]...
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR FUNC_CALL VAR VAR VAR NUMBER A...
Vasya has a sequence a consisting of n integers a_1, a_2, ..., a_n. Vasya may pefrom the following operation: choose some number from the sequence and swap any pair of bits in its binary representation. For example, Vasya can transform number 6 (... 00000000110_2) into 3 (... 00000000011_2), 12 (... 000000001100_2), 10...
import sys def rint(): return map(int, sys.stdin.readline().split()) def get_num1(i): cnt = 0 while i: if i % 2: cnt += 1 i //= 2 return cnt n = int(input()) a = list(rint()) b = [get_num1(aa) for aa in a] ans = 0 S0 = [0] * n S0[0] = b[0] % 2 for i in range(1, n): ...
IMPORT FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER V...
Vasya has a sequence a consisting of n integers a_1, a_2, ..., a_n. Vasya may pefrom the following operation: choose some number from the sequence and swap any pair of bits in its binary representation. For example, Vasya can transform number 6 (... 00000000110_2) into 3 (... 00000000011_2), 12 (... 000000001100_2), 10...
n = int(input()) cnt = [[(0) for _ in range(n + 1)] for _ in range(2)] b = [bin(_).count("1") for _ in list(map(int, input().split()))] res = 0 suf_sum = 0 cnt[0][n] = 1 for i in range(n)[::-1]: _sum, mx = 0, 0 lst_j = i add = 0 for j in range(i, min(n, i + 65)): _sum += b[j] mx = max(mx...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBE...
Vasya has a sequence a consisting of n integers a_1, a_2, ..., a_n. Vasya may pefrom the following operation: choose some number from the sequence and swap any pair of bits in its binary representation. For example, Vasya can transform number 6 (... 00000000110_2) into 3 (... 00000000011_2), 12 (... 000000001100_2), 10...
N = int(input()) a = list(map(int, input().split())) cnt = [([0] * (N + 1)) for i in range(2)] b = [0] * N for i in range(N): b[i] = bin(a[i]).count("1") num = 0 suf = 0 cnt[0][N] = 1 for i in range(N - 1, -1, -1): s = 0 ma = 0 add = 0 for j in range(i, min(N, i + 65)): s += b[j] ma ...
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 LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VA...
Vasya has a sequence a consisting of n integers a_1, a_2, ..., a_n. Vasya may pefrom the following operation: choose some number from the sequence and swap any pair of bits in its binary representation. For example, Vasya can transform number 6 (... 00000000110_2) into 3 (... 00000000011_2), 12 (... 000000001100_2), 10...
n = int(input()) a = [int(x) for x in input().split()] c = [bin(x).count("1") for x in a] d = [(0) for i in range(n + 1)] even = 1 for i in range(1, n + 1): d[i] = d[i - 1] + c[i - 1] if d[i] % 2 == 0: even += 1 odd = n + 1 - even temp = even * (even - 1) // 2 + odd * (odd - 1) // 2 for i in range(n): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN...
Vasya has a sequence a consisting of n integers a_1, a_2, ..., a_n. Vasya may pefrom the following operation: choose some number from the sequence and swap any pair of bits in its binary representation. For example, Vasya can transform number 6 (... 00000000110_2) into 3 (... 00000000011_2), 12 (... 000000001100_2), 10...
import sys input = sys.stdin.readline n = int(input()) A = [int(x) for x in input().split()] B = [bin(a).count("1") for a in A] Bcumsum = [0] for b in B: Bcumsum.append((Bcumsum[-1] + b) % 2) count0 = [0] * (n + 1) for i in reversed(range(n)): count0[i] = count0[i + 1] + (Bcumsum[i + 1] == 0) numb = 65 sol = 0...
IMPORT ASSIGN 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 FUNC_CALL VAR VAR STRING VAR VAR ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FU...
Vasya has a sequence a consisting of n integers a_1, a_2, ..., a_n. Vasya may pefrom the following operation: choose some number from the sequence and swap any pair of bits in its binary representation. For example, Vasya can transform number 6 (... 00000000110_2) into 3 (... 00000000011_2), 12 (... 000000001100_2), 10...
n = int(input()) a = list(map(int, input().split())) for i in range(n): x = bin(a[i]) a[i] = x.count("1") even = 0 odd = 0 cnt = 0 sofar = 0 for i in range(n): sofar += a[i] if sofar % 2: odd += 1 else: even += 1 even += 1 sofar = 0 for i in range(n): if sofar % 2: odd -=...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP...
Sam has been teaching Jon the Game of Stones to sharpen his mind and help him devise a strategy to fight the white walkers. The rules of this game are quite simple: The game starts with n piles of stones indexed from 1 to n. The i-th pile contains s_{i} stones. The players make their moves alternatively. A move is con...
memo = {} def get_reachable_states(k, max_allowed): states = [] for i in range(1, min(k, max_allowed) + 1): new_k = k - i states.append((new_k, i - 1)) return states def Grundy(k, max_allowed): if k == 0: return 0 if (k, max_allowed) in memo: return memo[k, max_al...
ASSIGN VAR DICT FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSI...
Sam has been teaching Jon the Game of Stones to sharpen his mind and help him devise a strategy to fight the white walkers. The rules of this game are quite simple: The game starts with n piles of stones indexed from 1 to n. The i-th pile contains s_{i} stones. The players make their moves alternatively. A move is con...
s = 0 for t in range(int(input())): s ^= int((8 * int(input()) + 1) ** 0.5 - 1) // 2 print(["YES", "NO"][s > 0])
ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR LIST STRING STRING VAR NUMBER
Sam has been teaching Jon the Game of Stones to sharpen his mind and help him devise a strategy to fight the white walkers. The rules of this game are quite simple: The game starts with n piles of stones indexed from 1 to n. The i-th pile contains s_{i} stones. The players make their moves alternatively. A move is con...
n = int(input()) arr = [int(input()) for i in range(n)] b = [(0) for i in range(n)] s = 0 for i in range(n): j = int((arr[i] << 1) ** 0.5) if j * (j + 1) > arr[i] << 1: j -= 1 s ^= j if s != 0: print("NO") else: print("YES")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR IF...
Sam has been teaching Jon the Game of Stones to sharpen his mind and help him devise a strategy to fight the white walkers. The rules of this game are quite simple: The game starts with n piles of stones indexed from 1 to n. The i-th pile contains s_{i} stones. The players make their moves alternatively. A move is con...
import sys input = sys.stdin.readline def large(x): for i in range(10, -1, -1): if i * (i + 1) // 2 <= x: return i x = int(input()) l = [] for i in range(x): l.append(int(input())) a = [large(i) for i in range(0, 61)] lol = 0 for i in l: i = a[i] lol = lol ^ i if lol == 0: p...
IMPORT ASSIGN VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER NUM...
Sam has been teaching Jon the Game of Stones to sharpen his mind and help him devise a strategy to fight the white walkers. The rules of this game are quite simple: The game starts with n piles of stones indexed from 1 to n. The i-th pile contains s_{i} stones. The players make their moves alternatively. A move is con...
import sys input = sys.stdin.readline dp = {} def cal(x, y): x, y = int(x), int(y) a = set() if (x, y) in dp: return dp[x, y] for i in range(min(int(60), x)): p = y & 1 << i if p > 0: continue r = cal(x - i - 1, y | 1 << i) a.add(r) cn = 0 f...
IMPORT ASSIGN VAR VAR ASSIGN VAR DICT FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR VAR RETURN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR N...
Vasya has a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$. Vasya may pefrom the following operation: choose some number from the sequence and swap any pair of bits in its binary representation. For example, Vasya can transform number $6$ $(\dots 00000000110_2)$ into $3$ $(\dots 00000000011_2)$, $12$ $(...
import sys def rint(): return list(map(int, sys.stdin.readline().split())) def get_num1(i): cnt = 0 while i: if i % 2: cnt += 1 i //= 2 return cnt n = int(input()) a = list(rint()) b = [get_num1(aa) for aa in a] ans = 0 S0 = [0] * n S0[0] = b[0] % 2 for i in range(1, n)...
IMPORT FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP...
Vasya has a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$. Vasya may pefrom the following operation: choose some number from the sequence and swap any pair of bits in its binary representation. For example, Vasya can transform number $6$ $(\dots 00000000110_2)$ into $3$ $(\dots 00000000011_2)$, $12$ $(...
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) b = [0] * n for i in range(n): ai = a[i] for j in range(61): if ai >> j & 1: b[i] += 1 cnt = [([0] * (n + 1)) for i in range(2)] cnt[0][n] = 1 res = 0 suf = 0 for i in range(n)[::-1]: s = 0 MA...
IMPORT ASSIGN 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 BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP ...
Vasya has a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$. Vasya may pefrom the following operation: choose some number from the sequence and swap any pair of bits in its binary representation. For example, Vasya can transform number $6$ $(\dots 00000000110_2)$ into $3$ $(\dots 00000000011_2)$, $12$ $(...
N = int(input()) a = list(map(int, input().split())) cnt = [([0] * (N + 1)) for i in range(2)] b = [0] * N for i in range(N): b[i] = bin(a[i]).count("1") num = 0 suf = 0 cnt[0][N] = 1 for i in range(N - 1, -1, -1): s = 0 ma = 0 suf += b[i] num += cnt[suf & 1][i + 1] for j in range(i, min(N, i + ...
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 LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VA...
Ujan has a lot of numbers in his boxes. He likes order and balance, so he decided to reorder the numbers. There are $k$ boxes numbered from $1$ to $k$. The $i$-th box contains $n_i$ integer numbers. The integers can be negative. All of the integers are distinct. Ujan is lazy, so he will do the following reordering o...
from itertools import accumulate from sys import stdin, stdout def main(): k = int(stdin.readline()) a = [tuple(map(int, stdin.readline().split()[1:])) for _ in range(k)] a2ij = {aij: (i, j) for i, ai in enumerate(a) for j, aij in enumerate(ai)} plena = [0] + list(accumulate(map(len, a))) suma = t...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL ...
Ujan has a lot of numbers in his boxes. He likes order and balance, so he decided to reorder the numbers. There are $k$ boxes numbered from $1$ to $k$. The $i$-th box contains $n_i$ integer numbers. The integers can be negative. All of the integers are distinct. Ujan is lazy, so he will do the following reordering o...
def main(): k = int(input()) n = [] a = [] for i in range(k): line = [int(x) for x in input().split()] ni = line[0] ai = [] n.append(ni) a.append(ai) for j in range(ni): ai.append(line[1 + j]) answer, c, p = solve(k, n, a) if answer: ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP NUMBER VAR ASSIGN...
Ujan has a lot of numbers in his boxes. He likes order and balance, so he decided to reorder the numbers. There are $k$ boxes numbered from $1$ to $k$. The $i$-th box contains $n_i$ integer numbers. The integers can be negative. All of the integers are distinct. Ujan is lazy, so he will do the following reordering o...
import sys reader = (s.rstrip() for s in sys.stdin) input = reader.__next__ k = int(input()) d = {} aa = [] sa = [] for i in range(k): ni, *a = map(int, input().split()) for ai in a: d[ai] = i aa.append(a) sa.append(sum(a)) s = sum(sa) if s % k != 0: print("No") exit() s //= k def cal...
IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSI...
Ujan has a lot of numbers in his boxes. He likes order and balance, so he decided to reorder the numbers. There are $k$ boxes numbered from $1$ to $k$. The $i$-th box contains $n_i$ integer numbers. The integers can be negative. All of the integers are distinct. Ujan is lazy, so he will do the following reordering o...
import sys n = sys.stdin.readline() n = int(n) def get_graph(n): graph = [] for _ in range(n): entries = list(map(lambda x: int(x), sys.stdin.readline().split(" ")[1:])) graph.append(entries) return graph def chain(target, buckets, reverse_bucket, sum_bucket, bucket_num, val): mask ...
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR ...
You are given an integer m. Let M = 2^{m} - 1. You are also given a set of n integers denoted as the set T. The integers will be provided in base 2 as n binary strings of length m. A set of integers S is called "good" if the following hold. If $a \in S$, then [Image]. If $a, b \in S$, then $a \text{AND} b \in S$ ...
MOD = 10**9 + 7 m, N = list(map(int, input().split())) binom = [([1] + [(0) for i in range(m)]) for j in range(m + 1)] for n in range(1, m + 1): for k in range(1, n + 1): binom[n][k] = (binom[n - 1][k] + binom[n - 1][k - 1]) % MOD bell = [(0) for n in range(m + 1)] bell[0] = bell[1] = 1 for n in range(1, m)...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR...
Read problems statements in Russian here Chef has a special affection for sets of binary strings of equal length which have same numbers of 1's. Given three integers n, k and m, your task is to find the the lexicographically m^{th} smallest string among strings which have length n and have k 1's. If no such string e...
tests = int(input()) MAXN = 400 c = [[(-1) for _ in range(MAXN)] for _ in range(MAXN)] def cnk(n, k): if k > n: return 0 if k == 0 or n == k: return 1 if c[n][k] != -1: return c[n][k] c[n][k] = cnk(n - 1, k) + cnk(n - 1, k - 1) return c[n][k] for it in range(tests): n...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR NUMBER VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUM...
Read problems statements in Russian here Chef has a special affection for sets of binary strings of equal length which have same numbers of 1's. Given three integers n, k and m, your task is to find the the lexicographically m^{th} smallest string among strings which have length n and have k 1's. If no such string e...
def combi(n, k): res = 1 for i in range(k): res *= n - i for i in range(k): res //= i + 1 return res T = int(input()) for case in range(T): n, k, m = map(int, input().split()) if combi(n, k) < m: print(-1) continue b = [] for i in range(n): rem_b...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN V...
The only difference between easy and hard versions is constraints. Polycarp loves to listen to music, so he never leaves the player, even on the way home from the university. Polycarp overcomes the distance from the university to the house in exactly $T$ minutes. In the player, Polycarp stores $n$ songs, each of whic...
def popcount(i): assert 0 <= i < 4294967296 i = i - (i >> 1 & 1431655765) i = (i & 858993459) + (i >> 2 & 858993459) return ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 24 N, T = map(int, input().split()) TG = [list(map(int, input().split())) for _ in range(N)] mod = 10**9 + 7 dp = [([0] * ...
FUNC_DEF NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL V...
The only difference between easy and hard versions is constraints. Polycarp loves to listen to music, so he never leaves the player, even on the way home from the university. Polycarp overcomes the distance from the university to the house in exactly $T$ minutes. In the player, Polycarp stores $n$ songs, each of whic...
n, tnow = map(int, input().split()) left = int("".join(["1" for i in range(n)]), 2) arr = [] dp = {} for i in range(n): a, b = map(int, input().split()) arr.append([a, b]) def recur(tnow, prevgenre, left): key = str(left) + "_" + str(prevgenre) if tnow == 0: return 1 elif key in dp: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING STRING VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP FUNC...
The only difference between easy and hard versions is constraints. Polycarp loves to listen to music, so he never leaves the player, even on the way home from the university. Polycarp overcomes the distance from the university to the house in exactly $T$ minutes. In the player, Polycarp stores $n$ songs, each of whic...
import sys input = sys.stdin.readline mod = 10**9 + 7 n, t = map(int, input().split()) a = [] for i in range(n): time, genre = map(int, input().split()) genre -= 1 a.append((time, genre)) dp = [[(0) for j in range(3)] for i in range(1 << n)] for i in range(n): dp[1 << i][a[i][1]] = 1 for i in range(1 <...
IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL V...
The only difference between easy and hard versions is constraints. Polycarp loves to listen to music, so he never leaves the player, even on the way home from the university. Polycarp overcomes the distance from the university to the house in exactly $T$ minutes. In the player, Polycarp stores $n$ songs, each of whic...
from itertools import combinations def findsum(comb): sum = 0 for song in comb: sum += song[0] return sum def finda(a, b, c): if a == 0: return 0 if a == 1 and b == 0 and c == 0: return 1 else: return a * findb(a - 1, b, c) + a * findc(a - 1, b, c) def findb...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER RETURN BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER V...
The only difference between easy and hard versions is constraints. Polycarp loves to listen to music, so he never leaves the player, even on the way home from the university. Polycarp overcomes the distance from the university to the house in exactly $T$ minutes. In the player, Polycarp stores $n$ songs, each of whic...
from itertools import combinations def out1(a, b, c): if a < 0 or b < 0 or c < 0: return 0 if a == 1 and b == 0 and c == 0: return 1 return a * (out2(a - 1, b, c) + out3(a - 1, b, c)) def out2(a, b, c): if a < 0 or b < 0 or c < 0: return 0 if a == 0 and b == 1 and c == 0:...
FUNC_DEF IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER RETURN BIN_OP VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMB...
Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n - 1. For all 0 ≤ u < v < n, vertex u and vertex v are connected with an undirected edge that has weight $u \oplus v$ (where $\oplus...
def f(n): if n == 0: return 0 return 2 ** (n - 1) + 2 * f(n - 1) f = [0] * 60 for n in range(1, 60): f[n] = 2 ** (n - 1) + 2 * f[n - 1] n = int(input()) ans = 0 for k in range(60, 0, -1): if n >= 2**k: ans += f[k] n -= 2**k if n > 0: ans += 2**k print(int(an...
FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUN...
Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n - 1. For all 0 ≤ u < v < n, vertex u and vertex v are connected with an undirected edge that has weight $u \oplus v$ (where $\oplus...
def slow_cal(x): if x == 0: return 0 else: return slow_cal(x - 1) + min(x ^ v for v in range(x)) def med_cal(x): if x == 0: return 0 return sum(min(i ^ j for j in range(i)) for i in range(1, x + 1)) def fast_cal(x): res = 0 for bit in range(50): res += (x // (...
FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR...
Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n - 1. For all 0 ≤ u < v < n, vertex u and vertex v are connected with an undirected edge that has weight $u \oplus v$ (where $\oplus...
n = int(input()) def PotenciaDosMasCercana(n): if n == 0: return 0, 0 p = 1 i = 0 while p <= n: p = p << 1 i += 1 return p >> 1, i - 1 def C_Conexas(b): dp = [int] * 2 dp[0] = 0 for i in range(1, b + 1): dp[1] = 2 * dp[0] + 2 ** (i - 1) dp[0] =...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER RETURN BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP LIST VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP ...
Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n - 1. For all 0 ≤ u < v < n, vertex u and vertex v are connected with an undirected edge that has weight $u \oplus v$ (where $\oplus...
from sys import stdin, stdout n = int(stdin.readline()) psze = 41 ans = 0 def trans(s): cnt = 0 for i in range(psze * 2): if i < len(s) and s[i] == "1": cnt += 1 << i return cnt n -= 1 for i in range(psze): if 1 << i > n: break s = "0" * i + "1" cnt = 1 l, r ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR VAR STRING VAR BIN_OP NUMBER VAR RETURN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING VAR STRING ...
Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n - 1. For all 0 ≤ u < v < n, vertex u and vertex v are connected with an undirected edge that has weight $u \oplus v$ (where $\oplus...
n = int(input()) - 1 r = 0 while n != 0: zz = 1 a = 1 z = 1 while zz <= n: z <<= 1 zz <<= 1 zz += 1 a <<= 1 a += z zz >>= 1 a -= z a >>= 1 n -= zz r += a if n: n -= 1 r += z print(r)
ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR IF VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n - 1. For all 0 ≤ u < v < n, vertex u and vertex v are connected with an undirected edge that has weight $u \oplus v$ (where $\oplus...
n = int(input()) a, t = n - 1, 1 n -= 1 i = 2 while i <= n: a += n // i * t i *= 2 t *= 2 print(a)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n - 1. For all 0 ≤ u < v < n, vertex u and vertex v are connected with an undirected edge that has weight $u \oplus v$ (where $\oplus...
def main(): n = int(input()) - 1 res = n power = 1 while n // 2**power > 0: res += n // 2**power * 2 ** (power - 1) power += 1 print(res) main()
FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n - 1. For all 0 ≤ u < v < n, vertex u and vertex v are connected with an undirected edge that has weight $u \oplus v$ (where $\oplus...
def func(n): if n == 0: return 0 if n == 1: return 1 if n % 2: return func(n // 2) * 2 + n // 2 + 1 else: return func(n // 2) * 2 + n // 2 n = int(input()) a = [1, 2, 1, 4, 1, 2, 1, 8, 1, 2, 1, 4, 1, 2, 1] print(func(n - 1))
FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NU...
Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n - 1. For all 0 ≤ u < v < n, vertex u and vertex v are connected with an undirected edge that has weight $u \oplus v$ (where $\oplus...
L = input().split() n = int(L[0]) - 1 k = 0 while 1 << k < n: k += 1 ans = 0 for i in range(0, k + 1): ans += (1 << i) * ((n + (1 << i + 1) - (1 << i)) // (1 << i + 1)) print(ans)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE BIN_OP NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP NU...
Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n - 1. For all 0 ≤ u < v < n, vertex u and vertex v are connected with an undirected edge that has weight $u \oplus v$ (where $\oplus...
ans = 0 n = int(input()) k = 2**63 lpre = [0] for i in range(50): lpre.append(lpre[-1] * 2 + 2**i) lmax = -1 for i in range(42, -1, -1): if n & 2**i: ans += lpre[i] if lmax != -1: ans += 2**lmax lmax = i print(ans)
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR VAR IF VA...
Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n - 1. For all 0 ≤ u < v < n, vertex u and vertex v are connected with an undirected edge that has weight $u \oplus v$ (where $\oplus...
import sys n = int(sys.stdin.readline()) L = [0, 1] for i in range(1, 48): L.append(2 * L[i] + 2**i) B = bin(n - 1)[2:] result = 0 l = len(B) for i in range(0, len(B)): if B[i] == "1": result = result + 2 ** (l - 1 - i) + L[l - 1 - i] print(result) L
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VA...
Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n - 1. For all 0 ≤ u < v < n, vertex u and vertex v are connected with an undirected edge that has weight $u \oplus v$ (where $\oplus...
n = int(input()) - 1 dp = [0] * 40 for i in range(1, 40): dp[i] = 2 * dp[i - 1] + 2 ** (i - 1) c = 0 for i in range(40): if 1 << i & n: c += dp[i] + 2**i print(c)
ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR VAR BIN_OP VAR VAR BIN_OP...
Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n - 1. For all 0 ≤ u < v < n, vertex u and vertex v are connected with an undirected edge that has weight $u \oplus v$ (where $\oplus...
a = [0] cur = 1 while cur < 10**13: x = a[-1] a.append(x * 2 + cur) cur *= 2 n = int(input()) n -= 1 ans = 0 i = 1 cur = 1 while n > 0: x = n % 2 n = n // 2 if x > 0: ans += cur + a[i - 1] i += 1 cur *= 2 print(ans)
ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP...
Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n - 1. For all 0 ≤ u < v < n, vertex u and vertex v are connected with an undirected edge that has weight $u \oplus v$ (where $\oplus...
n = int(input().strip()) res = 0 i = 1 n -= 1 while i <= n: res += ((n - i) // (i << 1) + 1) * i i <<= 1 print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER WHILE VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n - 1. For all 0 ≤ u < v < n, vertex u and vertex v are connected with an undirected edge that has weight $u \oplus v$ (where $\oplus...
nn = input() n = int(nn) st = 0 dv = 1 step = [] while dv <= n: step.append(dv) dv = dv * 2 st += 1 step.append(dv) step.append(dv * 2) otv = 0 f = 1 q = 0 while f != 0: if n == 0: break if n == 1: break for i in range(len(step)): if step[i] > n: q = i - 1 ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR...
Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n - 1. For all 0 ≤ u < v < n, vertex u and vertex v are connected with an undirected edge that has weight $u \oplus v$ (where $\oplus...
n = int(input()) ans2 = [0] for i in range(1, 64): ans2.append(ans2[i - 1] + ans2[i - 1] + pow(2, i - 1)) def ans(n): if n == 0: return 0 else: length = n.bit_length() - 1 if n == pow(2, length): return ans2[length] else: return ans2[length] + ans(n ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER IF VAR FUNC_CALL VAR NUMBER VA...
Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n - 1. For all 0 ≤ u < v < n, vertex u and vertex v are connected with an undirected edge that has weight $u \oplus v$ (where $\oplus...
a = int(input()) def ans(n, p=1): return ans((n + 1) // 2, p * 2) + n // 2 * p if n > 1 else 0 print(ans(a))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF NUMBER RETURN VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n - 1. For all 0 ≤ u < v < n, vertex u and vertex v are connected with an undirected edge that has weight $u \oplus v$ (where $\oplus...
n = int(input()) n -= 1 tot = n // 2 ans = 0 ans += n - tot mask = 1 while mask <= 40: curr = 1 << mask strt = curr // 2 cnt = (tot - strt) // curr + 1 ans += curr * cnt mask += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n - 1. For all 0 ≤ u < v < n, vertex u and vertex v are connected with an undirected edge that has weight $u \oplus v$ (where $\oplus...
n = int(input()) def pow2(x): r = 1 while x > 0: x -= 1 r *= 2 return r def val_pow_2(x): lst = [] lst.append(0) for i in range(x): lst.append(2 * lst[i] + pow2(i)) return lst def lg2(x): r = 0 ans = 1 while x > 1: x = int(x / 2) ans ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE...
Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n - 1. For all 0 ≤ u < v < n, vertex u and vertex v are connected with an undirected edge that has weight $u \oplus v$ (where $\oplus...
import sys input = sys.stdin.readline n = int(input()) n -= 1 ans = 0 for i in range(50): ans += (n // (1 << i) - n // (1 << i + 1)) * (1 << i) print(ans)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n - 1. For all 0 ≤ u < v < n, vertex u and vertex v are connected with an undirected edge that has weight $u \oplus v$ (where $\oplus...
import sys input = sys.stdin.readline n = int(input()) ans = 0 w = 1 while n > 1: cnt = n // 2 ans += w * cnt n = (n + 1) // 2 w <<= 1 print(ans)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n - 1. For all 0 ≤ u < v < n, vertex u and vertex v are connected with an undirected edge that has weight $u \oplus v$ (where $\oplus...
n = int(input()) ans = 0 _pow = 2 while 2 * n > _pow: ans += _pow // 2 * (n // _pow + (1 if n % _pow > _pow // 2 else 0)) _pow *= 2 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP NUMBER VAR VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n - 1. For all 0 ≤ u < v < n, vertex u and vertex v are connected with an undirected edge that has weight $u \oplus v$ (where $\oplus...
import sys def main(): import sys input = sys.stdin.readline def rec(n, k): if n == 1: return 0 return n // 2 * k + rec((n + 1) // 2, 2 * k) print(rec(int(input()), 1)) return 0 main()
IMPORT FUNC_DEF IMPORT ASSIGN VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR
Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n - 1. For all 0 ≤ u < v < n, vertex u and vertex v are connected with an undirected edge that has weight $u \oplus v$ (where $\oplus...
def f(n): if n == 2: return 1 if n == 3: return 3 if n % 2 == 0: return 2 * f(n // 2) + n // 2 else: return 2 * f(n // 2 + 1) + n // 2 n = int(input()) print(f(n))
FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR...
Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n - 1. For all 0 ≤ u < v < n, vertex u and vertex v are connected with an undirected edge that has weight $u \oplus v$ (where $\oplus...
def gao(n): if n == 1: return 1 else: return 2 * gao(n // 2) + (n + 1) // 2 while True: try: n = int(input()) print(gao(n - 1)) except BaseException: break
FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER WHILE NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR
Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n - 1. For all 0 ≤ u < v < n, vertex u and vertex v are connected with an undirected edge that has weight $u \oplus v$ (where $\oplus...
n = int(input()) n = n - 1 ans = 0 dp = [] dp.append(1) for i in range(1, 41): dp.append(2 * dp[i - 1] + pow(2, i)) for i in range(40, -1, -1): if n & 1 << i > 0: ans += pow(2, i) if i != 0: ans += dp[i - 1] print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP NUMBE...
Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n - 1. For all 0 ≤ u < v < n, vertex u and vertex v are connected with an undirected edge that has weight $u \oplus v$ (where $\oplus...
n = int(input()) c = 0 for i in range(39, 0, -1): s = pow(2, i) if s <= n: n -= s c += s // 2 * i if n != 0: c += s print(c)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Bakry faced a problem, but since he's lazy to solve it, he asks for your help. You are given a tree of $n$ nodes, the $i$-th node has value $a_i$ assigned to it for each $i$ from $1$ to $n$. As a reminder, a tree on $n$ nodes is a connected graph with $n-1$ edges. You want to delete at least $1$, but at most $k-1$ ed...
import sys input = sys.stdin.readline def solve(): n, k = map(int, input().split()) (*a,) = map(int, input().split()) X = 0 for i in a: X ^= i g = [[] for i in range(n)] for i in range(n - 1): u, v = map(int, input().split()) g[u - 1].append(v - 1) g[v - 1].app...
IMPORT ASSIGN VAR VAR FUNC_DEF 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 NUMBER FOR VAR VAR VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR F...
The Bubble Cup hypothesis stood unsolved for 130 years. Who ever proves the hypothesis will be regarded as one of the greatest mathematicians of our time! A famous mathematician Jerry Mao managed to reduce the hypothesis to this problem: Given a number m, how many polynomials P with coefficients in set {\{0,1,2,3,4,5,...
T = input() mod = int(1000000000.0 + 7) a = map(int, input().split()) c = [] for n in a: b = n // 2 + 2 b = b * b b //= 4 c.append(str(b % mod)) print(" ".join(c))
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
The Bubble Cup hypothesis stood unsolved for 130 years. Who ever proves the hypothesis will be regarded as one of the greatest mathematicians of our time! A famous mathematician Jerry Mao managed to reduce the hypothesis to this problem: Given a number m, how many polynomials P with coefficients in set {\{0,1,2,3,4,5,...
t = int(input()) a = list(map(int, input().split())) out = [] for n in a: ans = n // 2 + 2 ans = ans * ans ans //= 4 out.append(ans % 1000000007) print(" ".join(str(x) for x in out))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
There is the following puzzle popular among nuclear physicists. A reactor contains a set of n atoms of some chemical elements. We shall understand the phrase "atomic number" as the number of this atom's element in the periodic table of the chemical elements. You are allowed to take any two different atoms and fuse a ...
import itertools element_to_value = { "H": 1, "He": 2, "Li": 3, "Be": 4, "B": 5, "C": 6, "N": 7, "O": 8, "F": 9, "Ne": 10, "Na": 11, "Mg": 12, "Al": 13, "Si": 14, "P": 15, "S": 16, "Cl": 17, "Ar": 18, "K": 19, "Ca": 20, "Sc": 21, "...
IMPORT ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STR...
Monocarp has arranged $n$ colored marbles in a row. The color of the $i$-th marble is $a_i$. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color). In other words, Monocarp wants to ...
n = int(input()) a = [int(x) for x in input().split()] d = {} for i in range(1, 21): for j in range(1, 21): d[i, j] = 0 cv = [(0) for i in range(21)] for j in a: for i in range(1, 21): d[i, j] += cv[i] cv[j] += 1 s = 0 for i in range(1, 21): for j in range(i + 1, 21): s += min(d[...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR VAR VAR...
Monocarp has arranged $n$ colored marbles in a row. The color of the $i$-th marble is $a_i$. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color). In other words, Monocarp wants to ...
import sys n = int(sys.stdin.readline().strip()) a = list(map(int, sys.stdin.readline().strip().split())) M = [[(0) for i in range(0, 21)] for j in range(0, 21)] F = [(0) for i in range(0, 21)] for i in range(0, n): x = int(a[i]) for j in range(0, 21): if j != x: M[j][x] = M[j][x] + F[j] ...
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL V...
You are given a string s, a split is called good if you can split s into 2 non-empty strings p and q where its concatenation is equal to s and the number of distinct letters in p and q are the same. Return the number of good splits you can make in s.   Example 1: Input: s = "aacaba" Output: 2 Explanation: There are 5 w...
class Solution: def numSplits(self, s: str) -> int: if len(s) == 0: return 0 count = 0 counterLeft = collections.Counter() counterRight = collections.Counter(s) for element in s: counterLeft[element] += 1 counterRight[element] -= 1 ...
CLASS_DEF FUNC_DEF VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR VAR
You are given a string s, a split is called good if you can split s into 2 non-empty strings p and q where its concatenation is equal to s and the number of distinct letters in p and q are the same. Return the number of good splits you can make in s.   Example 1: Input: s = "aacaba" Output: 2 Explanation: There are 5 w...
class Solution: def numSplits(self, s: str) -> int: left_count = collections.Counter() right_count = collections.Counter(s) ans = 0 for ch in s: left_count[ch] += 1 right_count[ch] -= 1 if right_count[ch] == 0: del right_count[ch] ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR VAR
You are given a string s, a split is called good if you can split s into 2 non-empty strings p and q where its concatenation is equal to s and the number of distinct letters in p and q are the same. Return the number of good splits you can make in s.   Example 1: Input: s = "aacaba" Output: 2 Explanation: There are 5 w...
class Solution: def numSplits(self, s: str) -> int: dic_b = {} for i in s[1:]: if i not in dic_b: dic_b[i] = 1 else: dic_b[i] += 1 b_count = len(dic_b) a = list(s[:1]) a_count = 1 count = int(b_count == a_count)...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT FOR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR...
You are given a string s, a split is called good if you can split s into 2 non-empty strings p and q where its concatenation is equal to s and the number of distinct letters in p and q are the same. Return the number of good splits you can make in s.   Example 1: Input: s = "aacaba" Output: 2 Explanation: There are 5 w...
class Solution: def numSplits(self, s: str) -> int: index_one = 0 index_two = 0 set_one = set() set_two = set() s_r = s[::-1] for i in range(len(s)): print((i, len(set(s[: i + 1])), len(set(s[i + 1 :])))) if len(set(s[: i + 1])) == len(set(s[i...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR FUNC_CALL...
You are given a string s, a split is called good if you can split s into 2 non-empty strings p and q where its concatenation is equal to s and the number of distinct letters in p and q are the same. Return the number of good splits you can make in s.   Example 1: Input: s = "aacaba" Output: 2 Explanation: There are 5 w...
class Solution: def numSplits(self, s: str) -> int: counter = 0 left = defaultdict(int) right = defaultdict(int) for c in s: right[c] += 1 for i in range(len(s)): left[s[i]] += 1 right[s[i]] -= 1 if right[s[i]] == 0: ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMB...
You are given a string s, a split is called good if you can split s into 2 non-empty strings p and q where its concatenation is equal to s and the number of distinct letters in p and q are the same. Return the number of good splits you can make in s.   Example 1: Input: s = "aacaba" Output: 2 Explanation: There are 5 w...
class Solution: def numSplits(self, string: str) -> int: def isValid(string, i): return 0 <= i < len(string) def getLength(string, unique, i): if isValid(string, i): unique.add(string[i]) return len(unique) return len(unique) ...
CLASS_DEF FUNC_DEF VAR FUNC_DEF RETURN NUMBER VAR FUNC_CALL VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VA...
You are given a string s, a split is called good if you can split s into 2 non-empty strings p and q where its concatenation is equal to s and the number of distinct letters in p and q are the same. Return the number of good splits you can make in s.   Example 1: Input: s = "aacaba" Output: 2 Explanation: There are 5 w...
class Solution: def numSplits(self, s: str) -> int: left = sorted([s.find(l) for l in set(s)]) + [len(s)] right = sorted([s.rfind(l) for l in set(s)], reverse=True) + [0] ind = max(ind for ind in range(len(left)) if left[ind] <= right[ind]) return min(right[ind], left[ind + 1]) - ma...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR LIST FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER LIST NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR VA...
You are given a string s, a split is called good if you can split s into 2 non-empty strings p and q where its concatenation is equal to s and the number of distinct letters in p and q are the same. Return the number of good splits you can make in s.   Example 1: Input: s = "aacaba" Output: 2 Explanation: There are 5 w...
class Solution: def numSplits(self, s: str) -> int: set_f = set() map_b = defaultdict(int) for c in s: map_b[c] += 1 num = 0 for c in s: map_b[c] -= 1 if not map_b[c]: del map_b[c] set_f.add(c) if le...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR VAR
You are given a string s, a split is called good if you can split s into 2 non-empty strings p and q where its concatenation is equal to s and the number of distinct letters in p and q are the same. Return the number of good splits you can make in s.   Example 1: Input: s = "aacaba" Output: 2 Explanation: There are 5 w...
class Solution: def numSplits(self, s: str) -> int: if len(s) == 1: return 0 ln = len(s) ans = 0 t1 = {} t2 = {} l1, l2 = 0, 0 t1[s[0]] = 1 for i in range(1, ln): if s[i] in list(t2.keys()): t2[s[i]] += 1 ...
CLASS_DEF FUNC_DEF VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER I...
You are given a string s, a split is called good if you can split s into 2 non-empty strings p and q where its concatenation is equal to s and the number of distinct letters in p and q are the same. Return the number of good splits you can make in s.   Example 1: Input: s = "aacaba" Output: 2 Explanation: There are 5 w...
class Solution: def numSplits(self, s: str) -> int: left_unique = [(0) for x in range(len(s))] right_unique = [(0) for x in range(len(s))] left_set = set() right_set = set() for x in range(len(s)): if s[x] not in left_set: left_set.add(s[x]) ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER...
You are given a string s, a split is called good if you can split s into 2 non-empty strings p and q where its concatenation is equal to s and the number of distinct letters in p and q are the same. Return the number of good splits you can make in s.   Example 1: Input: s = "aacaba" Output: 2 Explanation: There are 5 w...
class Solution: def numSplits(self, s: str) -> int: if not s: return 0 l_unique = set([]) r_unique = set(s) good_splits = 0 for i, x in enumerate(s): l_unique.add(x) if x not in s[i + 1 :]: r_unique.discard(x) i...
CLASS_DEF FUNC_DEF VAR IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR VAR
You are given a string s, a split is called good if you can split s into 2 non-empty strings p and q where its concatenation is equal to s and the number of distinct letters in p and q are the same. Return the number of good splits you can make in s.   Example 1: Input: s = "aacaba" Output: 2 Explanation: There are 5 w...
class Solution: def numSplits(self, s: str) -> int: left = {s[0]: 1} right = {} for i in range(1, len(s)): right[s[i]] = right.get(s[i], 0) + 1 middle_i = 1 count = 0 while middle_i < len(s): if len(left) == len(right): count +...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT VAR NUMBER NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR V...
You are given a string s, a split is called good if you can split s into 2 non-empty strings p and q where its concatenation is equal to s and the number of distinct letters in p and q are the same. Return the number of good splits you can make in s.   Example 1: Input: s = "aacaba" Output: 2 Explanation: There are 5 w...
class Solution: def numSplits(self, s: str) -> int: unique_chars = {} for i, char in enumerate(s): if char in unique_chars: first, last = unique_chars[char] unique_chars[char] = first, i else: unique_chars[char] = i, i ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EX...
You are given a string s, a split is called good if you can split s into 2 non-empty strings p and q where its concatenation is equal to s and the number of distinct letters in p and q are the same. Return the number of good splits you can make in s.   Example 1: Input: s = "aacaba" Output: 2 Explanation: There are 5 w...
class Solution: def numSplits(self, s: str) -> int: left = Counter() right = Counter(s) res = 0 for ch in s: if right[ch] == 1: del right[ch] else: right[ch] -= 1 left[ch] += 1 if len(list(left.keys())) ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN VAR VAR
You are given a string s, a split is called good if you can split s into 2 non-empty strings p and q where its concatenation is equal to s and the number of distinct letters in p and q are the same. Return the number of good splits you can make in s.   Example 1: Input: s = "aacaba" Output: 2 Explanation: There are 5 w...
class Solution: def numSplits(self, s: str) -> int: p_dict = {s[0]: 1} q_dict = {} for char in s[1:]: self.addToDict(q_dict, char) if len(p_dict.keys()) == len(q_dict.keys()): count = 1 else: count = 0 for i in range(1, len(s) - 1)...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT VAR NUMBER NUMBER ASSIGN VAR DICT FOR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR...
You are given a string s, a split is called good if you can split s into 2 non-empty strings p and q where its concatenation is equal to s and the number of distinct letters in p and q are the same. Return the number of good splits you can make in s.   Example 1: Input: s = "aacaba" Output: 2 Explanation: There are 5 w...
class Solution: def numSplits(self, s: str) -> int: res = 0 fs = set() d = {} for x in s: if x not in d: d[x] = 1 else: d[x] += 1 i = 0 while i < len(s): fs.add(s[i]) if d[s[i]] > 1: ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUN...