message
stringlengths
2
23.8k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
97
109k
cluster
float64
0
0
__index_level_0__
int64
194
217k
Provide tags and a correct Python 3 solution for this coding contest problem. Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gemstones, the i-th of which has color ci. The goal of the game is to destroy all the gemstones in the line as quickly as possible. In one second, Genos i...
instruction
0
70,259
0
140,518
Tags: dp Correct Solution: ``` from sys import stdin,stdout for _ in range(1):#(stdin.readline())): n=int(stdin.readline()) # n,m=list(map(int,stdin.readline().split())) a=list(map(int,stdin.readline().split())) dp=[[0 for _ in range(n)] for _ in range(n)] for sz in range(n): for i in range(...
output
1
70,259
0
140,519
Provide tags and a correct Python 3 solution for this coding contest problem. Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gemstones, the i-th of which has color ci. The goal of the game is to destroy all the gemstones in the line as quickly as possible. In one second, Genos i...
instruction
0
70,265
0
140,530
Tags: dp Correct Solution: ``` # by the authority of GOD author: manhar singh sachdev # import os,sys from io import BytesIO,IOBase from array import array def main(): n = int(input()) c = array('i',map(int,input().split())) dp = [array('i',[0]*n) for _ in range(n)] for i in range(n): dp[i][...
output
1
70,265
0
140,531
Provide tags and a correct Python 3 solution for this coding contest problem. Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gemstones, the i-th of which has color ci. The goal of the game is to destroy all the gemstones in the line as quickly as possible. In one second, Genos i...
instruction
0
70,266
0
140,532
Tags: dp Correct Solution: ``` from math import inf n=int(input()) s=[int(X) for X in input().split()] dp=[[inf for i in range(n)] for j in range(n)] isdp=[[0 for i in range(n)] for j in range(n)] for i in range(n): isdp[i][i]=1 for i in range(1,n): for j in range(n): if i+j>=n: break ...
output
1
70,266
0
140,533
Provide tags and a correct Python 2 solution for this coding contest problem. Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gemstones, the i-th of which has color ci. The goal of the game is to destroy all the gemstones in the line as quickly as possible. In one second, Genos i...
instruction
0
70,267
0
140,534
Tags: dp Correct Solution: ``` from sys import stdin, stdout from collections import Counter, defaultdict from itertools import permutations, combinations raw_input = stdin.readline pr = stdout.write def in_num(): return int(raw_input()) def in_arr(): return map(int,raw_input().split()) def pr_num(n): ...
output
1
70,267
0
140,535
Provide a correct Python 3 solution for this coding contest problem. Given is a string S. Each character in S is either a digit (`0`, ..., `9`) or `?`. Among the integers obtained by replacing each occurrence of `?` with a digit, how many have a remainder of 5 when divided by 13? An integer may begin with 0. Since t...
instruction
0
70,546
0
141,092
"Correct Solution: ``` s = input() mod = 10**9 + 7 n = len(s) dp = [[0] * 13 for i in range(n+1)] dp[0][0] = 1 for i in range(n): ss = s[i] for j in range(13): if ss == '?': for k in range(10): dp[i+1][(j*10+k)%13] += dp[i][j] else: dp[i+1][(j*10+int(ss))%...
output
1
70,546
0
141,093
Provide a correct Python 3 solution for this coding contest problem. Welcome to CODE FESTIVAL 2016! In order to celebrate this contest, find a string s that satisfies the following conditions: * The length of s is between 1 and 5000, inclusive. * s consists of uppercase letters. * s contains exactly K occurrences of ...
instruction
0
70,635
0
141,270
"Correct Solution: ``` import math import sys input = sys.stdin.readline k = int(input()) n = 512 pattern = 0 a = [] for i in range(n): val = math.factorial(7 + i) // math.factorial(i) // math.factorial(7) a.append(val) a.reverse() cnt = 600 * 7 ans = ["FESTIVA" for _ in range(n)] for i, item in enumerate(a...
output
1
70,635
0
141,271
Provide a correct Python 3 solution for this coding contest problem. Consider a string with rings on both ends. Rings have positive integers to distinguish them. Rings on both ends of the string have different numbers a and b. Describe this as [a, b]. If there are multiple strings and the number attached to the ring o...
instruction
0
70,672
0
141,344
"Correct Solution: ``` def solve(): def dfs(ring, chain_len=1): unchecked[ring] = False unvisited[ring] = False len_rec[ring] = max(len_rec[ring], chain_len) for r in adj_list[ring]: if unvisited[r]: dfs(r, chain_len + 1) unvisited[ring] = True ...
output
1
70,672
0
141,345
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Consider a string with rings on both ends. Rings have positive integers to distinguish them. Rings on both ends of the string have different numbers a and b. Describe this as [a, b]. If there ar...
instruction
0
70,673
0
141,346
No
output
1
70,673
0
141,347
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Consider a string with rings on both ends. Rings have positive integers to distinguish them. Rings on both ends of the string have different numbers a and b. Describe this as [a, b]. If there ar...
instruction
0
70,674
0
141,348
No
output
1
70,674
0
141,349
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Consider a string with rings on both ends. Rings have positive integers to distinguish them. Rings on both ends of the string have different numbers a and b. Describe this as [a, b]. If there ar...
instruction
0
70,675
0
141,350
No
output
1
70,675
0
141,351
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Consider a string with rings on both ends. Rings have positive integers to distinguish them. Rings on both ends of the string have different numbers a and b. Describe this as [a, b]. If there ar...
instruction
0
70,676
0
141,352
No
output
1
70,676
0
141,353
Provide tags and a correct Python 3 solution for this coding contest problem. You've got string s, consisting of only lowercase English letters. Find its lexicographically maximum subsequence. We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk(1 ≤ p1 < p2 < ... < pk ≤ |s|) a subsequence of string s = s1s2......
instruction
0
71,009
0
142,018
Tags: greedy, strings Correct Solution: ``` si = input() ans = "" while 1: co = si.count(max(si)) ans = ans + max(si)*co #print("ans " ,ans) new = (si[::-1].index(max(si))) #print("new ",new) si = si[len(si)-new:] #print(si) if len(si)==0: #print("lets break") break print...
output
1
71,009
0
142,019
Provide tags and a correct Python 3 solution for this coding contest problem. You've got string s, consisting of only lowercase English letters. Find its lexicographically maximum subsequence. We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk(1 ≤ p1 < p2 < ... < pk ≤ |s|) a subsequence of string s = s1s2......
instruction
0
71,010
0
142,020
Tags: greedy, strings Correct Solution: ``` s = input() n=len(s) ans = s[-1] for i in range(n - 2, -1, -1): if s[i] >= ans[-1]: ans += s[i] print(ans[::-1]) ```
output
1
71,010
0
142,021
Provide tags and a correct Python 3 solution for this coding contest problem. You've got string s, consisting of only lowercase English letters. Find its lexicographically maximum subsequence. We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk(1 ≤ p1 < p2 < ... < pk ≤ |s|) a subsequence of string s = s1s2......
instruction
0
71,011
0
142,022
Tags: greedy, strings Correct Solution: ``` s,l=input(),[''] for i in reversed(s): if l[-1]<=i: l.append(i) print(*reversed(l),sep='') ```
output
1
71,011
0
142,023
Provide tags and a correct Python 3 solution for this coding contest problem. You've got string s, consisting of only lowercase English letters. Find its lexicographically maximum subsequence. We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk(1 ≤ p1 < p2 < ... < pk ≤ |s|) a subsequence of string s = s1s2......
instruction
0
71,012
0
142,024
Tags: greedy, strings Correct Solution: ``` s=list(input()) a=sorted(set(s))[::-1] print(a[0]*(s.count(a[0])),end='') index=len(s)-s[::-1].index(a[0])-1 for i in range(1,len(a)): if a[i] in s[index:]: print(a[i]*(s[index:].count(a[i])),end='') index=len(s)-s[::-1].index(a[i])-1 ```
output
1
71,012
0
142,025
Provide tags and a correct Python 3 solution for this coding contest problem. You've got string s, consisting of only lowercase English letters. Find its lexicographically maximum subsequence. We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk(1 ≤ p1 < p2 < ... < pk ≤ |s|) a subsequence of string s = s1s2......
instruction
0
71,013
0
142,026
Tags: greedy, strings Correct Solution: ``` '''n = int(input()) a = [int(k) for k in input().split()] step1 = min(a) step2 = 10000 for i in range(0,n,2): if a[i] < step2: step2 = a[i] print(max(step1, step2))''' s = input() maxx = 'a' a = '' for i in range(len(s) - 1, -1, -1): if s[i] >= maxx: a...
output
1
71,013
0
142,027
Provide tags and a correct Python 3 solution for this coding contest problem. You've got string s, consisting of only lowercase English letters. Find its lexicographically maximum subsequence. We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk(1 ≤ p1 < p2 < ... < pk ≤ |s|) a subsequence of string s = s1s2......
instruction
0
71,014
0
142,028
Tags: greedy, strings Correct Solution: ``` from sys import stdin,stdout nmbr = lambda: int(stdin.readline()) lst = lambda: list(map(int,stdin.readline().split())) for _ in range(1):#nmbr(): s=input() n=len(s) dp=['a']*n dp[-1]=s[-1] for i in range(n-2,-1,-1): dp[i]=max(dp[i+1],s[i]) ans...
output
1
71,014
0
142,029
Provide tags and a correct Python 3 solution for this coding contest problem. You've got string s, consisting of only lowercase English letters. Find its lexicographically maximum subsequence. We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk(1 ≤ p1 < p2 < ... < pk ≤ |s|) a subsequence of string s = s1s2......
instruction
0
71,015
0
142,030
Tags: greedy, strings Correct Solution: ``` from collections import Counter s = input() c = Counter(s) cur_char = 'z' for ch in s: while c[cur_char] == 0: cur_char = chr(ord(cur_char) - 1) if ch == cur_char: print(cur_char, end='') c[ch] -= 1 ```
output
1
71,015
0
142,031
Provide tags and a correct Python 3 solution for this coding contest problem. You've got string s, consisting of only lowercase English letters. Find its lexicographically maximum subsequence. We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk(1 ≤ p1 < p2 < ... < pk ≤ |s|) a subsequence of string s = s1s2......
instruction
0
71,016
0
142,032
Tags: greedy, strings Correct Solution: ``` def main(): a, res = ' ', [] for b in reversed(input()): if a <= b: a = b res.append(a) print(''.join(reversed(res))) if __name__ == '__main__': main() ```
output
1
71,016
0
142,033
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You've got string s, consisting of only lowercase English letters. Find its lexicographically maximum subsequence. We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk(1 ≤ p1 < p2 < ... ...
instruction
0
71,017
0
142,034
Yes
output
1
71,017
0
142,035
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You've got string s, consisting of only lowercase English letters. Find its lexicographically maximum subsequence. We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk(1 ≤ p1 < p2 < ... ...
instruction
0
71,018
0
142,036
Yes
output
1
71,018
0
142,037
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You've got string s, consisting of only lowercase English letters. Find its lexicographically maximum subsequence. We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk(1 ≤ p1 < p2 < ... ...
instruction
0
71,019
0
142,038
Yes
output
1
71,019
0
142,039
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You've got string s, consisting of only lowercase English letters. Find its lexicographically maximum subsequence. We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk(1 ≤ p1 < p2 < ... ...
instruction
0
71,020
0
142,040
Yes
output
1
71,020
0
142,041
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You've got string s, consisting of only lowercase English letters. Find its lexicographically maximum subsequence. We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk(1 ≤ p1 < p2 < ... ...
instruction
0
71,021
0
142,042
No
output
1
71,021
0
142,043
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You've got string s, consisting of only lowercase English letters. Find its lexicographically maximum subsequence. We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk(1 ≤ p1 < p2 < ... ...
instruction
0
71,022
0
142,044
No
output
1
71,022
0
142,045
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You've got string s, consisting of only lowercase English letters. Find its lexicographically maximum subsequence. We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk(1 ≤ p1 < p2 < ... ...
instruction
0
71,023
0
142,046
No
output
1
71,023
0
142,047
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You've got string s, consisting of only lowercase English letters. Find its lexicographically maximum subsequence. We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk(1 ≤ p1 < p2 < ... ...
instruction
0
71,024
0
142,048
No
output
1
71,024
0
142,049
Provide tags and a correct Python 3 solution for this coding contest problem. You are given string s. Let's call word any largest sequence of consecutive symbols without symbols ',' (comma) and ';' (semicolon). For example, there are four words in string "aba,123;1a;0": "aba", "123", "1a", "0". A word can be empty: fo...
instruction
0
71,201
0
142,402
Tags: implementation, strings Correct Solution: ``` s = input() a = [] b = [] last_word = [] temp = 0 digits = "0123456789" for letter in s: if letter == ";" or letter == ",": for leter in last_word: if digits.find(leter) == -1: temp = 1 break if temp == 0...
output
1
71,201
0
142,403
Provide tags and a correct Python 3 solution for this coding contest problem. You are given string s. Let's call word any largest sequence of consecutive symbols without symbols ',' (comma) and ';' (semicolon). For example, there are four words in string "aba,123;1a;0": "aba", "123", "1a", "0". A word can be empty: fo...
instruction
0
71,202
0
142,404
Tags: implementation, strings Correct Solution: ``` import re def is_int(s: str) -> bool: if len(s) > 0 and (s[0] == "0" and len(s) > 1): return False else: try: int(s) return True except: return False def partition(pred, iterable): trues = []...
output
1
71,202
0
142,405
Provide tags and a correct Python 3 solution for this coding contest problem. You are given string s. Let's call word any largest sequence of consecutive symbols without symbols ',' (comma) and ';' (semicolon). For example, there are four words in string "aba,123;1a;0": "aba", "123", "1a", "0". A word can be empty: fo...
instruction
0
71,203
0
142,406
Tags: implementation, strings Correct Solution: ``` data = input().strip().replace(',', ';').split(';') l1 = [word for word in data if word.isdigit() and word == str(int(word))] sl1 = set(l1) l2 = [word for word in data if word not in sl1] print('"'+ ','.join(l1) + '"' if len(l1) > 0 else '-') print('"'+ ','.join(l2)...
output
1
71,203
0
142,407
Provide tags and a correct Python 3 solution for this coding contest problem. You are given string s. Let's call word any largest sequence of consecutive symbols without symbols ',' (comma) and ';' (semicolon). For example, there are four words in string "aba,123;1a;0": "aba", "123", "1a", "0". A word can be empty: fo...
instruction
0
71,204
0
142,408
Tags: implementation, strings Correct Solution: ``` import re s = re.split(',|;', input()) a = [] b = [] for item in s: if item.isdigit() and (item[0]!='0' or len(item)==1): a.append(item) else: b.append(item) if a: print("\"", ",".join(a), "\"", sep="") else: print("-") if b: print(...
output
1
71,204
0
142,409
Provide tags and a correct Python 3 solution for this coding contest problem. You are given string s. Let's call word any largest sequence of consecutive symbols without symbols ',' (comma) and ';' (semicolon). For example, there are four words in string "aba,123;1a;0": "aba", "123", "1a", "0". A word can be empty: fo...
instruction
0
71,205
0
142,410
Tags: implementation, strings Correct Solution: ``` #!/usr/bin/python import itertools s = input().split(',') for i in range(len(s)): s[i] = s[i].split(';') s = itertools.chain(*s) s = list(s) a = [] b = [] for i in range(len(s)): if s[i] == '0': a.append(s[i]) elif s[i].isdigit() and s[i][0] != ...
output
1
71,205
0
142,411
Provide tags and a correct Python 3 solution for this coding contest problem. You are given string s. Let's call word any largest sequence of consecutive symbols without symbols ',' (comma) and ';' (semicolon). For example, there are four words in string "aba,123;1a;0": "aba", "123", "1a", "0". A word can be empty: fo...
instruction
0
71,206
0
142,412
Tags: implementation, strings Correct Solution: ``` import re ss = re.split(";|,", input()) a = [] b = [] p = re.compile('^(-?([1-9]\d*)|0)$') for s in ss: if p.match(s): a.append(s) else: b.append(s) print('"' + ','.join(a) + '"' if len(a) else '-') print('"' + ','.join(b) + '"' if len(b) e...
output
1
71,206
0
142,413
Provide tags and a correct Python 3 solution for this coding contest problem. You are given string s. Let's call word any largest sequence of consecutive symbols without symbols ',' (comma) and ';' (semicolon). For example, there are four words in string "aba,123;1a;0": "aba", "123", "1a", "0". A word can be empty: fo...
instruction
0
71,207
0
142,414
Tags: implementation, strings Correct Solution: ``` import re s = input() a = [] b = [] # print(re.split(';,', s)) for word in re.split(';|,', s): try: if str(int(word)) == word: a.append(word) else: b.append(word) except ValueError: b.append(word) if a: print('"'...
output
1
71,207
0
142,415
Provide tags and a correct Python 3 solution for this coding contest problem. You are given string s. Let's call word any largest sequence of consecutive symbols without symbols ',' (comma) and ';' (semicolon). For example, there are four words in string "aba,123;1a;0": "aba", "123", "1a", "0". A word can be empty: fo...
instruction
0
71,208
0
142,416
Tags: implementation, strings Correct Solution: ``` s = input() X = [] Y = [] for word in s.split(';'): for num in word.split(','): try: if str(int(num)) == num: X.append(num) else: Y.append(num) except Exception: Y.append(num) if len(X) > 0: print('"' + ",".join(X) + '"') else: print('-') if le...
output
1
71,208
0
142,417
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given string s. Let's call word any largest sequence of consecutive symbols without symbols ',' (comma) and ';' (semicolon). For example, there are four words in string "aba,123;1a;0": "...
instruction
0
71,209
0
142,418
Yes
output
1
71,209
0
142,419
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given string s. Let's call word any largest sequence of consecutive symbols without symbols ',' (comma) and ';' (semicolon). For example, there are four words in string "aba,123;1a;0": "...
instruction
0
71,210
0
142,420
Yes
output
1
71,210
0
142,421
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given string s. Let's call word any largest sequence of consecutive symbols without symbols ',' (comma) and ';' (semicolon). For example, there are four words in string "aba,123;1a;0": "...
instruction
0
71,211
0
142,422
Yes
output
1
71,211
0
142,423
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given string s. Let's call word any largest sequence of consecutive symbols without symbols ',' (comma) and ';' (semicolon). For example, there are four words in string "aba,123;1a;0": "...
instruction
0
71,212
0
142,424
Yes
output
1
71,212
0
142,425
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given string s. Let's call word any largest sequence of consecutive symbols without symbols ',' (comma) and ';' (semicolon). For example, there are four words in string "aba,123;1a;0": "...
instruction
0
71,213
0
142,426
No
output
1
71,213
0
142,427
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given string s. Let's call word any largest sequence of consecutive symbols without symbols ',' (comma) and ';' (semicolon). For example, there are four words in string "aba,123;1a;0": "...
instruction
0
71,214
0
142,428
No
output
1
71,214
0
142,429
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given string s. Let's call word any largest sequence of consecutive symbols without symbols ',' (comma) and ';' (semicolon). For example, there are four words in string "aba,123;1a;0": "...
instruction
0
71,215
0
142,430
No
output
1
71,215
0
142,431
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given string s. Let's call word any largest sequence of consecutive symbols without symbols ',' (comma) and ';' (semicolon). For example, there are four words in string "aba,123;1a;0": "...
instruction
0
71,216
0
142,432
No
output
1
71,216
0
142,433
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let LCP(s, t) be the length of the longest common prefix of strings s and t. Also let s[x ... y] be the substring of s from index x to index y (inclusive). For example, if s = "abcde", then s[1...
instruction
0
71,660
0
143,320
No
output
1
71,660
0
143,321
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let LCP(s, t) be the length of the longest common prefix of strings s and t. Also let s[x ... y] be the substring of s from index x to index y (inclusive). For example, if s = "abcde", then s[1...
instruction
0
71,661
0
143,322
No
output
1
71,661
0
143,323
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let LCP(s, t) be the length of the longest common prefix of strings s and t. Also let s[x ... y] be the substring of s from index x to index y (inclusive). For example, if s = "abcde", then s[1...
instruction
0
71,662
0
143,324
No
output
1
71,662
0
143,325
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Let LCP(s, t) be the length of the longest common prefix of strings s and t. Also let s[x ... y] be the substring of s from index x to index y (inclusive). For example, if s = "abcde", then s[1...
instruction
0
71,663
0
143,326
No
output
1
71,663
0
143,327
Provide tags and a correct Python 3 solution for this coding contest problem. For the given integer n (n > 2) let's write down all the strings of length n which contain n-2 letters 'a' and two letters 'b' in lexicographical (alphabetical) order. Recall that the string s of length n is lexicographically less than stri...
instruction
0
71,805
0
143,610
Tags: binary search, brute force, combinatorics, implementation, math Correct Solution: ``` n = int(input()) for i in range(n): n, k = map(int, input().split()) count_b = 2 while count_b * (count_b - 1) // 2 < k: count_b += 1 count_b, count_a = n - count_b, n - count_b + (count_b * (count_b - 1)...
output
1
71,805
0
143,611
Provide tags and a correct Python 3 solution for this coding contest problem. For the given integer n (n > 2) let's write down all the strings of length n which contain n-2 letters 'a' and two letters 'b' in lexicographical (alphabetical) order. Recall that the string s of length n is lexicographically less than stri...
instruction
0
71,806
0
143,612
Tags: binary search, brute force, combinatorics, implementation, math Correct Solution: ``` import math test=int(input()) for _ in range(test): n,k=map(int,input().split()) i=math.floor((math.sqrt(8*k - 1) + 1)/2) ans=(k - 1 - i*(i - 1)/2) final=['a' for i in range(n)] final[int(i)]='b' f...
output
1
71,806
0
143,613
Provide tags and a correct Python 3 solution for this coding contest problem. For the given integer n (n > 2) let's write down all the strings of length n which contain n-2 letters 'a' and two letters 'b' in lexicographical (alphabetical) order. Recall that the string s of length n is lexicographically less than stri...
instruction
0
71,807
0
143,614
Tags: binary search, brute force, combinatorics, implementation, math Correct Solution: ``` import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) ############ ---- Input Functions ---- ############ def in_int(): return (int(input())) def in_list(): return (list(map(int, input().split()))) def...
output
1
71,807
0
143,615