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
Provide tags and a correct Python 3 solution for this coding contest problem. One day, Yuhao came across a problem about checking if some bracket sequences are correct bracket sequences. A bracket sequence is any non-empty sequence of opening and closing parentheses. A bracket sequence is called a correct bracket seq...
instruction
0
82,612
21
165,224
Tags: greedy, implementation Correct Solution: ``` n = int(input()) lparen = [] rparen = [] bparen = 0 for i in range(n): p = input() right = 0; left = 0; for j in range(len(p)): if p[j] == '(': right+=1 else: if right == 0: left+=1 ...
output
1
82,612
21
165,225
Provide tags and a correct Python 3 solution for this coding contest problem. One day, Yuhao came across a problem about checking if some bracket sequences are correct bracket sequences. A bracket sequence is any non-empty sequence of opening and closing parentheses. A bracket sequence is called a correct bracket seq...
instruction
0
82,613
21
165,226
Tags: greedy, implementation Correct Solution: ``` def check(s): a = 0 b = 0 for c in s: if c == "(": a += 1 else: a -= 1 if a < 0: b += 1 a = 0 return a, b n = int(input()) d = {} for i in range(0, n): s = input() a, b ...
output
1
82,613
21
165,227
Provide tags and a correct Python 3 solution for this coding contest problem. One day, Yuhao came across a problem about checking if some bracket sequences are correct bracket sequences. A bracket sequence is any non-empty sequence of opening and closing parentheses. A bracket sequence is called a correct bracket seq...
instruction
0
82,614
21
165,228
Tags: greedy, implementation Correct Solution: ``` '''input 4 ( (( ((( (()) ''' from sys import stdin def calculate_score(bracket): score = dict() for element in bracket: count = 0 for c in element: if c == '(': count += 1 else: count -= 1 score[element] = count return score def is_positive(s...
output
1
82,614
21
165,229
Provide tags and a correct Python 3 solution for this coding contest problem. One day, Yuhao came across a problem about checking if some bracket sequences are correct bracket sequences. A bracket sequence is any non-empty sequence of opening and closing parentheses. A bracket sequence is called a correct bracket seq...
instruction
0
82,615
21
165,230
Tags: greedy, implementation Correct Solution: ``` d={0:[0,0]} for _ in[0]*int(input()): m=c=0 for x in input():c+=2*(x<')')-1;m=min(m,c) d.setdefault(abs(c),[0,0])[m<0]+=m in(0,c) print(sum(map(min,d.values()))+d[0][0]//2) ```
output
1
82,615
21
165,231
Provide tags and a correct Python 3 solution for this coding contest problem. One day, Yuhao came across a problem about checking if some bracket sequences are correct bracket sequences. A bracket sequence is any non-empty sequence of opening and closing parentheses. A bracket sequence is called a correct bracket seq...
instruction
0
82,616
21
165,232
Tags: greedy, implementation Correct Solution: ``` n = int(input()) a = [] for i in range(n): a.append([(1 if x == '(' else -1) for x in input().strip()]) lsms = [] for p in a: cs = 0 ms = 0 for e in p: cs += e ms = min(ms, cs) lsms.append([cs, ms]) lsms.sort(key=lambda sms: sms[1], ...
output
1
82,616
21
165,233
Provide tags and a correct Python 3 solution for this coding contest problem. One day, Yuhao came across a problem about checking if some bracket sequences are correct bracket sequences. A bracket sequence is any non-empty sequence of opening and closing parentheses. A bracket sequence is called a correct bracket seq...
instruction
0
82,617
21
165,234
Tags: greedy, implementation Correct Solution: ``` n = int(input()) a = [input() for i in range(n)] kk = {} for i in a: if i[0] == ')' and i[-1] == '(': continue cnt = 0 flag1 = False flag2 = False isFirst = False for j in i: if j == '(': cnt += 1 else: ...
output
1
82,617
21
165,235
Provide tags and a correct Python 3 solution for this coding contest problem. One day, Yuhao came across a problem about checking if some bracket sequences are correct bracket sequences. A bracket sequence is any non-empty sequence of opening and closing parentheses. A bracket sequence is called a correct bracket seq...
instruction
0
82,618
21
165,236
Tags: greedy, implementation Correct Solution: ``` def mi(): return map(int, input().split()) ''' def gcd (a,b): if b==0: return a return gcd(b,a%b) 7 )()) ) (( (( ( ) ) ''' l = [0]*((10**5)*5+5) r = [0]*((10**5)*5+5) try: n = int(input()) for _ in range(n): a = input() la = len(a) ...
output
1
82,618
21
165,237
Provide tags and a correct Python 3 solution for this coding contest problem. One day, Yuhao came across a problem about checking if some bracket sequences are correct bracket sequences. A bracket sequence is any non-empty sequence of opening and closing parentheses. A bracket sequence is called a correct bracket seq...
instruction
0
82,619
21
165,238
Tags: greedy, implementation Correct Solution: ``` d={} r=0 for _ in[0]*int(input()): m=c=0 for x in input():c+=2*(x<')')-1;m=min(m,c) if c==m==0:r+=1 elif m in(0,c):i=m<0;d.setdefault((c,-m)[i],[0,0])[i]+=1 print(sum(map(min,d.values()))+r//2) ```
output
1
82,619
21
165,239
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day, Yuhao came across a problem about checking if some bracket sequences are correct bracket sequences. A bracket sequence is any non-empty sequence of opening and closing parentheses. A b...
instruction
0
82,620
21
165,240
Yes
output
1
82,620
21
165,241
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day, Yuhao came across a problem about checking if some bracket sequences are correct bracket sequences. A bracket sequence is any non-empty sequence of opening and closing parentheses. A b...
instruction
0
82,621
21
165,242
Yes
output
1
82,621
21
165,243
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day, Yuhao came across a problem about checking if some bracket sequences are correct bracket sequences. A bracket sequence is any non-empty sequence of opening and closing parentheses. A b...
instruction
0
82,622
21
165,244
Yes
output
1
82,622
21
165,245
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day, Yuhao came across a problem about checking if some bracket sequences are correct bracket sequences. A bracket sequence is any non-empty sequence of opening and closing parentheses. A b...
instruction
0
82,623
21
165,246
Yes
output
1
82,623
21
165,247
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day, Yuhao came across a problem about checking if some bracket sequences are correct bracket sequences. A bracket sequence is any non-empty sequence of opening and closing parentheses. A b...
instruction
0
82,624
21
165,248
No
output
1
82,624
21
165,249
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day, Yuhao came across a problem about checking if some bracket sequences are correct bracket sequences. A bracket sequence is any non-empty sequence of opening and closing parentheses. A b...
instruction
0
82,625
21
165,250
No
output
1
82,625
21
165,251
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day, Yuhao came across a problem about checking if some bracket sequences are correct bracket sequences. A bracket sequence is any non-empty sequence of opening and closing parentheses. A b...
instruction
0
82,626
21
165,252
No
output
1
82,626
21
165,253
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. One day, Yuhao came across a problem about checking if some bracket sequences are correct bracket sequences. A bracket sequence is any non-empty sequence of opening and closing parentheses. A b...
instruction
0
82,627
21
165,254
No
output
1
82,627
21
165,255
Provide tags and a correct Python 3 solution for this coding contest problem. Recently Polycarp started to develop a text editor that works only with correct bracket sequences (abbreviated as CBS). Note that a bracket sequence is correct if it is possible to get a correct mathematical expression by adding "+"-s and ...
instruction
0
84,646
21
169,292
Tags: data structures, dsu, strings Correct Solution: ``` import sys sys.stderr = sys.stdout from collections import deque def brackets(n, m, p, B, S): P = [i-1 for i in range(n+2)] P[0] = None Q = [i+1 for i in range(n+2)] Q[n+1] = None J = [None] * (n + 2) D = deque() for i, b in enume...
output
1
84,646
21
169,293
Provide tags and a correct Python 3 solution for this coding contest problem. Recently Polycarp started to develop a text editor that works only with correct bracket sequences (abbreviated as CBS). Note that a bracket sequence is correct if it is possible to get a correct mathematical expression by adding "+"-s and ...
instruction
0
84,647
21
169,294
Tags: data structures, dsu, strings Correct Solution: ``` def preproc(str, leng): li = [] res = [-1]*leng for i in range(leng): if str[i] == '(': li.append(i) else: start, end = li.pop(), i res[start] = end res[end] = start return res def delete(flags, cursor, pairs): pos = pairs[cursor] directi...
output
1
84,647
21
169,295
Provide tags and a correct Python 3 solution for this coding contest problem. Recently Polycarp started to develop a text editor that works only with correct bracket sequences (abbreviated as CBS). Note that a bracket sequence is correct if it is possible to get a correct mathematical expression by adding "+"-s and ...
instruction
0
84,648
21
169,296
Tags: data structures, dsu, strings Correct Solution: ``` class Node: def __init__(self, index): self.left = index - 1 self.right = index + 1 self.pair = -1 if __name__ == "__main__": n, m, p = map(int, input().split()) brackets = input() operations = input() nodes = [Node(...
output
1
84,648
21
169,297
Provide tags and a correct Python 3 solution for this coding contest problem. Recently Polycarp started to develop a text editor that works only with correct bracket sequences (abbreviated as CBS). Note that a bracket sequence is correct if it is possible to get a correct mathematical expression by adding "+"-s and ...
instruction
0
84,649
21
169,298
Tags: data structures, dsu, strings Correct Solution: ``` n, m, p = [int(x) for x in input().split()] A = input().rstrip() B = input().rstrip() pair = [0] * n stack = [] for (i, c) in enumerate(A): if c == '(': stack.append(i) else: j = stack.pop() pair[i] = j pair[j] = i start...
output
1
84,649
21
169,299
Provide tags and a correct Python 3 solution for this coding contest problem. Recently Polycarp started to develop a text editor that works only with correct bracket sequences (abbreviated as CBS). Note that a bracket sequence is correct if it is possible to get a correct mathematical expression by adding "+"-s and ...
instruction
0
84,650
21
169,300
Tags: data structures, dsu, strings Correct Solution: ``` def main(): n, m, p = map(int, input().split()) xlat, l, s, ll, lr = [0] * n, [], input(), list(range(-1, n)), list(range(1, n + 2)) p -= 1 for i, c in enumerate(s): if c == '(': l.append(i) else: j = l.pop...
output
1
84,650
21
169,301
Provide tags and a correct Python 3 solution for this coding contest problem. Recently Polycarp started to develop a text editor that works only with correct bracket sequences (abbreviated as CBS). Note that a bracket sequence is correct if it is possible to get a correct mathematical expression by adding "+"-s and ...
instruction
0
84,651
21
169,302
Tags: data structures, dsu, strings Correct Solution: ``` class Node: def __init__(self, index): self.left = index - 1 self.right = index + 1 self.pair = -1 if __name__ == "__main__": n, m, p = map(int, input().split()) brackets = input() operations = input() nodes = [Node(...
output
1
84,651
21
169,303
Provide tags and a correct Python 3 solution for this coding contest problem. Recently Polycarp started to develop a text editor that works only with correct bracket sequences (abbreviated as CBS). Note that a bracket sequence is correct if it is possible to get a correct mathematical expression by adding "+"-s and ...
instruction
0
84,652
21
169,304
Tags: data structures, dsu, strings Correct Solution: ``` jump_r = {} jump_l = {} def bracket_to_value(bracket): if bracket == '(': return 1 if bracket == ')': return -1 def move_r(c): if c+1 in jump_r: return jump_r[c+1]+1 else: return c+1 def move_l(c): if c-...
output
1
84,652
21
169,305
Provide tags and a correct Python 3 solution for this coding contest problem. Recently Polycarp started to develop a text editor that works only with correct bracket sequences (abbreviated as CBS). Note that a bracket sequence is correct if it is possible to get a correct mathematical expression by adding "+"-s and ...
instruction
0
84,653
21
169,306
Tags: data structures, dsu, strings Correct Solution: ``` n, m, p = map(int, input().split()); x, v, s, l, r = [0]*n, [], input(), list(range(-1, n)), list(range(1, n+2)) p -= 1 for i, c in enumerate(s): if c == '(': v.append(i) else: j = v.pop() x[i] = j ...
output
1
84,653
21
169,307
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Recently Polycarp started to develop a text editor that works only with correct bracket sequences (abbreviated as CBS). Note that a bracket sequence is correct if it is possible to get a corre...
instruction
0
84,654
21
169,308
No
output
1
84,654
21
169,309
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Recently Polycarp started to develop a text editor that works only with correct bracket sequences (abbreviated as CBS). Note that a bracket sequence is correct if it is possible to get a corre...
instruction
0
84,655
21
169,310
No
output
1
84,655
21
169,311
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Recently Polycarp started to develop a text editor that works only with correct bracket sequences (abbreviated as CBS). Note that a bracket sequence is correct if it is possible to get a corre...
instruction
0
84,656
21
169,312
No
output
1
84,656
21
169,313
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Recently Polycarp started to develop a text editor that works only with correct bracket sequences (abbreviated as CBS). Note that a bracket sequence is correct if it is possible to get a corre...
instruction
0
84,657
21
169,314
No
output
1
84,657
21
169,315
Provide tags and a correct Python 3 solution for this coding contest problem. This is a harder version of the problem. In this version, n ≀ 300 000. Vasya is an experienced developer of programming competitions' problems. As all great minds at some time, Vasya faced a creative crisis. To improve the situation, Petya ...
instruction
0
86,704
21
173,408
Tags: implementation Correct Solution: ``` n = int(input()) seq = list(input()) def get_comps(seq): depth = 0 components = 0 lookingfor = 0 for i in range(n): if seq[i] == "(": depth += 1 else: depth -= 1 if depth < lookingfor: looking...
output
1
86,704
21
173,409
Provide tags and a correct Python 3 solution for this coding contest problem. This is a harder version of the problem. In this version, n ≀ 300 000. Vasya is an experienced developer of programming competitions' problems. As all great minds at some time, Vasya faced a creative crisis. To improve the situation, Petya ...
instruction
0
86,705
21
173,410
Tags: implementation Correct Solution: ``` n = int(input()) S = list(input()) def count_all(s): cnt=0 l_cnt=1 for c in s[1:]: if c==')': l_cnt-=1 else: l_cnt+=1 if l_cnt==0: cnt+=1 return cnt if S==list('()'*(n//2)) or S==list(')'+'()'*(n//2-1)...
output
1
86,705
21
173,411
Provide tags and a correct Python 3 solution for this coding contest problem. This is a harder version of the problem. In this version, n ≀ 300 000. Vasya is an experienced developer of programming competitions' problems. As all great minds at some time, Vasya faced a creative crisis. To improve the situation, Petya ...
instruction
0
86,706
21
173,412
Tags: implementation Correct Solution: ``` n = int(input()) s = [1 if c == '(' else -1 for c in input()] if s.count(1) != s.count(-1): print(0) print(1, 1) exit() ans = 0 pair = 1, 1 for i in range(n-1): for j in range(i, n): s[i], s[j] = s[j], s[i] min_p, cnt = 10**9, 0 nest = ...
output
1
86,706
21
173,413
Provide tags and a correct Python 3 solution for this coding contest problem. This is a harder version of the problem. In this version, n ≀ 300 000. Vasya is an experienced developer of programming competitions' problems. As all great minds at some time, Vasya faced a creative crisis. To improve the situation, Petya ...
instruction
0
86,707
21
173,414
Tags: implementation Correct Solution: ``` n = int(input()) s = list(input()) best = 0 L = 1 R = 1 def check(): calc = 0 min = 0 cntmin = 0 for ch in s: if ch == '(': calc += 1 else: calc -= 1 if min > calc: min = calc cntmin = 1 elif min == calc: cntmin += 1 return cntmin if calc == 0 els...
output
1
86,707
21
173,415
Provide tags and a correct Python 3 solution for this coding contest problem. This is a harder version of the problem. In this version, n ≀ 300 000. Vasya is an experienced developer of programming competitions' problems. As all great minds at some time, Vasya faced a creative crisis. To improve the situation, Petya ...
instruction
0
86,708
21
173,416
Tags: implementation Correct Solution: ``` n = int(input()) ddd = input() d = [0] for dd in ddd: if dd == '(': d.append(d[-1] + 1) else: d.append(d[-1] - 1) if d[-1] != 0: print("0\n1 1") exit(0) d.pop() mn = min(d) ind = d.index(mn) d = d[ind:] + d[:ind] d = [i - mn for i in d] fi = ...
output
1
86,708
21
173,417
Provide tags and a correct Python 3 solution for this coding contest problem. This is a harder version of the problem. In this version, n ≀ 300 000. Vasya is an experienced developer of programming competitions' problems. As all great minds at some time, Vasya faced a creative crisis. To improve the situation, Petya ...
instruction
0
86,709
21
173,418
Tags: implementation Correct Solution: ``` n = int(input().strip()) s= input().strip() ss= 0 mina = 0 ti = 0 for k in range(len(s)): if(s[k] == "("): ss+=1 else: ss-=1 if(ss<0): ti = k+1 ss = 0 s=s[ti:]+s[:ti] #print(s) ss= 0 for k in range(len(s)): if(s[k] == "("): ...
output
1
86,709
21
173,419
Provide tags and a correct Python 3 solution for this coding contest problem. This is a harder version of the problem. In this version, n ≀ 300 000. Vasya is an experienced developer of programming competitions' problems. As all great minds at some time, Vasya faced a creative crisis. To improve the situation, Petya ...
instruction
0
86,710
21
173,420
Tags: implementation Correct Solution: ``` #Code by Sounak, IIESTS #------------------------------warmup---------------------------- import os import sys import math from io import BytesIO, IOBase from fractions import Fraction import collections from itertools import permutations from collections import defaultdict f...
output
1
86,710
21
173,421
Provide tags and a correct Python 3 solution for this coding contest problem. This is a harder version of the problem. In this version, n ≀ 300 000. Vasya is an experienced developer of programming competitions' problems. As all great minds at some time, Vasya faced a creative crisis. To improve the situation, Petya ...
instruction
0
86,711
21
173,422
Tags: implementation Correct Solution: ``` # import cProfile def prefix(s): count = 0 cur = 0 m = 0 for c in s: if c == '(': cur += 1 else: cur -= 1 if cur < m: m = cur count = 0 if cur == m: count += 1 retur...
output
1
86,711
21
173,423
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is a harder version of the problem. In this version, n ≀ 300 000. Vasya is an experienced developer of programming competitions' problems. As all great minds at some time, Vasya faced a cr...
instruction
0
86,712
21
173,424
Yes
output
1
86,712
21
173,425
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is a harder version of the problem. In this version, n ≀ 300 000. Vasya is an experienced developer of programming competitions' problems. As all great minds at some time, Vasya faced a cr...
instruction
0
86,713
21
173,426
Yes
output
1
86,713
21
173,427
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is a harder version of the problem. In this version, n ≀ 300 000. Vasya is an experienced developer of programming competitions' problems. As all great minds at some time, Vasya faced a cr...
instruction
0
86,714
21
173,428
Yes
output
1
86,714
21
173,429
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is a harder version of the problem. In this version, n ≀ 300 000. Vasya is an experienced developer of programming competitions' problems. As all great minds at some time, Vasya faced a cr...
instruction
0
86,715
21
173,430
Yes
output
1
86,715
21
173,431
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is a harder version of the problem. In this version, n ≀ 300 000. Vasya is an experienced developer of programming competitions' problems. As all great minds at some time, Vasya faced a cr...
instruction
0
86,716
21
173,432
No
output
1
86,716
21
173,433
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is a harder version of the problem. In this version, n ≀ 300 000. Vasya is an experienced developer of programming competitions' problems. As all great minds at some time, Vasya faced a cr...
instruction
0
86,717
21
173,434
No
output
1
86,717
21
173,435
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is a harder version of the problem. In this version, n ≀ 300 000. Vasya is an experienced developer of programming competitions' problems. As all great minds at some time, Vasya faced a cr...
instruction
0
86,718
21
173,436
No
output
1
86,718
21
173,437
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. This is a harder version of the problem. In this version, n ≀ 300 000. Vasya is an experienced developer of programming competitions' problems. As all great minds at some time, Vasya faced a cr...
instruction
0
86,719
21
173,438
No
output
1
86,719
21
173,439
Provide tags and a correct Python 3 solution for this coding contest problem. As you probably know, Anton goes to school. One of the school subjects that Anton studies is Bracketology. On the Bracketology lessons students usually learn different sequences that consist of round brackets (characters "(" and ")" (without...
instruction
0
90,596
21
181,192
Tags: combinatorics, dp, math, number theory Correct Solution: ``` t = input() n, m = len(t) + 1, 1000000007 a, b = 0, t.count(')') - 1 f = [1] * n for i in range(2, n): f[i] = i * f[i - 1] % m g = [pow(q, m - 2, m) for q in f] s = 0 for q in t: if b < 0: break if q == '(': a += 1 s += f[a + b] ...
output
1
90,596
21
181,193
Provide tags and a correct Python 3 solution for this coding contest problem. As you probably know, Anton goes to school. One of the school subjects that Anton studies is Bracketology. On the Bracketology lessons students usually learn different sequences that consist of round brackets (characters "(" and ")" (without...
instruction
0
90,597
21
181,194
Tags: combinatorics, dp, math, number theory Correct Solution: ``` mod = 10 ** 9 + 7 s = input() n = len(s) f = [1] * (n + 1) for i in range(1, n + 1): f[i] = i * f[i - 1] % mod finv = [pow(x, mod - 2, mod) for x in f] op = 0 cl = s.count(')') ans = 0 if cl > 0: for c in s: if c == '(': op += 1 ans...
output
1
90,597
21
181,195
Provide tags and a correct Python 3 solution for this coding contest problem. As you probably know, Anton goes to school. One of the school subjects that Anton studies is Bracketology. On the Bracketology lessons students usually learn different sequences that consist of round brackets (characters "(" and ")" (without...
instruction
0
90,598
21
181,196
Tags: combinatorics, dp, math, number theory Correct Solution: ``` mod = 10 ** 9 + 7 fact, inv, invfact = [1, 1], [0, 1], [1, 1] for i in range(2, 200200): fact.append(fact[-1] * i % mod) inv.append(inv[mod % i] * (mod - mod // i) % mod) invfact.append(invfact[-1] * inv[-1] % mod) def C(n, k): if k < ...
output
1
90,598
21
181,197
Provide tags and a correct Python 3 solution for this coding contest problem. As you probably know, Anton goes to school. One of the school subjects that Anton studies is Bracketology. On the Bracketology lessons students usually learn different sequences that consist of round brackets (characters "(" and ")" (without...
instruction
0
90,599
21
181,198
Tags: combinatorics, dp, math, number theory Correct Solution: ``` #!/usr/bin/env python3 def ri(): return map(int, input().split()) m = 10**9+7 s = input() n = len(s) o = [0 for i in range(len(s))] c = [0 for i in range(len(s))] fac = [0 for i in range(n)] fac[0] = 1 for i in range(1,n): fac[i] = fac[i-1]*i...
output
1
90,599
21
181,199
Provide tags and a correct Python 3 solution for this coding contest problem. As you probably know, Anton goes to school. One of the school subjects that Anton studies is Bracketology. On the Bracketology lessons students usually learn different sequences that consist of round brackets (characters "(" and ")" (without...
instruction
0
90,600
21
181,200
Tags: combinatorics, dp, math, number theory Correct Solution: ``` mod = 10 ** 9 + 7 s = input() n = len(s) f = [1] * (n + 1) for i in range(1, n + 1): f[i] = i * f[i - 1] % mod finv = [pow(x, mod - 2, mod) for x in f] op = 0 cl = s.count(')') ans = 0 if cl > 0: for c in s: if c == '(': op += 1 ans...
output
1
90,600
21
181,201
Provide tags and a correct Python 3 solution for this coding contest problem. As you probably know, Anton goes to school. One of the school subjects that Anton studies is Bracketology. On the Bracketology lessons students usually learn different sequences that consist of round brackets (characters "(" and ")" (without...
instruction
0
90,601
21
181,202
Tags: combinatorics, dp, math, number theory Correct Solution: ``` p = 10**9+7 def power(x, y, p): b = bin(y)[2:] answer = 1 start = x % p for i in range(len(b)): if b[len(b)-1-i]=='1': answer = (answer*start) % p start = (start*start) % p return answer def process(S): ...
output
1
90,601
21
181,203