description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Given an undirected graph with V vertices. We say two vertices u and v belong to a single province if there is a path from u to v or v to u. Your task is to find the number of provinces.
Note: A province is a group of directly or indirectly connected cities and no other cities outside of the group.
Example 1:
Input:
... | class Solution:
def numProvinces(self, adj, V):
provinces = 0
visited = [False] * V
res = []
for node in range(V):
if not visited[node]:
provinces += 1
queue = [node]
visited[node] = True
while queue:
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR LIST VAR ASSIGN VAR VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ... |
Given an undirected graph with V vertices. We say two vertices u and v belong to a single province if there is a path from u to v or v to u. Your task is to find the number of provinces.
Note: A province is a group of directly or indirectly connected cities and no other cities outside of the group.
Example 1:
Input:
... | class Solution:
def numProvinces(self, adj, V):
n = len(adj)
visited = [(0) for _ in range(n)]
def dfs(i):
visited[i] = 1
for city in range(n):
if not visited[city] and adj[i][city]:
dfs(city)
return
count = 0... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR |
Given an undirected graph with V vertices. We say two vertices u and v belong to a single province if there is a path from u to v or v to u. Your task is to find the number of provinces.
Note: A province is a group of directly or indirectly connected cities and no other cities outside of the group.
Example 1:
Input:
... | class Solution:
def numProvinces(self, adj, V):
visited = [0] * V
cnt = 0
for i in range(V):
if not visited[i]:
cnt += 1
self.dfs(i, visited, adj, cnt)
return cnt
def dfs(self, node, visited, adj, cnt):
visited[node] = 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR |
Given an undirected graph with V vertices. We say two vertices u and v belong to a single province if there is a path from u to v or v to u. Your task is to find the number of provinces.
Note: A province is a group of directly or indirectly connected cities and no other cities outside of the group.
Example 1:
Input:
... | class Solution:
def numProvinces(self, adj, V):
def bfs(V, adjLS):
final = []
queue = []
queue.append(V)
while len(queue) > 0:
element = queue.pop(0)
final.append(element)
for i in adjLs[element]:
... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR VAR IF VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST NUMBER V... |
Given an undirected graph with V vertices. We say two vertices u and v belong to a single province if there is a path from u to v or v to u. Your task is to find the number of provinces.
Note: A province is a group of directly or indirectly connected cities and no other cities outside of the group.
Example 1:
Input:
... | def make_adj(mat, adj):
for i in range(len(mat)):
for j in range(len(mat[0])):
if mat[i][j] == 1 and i != j:
adj[i].append(j)
return adj
def dfs(adj, s, visited):
visited[s] = True
for u in adj[s]:
if visited[u] == False:
dfs(adj, u, visited)
d... | FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASS... |
Given an undirected graph with V vertices. We say two vertices u and v belong to a single province if there is a path from u to v or v to u. Your task is to find the number of provinces.
Note: A province is a group of directly or indirectly connected cities and no other cities outside of the group.
Example 1:
Input:
... | class Solution:
def numProvinces(self, adj, V):
visited = [(0) for i in range(V)]
ans = 0
def traverse(i):
if visited[i] == 0:
visited[i] = 1
for j in range(V):
if adj[i][j] == 1 and i != j and visited[j] == 0:
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR V... |
Given an undirected graph with V vertices. We say two vertices u and v belong to a single province if there is a path from u to v or v to u. Your task is to find the number of provinces.
Note: A province is a group of directly or indirectly connected cities and no other cities outside of the group.
Example 1:
Input:
... | class Solution:
def numProvinces(self, adj, V):
if V == 0:
return 0
visited = [(0) for i in range(V)]
count = 0
for i in range(V):
if visited[i] == 0:
count = count + 1
self.dfs(i, -1, visited, adj, V)
return count
... | CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR VA... |
Given an undirected graph with V vertices. We say two vertices u and v belong to a single province if there is a path from u to v or v to u. Your task is to find the number of provinces.
Note: A province is a group of directly or indirectly connected cities and no other cities outside of the group.
Example 1:
Input:
... | class Solution:
def numProvinces(self, adj, V):
def bfs(adjlst, node, visited, q):
visited[node] = 1
q.append(node)
while q:
f = q[0]
q.pop(0)
for i in adjlst[f]:
if visited[i] != 1:
... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR ... |
Given an undirected graph with V vertices. We say two vertices u and v belong to a single province if there is a path from u to v or v to u. Your task is to find the number of provinces.
Note: A province is a group of directly or indirectly connected cities and no other cities outside of the group.
Example 1:
Input:
... | class Solution:
def numProvinces(self, adj, V):
class UnionFind:
def __init__(self, size):
self.root = {i: i for i in range(size)}
self.rank = [0] * size
self.size = size
def find(self, member):
root = member
... | CLASS_DEF FUNC_DEF CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR WHILE VAR VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC... |
Given an undirected graph with V vertices. We say two vertices u and v belong to a single province if there is a path from u to v or v to u. Your task is to find the number of provinces.
Note: A province is a group of directly or indirectly connected cities and no other cities outside of the group.
Example 1:
Input:
... | def dfs(adj, i, vis):
vis.add(i)
for j in adj[i]:
if j not in vis:
dfs(adj, j, vis)
class Solution:
def numProvinces(self, adj, V):
vis = set()
ans = 0
mp = {}
for i in range(V):
mp[i] = []
for i in range(V):
for j in ran... | FUNC_DEF EXPR FUNC_CALL VAR VAR FOR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR ... |
Given an undirected graph with V vertices. We say two vertices u and v belong to a single province if there is a path from u to v or v to u. Your task is to find the number of provinces.
Note: A province is a group of directly or indirectly connected cities and no other cities outside of the group.
Example 1:
Input:
... | class Solution:
def findparent(self, node, parent):
if parent[node] == node:
return node
parent[node] = self.findparent(parent[node], parent)
return parent[node]
def unite(self, a, b, parent):
m = self.findparent(a, parent)
n = self.findparent(b, parent)
... | CLASS_DEF FUNC_DEF IF VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR RETURN 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 FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR F... |
Given an undirected graph with V vertices. We say two vertices u and v belong to a single province if there is a path from u to v or v to u. Your task is to find the number of provinces.
Note: A province is a group of directly or indirectly connected cities and no other cities outside of the group.
Example 1:
Input:
... | class Solution:
def numProvinces(self, adj, V):
def dfs(adjlst, node, visited):
visited[node] = 1
for i in adjlst[node]:
if visited[i] != 1:
dfs(adjlst, i, visited)
visited = [0] * V
q = []
c = 0
adjlst = [[] for ... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VA... |
Given an undirected graph with V vertices. We say two vertices u and v belong to a single province if there is a path from u to v or v to u. Your task is to find the number of provinces.
Note: A province is a group of directly or indirectly connected cities and no other cities outside of the group.
Example 1:
Input:
... | class Solution:
def numProvinces(self, adj, V):
def dfs(adj, i):
adj[i][i] = 0
for j in range(len(adj)):
if adj[i][j] == 1:
adj[i][j] = 0
if adj[j][j] == 1:
dfs(adj, j)
ans = 0
for i in... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR RETURN VAR |
Given an undirected graph with V vertices. We say two vertices u and v belong to a single province if there is a path from u to v or v to u. Your task is to find the number of provinces.
Note: A province is a group of directly or indirectly connected cities and no other cities outside of the group.
Example 1:
Input:
... | class Solution:
def numProvinces(self, adj, V):
n = len(adj)
visited = [0] * n
adjj = [[] for i in range(V)]
for i in range(0, n):
for j in range(0, n):
if adj[i][j] == 1 and i != j:
adjj[i].append(j)
adjj[j].append... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR... |
Given an undirected graph with V vertices. We say two vertices u and v belong to a single province if there is a path from u to v or v to u. Your task is to find the number of provinces.
Note: A province is a group of directly or indirectly connected cities and no other cities outside of the group.
Example 1:
Input:
... | class Solution:
def bfs(self, adj, V, vertex, visited):
queue = []
queue.append(vertex)
visited[vertex] = True
while queue:
node = queue.pop(0)
for i in adj[node]:
if visited[i] == False:
queue.append(i)
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FUNC_DEF ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR... |
PolandBall has such a convex polygon with n veritces that no three of its diagonals intersect at the same point. PolandBall decided to improve it and draw some red segments.
He chose a number k such that gcd(n, k) = 1. Vertices of the polygon are numbered from 1 to n in a clockwise way. PolandBall repeats the followi... | import sys
inf = (1 << 31) - 1
def solve():
n, k = map(int, input().split())
if k > n - k:
k = n - k
bit = BinaryIndexedTree([0] * n)
s = 0
res = 1
ans = []
for i in range(n):
t = (s + k) % n
if s < t:
res += bit.get_sum(t) - bit.get_sum(s + 1) + 1
... | IMPORT ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VA... |
PolandBall has such a convex polygon with n veritces that no three of its diagonals intersect at the same point. PolandBall decided to improve it and draw some red segments.
He chose a number k such that gcd(n, k) = 1. Vertices of the polygon are numbered from 1 to n in a clockwise way. PolandBall repeats the followi... | n, k = map(int, input().split())
if k << 1 > n:
k = n - k
s = 1
for i in range(n):
s += 1 + i * k // n + (i * k + k - 1) // n
print(s) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR |
PolandBall has such a convex polygon with n veritces that no three of its diagonals intersect at the same point. PolandBall decided to improve it and draw some red segments.
He chose a number k such that gcd(n, k) = 1. Vertices of the polygon are numbered from 1 to n in a clockwise way. PolandBall repeats the followi... | def euclid(a, b):
if b == 0:
return [1, 0]
if b > a:
l = euclid(b, a)
l.reverse()
return l
else:
quo = a // b
rem = a % b
l = euclid(b, rem)
m = l[0]
n = l[1]
return [n, m - n * quo]
s = input().split()
n = int(s[0])
k = int(s... | FUNC_DEF IF VAR NUMBER RETURN LIST NUMBER NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR RETURN VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER RETURN LIST VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL FUNC_... |
PolandBall has such a convex polygon with n veritces that no three of its diagonals intersect at the same point. PolandBall decided to improve it and draw some red segments.
He chose a number k such that gcd(n, k) = 1. Vertices of the polygon are numbered from 1 to n in a clockwise way. PolandBall repeats the followi... | l = input().split()
n = int(l[0])
k = int(l[1])
curr = 0
ans = 1
if k > n // 2:
k = n - k
for i in range(n):
curr += k
if i == n - 1:
ans = ans + 2 * (curr // n) - 1
elif curr % n < k:
ans = ans + 2 * (curr // n)
else:
ans = ans + 2 * (curr // n) + 1
print(ans, end=" ") | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR VAR NUMBER IF... |
PolandBall has such a convex polygon with n veritces that no three of its diagonals intersect at the same point. PolandBall decided to improve it and draw some red segments.
He chose a number k such that gcd(n, k) = 1. Vertices of the polygon are numbered from 1 to n in a clockwise way. PolandBall repeats the followi... | class Fen:
def __init__(self, n):
self.value = [0] * n
def get(self, fro, to):
return self.get1(to) - self.get1(fro - 1)
def get1(self, to):
to = min(to, len(self.value))
result = 0
while to >= 0:
result += self.value[to]
to = (to & to + 1) ... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN VAR FUNC_DEF WHILE VAR FUNC_CA... |
PolandBall has such a convex polygon with n veritces that no three of its diagonals intersect at the same point. PolandBall decided to improve it and draw some red segments.
He chose a number k such that gcd(n, k) = 1. Vertices of the polygon are numbered from 1 to n in a clockwise way. PolandBall repeats the followi... | n, m = [int(i) for i in input().split()]
if m > n // 2:
m = n - m
ans = [1]
count = 0
c = 1
for i in range(n):
count += m
if count > n:
c += 1
count -= n
ans.append(ans[-1] + c)
c += 1
else:
ans.append(ans[-1] + c)
ans = ans[1:]
print(*ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUM... |
PolandBall has such a convex polygon with n veritces that no three of its diagonals intersect at the same point. PolandBall decided to improve it and draw some red segments.
He chose a number k such that gcd(n, k) = 1. Vertices of the polygon are numbered from 1 to n in a clockwise way. PolandBall repeats the followi... | n, k = list(map(int, input().split()))
if n // 2 < k:
k = n - k
i = 1
count = 1
ans = [1]
for _ in range(n):
i += k
if i > n + 1:
count += 1
ans.append(ans[-1] + count)
count += 1
i -= n
else:
ans.append(ans[-1] + count)
print(*ans[1:]) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR EXPR FUNC... |
PolandBall has such a convex polygon with n veritces that no three of its diagonals intersect at the same point. PolandBall decided to improve it and draw some red segments.
He chose a number k such that gcd(n, k) = 1. Vertices of the polygon are numbered from 1 to n in a clockwise way. PolandBall repeats the followi... | n, k = list(map(int, input().strip().split()))
if k > n // 2:
k = n - k
intersection = n * [0]
count = 1
done = False
i = 0
result = []
for i in range(1, n + 1):
nn = i * k // n
j = i * k % n
if j < k:
count += 2 * nn
else:
count += 2 * nn + 1
result.append(count)
result[-1] -= 1... | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ... |
PolandBall has such a convex polygon with n veritces that no three of its diagonals intersect at the same point. PolandBall decided to improve it and draw some red segments.
He chose a number k such that gcd(n, k) = 1. Vertices of the polygon are numbered from 1 to n in a clockwise way. PolandBall repeats the followi... | import sys
inf = (1 << 31) - 1
def solve():
n, k = map(int, input().split())
if k > n - k:
k = n - k
s = 0
res = 1
a = 1
ans = [0] * n
for i in range(n):
t = (s + k) % n
if t < s and t > 0:
res += a + 1
a += 2
else:
res +... | IMPORT ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF... |
Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.
Example:
Input: 3
Output:
[
[ 1, 2, 3 ],
[ 8, 9, 4 ],
[ 7, 6, 5 ]
] | class Solution:
def generateMatrix(self, n):
left = 0
top = 0
right = n - 1
bottom = n - 1
res = [[(0) for _ in range(n)] for _ in range(n)]
num = 1
while left < right and top < bottom:
for i in range(left, right):
res[top][i] = nu... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR ... |
Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.
Example:
Input: 3
Output:
[
[ 1, 2, 3 ],
[ 8, 9, 4 ],
[ 7, 6, 5 ]
] | class Solution:
def generateMatrix(self, n):
retv = [[(0) for i in range(n)] for j in range(n)]
num = n * n
i, j, di, dj = 0, 0, 0, 1
for k in range(1, num + 1):
retv[i][j] = k
if retv[(i + di) % n][(j + dj) % n]:
di, dj = dj, -di
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VA... |
Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.
Example:
Input: 3
Output:
[
[ 1, 2, 3 ],
[ 8, 9, 4 ],
[ 7, 6, 5 ]
] | class Solution:
def generateMatrix(self, n):
arr = [a for a in range(1, n * n + 1)]
matrix = [[a for a in range(1, n + 1)] for b in range(1, n + 1)]
num = 0
row_s = 0
row_e = n - 1
col_s = 0
col_e = n - 1
while col_e > col_s and row_e > row_s:
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR V... |
Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.
Example:
Input: 3
Output:
[
[ 1, 2, 3 ],
[ 8, 9, 4 ],
[ 7, 6, 5 ]
] | class Solution:
def generateMatrix(self, n):
t = 1
temp = []
for i in range(n):
temp.append([None] * n)
rep = int(n / 2) if n % 2 == 0 else int(n / 2) + 1
k = 1
for i in range(rep):
for j in range(i, n - i - 1):
temp[i][j] = k
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST NONE VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR... |
Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.
Example:
Input: 3
Output:
[
[ 1, 2, 3 ],
[ 8, 9, 4 ],
[ 7, 6, 5 ]
] | class Solution:
def generateMatrix(self, n):
matrix = []
if n == 0:
return matrix
matrix = [([0] * n) for i in range(n)]
rowBegin = 0
rowEnd = n - 1
colBegin = 0
colEnd = n - 1
num = 0
while True:
for j in range(colBegi... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST IF VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR V... |
Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.
Example:
Input: 3
Output:
[
[ 1, 2, 3 ],
[ 8, 9, 4 ],
[ 7, 6, 5 ]
] | class Solution:
def generateMatrix(self, n):
if n == 0:
return []
nums = list(range(1, n * n + 1))
matrix = [[nums[-1]]]
start = n * n - 1
while start > 0:
matrix = matrix[::-1]
matrix = [*zip(*matrix)]
matrix = [nums[start - l... | CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR LIST LIST VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST VAR BIN_OP VAR FUNC_CALL VAR VAR... |
Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.
Example:
Input: 3
Output:
[
[ 1, 2, 3 ],
[ 8, 9, 4 ],
[ 7, 6, 5 ]
] | class Solution:
def generateMatrix(self, n):
if n < 1:
return []
left = 0
right = n - 1
up = 0
bottom = n - 1
self.matrix = [[(0) for i in range(n)] for j in range(n)]
count = 1
while left <= right:
if left < right:
... | CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VA... |
Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.
Example:
Input: 3
Output:
[
[ 1, 2, 3 ],
[ 8, 9, 4 ],
[ 7, 6, 5 ]
] | class Solution:
def generateMatrix(self, n):
res = [[(0) for i in range(n)] for j in range(n)]
count, rowNum = 1, n
rowIndex1, rowIndex2, colIndex1, colIndex2 = 0, n - 1, n - 1, 0
while rowNum >= 1:
for i in range(colIndex2, colIndex1 + 1):
res[rowIndex1]... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER WHILE VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP V... |
Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.
Example:
Input: 3
Output:
[
[ 1, 2, 3 ],
[ 8, 9, 4 ],
[ 7, 6, 5 ]
] | class Solution:
def generateMatrix(self, n):
if n == 0:
return []
res = [([0] * n) for _ in range(n)]
record = set()
rupper, rdown, cleft, cright, val = 0, n - 1, 0, n - 1, 1
while rupper < rdown and cleft < cright:
for col in range(cleft, cright):
... | CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN LIST ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER WHILE VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VA... |
Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.
Example:
Input: 3
Output:
[
[ 1, 2, 3 ],
[ 8, 9, 4 ],
[ 7, 6, 5 ]
] | class Solution:
def generateMatrix(self, n):
matrix = [[(0) for i in range(n)] for i in range(n)]
start, end = 0, n - 1
count = 1
for j in range(int(n / 2)):
for i in range(start, end + 1):
matrix[start][i] = count
count += 1
f... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VA... |
Given a positive integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.
Example:
Input: 3
Output:
[
[ 1, 2, 3 ],
[ 8, 9, 4 ],
[ 7, 6, 5 ]
] | class Solution:
def generateMatrix(self, n):
if n == 0:
return []
elif n == 1:
return [[1]]
cnt = 1
ret = [([None] * n) for _ in range(n)]
def layer(width, margin):
if not width > 0:
return
nonlocal cnt
... | CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN LIST IF VAR NUMBER RETURN LIST LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NONE VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER RETURN FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIG... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | st = input()
cnt = 0
a = []
di = {")": "(", ">": "<", "]": "[", "}": "{"}
for i in st:
if i in ["(", "<", "[", "{"]:
a.append(i)
elif a != []:
x = a.pop()
if x != di[i]:
cnt += 1
else:
a = [-1]
break
if a == []:
print(cnt)
else:
print("Impossible") | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING FOR VAR VAR IF VAR LIST STRING STRING STRING STRING EXPR FUNC_CALL VAR VAR IF VAR LIST ASSIGN VAR FUNC_CALL VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR LIST NUMBER IF VAR LIST EXPR FUNC_CALL V... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | def solve():
S = input()
P = {">": "<", "]": "[", ")": "(", "}": "{"}
stack = []
n = 0
ans = 0
for i, c in enumerate(S):
if c in "<[{(":
n += 1
stack.append(c)
else:
n -= 1
if len(stack) == 0:
print("Impossible")
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR F... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | import sys
def input():
return sys.stdin.readline().strip()
def iinput():
return int(input())
def rinput():
return map(int, sys.stdin.readline().strip().split())
def get_list():
return list(map(int, sys.stdin.readline().strip().split()))
n = input()
a = ["[", "<", "{", "(", "]", ">", "}", ")"]... | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING STR... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | S = input()
N = len(S)
lt = {"[", "(", "{", "<"}
rt = {"]", ")", "}", ">"}
stack = []
res = 0
for i in range(N):
if S[i] in lt:
stack.append(i)
elif not stack:
print("Impossible")
break
else:
c = stack.pop()
if S[c] + S[i] not in {"[]", "()", "{}", "<>"}:
... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING STRING STRING STRING ASSIGN VAR STRING STRING STRING STRING ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR VAR VAR VAR STRING... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | s = input()
d = ["<", "{", "[", "("]
d2 = [">", "}", "]", ")"]
a = []
k = 0
sum1 = 0
sum2 = 0
for i in s:
if i in d:
sum1 += 1
a.append(d.index(i))
else:
sum2 += 1
if len(a) == 0:
k = "Impossible"
break
elif a[-1] == d2.index(i):
a.pop(... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING STRING ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING IF VAR NU... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | s = input()
otc = {"[": "]", "{": "}", "(": ")", "<": ">"}
cto = {">": "<", "}": "{", ")": "(", "]": "["}
stack = []
res1 = 0
for c in s:
if c in otc.keys():
stack.append(c)
continue
if len(stack) == 0:
res1 = -1
break
o = stack[len(stack) - 1]
stack.pop()
if c == otc... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | def getResult(s):
if not s:
return "Impossible"
dic = {"(": ")", "[": "]", "{": "}", "<": ">"}
res = 0
stack = []
for x in list(s):
if x in dic:
stack.append(x)
elif len(stack) == 0:
return "Impossible"
else:
cur = stack.pop()
... | FUNC_DEF IF VAR RETURN STRING ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN STRING ASSIGN VAR FUNC_CALL VAR IF VAR VAR VAR VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | bracket = input()
stack = []
bracketType = {
"[": (0, "]"),
"(": (0, ")"),
"<": (0, ">"),
"{": (0, "}"),
"]": (1,),
")": (1,),
">": (1,),
"}": (1,),
}
res = 0
for b in bracket:
if bracketType.get(b) == None:
break
elif bracketType.get(b)[0] == 0:
stack.append(b)
... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING NUMBER STRING NUMBER STRING NUMBER STRING NUMBER STRING NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NONE IF FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_C... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | s = input()
open_b = ["<", "{", "[", "("]
close_b = [">", "}", "]", ")"]
stack = []
d = {open_b[i]: close_b[i] for i in range(4)}
stack = []
ans = 0
for i in range(len(s)):
stack.append(s[i])
if len(stack) >= 2 and stack[-1] in close_b and stack[-2] in open_b:
if d[stack[-2]] != stack[-1]:
a... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING STRING ASSIGN VAR LIST ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | k, s = 0, []
for q in input():
i = "[{<(]}>)".find(q)
if i > 3:
if not s:
s = 1
break
if s.pop() != i - 4:
k += 1
else:
s += [i]
print("Impossible" if s else k) | ASSIGN VAR VAR NUMBER LIST FOR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR IF VAR NUMBER IF VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR LIST VAR EXPR FUNC_CALL VAR VAR STRING VAR |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | import sys
s = input()
stack = []
piar = {"{": "}", "(": ")", "<": ">", "[": "]"}
ans = 0
for ch in s:
if ch in piar.keys():
stack.append(ch)
else:
if len(stack) == 0:
print("Impossible")
sys.exit()
if piar[stack.pop()] != ch:
ans += 1
if len(stack) !... | IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR ... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | import sys
def fun():
try:
str = input()
except ValueError:
print("Invalid number")
return
S = {"}": "{", ")": "(", ">": "<", "]": "["}
L = []
ans = 0
for c in str:
if c in S.values():
L.append(c)
pass
else:
if len(L) ... | IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR N... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | from sys import stdin
def main():
s = stdin.readline()
stack = []
ok = True
ans = 0
close = ">}])"
open = "<{[("
for i in range(len(s) - 1):
if s[i] in close:
if not stack:
ok = False
break
else:
i1 = close.ind... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR IF VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CAL... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | s = input()
s1 = []
for i in s:
if i == "(":
s1.append(1)
elif i == "[":
s1.append(2)
elif i == "{":
s1.append(3)
elif i == "<":
s1.append(4)
elif i == ")":
s1.append(-1)
elif i == "]":
s1.append(-2)
elif i == "}":
s1.append(-3)
els... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR STRING EXPR FUNC_CAL... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | def p1(s):
stack = []
n = len(s)
dic = {")": "(", "}": "{", "]": "[", ">": "<"}
cnt = 0
for x in s:
if x not in dic:
stack.append(x)
elif not stack:
return "Impossible"
elif dic[x] != stack.pop():
cnt += 1
else:
pass
... | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR RETURN STRING IF VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR RETURN VAR RETURN STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EX... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | try:
def ad(expr):
stack = []
l = 0
for char in expr:
if char in ["(", "{", "[", "<"]:
stack.append(char)
else:
if not stack:
return "Impossible"
current_char = stack.pop()
if current... | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR LIST STRING STRING STRING STRING EXPR FUNC_CALL VAR VAR IF VAR RETURN STRING ASSIGN VAR FUNC_CALL VAR IF VAR STRING IF VAR STRING VAR STRING VAR STRING VAR STRING VAR NUMBER IF VAR STRING IF VAR STRING VAR STRING VAR STRING VAR STRING VAR NUMBER IF VAR STRIN... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | s = input()
cnt = 0
closing = [">", "}", "]", ")"]
opening = ["<", "{", "[", "("]
oc = 0
cc = 0
for i in s:
if i in opening:
oc += 1
else:
cc += 1
if s[0] in closing or len(s) & 1 or oc != cc:
print("Impossible")
else:
stack = []
for i in s:
if i in closing:
if le... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST STRING STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR ... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | def process(S):
flip = {"(": ")", "[": "]", "{": "}", "<": ">"}
other = {flip[x]: x for x in flip}
for x in other:
flip[x] = other[x]
d = []
answer = 0
for x in S:
if x in "([{<":
d.append(x)
else:
if len(d) == 0:
return [False, 0]
... | FUNC_DEF ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR VAR VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN LIST NUMBER NUMBER ASSIGN VAR VAR VAR IF VAR VAR NUMBER... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | def opposto(s):
if s == ")":
return "("
elif s == "]":
return "["
elif s == "}":
return "{"
else:
return "<"
def f(s):
n = [0] * 10**6
checker = 0
cont = 0
pos = 0
for c in s:
if c in ["(", "[", "{", "<"]:
n[checker] = c
... | FUNC_DEF IF VAR STRING RETURN STRING IF VAR STRING RETURN STRING IF VAR STRING RETURN STRING RETURN STRING FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR LIST STRING STRING STRING STRING ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | opening = set(["(", "<", "[", "{"])
closing = set([")", ">", "]", "}"])
def im_noob(s):
ans = 0
l = 0
stack = []
for i in s:
if i in opening:
if i == "[":
stack.append("]")
elif i == "<":
stack.append(">")
elif i == "{":
... | ASSIGN VAR FUNC_CALL VAR LIST STRING STRING STRING STRING ASSIGN VAR FUNC_CALL VAR LIST STRING STRING STRING STRING FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR IF VAR STRING EXPR FUNC_CALL VAR STRING IF VAR STRING EXPR FUNC_CALL VAR STRING IF VAR STRING EXPR FUNC_CALL VAR STRING ... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | S = input()
stack = []
count = 0
length = len(S)
flag = 0
if length % 2:
flag = 1
else:
for i in range(length):
if S[i] == "<" or S[i] == "(" or S[i] == "{" or S[i] == "[":
stack.append(S[i])
elif stack != []:
if S[i] == ">" and stack.pop() != "<":
count +... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR IF VAR LIST IF VAR VAR STRING FUNC_CALL VAR STRING VAR NUMB... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | s = input()
stack = []
res = 0
for c in s:
if c in "(<[{":
stack.append(c)
else:
if not stack:
print("Impossible")
break
last = stack.pop()
if last + c not in ("[]", "()", "<>", "{}"):
res += 1
else:
if stack:
print("Impossible")
... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR IF BIN_OP VAR VAR STRING STRING STRING STRING VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | a = input()
b = 0
c = "([{<"
d = ")]}>"
e = []
f = False
for i in a:
if i in c:
e += [i]
else:
if not e:
print("Impossible")
f = True
break
if d.index(i) != c.index(e[-1]):
b += 1
e.pop()
if e:
print("Impossible")
elif not f:
... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR LIST VAR IF VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR IF VAR EXPR FUNC_CALL VAR STRING IF VAR EXPR... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | st = input()
c = 0
b = r = s = l = 0
for i in st:
if i in ["[", "<", "{", "("]:
c += 1
else:
c -= 1
if c < 0:
break
ans = 0
if c != 0:
print("Impossible")
else:
stack = []
for i in st:
if i in ["[", "<", "{", "("]:
stack.append(i)
elif ... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER FOR VAR VAR IF VAR LIST STRING STRING STRING STRING VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR VAR IF VAR LIST STRING STRING STRING STRING EXPR FUNC_CALL VAR VAR IF VAR NUM... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | from sys import stdin, stdout
class SOLVE:
def solve(self):
R = stdin.readline
W = stdout.write
s = R()[:-1]
brackets, cnt, check = [], 0, 0
for i in range(len(s)):
if s[i] in ["(", "<", "{", "["]:
brackets.append(s[i])
check += ... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR LIST STRING STRING STRING STRING EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN NUMBER IF VAR VAR ... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | s = input()
n = len(s)
op = {"<": 0, "{": 1, "[": 2, "(": 3}
cl = {">": 0, "}": 1, "]": 2, ")": 3}
stack = []
flag = True
swaps = 0
for i in range(n):
if s[i] in op:
stack.append(s[i])
elif stack:
if op[stack.pop()] != cl[s[i]]:
swaps += 1
else:
flag = False
break... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER ASSIGN VAR DICT STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | stack = []
counter = 0
possible = True
for b in input():
if b in "{<([":
stack.append(b)
else:
if not stack:
possible = False
break
popped = stack.pop()
if (
b == "}"
and popped != "{"
or b == ">"
and popped ... | ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR STRING EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRI... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | di = {")": "(", ">": "<", "]": "[", "}": "{"}
stack = []
s = list(input())
flag = 0
c = 0
for i in s:
if i in ["(", "<", "[", "{"]:
stack.append(i)
elif len(stack) != 0:
x = stack.pop()
if x != di[i]:
c += 1
else:
stack = [0]
break
if len(stack) == 0:
... | ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR LIST STRING STRING STRING STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR VAR VAR VAR NUMBER ASS... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | s = input()
def fun():
t = ["[", "<", "{", "("]
t1 = ["]", ">", "}", ")"]
res = []
summ = 0
for i in range(len(s)):
try:
if s[i] in t:
res.append(s[i])
elif s[i] in t1:
d = len(res) - 1
if t.index(res[d]) != t1.index(s... | ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST STRING STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING STRING ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | s = list(input())
d = {"(": ")", "[": "]", "<": ">", "{": "}"}
stack = []
ans = 0
c = 0
for i in s:
if i in d.keys():
stack.append(i)
c += 1
else:
c -= 1
if c < 0:
print("Impossible")
exit()
b = stack.pop()
if i != d[b]:
ans += ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | opening = set(["(", "<", "[", "{"])
closing = set([")", ">", "]", "}"])
def im_noob(s):
o = c = boom = 0
for i in s:
if i in opening:
o += 1
boom += 1
else:
c += 1
boom -= 1
if boom < 0:
return "Impossible"
if o != c:
... | ASSIGN VAR FUNC_CALL VAR LIST STRING STRING STRING STRING ASSIGN VAR FUNC_CALL VAR LIST STRING STRING STRING STRING FUNC_DEF ASSIGN VAR VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN STRING IF VAR VAR RETURN STRING IF VAR NUMBER RETURN STRING ASSIGN VAR NUMBER ASS... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | s = input()
open = "({<["
close = ")}>]"
clopen = {"]": "[", "}": "{", ">": "<", ")": "("}
ir2 = 0
ir = 0
if len(s) % 2 == 1:
print("Impossible")
return
else:
l = []
for i in range(len(s)):
if s[i] in open:
ir += 1
l.append(s[i])
else:
ir -= 1
... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR N... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | seq = input()
a = []
fl = True
z = 0
for i in seq:
if i == "<" or i == "[" or i == "{" or i == "(":
a.append(i)
elif i == ">":
if len(a) and a[-1] == "<":
a.pop()
elif len(a) and a[-1] != "<":
a.pop()
z += 1
else:
fl = False
... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR IF VAR STRING IF FUNC_CALL VAR VAR VAR NUMBER STRING EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR NUMBER STRING EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | import sys
def rbs(mystr):
stack = []
kuohao = {"<": ">", "{": "}", "[": "]", "(": ")"}
count = 0
for x in mystr:
if x in kuohao:
stack.append(x)
elif len(stack) == 0:
return "Impossible"
elif kuohao[stack.pop()] != x:
count += 1
else... | IMPORT FUNC_DEF ASSIGN VAR LIST ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN STRING IF VAR FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN VAR RETURN STRING ASSIGN VAR FUNC_CALL ... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | import sys
s = input()
stack = []
ans = 0
brackets = {">": "<", "}": "{", "]": "[", ")": "("}
for c in s:
if c in ">}])":
if not stack:
print("Impossible")
exit()
if stack[-1] != brackets[c]:
ans += 1
stack.pop()
else:
stack.append(c)
if len(s... | IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING FOR VAR VAR IF VAR STRING IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR EXPR FUN... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | import sys
s = input()
OPENING = "<", "{", "[", "("
CLOSING = ">", "}", "]", ")"
result = 0
stack = []
for c in s:
if c in OPENING:
stack.append(c)
elif stack:
last_br = stack.pop()
if c != CLOSING[OPENING.index(last_br)]:
result += 1
else:
print("Impossible")
... | IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING STRING STRING STRING ASSIGN VAR STRING STRING STRING STRING ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR VAR ST... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | opening = {"[": "]", "<": ">", "{": "}", "(": ")"}
closing = {"]": "[", ">": "<", "}": "{", ")": "("}
s = input()
stack = []
answ = 0
for c in s:
if c in opening:
stack.append(c)
else:
if len(stack) == 0:
print("Impossible")
return
op = stack.pop()
if c !=... | ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | s = list(input())
def isopen(c):
return c == "<" or c == "{" or c == "[" or c == "("
def match(a, b):
return (
a == "<"
and b == ">"
or a == "{"
and b == "}"
or a == "["
and b == "]"
or a == "("
and b == ")"
)
def isRbs():
br = []
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN VAR STRING VAR STRING VAR STRING VAR STRING FUNC_DEF RETURN VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING FUNC_DEF ASSIGN VAR LIST IF FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING RETURN NUMBER ASSIGN VAR NUMBER... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | BRACKETS = "{ }, [ ], < >, ( )"
openers = dict()
closers = dict()
for opener, closer in [x.split() for x in BRACKETS.split(",")]:
openers[opener] = closer
closers[closer] = opener
stack = list()
impossible = False
res = 0
for char in input():
if char in openers:
stack.append(char)
else:
... | ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR VAR... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | word = input()
BRACKETS = [("<", ">"), ("{", "}"), ("[", "]"), ("(", ")")]
OPENING = [b[0] for b in BRACKETS]
MATCH = dict(BRACKETS)
IMPOSSIBLE = "Impossible"
def is_opening(w):
return w in OPENING
def same_kind(wo, wc):
return MATCH[wo] == wc
def solve(word):
temp = []
result = 0
for w in wor... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FUNC_DEF RETURN VAR VAR FUNC_DEF RETURN VAR VAR VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | s = str(input())
a = []
v = 0
k = 0
map = {")": "(", "]": "[", "}": "{", ">": "<"}
for _ in range(len(s)):
if s[_] == "<" or s[_] == "(" or s[_] == "{" or s[_] == "[":
a.append(s[_])
elif len(a) == 0:
print("Impossible")
k = 1
break
elif a[-1] == map[s[_]]:
a.pop(-1)
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | def solution(s):
st = []
ans = 0
for i, j in enumerate(s):
if j in open:
st.append((i, j))
if j in close:
if not st:
return "Impossible"
q, w = st.pop()
if close.index(j) != open.index(w):
ans += 1
if st:
... | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR IF VAR RETURN STRING ASSIGN VAR VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR RETURN STRING RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRI... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | s = input()
d = []
ans = 0
for f in s:
if f in "{[<(":
d.append(f)
elif f == ")" and d and d[-1] == "(":
d.pop()
elif f == "}" and d and d[-1] == "{":
d.pop()
elif f == "]" and d and d[-1] == "[":
d.pop()
elif f == ">" and d and d[-1] == "<":
d.pop()
elif ... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR IF VAR STRING VAR VAR NUMBER STRING EXPR FUNC_CALL VAR IF VAR STRING VAR VAR NUMBER STRING EXPR FUNC_CALL VAR IF VAR STRING VAR VAR NUMBER STRING EXPR FUNC_CALL VAR IF VAR STRING VAR VAR NUMBER STRING EXPR FUNC_C... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | k = input()
p = 0
q = []
for i in range(len(k)):
if k[i] == "(" or k[i] == "{" or k[i] == "[" or k[i] == "<":
q.append(k[i])
else:
if len(q) <= 0:
print("Impossible")
exit(0)
m = q.pop()
if k[i] == ")" and m == "(":
continue
elif k[i] =... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR VAR STRING VAR STRI... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | s = input()
sc = s
sc = sc.replace("<", "(").replace("[", "(").replace("{", "(")
sc = sc.replace(">", ")").replace("]", ")").replace("}", ")")
def chec(ss):
c = 0
for i in ss:
if i == "(":
c += 1
if i == ")":
c -= 1
if c < 0:
return False
return ... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING STRING STRING STRING STRING STRING ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING STRING STRING STRING STRING STRING FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER IF VAR NUMBER RET... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | def stacks(brackets):
opening = ["[", "{", "(", "<"]
closing = ["}", "{", "(", "<"]
stack = []
changes = 0
for b in brackets:
if b in opening:
stack.append(b)
else:
if len(stack) == 0:
return -1
last_brackets = stack.pop()
... | FUNC_DEF ASSIGN VAR LIST STRING STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING STRING ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR STRING IF VAR STRING VAR NUMBER IF VAR STRING IF VAR STRING VAR NUMBE... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | s2 = input()
dic = {"{": 1, "}": -1, "<": 2, ">": -2, "[": 3, "]": -3, "(": 4, ")": -4}
stack = []
count = 0
n = 0
for x in s2:
if dic[x] < 0:
if n == 0:
print("Impossible")
quit()
if dic[stack[n - 1]] + dic[x] != 0:
count += 1
stack.pop()
n = n - ... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF BIN_OP VAR VAR BIN_OP V... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | stk = []
ops = 0
f = 1
l = list(input())
for i in l:
if i in "{<([":
stk.append(i)
else:
if not stk:
f = 0
break
c = stk[-1]
if c + i in ["[]", "{}", "<>", "()"]:
stk.pop()
else:
ops += 1
stk.pop()
if f == 1 and ... | ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP VAR VAR LIST STRING STRING STRING STRING EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER VAR EXPR FUNC_CALL ... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | a = input()
s = []
replacements = 0
flag = 0
for i in range(len(a)):
if a[i] in "({[<":
s.append(a[i])
else:
if len(s) == 0:
flag = 1
break
top = s.pop()
if a[i] == ">" and top != "<":
replacements += 1
if a[i] == ")" and top != "(":
... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR VAR STRING VAR STRING VAR NUMBER IF VAR VAR STRING VAR STRING VAR NUMBER IF VAR ... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | def solve(s: str):
stack = []
answer = 0
for c in s:
if c in "([{<":
stack.append(c)
else:
if not stack:
print("Impossible")
return
b = stack[-1]
if (
b == "("
and c != ")"
... | FUNC_DEF VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR VAR NUMBER IF VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR STRING VAR ASSIGN ... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | s = input()
flag = 0
stack = []
op = ["<", "{", "[", "("]
ans = 0
for i in range(len(s)):
if s[i] in op:
flag += 1
else:
flag -= 1
if flag < 0:
print("Impossible")
break
if s[i] in op:
stack.append(s[i])
elif s[i] == ">" and stack.pop() != "<":
ans += ... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST STRING STRING STRING STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR STRING FUNC_CALL VAR STRING V... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | s = input()
open = {"(", "{", "[", "<"}
res = 0
our = []
for elem in s:
if elem in open:
our.append(elem)
elif our:
res += abs(ord(elem) - ord(our[-1])) > 2
our.pop()
else:
print("Impossible")
exit()
if our:
print("Impossible")
else:
print(res) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING STRING STRING STRING ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR EXPR FUNC_CALL VAR STRI... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | s = input()
left, ans = list(), 0
def type(ch):
if ch in "<>":
return 0
if ch in "{}":
return 1
if ch in "[]":
return 2
if ch in "()":
return 3
for ch in s:
if ch in "<{[(":
left.append(ch)
else:
if len(left) == 0:
print("Impossible... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR STRING RETURN NUMBER IF VAR STRING RETURN NUMBER IF VAR STRING RETURN NUMBER IF VAR STRING RETURN NUMBER FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VA... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | s = input()
open = "<", "(", "[", "{"
close = ">", ")", "]", "}"
resp = {close[i]: open[i] for i in (0, 1, 2, 3)}
cnt = 0
st = []
flag = True
for c in s:
if c in open:
st.append(c)
elif st and st[-1] == resp[c]:
st.pop()
elif st:
st.pop()
cnt += 1
else:
flag = Fal... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING STRING STRING STRING ASSIGN VAR STRING STRING STRING STRING ASSIGN VAR VAR VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR IF VAR EXPR FUN... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | s = input()
arr = []
l = len(s)
flag = False
cnt = 0
open = ["{", "[", "<", "("]
close = ["}", "]", ">", ")"]
dic = {"{": "}", "[": "]", "<": ">", "(": ")"}
for i in range(l):
if s[i] in open:
arr.append(s[i])
else:
if arr == []:
flag = True
break
if dic[arr[-1]] ... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST STRING STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING STRING ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CAL... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | stack = []
def main():
s = str(input())
open = list("<{[(")
close = list(">}])")
answer = 0
for e in s:
if len(stack) == 0:
if e in open:
stack.append(e)
else:
print("Impossible")
return
else:
top =... | ASSIGN VAR LIST FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR IF VAR VAR VA... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | s = list(input())
x = list("<>{}[]()")
l = [0] * 4
d = {}
k = 0
o, c = 0, 0
f = 1
ans = 0
for t in s:
y = x.index(t)
yy = y // 2
if y % 2 == 0:
if f:
k += 1
o += 1
d[k] = yy
f = 1
else:
if not f:
k -= 1
if k <= 0:
print(... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMB... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | from sys import argv, exit
def rstr():
return input()
def rint():
return int(input())
def rints():
return [int(i) for i in input().split(" ")]
def prnt(*args):
if "-v" in argv:
print(*args)
op = ["[", "{", "(", "<"]
cl = ["]", "}", ")", ">"]
oppo = {"]": "[", "}": "{", ">": "<", ")": "... | FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF IF STRING VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST STRING STRING STRING STRING ASSIGN VAR LIST STRING STRING STRING STRING ASSIGN VAR DICT STRING STRING STRING STRING... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | d = {"(": ")", "[": "]", "{": "}", "<": ">"}
st, k = [], 0
for i in input():
if i in d:
st.append(i)
elif st:
if d[st[-1]] != i:
k += 1
st.pop()
else:
print("Impossible")
exit()
if st:
print("Impossible")
exit()
print(k) | ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR VAR LIST NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | SYMBOLS = {"}": "{", "]": "[", ")": "(", ">": "<"}
SYMBOLS_L, SYMBOLS_R = SYMBOLS.values(), SYMBOLS.keys()
arr = []
num = 0
left = 0
right = 0
flag = True
s = input()
for c in s:
if c in SYMBOLS_L:
arr.append(c)
left += 1
elif c in SYMBOLS_R:
right += 1
if len(arr) == 0:
... | ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER IF FUNC_CALL ... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | def main():
s = input()
open_paren = "<([{"
close = {"]": "[", ">": "<", ")": "(", "}": "{"}
stack = []
ans = 0
imp = False
for c in s:
if c in open_paren:
stack.append(c)
else:
if not stack:
imp = True
break
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR FUNC_C... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | R = lambda: list(map(int, input().split()))
s = input()
ok = True
ans = 0
st = []
opn = set("<[({")
inv = {"}": "{", ")": "(", ">": "<", "]": "["}
for i in s:
if i in opn:
st.append(i)
else:
if not st:
ok = False
break
if inv[i] != st[-1]:
ans += 1
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR NUMBER I... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | import sys
s = input()
q = []
c = 0
for x in s:
if x == "[" or x == "{" or x == "(" or x == "<":
q.append(x)
elif len(q) > 0 and (ord(x) == ord(q[-1]) + 2 or x == ")" and q[-1] == "("):
q.pop(-1)
elif len(q) > 0:
q.pop(-1)
c += 1
else:
print("Impossible")
... | IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR STRING VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | s = input()
brackets = {"<": ">", "{": "}", "[": "]", "(": ")"}
OPENING = "<{[("
CLOSING = ">}])"
def main(s):
stack = []
res = 0
for c in s:
if c in OPENING:
stack.append(c)
else:
if stack:
top = stack.pop()
if top in OPENING:
... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR STRING ASSIGN VAR STRING FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR IF VAR VAR VAR VAR NUMBER RETURN STRING RETURN VAR VAR ... |
You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following definition of a... | s = input().strip()
braces = {
"<": ">",
">": "<",
"{": "}",
"}": "{",
"[": "]",
"]": "[",
"(": ")",
")": "(",
}
stack = []
answer = 0
for char in s:
if char in "(<{[":
stack.append(char)
elif char in ")>}]":
if not stack:
print("Impossible")
... | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR IF VAR STRING IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN V... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.