description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Given two strings s1 and s2, The task is to convert s1 into a palindrome such that s1 contain s2 as a substring in a minimum number of operation. In a single operation, we can replace any word of s1 with any character. Note: If it is not possible to convert s1 such that it is a palindrome as well as contains substring ...
class Solution: def solve(self, temp, x, y): c = 0 i, j = 0, len(temp) - 1 while i < j: if temp[i] != temp[j]: c += 1 if i >= x and j <= y: return 1000000000.0 i += 1 j -= 1 return c def spe...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER RE...
Given two strings s1 and s2, The task is to convert s1 into a palindrome such that s1 contain s2 as a substring in a minimum number of operation. In a single operation, we can replace any word of s1 with any character. Note: If it is not possible to convert s1 such that it is a palindrome as well as contains substring ...
class Solution: def specialPalindrome(self, s1, s2): ls1 = [i for i in s1] ls2 = [i for i in s2] n = len(ls1) m = len(ls2) def minConvert(a, bl, br): c = 0 l, r = 0, n - 1 while l <= r: if a[l] != a[r]: ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR RETURN NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_...
Given two strings s1 and s2, The task is to convert s1 into a palindrome such that s1 contain s2 as a substring in a minimum number of operation. In a single operation, we can replace any word of s1 with any character. Note: If it is not possible to convert s1 such that it is a palindrome as well as contains substring ...
class Solution: def specialPalindrome(self, s1, s2): l1 = len(s1) l2 = len(s2) if l1 == l2 and s1 != s2: return -1 f = 1 m = 10**20 for i in range(l1 - l2 + 1): f = 1 c = 0 s3 = s1[:i] + s2 + s1[i + l2 :] fo...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL...
Find the minimum length word from a given dictionary words, which has all the letters from the string licensePlate. Such a word is said to complete the given string licensePlate Here, for letters we ignore case. For example, "P" on the licensePlate still matches "p" on the word. It is guaranteed an answer exists. ...
class Solution: def dominantIndex(self, nums): if len(nums) <= 1: return 0 max1 = max(nums) idx = nums.index(max1) del nums[idx] max2 = max(nums) return idx if max2 * 2 <= max1 else -1
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN BIN_OP VAR NUMBER VAR VAR NUMBER
Find the minimum length word from a given dictionary words, which has all the letters from the string licensePlate. Such a word is said to complete the given string licensePlate Here, for letters we ignore case. For example, "P" on the licensePlate still matches "p" on the word. It is guaranteed an answer exists. ...
class Solution: def dominantIndex(self, nums): largest = max(nums) for n in nums: if 2 * n > largest and n != largest: return -1 return nums.index(largest)
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP NUMBER VAR VAR VAR VAR RETURN NUMBER RETURN FUNC_CALL VAR VAR
Find the minimum length word from a given dictionary words, which has all the letters from the string licensePlate. Such a word is said to complete the given string licensePlate Here, for letters we ignore case. For example, "P" on the licensePlate still matches "p" on the word. It is guaranteed an answer exists. ...
class Solution: def dominantIndex(self, nums): out_index = -1 lrgst, scnd, ind = -float("inf"), None, None for i in range(len(nums)): if nums[i] > lrgst: lrgst, scnd, ind = nums[i], lrgst, i elif nums[i] > scnd: scnd = nums[i] ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR STRING NONE NONE FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR BIN_OP NUMBER VAR ASSIGN VAR VAR RETURN VAR
Find the minimum length word from a given dictionary words, which has all the letters from the string licensePlate. Such a word is said to complete the given string licensePlate Here, for letters we ignore case. For example, "P" on the licensePlate still matches "p" on the word. It is guaranteed an answer exists. ...
class Solution: def dominantIndex(self, nums): if len(nums) == 1: return 0 doubleBigIndex = 0 halfpoint = 0 biggest = 0 for index, item in enumerate(nums): print((biggest, halfpoint, doubleBigIndex, item)) if item >= 2 * biggest: ...
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR IF VAR BIN_OP NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR RETU...
Find the minimum length word from a given dictionary words, which has all the letters from the string licensePlate. Such a word is said to complete the given string licensePlate Here, for letters we ignore case. For example, "P" on the licensePlate still matches "p" on the word. It is guaranteed an answer exists. ...
class Solution: def dominantIndex(self, nums): if len(nums) == 1: return 0 Max = max(nums) if nums.count(Max) > 1: return -1 if any(nums) == False: return 0 if nums.count(0) == len(nums) - 1: return nums.index(Max) for ...
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER RETURN...
Find the minimum length word from a given dictionary words, which has all the letters from the string licensePlate. Such a word is said to complete the given string licensePlate Here, for letters we ignore case. For example, "P" on the licensePlate still matches "p" on the word. It is guaranteed an answer exists. ...
class Solution: def dominantIndex(self, nums): first = float("-Inf") second = float("-Inf") index = None for d, num in enumerate(nums): if num > first: second = first first = num index = d if second < num < firs...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NONE FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR FUNC_CALL VAR STRING BIN_OP VAR VAR NUMBER RETURN VAR RETURN NUMBER
Find the minimum length word from a given dictionary words, which has all the letters from the string licensePlate. Such a word is said to complete the given string licensePlate Here, for letters we ignore case. For example, "P" on the licensePlate still matches "p" on the word. It is guaranteed an answer exists. ...
class Solution: def dominantIndex(self, nums): if len(nums) > 1: n = max(nums) id = nums.index(n) nums.remove(n) return id if n >= max(nums) * 2 else -1 else: return 0
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER RETURN NUMBER
Find the minimum length word from a given dictionary words, which has all the letters from the string licensePlate. Such a word is said to complete the given string licensePlate Here, for letters we ignore case. For example, "P" on the licensePlate still matches "p" on the word. It is guaranteed an answer exists. ...
class Solution: def dominantIndex(self, nums): max_num = 0 s_max = 0 max_num_index = 0 if len(nums) != 1: for i in range(len(nums)): if nums[i] > max_num: s_max = max_num s_max_index = max_num_index ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR BIN_OP NUMBER VAR RETURN VAR RETURN NUMBER RETURN NUMBER
Find the minimum length word from a given dictionary words, which has all the letters from the string licensePlate. Such a word is said to complete the given string licensePlate Here, for letters we ignore case. For example, "P" on the licensePlate still matches "p" on the word. It is guaranteed an answer exists. ...
class Solution: def dominantIndex(self, nums): n = len(nums) if n <= 1: return n - 1 im = 0 im2 = 1 if nums[im2] > nums[im]: im, im2 = im2, im for i in range(2, n): if nums[i] > nums[im]: im2 = im im...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR IF VAR VAR BIN_OP VAR VAR NUMBER RETURN...
Find the minimum length word from a given dictionary words, which has all the letters from the string licensePlate. Such a word is said to complete the given string licensePlate Here, for letters we ignore case. For example, "P" on the licensePlate still matches "p" on the word. It is guaranteed an answer exists. ...
class Solution: def dominantIndex(self, nums): if len(nums) == 1: return 0 maxnum = max(nums) index = nums.index(maxnum) nums.sort() if nums[-1] >= nums[-2] * 2: return index else: return -1
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER RETURN VAR RETURN NUMBER
Find the minimum length word from a given dictionary words, which has all the letters from the string licensePlate. Such a word is said to complete the given string licensePlate Here, for letters we ignore case. For example, "P" on the licensePlate still matches "p" on the word. It is guaranteed an answer exists. ...
class Solution: def dominantIndex(self, nums): if len(nums) == 1: return 0 maxval = nums[0] maxindex = 0 secVal = None for i, e in enumerate(nums): if i == 0: continue if e > maxval: secVal, maxval = maxval,...
CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NONE FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR IF VAR NONE ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR IF BIN_OP VAR NUMBER VAR RETURN VAR RETURN NUMBER
Chef _c8kbf_ has an unrooted, weighted tree with N nodes, where vertices u and v are connected by an edge with weight w. The value of the simple path from x to y is defined as the [bitwise XOR] of the weights of the edges it consists of. Recall that a simple path is a path that does not have repeating vertices. Hel...
import sys input = sys.stdin.readline def dfs(dist, graph, node=1): for child in graph[node]: if dist[child[0]] == -1: dist[child[0]] = dist[node] ^ child[1] dfs(dist, graph, child[0]) def solve(): n = int(input()) graph = {} for _ in range(n - 1): u, v, w = ...
IMPORT ASSIGN VAR VAR FUNC_DEF NUMBER FOR VAR VAR VAR IF VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC...
Chef _c8kbf_ has an unrooted, weighted tree with N nodes, where vertices u and v are connected by an edge with weight w. The value of the simple path from x to y is defined as the [bitwise XOR] of the weights of the edges it consists of. Recall that a simple path is a path that does not have repeating vertices. Hel...
import sys sys.setrecursionlimit(10**6) SIZE = int(1000000.0 + 2) JM = 1022 MOD = 1000000005 + 2 def dfs(adj, node, vis, dis): vis[node] = 1 for x in adj[node]: if not vis[x[0]]: dis[x[0]] = dis[node] ^ x[1] dfs(adj, x[0], vis, dis) def megha(): n = int(input()) adj ...
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR FUNC_DEF ASSIGN VAR FU...
Chef _c8kbf_ has an unrooted, weighted tree with N nodes, where vertices u and v are connected by an edge with weight w. The value of the simple path from x to y is defined as the [bitwise XOR] of the weights of the edges it consists of. Recall that a simple path is a path that does not have repeating vertices. Hel...
mod = 10**9 + 7 def checkerforlecker(adj, node, dis, vis): vis[node] = 1 for it in adj[node]: if not vis[it[0]]: dis[it[0]] = dis[node] ^ it[1] checkerforlecker(adj, it[0], dis, vis) def harukicheck2(): n = int(input()) res = 0 pakkachakka = 1 v = [] panip...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR DICT FOR...
Chef _c8kbf_ has an unrooted, weighted tree with N nodes, where vertices u and v are connected by an edge with weight w. The value of the simple path from x to y is defined as the [bitwise XOR] of the weights of the edges it consists of. Recall that a simple path is a path that does not have repeating vertices. Hel...
def countingSort(arr, exp1): n = len(arr) output = [0] * n count = [0] * 10 for i in range(0, n): index = arr[i] // exp1 count[index % 10] += 1 for i in range(1, 10): count[i] += count[i - 1] i = n - 1 while i >= 0: index = arr[i] // exp1 output[count[...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN ...
Chef _c8kbf_ has an unrooted, weighted tree with N nodes, where vertices u and v are connected by an edge with weight w. The value of the simple path from x to y is defined as the [bitwise XOR] of the weights of the edges it consists of. Recall that a simple path is a path that does not have repeating vertices. Hel...
def dfs(adj_list, node, visited, distances): visited[node] = True for neighbor, weight in adj_list[node]: if not visited[neighbor]: distances[neighbor] = distances[node] ^ weight dfs(adj_list, neighbor, visited, distances) def sol(): num_nodes = int(input()) adj_list = ...
FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VA...
Chef _c8kbf_ has an unrooted, weighted tree with N nodes, where vertices u and v are connected by an edge with weight w. The value of the simple path from x to y is defined as the [bitwise XOR] of the weights of the edges it consists of. Recall that a simple path is a path that does not have repeating vertices. Hel...
t = int(input()) ans = [] for _ in range(t): n = int(input()) l = [[] for i in range(n + 1)] for i in range(n - 1): u, v, w = map(int, input().split()) l[u].append([v, w]) l[v].append([u, w]) xorl = [(0) for i in range(n + 1)] visited = [(False) for i in range(n + 1)] que...
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 ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR LIST VAR VAR EXPR FUNC_C...
Chef _c8kbf_ has an unrooted, weighted tree with N nodes, where vertices u and v are connected by an edge with weight w. The value of the simple path from x to y is defined as the [bitwise XOR] of the weights of the edges it consists of. Recall that a simple path is a path that does not have repeating vertices. Hel...
def solve(node): vis[node] = 1 for x in adj[node]: if not vis[x[0]]: dist[x[0]] = dist[node] ^ x[1] solve(x[0]) def main(): n = int(input()) global adj adj = [[] for i in range(n + 1)] for i in range(n - 1): u, v, w = map(int, input().split()) u ...
FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ...
Chef _c8kbf_ has an unrooted, weighted tree with N nodes, where vertices u and v are connected by an edge with weight w. The value of the simple path from x to y is defined as the [bitwise XOR] of the weights of the edges it consists of. Recall that a simple path is a path that does not have repeating vertices. Hel...
mod_ = 10**9 + 7 ans = [[-1]] def dfs(root, g, p, px, weight, start, map_): xor = px ^ weight left, right = min(start, root), max(start, root) if start != root and xor in map_: if map_[xor] != (left, right): ans[0] = [*map_[xor], left, right] return map_[xor] = left, ri...
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST LIST NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER LIST VAR VAR VAR VAR RETURN ASSIGN VAR VAR VAR VAR FOR VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMB...
Consider a series of numbers composed of only digits 4 and 7. First few numbers in the series are 4, 7, 44, 47, 74, 77, 444, .. etc. Given a string N constructed by 4, 7 digit only, find position of this number in this series. Example 1: Input: N = "7" Output: 2 Explanation: In the series 4 , 7 , 44 , 47... 7 is at s...
class Solution: def findpos(self, n): ans = 2 * (pow(2, len(n) - 1) - 1) i = 0 while i < len(n): if n[i] == "7": ans += pow(2, len(n) - 1 - i) i += 1 return ans + 1
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER RETURN BIN_OP VAR NUMBER
Consider a series of numbers composed of only digits 4 and 7. First few numbers in the series are 4, 7, 44, 47, 74, 77, 444, .. etc. Given a string N constructed by 4, 7 digit only, find position of this number in this series. Example 1: Input: N = "7" Output: 2 Explanation: In the series 4 , 7 , 44 , 47... 7 is at s...
class Solution: def findpos(self, n): k = len(n) output = 0 for j in range(k): output += 2**j num = "" for item in n: if item == "4": num += "0" else: num += "1" return output + int(num, 2)
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR STRING VAR STRING RETURN BIN_OP VAR FUNC_CALL VAR VAR NUMBER
Consider a series of numbers composed of only digits 4 and 7. First few numbers in the series are 4, 7, 44, 47, 74, 77, 444, .. etc. Given a string N constructed by 4, 7 digit only, find position of this number in this series. Example 1: Input: N = "7" Output: 2 Explanation: In the series 4 , 7 , 44 , 47... 7 is at s...
class Solution: def findpos(self, n): l = len(n) first = 0 last = 2**l res = 0 for i in range(l): res = res + 2**i i = 0 while i < l - 1: if n[i] == "4": last = (first + last) // 2 else: firs...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMB...
Consider a series of numbers composed of only digits 4 and 7. First few numbers in the series are 4, 7, 44, 47, 74, 77, 444, .. etc. Given a string N constructed by 4, 7 digit only, find position of this number in this series. Example 1: Input: N = "7" Output: 2 Explanation: In the series 4 , 7 , 44 , 47... 7 is at s...
class Solution: def findpos(self, n): l = len(n) ans = 0 for i in range(1, l): ans += pow(2, i) for i in range(len(n)): if n[i] == "7": ans += pow(2, l) / pow(2, i + 1) return int(ans + 1)
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR NUMBER
Consider a series of numbers composed of only digits 4 and 7. First few numbers in the series are 4, 7, 44, 47, 74, 77, 444, .. etc. Given a string N constructed by 4, 7 digit only, find position of this number in this series. Example 1: Input: N = "7" Output: 2 Explanation: In the series 4 , 7 , 44 , 47... 7 is at s...
class Solution: def findpos(self, n): pos = 0 for i in n: if i == "4": pos = 2 * pos + 1 else: pos = 2 * pos + 2 return pos
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER RETURN VAR
Consider a series of numbers composed of only digits 4 and 7. First few numbers in the series are 4, 7, 44, 47, 74, 77, 444, .. etc. Given a string N constructed by 4, 7 digit only, find position of this number in this series. Example 1: Input: N = "7" Output: 2 Explanation: In the series 4 , 7 , 44 , 47... 7 is at s...
class Solution: def findpos(self, n): if n == "7": return 2 if n == "4": return 1 cnt = len(n) ans = 0 for i in range(1, cnt): ans += 2**i s = "" for i in n: if i == "4": s = s + "0" ...
CLASS_DEF FUNC_DEF IF VAR STRING RETURN NUMBER IF VAR STRING RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP NUMBER VAR ASSIGN VAR STRING FOR VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR V...
Consider a series of numbers composed of only digits 4 and 7. First few numbers in the series are 4, 7, 44, 47, 74, 77, 444, .. etc. Given a string N constructed by 4, 7 digit only, find position of this number in this series. Example 1: Input: N = "7" Output: 2 Explanation: In the series 4 , 7 , 44 , 47... 7 is at s...
class Solution: def findpos(self, n): cnt = [0] * 51 for i in range(1, 51): cnt[i] = 2**i total = cnt.copy() for i in range(1, 51): total[i] += total[i - 1] sz = len(n) ans = total[sz - 1] for i in range(sz - 1): if n[i] ==...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF...
Consider a series of numbers composed of only digits 4 and 7. First few numbers in the series are 4, 7, 44, 47, 74, 77, 444, .. etc. Given a string N constructed by 4, 7 digit only, find position of this number in this series. Example 1: Input: N = "7" Output: 2 Explanation: In the series 4 , 7 , 44 , 47... 7 is at s...
class Solution: def findpos(self, n): last_n = len(n) - 1 a = 2 r = 2 gp_sum = int(a * (r**last_n - 1) / (r - 1)) s = 1 e = 2 ** len(n) for i in range(len(n)): diff = e - s + 1 if n[i] == "4": e = e - diff // 2 ...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VA...
Consider a series of numbers composed of only digits 4 and 7. First few numbers in the series are 4, 7, 44, 47, 74, 77, 444, .. etc. Given a string N constructed by 4, 7 digit only, find position of this number in this series. Example 1: Input: N = "7" Output: 2 Explanation: In the series 4 , 7 , 44 , 47... 7 is at s...
class Solution: def findpos(self, n): p = 0 for i in range(len(n)): if n[i] == "4": p = p * 2 + 1 else: p = p * 2 + 2 return p
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER RETURN VAR
Consider a series of numbers composed of only digits 4 and 7. First few numbers in the series are 4, 7, 44, 47, 74, 77, 444, .. etc. Given a string N constructed by 4, 7 digit only, find position of this number in this series. Example 1: Input: N = "7" Output: 2 Explanation: In the series 4 , 7 , 44 , 47... 7 is at s...
class Solution: def findpos(self, n): j = len(n) i = 0 c = 0 while i < j: if n[i] == "7": c = c * 2 + 2 if n[i] == "4": c = c * 2 + 1 i += 1 return c
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER RETURN VAR
Consider a series of numbers composed of only digits 4 and 7. First few numbers in the series are 4, 7, 44, 47, 74, 77, 444, .. etc. Given a string N constructed by 4, 7 digit only, find position of this number in this series. Example 1: Input: N = "7" Output: 2 Explanation: In the series 4 , 7 , 44 , 47... 7 is at s...
class Solution: def findpos(self, n): length = len(n) ans = 2**length - 2 string_length = 2**length for i in range(length): if n[i] == "7": ans += string_length / 2 string_length /= 2 return int(ans + 1)
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR NUMBER
Consider a series of numbers composed of only digits 4 and 7. First few numbers in the series are 4, 7, 44, 47, 74, 77, 444, .. etc. Given a string N constructed by 4, 7 digit only, find position of this number in this series. Example 1: Input: N = "7" Output: 2 Explanation: In the series 4 , 7 , 44 , 47... 7 is at s...
class Solution: def findpos(self, n): s, p = 0, 1 l = len(n) for i in range(l - 1, -1, -1): if n[i] == "7": s += p p *= 2 return s + 2**l - 1
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR VAR VAR NUMBER RETURN BIN_OP BIN_OP VAR BIN_OP NUMBER VAR NUMBER
Consider a series of numbers composed of only digits 4 and 7. First few numbers in the series are 4, 7, 44, 47, 74, 77, 444, .. etc. Given a string N constructed by 4, 7 digit only, find position of this number in this series. Example 1: Input: N = "7" Output: 2 Explanation: In the series 4 , 7 , 44 , 47... 7 is at s...
class Solution: def findpos(self, n): i = 1 j = 2 ** len(n) mid = (i + j) // 2 for elm in n: if elm == "4": j = mid else: i = mid + 1 mid = (i + j) // 2 result = mid for i in range(1, len(n)): ...
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR VAR IF VAR STRING ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR RETURN...
We are given an elevation map, heights[i] representing the height of the terrain at that index. The width at each index is 1. After V units of water fall at index K, how much water is at each index? Water first drops at index K and rests on top of the highest terrain or water at that index. Then, it flows according...
class Solution: def reachNumber(self, target): target = abs(target) def binary_search(lo, hi): if lo >= hi: return lo mi = lo + (hi - lo) // 2 t = mi * (mi + 1) // 2 if t == target: return mi elif t < targe...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR RETURN VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR RETURN VAR IF VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER...
We are given an elevation map, heights[i] representing the height of the terrain at that index. The width at each index is 1. After V units of water fall at index K, how much water is at each index? Water first drops at index K and rests on top of the highest terrain or water at that index. Then, it flows according...
class Solution: def reachNumber(self, target): target = abs(target) n = math.ceil(((1 + 8 * target) ** 0.5 - 1) / 2) if target % 2 > 0: if n % 4 == 1 or n % 4 == 2: return n elif n % 4 == 3: return n + 2 else: ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER BIN_OP NUMBER VAR NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER RETURN VAR IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER IF ...
We are given an elevation map, heights[i] representing the height of the terrain at that index. The width at each index is 1. After V units of water fall at index K, how much water is at each index? Water first drops at index K and rests on top of the highest terrain or water at that index. Then, it flows according...
class Solution: def reachNumber(self, target): target = abs(target) s = 0 for i in range(target + 1): s += i if s >= target: break if s - target & 1: if i + 1 & 1: return i + 1 else: retu...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER NUMBER RETURN BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER RETURN VAR
We are given an elevation map, heights[i] representing the height of the terrain at that index. The width at each index is 1. After V units of water fall at index K, how much water is at each index? Water first drops at index K and rests on top of the highest terrain or water at that index. Then, it flows according...
class Solution: def reachNumber(self, target): t = abs(target) n = math.floor(math.sqrt(2 * t)) while True: to_minus = (n + 1) * n / 2 - t if to_minus >= 0: if to_minus % 2 == 0: return int(n) n += 1
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER VAR WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR VAR VAR NUMBER
We are given an elevation map, heights[i] representing the height of the terrain at that index. The width at each index is 1. After V units of water fall at index K, how much water is at each index? Water first drops at index K and rests on top of the highest terrain or water at that index. Then, it flows according...
class Solution: def reachNumber(self, t): t = abs(t) lo, hi = 1, t while lo < hi: m = (lo + hi) // 2 val = m * (m + 1) // 2 if val < t: lo = m + 1 else: hi = m sm = lo * (lo + 1) // 2 ans = lo ...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR WHILE BIN_OP B...
You are given $N$ gears numbered $1$ through $N$. For each valid $i$, gear $i$ has $A_i$ teeth. In the beginning, no gear is connected to any other. Your task is to process $M$ queries and simulate the gears' mechanism. There are three types of queries: - Type 1: Change the number of teeth of gear $X$ to $C$. - Type 2:...
def gcd(a, b): if a == 0: return b else: return gcd(b % a, a) def dsfind(parent, i): if parent[i] == i: return i return dsfind(parent, parent[i]) def dsunion(parent, rank, x, y, chn): xroot = dsfind(parent, x) yroot = dsfind(parent, y) sx = dssign(parent, x, chn) ...
FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_DEF IF VAR VAR VAR RETURN VAR RETURN FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR VAR IF VAR VAR...
You are given $N$ gears numbered $1$ through $N$. For each valid $i$, gear $i$ has $A_i$ teeth. In the beginning, no gear is connected to any other. Your task is to process $M$ queries and simulate the gears' mechanism. There are three types of queries: - Type 1: Change the number of teeth of gear $X$ to $C$. - Type 2:...
class disjointsets: def __init__(self, n): self.arr = [0] * n self.size = [1] * n for i in range(n): self.arr[i] = i def find(self, i): if self.arr[i] == i: return i else: self.arr[i] = self.find(self.arr[i]) return self.a...
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_DEF IF VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN IF VAR VAR VAR V...
You are given $N$ gears numbered $1$ through $N$. For each valid $i$, gear $i$ has $A_i$ teeth. In the beginning, no gear is connected to any other. Your task is to process $M$ queries and simulate the gears' mechanism. There are three types of queries: - Type 1: Change the number of teeth of gear $X$ to $C$. - Type 2:...
N, M = map(int, input().split()) (*A,) = map(int, input().split()) def gcd(m, n): r = m % n return gcd(n, r) if r else n blk = [0] * N F = [0] * N (*p,) = range(N) def root(x): if p[x] == x: return x z = p[x] p[x] = y = root(p[x]) if F[z]: F[x] ^= 1 A[x] = -A[x] ...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP VAR VAR RETURN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR VAR RETURN VAR ASSIGN...
You are given $N$ gears numbered $1$ through $N$. For each valid $i$, gear $i$ has $A_i$ teeth. In the beginning, no gear is connected to any other. Your task is to process $M$ queries and simulate the gears' mechanism. There are three types of queries: - Type 1: Change the number of teeth of gear $X$ to $C$. - Type 2:...
class Node: def __init__(self, i, v, p): self.data = i self.val = v self.parent = p def gcd(a, b): if a > b: a = a % b if a == 0: return b else: b = b % a if b == 0: return a return gcd(a, b) n, m = map(int, input().spl...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF IF VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_...
You are given $N$ gears numbered $1$ through $N$. For each valid $i$, gear $i$ has $A_i$ teeth. In the beginning, no gear is connected to any other. Your task is to process $M$ queries and simulate the gears' mechanism. There are three types of queries: - Type 1: Change the number of teeth of gear $X$ to $C$. - Type 2:...
class Dsu: def __init__(self, v, s): self.par = s self.v = v self.dr = [1] * v self.zero = [False] * v self.speed = [] for i in range(v): self.speed.append([]) self.speed[i].append(i) def find(self, i): if i != self.par[i][0]: ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST EXPR FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER IF...
We are given an array asteroids of integers representing asteroids in a row. For each asteroid, the absolute value represents its size, and the sign represents its direction (positive meaning right, negative meaning left). Each asteroid moves at the same speed. Find out the state of the asteroids after all collision...
class Solution: def asteroidCollision(self, asteroids): stack = [] for a in asteroids: if a >= 0 or a < 0 and (not stack or stack[-1] < 0): stack.append(a) else: while a < 0 and stack and stack[-1] > 0: last = stack.pop() ...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER VAR NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR WHILE VAR NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR
We are given an array asteroids of integers representing asteroids in a row. For each asteroid, the absolute value represents its size, and the sign represents its direction (positive meaning right, negative meaning left). Each asteroid moves at the same speed. Find out the state of the asteroids after all collision...
class Solution: def asteroidCollision(self, asteroids): ret = [] for val in asteroids: append_flag = True while len(ret) > 0: if val * ret[-1] > 0: break if val > 0: break if abs(val) < a...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR IF VAR EXPR FUNC_CALL VAR ...
We are given an array asteroids of integers representing asteroids in a row. For each asteroid, the absolute value represents its size, and the sign represents its direction (positive meaning right, negative meaning left). Each asteroid moves at the same speed. Find out the state of the asteroids after all collision...
class Solution: def asteroidCollision(self, asteroids): st, res = [], [] for ast in asteroids: if ast > 0: st.append(ast) continue elif not st: res.append(ast) continue flag = True while ...
CLASS_DEF FUNC_DEF ASSIGN VAR VAR LIST LIST FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR RETURN BIN_OP VAR VAR
We are given an array asteroids of integers representing asteroids in a row. For each asteroid, the absolute value represents its size, and the sign represents its direction (positive meaning right, negative meaning left). Each asteroid moves at the same speed. Find out the state of the asteroids after all collision...
class Solution: def asteroidCollision(self, asteroids): ans = [] for new in asteroids: while True: if ans and new < 0 < ans[-1]: if ans[-1] < abs(new): ans.pop() continue elif ans[-1]...
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR WHILE NUMBER IF VAR VAR NUMBER VAR NUMBER IF VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR RETURN VAR
We are given an array asteroids of integers representing asteroids in a row. For each asteroid, the absolute value represents its size, and the sign represents its direction (positive meaning right, negative meaning left). Each asteroid moves at the same speed. Find out the state of the asteroids after all collision...
class Solution: def asteroidCollision(self, asteroids): l = len(asteroids) if l < 2: return asteroids ans = [] stack = [] for a in asteroids: if a > 0: stack.append(a) else: a = -a equal_flag...
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR IF VAR EXPR FUNC_CALL VAR VA...
We are given an array asteroids of integers representing asteroids in a row. For each asteroid, the absolute value represents its size, and the sign represents its direction (positive meaning right, negative meaning left). Each asteroid moves at the same speed. Find out the state of the asteroids after all collision...
class Solution: def asteroidCollision(self, asteroids): if not asteroids: return asteroids remaining = [] for item in asteroids: itemSign, itemVal = self.getItemDetails(item) shouldAppend = False while True: if not remaining: ...
CLASS_DEF FUNC_DEF IF VAR RETURN VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE NUMBER IF VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR EXPR FUNC_CALL VAR VAR RETURN ...
A chess board is normally played with 16 pawns and 16 other pieces, for this kata a variant will be played with only the pawns. All other pieces will not be on the board. For information on how pawns move, refer [here](http://www.chesscorner.com/tutorial/basic/pawn/pawn.htm) Write a function that can turn a li...
def pawn_move_tracker(moves): def getSourcePos(m, delta): return m[0] + str(int(m[-1]) + delta * comingFrom[player]) ROWS, COLS = "87654321", "abcdefgh" comingFrom, mayBeDouble = {"P": -1, "p": 1}, {"P": "4", "p": "5"} pawns = {"P": {(y + "2") for y in COLS}, "p": {(y + "7") for y in COLS}} ...
FUNC_DEF FUNC_DEF RETURN BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR VAR STRING STRING ASSIGN VAR VAR DICT STRING STRING NUMBER NUMBER DICT STRING STRING STRING STRING ASSIGN VAR DICT STRING STRING BIN_OP VAR STRING VAR VAR BIN_OP VAR STRING VAR VAR FOR VAR VAR FUNC_CAL...
A chess board is normally played with 16 pawns and 16 other pieces, for this kata a variant will be played with only the pawns. All other pieces will not be on the board. For information on how pawns move, refer [here](http://www.chesscorner.com/tutorial/basic/pawn/pawn.htm) Write a function that can turn a li...
def pawn_move_tracker(moves): board = [([c] * 8) for c in ".p....P."] for turn, move in enumerate(moves, 1): capture, white_turn = len(move) == 4, turn % 2 direction = 2 * white_turn - 1 c0, _, c, r = (move * 2)[:4] c0, c, r = ord(c0) - ord("a"), ord(c) - ord("a"), 8 - int(r) ...
FUNC_DEF ASSIGN VAR BIN_OP LIST VAR NUMBER VAR STRING FOR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING BIN_OP FUNC_CAL...
A chess board is normally played with 16 pawns and 16 other pieces, for this kata a variant will be played with only the pawns. All other pieces will not be on the board. For information on how pawns move, refer [here](http://www.chesscorner.com/tutorial/basic/pawn/pawn.htm) Write a function that can turn a li...
LETTERS = "abcdefgh" NUMBERS = "87654321" W, B = WB = "Pp" EMPTY, CAPTURE = ".x" WHITEHOME = "12" BLACKHOME = "87" JUMP = "54" def pawn_move_tracker(moves): board = { (letter + number): ( B if number == BLACKHOME[1] else W if number == WHITEHOME[1] else EMPTY ) for letter in LE...
ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING FUNC_DEF ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CAL...
A chess board is normally played with 16 pawns and 16 other pieces, for this kata a variant will be played with only the pawns. All other pieces will not be on the board. For information on how pawns move, refer [here](http://www.chesscorner.com/tutorial/basic/pawn/pawn.htm) Write a function that can turn a li...
def pawn_move_tracker(moves): board = [ [".", ".", ".", ".", ".", ".", ".", "."], ["p", "p", "p", "p", "p", "p", "p", "p"], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", "....
FUNC_DEF ASSIGN VAR LIST LIST STRING STRING STRING STRING STRING STRING STRING STRING LIST STRING STRING STRING STRING STRING STRING STRING STRING LIST STRING STRING STRING STRING STRING STRING STRING STRING LIST STRING STRING STRING STRING STRING STRING STRING STRING LIST STRING STRING STRING STRING STRING STRING STRI...
A chess board is normally played with 16 pawns and 16 other pieces, for this kata a variant will be played with only the pawns. All other pieces will not be on the board. For information on how pawns move, refer [here](http://www.chesscorner.com/tutorial/basic/pawn/pawn.htm) Write a function that can turn a li...
def pawn_move_tracker(moves): white_pawns = [(x, 2) for x in range(1, 9)] black_pawns = [(x, 7) for x in range(1, 9)] all_pawns = white_pawns, black_pawns turn = 0 for move in moves: pawns = all_pawns[turn] opponent = all_pawns[turn ^ 1] direction = 1 - 2 * turn captu...
FUNC_DEF ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER VAR ASSIGN VAR STRING VAR IF VAR ASSIGN VAR VAR VAR FUNC_CALL V...
A chess board is normally played with 16 pawns and 16 other pieces, for this kata a variant will be played with only the pawns. All other pieces will not be on the board. For information on how pawns move, refer [here](http://www.chesscorner.com/tutorial/basic/pawn/pawn.htm) Write a function that can turn a li...
def pawn_move_tracker(moves): board = [ [".", ".", ".", ".", ".", ".", ".", "."], ["p", "p", "p", "p", "p", "p", "p", "p"], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", ".", ".", ".", ".", "."], [".", ".", ".", "....
FUNC_DEF ASSIGN VAR LIST LIST STRING STRING STRING STRING STRING STRING STRING STRING LIST STRING STRING STRING STRING STRING STRING STRING STRING LIST STRING STRING STRING STRING STRING STRING STRING STRING LIST STRING STRING STRING STRING STRING STRING STRING STRING LIST STRING STRING STRING STRING STRING STRING STRI...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
t = int(input()) for _ in range(t): N, K = map(int, input().split()) s = input() no0 = s.count("0") no1 = s.count("1") seg = N // K count0 = no0 // seg count1 = no1 // seg if no0 % seg == 0 and no1 % seg == 0: for i in range(seg): if i % 2 == 0: for j ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
T = int(input()) for i in range(T): N, K = map(int, input().split(" ")) U = input() S = N // K ans = "" Z = U.count("0") O = U.count("1") ZCount = Z // S OCount = O // S if Z % S != 0 or O % S != 0: print("IMPOSSIBLE") elif S != N / K: print("".join(map(str, sorte...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
import sys input = sys.stdin.readline def inp(): return int(input()) def inlt(): return list(map(int, input().split(" "))) def insr(): s = input() return list(s[: len(s) - 1]) def invr(): return map(int, input().split()) def solve(n, k, string): zero = 0 one = 0 repeat = n // ...
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
t = int(input()) for _ in range(t): [n, k] = [int(i) for i in input().split()] s = str(input()) x, y = 0, 0 for i in range(n): if s[i] == "0": x += 1 else: y += 1 q = n // k if x % q != 0 or y % q != 0: print("IMPOSSIBLE") else: a = "0"...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER BIN_...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
for _ in range(int(input())): n, k = map(int, input().split()) S = input() knd = n // k d = {"0": 0, "1": 0} for ele in S: d[ele] += 1 if d["0"] % knd != 0 or d["1"] % knd != 0: print("IMPOSSIBLE") else: p = d["0"] // knd q = d["1"] // knd ans = "" ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR DICT STRING STRING NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER IF BIN_OP VAR STRING VAR NUMBER BIN_OP VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING ASSI...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
test = int(input()) for _ in range(test): n, k = map(int, input().split()) s = input() l = [0, 0] for i in s: l[int(i)] += 1 j = n // k if l[0] % j == 0 and l[1] % j == 0: o, p = l[0] // j, l[1] // j s = "" e = "0" * o + "1" * p f = e[::-1] for i i...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR ...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
T = int(input()) for j in range(T): N, K = map(int, input().split()) S = input() ans = str() Z = O = 0 for e in S: if e == "0": Z += 1 else: O += 1 a = N // K if Z % a != 0: print("IMPOSSIBLE") continue z = Z // a o = O // a ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING A...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
for _ in range(int(input())): n, k = map(int, input().split()) s = input() one, zero = 0, 0 for x in s: if x == "1": one += 1 else: zero += 1 if one == 0 or zero == 0: print(s) else: ans, zc = "", -1 kset = n // k for i in r...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR STRING NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR ...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
for _ in range(int(input())): n, k = map(int, input().split()) s = input() zeros, ones = s.count("0"), s.count("1") d = n // k if zeros % d != 0 or ones % d != 0: print("IMPOSSIBLE") continue else: str = "" str += "".join("0" * (zeros // d)) str += "".join...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR STRING VAR FUNC_CALL ...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
def count(): c1, c2 = 0, 0 for ch in s: if ch == "1": c1 += 1 else: c2 += 1 return c1, c2 def answer(): no, nz = count() div = n // k if no % div == 0 and nz % div == 0: st = "" for i in range(div // 2): st += "0" * (nz // div...
FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP STRING BIN_OP VAR VAR BIN_OP STR...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
testcase = int(input()) for _ in range(testcase): li = [0, 0] n, k = map(int, input().split()) s = input() for i in range(n): li[int(s[i])] += 1 if li[0] % (n / k) != 0 or li[1] % (n / k) != 0: print("IMPOSSIBLE") continue if li[0] == n or li[1] == n: print(s) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER E...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
t = int(input()) for i in range(t): [n, k] = [int(temp) for temp in input().split()] s = input() _0 = 0 for j in range(n): if s[j] == "0": _0 = _0 + 1 if _0 % (n / k) != 0: print("IMPOSSIBLE") else: temp = "" for i in range(int(_0 / (n / k))): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR ...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
for _ in range(int(input())): n, k = map(int, input().split()) s = input() zero = s.count("0") one = s.count("1") m = n // k if zero % m == 0 and zero % m == 0: n1 = zero // m n2 = one // m har = "0" * n1 + "1" * n2 tess = "1" * n2 + "0" * n1 final = "" ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
def solve(n, k, s): one = s.count("1") zero = s.count("0") folds = n // k if zero % folds != 0 or one % folds != 0: return "IMPOSSIBLE" else: n1 = one // folds n0 = zero // folds s = "0" * n0 + "1" * n1 t = s[::-1] c = 1 res = "" while ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER RETURN STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STR...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
for _ in range(int(input())): n, k = map(int, input().split()) string = input() cou1 = string.count("1") cou0 = n - cou1 if cou1 == 0 or cou0 == 0: print(string) else: val = n // k i = 1 ans = [] if cou0 % val != 0 or cou1 % val != 0: print("IM...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST IF BIN_OP VAR VAR NUMB...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
def countChars(s): counts = {} for c in s: counts[c] = counts.setdefault(c, 0) + 1 return counts def isPoss(counts, K, N): for v in counts.values(): if v % (N // K): return False return True def arrange(counts, K, N): baseS = "" for k in sorted(counts.keys(), ...
FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR IF BIN_OP VAR BIN_OP VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR ...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
for _ in range(int(input())): n, k = map(int, input().split()) z = 0 o = 0 for sub in input(): if sub == "0": z += 1 else: o += 1 r = n // k a = 0 b = 0 ans = "" if not n % k and not z % r and not o % r: a = z // r b = o // r ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING IF BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
t = int(input()) for _ in range(t): n, k = map(int, input().split()) s = input() no_of_ones, no_of_zeros = s.count("1"), s.count("0") total_segments = n // k result = "" if no_of_zeros % total_segments == 0 and no_of_ones % total_segments == 0: no_of_ones_per_segment = no_of_ones // tota...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR STRING IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
for _ in range(int(input())): n, k = [int(x) for x in input().split()] a = input() t0 = 0 t1 = 0 for i in a: if int(i): t1 += 1 else: t0 += 1 b = t0 * k // n c = t1 * k // n if b + c == k: ss = "0" * b + "1" * c for i in range(n // ...
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 FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF BIN_OP VAR VAR V...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
for _ in range(int(input())): n, k = map(int, input().split()) string = input() zeroCount = string.count("0") oneCount = string.count("1") noSeg = n // k if zeroCount % noSeg == 0 and oneCount % noSeg == 0: for i in range(1, noSeg + 1): if i % 2: for j in rang...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF B...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
for t in range(int(input())): a = input().split() n, k = int(a[0]), int(a[1]) k = int(n / k) a = input() x = a.count("0") y = a.count("1") if x % k != 0 or y % k != 0: print("IMPOSSIBLE") else: x, y = int(x / k), int(y / k) a = [(0) for i in range(x)] + [(1) for i...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR N...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
def method_1(s, n, k): k0 = s.count("0") k1 = s.count("1") temp = n // k if k0 % temp == 0 and k1 % temp == 0: res1 = "0" * (k0 // temp) + "1" * (k1 // temp) else: return "IMPOSSIBLE" ans = "" for i in range(temp): if i % 2 == 0: ans = ans + res1 e...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR VAR BIN_OP STRING BIN_OP VAR VAR RETURN STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR B...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
for _ in range(int(input())): n, k = [int(x) for x in input().split()] s = input() flag = 0 if k > n: flag = 1 if n % k != 0: flag = 1 t = 0 for i in range(n): if s[i] == "0": t += 1 if t % (n // k) != 0 or (n - t) % (n // k) != 0: flag = 1 ...
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 FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF BIN_OP VAR BIN_OP ...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
t = int(input()) for i in range(t): n, k = map(int, input().split()) s = list(input()) x = s.count("1") y = s.count("0") f = n // k if y % f != 0: print("IMPOSSIBLE") continue z = y // f ans1 = z * "0" + (k - z) * "1" ans = "" for j in range(f): if j % 2 =...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP ...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
for _ in range(int(input())): n, k = map(int, input().split()) s = input() zero, one = 0, 0 for i, j in enumerate(s): if j == "0": zero += 1 else: one += 1 ans = "IMPOSSIBLE" if zero % (n // k) == 0: ans = zero // (n // k) * "0" + one // (n // k) *...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR STRING IF BIN_OP VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
t = int(input()) for _ in range(t): N, K = map(int, input().split()) S = input() zeros = 0 ones = 0 for i in S: if int(i) & 1: ones += 1 else: zeros += 1 rem = N // K if ones == N or zeros == N: print(S) elif ones % rem == 0 and zeros % rem...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
for _ in range(int(input())): n, k = map(int, input().split()) binary_string = input() ones = 0 for i in binary_string: ones += 1 & int(i) zeros = n - ones strk = n // k str2k = "0" * (zeros // strk) + "1" * (ones // strk) if zeros // strk + ones // strk == k: print(((str...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR VAR BIN_OP STRING BIN_OP VA...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
t = int(input()) for p in range(t): n, k = input().split() n = int(n) k = int(k) s = input() z = s.count("0") o = s.count("1") ns = int(n / k) nz = int(z / ns) no = int(o / ns) if z % ns == 0 and o % ns == 0: temp = "0" * nz + "1" * no ans = "" for i in ra...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
t = int(input()) while t: n, k = map(int, input().split()) s = input() i, j = s.count("1"), s.count("0") p = "" q = "" a = "" if i % (n / k): print("IMPOSSIBLE") else: for m in range(int(j / (n / k))): p += "0" for b in range(int(i / (n / k))): ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING IF BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR F...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
for _ in range(int(input())): n, k = map(int, input().split()) s = input() no_of_seg = n // k zeros = 0 ones = 0 for i in s: if i == "0": zeros += 1 else: ones += 1 if zeros % no_of_seg != 0 or ones % no_of_seg != 0: print("IMPOSSIBLE") ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIG...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
try: for _ in range(int(input())): n, k = map(int, input().split()) s = input() a = 0 b = 0 for i in range(len(s)): if s[i] == "0": a += 1 else: b += 1 c = n // k if a % c == 0 and b % c == 0: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
for _ in range(int(input())): n, k = map(int, input().split()) s = input() n0 = s.count("0") n1 = s.count("1") fold = n // k if n0 % fold == 0 and n1 % fold == 0: tr = "0" * (n0 // fold) + "1" * (n1 // fold) for i in range(fold): if i % 2 == 0: print(t...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR VAR BIN_...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
i = 0 T = int(input()) while i < T: N, K = map(int, input().split(" ")) U = input() S = N // K ans = "" Z = U.count("0") O = U.count("1") ZCount = Z // S OCount = O // S if Z % S != 0 or O % S != 0: print("IMPOSSIBLE") else: for x in range(0, N // K): ...
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
t = int(input()) for i in range(t): n, k = map(int, input().split()) s = input() s = list(s) a = s.count("0") b = n - a x = n // k a1 = a // x b1 = b // x if a % x != 0 or b % x != 0: print("IMPOSSIBLE") else: s1 = "" for j in range(x): if j % ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_O...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
for _ in range(int(input())): n, k = map(int, input().split()) s = input() se = {"0": 0, "1": 0} for c in s: if c == "0": se["0"] += 1 else: se["1"] += 1 x, y = int(se["0"] / (n // k)), int(se["1"] / (n // k)) if x + y - k: print("IMPOSSIBLE") ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT STRING STRING NUMBER NUMBER FOR VAR VAR IF VAR STRING VAR STRING NUMBER VAR STRING NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR STRING BIN_OP VAR VAR FUNC_CALL VAR BIN_OP...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
for _ in range(int(input())): N, K = list(map(int, input().split())) S = input() n0 = 0 n1 = 0 for i in range(N): if S[i] == "1": n1 += 1 else: n0 += 1 if n0 % (N // K) == 0 and n1 % (N // K) == 0: A = ["0"] * (n0 // (N // K)) + ["1"] * (n1 // (N /...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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 NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER IF BIN_OP VAR BIN_OP VAR VAR NUMBER BIN_OP VAR BIN_OP VAR VAR NUMBER ASS...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
t = int(input()) for _ in range(t): n, k = map(int, input().split()) s = input() ones = 0 zeros = 0 for i in s: if i == "1": ones += 1 else: zeros += 1 folds = n // k if zeros % folds == 0 and ones % folds == 0: ans = "" for i in range(...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR STRIN...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
for _ in range(int(input())): n, k = map(int, input().split()) s = input() zero = s.count("0") one = s.count("1") val = n // k if zero % val != 0 or one % val != 0: print("IMPOSSIBLE") else: v1 = zero // val v2 = one // val for i in range(val): if ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
t = int(input()) for _ in range(t): n, k = map(int, input().split()) s = input() seg = n // k ones = s.count("1") zeros = s.count("0") if ones % seg == 0 and zeros % seg == 0: ans = "0" * (zeros // seg) + "1" * (ones // seg) ans1 = ans[::-1] if n % (2 * k) == 0: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
for _ in range(int(input())): n, k = map(int, input().split()) s = input() d = dict() for i in s: if i in d: d[i] += 1 else: d[i] = 1 no_zero = d.get("0", 0) no_ones = d.get("1", 0) m = n // k if no_ones % m != 0 or no_ones % m != 0: print(...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR BIN_OP VAR VAR...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
import sys def uno(): return int(sys.stdin.readline().strip()) def dos(): return sys.stdin.readline().strip() def tres(): return map(int, sys.stdin.readline().strip().split()) for _ in range(uno()): n, k = tres() s = dos() z, o, ts = s.count("0"), s.count("1"), n // k if z % ts or o ...
IMPORT FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING ...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
for _ in range(int(input())): n, k = map(int, input().split()) s = input() z = 0 o = 0 for i in range(n): if s[i] == "0": z = z + 1 else: o = o + 1 if z % (n // k) > 0 or o % (n // k) > 0: print("IMPOSSIBLE") else: a = z // (n // k) ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR VAR NUMBER BIN_OP VAR BIN...
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be changed to a string with length $K$ by repeating the following proc...
for _ in range(int(input())): n, k = map(int, input().split()) s = input() zero, one = 0, 0 for i in s: if i == "0": zero += 1 else: one += 1 seg = int(n / k) if zero % seg != 0 or one % seg != 0: print("IMPOSSIBLE") continue else: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRIN...