message stringlengths 2 15.4k | message_type stringclasses 2
values | message_id int64 0 1 | conversation_id int64 45 107k | cluster float64 21 21 | __index_level_0__ int64 90 214k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string a, consisting of n characters, n is even. For each i from 1 to n a_i is one of 'A', 'B' or 'C'.
A bracket sequence is a string containing only characters "(" and ")". A r... | instruction | 0 | 21,435 | 21 | 42,870 |
Yes | output | 1 | 21,435 | 21 | 42,871 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string a, consisting of n characters, n is even. For each i from 1 to n a_i is one of 'A', 'B' or 'C'.
A bracket sequence is a string containing only characters "(" and ")". A r... | instruction | 0 | 21,436 | 21 | 42,872 |
Yes | output | 1 | 21,436 | 21 | 42,873 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string a, consisting of n characters, n is even. For each i from 1 to n a_i is one of 'A', 'B' or 'C'.
A bracket sequence is a string containing only characters "(" and ")". A r... | instruction | 0 | 21,437 | 21 | 42,874 |
Yes | output | 1 | 21,437 | 21 | 42,875 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string a, consisting of n characters, n is even. For each i from 1 to n a_i is one of 'A', 'B' or 'C'.
A bracket sequence is a string containing only characters "(" and ")". A r... | instruction | 0 | 21,438 | 21 | 42,876 |
Yes | output | 1 | 21,438 | 21 | 42,877 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string a, consisting of n characters, n is even. For each i from 1 to n a_i is one of 'A', 'B' or 'C'.
A bracket sequence is a string containing only characters "(" and ")". A r... | instruction | 0 | 21,439 | 21 | 42,878 |
No | output | 1 | 21,439 | 21 | 42,879 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string a, consisting of n characters, n is even. For each i from 1 to n a_i is one of 'A', 'B' or 'C'.
A bracket sequence is a string containing only characters "(" and ")". A r... | instruction | 0 | 21,440 | 21 | 42,880 |
No | output | 1 | 21,440 | 21 | 42,881 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string a, consisting of n characters, n is even. For each i from 1 to n a_i is one of 'A', 'B' or 'C'.
A bracket sequence is a string containing only characters "(" and ")". A r... | instruction | 0 | 21,441 | 21 | 42,882 |
No | output | 1 | 21,441 | 21 | 42,883 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string a, consisting of n characters, n is even. For each i from 1 to n a_i is one of 'A', 'B' or 'C'.
A bracket sequence is a string containing only characters "(" and ")". A r... | instruction | 0 | 21,442 | 21 | 42,884 |
No | output | 1 | 21,442 | 21 | 42,885 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A bracket sequence is a string, containing only characters "(", ")", "[" and "]".
A correct bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the ... | instruction | 0 | 24,096 | 21 | 48,192 |
Tags: data structures, expression parsing, implementation
Correct Solution:
```
'''input
((()))([]
'''
from sys import stdin
def check_valid(string):
stack = []
for i in string:
if i in ['(', '[']:
stack.append(i)
elif i == ')':
if len(stack) > 0:
if stack[-1] == '(':
stack.pop()
continue
... | output | 1 | 24,096 | 21 | 48,193 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A bracket sequence is a string, containing only characters "(", ")", "[" and "]".
A correct bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the ... | instruction | 0 | 24,097 | 21 | 48,194 |
Tags: data structures, expression parsing, implementation
Correct Solution:
```
import sys
import math
import string
import operator
import functools
import fractions
import collections
sys.setrecursionlimit(10**7)
dX= [-1, 1, 0, 0,-1, 1,-1, 1]
dY= [ 0, 0,-1, 1, 1,-1,-1, 1]
RI=lambda: list(map(int,input().split()))
RS=... | output | 1 | 24,097 | 21 | 48,195 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A bracket sequence is a string, containing only characters "(", ")", "[" and "]".
A correct bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the ... | instruction | 0 | 24,098 | 21 | 48,196 |
Tags: data structures, expression parsing, implementation
Correct Solution:
```
string = list(input())
d, p = [], set(range(len(string)))
for j, q in enumerate(string):
if q in '([': d.append((j,q))
elif d:
i, x = d.pop()
if x+q in '(][)': d = []
else: p -= {i, j}
n, s = 0, ''
for i i... | output | 1 | 24,098 | 21 | 48,197 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A bracket sequence is a string, containing only characters "(", ")", "[" and "]".
A correct bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the ... | instruction | 0 | 24,099 | 21 | 48,198 |
Tags: data structures, expression parsing, implementation
Correct Solution:
```
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.m... | output | 1 | 24,099 | 21 | 48,199 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A bracket sequence is a string, containing only characters "(", ")", "[" and "]".
A correct bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the ... | instruction | 0 | 24,100 | 21 | 48,200 |
Tags: data structures, expression parsing, implementation
Correct Solution:
```
t = list(input())
d, p = [], set(range(len(t)))
for j, q in enumerate(t):
if q in '([': d.append((q, j))
elif d:
x, i = d.pop()
if x + q in '(][)': d = []
else: p -= {i, j}
for i in p: t[i] = ' '
n, s = 0, ''... | output | 1 | 24,100 | 21 | 48,201 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A bracket sequence is a string, containing only characters "(", ")", "[" and "]".
A correct bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the ... | instruction | 0 | 24,101 | 21 | 48,202 |
Tags: data structures, expression parsing, implementation
Correct Solution:
```
s, st, v, vi, vj, vc = input(), [], [], 0, 0, 0
for i, ch in enumerate(s):
if ch == "[" or ch == "(":
st.append(i)
else:
if st and s[st[-1]] + ch in ('()', '[]'):
b = (st[-1], i + 1)
if v and ... | output | 1 | 24,101 | 21 | 48,203 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A bracket sequence is a string, containing only characters "(", ")", "[" and "]".
A correct bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the ... | instruction | 0 | 24,102 | 21 | 48,204 |
Tags: data structures, expression parsing, implementation
Correct Solution:
```
s = input()
a = []
for i in range(len(s)):
if len(a) != 0 and ((s[a[-1]] == '(' and s[i] == ')') or (s[a[-1]] == '[' and s[i] == ']')):
a.pop()
else:
a.append(i)
if len(a) == 0:
print(s.count('['))
print(s)
e... | output | 1 | 24,102 | 21 | 48,205 |
Provide tags and a correct Python 3 solution for this coding contest problem.
A bracket sequence is a string, containing only characters "(", ")", "[" and "]".
A correct bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the ... | instruction | 0 | 24,103 | 21 | 48,206 |
Tags: data structures, expression parsing, implementation
Correct Solution:
```
S=input().strip()
subIndex=[]
for i in range(len(S)):
if len(subIndex)!=0 and (((S[subIndex[-1]]=='[' and S[i]==']') or (S[subIndex[-1]]=='(' and S[i]==')'))):
subIndex.pop()
else:
subIndex.append(i)
'tamamı dogru... | output | 1 | 24,103 | 21 | 48,207 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A bracket sequence is a string, containing only characters "(", ")", "[" and "]".
A correct bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression b... | instruction | 0 | 24,104 | 21 | 48,208 |
Yes | output | 1 | 24,104 | 21 | 48,209 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A bracket sequence is a string, containing only characters "(", ")", "[" and "]".
A correct bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression b... | instruction | 0 | 24,105 | 21 | 48,210 |
Yes | output | 1 | 24,105 | 21 | 48,211 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A bracket sequence is a string, containing only characters "(", ")", "[" and "]".
A correct bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression b... | instruction | 0 | 24,106 | 21 | 48,212 |
Yes | output | 1 | 24,106 | 21 | 48,213 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A bracket sequence is a string, containing only characters "(", ")", "[" and "]".
A correct bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression b... | instruction | 0 | 24,107 | 21 | 48,214 |
Yes | output | 1 | 24,107 | 21 | 48,215 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A bracket sequence is a string, containing only characters "(", ")", "[" and "]".
A correct bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression b... | instruction | 0 | 24,108 | 21 | 48,216 |
No | output | 1 | 24,108 | 21 | 48,217 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A bracket sequence is a string, containing only characters "(", ")", "[" and "]".
A correct bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression b... | instruction | 0 | 24,109 | 21 | 48,218 |
No | output | 1 | 24,109 | 21 | 48,219 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A bracket sequence is a string, containing only characters "(", ")", "[" and "]".
A correct bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression b... | instruction | 0 | 24,110 | 21 | 48,220 |
No | output | 1 | 24,110 | 21 | 48,221 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A bracket sequence is a string, containing only characters "(", ")", "[" and "]".
A correct bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression b... | instruction | 0 | 24,111 | 21 | 48,222 |
No | output | 1 | 24,111 | 21 | 48,223 |
Provide a correct Python 3 solution for this coding contest problem.
The Balance of the World
The world should be finely balanced. Positive vs. negative, light vs. shadow, and left vs. right brackets. Your mission is to write a program that judges whether a string is balanced with respect to brackets so that we can o... | instruction | 0 | 24,688 | 21 | 49,376 |
"Correct Solution:
```
def is_balanced(s):
stack = []
for c in s:
if c == '(' or c == '[':
stack.append(c)
elif c == ')':
if not stack:
return "no"
elif stack[-1] == '(':
stack.pop()
else:
return "no"... | output | 1 | 24,688 | 21 | 49,377 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Balance of the World
The world should be finely balanced. Positive vs. negative, light vs. shadow, and left vs. right brackets. Your mission is to write a program that judges whether a stri... | instruction | 0 | 24,689 | 21 | 49,378 |
No | output | 1 | 24,689 | 21 | 49,379 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Balance of the World
The world should be finely balanced. Positive vs. negative, light vs. shadow, and left vs. right brackets. Your mission is to write a program that judges whether a stri... | instruction | 0 | 24,690 | 21 | 49,380 |
No | output | 1 | 24,690 | 21 | 49,381 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Balance of the World
The world should be finely balanced. Positive vs. negative, light vs. shadow, and left vs. right brackets. Your mission is to write a program that judges whether a stri... | instruction | 0 | 24,691 | 21 | 49,382 |
No | output | 1 | 24,691 | 21 | 49,383 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Balance of the World
The world should be finely balanced. Positive vs. negative, light vs. shadow, and left vs. right brackets. Your mission is to write a program that judges whether a stri... | instruction | 0 | 24,692 | 21 | 49,384 |
No | output | 1 | 24,692 | 21 | 49,385 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This is yet another problem on regular bracket sequences.
A bracket sequence is called regular, if by inserting "+" and "1" into it we get a correct mathematical expression. For example, sequences "(())()", "()" and "(()(()))" are regular, ... | instruction | 0 | 25,955 | 21 | 51,910 |
Tags: greedy
Correct Solution:
```
from heapq import *
k = d = 0
s, h = [], []
for i, q in enumerate(input()):
if q == '?':
q = ')'
x, y = map(int, input().split())
d += y
heappush(h, (x - y, i))
s.append(q)
if q == '(': k += 1
elif k: k -= 1
elif h:
k = 1
... | output | 1 | 25,955 | 21 | 51,911 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This is yet another problem on regular bracket sequences.
A bracket sequence is called regular, if by inserting "+" and "1" into it we get a correct mathematical expression. For example, sequences "(())()", "()" and "(()(()))" are regular, ... | instruction | 0 | 25,956 | 21 | 51,912 |
Tags: greedy
Correct Solution:
```
"""
Codeforces
3D - Least Cost Bracket Sequence
http://codeforces.com/problemset/problem/3/D
Héctor González Belver
../07/2018
"""
import sys
import heapq
def main():
cost = []
pattern = sys.stdin.readline().strip()
unknown = pattern.count('?')
cost = [tuple(int(c) for c in ... | output | 1 | 25,956 | 21 | 51,913 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This is yet another problem on regular bracket sequences.
A bracket sequence is called regular, if by inserting "+" and "1" into it we get a correct mathematical expression. For example, sequences "(())()", "()" and "(()(()))" are regular, ... | instruction | 0 | 25,957 | 21 | 51,914 |
Tags: greedy
Correct Solution:
```
import heapq
s = input()
l = len(s)
cnt = 0
for i in range(l):
if s[i] == '?':
cnt += 1
a = []
for i in range(cnt):
a.append(list(map(int, input().split())))
idx = 0
res = 0
left = 0
b = []
p = [0] * len(a)
ans = True
for i in range(l):
if s[i] == '(':
left... | output | 1 | 25,957 | 21 | 51,915 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This is yet another problem on regular bracket sequences.
A bracket sequence is called regular, if by inserting "+" and "1" into it we get a correct mathematical expression. For example, sequences "(())()", "()" and "(()(()))" are regular, ... | instruction | 0 | 25,958 | 21 | 51,916 |
Tags: greedy
Correct Solution:
```
__author__ = 'Darren'
def solve():
import sys
stdin = sys.stdin if True else open('data')
from heapq import heappush, heappop
seq = [c for c in next(stdin).strip()]
n = len(seq)
if n % 2 == 1:
print(-1)
return
min_heap = []
balance, ... | output | 1 | 25,958 | 21 | 51,917 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This is yet another problem on regular bracket sequences.
A bracket sequence is called regular, if by inserting "+" and "1" into it we get a correct mathematical expression. For example, sequences "(())()", "()" and "(()(()))" are regular, ... | instruction | 0 | 25,959 | 21 | 51,918 |
Tags: greedy
Correct Solution:
```
import heapq
s = list(input())
new_s, cost, opens, opens_i = str(), 0, 0, list()
for i in range(len(s)):
opens += int(s[i] == '(') - int(s[i] != '(')
if s[i] == '?':
a, b = [int(i) for i in input().split()]
s[i] = ')'
heapq.heappush(opens_i, [-b + ... | output | 1 | 25,959 | 21 | 51,919 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This is yet another problem on regular bracket sequences.
A bracket sequence is called regular, if by inserting "+" and "1" into it we get a correct mathematical expression. For example, sequences "(())()", "()" and "(()(()))" are regular, ... | instruction | 0 | 25,960 | 21 | 51,920 |
Tags: greedy
Correct Solution:
```
import heapq
s = input()
sl = list(s)
ct = 0
cost = 0
flag = True
h = []
for i,c in enumerate(s):
if c == '(':
ct+=1
elif c == ')':
ct-=1
else:
l,r = map(int,input().split())
sl[i] = ')'
cost += r
ct-=1
heapq.heappus... | output | 1 | 25,960 | 21 | 51,921 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This is yet another problem on regular bracket sequences.
A bracket sequence is called regular, if by inserting "+" and "1" into it we get a correct mathematical expression. For example, sequences "(())()", "()" and "(()(()))" are regular, ... | instruction | 0 | 25,961 | 21 | 51,922 |
Tags: greedy
Correct Solution:
```
from heapq import *
#priority queue
#see healp(heapq)
def CF_3D():
line=input()
n=line.count('?')
sequence=list(line)
bracket=[]
for i in range(n):
bracket.append(list(map(int,input().split())))
index=0
cost=0
balance=0
heap=[]
f... | output | 1 | 25,961 | 21 | 51,923 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This is yet another problem on regular bracket sequences.
A bracket sequence is called regular, if by inserting "+" and "1" into it we get a correct mathematical expression. For example, sequences "(())()", "()" and "(()(()))" are regular, ... | instruction | 0 | 25,962 | 21 | 51,924 |
Tags: greedy
Correct Solution:
```
from heapq import heappush, heappop
ans=b=0
d=[]
s=list(input())
for i in range(len(s)):
if s[i]=='(':
b+=1
elif s[i]==')':
b-=1
else:
c=list(map(int,input().split()))
s[i]=')'
b-=1
heappush(d,(c[0]-c[1],i))
ans+=c[... | output | 1 | 25,962 | 21 | 51,925 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is yet another problem on regular bracket sequences.
A bracket sequence is called regular, if by inserting "+" and "1" into it we get a correct mathematical expression. For example, sequen... | instruction | 0 | 25,963 | 21 | 51,926 |
Yes | output | 1 | 25,963 | 21 | 51,927 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is yet another problem on regular bracket sequences.
A bracket sequence is called regular, if by inserting "+" and "1" into it we get a correct mathematical expression. For example, sequen... | instruction | 0 | 25,964 | 21 | 51,928 |
Yes | output | 1 | 25,964 | 21 | 51,929 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is yet another problem on regular bracket sequences.
A bracket sequence is called regular, if by inserting "+" and "1" into it we get a correct mathematical expression. For example, sequen... | instruction | 0 | 25,965 | 21 | 51,930 |
Yes | output | 1 | 25,965 | 21 | 51,931 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is yet another problem on regular bracket sequences.
A bracket sequence is called regular, if by inserting "+" and "1" into it we get a correct mathematical expression. For example, sequen... | instruction | 0 | 25,966 | 21 | 51,932 |
Yes | output | 1 | 25,966 | 21 | 51,933 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is yet another problem on regular bracket sequences.
A bracket sequence is called regular, if by inserting "+" and "1" into it we get a correct mathematical expression. For example, sequen... | instruction | 0 | 25,967 | 21 | 51,934 |
No | output | 1 | 25,967 | 21 | 51,935 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is yet another problem on regular bracket sequences.
A bracket sequence is called regular, if by inserting "+" and "1" into it we get a correct mathematical expression. For example, sequen... | instruction | 0 | 25,968 | 21 | 51,936 |
No | output | 1 | 25,968 | 21 | 51,937 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is yet another problem on regular bracket sequences.
A bracket sequence is called regular, if by inserting "+" and "1" into it we get a correct mathematical expression. For example, sequen... | instruction | 0 | 25,969 | 21 | 51,938 |
No | output | 1 | 25,969 | 21 | 51,939 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is yet another problem on regular bracket sequences.
A bracket sequence is called regular, if by inserting "+" and "1" into it we get a correct mathematical expression. For example, sequen... | instruction | 0 | 25,970 | 21 | 51,940 |
No | output | 1 | 25,970 | 21 | 51,941 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya's friends made him a birthday present — a bracket sequence. Petya was quite disappointed with his gift, because he dreamed of correct bracket sequence, yet he told his friends nothing about his dreams and decided to fix present himself... | instruction | 0 | 30,145 | 21 | 60,290 |
Tags: data structures, greedy
Correct Solution:
```
def read():
n = int(input())
s = input()
return n, s
def solve(n, s):
st = [s[0]]
for i in range(1, n):
if s[i] == "(":
st.append(s[i])
else:
if len(st) == 0:
st.append(s[i])
eli... | output | 1 | 30,145 | 21 | 60,291 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya's friends made him a birthday present — a bracket sequence. Petya was quite disappointed with his gift, because he dreamed of correct bracket sequence, yet he told his friends nothing about his dreams and decided to fix present himself... | instruction | 0 | 30,146 | 21 | 60,292 |
Tags: data structures, greedy
Correct Solution:
```
import sys
import collections
import functools
n = int(input().strip())
s = input().strip()
stack, s2 = [], []
for i in s:
if i == "(":
stack.append(i)
elif i == ")" and stack and stack[-1] == "(":
stack.pop()
else:
s2.append(i)
... | output | 1 | 30,146 | 21 | 60,293 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya's friends made him a birthday present — a bracket sequence. Petya was quite disappointed with his gift, because he dreamed of correct bracket sequence, yet he told his friends nothing about his dreams and decided to fix present himself... | instruction | 0 | 30,147 | 21 | 60,294 |
Tags: data structures, greedy
Correct Solution:
```
from collections import Counter
n = int(input())
bra = input()
d=Counter(bra)
ans=0
if d['(']==d[')']:
c=0
for i in bra:
if i=='(':
c+=1
else:
if c==0:
ans+=1
else:
c-=1
... | output | 1 | 30,147 | 21 | 60,295 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya's friends made him a birthday present — a bracket sequence. Petya was quite disappointed with his gift, because he dreamed of correct bracket sequence, yet he told his friends nothing about his dreams and decided to fix present himself... | instruction | 0 | 30,148 | 21 | 60,296 |
Tags: data structures, greedy
Correct Solution:
```
def countbrackets(string):
if string.replace("(", "").replace(")", ""): return None
string = [x == '(' for x in string]
bopen, extraclose = 0, 0
for x in string:
if x: bopen += 1
else:
if bopen == 0: extraclose += 1
... | output | 1 | 30,148 | 21 | 60,297 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Petya's friends made him a birthday present — a bracket sequence. Petya was quite disappointed with his gift, because he dreamed of correct bracket sequence, yet he told his friends nothing about his dreams and decided to fix present himself... | instruction | 0 | 30,149 | 21 | 60,298 |
Tags: data structures, greedy
Correct Solution:
```
def solution():
from sys import stdout, stdin
_input, _print = stdin.readline, stdout.write
_int, _range, _min, _max = int, range, min, max
n = int(input())
arr = [1 if i == '(' else -1 for i in input()]
if sum(arr) != 0:
print("No")
... | output | 1 | 30,149 | 21 | 60,299 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.