description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef's team is going to participate at the legendary math battles. One of the main task in the competition is to calculate the number of ways to create a number by adding some Chefonacci numbers. A number is called a Chefonacci number if it...
for _ in range(int(input())): x, k = (int(x) for x in input().split()) fib = [ 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 676...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMB...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef's team is going to participate at the legendary math battles. One of the main task in the competition is to calculate the number of ways to create a number by adding some Chefonacci numbers. A number is called a Chefonacci number if it...
fibo = [0] * 44 fibo[0], fibo[1] = 1, 2 for i in range(2, 44): fibo[i] = fibo[i - 1] + fibo[i - 2] def chefonnaci_number(x, k, idx): if k == 0: if x == 0: return 1 else: return 0 elif x == 0 or idx == 0: return 0 elif x >= 0 and x <= k * fibo[idx - 1]: ...
ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR BIN_OP VAR VAR B...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef's team is going to participate at the legendary math battles. One of the main task in the competition is to calculate the number of ways to create a number by adding some Chefonacci numbers. A number is called a Chefonacci number if it...
import sys sys.setrecursionlimit(10000000) N = 1000000000 fib = [1, 2] while True: val = fib[-1] + fib[-2] if val > N: break fib.append(val) def getans(i, x, k): if x < 0 or k == 0 and x > 0 or i < 0 or k * fib[i] < x: return 0 if x == 0 and k == 0: return 1 ans = geta...
IMPORT EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER WHILE NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP VAR VAR VAR VAR RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP FU...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef's team is going to participate at the legendary math battles. One of the main task in the competition is to calculate the number of ways to create a number by adding some Chefonacci numbers. A number is called a Chefonacci number if it...
MOD = 1000000007 fib = [1, 2] for i in range(2, 50): fib.append(fib[i - 1] + fib[i - 2]) def solve(x, k, n): if k == 0: return int(x == 0) ans = 0 for i in range(n, -1, -1): if fib[i] * k < x: return ans if fib[i] <= x: ans = (ans + solve(x - fib[i], k -...
ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR VAR RETURN VAR IF VAR VAR VAR A...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef's team is going to participate at the legendary math battles. One of the main task in the competition is to calculate the number of ways to create a number by adding some Chefonacci numbers. A number is called a Chefonacci number if it...
def solve(x, k, n): if k == 0: if x == 0: return 1 else: return 0 elif x == 0 or n == 0: return 0 else: total = solve(x, k, n - 1) if x >= chef[n - 1] and x <= k * chef[n - 1]: total += solve(x - chef[n - 1], k - 1, n) retur...
FUNC_DEF IF VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR RETURN VAR ASSIGN VAR BIN_...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef's team is going to participate at the legendary math battles. One of the main task in the competition is to calculate the number of ways to create a number by adding some Chefonacci numbers. A number is called a Chefonacci number if it...
mod = 10**9 + 7 fib = [1, 2] while fib[-1] < 10**9: fib.append(fib[-1] + fib[-2]) fibs = set(fib) cache = {} def ways(num, parts, maxused): if num == 0 and parts == 0: return 1 if parts == 0 or maxused == 1: return 0 if parts * maxused < num: return 0 if parts == 1: ...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER WHILE VAR NUMBER BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF BIN_OP VAR VAR VAR RETU...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef's team is going to participate at the legendary math battles. One of the main task in the competition is to calculate the number of ways to create a number by adding some Chefonacci numbers. A number is called a Chefonacci number if it...
cn = [0] * 44 cn[1], cn[0] = 2, 1 for i in range(2, 44): cn[i] = cn[i - 1] + cn[i - 2] def findWays(x, k, ind): if k == 0: return 1 if x == 0 else 0 elif x == 0 or ind == 0: return 0 else: if x >= 0 and k * cn[ind] >= x: return findWays(x - cn[ind - 1], k - 1, ind) ...
ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER BIN_OP VAR VAR VAR VAR RETURN ...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef's team is going to participate at the legendary math battles. One of the main task in the competition is to calculate the number of ways to create a number by adding some Chefonacci numbers. A number is called a Chefonacci number if it...
def chefonacci(n): f = [] for val in range(n): if val == 0: f.append(1) if val == 1: f.append(2) if val > 1: f.append(f[val - 1] + f[val - 2]) return f def F(x, k, n): if k > 0 and x < k * f[0] and x >= 0: return 0 if x < 0: ...
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF IF VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef's team is going to participate at the legendary math battles. One of the main task in the competition is to calculate the number of ways to create a number by adding some Chefonacci numbers. A number is called a Chefonacci number if it...
f = [1, 2] f1 = 1 f2 = 2 while True: f3 = f2 + f1 if f3 > 10**9: break f.append(f3) f1 = f2 f2 = f3 def F(x, k, n): if x < 0: return 0 if k == 0: if x == 0: return 1 else: return 0 if x == 0 or n == 0: return 0 total =...
ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER AS...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef's team is going to participate at the legendary math battles. One of the main task in the competition is to calculate the number of ways to create a number by adding some Chefonacci numbers. A number is called a Chefonacci number if it...
chef = [1, 2] i = 2 while chef[-1] < 10**9: chef.append(chef[i - 1] + chef[i - 2]) i += 1 cache = {} def fetch(X, K, i): if X in cache: if K in cache[X]: if i in cache[X][K]: return cache[X][K][i] return -1 def store(X, K, i, val): if X not in cache: c...
ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR DICT FUNC_DEF IF VAR VAR IF VAR VAR VAR IF VAR VAR VAR VAR RETURN VAR VAR VAR VAR RETURN NUMBER FUNC_DEF IF VAR VAR ASSIGN VAR VAR DICT IF VAR...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
class Solution: def isKPartitionPossible(self, a, k): if sum(a) % k != 0: return 0 target = sum(a) // k vis = [False] * len(a) def recurse(i, l, k): if l == target: return recurse(0, 0, k - 1) if k == 0: return Tru...
CLASS_DEF FUNC_DEF IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR RETURN FUNC_CALL VAR NUMBER NUMBER BIN_OP VAR NUMBER IF VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMB...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
def k_subset_possible( input_arr: [], index, n, k, result_arr: [], sum_path_arr: [], required_sum ): if index > n: return if index == n: for i in range(k): element = sum_path_arr[i] if element != required_sum: return result_arr[0] = True ...
FUNC_DEF LIST LIST LIST IF VAR VAR RETURN IF VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR RETURN ASSIGN VAR NUMBER NUMBER RETURN ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR VAR...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
class Solution: def isKPartitionPossible(self, a, k): s = sum(a) if s % k != 0: return 0 s = s // k def manu(i, subnum, picked, s, cursum): if subnum == k + 1: return True if cursum == s: return manu(0, subnum + 1,...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR FUNC_DEF IF VAR BIN_OP VAR NUMBER RETURN NUMBER IF VAR VAR RETURN FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR VAR RETURN NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR VAR NUMBER RETUR...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
def kPartation(arr, i, k): if i >= len(arr): for j in range(1, len(k)): if k[j - 1] != k[j]: return False return True res = False for n in range(len(k)): if k[n] == 0: k[n] = k[n] + arr[i] res = res or kPartation(arr, i + 1, k) ...
FUNC_DEF IF VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR IF VAR NU...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
class Solution: def isKPartitionPossible(self, a, k): total = sum(a) if total % k != 0: return False share = total // k n = len(a) subset = [0] * n prev_choice = [-1] * n possible = False ind = 0 sub = 1 summation = 0 ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR ...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
class Solution: def __init__(self): self.flag = False def KPartition(self, indx, nos, k, n, a, sum, ans): if indx == n: if nos == k: f = True for i in range(k - 1): if sum[i] != sum[i + 1]: f = False ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR IF VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER RETURN FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
class Solution: def isKPartitionPossible(self, a, k): if not a: return s = sum(a) if s % k != 0: return False div = s // k sides = [0] * k a.sort(reverse=True) def dfs(i): if i == len(a): return True ...
CLASS_DEF FUNC_DEF IF VAR RETURN ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR IF VAR NUMBER VAR VAR VAR BIN...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
class Solution: def isKPartitionPossible(self, a, k): def help(i): if i == len(a): for i in arr: if i != n: return False return True for j in range(len(arr)): if arr[j] + a[i] <= n: ...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER RETURN NUMBER VAR VAR VAR VAR IF VAR VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR BIN_OP F...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
class Solution: def solve(self, a, k, sum1, index, visited, subset, reqsum): if subset == k: return True if sum1 == 0: return self.solve(a, k, reqsum, 0, visited, subset + 1, reqsum) if index == len(a): return False if sum1 >= a[index] and visited...
CLASS_DEF FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
class Solution: def isKPartitionPossible(self, a, k): n = len(a) a.sort(reverse=True) Sum = sum(a) if Sum % k: return False used = [False] * n target = Sum // k def dfs(ind, total, k): if k == 0: return True ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VA...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
class Solution: def isKPartitionPossible(self, nums, K): T = sum(nums) if T % K: return False N = len(nums) T = T // K taken = [False] * N d = {} def helper(S, K, curr): if K == 0: return True if S > T: ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR DICT FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR VAR NONE NONE RETURN VAR VAR VAR IF VAR VAR ASSIGN V...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
class Solution: def solvepartition(self, idx, a, k, reqdsum, used, subsetsum): if k == 0: return True if subsetsum == reqdsum: return self.solvepartition(0, a, k - 1, reqdsum, used, 0) for i in range(idx, len(arr)): if i > 0 and not used[i - 1] and arr[i]...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUM...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
class Solution: def is_possible(self, idx, res, subset_sums, a, k): if idx == len(a): if k == 0: for i in range(len(subset_sums) - 1): if subset_sums[i] != subset_sums[i + 1]: return False return True return...
CLASS_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR IF FUNC_CALL V...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
class Solution: def isKPartitionPossible(self, a, k): if k == 1: return True if len(a) < k: return False if sum(a) % k != 0: return False sum_num = sum(a) // k used = [0] * len(a) self.res = False def dfs(index, cur, depth...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR VAR RETURN NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR RETURN FUNC_CALL VAR NUMBER NU...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
class Solution: def isKPartitionPossible(self, a, k): n = len(a) used = [False] * n if sum(a) % k: return False target = sum(a) // k def dfs(ind, total, k): if k == 0: return True if total == 0: return dfs(...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR IF BIN_OP FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR ...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
class Solution: def isKPartitionPossible(self, a, k): n = len(a) target = sum(a) // k subset = [0] * k def func(ind, n, k, a, taregt, subset): if ind == n: return True for j in range(k): if subset[j] + a[ind] <= target: ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF IF VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR RETURN NUMBER VAR VAR VAR VAR IF VAR ...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
class Solution: def recsol2(self, set_arr, set_idx, set_sum, req_sum, k, istaken): if set_sum == req_sum: if set_idx == k - 2: return True return self.recsol2(set_arr, set_idx + 1, 0, req_sum, k, istaken) for j in range(len(set_arr)): if istaken[j...
CLASS_DEF FUNC_DEF IF VAR VAR IF VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
class Solution: def isKPartitionPossible(self, a, k): res = [] def solve(a, s, p, k, vis, i, n): if k == 0: return True if s > p: return False if s == p: return solve(a, 0, p, k - 1, vis, 0, n) for i in...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN NUMBER IF VAR VAR RETURN FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
class Solution: def isKPartitionPossible(self, a, k): total = sum(a) if total % k: return False a.sort(reverse=True) target = total // k subsets = [0] * k def backtrack(i): if i == len(a): return True for j in rang...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
class Solution: def isKPartitionPossible(self, a, k): dp = [-1] * (1 << 12) dp[0] = 0 n = len(a) summ = sum(a) if summ % k != 0: return False target = summ // k for mask in range(1 << n): if dp[mask] == -1: continue ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
class Solution: def isKPartitionPossible(self, a, k): a.sort(reverse=True) summa = sum(a) target = summa // k if summa % k or max(a) > target: return 0 output = 0 for item in a: output += self.helper(item, item, target, a.copy()) retur...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR RETURN VAR FUNC_DEF EXPR FUNC_CALL VAR VAR IF VAR RETURN NUMBER IF VAR VAR ASSIGN VAR NUMBER...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
class Solution: def isKPartitionPossible(self, nums, k): nums.sort() target, rem = divmod(sum(nums), k) if rem or nums[-1] > target: return False dp = [False] * (1 << len(nums)) dp[0] = True total = [0] * (1 << len(nums)) for state in range(1 << l...
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER VAR RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL ...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
class Solution: def isKPartitionPossible(self, a, k): if k < 2: return k if sum(a) % k: return False n = len(a) arr = [False] * n def helper(summ, s, k, arr, ind, n, a): if k == 1: return True if summ > s: ...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN VAR IF BIN_OP FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN NUMBER IF VAR VAR RETURN FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
class Solution: def find(self, i, a, d, gs, x, s): if x == 1: return True if gs == s: return self.find(0, a, d, 0, x - 1, s) for j in range(i, N): if not d[j]: d[j] = True if self.find(j + 1, a, d, gs + a[j], x, s): ...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN FUNC_CALL VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR NUMBER RETURN NUMBER FUNC_DEF ASSIG...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
def isKPartitionPossibleRec(arr, subsetSum, taken, subset, K, N, curIdx, limitIdx): if subsetSum[curIdx] == subset: if curIdx == K - 2: return True return isKPartitionPossibleRec( arr, subsetSum, taken, subset, K, N, curIdx + 1, N - 1 ) for i in range(limitIdx, -1...
FUNC_DEF IF VAR VAR VAR IF VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR V...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
class Solution: def isKPartitionPossible(self, a, k): def foo(a, i, k, n, grp, g): if n == i: return len(set(grp)) == 1 for j in range(k): if grp[j] + a[i] > g: continue grp[j] += a[i] res = foo(a, ...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR IF VAR RETURN NUMBER VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP FUN...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
class Solution: def isKPartitionPossible(self, a, k): def solve(i, a, n, k, target, visit, cnt, cursum): if cursum == target: cursum = 0 cnt += 1 return solve(0, a, n, k, target, visit, cnt, cursum) if cnt == k + 1: re...
CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER RETURN NUMBER IF VAR VAR RETURN NUMBER IF VAR VAR RETURN NUMBER IF VAR VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
class Solution: def isKPartitionPossible(self, array, k): i = 0 n = len(array) zeroscount = 0 holdanswer = [(0) for i in range(k)] hold = self.solve(i, zeroscount, array, holdanswer, k, n) return hold def isPossible(self, result, k): hold = result[0] ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR VAR IF VAR VAR IF FUNC_CALL VAR VAR VA...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
class Solution: def isKPartitionPossible(self, a, k): if not sum(a) % k == 0: return False def dfs(curr, k, a): if curr > target: return False if curr == target: k -= 1 curr = 0 if not a: ...
CLASS_DEF FUNC_DEF IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER RETURN NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR RETURN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER EXPR FUNC_C...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
class Solution: def isKPartitionPossible(self, array, k): self.result = list() i = 0 n = len(array) zeroscount = 0 holdanswer = [(0) for i in range(k)] self.solve(i, zeroscount, array, holdanswer, k, n) if self.isPossible(k): return 1 retu...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
class Solution: def isKPartitionPossible(self, a, k): if sum(a) % k: return False a.sort() visited = set() target = sum(a) / k def backtrack(idx, count, currsum): if count == k: return True if currsum == target: ...
CLASS_DEF FUNC_DEF IF BIN_OP FUNC_CALL VAR VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR RETURN FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER BIN_OP VAR NUMB...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
def helper(i, reqSum, nums, subset, k): if i == len(nums): return True for j in range(k): if subset[j] + nums[i] <= reqSum: subset[j] += nums[i] if helper(i + 1, reqSum, nums, subset, k): return True subset[j] -= nums[i] if subset[j...
FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR RETURN NUMBER VAR VAR VAR VAR IF VAR VAR NUMBER RETURN NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR IF BI...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
class Solution: def solve(self, arr, ind, sum1, tar, k): if k == 0: return True if sum1 == tar: return self.solve(arr, 0, 0, tar, k - 1) for j in range(ind, len(arr)): if vis[j] or arr[j] + sum1 > tar: continue vis[j] = 1 ...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN FUNC_CALL VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR NUMBER...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
class Solution: def isKPartitionPossible(self, a, k): n = len(a) target = sum(a) // k subset = [False] * n if sum(a) % k: return False def recur(ind, k, subsetsum): if k == 0: return True if subsetsum == target: ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR IF BIN_OP FUNC_CALL VAR VAR VAR RETURN NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR BIN_OP VAR...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
class Solution: def isKPartitionPossible(self, a, k): _sum = sum(a) n = len(a) if n < k or _sum % k != 0: return False target = _sum // k used = [False] * n def helper(sum, index, id): nonlocal a, n, k, target, used if sum == targ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF IF VAR VAR IF VAR VAR RETURN NUMBER RETURN FUNC_CALL VAR NUMBER NUMBER BIN_OP VAR NUMBER IF VAR VAR RETURN NUMBER FOR VAR FUNC_...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
class Solution: def __init__(self): self.flag = False def KPartition(self, indx, n, a, k, subsetsum, dp, nos): if indx == n: if nos == k: for i in range(k - 1): if subsetsum[i] != subsetsum[i + 1]: return s...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER RETURN ASSIGN VAR NUMBER RETURN FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR V...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
class Solution: def isKPartitionPossible(self, a, k): arr = [[] for i in range(k)] n = len(a) fill = 0 ans = [0] if k == 1: return True def sol(i, fill, n): if i == n: if fill == k: s = sum(arr[0]) ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER IF VAR NUMBER RETURN NUMBER FUNC_DEF IF VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR IF VAR FUNC_CALL VAR VAR RETURN VAR NUMBER NUMBER RETURN RETURN FOR VAR FUNC_CALL VAR ...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
class Solution: def isKPartitionPossible(self, a, k): s = sum(a) if s % k != 0: return False e = s / k a.sort(reverse=True) visited = [False] * len(a) def dfs(kleft, cursum, start): if kleft == 1: return True if cu...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_C...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
class Solution: def isKPartitionPossible(self, a, k): if sum(a) % k != 0: return False target = sum(a) // k used = [(False) for i in range(len(a))] def backtrack(index, k, subsetSum): if k == 0: return True if subsetSum == target:...
CLASS_DEF FUNC_DEF IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VA...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
class Solution: def part(self, i, a, k, target, subsetsum, used): if k == 0: return True if subsetsum == target: return self.part(0, a, k - 1, target, 0, used) for j in range(i, len(a)): if a[j] + subsetsum > target or used[j] == True: con...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR VAR VAR VAR RETURN NUMBER ASSIGN...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
class Solution: def isKPartitionPossible(self, arr, k): n = len(arr) ans = [False] visited = [0] * n sum_arr = sum(arr) if k == 1: return True if sum_arr % k: return False target = sum_arr // k def rec(i, total, j): ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR FUNC_DEF IF VAR NUMBER IF VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER EXPR FUNC_CALL V...
Given an integer array a[ ] of N elements and an integer K, the task is to check if the array a[ ] could be divided into K non-empty subsets with equal sum of elements. Note: All elements of this array should be part of exactly one partition. Example 1: Input: N = 5 a[] = {2,1,4,5,6} K = 3 Output: 1 Explanation: we c...
class Solution: def solve(self, arr, idx, k, curSum, target, taken): if k == 0: return 1 if curSum == target: return self.solve(arr, 0, k - 1, 0, target, taken) for j in range(idx, len(arr)): if taken[j] == True or curSum + arr[j] > target: ...
CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR VAR RETURN NUMBER ASSIGN...
Innokenty works at a flea market and sells some random stuff rare items. Recently he found an old rectangular blanket. It turned out that the blanket is split in $n \cdot m$ colored pieces that form a rectangle with $n$ rows and $m$ columns. The colored pieces attracted Innokenty's attention so he immediately came up...
n, m = map(int, input().split()) grid = [] for i in range(n): s = input() grid.append(s) grid2 = [] for i in range(n): grid2.append([]) for j in range(m): grid2[-1].append(0) for j in range(m): lastchar = "" int1 = 0 int2 = 0 int3 = 0 for i in range(n): if grid[i][j] ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSI...
Innokenty works at a flea market and sells some random stuff rare items. Recently he found an old rectangular blanket. It turned out that the blanket is split in $n \cdot m$ colored pieces that form a rectangle with $n$ rows and $m$ columns. The colored pieces attracted Innokenty's attention so he immediately came up...
H, W = map(int, input().split()) G = [[(ord(s) - 96) for s in input().strip()] for _ in range(H)] G = list(map(list, zip(*G))) A = [None] * W B = [None] * W Col = [None] * W Dic = [None] * W for j, Gi in enumerate(G): pre = -1 D = [None] * H con = 0 ctr = 0 E = [None] * H F = [] for i, g in ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR BI...
Innokenty works at a flea market and sells some random stuff rare items. Recently he found an old rectangular blanket. It turned out that the blanket is split in $n \cdot m$ colored pieces that form a rectangle with $n$ rows and $m$ columns. The colored pieces attracted Innokenty's attention so he immediately came up...
n, m = map(int, input().split()) a = [] flagTable = [[0] * m] * n totalFlagNum = 0 def countFlagNum(x): y = 0 flagNum = 0 while y < m: curColor = a[x][y] colorCountByX = 1 isItFlag = True while x + colorCountByX < n and a[x + colorCountByX][y] == curColor: color...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST BIN_OP LIST NUMBER VAR VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBE...
Innokenty works at a flea market and sells some random stuff rare items. Recently he found an old rectangular blanket. It turned out that the blanket is split in $n \cdot m$ colored pieces that form a rectangle with $n$ rows and $m$ columns. The colored pieces attracted Innokenty's attention so he immediately came up...
a, b = map(int, input().split()) c = [([0] * b) for i in range(a)] d = [input() for i in range(a)] for j in range(b): n = [] pred = d[0][j] cnt = 1 for i in range(1, a): if d[i][j] == pred: cnt += 1 else: n.append((cnt, pred)) cnt = 1 pred = d[...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_C...
Innokenty works at a flea market and sells some random stuff rare items. Recently he found an old rectangular blanket. It turned out that the blanket is split in $n \cdot m$ colored pieces that form a rectangle with $n$ rows and $m$ columns. The colored pieces attracted Innokenty's attention so he immediately came up...
from sys import stdin, stdout n, m = list(map(int, stdin.readline().split())) t = [[(0) for i in range(m)] for j in range(n)] for i in range(n): s = stdin.readline().strip() for j, c in enumerate(s): t[i][j] = c begins = [[(False) for i in range(m)] for j in range(n)] lens = [[(0) for i in range(m)] fo...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR ...
Innokenty works at a flea market and sells some random stuff rare items. Recently he found an old rectangular blanket. It turned out that the blanket is split in $n \cdot m$ colored pieces that form a rectangle with $n$ rows and $m$ columns. The colored pieces attracted Innokenty's attention so he immediately came up...
n, m = list(map(int, input().split())) a = [input() for i in range(n)] b, c = [[(0) for i in range(m)] for j in range(n)], 0 for i in range(n): for j in range(m): if i == 0 or a[i][j] != a[i - 1][j]: b[i][j] = 1 else: b[i][j] = b[i - 1][j] + 1 w = 0 for i in range(2, n): ...
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER...
Innokenty works at a flea market and sells some random stuff rare items. Recently he found an old rectangular blanket. It turned out that the blanket is split in $n \cdot m$ colored pieces that form a rectangle with $n$ rows and $m$ columns. The colored pieces attracted Innokenty's attention so he immediately came up...
import sys input = lambda: sys.stdin.readline().strip() def f(A, r, c, l): q, w, e = A[r][c][0], A[r][c - l][0], A[r][c - 2 * l][0] x, y, z = A[r][c][1], A[r][c - l][1], A[r][c - 2 * l][1] if x != y and y != z and e >= l and w == q == l: return l, z, y, x else: return 0 r, c = map(i...
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR BIN_OP NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR VAR RETURN...
Innokenty works at a flea market and sells some random stuff rare items. Recently he found an old rectangular blanket. It turned out that the blanket is split in $n \cdot m$ colored pieces that form a rectangle with $n$ rows and $m$ columns. The colored pieces attracted Innokenty's attention so he immediately came up...
n, m = map(int, input().split()) grid = [] d = {} flags = 0 for i in range(n): grid.append(input()) for j in range(m): b = 0 while b < n - 1: i = b k = i while k < n and grid[k][j] == grid[i][j]: k += 1 c1 = k - i clr1 = grid[k - 1][j] i = k ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASS...
Innokenty works at a flea market and sells some random stuff rare items. Recently he found an old rectangular blanket. It turned out that the blanket is split in $n \cdot m$ colored pieces that form a rectangle with $n$ rows and $m$ columns. The colored pieces attracted Innokenty's attention so he immediately came up...
def return_specific_col(matrix, col_index): col = [] for i in range(len(matrix)): col.append(matrix[i][col_index]) return col def make_list_to_str(lst): result = "" for e in lst: result += e return result def find_strikes(lst): first = lst[0] counter = 1 strikes_l...
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR STRING FOR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP ...
Innokenty works at a flea market and sells some random stuff rare items. Recently he found an old rectangular blanket. It turned out that the blanket is split in $n \cdot m$ colored pieces that form a rectangle with $n$ rows and $m$ columns. The colored pieces attracted Innokenty's attention so he immediately came up...
import sys def __starting_point(): n, m = list(map(int, input().split())) arr = sys.stdin.readlines() f = 0 flgs = {} for c in range(m): cnts = [[arr[0][c], 1]] for r in range(1, n): if arr[r][c] == cnts[-1][0]: cnts[-1][1] += 1 else: ...
IMPORT FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST LIST VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL...
Innokenty works at a flea market and sells some random stuff rare items. Recently he found an old rectangular blanket. It turned out that the blanket is split in $n \cdot m$ colored pieces that form a rectangle with $n$ rows and $m$ columns. The colored pieces attracted Innokenty's attention so he immediately came up...
n, m = map(int, input().split()) up = [[(0) for j in range(m)] for i in range(n)] ldw = [[(0) for j in range(m)] for i in range(n)] lup = [[(0) for j in range(m)] for i in range(n)] v = [] for i in range(n): v.append(input()) for i in range(n): for j in range(m): if not i or v[i][j] != v[i - 1][j]: ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FO...
Innokenty works at a flea market and sells some random stuff rare items. Recently he found an old rectangular blanket. It turned out that the blanket is split in $n \cdot m$ colored pieces that form a rectangle with $n$ rows and $m$ columns. The colored pieces attracted Innokenty's attention so he immediately came up...
def test_c(n, m, G): mid = [[(False) for i in range(m)] for j in range(n)] vis = [[(False) for i in range(m)] for j in range(n)] L = [[(1) for i in range(m)] for j in range(n)] for i in range(1, n): for j in range(m): if G[i][j] != G[i - 1][j]: mid[i][j] = True fo...
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER...
Innokenty works at a flea market and sells some random stuff rare items. Recently he found an old rectangular blanket. It turned out that the blanket is split in $n \cdot m$ colored pieces that form a rectangle with $n$ rows and $m$ columns. The colored pieces attracted Innokenty's attention so he immediately came up...
def number_rectangle(h): l = [(0) for i in range(len(h))] stack = [] dp = [(0) for i in range(len(h))] result = 0 for i in range(len(h)): while len(stack) > 0 and stack[-1] >= h[i]: stack.pop() if len(stack) == 0: dp[i] = i + 1 else: dp[i] ...
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER...
Innokenty works at a flea market and sells some random stuff rare items. Recently he found an old rectangular blanket. It turned out that the blanket is split in $n \cdot m$ colored pieces that form a rectangle with $n$ rows and $m$ columns. The colored pieces attracted Innokenty's attention so he immediately came up...
def main(): buf = input() buflist = buf.split() n = int(buflist[0]) m = int(buflist[1]) blanket = [] for i in range(n): buf = input() blanket.append(buf) dp = [[]] for j in range(m + 1): dp[0].append([0, (0, "0"), (0, "0"), (0, "0"), 0]) for i in range(n): ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER LIST NUMBER ...
Innokenty works at a flea market and sells some random stuff rare items. Recently he found an old rectangular blanket. It turned out that the blanket is split in $n \cdot m$ colored pieces that form a rectangle with $n$ rows and $m$ columns. The colored pieces attracted Innokenty's attention so he immediately came up...
n, m = [int(i) for i in input().split()] data = [] for i in range(n): data.append(list(input())) f = [] for i in range(m): temp = [] prev = 0 cnt = 0 for j in range(n): ch = ord(data[j][i]) - 95 if ch == prev: cnt += 1 else: temp.append((prev, cnt, j -...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER...
Innokenty works at a flea market and sells some random stuff rare items. Recently he found an old rectangular blanket. It turned out that the blanket is split in $n \cdot m$ colored pieces that form a rectangle with $n$ rows and $m$ columns. The colored pieces attracted Innokenty's attention so he immediately came up...
n, m = map(int, input().split()) board = [input() for _ in range(n)] u = [[(1) for _ in range(m)] for _ in range(n)] l = [[(1) for _ in range(m)] for _ in range(n)] for i in range(1, n): for j in range(m): if board[i][j] == board[i - 1][j]: u[i][j] = u[i - 1][j] + 1 for j in range(1, m): for...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP VAR NUM...
Innokenty works at a flea market and sells some random stuff rare items. Recently he found an old rectangular blanket. It turned out that the blanket is split in $n \cdot m$ colored pieces that form a rectangle with $n$ rows and $m$ columns. The colored pieces attracted Innokenty's attention so he immediately came up...
n, m = map(int, input().split()) A = [input() for _ in range(n)] Dx = [[0] for _ in range(n)] Dy = [[0] for _ in range(m)] for i in range(n): last = None k = 0 for j in range(m): c = A[i][j] if c != last: k = 0 k += 1 last = c Dx[i].append(k) for j in rang...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NONE ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR ASSIGN...
Innokenty works at a flea market and sells some random stuff rare items. Recently he found an old rectangular blanket. It turned out that the blanket is split in $n \cdot m$ colored pieces that form a rectangle with $n$ rows and $m$ columns. The colored pieces attracted Innokenty's attention so he immediately came up...
n, m = [int(x) for x in input().split()] a = [([] * (m + 1)) for i in range(n + 1)] cols = [([0] * (m + 1)) for i in range(n + 1)] rows = [([0] * (m + 1)) for i in range(n + 1)] a[0] = "*" * (m + 1) for i in range(1, n + 1): a[i] = "*" + input() for i in range(1, n + 1): for j in range(1, m + 1): if a[i...
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST BIN_OP VAR NUMBER VAR FUNC_CALL 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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUM...
You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes. Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-...
s = input() n = len(s) f = False for i in range(n): for j in range(i + 1, n): for k in range(j + 1, n): if ( not f and not s[i] == s[j] == s[k] == "0" and int(s[i] + s[j] + s[k]) % 8 == 0 ): f = True prin...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR VAR VAR STRING BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER EXPR ...
You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes. Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-...
n = input() ans = -1 def findNum(num): j = 0 for i in n: if i == str(num)[j]: j += 1 if j == len(str(num)): return True return False for i in range(0, 999, 8): if findNum(i): ans = i break if ans == -1: print("NO") else: print("YES") ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CA...
You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes. Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-...
n = input() for i in range(len(n)): if int(n[i]) % 8 == 0: print("YES") print(n[i]) exit(0) for i in range(len(n)): for j in range(0, i): if (int(n[j]) * 10 + int(n[i])) % 8 == 0: print("YES") print(n[j] + n[i]) exit(0) for i in range(len(n)): ...
ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC...
You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes. Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-...
def func(s, i, ans, b): if ans % 8 == 0 and b: return ans if i < 0: return -1 if ans > 99: return -1 x = func(s, i - 1, ans, b) if x != -1: return x if ans > 9: ans += 100 * int(s[i]) return func(s, i - 1, ans, b) elif ans > 0: ans += 1...
FUNC_DEF IF BIN_OP VAR NUMBER NUMBER VAR RETURN VAR IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER RETURN VAR IF VAR NUMBER VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER VAR BIN_OP NU...
You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes. Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-...
N = list(input()) M = len(N) for i in N: if int(i) % 8 == 0: print("YES") print(i) exit() for i in range(M - 1): for j in range(i, M): if int(N[i] + N[j]) % 8 == 0: print("YES") print(N[i] + N[j]) exit() for i in range(M - 2): for j in rang...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER NUMBER...
You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes. Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-...
a = input()[::-1] u = [False] * 3 t4 = 0 done = False for i in a: j = int(i) if j % 2: if t4: print("YES\n" + i + t4) done = True break if j % 4 == 1: if u[2]: print("YES\n" + i + "6") done = True bre...
ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP STRIN...
You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes. Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-...
s = str(input()) if len(s) < 3: a = list(map(str, list(range(0, 100, 8)))) if s in a: print("YES") print(s) quit() else: if len(s) == 1: print("NO") quit() if len(s) == 2: if str(s[0]) in a: print("YES") ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF FUNC_C...
You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes. Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-...
class Solver: def __init__(self): self.n = None def main(self): self.n = input().strip() l = len(self.n) for i in range(l): i1 = int(self.n[i]) if i1 % 8 == 0: print("Yes\n{}".format(i1)) return for j in range(...
CLASS_DEF FUNC_DEF ASSIGN VAR NONE FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VA...
You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes. Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-...
def check2(s): if int(s) % 8 == 0: return s elif int(s[0]) % 8 == 0: return s[0] elif int(s[1]) % 8 == 0: return s[1] else: return -1 def check3(s): if int(s) % 8 == 0: return s if int(s[2]) % 8 == 0: return s[2] if int(s[1]) % 8 == 0: ...
FUNC_DEF IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER RETURN VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER RETURN VAR NUMBER RETURN NUMBER FUNC_DEF IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER...
You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes. Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-...
n = int(input()) solved = 0 if "0" in str(n): print("YES") print(0) solved = 1 elif "8" in str(n): print("YES") print(8) solved = 1 if solved == 0: nstr = str(n) for i in range(len(str(n))): for j in range(i + 1, len(str(n))): if (int(nstr[i]) * 10 + int(nstr[j])) % 8...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FU...
You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes. Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-...
if True: s = input() for ans in range(0, 1000, 8): i = -1 for x in str(ans): i = s.find(x, i + 1) if i < 0: break else: print("YES") print(ans) break else: print("NO") exit()
IF NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes. Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-...
import sys reader = (s.rstrip() for s in sys.stdin) input = reader.__next__ def solve(num): for x in range(len(num)): if int(num[x]) % 8 == 0: return "YES\n" + num[x] + "\n" for y in range(x + 1, len(num)): if int(num[x] + num[y]) % 8 == 0: return "YES\n" +...
IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER RETURN BIN_OP BIN_OP STRING VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER NUMBER RETURN B...
You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes. Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-...
n = input() m = len(n) if "0" in n: print("YES") print(0) elif "8" in n: print("YES") print(8) else: f = 0 for i in range(m): for j in range(i + 1, m): if int(n[i] + n[j]) % 8 == 0: f = 1 out = int(n[i] + n[j]) break if f ==...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR...
You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes. Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-...
x = input() if x.count("8") > 0: print("YES") print(8) elif x.count("0") > 0: print("YES") print(0) else: ok = False for a in range(len(x)): for b in range(a + 1, len(x)): if int(x[a] + x[b]) % 8 == 0: ok = True print("YES") pri...
ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP FUN...
You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes. Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-...
n = input() f = 0 for i in n: if i == "0": f = 1 break if f == 1: print("YES") print(0) elif len(n) == 1: if int(n) % 8 == 0: print("YES") print(int(n)) else: print("NO") elif len(n) == 2: if int(n) % 8 == 0: print("YES") print(int(n)) ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING IF FUNC_...
You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes. Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-...
def solve(s): for i in range(len(s)): a = int(s[i]) if a % 2 != 0: continue if a % 8 == 0: print("YES") print(a) return for j in range(i + 1, len(s)): b = int(s[j]) * 10 + a if b % 4 != 0: continu...
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR IF BIN_OP ...
You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes. Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-...
a = input() n = len(a) can = False ans = 0 for i in range(n): t = int(a[i]) if t % 8 == 0: can = True ans = t break for j in range(i + 1, n): t = int(a[i] + a[j]) if t % 8 == 0: ans = t can = True break for k in range(j + 1,...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR NUMB...
You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes. Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-...
a, s = [str(8 * x) for x in range(125)], input() for num in a: p = -1 for d in num: p = s.find(d, p + 1) if p == -1: break else: print("YES\n{}".format(num)) break else: print("NO")
ASSIGN VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR STRING
You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes. Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-...
def read(): a = input().strip() return a def find(a, n): pos = 0 for c in n: pos = a.find(c, pos) + 1 if pos == 0: break if pos: return n def solve(): if len(a) >= 3: for i in range(125): v = find(a, str(i * 8)) if v: ...
FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER IF VAR RETURN VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR RETURN VAR IF...
You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes. Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-...
s = input() x = "" n = len(s) if n == 1: if int(s) % 8 == 0: print("YES") print(s) else: print("NO") elif n == 2: if int(s) % 8 == 0: print("YES") print(s) elif int(s[1]) % 8 == 0: print("YES") print(s[1]) elif int(s[0]) % 8 == 0: print...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR IF BIN_OP FU...
You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes. Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-...
from itertools import combinations number = "00" + input() for w in ( int(number[i] + number[j] + number[k]) for i, j, k in combinations(range(len(number)), 3) ): if w % 8 == 0: print("YES\n{}".format(w)) exit(0) print("NO")
ASSIGN VAR BIN_OP STRING FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING
You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes. Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-...
n = input() def solve(n): for i in range(len(n)): number = n[i] if int(number) % 8 == 0: return number for j in range(i + 1, len(n)): tmp = number + n[j] if int(tmp) % 8 == 0 or int(n[j]) % 8 == 0: return tmp if int(tmp) % 8 == 0 else n[j...
ASSIGN VAR FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER R...
You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes. Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-...
from itertools import combinations s = input() sss = s flag = 0 flag2 = 0 ss = [] even = ["0", "2", "4", "6", "8"] for i in range(len(sss)): if sss[i] in even: if i >= 3: s = sss[i - 3 : i + 1] else: s = sss[: i + 1] ss.append(s) flag2 = 1 if flag2 == 0: ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST STRING STRING STRING STRING STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR A...
You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes. Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-...
n = ["0", "0"] + list(input()) l = len(n) n = [int(x) for x in n] for i in range(l): for j in range(i + 1, l): for k in range(j + 1, l): x = n[i] * 100 + n[j] * 10 + n[k] if x % 8 == 0: print("YES") print(x) exit(0) print("NO")
ASSIGN VAR BIN_OP LIST STRING STRING FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VA...
You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes. Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-...
n = input() l = len(n) f = 0 for i in range(l): if int(n[i]) % 8 == 0: f = 1 print("YES") print(n[i]) break if f == 0 and l > 1: for i in range(l - 1): for j in range(i + 1, l): if n[i] != "0" and (10 * int(n[i]) + int(n[j])) % 8 == 0: print("Y...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ...
You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes. Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-...
import sys def func_(arr): for i in range(0, len(arr) - 2): for j in range(i + 1, len(arr) - 1): for k in range(j + 1, len(arr)): tmp = arr[i] * 100 + arr[j] * 10 + arr[k] if tmp % 8 is 0: print("YES") print(tmp) ...
IMPORT FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUN...
You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes. Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-...
n = input() s = len(n) a = [([False] * 8) for _ in range(s)] prev = [([-1] * 8) for _ in range(s)] a[0][int(n[0]) % 8] = True for i in range(1, s): a[i][int(n[i]) % 8] = True for j in range(8): if a[i - 1][j]: a[i][(j * 10 + int(n[i])) % 8] = True prev[i][(j * 10 + int(n[i])) % 8...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ...
You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes. Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-...
List = input() Len = len(List) for i in range(Len): if int(List[i]) % 8 == 0: print("YES\n" + List[i]) exit() for i in range(Len): for j in range(i + 1, Len): if int(List[i] + List[j]) % 8 == 0: print("YES\n" + List[i] + List[j]) exit() for i in range(Len): fo...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER NUMBER EXP...
You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes. Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-...
s = input() if s.count("0"): print("YES") print("0") exit() if s.count("8"): print("YES") print("8") exit() if len(s) < 3: x = int(s) if x % 8 == 0: print("YES") print(s) else: print("NO") exit() else: i = 0 f = 0 while i < len(s) - 2 and f == ...
ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR S...
You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes. Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-...
answer = "" def exists(a, b): pos = 0 global answer answer = "" for ch in a: if int(ch) % 8 == 0: digit = 0 elif int(ch) % 4 == 0: digit = 4 elif int(ch) % 2 == 0: digit = 2 elif int(ch) % 2 != 0: digit = 1 if pos ...
ASSIGN VAR STRING FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VA...