description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
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: total_chars_1 = defaultdict(int) total_chars_1[s[0]] = 1 total_chars_2 = defaultdict(int) splits = 0 for i in range(1, len(s)): total_chars_2[s[i]] += 1 for i in range(len(s) - 1): if len(tot...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUM...
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: dictionary = {} sol = 0 for i in range(len(s)): dictionary[s[i]] = i dictionary2 = {} for i in range(len(s) - 1): dictionary2[s[i]] = i if i == dictionary[s[i]]: dictionar...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER RETURN 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: good_splits = 0 first_map = {} s_map = {} for letter in s: if s_map.get(letter): s_map[letter] += 1 else: s_map[letter] = 1 for split_point in range(len(s)): ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUM...
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 sub(self, h, h2): nh = h.copy() for k in h2: if k in nh: nh[k] = nh[k] - h2[k] if nh[k] == 0: del nh[k] return nh def numSplits(self, s: str) -> int: h = {} for c in s: if c ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR NUMBER VAR VAR RETURN VAR FUNC_DEF VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR IF ...
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: n = len(s) lc = [1] * n rc = [1] * n ls = set() rs = set() for i in range(n): ls.add(s[i]) rs.add(s[-(i + 1)]) lc[i] = len(ls) rc[-(i + 1)] = len(rs) r = 0 ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR N...
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: leftMap = {} rightMap = {} for j in range(len(s)): rightMap[s[j]] = rightMap.get(s[j], 0) + 1 i = 0 result = 0 while i < len(s) - 1: leftMap[s[i]] = leftMap.get(s[i], 0) + 1 right...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR 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 BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_...
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: c = Counter(s) res = 0 d = dict() for i, v in enumerate(s): if v not in d: d[v] = 1 else: d[v] += 1 c[v] -= 1 if c[v] == 0: del c[v] ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER 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: cnt = 0 l_set = set() d = {c: s.count(c) for c in set(s)} for c in s: l_set.add(c) d[c] -= 1 if d[c] == 0: d.pop(c, None) if len(l_set) == len(d): cnt ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NONE 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: uniqueLeft = 0 uniqueRight = 0 ans = 0 leftDict = {} rightDict = {} for i in s: if i in rightDict: rightDict[i] += 1 else: rightDict[i] = 1 uni...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER RET...
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: right = collections.Counter(s) left = collections.defaultdict(int) res = 0 for i in range(len(s) - 1): c = s[i] right[c] -= 1 if not right[c]: del right[c] left[c] += ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER 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: result1 = [[s[0]]] result2 = [[s[-1]]] n = len(s) for i in range(1, len(s)): list1 = list(result1[i - 1]) list2 = list(result2[i - 1]) if s[i] not in list1: list1.append(s[i]) ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR LIST LIST VAR NUMBER ASSIGN VAR LIST LIST VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR BIN_OP BIN_OP ...
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 lmap = collections.Counter(s[0:1]) rmap = collections.Counter(s[1:]) ans = 0 for i in range(1, len(s)): if len(lmap) == len(rmap): ans += 1 lmap.u...
CLASS_DEF FUNC_DEF VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR VAR NUMBER IF 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: s_len = len(s) if s_len == 0 or s_len == 1: return 0 seen = set() dp = [(0) for _ in range(s_len - 1)] dp[0] = 1 seen.add(s[0]) for i in range(1, s_len - 1): if s[i] in seen: ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUM...
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 or len(s) < 0: return 0 right = {} left = {s[0]: 1} count = 0 if len(left) == len(right): count += 1 for i in range(1, len(s)): if s[i] in right: right[s[...
CLASS_DEF FUNC_DEF VAR IF VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR DICT ASSIGN VAR DICT VAR NUMBER NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_...
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: le_set, ri_set = [s[0]], [s[-1]] le_arr, ri_arr = [1] * len(s), [1] * len(s) for i in range(1, len(s)): le_arr[i] = le_arr[i - 1] if s[i] not in le_set: le_set.append(s[i]) le_arr[i] ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR VAR LIST VAR NUMBER LIST VAR NUMBER ASSIGN VAR VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL 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: b_c = collections.defaultdict(lambda: 0) a_c = dict(collections.Counter(list(s))) ans = 0 for i, ch in enumerate(list(s)): b_c[ch] += 1 a_c[ch] -= 1 if len({k for k, v in list(b_c.items()) if v >...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CAL...
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: fila = {} tot = len(set(s)) x = set() for i in range(len(s)): x.add(s[i]) if len(x) == tot: fa = i break x = set() for i in range(len(s) - 1, -1, -1): ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CAL...
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, ss: str) -> int: a = set() k = {} p = {} n = len(ss) def myfunc(s, aa): for i in range(n - 1): if s[i] not in a: a.add(s[i]) aa[i] = 1 else: ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR ...
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: lc, rc = [], [] ls, rs = set(), set() for c in s: ls.add(c) lc.append(len(ls)) for c in reversed(s): rs.add(c) rc.append(len(rs)) res = 0 rc = rc[::-1] for i i...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR VAR LIST LIST ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FU...
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: auxDict = {} auxLeftToRight = [0] * len(s) count = 0 for pos in range(len(s)): if s[pos] not in auxDict: auxDict[s[pos]] = 1 count += 1 auxLeftToRight[pos] = count aux...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL 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 count_chars(self, s): count = {} for c in s: if c in count: count[c] += 1 else: count[c] = 1 return count def dict_decr(self, d, c): if c in d: d[c] -= 1 if d[c] <= 0: de...
CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER RETURN VAR FUNC_DEF IF VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR FUNC_DEF VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR IF 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 make_hist(self, array: str) -> dict: hist = {} for s in array: if s not in list(hist.keys()): hist[s] = 1 else: hist[s] += 1 return hist def numSplits(self, s: str) -> int: hist_left = self.make_hist(s[...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT FOR VAR VAR IF VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER RETURN VAR VAR FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF 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: count = 0 left = set(s[:1]) right = set(s[1:]) if len(left) == len(right): count += 1 k = 0 for i in range(1, len(s)): if s[i] not in left: left.add(s[i]) if s[i] ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN...
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_map = {} right_map = {} unique_right = 0 unique_left = 0 for i in range(len(s)): if s[i] not in right_map: right_map[s[i]] = 1 unique_right += 1 else: ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER 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 numSplitsBF(self, s: str) -> int: cntr = 0 for i in range(1, len(s)): a, b = collections.Counter(s[:i]), collections.Counter(s[i:]) if len(a) == len(b): cntr += 1 return cntr def numSplits(self, s: str) -> int: a = col...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR VAR FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER A...
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 = int q = int ll = len(s) if ll < 2: return 0 ns = len(set(s)) np = nq = 0 for ii in range(1, ll): if len(set(s[:ii])) == ns: np = ii break f...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR FUNC...
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: characters = [] possibleSplits = 0 for i in range(len(s)): if s[i] not in characters: characters.append(s[i]) for i in range(len(s)): leftChars = 0 rightChars = 0 left...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR 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: l_count = [] r_count = [] tmp = 0 for i in range(len(s)): if s[i] not in s[:i]: tmp += 1 l_count.append(tmp) tmp = 0 for i in range(len(s))[::-1]: if s[i] not in s...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR 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: pre = [0] * len(s) acc = set() cnt = 0 for i in range(len(s) - 1): if s[i] not in acc: cnt += 1 acc.add(s[i]) pre[i] = cnt cnt = 0 acc.clear() res = 0 ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN...
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 left = len(s) * [0] right = len(s) * [0] seen = set(s[0]) left[0] = 1 for i in range(1, len(s)): if s[i] not in seen: seen.add(s[i]) l...
CLASS_DEF FUNC_DEF VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR LIST NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR 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: initial = {} for char in s: if char in initial: initial[char] += 1 else: initial[char] = 1 other = {} output = 0 for char in s: initial[char] -= 1 ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER 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: n = len(s) output = 0 dic = {} for i, x in enumerate(s): if not x in dic: dic[x] = [i, i] else: dic[x][1] = i for i in range(0, n - 1): left = 0 ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR LIST VAR VAR ASSIGN VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR NUMBE...
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: seen_letters = [] preprocess_prefix = [0] for i in range(len(s)): if s[i] not in seen_letters: seen_letters.append(s[i]) preprocess_prefix.append(len(seen_letters)) seen_letters = [] ...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR LIST ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR VAR EXPR FUNC_CALL 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: def decorate(a, b): final = {(1): defaultdict(int), (2): defaultdict(int)} count1, count2 = 0, 0 for char in a: final[1][char] += 1 if final[1][char] == 1: count1 += ...
CLASS_DEF FUNC_DEF VAR FUNC_DEF ASSIGN VAR DICT NUMBER NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR NONE ASSIGN VAR VAR NUM...
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, q, ans = Counter(), Counter(s), 0 for c in s[:-1]: p[c] += 1 q[c] -= 1 if not q[c]: del q[c] ans += len(p) == len(q) return ans
CLASS_DEF FUNC_DEF VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR 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: N = len(s) left = [0] * (N + 1) seen = set() for i in range(1, N + 1): c = s[i - 1] if c not in seen: left[i] = left[i - 1] + 1 seen.add(c) else: l...
CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR ...
You are given a grid, consisting of $2$ rows and $n$ columns. Each cell of this grid should be colored either black or white. Two cells are considered neighbours if they have a common border and share the same color. Two cells $A$ and $B$ belong to the same component if they are neighbours, or if there is a neighbour ...
n, K = map(int, input().split()) mod = 998244353 if K == 1: print(2) exit() dp = [([0] * 2**2) for i in range(K + 1)] dp[1][0] = 1 dp[2][1] = 1 dp[2][2] = 1 dp[1][3] = 1 for i in range(1, n): nx = [([0] * 2**2) for i in range(K + 1)] for k in range(K + 1): for j in range(4): if j == ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASS...
You are given a grid, consisting of $2$ rows and $n$ columns. Each cell of this grid should be colored either black or white. Two cells are considered neighbours if they have a common border and share the same color. Two cells $A$ and $B$ belong to the same component if they are neighbours, or if there is a neighbour ...
import itertools n, k = [int(i) for i in input().split()] kas = [[0, 0, 0, 0], [1, 0, 0, 1], [0, 1, 1, 0]] mmm = 998244353 def count_k(ka, k, t): if t == 0: return ka[k][0] + ka[k][1] + ka[k][2] + ka[k - 1][3] if t == 1: return ka[k - 1][0] + ka[k][1] + ka[k - 2][2] + ka[k - 1][3] if t ==...
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER N...
You are given a grid, consisting of $2$ rows and $n$ columns. Each cell of this grid should be colored either black or white. Two cells are considered neighbours if they have a common border and share the same color. Two cells $A$ and $B$ belong to the same component if they are neighbours, or if there is a neighbour ...
ch_0 = {(0): [0, 1, 2], (2): [2], (1): [1], (3): [1, 2, 3]} ch_1 = {(0): [3], (3): [0], (1): [0, 3], (2): [0, 3]} ch_2 = {(0): [], (3): [], (2): [1], (1): [2]} N = 998244353 n, k = map(int, input().strip().split(" ")) dp = [[([0] * 4) for j in range(k + 5)] for i in range(n + 5)] dp[0][1][3] = 1 dp[0][1][0] = 1 dp[0][2...
ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER LIST NUMBER LIST NUMBER NUMBER NUMBER ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER LIST NUMBER LIST NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER LIST LIST LIST NUMBER LIST NUMBER ASSIGN VAR NUMBE...
You are given a grid, consisting of $2$ rows and $n$ columns. Each cell of this grid should be colored either black or white. Two cells are considered neighbours if they have a common border and share the same color. Two cells $A$ and $B$ belong to the same component if they are neighbours, or if there is a neighbour ...
n, k = [int(x) for x in input().split()] dp = [[[(0) for _ in range(4)] for _ in range(k + 2)] for _ in range(2)] dp[1][2][0] = 1 dp[1][2][1] = 1 dp[1][1][2] = 1 dp[1][1][3] = 1 for n1 in range(1, n): for k1 in range(1, k + 1): dp[0][k1][0] = dp[1][k1][0] dp[0][k1][1] = dp[1][k1][1] dp[0][k1...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER NUMBER...
You are given a grid, consisting of $2$ rows and $n$ columns. Each cell of this grid should be colored either black or white. Two cells are considered neighbours if they have a common border and share the same color. Two cells $A$ and $B$ belong to the same component if they are neighbours, or if there is a neighbour ...
n, K = map(int, input().split()) dp = [[([0] * 4) for j in range(K + 2)] for i in range(n)] MOD = 998244353 dp[0][1][0] = 1 dp[0][1][1] = 1 dp[0][2][2] = 1 dp[0][2][3] = 1 for i in range(n - 1): for j in range(1, K + 1): if j < K + 1: for k in range(4): dp[i + 1][j][k] += dp[i][j...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER N...
You are given a grid, consisting of $2$ rows and $n$ columns. Each cell of this grid should be colored either black or white. Two cells are considered neighbours if they have a common border and share the same color. Two cells $A$ and $B$ belong to the same component if they are neighbours, or if there is a neighbour ...
n, k = map(int, input().split()) mod = 998244353 dp = [[[0, 0] for j in range(2 * n + 1)] for i in range(n)] dp[0][0][0] = dp[0][1][1] = 1 for i in range(1, n): for j in range(2 * n - 1): dp[i][j][0] += (dp[i - 1][j][0] + dp[i - 1][j][1] + dp[i - 1][j][1]) % mod dp[i][j + 1][0] += dp[i - 1][j][0] % ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR...
You are given a grid, consisting of $2$ rows and $n$ columns. Each cell of this grid should be colored either black or white. Two cells are considered neighbours if they have a common border and share the same color. Two cells $A$ and $B$ belong to the same component if they are neighbours, or if there is a neighbour ...
def main(): n, k = map(int, input().split(" ")) if k > 2 * n: return 0 if k == 2 * n or k == 1: return 2 iguales = [0] * (k + 1) diferentes = [0] * (k + 1) iguales[1] = 2 diferentes[2] = 2 modulo = 998244353 for i in range(1, n): auxigual, auxdiff = [0] * (k +...
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR BIN_OP NUMBER VAR RETURN NUMBER IF VAR BIN_OP NUMBER VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR N...
You are given a grid, consisting of $2$ rows and $n$ columns. Each cell of this grid should be colored either black or white. Two cells are considered neighbours if they have a common border and share the same color. Two cells $A$ and $B$ belong to the same component if they are neighbours, or if there is a neighbour ...
n, k = map(int, input().split()) mod = 998244353 NEXT = {(0, 1): 2, (1, 2): 2} for i in range(1, n): NOW = NEXT NEXT = dict() for key in NOW: if key[0] == 0: if k - (n - i) * 2 <= key[1] <= k: NEXT[key] = NEXT.get(key, 0) + NOW[key] if k - (n - i) * 2 < key[1]...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR ASSIGN VAR VAR BIN_OP F...
You are given a grid, consisting of $2$ rows and $n$ columns. Each cell of this grid should be colored either black or white. Two cells are considered neighbours if they have a common border and share the same color. Two cells $A$ and $B$ belong to the same component if they are neighbours, or if there is a neighbour ...
from sys import exit, stdin, stdout def sin(): return stdin.readline().rstrip() def listInput(): return list(map(int, sin().split())) def printBS(li): if not li: return for i in range(len(li) - 1): stdout.write("%d " % li[i]) stdout.write("%d\n" % li[-1]) N, K = listInput() M...
FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR RETURN FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER...
You are given a grid, consisting of $2$ rows and $n$ columns. Each cell of this grid should be colored either black or white. Two cells are considered neighbours if they have a common border and share the same color. Two cells $A$ and $B$ belong to the same component if they are neighbours, or if there is a neighbour ...
mod = 998244353 N, K = map(int, input().split()) dp = [[([0] * (K + 2)) for i in range(2)] for i in range(N)] dp[0][0][0] = 1 dp[0][1][1] = 1 for i in range(1, N): for b in range(K): dp[i][0][b] += dp[i - 1][0][b] dp[i][0][b] += dp[i - 1][1][b] dp[i][0][b] += dp[i - 1][1][b] dp[i][0]...
ASSIGN VAR NUMBER ASSIGN VAR 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 VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR VAR NUMBE...
You are given a grid, consisting of $2$ rows and $n$ columns. Each cell of this grid should be colored either black or white. Two cells are considered neighbours if they have a common border and share the same color. Two cells $A$ and $B$ belong to the same component if they are neighbours, or if there is a neighbour ...
n, k = list(map(int, input().split())) same = [0] * (k + 1) diff = [0] * (k + 1) mod = 998244353 same[1] = 2 if k > 1: diff[2] = 2 for i in range(n - 1): newsame = [0] * (k + 1) newdiff = [0] * (k + 1) for i in range(1, k + 1): newsame[i] = (same[i] + same[i - 1] + 2 * diff[i]) % mod for i i...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER B...
You are given a grid, consisting of $2$ rows and $n$ columns. Each cell of this grid should be colored either black or white. Two cells are considered neighbours if they have a common border and share the same color. Two cells $A$ and $B$ belong to the same component if they are neighbours, or if there is a neighbour ...
n, k = list(map(int, input().split())) limit = 998244353 if k > 2 * n: print(0) elif k == 1 or k == 2 * n: print(2) else: same = [0] * (k + 1) same[1] = 2 diff = [0] * (k + 1) diff[2] = 2 for i in range(2, n + 1): for j in range(min(k, 2 * i), 1, -1): same[j] = same[j] + ...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMB...
You are given a grid, consisting of $2$ rows and $n$ columns. Each cell of this grid should be colored either black or white. Two cells are considered neighbours if they have a common border and share the same color. Two cells $A$ and $B$ belong to the same component if they are neighbours, or if there is a neighbour ...
n, k = map(int, input().split()) mod = 998244353 dp = [[0, 0, 0, 0] for _ in range(k + 1)] dp[1][0] = dp[1][3] = 1 if k > 1: dp[2][2] = dp[2][1] = 1 for x in range(1, n): g = [[0, 0, 0, 0] for _ in range(k + 1)] g[1][0] = g[1][3] = 1 for i in range(2, k + 1): g[i][0] = (dp[i][0] + dp[i][1] + dp[...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST NU...
You are given a grid, consisting of $2$ rows and $n$ columns. Each cell of this grid should be colored either black or white. Two cells are considered neighbours if they have a common border and share the same color. Two cells $A$ and $B$ belong to the same component if they are neighbours, or if there is a neighbour ...
pri = 998244353 dp = [[[(0) for i in range(2001)] for i in range(1001)] for i in range(2)] n, k = map(int, input().split()) for i in range(1, n + 1): if i == 1: dp[0][i][1] = 2 dp[1][i][2] = 2 continue for j in range(1, 2 * i + 1): dp[0][i][j] = dp[0][i - 1][j] + dp[0][i - 1][j -...
ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL V...
Read problems statements in mandarin chinese, russian and vietnamese as well. Given a board of N rows and M columns, place the minimum number of knights such that every cell either contains a knight or is attacked by at least one knight. Like in standard chess, a knight attacks every cell that is two squares away ho...
for t in range(int(input())): N, M = map(int, input().split()) if M < N: N, M = M, N if N == 1: print(M) else: res = M // 6 * 4 if M % 6 > 0: if M % 6 == 1: res += 2 elif N == 3 and M > 12 and M % 6 == 2: res += 3 ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER BIN_OP ...
Read problems statements in mandarin chinese, russian and vietnamese as well. Given a board of N rows and M columns, place the minimum number of knights such that every cell either contains a knight or is attacked by at least one knight. Like in standard chess, a knight attacks every cell that is two squares away ho...
def knights(n, m): if n == 1: return m elif n == 2: if m == 1: return 2 else: table = [0, 2, 4, 4, 4, 4, 4] if m <= 6: return table[m] else: k = 0 while m > 6: m -= 6 ...
FUNC_DEF IF VAR NUMBER RETURN VAR IF VAR NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER IF VAR NUMBER RETURN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER RETURN BIN_OP VAR VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NU...
Given an integer n, you must transform it into 0 using the following operations any number of times: Change the rightmost (0th) bit in the binary representation of n. Change the ith bit in the binary representation of n if the (i-1)th bit is set to 1 and the (i-2)th through 0th bits are set to 0. Return the minimum n...
class Solution: def minimumOneBitOperations(self, n: int) -> int: if n <= 1: return n b = int(math.log2(n)) + 1 return (1 << b) - 1 - self.minimumOneBitOperations(n - (1 << b - 1))
CLASS_DEF FUNC_DEF VAR IF VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR
Given an integer n, you must transform it into 0 using the following operations any number of times: Change the rightmost (0th) bit in the binary representation of n. Change the ith bit in the binary representation of n if the (i-1)th bit is set to 1 and the (i-2)th through 0th bits are set to 0. Return the minimum n...
class Solution: def minimumOneBitOperations(self, n: int) -> int: s = 0 m = n while m: s += m & 1 m >>= 1 k = 1 while s: s -= bool(n & k) n ^= s & 1 and k k <<= 1 return n
CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER RETURN VAR VAR
Given an integer n, you must transform it into 0 using the following operations any number of times: Change the rightmost (0th) bit in the binary representation of n. Change the ith bit in the binary representation of n if the (i-1)th bit is set to 1 and the (i-2)th through 0th bits are set to 0. Return the minimum n...
class Solution: def minimumOneBitOperations(self, n: int) -> int: result = 0 while n: result = ((n & -n) << 1) - 1 - result n -= n & -n return result
CLASS_DEF FUNC_DEF VAR ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR BIN_OP VAR VAR RETURN VAR VAR
Given an integer n, you must transform it into 0 using the following operations any number of times: Change the rightmost (0th) bit in the binary representation of n. Change the ith bit in the binary representation of n if the (i-1)th bit is set to 1 and the (i-2)th through 0th bits are set to 0. Return the minimum n...
class Solution: def minimumOneBitOperations(self, n: int) -> int: if n == 0: return 0 if n == 1: return 1 tot = 0 b = bin(n)[2:] if b[1] == "0": tot += 2 ** (len(b) - 2) lastChanged = b[1] == "0" for i in range(2, len(b)): ...
CLASS_DEF FUNC_DEF VAR IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR VAR VAR STRING...
Please note the non-standard memory limit. There are n problems numbered with integers from 1 to n. i-th problem has the complexity c_i = 2^i, tag tag_i and score s_i. After solving the problem i it's allowed to solve problem j if and only if IQ < |c_i - c_j| and tag_i ≠ tag_j. After solving it your IQ changes and be...
import sys input = sys.stdin.readline t = int(input()) for tests in range(t): n = int(input()) Tag = list(map(int, input().split())) S = list(map(int, input().split())) DP = [0] * n ANS = 0 for i in range(1, n): MAX = 0 for j in range(i - 1, -1, -1): temp = DP[j] ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR ...
Please note the non-standard memory limit. There are n problems numbered with integers from 1 to n. i-th problem has the complexity c_i = 2^i, tag tag_i and score s_i. After solving the problem i it's allowed to solve problem j if and only if IQ < |c_i - c_j| and tag_i ≠ tag_j. After solving it your IQ changes and be...
def nr(): return int(input()) def nrs(): return [int(i) for i in input().split()] def f(n, t, s): d = [0] * n for i in range(1, n): for j in range(i - 1, -1, -1): if t[i] == t[j]: continue sc = abs(s[i] - s[j]) d[i], d[j] = max(d[i], d[j] +...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VA...
Please note the non-standard memory limit. There are n problems numbered with integers from 1 to n. i-th problem has the complexity c_i = 2^i, tag tag_i and score s_i. After solving the problem i it's allowed to solve problem j if and only if IQ < |c_i - c_j| and tag_i ≠ tag_j. After solving it your IQ changes and be...
for _ in range(int(input())): n = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) dp = [0] * n for i in range(n): for j in range(i - 1, -1, -1): if A[i] == A[j]: continue s = abs(B[i] - B[j]) dp[i], dp[j...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR 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 FOR VAR FUNC_CALL VAR BIN_OP VAR NUMB...
Please note the non-standard memory limit. There are n problems numbered with integers from 1 to n. i-th problem has the complexity c_i = 2^i, tag tag_i and score s_i. After solving the problem i it's allowed to solve problem j if and only if IQ < |c_i - c_j| and tag_i ≠ tag_j. After solving it your IQ changes and be...
def solve(): n = int(input()) c = list(map(int, input().split())) s = list(map(int, input().split())) ans = 0 dp = [0] * n for i in range(n): for j in range(i - 1, -1, -1): if c[i] != c[j]: tmp = dp[j] dp[j] = max(dp[j], dp[i] + abs(s[i] - s[j]...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR...
It has been truly said that love is not meant for everyone. Let me introduce you to a very sad story of my friend Broken Amit. Yes several times he has been left heartbroken. Looking at his poor condition even God is pity on him. God has given Amit a very nice opportunity to Kiss as many girls as he likes . There ar...
def sumlval(lst, n): res = 0 for i in range(n): res += lst[i][0] return res def update(lst, k, n): for i in range(k, n): lst[i][0] -= lst[i][1] * lst[i][2] n = int(input()) lval = list(map(int, input().split())) dval = list(map(int, input().split())) lst = [] for i in range(n): l...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR V...
n fish, numbered from 1 to n, live in a lake. Every day right one pair of fish meet, and the probability of each other pair meeting is the same. If two fish with indexes i and j meet, the first will eat up the second with the probability aij, and the second will eat up the first with the probability aji = 1 - aij. The ...
n = int(input()) b = [] for i in range(n): b.append(list(map(float, input().split()))) ma = 1 << n dp = [(0) for j in range(ma)] dp[0] = 1 for mask in range(1, ma): l = n - bin(mask).count("1") + 1 res = l * (l - 1) // 2 for i in range(n): if mask & 1 << i: for j in range(n): ...
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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CAL...
n fish, numbered from 1 to n, live in a lake. Every day right one pair of fish meet, and the probability of each other pair meeting is the same. If two fish with indexes i and j meet, the first will eat up the second with the probability aij, and the second will eat up the first with the probability aji = 1 - aij. The ...
import sys input = sys.stdin.readline def count_bits(x): cnt = 0 for i in range(n): if 1 << i & x: cnt += 1 return cnt n = int(input()) a = [list(map(float, input().split())) for i in range(n)] dp = [(0) for i in range(1 << n)] dp[-1] = 1 for mask in range((1 << n) - 1, -1, -1): ...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP NUMBER VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VA...
n fish, numbered from 1 to n, live in a lake. Every day right one pair of fish meet, and the probability of each other pair meeting is the same. If two fish with indexes i and j meet, the first will eat up the second with the probability aij, and the second will eat up the first with the probability aji = 1 - aij. The ...
n = int(input()) probs = list() for i in range(n): probs.append(list(map(float, input().split()))) dp = [list([(0) for i in range(1 << n)]) for i in range(n)] dp[0][(1 << n) - 1] = 1 ak = [list() for i in range(n + 1)] for i in range(1 << n): ak[bin(i).count("1")].append(i) for k in range(1, n): for ele in ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN V...
n fish, numbered from 1 to n, live in a lake. Every day right one pair of fish meet, and the probability of each other pair meeting is the same. If two fish with indexes i and j meet, the first will eat up the second with the probability aij, and the second will eat up the first with the probability aji = 1 - aij. The ...
from sys import stdin input = stdin.readline def count(n): value = 0 while n: n &= n - 1 value += 1 return value def nc2(n): return n * (n - 1) // 2 def answer(): dp = [0] * (1 << n) dp[(1 << n) - 1] = 1 for mask in range((1 << n) - 1, 0, -1): m = count(mask) ...
ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMB...
n fish, numbered from 1 to n, live in a lake. Every day right one pair of fish meet, and the probability of each other pair meeting is the same. If two fish with indexes i and j meet, the first will eat up the second with the probability aij, and the second will eat up the first with the probability aji = 1 - aij. The ...
n = int(input()) p = [] for i in range(n): la = list(map(float, input().split())) p.append(la) full_bit = (1 << n) - 1 dp = [0] * full_bit + [1] for i in range(full_bit, 0, -1): cunt = bin(i)[2:].count("1") if cunt == 1 or dp[i] == 0: continue mul = 1 / (cunt * (cunt - 1) >> 1) for x in ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FU...
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a...
import sys def get_ints(): return list(map(int, sys.stdin.readline().strip().split())) N = int(input()) nums = get_ints() s = sum(nums) dp = [False] * (s + 1) dp[0] = True for a in nums: for b in range(s - a, -1, -1): if dp[b]: dp[a + b] = True if s & 1 or not dp[s // 2]: print(0) el...
IMPORT FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER IF...
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a...
def partition(arr): n = len(arr) k = sum(arr) m = k // 2 p = [([False] * (n + 1)) for i in range(m + 1)] p[0] = [True] * (n + 1) for i in range(1, m + 1): for j in range(1, n + 1): x = arr[j - 1] if i - x >= 0: p[i][j] = p[i][j - 1] or p[i - x][j -...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VA...
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a...
import sys def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int, sys.stdin.readline().rstrip().split()) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) def LI2(): return list(map(int, sys.stdin.readline().rstrip())) def S(): return sys.stdin.re...
IMPORT FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL V...
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a...
def possible(nums, target): reach = {0} for num in nums: reach |= {(i + num) for i in reach if i + num <= target} if target in reach: return True return False n = int(input()) arr = list(map(int, input().split())) s = sum(arr) if s % 2 == 1 or not possible(arr, s // 2): print(0) el...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMB...
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a...
n = int(input()) a = list(map(int, input().split())) S = sum(a) dp = [False] * (S + 1) dp[0] = True for x in a: for y in range(S - x, -1, -1): dp[x + y] = dp[x + y] or dp[y] if S % 2 == 1 or not dp[S // 2]: print(0) exit() else: norm = 30 res = -1 for i, x in enumerate(a): cnt = ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR ...
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a...
import sys input = sys.stdin.readline n = int(input()) l = list(map(int, input().split())) dp = [([-1] * 200003) for _ in range(103)] def fun(i, s): if s == 0: return 1 if s < 0 or i >= n: return 0 if dp[i][s] != -1: return dp[i][s] v = fun(i + 1, s - l[i]) u = fun(i + 1, ...
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 NUMBER VAR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR FUNC_...
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a...
def isSubsetSum(arr, n, sm): subset = [[(False) for j in range(sm + 1)] for i in range(3)] for i in range(n + 1): for j in range(sm + 1): if j == 0: subset[i % 2][j] = True elif i == 0: subset[i % 2][j] = False elif arr[i - 1] <= j: ...
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_...
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a...
def highestPowerOf2(n): return n & ~(n - 1) def solve(a): s = sum(a) q, r = divmod(s, 2) if r == 1: return 0, 0 else: x = 1 for ai in a: x |= x << ai if not x >> q & 1: return 0, 0 else: powers2 = [highestPowerOf2(ai) for ...
FUNC_DEF RETURN BIN_OP VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER RETURN NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN NUMBER FUNC_CALL...
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a...
def answer(): s = sum(a) dp = [[(False) for i in range(s + 1)] for j in range(n + 1)] hs = False dp[0][0] = True for i in range(n): for j in range(s + 1): dp[i + 1][j] |= dp[i][j] if dp[i][j]: dp[i + 1][j + a[i]] = True if j == s - j: ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR N...
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a...
I = input IN = lambda x: map(int, x.split()) L = lambda x: list(IN(x)) n = int(I()) a = L(I()) def find(a, n): s = sum(a) if s % 2 == 1: print(0) return t = 1 for i in a: t |= t << i if t & 1 << s // 2: pass else: print(0) return z = 0 p ...
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP V...
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a...
import sys def zip_sorted(a, b): a, b = zip(*sorted(zip(a, b))) sorted(zip(a, b), key=lambda x: x[1]) return a, b def number_to_list(a): b = [] while a >= 1: c = a % 10 a = int(a / 10) b.append(c) return list(reversed(b)) def str_list_to_int_list(a): a = list(ma...
IMPORT FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR ...
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a...
def can1timsum(nums, i, val, memo={}): if val in memo: print(i, val, "in memo") return memo[val] if val == 0: return True if val < 0 or i < 0: return False result = can1timsum(nums, i - 1, val - nums[i], memo) or can1timsum( nums, i - 1, val, memo ) memo[v...
FUNC_DEF DICT IF VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING RETURN VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF DICT LIST IF VAR VAR ASSIG...
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a...
n = int(input()) a = list(map(int, input().split())) s = sum(a) if s % 2 == 1: print(0) exit() dp = [([False] * (s // 2 + 1)) for _ in range(n + 1)] dp[0][0] = True for i in range(n): for j in range(s // 2 + 1): if j < a[i]: dp[i + 1][j] = dp[i][j] else: dp[i + 1][j] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUM...
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a...
def check(l): for v in l: if v % 2 == 1: return False else: return True def findTargetSumWays(nums): sumAll = sum(nums) if 0 > sumAll or (0 + sumAll) % 2: return 0 target = (0 + sumAll) // 2 dp = [0] * (target + 1) dp[0] = 1 for num in nums: ...
FUNC_DEF FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR VAR FOR VAR FUNC_CALL...
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a...
maxn = 200700 n = int(input()) a = list(map(int, input().split())) dp = [0] * (2 * maxn) dp[0] = 1 s = sum(a) if s & 1: print(0) exit() for v in a: for i in range(s, -1, -1): dp[i + v] |= dp[i] if dp[s // 2] == 0: print(0) else: for i, v in enumerate(a, 1): if v & 1 or dp[(s - v) // ...
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FOR VAR VAR FOR VAR FUNC_CAL...
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a...
import sys reader = (s.rstrip() for s in sys.stdin) input = reader.__next__ n = int(input()) lst = list(map(int, input().split())) def can_partition(num): s = sum(num) if s % 2 != 0: return False dp = [[(-1) for x in range(int(s / 2) + 1)] for y in range(len(num))] return True if can_partitio...
IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR 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 FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMB...
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a...
input() aa = list(map(int, input().split())) ans = [] n = len(aa) saa = sum(aa) if saa & 1 == 0: k = saa // 2 dp = [([False] * (k + 1)) for _ in range(n + 1)] for i in range(n + 1): dp[i][0] = True for i in range(1, n + 1): for cs in range(1, k + 1): dp[i][cs] = dp[i - 1][cs]...
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL V...
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a...
from sys import stdin, stdout get_string = lambda: stdin.readline().strip(" ") get_intmap = lambda: map(int, get_string().split(" ")) def testcase(): n = int(input()) l = list(get_intmap()) suml = sum(l) if suml % 2 == 1: print(0) return dp = 1 for i in l: dp |= dp << ...
ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP ...
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a...
def good(a): s = sum(a) if s % 2 == 1: return False can = [False] * (s // 2 + 1) can[0] = True for e in a: for i in range(len(can) - 1 - e, -1, -1): if can[i]: can[i + e] = True return can[-1] def calc(n): r = 0 while n % 2 == 0: n //...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER RETURN VAR NUMBER ...
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a...
for _ in range(1): n = int(input()) a = list(map(int, input().split())) b = a[:] a.sort() a = a if sum(a) % 2 == 1: print(0) continue add = sum(a) arr1 = [0] * (add + 2) for i in range(n - 1): arr1[a[i]] = 1 for j in range(add, -1, -1): if ...
FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VA...
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a...
n = int(input()) a = list(map(int, input().split())) s = sum(a) if s % 2: print(0) exit() dp = [[(0) for i in range(s + 1)] for j in range(n)] for i in range(n): dp[i][0] = 1 dp[0][a[0]] = 1 for i in range(1, n): for j in range(1, s + 1): if j > a[i]: dp[i][j] = max(dp[i][j], dp[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 FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NU...
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a...
def bad(v): global n s = 0 for i in v: s += i if s % 2 != 0: return 0 b = 2**200005 for i in v: b |= b >> i r = b // 2 ** (200005 - s // 2) % 2 return r pw = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024] n = int(input()) m = [int(i) for i in input().split()] if bad...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER RETURN VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUM...
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a...
N = int(input()) A = list(map(int, input().split())) S = sum(A) if S % 2: print(0) exit() val = S // 2 num = [False] * 200001 num[0] = True for i in A: tmp = num[:] for j in range(200001): if tmp[j]: if j + i <= 200000: num[i + j] = True if not num[val]: print(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 FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR F...
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a...
def inp(): return [int(a) for a in input().split()] def gcd(x, y): if y: return gcd(y, x % y) else: return x def bad(array): st = set() st.add(0) for i in array: st1 = set() for j in st: st1.add(i + j) st = st.union(st1) if sum(array) /...
FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL...
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a...
import time def main(): n = i_input() a = li_input() p = [0] * n s = 0 for i, aa in enumerate(a): s += aa c = 0 while not aa % 2: aa //= 2 c += 1 p[i] = c if s % 2: print(0) return a.sort() limit = s // 2 l = [...
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN EXPR FUNC_CALL VAR ASSIGN V...
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a...
import sys def findMin(S, n): total = sum(S) T = [([False] * (total + 1)) for _ in range(len(S) + 1)] for i in range(len(S) + 1): T[i][0] = True j = 1 while i > 0 and j <= total: T[i][j] = T[i - 1][j] if S[i - 1] <= j: T[i][j] |= T[i - 1][j -...
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR...
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a...
from sys import stdin def read_int(): return int(stdin.readline()) def read_ints(): return map(int, stdin.readline().split(" ")) n = read_int() a = list(read_ints()) s = sum(a) if s % 2 == 1: print(0) exit(0) dp = [False] * (s // 2 + 1) dp[0] = True for ai in a: for j in range(s // 2, ai - 1, ...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP B...
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a...
N = int(input()) aa = [int(x) for x in input().split()] def get_max_pow2_factor(x): result = 0 cur_a = x while cur_a > 0 and cur_a % 2 == 0: cur_a //= 2 result += 1 return result shared_pow2_factor = min([get_max_pow2_factor(x) for x in aa]) if shared_pow2_factor > 0: aa = [(x //...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR VA...
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a...
n = int(input()) a = list(map(int, input().split())) s = sum(a) if s % 2 == 1: print(0) else: s = s // 2 dp = [[(False) for i in range(s + 1)] for _ in range(len(a) + 1)] for i in range(len(dp)): dp[i][0] = True for i in range(1, len(a) + 1): for j in range(1, s + 1): if ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBE...
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a...
import sys n = int(input()) a = [int(x) for x in input().split()] z = sum(a) if z % 2: print(0) sys.exit() s = set([0]) for x in a: s.update([(t + x) for t in s]) if z // 2 not in s: print(0) sys.exit() b = [(x & -x) for x in a] i = b.index(min(b)) print(f"1\n{i + 1}")
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR NUMBER VAR EXPR F...
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a...
import sys n = int(input()) array = [int(x) for x in input().split()] if sum(array) % 2 == 0: s = 1 for i in array: s |= s << i if s & 1 << sum(array) // 2: b = [(x & -x) for x in array] i = b.index(min(b)) print(f"1\n{i + 1}") sys.exit() print(0)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR VAR IF BIN_OP VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CA...
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a...
def solve(arr): s = sum(arr) if s & 1: print(0) return half = s // 2 dp = [False] * (half + 1) dp[0] = True for a in arr: if a > half: print(0) return for j in range(half, a - 1, -1): dp[j] = dp[j] or dp[j - a] if not dp[-1]...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR ...
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a...
n = int(input()) a = list(map(int, input().split())) sums = sum(a) b = [] for i in range(n): b.append([i + 1]) dp = dict(zip(a, b)) for i in range(n): for j in range(sums // 2, 0, -1): if j - a[i] in dp and i + 1 not in dp[j - a[i]]: dp[j] = list(dp[j - a[i]]) dp[j].append(i + 1)...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP...
Baby Ehab was toying around with arrays. He has an array $a$ of length $n$. He defines an array to be good if there's no way to partition it into $2$ subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in $a...
N = int(input()) A = list(map(int, input().split())) def findPartiion(arr, n): Sum = 0 for i in range(n): Sum += arr[i] if Sum % 2 != 0: return 0 part = [0] * (Sum // 2 + 1) for i in range(Sum // 2 + 1): part[i] = 0 for i in range(n): for j in range(Sum // 2, ar...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBE...