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. A telephone number is a sequence of exactly 11 digits, where the first digit is 8. For example, the sequence 80011223388 is a telephone number, but the sequences 70011223388 and 80000011223388 are not. You are given a string s of length n, ...
instruction
0
51,379
0
102,758
Tags: brute force, greedy, strings Correct Solution: ``` T=int(input()) for _ in range(T): n=int(input()) strng=input().strip() if (n<11): print('NO') else: if('8' in strng[:n-10]): print('YES') else: print('NO') ```
output
1
51,379
0
102,759
Provide tags and a correct Python 3 solution for this coding contest problem. A telephone number is a sequence of exactly 11 digits, where the first digit is 8. For example, the sequence 80011223388 is a telephone number, but the sequences 70011223388 and 80000011223388 are not. You are given a string s of length n, ...
instruction
0
51,380
0
102,760
Tags: brute force, greedy, strings Correct Solution: ``` import sys import re def main(): inp = sys.stdin.read().strip().split()[2::2] out = [] for s in inp: out.append(('NO', 'YES')[bool(re.search('8\d{10}', s))]) return out print(*main(), sep='\n') ```
output
1
51,380
0
102,761
Provide tags and a correct Python 3 solution for this coding contest problem. A telephone number is a sequence of exactly 11 digits, where the first digit is 8. For example, the sequence 80011223388 is a telephone number, but the sequences 70011223388 and 80000011223388 are not. You are given a string s of length n, ...
instruction
0
51,381
0
102,762
Tags: brute force, greedy, strings Correct Solution: ``` for _ in range(int(input())): n = int(input()) s = input() if n>=11 and '8' in s[:-10]: print('YES') else: print('NO') ```
output
1
51,381
0
102,763
Provide tags and a correct Python 3 solution for this coding contest problem. A telephone number is a sequence of exactly 11 digits, where the first digit is 8. For example, the sequence 80011223388 is a telephone number, but the sequences 70011223388 and 80000011223388 are not. You are given a string s of length n, ...
instruction
0
51,382
0
102,764
Tags: brute force, greedy, strings Correct Solution: ``` [[print('YES' if n >= n - input().find('8') >= 11 else 'NO') for n in [int(input())]] for _ in range(int(input()))] ```
output
1
51,382
0
102,765
Provide tags and a correct Python 3 solution for this coding contest problem. A telephone number is a sequence of exactly 11 digits, where the first digit is 8. For example, the sequence 80011223388 is a telephone number, but the sequences 70011223388 and 80000011223388 are not. You are given a string s of length n, ...
instruction
0
51,383
0
102,766
Tags: brute force, greedy, strings Correct Solution: ``` t = int(input()) for i in range(t): n = int(input()) s = input() if n < 11: print("NO") else: a = s.find('8') if -1 == a: print("NO") else: if n - a >= 11: print("YES") ...
output
1
51,383
0
102,767
Provide tags and a correct Python 3 solution for this coding contest problem. A telephone number is a sequence of exactly 11 digits, where the first digit is 8. For example, the sequence 80011223388 is a telephone number, but the sequences 70011223388 and 80000011223388 are not. You are given a string s of length n, ...
instruction
0
51,384
0
102,768
Tags: brute force, greedy, strings Correct Solution: ``` def solve(s): if len(s) == 11 and s[0] == '8': return True if len(s) < 11: return False if len(s) > 11: i = 0 while i < len(s): if s[i] == '8': break i += 1 if len(s)-i >= 11: return True return False t = int(input()) for _ in rang...
output
1
51,384
0
102,769
Provide tags and a correct Python 3 solution for this coding contest problem. A telephone number is a sequence of exactly 11 digits, where the first digit is 8. For example, the sequence 80011223388 is a telephone number, but the sequences 70011223388 and 80000011223388 are not. You are given a string s of length n, ...
instruction
0
51,385
0
102,770
Tags: brute force, greedy, strings Correct Solution: ``` t = int(input()) output = [] for _ in range(t): n = int(input()) s = input() p = s.find("8") ans = "YES" if (p >= 0) and (p + 10 < n) else "NO" output.append(ans) print("\n".join(output)) ```
output
1
51,385
0
102,771
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A telephone number is a sequence of exactly 11 digits, where the first digit is 8. For example, the sequence 80011223388 is a telephone number, but the sequences 70011223388 and 80000011223388 a...
instruction
0
51,390
0
102,780
No
output
1
51,390
0
102,781
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A telephone number is a sequence of exactly 11 digits, where the first digit is 8. For example, the sequence 80011223388 is a telephone number, but the sequences 70011223388 and 80000011223388 a...
instruction
0
51,392
0
102,784
No
output
1
51,392
0
102,785
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. A telephone number is a sequence of exactly 11 digits, where the first digit is 8. For example, the sequence 80011223388 is a telephone number, but the sequences 70011223388 and 80000011223388 a...
instruction
0
51,393
0
102,786
No
output
1
51,393
0
102,787
Provide tags and a correct Python 3 solution for this coding contest problem. Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string s of lowercase Latin letters. She considers a string t as hidden in...
instruction
0
51,464
0
102,928
Tags: brute force, dp, math, strings Correct Solution: ``` from collections import Counter a = list(map(lambda c: ord(c)-97, input())) dp = [0]*26 dp2 = Counter() for c in a: for i in range(26): if i == c: continue dp2[i, c] += dp[i] dp[c] += 1 ans = max( max(dp), max(dp) ...
output
1
51,464
0
102,929
Provide tags and a correct Python 3 solution for this coding contest problem. Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string s of lowercase Latin letters. She considers a string t as hidden in...
instruction
0
51,465
0
102,930
Tags: brute force, dp, math, strings Correct Solution: ``` from collections import * l = list(input()) n = len(l) arr = [[0]*30 for i in range(30)] array = [0]*30 for i in range(n): val = ord(l[i]) - ord('a') + 1 for j in range(1,27): arr[j][val] += array[j] array[val] += 1 ans = 0 for i in range(1,...
output
1
51,465
0
102,931
Provide tags and a correct Python 3 solution for this coding contest problem. Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string s of lowercase Latin letters. She considers a string t as hidden in...
instruction
0
51,466
0
102,932
Tags: brute force, dp, math, strings Correct Solution: ``` d={} s={0} for x in input(""): for y in s:d[x,y]=d.get((x,y),0)+d.get(y,0) s|={x};d[x]=d.get(x,0)+1 print(max(d.values())) ```
output
1
51,466
0
102,933
Provide tags and a correct Python 3 solution for this coding contest problem. Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string s of lowercase Latin letters. She considers a string t as hidden in...
instruction
0
51,467
0
102,934
Tags: brute force, dp, math, strings Correct Solution: ``` def main(): s = input() cnt = [s.count(chr(ord('a') + i)) for i in range(26)] an = max(cnt) for i in range(26): lol = [0] * 26 kek = cnt[::] for c in s: kek[ord(c) - ord('a')] -= 1 if ord(c) - ord(...
output
1
51,467
0
102,935
Provide tags and a correct Python 3 solution for this coding contest problem. Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string s of lowercase Latin letters. She considers a string t as hidden in...
instruction
0
51,468
0
102,936
Tags: brute force, dp, math, strings 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.mode or "r" not in f...
output
1
51,468
0
102,937
Provide tags and a correct Python 3 solution for this coding contest problem. Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string s of lowercase Latin letters. She considers a string t as hidden in...
instruction
0
51,469
0
102,938
Tags: brute force, dp, math, strings Correct Solution: ``` import sys input = lambda: sys.stdin.readline().rstrip() ans=[0]*26 a=[ord(i)-97 for i in input()] cnt=[0]*26 ; maxx=[0]*26 ; ans=[0]*26 for i in a: cnt[i]+=1 for i in range(len(ans)): z=cnt[i]*(cnt[i]+1)//2-cnt[i] for j in range(len(a)-1,-1,-1): ...
output
1
51,469
0
102,939
Provide tags and a correct Python 3 solution for this coding contest problem. Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string s of lowercase Latin letters. She considers a string t as hidden in...
instruction
0
51,470
0
102,940
Tags: brute force, dp, math, strings Correct Solution: ``` from collections import defaultdict s = list(input()) arr = [0 for j in range(26)] index = defaultdict(int) for j in range(len(s)): for k in range(26): v = chr(k+97)+s[j] index[v]+=arr[k] arr[ord(s[j])-97]+=1 maximum = max(arr) for j in ...
output
1
51,470
0
102,941
Provide tags and a correct Python 3 solution for this coding contest problem. Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string s of lowercase Latin letters. She considers a string t as hidden in...
instruction
0
51,471
0
102,942
Tags: brute force, dp, math, strings Correct Solution: ``` s=str(input()) cml=[[0 for i in range(len(s)+1)] for j in range(26)] c=1 for i in s: k=ord(i)-ord("a") cml[k][c]=cml[k][c-1]+1 for j in range(26): if j!=k:cml[j][c]=cml[j][c-1] c+=1 ab=[[0 for i in range(26)] for j in range(26)] c=1 for k in s: i=ord(...
output
1
51,471
0
102,943
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string s of lowercase Latin...
instruction
0
51,472
0
102,944
Yes
output
1
51,472
0
102,945
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string s of lowercase Latin...
instruction
0
51,473
0
102,946
Yes
output
1
51,473
0
102,947
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string s of lowercase Latin...
instruction
0
51,474
0
102,948
Yes
output
1
51,474
0
102,949
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string s of lowercase Latin...
instruction
0
51,475
0
102,950
Yes
output
1
51,475
0
102,951
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string s of lowercase Latin...
instruction
0
51,476
0
102,952
No
output
1
51,476
0
102,953
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string s of lowercase Latin...
instruction
0
51,477
0
102,954
No
output
1
51,477
0
102,955
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string s of lowercase Latin...
instruction
0
51,478
0
102,956
No
output
1
51,478
0
102,957
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside. The text is a string s of lowercase Latin...
instruction
0
51,479
0
102,958
No
output
1
51,479
0
102,959
Provide a correct Python 3 solution for this coding contest problem. We have N strings of lowercase English letters: S_1, S_2, \cdots, S_N. Takahashi wants to make a string that is a palindrome by choosing one or more of these strings - the same string can be chosen more than once - and concatenating them in some ord...
instruction
0
51,916
0
103,832
"Correct Solution: ``` import sys INF = 1 << 60 MOD = 10**9 + 7 # 998244353 sys.setrecursionlimit(2147483647) input = lambda:sys.stdin.readline().rstrip() from itertools import product from heapq import heappop, heappush def resolve(): n = int(input()) S = [None] * n C = [None] * n for i in range(n): ...
output
1
51,916
0
103,833
Provide a correct Python 3 solution for this coding contest problem. We have N strings of lowercase English letters: S_1, S_2, \cdots, S_N. Takahashi wants to make a string that is a palindrome by choosing one or more of these strings - the same string can be chosen more than once - and concatenating them in some ord...
instruction
0
51,917
0
103,834
"Correct Solution: ``` import sys import queue input_methods=['clipboard','file','key'] using_method=0 input_method=input_methods[using_method] tin=lambda : map(int, input().split()) lin=lambda : list(tin()) mod=1000000007 #+++++ def is_kaibun(s): if len(s) <= 1: return True for c, cc in zip(s,s[::-1]): if c ...
output
1
51,917
0
103,835
Provide a correct Python 3 solution for this coding contest problem. We have N strings of lowercase English letters: S_1, S_2, \cdots, S_N. Takahashi wants to make a string that is a palindrome by choosing one or more of these strings - the same string can be chosen more than once - and concatenating them in some ord...
instruction
0
51,918
0
103,836
"Correct Solution: ``` from heapq import heappush, heappop inf = float('inf') def dijkstra(graph:list, node:int, start:int) -> list: dist = [inf]*node dist[start] = 0 heap = [(0,start)] while heap: cost,thisNode = heappop(heap) for NextCost,NextNode in graph[thisNode]: dist_...
output
1
51,918
0
103,837
Provide a correct Python 3 solution for this coding contest problem. We have N strings of lowercase English letters: S_1, S_2, \cdots, S_N. Takahashi wants to make a string that is a palindrome by choosing one or more of these strings - the same string can be chosen more than once - and concatenating them in some ord...
instruction
0
51,919
0
103,838
"Correct Solution: ``` ''' 自宅用PCでの解答 ''' import math #import numpy as np import itertools import queue import bisect from collections import deque,defaultdict import heapq as hpq from sys import stdin,setrecursionlimit #from scipy.sparse.csgraph import dijkstra #from scipy.sparse import csr_matrix ipt = stdin.readline ...
output
1
51,919
0
103,839
Provide a correct Python 3 solution for this coding contest problem. We have N strings of lowercase English letters: S_1, S_2, \cdots, S_N. Takahashi wants to make a string that is a palindrome by choosing one or more of these strings - the same string can be chosen more than once - and concatenating them in some ord...
instruction
0
51,920
0
103,840
"Correct Solution: ``` from collections import deque def isPalindrome(s): L = len(s) rst = True if L: for i in range(L // 2): if s[i] != s[L - 1 - i]: rst = False break return rst N = int(input()) S = [] for _ in range(N): s, c = input().split(...
output
1
51,920
0
103,841
Provide a correct Python 3 solution for this coding contest problem. We have N strings of lowercase English letters: S_1, S_2, \cdots, S_N. Takahashi wants to make a string that is a palindrome by choosing one or more of these strings - the same string can be chosen more than once - and concatenating them in some ord...
instruction
0
51,921
0
103,842
"Correct Solution: ``` # -*- coding: utf-8 -*- ############# # Libraries # ############# import sys input = sys.stdin.readline import math #from math import gcd import bisect import heapq from collections import defaultdict from collections import deque from collections import Counter from functools import lru_cache...
output
1
51,921
0
103,843
Provide a correct Python 3 solution for this coding contest problem. We have N strings of lowercase English letters: S_1, S_2, \cdots, S_N. Takahashi wants to make a string that is a palindrome by choosing one or more of these strings - the same string can be chosen more than once - and concatenating them in some ord...
instruction
0
51,922
0
103,844
"Correct Solution: ``` it = lambda: list(map(int, input().strip().split())) INF = float('inf') def solve(): N = int(input()) S = [] R = [] C = [] for _ in range(N): s, c = input().strip().split() S.append(s) R.append(s[::-1]) C.append(int(c)) vis = set() ...
output
1
51,922
0
103,845
Provide a correct Python 3 solution for this coding contest problem. We have N strings of lowercase English letters: S_1, S_2, \cdots, S_N. Takahashi wants to make a string that is a palindrome by choosing one or more of these strings - the same string can be chosen more than once - and concatenating them in some ord...
instruction
0
51,923
0
103,846
"Correct Solution: ``` from collections import deque def isPalindrome(s): L = len(s) return all(s[i] == s[L - 1 - i] for i in range(L // 2)) N = int(input()) S = [] for _ in range(N): s, c = input().split() S.append((s, int(c))) path = [dict() for _ in range(2)] q = deque() # S.sort(key=lambda x: x...
output
1
51,923
0
103,847
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have N strings of lowercase English letters: S_1, S_2, \cdots, S_N. Takahashi wants to make a string that is a palindrome by choosing one or more of these strings - the same string can be ch...
instruction
0
51,924
0
103,848
Yes
output
1
51,924
0
103,849
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have N strings of lowercase English letters: S_1, S_2, \cdots, S_N. Takahashi wants to make a string that is a palindrome by choosing one or more of these strings - the same string can be ch...
instruction
0
51,925
0
103,850
Yes
output
1
51,925
0
103,851
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have N strings of lowercase English letters: S_1, S_2, \cdots, S_N. Takahashi wants to make a string that is a palindrome by choosing one or more of these strings - the same string can be ch...
instruction
0
51,926
0
103,852
Yes
output
1
51,926
0
103,853
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have N strings of lowercase English letters: S_1, S_2, \cdots, S_N. Takahashi wants to make a string that is a palindrome by choosing one or more of these strings - the same string can be ch...
instruction
0
51,927
0
103,854
Yes
output
1
51,927
0
103,855
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have N strings of lowercase English letters: S_1, S_2, \cdots, S_N. Takahashi wants to make a string that is a palindrome by choosing one or more of these strings - the same string can be ch...
instruction
0
51,928
0
103,856
No
output
1
51,928
0
103,857
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have N strings of lowercase English letters: S_1, S_2, \cdots, S_N. Takahashi wants to make a string that is a palindrome by choosing one or more of these strings - the same string can be ch...
instruction
0
51,929
0
103,858
No
output
1
51,929
0
103,859
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have N strings of lowercase English letters: S_1, S_2, \cdots, S_N. Takahashi wants to make a string that is a palindrome by choosing one or more of these strings - the same string can be ch...
instruction
0
51,930
0
103,860
No
output
1
51,930
0
103,861
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. We have N strings of lowercase English letters: S_1, S_2, \cdots, S_N. Takahashi wants to make a string that is a palindrome by choosing one or more of these strings - the same string can be ch...
instruction
0
51,931
0
103,862
No
output
1
51,931
0
103,863
Provide a correct Python 3 solution for this coding contest problem. You are given a string $S$, which is balanced parentheses with a star symbol '*' inserted. Any balanced parentheses can be constructed using the following rules: * An empty string is balanced. * Concatenation of two balanced parentheses is balanced...
instruction
0
52,148
0
104,296
"Correct Solution: ``` S = list(input()) S_l = len(S) n=0 l = [] r = [] f_l, f_r = 0,0 for n in range(S.index('*')): if S[n]== '(': f_l += 1 elif S[n]== ')': f_l -= 1 for n in range(S_l - S.index('*')): if S[S_l-n-1] == ')': f_r += 1 elif S[S_l-n-1]== '(': f_r -= 1 print(...
output
1
52,148
0
104,297
Provide a correct Python 3 solution for this coding contest problem. You are given a string $S$, which is balanced parentheses with a star symbol '*' inserted. Any balanced parentheses can be constructed using the following rules: * An empty string is balanced. * Concatenation of two balanced parentheses is balanced...
instruction
0
52,149
0
104,298
"Correct Solution: ``` S=list(input()) N=S.index('*') P=abs(S[0:N].count('(')-S[0:N].count(')')) Q=abs(S[N+1:len(S)].count('(')-S[N+1:len(S)].count(')')) print(min(P,Q)) ```
output
1
52,149
0
104,299
Provide a correct Python 3 solution for this coding contest problem. You are given a string $S$, which is balanced parentheses with a star symbol '*' inserted. Any balanced parentheses can be constructed using the following rules: * An empty string is balanced. * Concatenation of two balanced parentheses is balanced...
instruction
0
52,150
0
104,300
"Correct Solution: ``` s = input() while '()' in s: s = s.replace('()', '') else: print(s.count('(')) ```
output
1
52,150
0
104,301
Provide a correct Python 3 solution for this coding contest problem. You are given a string $S$, which is balanced parentheses with a star symbol '*' inserted. Any balanced parentheses can be constructed using the following rules: * An empty string is balanced. * Concatenation of two balanced parentheses is balanced...
instruction
0
52,151
0
104,302
"Correct Solution: ``` S = input() n = 0 ans = 0 for i in S: if i == "(": n += 1 elif i == ")": n -= 1 else: print (n) break ```
output
1
52,151
0
104,303
Provide a correct Python 3 solution for this coding contest problem. You are given a string $S$, which is balanced parentheses with a star symbol '*' inserted. Any balanced parentheses can be constructed using the following rules: * An empty string is balanced. * Concatenation of two balanced parentheses is balanced...
instruction
0
52,153
0
104,306
"Correct Solution: ``` s=input() ans=0 for i in range(len(s)): if s[i]=="*": break elif s[i]=="(": ans+=1 else: ans-=1 print(ans) ```
output
1
52,153
0
104,307
Provide a correct Python 3 solution for this coding contest problem. You are given a string of length N. Calculate the number of distinct substrings of S. Constraints * 1 \leq N \leq 500,000 * S consists of lowercase English letters. Input Input is given from Standard Input in the following format: S Output P...
instruction
0
52,822
0
105,644
"Correct Solution: ``` def sa_naive(s): n = len(s) sa = list(range(n)) sa.sort(key=lambda x: s[x:]) return sa def sa_doubling(s): n = len(s) sa = list(range(n)) rnk = s tmp = [0] * n k = 1 while k < n: sa.sort(key=lambda x: (rnk[x], rnk[x + k]) if x + k < n else (rnk[x],...
output
1
52,822
0
105,645
Provide a correct Python 3 solution for this coding contest problem. You are given a string of length N. Calculate the number of distinct substrings of S. Constraints * 1 \leq N \leq 500,000 * S consists of lowercase English letters. Input Input is given from Standard Input in the following format: S Output P...
instruction
0
52,823
0
105,646
"Correct Solution: ``` def sa_naive(s): n = len(s) sa = list(range(n)) sa.sort(key=lambda x: s[x:]) return sa def sa_doubling(s): n = len(s) sa = list(range(n)) rnk = s tmp = [0] * n k = 1 while k < n: sa.sort(key=lambda x: (rnk[x], rnk[x + k]) if x + k < n else (rnk[x],...
output
1
52,823
0
105,647
Provide a correct Python 3 solution for this coding contest problem. You are given a string of length N. Calculate the number of distinct substrings of S. Constraints * 1 \leq N \leq 500,000 * S consists of lowercase English letters. Input Input is given from Standard Input in the following format: S Output P...
instruction
0
52,824
0
105,648
"Correct Solution: ``` # # https://github.com/not522/ac-library-python/blob/master/atcoder/string.py import copy import functools import typing def _sa_naive(s: typing.List[int]) -> typing.List[int]: sa = list(range(len(s))) return sorted(sa, key=lambda i: s[i:]) def _sa_doubling(s: typing.List[int]) -> ty...
output
1
52,824
0
105,649