message
stringlengths
2
23.4k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
129
108k
cluster
float64
6
6
__index_level_0__
int64
258
216k
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Berland scientists know that the Old Berland language had exactly n words. Those words had lengths of l1, l2, ..., ln letters. Every word consisted of two letters, 0 and 1. Ancient Berland people spoke quickly and didn’t make pauses between the words, but at the same time they could always understand each other perfectly. It was possible because no word was a prefix of another one. The prefix of a string is considered to be one of its substrings that starts from the initial symbol. Help the scientists determine whether all the words of the Old Berland language can be reconstructed and if they can, output the words themselves. Input The first line contains one integer N (1 ≤ N ≤ 1000) — the number of words in Old Berland language. The second line contains N space-separated integers — the lengths of these words. All the lengths are natural numbers not exceeding 1000. Output If there’s no such set of words, in the single line output NO. Otherwise, in the first line output YES, and in the next N lines output the words themselves in the order their lengths were given in the input file. If the answer is not unique, output any. Examples Input 3 1 2 3 Output YES 0 10 110 Input 3 1 1 1 Output NO Submitted Solution: ``` from sys import stdin n = int(stdin.readline()) a = [int(x) for x in stdin.readline().split()] a.sort() high = a[-1] total = 1<<high a = [high-x for x in a] current = 0 words = [] for x in a: words.append(current>>x) current += 1<<x if current > total: print('NO') else: print('YES') print('\n'.join(["{0:b}".format(x) for x in words])) ```
instruction
0
23,210
6
46,420
No
output
1
23,210
6
46,421
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Berland scientists know that the Old Berland language had exactly n words. Those words had lengths of l1, l2, ..., ln letters. Every word consisted of two letters, 0 and 1. Ancient Berland people spoke quickly and didn’t make pauses between the words, but at the same time they could always understand each other perfectly. It was possible because no word was a prefix of another one. The prefix of a string is considered to be one of its substrings that starts from the initial symbol. Help the scientists determine whether all the words of the Old Berland language can be reconstructed and if they can, output the words themselves. Input The first line contains one integer N (1 ≤ N ≤ 1000) — the number of words in Old Berland language. The second line contains N space-separated integers — the lengths of these words. All the lengths are natural numbers not exceeding 1000. Output If there’s no such set of words, in the single line output NO. Otherwise, in the first line output YES, and in the next N lines output the words themselves in the order their lengths were given in the input file. If the answer is not unique, output any. Examples Input 3 1 2 3 Output YES 0 10 110 Input 3 1 1 1 Output NO Submitted Solution: ``` # l1, l2, ln # 1 2 3 # 0 10 110 # 1 01 001 # 0 1 ? # N # 1 2 3 # root # 0 1 # 0 in children and this node is end of word => 1 ? , 1 is also end of word: yes: return NO # else: add children in # 1: add 0 # prefix is when end of word # 0 1 1 0 # 0 1 1 1 class Node: def __init__(self): self.endWord = False self.children = {} # add(1) # 0 # add(2) # 10 # add(3) # 110 # add(2) # 00 # add(2) # 01 # add(2) # 0 def addNode(root, num): # num = 1, 2 ,3 s = '' cur = root for i in range(num): c = '0' if c not in cur.children: cur.children[c] = Node() elif cur.children[c].endWord == True: c = '1' if c not in cur.children: cur.children[c] = Node() elif cur.children[c].endWord == True: return '' cur = cur.children[c] # print(cur) s += c # print(s) cur.endWord = True return s def main(): n = int(input()) nums = map(int, input().split()) res = [] root = Node() # print(res) for num in nums: s = addNode(root, num) # print(s) if s == '': return [] res.append(s) return res ans = main() if len(ans) == 0: print('NO') else: print('YES') print('\n'.join(ans)) ```
instruction
0
23,211
6
46,422
No
output
1
23,211
6
46,423
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Berland scientists know that the Old Berland language had exactly n words. Those words had lengths of l1, l2, ..., ln letters. Every word consisted of two letters, 0 and 1. Ancient Berland people spoke quickly and didn’t make pauses between the words, but at the same time they could always understand each other perfectly. It was possible because no word was a prefix of another one. The prefix of a string is considered to be one of its substrings that starts from the initial symbol. Help the scientists determine whether all the words of the Old Berland language can be reconstructed and if they can, output the words themselves. Input The first line contains one integer N (1 ≤ N ≤ 1000) — the number of words in Old Berland language. The second line contains N space-separated integers — the lengths of these words. All the lengths are natural numbers not exceeding 1000. Output If there’s no such set of words, in the single line output NO. Otherwise, in the first line output YES, and in the next N lines output the words themselves in the order their lengths were given in the input file. If the answer is not unique, output any. Examples Input 3 1 2 3 Output YES 0 10 110 Input 3 1 1 1 Output NO Submitted Solution: ``` # Problem from Codeforces # http://codeforces.com/contest/37/problem/C import sys class input_tokenizer: __tokens = None def has_next(self): return self.__tokens != [] and self.__tokens != None def next(self): token = self.__tokens[-1] self.__tokens.pop() return token def __init__(self): self.__tokens = sys.stdin.read().split()[::-1] inp = input_tokenizer() class Node: def __init__(self, index, depth): self.index = index self.depth = depth def __lt__(self, other): return self.depth < other.depth def dfs(s, depth, n, curr, word, arr): if curr >= n: return curr, word if arr[curr].depth == depth: word[arr[curr].index] = s curr += 1 return curr, word s += '0' curr, word = dfs(s, depth + 1, n, curr, word, arr) s = s[:len(s) - 1] + '1' curr, word = dfs(s, depth + 1, n, curr, word, arr) return curr, word def solution(): try: n = int(inp.next()) arr = [] for i in range(n): word_len = int(inp.next()) arr.append(Node(i, word_len)) arr.sort() word = ['' for i in range(n)] curr = 0 results = dfs('', 0, n, curr, word, arr) word = results[1] curr = results[0] if curr < n: print('NO') else: print('YES') print(*word, sep='\n') except Exception: import traceback print(traceback.format_exc()) solution() ```
instruction
0
23,212
6
46,424
No
output
1
23,212
6
46,425
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Berland scientists know that the Old Berland language had exactly n words. Those words had lengths of l1, l2, ..., ln letters. Every word consisted of two letters, 0 and 1. Ancient Berland people spoke quickly and didn’t make pauses between the words, but at the same time they could always understand each other perfectly. It was possible because no word was a prefix of another one. The prefix of a string is considered to be one of its substrings that starts from the initial symbol. Help the scientists determine whether all the words of the Old Berland language can be reconstructed and if they can, output the words themselves. Input The first line contains one integer N (1 ≤ N ≤ 1000) — the number of words in Old Berland language. The second line contains N space-separated integers — the lengths of these words. All the lengths are natural numbers not exceeding 1000. Output If there’s no such set of words, in the single line output NO. Otherwise, in the first line output YES, and in the next N lines output the words themselves in the order their lengths were given in the input file. If the answer is not unique, output any. Examples Input 3 1 2 3 Output YES 0 10 110 Input 3 1 1 1 Output NO Submitted Solution: ``` import sys class Node: def __init__(self, depth, parent): self.depth = depth self.parent = parent self.left = None self.right = None self.leaf = False def __str__(self): return 'depth = %d, left? %s, right? %s' % (self.depth, self.left != None, self.right != None) def traverse(node, symbols): if node.leaf: print(''.join(symbols)) return if node.left != None: symbols.append('0') traverse(node.left, symbols) symbols.pop() if node.right != None: symbols.append('1') traverse(node.right, symbols) symbols.pop() n = int(input()) lengths = sorted(list(map(int, input().split()))) root = Node(0, None) curr = root for i in range(lengths[0]): curr.left = Node(curr.depth+1, curr) curr = curr.left curr.leaf = True for length in lengths[1:]: curr = curr.parent while curr.right != None: if curr == root: print('NO') sys.exit() curr = curr.parent curr.right = Node(curr.depth+1, curr) curr = curr.right while curr.depth != length: curr.left = Node(curr.depth+1, curr) curr = curr.left curr.leaf = True print('YES') traverse(root, []) ```
instruction
0
23,213
6
46,426
No
output
1
23,213
6
46,427
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the table abcd edfg hijk we obtain the table: acd efg hjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good. Input The first line contains two integers — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table. Output Print a single number — the minimum number of columns that you need to remove in order to make the table good. Examples Input 1 10 codeforces Output 0 Input 4 4 case care test code Output 2 Input 5 4 code forc esco defo rces Output 4 Note In the first sample the table is already good. In the second sample you may remove the first and third column. In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition). Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t.
instruction
0
23,278
6
46,556
Tags: brute force, constructive algorithms, implementation Correct Solution: ``` # cook your dish here import sys from functools import lru_cache, cmp_to_key from heapq import merge, heapify, heappop, heappush from math import * from collections import defaultdict as dd, deque, Counter as C from itertools import combinations as comb, permutations as perm from bisect import bisect_left as bl, bisect_right as br, bisect from time import perf_counter from fractions import Fraction import copy import time starttime = time.time() mod = int(pow(10, 9) + 7) mod2 = 998244353 def data(): return sys.stdin.readline().strip() def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end) def L(): return list(sp()) def sl(): return list(ssp()) def sp(): return map(int, data().split()) def ssp(): return map(str, data().split()) def l1d(n, val=0): return [val for i in range(n)] def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)] try: # sys.setrecursionlimit(int(pow(10,7))) sys.stdin = open("input.txt", "r") # sys.stdout = open("../output.txt", "w") except: pass def pmat(A): for ele in A: print(*ele,end="\n") def seive(): prime=[1 for i in range(10**6+1)] prime[0]=0 prime[1]=0 for i in range(10**6+1): if(prime[i]): for j in range(2*i,10**6+1,i): prime[j]=0 return prime # exit() # from sys import stdin # input = stdin.readline n,m=L() A=[input() for i in range(n)] t=["" for i in range(n)] ans=0 for i in range(m): f=[t[j]+A[j][i] for j in range(n)] if f==sorted(f): t=f else: ans+=1 print(ans) endtime = time.time() # print(f"Runtime of the program is {endtime - starttime}") ```
output
1
23,278
6
46,557
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the table abcd edfg hijk we obtain the table: acd efg hjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good. Input The first line contains two integers — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table. Output Print a single number — the minimum number of columns that you need to remove in order to make the table good. Examples Input 1 10 codeforces Output 0 Input 4 4 case care test code Output 2 Input 5 4 code forc esco defo rces Output 4 Note In the first sample the table is already good. In the second sample you may remove the first and third column. In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition). Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t.
instruction
0
23,279
6
46,558
Tags: brute force, constructive algorithms, implementation Correct Solution: ``` # cook your dish here from sys import stdin,stdout from collections import Counter from itertools import permutations import bisect import math I=lambda: map(int,stdin.readline().split()) I1=lambda: stdin.readline() n,m=I() if n==1: print(0) exit() s=[I1() for i in range(n)] if m==1: if s==sorted(s): print(0) else: print(1) exit() c,i=0,1 while True: if i>len(s[0]): break for j in range(n-1): if s[j][:i]>s[j+1][:i]: c+=1 s=[x[:(i-1)]+x[i:] for x in s] i-=1 break i+=1 print(c) ```
output
1
23,279
6
46,559
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the table abcd edfg hijk we obtain the table: acd efg hjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good. Input The first line contains two integers — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table. Output Print a single number — the minimum number of columns that you need to remove in order to make the table good. Examples Input 1 10 codeforces Output 0 Input 4 4 case care test code Output 2 Input 5 4 code forc esco defo rces Output 4 Note In the first sample the table is already good. In the second sample you may remove the first and third column. In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition). Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t.
instruction
0
23,280
6
46,560
Tags: brute force, constructive algorithms, implementation Correct Solution: ``` n, m = list(map(int, input().rstrip().split())) words = [] op = 0 for i in range(n): words += [input()] final = [""]*n for j in range(m): flag = 1 for i in range(n - 1): x = final[i] + words[i][j] y = final[i + 1] + words[i + 1][j] if x > y: op += 1 flag = 0 break if flag == 1: for i in range(n): final[i] += words[i][j] print(op) ```
output
1
23,280
6
46,561
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the table abcd edfg hijk we obtain the table: acd efg hjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good. Input The first line contains two integers — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table. Output Print a single number — the minimum number of columns that you need to remove in order to make the table good. Examples Input 1 10 codeforces Output 0 Input 4 4 case care test code Output 2 Input 5 4 code forc esco defo rces Output 4 Note In the first sample the table is already good. In the second sample you may remove the first and third column. In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition). Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t.
instruction
0
23,281
6
46,562
Tags: brute force, constructive algorithms, implementation Correct Solution: ``` from sys import maxsize, stdout, stdin,stderr mod = int(1e9+7) import sys def I(): return int(stdin.readline()) def lint(): return [int(x) for x in stdin.readline().split()] def S(): return list(map(str,input().strip())) def grid(r, c): return [lint() for i in range(r)] from collections import defaultdict, Counter, deque import math import heapq from heapq import heappop , heappush import bisect from itertools import groupby from itertools import permutations as comb def gcd(a,b): while b: a %= b tmp = a a = b b = tmp return a def lcm(a,b): return a // gcd(a, b) * b def check_prime(n): for i in range(2, int(n ** (1 / 2)) + 1): if not n % i: return False return True def nCr(n, r): return (fact(n) // (fact(r) * fact(n - r))) # Returns factorial of n def fact(n): res = 1 for i in range(2, n+1): res = res * i return res def primefactors(n): num=0 while n % 2 == 0: num+=1 n = n / 2 for i in range(3,int(math.sqrt(n))+1,2): while n % i== 0: num+=1 n = n // i if n > 2: num+=1 return num ''' def iter_ds(src): store=[src] while len(store): tmp=store.pop() if not vis[tmp]: vis[tmp]=True for j in ar[tmp]: store.append(j) ''' def ask(a): print('? {}'.format(a),flush=True) n=I() return n def dfs(i,p): a,tmp=0,0 for j in d[i]: if j!=p: a+=1 tmp+=dfs(j,i) if a==0: return 0 return tmp/a + 1 def primeFactors(n): l=[] while n % 2 == 0: l.append(2) n = n // 2 if n > 2: l.append(n) return l r,c=lint() s=[] s.append(['a']*(c+1)) for _ in range(r): s.append(['a']+S()) cnt=0 k=0 t=[0]*(r+1) for i in range(1,c+1): flag=0 for j in range(1,r): if not t[j]: if ord(s[j+1][i])<ord(s[j][i]): cnt+=1 flag=1 break if not flag: for j in range(1,r): if s[j][i]<s[j+1][i]: t[j]=1 print(cnt) ```
output
1
23,281
6
46,563
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the table abcd edfg hijk we obtain the table: acd efg hjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good. Input The first line contains two integers — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table. Output Print a single number — the minimum number of columns that you need to remove in order to make the table good. Examples Input 1 10 codeforces Output 0 Input 4 4 case care test code Output 2 Input 5 4 code forc esco defo rces Output 4 Note In the first sample the table is already good. In the second sample you may remove the first and third column. In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition). Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t.
instruction
0
23,282
6
46,564
Tags: brute force, constructive algorithms, implementation Correct Solution: ``` from operator import itemgetter n, m = map(int, input().strip().split()) table = [] bad_cols = [False] * m for _ in range(n): table.append(input().strip()) for j in range(m): indices = [idx for idx in range(j + 1) if not bad_cols[idx]] for i in range(1, n): if itemgetter(*indices)(table[i]) < itemgetter(*indices)(table[i - 1]): bad_cols[j] = True break print(sum(bad_cols)) ```
output
1
23,282
6
46,565
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the table abcd edfg hijk we obtain the table: acd efg hjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good. Input The first line contains two integers — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table. Output Print a single number — the minimum number of columns that you need to remove in order to make the table good. Examples Input 1 10 codeforces Output 0 Input 4 4 case care test code Output 2 Input 5 4 code forc esco defo rces Output 4 Note In the first sample the table is already good. In the second sample you may remove the first and third column. In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition). Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t.
instruction
0
23,283
6
46,566
Tags: brute force, constructive algorithms, implementation Correct Solution: ``` n, m = list(map(int, input().split())) ls = [input() for _ in range(n)] sorted_inds = [0] * n ans = 0 for i in range(m): new_sorted_inds = set() for j in range(1, n): if sorted_inds[j] == 0: if ls[j][i] < ls[j - 1][i]: ans += 1 break else: for j in range(1, n): if ls[j][i] > ls[j - 1][i]: sorted_inds[j] = 1 print(ans) ```
output
1
23,283
6
46,567
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the table abcd edfg hijk we obtain the table: acd efg hjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good. Input The first line contains two integers — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table. Output Print a single number — the minimum number of columns that you need to remove in order to make the table good. Examples Input 1 10 codeforces Output 0 Input 4 4 case care test code Output 2 Input 5 4 code forc esco defo rces Output 4 Note In the first sample the table is already good. In the second sample you may remove the first and third column. In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition). Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t.
instruction
0
23,284
6
46,568
Tags: brute force, constructive algorithms, implementation Correct Solution: ``` import sys import math MAXNUM = math.inf MINNUM = -1 * math.inf ASCIILOWER = 97 ASCIIUPPER = 65 def getInt(): return int(sys.stdin.readline().rstrip()) def getInts(): return map(int, sys.stdin.readline().rstrip().split(" ")) def getString(): return sys.stdin.readline().rstrip() def printOutput(ans): sys.stdout.write() pass def orderedVal(grid, curValues, column): if column == 0: return 0 for i in range(len(grid)): if grid[i][curValues] > grid[i][column]: return math.inf return 0 def isLex(grid, column): for i in range(1, len(grid)): if grid[i][column] < grid[i - 1][column]: return False return True def getLexPairs(grid, column): lPairs = set() for i in range(1, len(grid)): if grid[i][column] == grid[i - 1][column]: lPairs.add((i - 1, i)) return lPairs def compare(grid, column, lPairs): nextlPairs = set() """either returns remaining lPairs, True, or False""" for a, b in lPairs: # print("hi", a, b) # print(grid[a][column], grid[b][column]) if grid[a][column] > grid[b][column]: return False elif grid[a][column] == grid[b][column]: nextlPairs.add((a, b)) return nextlPairs def solve(grid): ans = len(grid[0]) for column in range(len(grid[0])): if ans <= column: break if isLex(grid, column): removeCol = 0 lPairs = getLexPairs(grid, column) # print(column, lPairs) for nextColumn in range(column + 1, len(grid[0])): k = compare(grid, nextColumn, lPairs) # print('comp',k) if k == False: removeCol += 1 elif len(k) == 0: break else: lPairs = k ans = min(ans, column + removeCol) return ans def readinput(): n, m = getInts() grid = [] for _ in range(n): grid.append(getString()) print(solve(grid)) readinput() ```
output
1
23,284
6
46,569
Provide tags and a correct Python 3 solution for this coding contest problem. You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the table abcd edfg hijk we obtain the table: acd efg hjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good. Input The first line contains two integers — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table. Output Print a single number — the minimum number of columns that you need to remove in order to make the table good. Examples Input 1 10 codeforces Output 0 Input 4 4 case care test code Output 2 Input 5 4 code forc esco defo rces Output 4 Note In the first sample the table is already good. In the second sample you may remove the first and third column. In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition). Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t.
instruction
0
23,285
6
46,570
Tags: brute force, constructive algorithms, implementation Correct Solution: ``` line = input().split() n = int(line[0]) m = int(line[1]) data = [] for i in range(n): data.append(input()) x = [1 for i in range(n)] delete = 0 for i in range(m): dum = [1 for j in range(n)] status = 1 for j in range(1,n): if data[j][i] > data[j-1][i]: dum[j] = 0 elif data[j][i] == data[j-1][i]: dum[j] = 1 else: if x[j] == 1: delete += 1 status = 0 break if status == 1: for j in range(len(dum)): if dum[j] == 0: x[j] = 0 print(delete) ```
output
1
23,285
6
46,571
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the table abcd edfg hijk we obtain the table: acd efg hjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good. Input The first line contains two integers — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table. Output Print a single number — the minimum number of columns that you need to remove in order to make the table good. Examples Input 1 10 codeforces Output 0 Input 4 4 case care test code Output 2 Input 5 4 code forc esco defo rces Output 4 Note In the first sample the table is already good. In the second sample you may remove the first and third column. In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition). Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t. Submitted Solution: ``` n, m = [int(x) for x in input().split()] rs = [input() for _ in range(n)] mask = [1] * m def get_masked(x): return ''.join(y for y, m in zip(x, mask) if m) res = 0 for i in range(m): l = [get_masked(x)[:i - res + 1] for x in rs] if not all(l[i] <= l[i+1] for i in range(len(l)-1)): mask[i] = 0 res += 1 print(res) ```
instruction
0
23,286
6
46,572
Yes
output
1
23,286
6
46,573
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the table abcd edfg hijk we obtain the table: acd efg hjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good. Input The first line contains two integers — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table. Output Print a single number — the minimum number of columns that you need to remove in order to make the table good. Examples Input 1 10 codeforces Output 0 Input 4 4 case care test code Output 2 Input 5 4 code forc esco defo rces Output 4 Note In the first sample the table is already good. In the second sample you may remove the first and third column. In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition). Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t. Submitted Solution: ``` n, m = map(int, input().split()) grid = [] for _ in range(n): grid.append(list(input())) deleted = 0 last = [] for j in range(m): for i in range(1,n): if grid[i][j] < grid[i-1][j] and len(last) == 0: deleted += 1 break elif len(last) and grid[i][j] < grid[i-1][j]: if ''.join(grid[i-1][x] for x in last+[j]) > ''.join(grid[i][x] for x in last+[j]): deleted += 1 break else: last.append(j) print(deleted) ```
instruction
0
23,287
6
46,574
Yes
output
1
23,287
6
46,575
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the table abcd edfg hijk we obtain the table: acd efg hjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good. Input The first line contains two integers — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table. Output Print a single number — the minimum number of columns that you need to remove in order to make the table good. Examples Input 1 10 codeforces Output 0 Input 4 4 case care test code Output 2 Input 5 4 code forc esco defo rces Output 4 Note In the first sample the table is already good. In the second sample you may remove the first and third column. In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition). Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t. Submitted Solution: ``` import sys from collections import deque import math input_ = lambda: sys.stdin.readline().strip("\r\n") ii = lambda : int(input_()) il = lambda : list(map(int, input_().split())) ilf = lambda : list(map(float, input_().split())) ip = lambda : input_() fi = lambda : float(input_()) li = lambda : list(input_()) pr = lambda x : print(x) f = lambda : sys.stdout.flush() n,m = il() ans = 0 a = [] for _ in range(n) : a.append(ip()) b = ['' for _ in range (n)] for i in range (m) : c = [] for j in range(n) : c.append(b[j]+a[j][i]) if (c == sorted(c)) : if len(c) == len(set(c)) : break else : b = c else : ans += 1 print(ans) ```
instruction
0
23,288
6
46,576
Yes
output
1
23,288
6
46,577
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the table abcd edfg hijk we obtain the table: acd efg hjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good. Input The first line contains two integers — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table. Output Print a single number — the minimum number of columns that you need to remove in order to make the table good. Examples Input 1 10 codeforces Output 0 Input 4 4 case care test code Output 2 Input 5 4 code forc esco defo rces Output 4 Note In the first sample the table is already good. In the second sample you may remove the first and third column. In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition). Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t. Submitted Solution: ``` def remove(p, a): for i in range(len(a)): a[i] = a[i][: p] + a[i][p + 1: ] n, m = [int(x) for x in input().split()] a = [] for i in range(n): a.append(input()) removed = 0 for i in range(m): i -= removed for j in range(n - 1): if a[j][: i + 1] > a[j + 1][: i + 1]: remove(i, a) removed += 1 break print(removed) # Made By Mostafa_Khaled ```
instruction
0
23,289
6
46,578
Yes
output
1
23,289
6
46,579
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the table abcd edfg hijk we obtain the table: acd efg hjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good. Input The first line contains two integers — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table. Output Print a single number — the minimum number of columns that you need to remove in order to make the table good. Examples Input 1 10 codeforces Output 0 Input 4 4 case care test code Output 2 Input 5 4 code forc esco defo rces Output 4 Note In the first sample the table is already good. In the second sample you may remove the first and third column. In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition). Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t. Submitted Solution: ``` #!/usr/bin/env python3 n, m = map(int, input().split()) table = [[c for c in input()] for i in range(n)] def is_good_column(c, adj): flag = False for i in range(n - 1): if (not adj or (adj and table[i][adj] == table[i+1][adj])) and table[i][c] > table[i+1][c]: return False, False elif table[i][c] == table[i+1][c]: flag = True return True, flag i = 0 need = m count = 0 adj = None while i < need: flag, dup = is_good_column(i, adj) if flag: adj = i if not dup: break else: count += 1 need = min(i + 2, m) i += 1 print(count) ```
instruction
0
23,290
6
46,580
No
output
1
23,290
6
46,581
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the table abcd edfg hijk we obtain the table: acd efg hjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good. Input The first line contains two integers — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table. Output Print a single number — the minimum number of columns that you need to remove in order to make the table good. Examples Input 1 10 codeforces Output 0 Input 4 4 case care test code Output 2 Input 5 4 code forc esco defo rces Output 4 Note In the first sample the table is already good. In the second sample you may remove the first and third column. In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition). Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t. Submitted Solution: ``` # from itertools import combinations # from bisect import bisect_left # from functools import * # from collections import Counter def is_lexigraphic(s): for i in range(len(s) - 1): if s[i] > s[i + 1]: return False return True I = lambda: list(map(int, input().split())) n, m = I() a = [input() for i in range(n)] mn = m columns = list(zip(*a)) for i in range(m): curCol = columns[i] if not is_lexigraphic(curCol): continue l = [] for j in range(n - 1): if curCol[j] == curCol[j + 1]: l.append((j, j + 1)) x = 0 for k in range(i + 1, m): if any([columns[k][a] > columns[k][b] for a, b in l]): x += 1 else: break mn = min(x + i, mn) print(mn) ```
instruction
0
23,291
6
46,582
No
output
1
23,291
6
46,583
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the table abcd edfg hijk we obtain the table: acd efg hjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good. Input The first line contains two integers — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table. Output Print a single number — the minimum number of columns that you need to remove in order to make the table good. Examples Input 1 10 codeforces Output 0 Input 4 4 case care test code Output 2 Input 5 4 code forc esco defo rces Output 4 Note In the first sample the table is already good. In the second sample you may remove the first and third column. In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition). Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t. Submitted Solution: ``` from itertools import combinations, permutations def is_good(s,n,m): for i in range(n-1): if s[i] > s[i+1]: return False return True def main2(n,m,a): if n <= 0 or m<=0 or is_good(a,n,m): print(0) return for i in range(1,m): p = combinations(range(m),i) for j in p: s = ["".join([k for b,k in enumerate(x) if b not in j]) for x in a] if is_good(s,n,m-i): print(i) return print(m) def main3(n,m,a): if n <= 1 or m<=0 or is_good(a,n,m): print(0) return bad = [] for i in range(0,m): if not is_good(["".join([k for b,k in enumerate(x) if b!=i]) for x in a],n,m): bad.append(i) for i in range(1,len(bad)+1): p = combinations(bad,i) for j in p: s = ["".join([k for b,k in enumerate(x) if b not in j]) for x in a] if is_good(s,n,m-i): print(i) return print(m) def main4(n,m,a): if n <= 1 or m<=0 or is_good(a,n,m): print(0) return bad = [] for i in range(0,m): if not is_good(["".join([k for b,k in enumerate(x) if b!=i]) for x in a],n,m): bad.append(i) p = [] for i in bad: p.append(i) s = ["".join([k for b,k in enumerate(x) if b not in p]) for x in a] if is_good(s,n,m-i): print(i) return print(m) def line_is_good(a,j): for i in range(len(a)-1): if a[i][j] > a[i+1][j]: return False return True def main(n,m,a): if n <= 1 or m<=0 or is_good(a,n,m): print(0) return bad = [] for i in range(0,m): if line_is_good(a,i): continue bad.append(i) print(i) s = ["".join([k for b,k in enumerate(x) if b not in bad]) for x in a] if is_good(s,n,m-len(bad)): print(len(bad)) return print(m) def main_input(): n,m = [int(i) for i in input().split()] a = [input() for s in range(n)] main(n,m,a) if __name__ == "__main__": main_input() ```
instruction
0
23,292
6
46,584
No
output
1
23,292
6
46,585
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the table abcd edfg hijk we obtain the table: acd efg hjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good. Input The first line contains two integers — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table. Output Print a single number — the minimum number of columns that you need to remove in order to make the table good. Examples Input 1 10 codeforces Output 0 Input 4 4 case care test code Output 2 Input 5 4 code forc esco defo rces Output 4 Note In the first sample the table is already good. In the second sample you may remove the first and third column. In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition). Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t. Submitted Solution: ``` from itertools import combinations, permutations def is_good(s,n,m): for i in range(n-1): if s[i] > s[i+1]: return False return True def main2(n,m,a): if n <= 0 or m<=0 or is_good(a,n,m): print(0) return for i in range(1,m): p = combinations(range(m),i) for j in p: s = ["".join([k for b,k in enumerate(x) if b not in j]) for x in a] if is_good(s,n,m-i): print(i) return print(m) def main(n,m,a): if n <= 0 or m<=0 or is_good(a,n,m): print(0) return bad = [] for i in range(0,m): if not is_good(["".join([k for b,k in enumerate(x) if b!=i]) for x in a],n,m): bad.append(i) for i in range(1,m): p = combinations(bad,i) for j in p: s = ["".join([k for b,k in enumerate(x) if b not in j]) for x in a] if is_good(s,n,m-i): print(i) return print(m) def main_input(): n,m = [int(i) for i in input().split()] a = [input() for s in range(n)] main(n,m,a) if __name__ == "__main__": main_input() ```
instruction
0
23,293
6
46,586
No
output
1
23,293
6
46,587
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp is working on a new operating system called BerOS. He asks you to help with implementation of a file suggestion feature. There are n files on hard drive and their names are f_1, f_2, ..., f_n. Any file name contains between 1 and 8 characters, inclusive. All file names are unique. The file suggestion feature handles queries, each represented by a string s. For each query s it should count number of files containing s as a substring (i.e. some continuous segment of characters in a file name equals s) and suggest any such file name. For example, if file names are "read.me", "hosts", "ops", and "beros.18", and the query is "os", the number of matched files is 2 (two file names contain "os" as a substring) and suggested file name can be either "hosts" or "beros.18". Input The first line of the input contains integer n (1 ≤ n ≤ 10000) — the total number of files. The following n lines contain file names, one per line. The i-th line contains f_i — the name of the i-th file. Each file name contains between 1 and 8 characters, inclusive. File names contain only lowercase Latin letters, digits and dot characters ('.'). Any sequence of valid characters can be a file name (for example, in BerOS ".", ".." and "..." are valid file names). All file names are unique. The following line contains integer q (1 ≤ q ≤ 50000) — the total number of queries. The following q lines contain queries s_1, s_2, ..., s_q, one per line. Each s_j has length between 1 and 8 characters, inclusive. It contains only lowercase Latin letters, digits and dot characters ('.'). Output Print q lines, one per query. The j-th line should contain the response on the j-th query — two values c_j and t_j, where * c_j is the number of matched files for the j-th query, * t_j is the name of any file matched by the j-th query. If there is no such file, print a single character '-' instead. If there are multiple matched files, print any. Example Input 4 test contests test. .test 6 ts . st. .test contes. st Output 1 contests 2 .test 1 test. 1 .test 0 - 4 test.
instruction
0
23,865
6
47,730
Tags: brute force, implementation Correct Solution: ``` import re import sys exit=sys.exit from bisect import bisect_left as bsl,bisect_right as bsr from collections import Counter,defaultdict as ddict,deque from functools import lru_cache cache=lru_cache(None) from heapq import * from itertools import * from math import inf from pprint import pprint as pp enum=enumerate ri=lambda:int(rln()) ris=lambda:list(map(int,rfs())) rln=sys.stdin.readline rl=lambda:rln().rstrip('\n') rfs=lambda:rln().split() mod=1000000007 d4=[(0,-1),(1,0),(0,1),(-1,0)] d8=[(-1,-1),(0,-1),(1,-1),(-1,0),(1,0),(-1,1),(0,1),(1,1)] ######################################################################## n=ri() d=ddict(lambda:[0,'']) for _ in range(n): s=rl() k=len(s) S=set() for i in range(k): for j in range(i,k): S.add(s[i:j+1]) for t in S: d[t][0]+=1 if d[t][0]==1: d[t][1]=s q=ri() for _ in range(q): s=rl() if s not in d: print(0,'-') continue print(*d[s]) ```
output
1
23,865
6
47,731
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp is working on a new operating system called BerOS. He asks you to help with implementation of a file suggestion feature. There are n files on hard drive and their names are f_1, f_2, ..., f_n. Any file name contains between 1 and 8 characters, inclusive. All file names are unique. The file suggestion feature handles queries, each represented by a string s. For each query s it should count number of files containing s as a substring (i.e. some continuous segment of characters in a file name equals s) and suggest any such file name. For example, if file names are "read.me", "hosts", "ops", and "beros.18", and the query is "os", the number of matched files is 2 (two file names contain "os" as a substring) and suggested file name can be either "hosts" or "beros.18". Input The first line of the input contains integer n (1 ≤ n ≤ 10000) — the total number of files. The following n lines contain file names, one per line. The i-th line contains f_i — the name of the i-th file. Each file name contains between 1 and 8 characters, inclusive. File names contain only lowercase Latin letters, digits and dot characters ('.'). Any sequence of valid characters can be a file name (for example, in BerOS ".", ".." and "..." are valid file names). All file names are unique. The following line contains integer q (1 ≤ q ≤ 50000) — the total number of queries. The following q lines contain queries s_1, s_2, ..., s_q, one per line. Each s_j has length between 1 and 8 characters, inclusive. It contains only lowercase Latin letters, digits and dot characters ('.'). Output Print q lines, one per query. The j-th line should contain the response on the j-th query — two values c_j and t_j, where * c_j is the number of matched files for the j-th query, * t_j is the name of any file matched by the j-th query. If there is no such file, print a single character '-' instead. If there are multiple matched files, print any. Example Input 4 test contests test. .test 6 ts . st. .test contes. st Output 1 contests 2 .test 1 test. 1 .test 0 - 4 test.
instruction
0
23,866
6
47,732
Tags: brute force, implementation Correct Solution: ``` # -*- coding:utf-8 -*- """ created by shuangquan.huang at 11/3/18 """ import collections N = int(input()) subs = collections.defaultdict(int) subi = collections.defaultdict(int) files = [] for fi in range(N): f = input() files.append(f) ss = set() for i in range(len(f)): for j in range(i+1, len(f)+1): s = f[i: j] ss.add(s) subi[s] = fi for s in ss: subs[s] += 1 Q = int(input()) qs = [input() for _ in range(Q)] ans = [] for s in qs: count = subs[s] af = files[subi[s]] if count > 0 else '-' ans.append('{} {}'.format(count, af)) print('\n'.join(ans)) ```
output
1
23,866
6
47,733
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp is working on a new operating system called BerOS. He asks you to help with implementation of a file suggestion feature. There are n files on hard drive and their names are f_1, f_2, ..., f_n. Any file name contains between 1 and 8 characters, inclusive. All file names are unique. The file suggestion feature handles queries, each represented by a string s. For each query s it should count number of files containing s as a substring (i.e. some continuous segment of characters in a file name equals s) and suggest any such file name. For example, if file names are "read.me", "hosts", "ops", and "beros.18", and the query is "os", the number of matched files is 2 (two file names contain "os" as a substring) and suggested file name can be either "hosts" or "beros.18". Input The first line of the input contains integer n (1 ≤ n ≤ 10000) — the total number of files. The following n lines contain file names, one per line. The i-th line contains f_i — the name of the i-th file. Each file name contains between 1 and 8 characters, inclusive. File names contain only lowercase Latin letters, digits and dot characters ('.'). Any sequence of valid characters can be a file name (for example, in BerOS ".", ".." and "..." are valid file names). All file names are unique. The following line contains integer q (1 ≤ q ≤ 50000) — the total number of queries. The following q lines contain queries s_1, s_2, ..., s_q, one per line. Each s_j has length between 1 and 8 characters, inclusive. It contains only lowercase Latin letters, digits and dot characters ('.'). Output Print q lines, one per query. The j-th line should contain the response on the j-th query — two values c_j and t_j, where * c_j is the number of matched files for the j-th query, * t_j is the name of any file matched by the j-th query. If there is no such file, print a single character '-' instead. If there are multiple matched files, print any. Example Input 4 test contests test. .test 6 ts . st. .test contes. st Output 1 contests 2 .test 1 test. 1 .test 0 - 4 test.
instruction
0
23,867
6
47,734
Tags: brute force, implementation Correct Solution: ``` def func1(s,i,index,dict1): if(i==len(s)): return sx='' for j in range(i,len(s)): sx+=s[j] try: if(dict1[sx][1]!=index): dict1[sx][0]+=1 dict1[sx][1]=index except: KeyError dict1[sx]=[1,index] func1(s,i+1,index,dict1) return n=int(input()) arr=[] dict1={} for i in range(n): s=str(input()) arr.append(s) func1(s,0,i,dict1) q=int(input()) for i in range(q): s=str(input()) #print(dict1['ts']) try: val1=dict1[s][0] val2=arr[dict1[s][1]] print(val1,val2) except: KeyError print(0,'-') ```
output
1
23,867
6
47,735
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp is working on a new operating system called BerOS. He asks you to help with implementation of a file suggestion feature. There are n files on hard drive and their names are f_1, f_2, ..., f_n. Any file name contains between 1 and 8 characters, inclusive. All file names are unique. The file suggestion feature handles queries, each represented by a string s. For each query s it should count number of files containing s as a substring (i.e. some continuous segment of characters in a file name equals s) and suggest any such file name. For example, if file names are "read.me", "hosts", "ops", and "beros.18", and the query is "os", the number of matched files is 2 (two file names contain "os" as a substring) and suggested file name can be either "hosts" or "beros.18". Input The first line of the input contains integer n (1 ≤ n ≤ 10000) — the total number of files. The following n lines contain file names, one per line. The i-th line contains f_i — the name of the i-th file. Each file name contains between 1 and 8 characters, inclusive. File names contain only lowercase Latin letters, digits and dot characters ('.'). Any sequence of valid characters can be a file name (for example, in BerOS ".", ".." and "..." are valid file names). All file names are unique. The following line contains integer q (1 ≤ q ≤ 50000) — the total number of queries. The following q lines contain queries s_1, s_2, ..., s_q, one per line. Each s_j has length between 1 and 8 characters, inclusive. It contains only lowercase Latin letters, digits and dot characters ('.'). Output Print q lines, one per query. The j-th line should contain the response on the j-th query — two values c_j and t_j, where * c_j is the number of matched files for the j-th query, * t_j is the name of any file matched by the j-th query. If there is no such file, print a single character '-' instead. If there are multiple matched files, print any. Example Input 4 test contests test. .test 6 ts . st. .test contes. st Output 1 contests 2 .test 1 test. 1 .test 0 - 4 test.
instruction
0
23,868
6
47,736
Tags: brute force, implementation Correct Solution: ``` ## necessary imports import sys input = sys.stdin.readline from math import ceil, floor, factorial; # swap_array function def swaparr(arr, a,b): temp = arr[a]; arr[a] = arr[b]; arr[b] = temp ## gcd function def gcd(a,b): if a == 0: return b return gcd(b%a, a) ## nCr function efficient using Binomial Cofficient def nCr(n, k): if(k > n - k): k = n - k res = 1 for i in range(k): res = res * (n - i) res = res / (i + 1) return int(res) ## upper bound function code -- such that e in a[:i] e < x; def upper_bound(a, x, lo=0): hi = len(a) while lo < hi: mid = (lo+hi)//2 if a[mid] < x: lo = mid+1 else: hi = mid return lo ## prime factorization def primefs(n): ## if n == 1 ## calculating primes primes = {} while(n%2 == 0): primes[2] = primes.get(2, 0) + 1 n = n//2 for i in range(3, int(n**0.5)+2, 2): while(n%i == 0): primes[i] = primes.get(i, 0) + 1 n = n//i if n > 2: primes[n] = primes.get(n, 0) + 1 ## prime factoriazation of n is stored in dictionary ## primes and can be accesed. O(sqrt n) return primes ## MODULAR EXPONENTIATION FUNCTION def power(x, y, p): res = 1 x = x % p if (x == 0) : return 0 while (y > 0) : if ((y & 1) == 1) : res = (res * x) % p y = y >> 1 x = (x * x) % p return res ## DISJOINT SET UNINON FUNCTIONS def swap(a,b): temp = a a = b b = temp return a,b # find function with path compression included (recursive) # def find(x, link): # if link[x] == x: # return x # link[x] = find(link[x], link); # return link[x]; # find function with path compression (ITERATIVE) def find(x, link): p = x; while( p != link[p]): p = link[p]; while( x != p): nex = link[x]; link[x] = p; x = nex; return p; # the union function which makes union(x,y) # of two nodes x and y def union(x, y, link, size): x = find(x, link) y = find(y, link) if size[x] < size[y]: x,y = swap(x,y) if x != y: size[x] += size[y] link[y] = x ## returns an array of boolean if primes or not USING SIEVE OF ERATOSTHANES def sieve(n): prime = [True for i in range(n+1)] p = 2 while (p * p <= n): if (prime[p] == True): for i in range(p * p, n+1, p): prime[i] = False p += 1 return prime #### PRIME FACTORIZATION IN O(log n) using Sieve #### MAXN = int(1e6 + 5) def spf_sieve(): spf[1] = 1; for i in range(2, MAXN): spf[i] = i; for i in range(4, MAXN, 2): spf[i] = 2; for i in range(3, ceil(MAXN ** 0.5), 2): if spf[i] == i: for j in range(i*i, MAXN, i): if spf[j] == j: spf[j] = i; ## function for storing smallest prime factors (spf) in the array ################## un-comment below 2 lines when using factorization ################# # spf = [0 for i in range(MAXN)] # spf_sieve() def factoriazation(x): ret = {}; while x != 1: ret[spf[x]] = ret.get(spf[x], 0) + 1; x = x//spf[x] return ret ## this function is useful for multiple queries only, o/w use ## primefs function above. complexity O(log n) ## taking integer array input def int_array(): return list(map(int, input().strip().split())) ## taking string array input def str_array(): return input().strip().split(); #defining a couple constants MOD = int(1e9)+7; CMOD = 998244353; INF = float('inf'); NINF = -float('inf'); ################### ---------------- TEMPLATE ENDS HERE ---------------- ################### count = {}; dick = {}; n = int(input()); for __ in range(n): s = input().strip(); this = set(); for i in range(len(s)): x = ''; for j in range(i, len(s)): x += s[j]; if x in this: continue; this.add(x); dick[x] = s; count[x] = count.get(x, 0) + 1; q = int(input()); for __ in range(q): s = input().strip(); if s in dick: x = count[s]; y = dick[s]; else: x = 0; y = '-'; print(*(x, y)); ```
output
1
23,868
6
47,737
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp is working on a new operating system called BerOS. He asks you to help with implementation of a file suggestion feature. There are n files on hard drive and their names are f_1, f_2, ..., f_n. Any file name contains between 1 and 8 characters, inclusive. All file names are unique. The file suggestion feature handles queries, each represented by a string s. For each query s it should count number of files containing s as a substring (i.e. some continuous segment of characters in a file name equals s) and suggest any such file name. For example, if file names are "read.me", "hosts", "ops", and "beros.18", and the query is "os", the number of matched files is 2 (two file names contain "os" as a substring) and suggested file name can be either "hosts" or "beros.18". Input The first line of the input contains integer n (1 ≤ n ≤ 10000) — the total number of files. The following n lines contain file names, one per line. The i-th line contains f_i — the name of the i-th file. Each file name contains between 1 and 8 characters, inclusive. File names contain only lowercase Latin letters, digits and dot characters ('.'). Any sequence of valid characters can be a file name (for example, in BerOS ".", ".." and "..." are valid file names). All file names are unique. The following line contains integer q (1 ≤ q ≤ 50000) — the total number of queries. The following q lines contain queries s_1, s_2, ..., s_q, one per line. Each s_j has length between 1 and 8 characters, inclusive. It contains only lowercase Latin letters, digits and dot characters ('.'). Output Print q lines, one per query. The j-th line should contain the response on the j-th query — two values c_j and t_j, where * c_j is the number of matched files for the j-th query, * t_j is the name of any file matched by the j-th query. If there is no such file, print a single character '-' instead. If there are multiple matched files, print any. Example Input 4 test contests test. .test 6 ts . st. .test contes. st Output 1 contests 2 .test 1 test. 1 .test 0 - 4 test.
instruction
0
23,869
6
47,738
Tags: brute force, implementation Correct Solution: ``` if __name__ == "__main__": Map = {} siz = {} n = int(input()) for i in range(n): str = input() MMap = {} for j in range(0,len(str)): t = "" for k in range(j,len(str)): t += str[k] MMap[t] = 1 for x in MMap: if not x in Map: Map[x] = str siz[x] = 0 siz[x] +=1 #for x in Map: #print(x,Map[x]) q = int(input()) for i in range(q): str = input() if str in Map: print(siz[str], Map[str]) else: print("0 -") ```
output
1
23,869
6
47,739
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp is working on a new operating system called BerOS. He asks you to help with implementation of a file suggestion feature. There are n files on hard drive and their names are f_1, f_2, ..., f_n. Any file name contains between 1 and 8 characters, inclusive. All file names are unique. The file suggestion feature handles queries, each represented by a string s. For each query s it should count number of files containing s as a substring (i.e. some continuous segment of characters in a file name equals s) and suggest any such file name. For example, if file names are "read.me", "hosts", "ops", and "beros.18", and the query is "os", the number of matched files is 2 (two file names contain "os" as a substring) and suggested file name can be either "hosts" or "beros.18". Input The first line of the input contains integer n (1 ≤ n ≤ 10000) — the total number of files. The following n lines contain file names, one per line. The i-th line contains f_i — the name of the i-th file. Each file name contains between 1 and 8 characters, inclusive. File names contain only lowercase Latin letters, digits and dot characters ('.'). Any sequence of valid characters can be a file name (for example, in BerOS ".", ".." and "..." are valid file names). All file names are unique. The following line contains integer q (1 ≤ q ≤ 50000) — the total number of queries. The following q lines contain queries s_1, s_2, ..., s_q, one per line. Each s_j has length between 1 and 8 characters, inclusive. It contains only lowercase Latin letters, digits and dot characters ('.'). Output Print q lines, one per query. The j-th line should contain the response on the j-th query — two values c_j and t_j, where * c_j is the number of matched files for the j-th query, * t_j is the name of any file matched by the j-th query. If there is no such file, print a single character '-' instead. If there are multiple matched files, print any. Example Input 4 test contests test. .test 6 ts . st. .test contes. st Output 1 contests 2 .test 1 test. 1 .test 0 - 4 test.
instruction
0
23,870
6
47,740
Tags: brute force, implementation Correct Solution: ``` ################### # 18th August 2019. ################### ########################################################################## # Getting fileCount from Codeforces. fileCount = int(input()) # Method to generate all substrings of given string. from itertools import combinations as cmb def generateSubstringsFor(string): length = len(string) + 1 return [string[x:y] for x, y in cmb(range(length), r=2)] # HashMap mapping substrings to set of containing strings. stringMap = {} for i in range(fileCount): newFile = input() # Generating entry for new file. for string in generateSubstringsFor(newFile): # Case Set has been created. if not string in stringMap: stringMap[string] = set([newFile]) # Case First Entry. else: stringMap[string].add(newFile) # Method to entertain a single query. def outputForQuery(query): if query in stringMap: return str(len(stringMap[query]))+" "+next(iter(stringMap[query])) else: return "0 - " # We now entertain all requests from Codeforces. queryCount = int(input()) for i in range(queryCount): print(outputForQuery(input())) ########################################################################## ######################################## # Programming-Credits atifcppprogrammer. ######################################## ```
output
1
23,870
6
47,741
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp is working on a new operating system called BerOS. He asks you to help with implementation of a file suggestion feature. There are n files on hard drive and their names are f_1, f_2, ..., f_n. Any file name contains between 1 and 8 characters, inclusive. All file names are unique. The file suggestion feature handles queries, each represented by a string s. For each query s it should count number of files containing s as a substring (i.e. some continuous segment of characters in a file name equals s) and suggest any such file name. For example, if file names are "read.me", "hosts", "ops", and "beros.18", and the query is "os", the number of matched files is 2 (two file names contain "os" as a substring) and suggested file name can be either "hosts" or "beros.18". Input The first line of the input contains integer n (1 ≤ n ≤ 10000) — the total number of files. The following n lines contain file names, one per line. The i-th line contains f_i — the name of the i-th file. Each file name contains between 1 and 8 characters, inclusive. File names contain only lowercase Latin letters, digits and dot characters ('.'). Any sequence of valid characters can be a file name (for example, in BerOS ".", ".." and "..." are valid file names). All file names are unique. The following line contains integer q (1 ≤ q ≤ 50000) — the total number of queries. The following q lines contain queries s_1, s_2, ..., s_q, one per line. Each s_j has length between 1 and 8 characters, inclusive. It contains only lowercase Latin letters, digits and dot characters ('.'). Output Print q lines, one per query. The j-th line should contain the response on the j-th query — two values c_j and t_j, where * c_j is the number of matched files for the j-th query, * t_j is the name of any file matched by the j-th query. If there is no such file, print a single character '-' instead. If there are multiple matched files, print any. Example Input 4 test contests test. .test 6 ts . st. .test contes. st Output 1 contests 2 .test 1 test. 1 .test 0 - 4 test.
instruction
0
23,871
6
47,742
Tags: brute force, implementation Correct Solution: ``` from collections import defaultdict N = int(input()) F = [] for i in range(N): F.append(input()) dic = defaultdict(set) for i in range(N): t = F[i] M = len(t) for j in range(M): for k in range(j + 1, M + 1): dic[t[j: k]].add(F[i]) Q = int(input()) for i in range(Q): s = input() if s in dic: print(len(dic[s]), list(dic[s])[0]) else: print("0 -") ```
output
1
23,871
6
47,743
Provide tags and a correct Python 3 solution for this coding contest problem. Polycarp is working on a new operating system called BerOS. He asks you to help with implementation of a file suggestion feature. There are n files on hard drive and their names are f_1, f_2, ..., f_n. Any file name contains between 1 and 8 characters, inclusive. All file names are unique. The file suggestion feature handles queries, each represented by a string s. For each query s it should count number of files containing s as a substring (i.e. some continuous segment of characters in a file name equals s) and suggest any such file name. For example, if file names are "read.me", "hosts", "ops", and "beros.18", and the query is "os", the number of matched files is 2 (two file names contain "os" as a substring) and suggested file name can be either "hosts" or "beros.18". Input The first line of the input contains integer n (1 ≤ n ≤ 10000) — the total number of files. The following n lines contain file names, one per line. The i-th line contains f_i — the name of the i-th file. Each file name contains between 1 and 8 characters, inclusive. File names contain only lowercase Latin letters, digits and dot characters ('.'). Any sequence of valid characters can be a file name (for example, in BerOS ".", ".." and "..." are valid file names). All file names are unique. The following line contains integer q (1 ≤ q ≤ 50000) — the total number of queries. The following q lines contain queries s_1, s_2, ..., s_q, one per line. Each s_j has length between 1 and 8 characters, inclusive. It contains only lowercase Latin letters, digits and dot characters ('.'). Output Print q lines, one per query. The j-th line should contain the response on the j-th query — two values c_j and t_j, where * c_j is the number of matched files for the j-th query, * t_j is the name of any file matched by the j-th query. If there is no such file, print a single character '-' instead. If there are multiple matched files, print any. Example Input 4 test contests test. .test 6 ts . st. .test contes. st Output 1 contests 2 .test 1 test. 1 .test 0 - 4 test.
instruction
0
23,872
6
47,744
Tags: brute force, implementation Correct Solution: ``` # https://codeforces.com/problemset/problem/1070/H from sys import stdin, exit from typing import List, Tuple sub_strings = dict() files_num = int(stdin.readline().rstrip()) for _id in range(files_num): f_name = stdin.readline().rstrip() for i in range(len(f_name)): for j in range(i + 1, len(f_name) + 1): key = f_name[i:j] if key not in sub_strings: sub_strings[key] = [1, f_name, _id] else: rez = sub_strings[key] if rez[2] != _id: rez[2] = _id sub_strings[key][0] += 1 queries = int(stdin.readline().rstrip()) for _ in range(queries): query = stdin.readline().rstrip() if query in sub_strings: rez = sub_strings[query] print(rez[0], ' ', rez[1]) else: print(0, ' ', '-') ```
output
1
23,872
6
47,745
Provide tags and a correct Python 3 solution for this coding contest problem. In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 — AB, column 52 is marked by AZ. After ZZ there follow three-letter numbers, etc. The rows are marked by integer numbers starting with 1. The cell name is the concatenation of the column and the row numbers. For example, BC23 is the name for the cell that is in column 55, row 23. Sometimes another numeration system is used: RXCY, where X and Y are integer numbers, showing the column and the row numbers respectfully. For instance, R23C55 is the cell from the previous example. Your task is to write a program that reads the given sequence of cell coordinates and produce each item written according to the rules of another numeration system. Input The first line of the input contains integer number n (1 ≤ n ≤ 105), the number of coordinates in the test. Then there follow n lines, each of them contains coordinates. All the coordinates are correct, there are no cells with the column and/or the row numbers larger than 106 . Output Write n lines, each line should contain a cell coordinates in the other numeration system. Examples Input 2 R23C55 BC23 Output BC23 R23C55
instruction
0
24,081
6
48,162
Tags: implementation, math Correct Solution: ``` import string import re alphabet=string.ascii_uppercase n=input() n=int(n) def numer1(inp): inp=inp.replace("R","") inp=inp.replace("C"," ") row,column=inp.split(" ",1) column=int(column) columnalpha=[] over=False while not over: a=(column-1)//26 b=column-a*26 if b==0: b=26 column=a columnalpha.insert(0,alphabet[b-1]) if column==0: over=True print("".join(columnalpha)+row) def numer2(inp): row="".join(list(filter(str.isdigit,inp))) columnalpha=list(filter(str.isalpha,inp)) column=0 for i in range(0,len(columnalpha)): column+=(alphabet.index(columnalpha[i])+1)*26**(len(columnalpha)-1-i) column=str(column) print("R"+row+"C"+column) for i in range(0,n): inp=input() numertypeR=len(re.findall(r"R"+"\d",inp)) numertypeC=len(re.findall(r"C"+"\d",inp)) if numertypeR==1 and numertypeC==1: numer1(inp) else: numer2(inp) ```
output
1
24,081
6
48,163
Provide tags and a correct Python 3 solution for this coding contest problem. Email address in Berland is a string of the form A@B, where A and B are arbitrary strings consisting of small Latin letters. Bob is a system administrator in «Bersoft» company. He keeps a list of email addresses of the company's staff. This list is as a large string, where all addresses are written in arbitrary order, separated by commas. The same address can be written more than once. Suddenly, because of unknown reasons, all commas in Bob's list disappeared. Now Bob has a string, where all addresses are written one after another without any separators, and there is impossible to determine, where the boundaries between addresses are. Unfortunately, on the same day his chief asked him to bring the initial list of addresses. Now Bob wants to disjoin addresses in some valid way. Help him to do that. Input The first line contains the list of addresses without separators. The length of this string is between 1 and 200, inclusive. The string consists only from small Latin letters and characters «@». Output If there is no list of the valid (according to the Berland rules) email addresses such that after removing all commas it coincides with the given string, output No solution. In the other case, output the list. The same address can be written in this list more than once. If there are several solutions, output any of them. Examples Input a@aa@a Output a@a,a@a Input a@a@a Output No solution Input @aa@a Output No solution
instruction
0
24,136
6
48,272
Tags: greedy, implementation, strings Correct Solution: ``` s=input() au=[pos for pos,char in enumerate(s) if char=='@'] dis=[au[i+1]-au[i] for i in range(len(au)-1)] dis=[1 for i in dis if i<=2] if len(au)==0 or au[0]==0 or au[-1]==len(s)-1 or sum(dis)>0: print("No solution") else: if len(au)==1: print(s) else: res=[] i=0 j=0 m=au[j]+2 while j<len(au): res.append(s[i:m]) i=m if i>len(s): break j+=1 if j==len(au)-1: m=len(s)+1 else: m=au[j]+2 print(*res,sep=",") ```
output
1
24,136
6
48,273
Provide tags and a correct Python 3 solution for this coding contest problem. Email address in Berland is a string of the form A@B, where A and B are arbitrary strings consisting of small Latin letters. Bob is a system administrator in «Bersoft» company. He keeps a list of email addresses of the company's staff. This list is as a large string, where all addresses are written in arbitrary order, separated by commas. The same address can be written more than once. Suddenly, because of unknown reasons, all commas in Bob's list disappeared. Now Bob has a string, where all addresses are written one after another without any separators, and there is impossible to determine, where the boundaries between addresses are. Unfortunately, on the same day his chief asked him to bring the initial list of addresses. Now Bob wants to disjoin addresses in some valid way. Help him to do that. Input The first line contains the list of addresses without separators. The length of this string is between 1 and 200, inclusive. The string consists only from small Latin letters and characters «@». Output If there is no list of the valid (according to the Berland rules) email addresses such that after removing all commas it coincides with the given string, output No solution. In the other case, output the list. The same address can be written in this list more than once. If there are several solutions, output any of them. Examples Input a@aa@a Output a@a,a@a Input a@a@a Output No solution Input @aa@a Output No solution
instruction
0
24,137
6
48,274
Tags: greedy, implementation, strings Correct Solution: ``` #amros s=input() t=[] k=0 y=1 while 1: a=s.find('@',k+1) if a<0:break r=s[k:a+2] if r.count('@')==0 or r[0]=='@'or r[-1]=='@':y=0 t+=[r];k=a+2 if t and s[k:].count('@')==0:t[-1]+=s[k:] p='' for i in t:p+=i print(['No solution',','.join(t)][p==s and y]) ```
output
1
24,137
6
48,275
Provide tags and a correct Python 3 solution for this coding contest problem. Email address in Berland is a string of the form A@B, where A and B are arbitrary strings consisting of small Latin letters. Bob is a system administrator in «Bersoft» company. He keeps a list of email addresses of the company's staff. This list is as a large string, where all addresses are written in arbitrary order, separated by commas. The same address can be written more than once. Suddenly, because of unknown reasons, all commas in Bob's list disappeared. Now Bob has a string, where all addresses are written one after another without any separators, and there is impossible to determine, where the boundaries between addresses are. Unfortunately, on the same day his chief asked him to bring the initial list of addresses. Now Bob wants to disjoin addresses in some valid way. Help him to do that. Input The first line contains the list of addresses without separators. The length of this string is between 1 and 200, inclusive. The string consists only from small Latin letters and characters «@». Output If there is no list of the valid (according to the Berland rules) email addresses such that after removing all commas it coincides with the given string, output No solution. In the other case, output the list. The same address can be written in this list more than once. If there are several solutions, output any of them. Examples Input a@aa@a Output a@a,a@a Input a@a@a Output No solution Input @aa@a Output No solution
instruction
0
24,138
6
48,276
Tags: greedy, implementation, strings Correct Solution: ``` from sys import stdout a=input() c=list(a.split('@')) while '' in c: c.remove('') if a.count('@')==0: exit(print('No solution')) if a.count('@')!=len(c)-1: exit(print('No solution')) if any(len(i)==1 for i in c[1:len(c)-1]): exit(print('No solution')) stdout.write(c[0]+'@') for i in range(1,len(c)-1): stdout.write(c[i][:len(c[i])//2]+','+c[i][len(c[i])//2:]+'@') stdout.write(c[-1]) ```
output
1
24,138
6
48,277
Provide tags and a correct Python 3 solution for this coding contest problem. Email address in Berland is a string of the form A@B, where A and B are arbitrary strings consisting of small Latin letters. Bob is a system administrator in «Bersoft» company. He keeps a list of email addresses of the company's staff. This list is as a large string, where all addresses are written in arbitrary order, separated by commas. The same address can be written more than once. Suddenly, because of unknown reasons, all commas in Bob's list disappeared. Now Bob has a string, where all addresses are written one after another without any separators, and there is impossible to determine, where the boundaries between addresses are. Unfortunately, on the same day his chief asked him to bring the initial list of addresses. Now Bob wants to disjoin addresses in some valid way. Help him to do that. Input The first line contains the list of addresses without separators. The length of this string is between 1 and 200, inclusive. The string consists only from small Latin letters and characters «@». Output If there is no list of the valid (according to the Berland rules) email addresses such that after removing all commas it coincides with the given string, output No solution. In the other case, output the list. The same address can be written in this list more than once. If there are several solutions, output any of them. Examples Input a@aa@a Output a@a,a@a Input a@a@a Output No solution Input @aa@a Output No solution
instruction
0
24,139
6
48,278
Tags: greedy, implementation, strings Correct Solution: ``` a=input().split('@') n=len(a) b=[] if n>=2: for i in range(n): if len(a[i])>int(i!=0 and i!=n-1): if i!=0 and i!=n-1: b.append(a[i-1][min(1,i-1):]+'@'+a[i][0]) elif i==n-1: b.append(a[i-1][min(1,i-1):]+'@'+a[i]) else: print('No solution') break else: c=b[0] for i in range(1,len(b)): c+=','+b[i] print(c) else: print('No solution') ```
output
1
24,139
6
48,279
Provide tags and a correct Python 3 solution for this coding contest problem. Email address in Berland is a string of the form A@B, where A and B are arbitrary strings consisting of small Latin letters. Bob is a system administrator in «Bersoft» company. He keeps a list of email addresses of the company's staff. This list is as a large string, where all addresses are written in arbitrary order, separated by commas. The same address can be written more than once. Suddenly, because of unknown reasons, all commas in Bob's list disappeared. Now Bob has a string, where all addresses are written one after another without any separators, and there is impossible to determine, where the boundaries between addresses are. Unfortunately, on the same day his chief asked him to bring the initial list of addresses. Now Bob wants to disjoin addresses in some valid way. Help him to do that. Input The first line contains the list of addresses without separators. The length of this string is between 1 and 200, inclusive. The string consists only from small Latin letters and characters «@». Output If there is no list of the valid (according to the Berland rules) email addresses such that after removing all commas it coincides with the given string, output No solution. In the other case, output the list. The same address can be written in this list more than once. If there are several solutions, output any of them. Examples Input a@aa@a Output a@a,a@a Input a@a@a Output No solution Input @aa@a Output No solution
instruction
0
24,140
6
48,280
Tags: greedy, implementation, strings Correct Solution: ``` a = input() b = a.split("@") ans = [] flag = True for i in b[1:-1]: if len(i) < 2: flag = False break if len(b) < 2: flag = False if b[0] and b[-1] and flag: ind = 0 index_list = [] str_len = len(a) temp = "" j = 0 ans = [] while j != str_len: temp += a[j] if a[j] == "@": temp += a[j + 1] ans.append(temp) temp = "" j += 1 j += 1 ans[-1] = ans[-1] + temp print(",".join(ans)) else: print("No solution") ```
output
1
24,140
6
48,281
Provide tags and a correct Python 3 solution for this coding contest problem. Email address in Berland is a string of the form A@B, where A and B are arbitrary strings consisting of small Latin letters. Bob is a system administrator in «Bersoft» company. He keeps a list of email addresses of the company's staff. This list is as a large string, where all addresses are written in arbitrary order, separated by commas. The same address can be written more than once. Suddenly, because of unknown reasons, all commas in Bob's list disappeared. Now Bob has a string, where all addresses are written one after another without any separators, and there is impossible to determine, where the boundaries between addresses are. Unfortunately, on the same day his chief asked him to bring the initial list of addresses. Now Bob wants to disjoin addresses in some valid way. Help him to do that. Input The first line contains the list of addresses without separators. The length of this string is between 1 and 200, inclusive. The string consists only from small Latin letters and characters «@». Output If there is no list of the valid (according to the Berland rules) email addresses such that after removing all commas it coincides with the given string, output No solution. In the other case, output the list. The same address can be written in this list more than once. If there are several solutions, output any of them. Examples Input a@aa@a Output a@a,a@a Input a@a@a Output No solution Input @aa@a Output No solution
instruction
0
24,141
6
48,282
Tags: greedy, implementation, strings Correct Solution: ``` import sys from array import array # noqa: F401 def input(): return sys.stdin.buffer.readline().decode('utf-8') s = input().rstrip() ans = [] while s and s[0] != '@': for i in range(len(s) - 1): if s[i] == '@': ans.append(s[:i + 2]) s = s[i + 2:] break else: break if s and '@' not in s and ans: ans[-1] += s s = '' if not s and all(addr.count('@') == 1 for addr in ans): print(','.join(ans)) else: print('No solution') ```
output
1
24,141
6
48,283
Provide tags and a correct Python 3 solution for this coding contest problem. Email address in Berland is a string of the form A@B, where A and B are arbitrary strings consisting of small Latin letters. Bob is a system administrator in «Bersoft» company. He keeps a list of email addresses of the company's staff. This list is as a large string, where all addresses are written in arbitrary order, separated by commas. The same address can be written more than once. Suddenly, because of unknown reasons, all commas in Bob's list disappeared. Now Bob has a string, where all addresses are written one after another without any separators, and there is impossible to determine, where the boundaries between addresses are. Unfortunately, on the same day his chief asked him to bring the initial list of addresses. Now Bob wants to disjoin addresses in some valid way. Help him to do that. Input The first line contains the list of addresses without separators. The length of this string is between 1 and 200, inclusive. The string consists only from small Latin letters and characters «@». Output If there is no list of the valid (according to the Berland rules) email addresses such that after removing all commas it coincides with the given string, output No solution. In the other case, output the list. The same address can be written in this list more than once. If there are several solutions, output any of them. Examples Input a@aa@a Output a@a,a@a Input a@a@a Output No solution Input @aa@a Output No solution
instruction
0
24,142
6
48,284
Tags: greedy, implementation, strings Correct Solution: ``` def cf31B(): #print("Hello World") from sys import stdin,stdout inp = list(stdin.readline().strip().split('@')) flag = True if len(inp)>=2: if len(inp[0])==0 or len(inp[-1])==0: flag = False if flag: for i in range(1,len(inp)-1): if len(inp[i]) < 2: flag = False break else: flag = False answer = "" if flag: for i , j in enumerate(inp): if i==0: answer+=j elif i==len(inp)-1: answer+='@'+j else: answer+='@'+j[:-1]+','+j[-1] else: answer = "No solution" stdout.write(answer+"\n") if __name__=='__main__': cf31B() ```
output
1
24,142
6
48,285
Provide tags and a correct Python 3 solution for this coding contest problem. Email address in Berland is a string of the form A@B, where A and B are arbitrary strings consisting of small Latin letters. Bob is a system administrator in «Bersoft» company. He keeps a list of email addresses of the company's staff. This list is as a large string, where all addresses are written in arbitrary order, separated by commas. The same address can be written more than once. Suddenly, because of unknown reasons, all commas in Bob's list disappeared. Now Bob has a string, where all addresses are written one after another without any separators, and there is impossible to determine, where the boundaries between addresses are. Unfortunately, on the same day his chief asked him to bring the initial list of addresses. Now Bob wants to disjoin addresses in some valid way. Help him to do that. Input The first line contains the list of addresses without separators. The length of this string is between 1 and 200, inclusive. The string consists only from small Latin letters and characters «@». Output If there is no list of the valid (according to the Berland rules) email addresses such that after removing all commas it coincides with the given string, output No solution. In the other case, output the list. The same address can be written in this list more than once. If there are several solutions, output any of them. Examples Input a@aa@a Output a@a,a@a Input a@a@a Output No solution Input @aa@a Output No solution
instruction
0
24,143
6
48,286
Tags: greedy, implementation, strings Correct Solution: ``` s=input() n=len(s) ans=[] x='' c=0 for i in range(n): if i!=n-1: if s[i+1]!='@': x=x+s[i] else: if c==0: x=x+s[i] c=1 else: ans.append(x) x='' x=x+s[i] c=1 else: x=x+s[i] ans.append(x) f=0 for i in range(len(ans)): if ans[i][0]=='@' or ans[i][-1]=='@' or '@' not in ans[i]: f=1 break if f: print('No solution') else: for i in range(len(ans)-1): print(ans[i]+',',end='') print(ans[-1]) ```
output
1
24,143
6
48,287
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Email address in Berland is a string of the form A@B, where A and B are arbitrary strings consisting of small Latin letters. Bob is a system administrator in «Bersoft» company. He keeps a list of email addresses of the company's staff. This list is as a large string, where all addresses are written in arbitrary order, separated by commas. The same address can be written more than once. Suddenly, because of unknown reasons, all commas in Bob's list disappeared. Now Bob has a string, where all addresses are written one after another without any separators, and there is impossible to determine, where the boundaries between addresses are. Unfortunately, on the same day his chief asked him to bring the initial list of addresses. Now Bob wants to disjoin addresses in some valid way. Help him to do that. Input The first line contains the list of addresses without separators. The length of this string is between 1 and 200, inclusive. The string consists only from small Latin letters and characters «@». Output If there is no list of the valid (according to the Berland rules) email addresses such that after removing all commas it coincides with the given string, output No solution. In the other case, output the list. The same address can be written in this list more than once. If there are several solutions, output any of them. Examples Input a@aa@a Output a@a,a@a Input a@a@a Output No solution Input @aa@a Output No solution Submitted Solution: ``` import sys def input(): return sys.stdin.readline().strip() def iinput(): return int(input()) def rinput(): return map(int, sys.stdin.readline().strip().split()) def get_list(): return list(map(int, sys.stdin.readline().strip().split())) mod = int(1e9)+7 s = input() l = len(s) ans = [] prev = -1 flag = True tot = s.count("@") cnt = 0 if (s[0]=="@" or s[l-1]=="@" or tot==0): print("No solution") sys.exit(0) for i in range(l): if s[i]=="@": bef = s[prev+1:i] aft = s[i+1:] if "@" in aft: aft = aft[:aft.index("@")] if (len(ans)>0 and len(bef)<1) or len(aft)==0: flag = False break if cnt!=tot-1: ans.append(bef+"@"+aft[0]) else: ans.append(bef+"@"+aft) prev = i+1 cnt+=1 # print(bef, aft) if flag == False: print("No solution") else: print(*ans, sep=",") ```
instruction
0
24,144
6
48,288
Yes
output
1
24,144
6
48,289
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Email address in Berland is a string of the form A@B, where A and B are arbitrary strings consisting of small Latin letters. Bob is a system administrator in «Bersoft» company. He keeps a list of email addresses of the company's staff. This list is as a large string, where all addresses are written in arbitrary order, separated by commas. The same address can be written more than once. Suddenly, because of unknown reasons, all commas in Bob's list disappeared. Now Bob has a string, where all addresses are written one after another without any separators, and there is impossible to determine, where the boundaries between addresses are. Unfortunately, on the same day his chief asked him to bring the initial list of addresses. Now Bob wants to disjoin addresses in some valid way. Help him to do that. Input The first line contains the list of addresses without separators. The length of this string is between 1 and 200, inclusive. The string consists only from small Latin letters and characters «@». Output If there is no list of the valid (according to the Berland rules) email addresses such that after removing all commas it coincides with the given string, output No solution. In the other case, output the list. The same address can be written in this list more than once. If there are several solutions, output any of them. Examples Input a@aa@a Output a@a,a@a Input a@a@a Output No solution Input @aa@a Output No solution Submitted Solution: ``` def solution(): s = input() if '@' not in s: return "No solution" mas = s.split('@') if len(mas[0]) < 1 or len(mas[-1]) < 1: return "No solution" front = mas[0] back = mas[-1] mas = mas[1:len(mas) - 1] for i in range(len(mas)): if len(mas[i]) < 2: return "No solution" else: mas[i] = mas[i][:len(mas[i]) // 2] + ',' + mas[i][len(mas[i]) // 2:] return '@'.join([front] + mas + [back]) print(solution()) ```
instruction
0
24,145
6
48,290
Yes
output
1
24,145
6
48,291
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Email address in Berland is a string of the form A@B, where A and B are arbitrary strings consisting of small Latin letters. Bob is a system administrator in «Bersoft» company. He keeps a list of email addresses of the company's staff. This list is as a large string, where all addresses are written in arbitrary order, separated by commas. The same address can be written more than once. Suddenly, because of unknown reasons, all commas in Bob's list disappeared. Now Bob has a string, where all addresses are written one after another without any separators, and there is impossible to determine, where the boundaries between addresses are. Unfortunately, on the same day his chief asked him to bring the initial list of addresses. Now Bob wants to disjoin addresses in some valid way. Help him to do that. Input The first line contains the list of addresses without separators. The length of this string is between 1 and 200, inclusive. The string consists only from small Latin letters and characters «@». Output If there is no list of the valid (according to the Berland rules) email addresses such that after removing all commas it coincides with the given string, output No solution. In the other case, output the list. The same address can be written in this list more than once. If there are several solutions, output any of them. Examples Input a@aa@a Output a@a,a@a Input a@a@a Output No solution Input @aa@a Output No solution Submitted Solution: ``` s = input().split('@') if len(s) > 1 and s[0] and s[-1] and min(map(len, s[1:-1] + ['__'])) > 1: for i in range(1, len(s) - 1): s[i] = s[i][0] + ',' + s[i][1:] print('@'.join(s)) else: print('No solution') ```
instruction
0
24,146
6
48,292
Yes
output
1
24,146
6
48,293
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Email address in Berland is a string of the form A@B, where A and B are arbitrary strings consisting of small Latin letters. Bob is a system administrator in «Bersoft» company. He keeps a list of email addresses of the company's staff. This list is as a large string, where all addresses are written in arbitrary order, separated by commas. The same address can be written more than once. Suddenly, because of unknown reasons, all commas in Bob's list disappeared. Now Bob has a string, where all addresses are written one after another without any separators, and there is impossible to determine, where the boundaries between addresses are. Unfortunately, on the same day his chief asked him to bring the initial list of addresses. Now Bob wants to disjoin addresses in some valid way. Help him to do that. Input The first line contains the list of addresses without separators. The length of this string is between 1 and 200, inclusive. The string consists only from small Latin letters and characters «@». Output If there is no list of the valid (according to the Berland rules) email addresses such that after removing all commas it coincides with the given string, output No solution. In the other case, output the list. The same address can be written in this list more than once. If there are several solutions, output any of them. Examples Input a@aa@a Output a@a,a@a Input a@a@a Output No solution Input @aa@a Output No solution Submitted Solution: ``` a=input().split("@") ans=a[0] if len(a[0])==0 or len(a)<=1 or len(a[-1])==0: print("No solution") exit() for u in range(1,len(a)-1): if len(a[u])>1: ans+="@"+a[u][0]+","+a[u][1:] else: print("No solution") exit() print(ans+"@"+a[-1]) ```
instruction
0
24,147
6
48,294
Yes
output
1
24,147
6
48,295
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Email address in Berland is a string of the form A@B, where A and B are arbitrary strings consisting of small Latin letters. Bob is a system administrator in «Bersoft» company. He keeps a list of email addresses of the company's staff. This list is as a large string, where all addresses are written in arbitrary order, separated by commas. The same address can be written more than once. Suddenly, because of unknown reasons, all commas in Bob's list disappeared. Now Bob has a string, where all addresses are written one after another without any separators, and there is impossible to determine, where the boundaries between addresses are. Unfortunately, on the same day his chief asked him to bring the initial list of addresses. Now Bob wants to disjoin addresses in some valid way. Help him to do that. Input The first line contains the list of addresses without separators. The length of this string is between 1 and 200, inclusive. The string consists only from small Latin letters and characters «@». Output If there is no list of the valid (according to the Berland rules) email addresses such that after removing all commas it coincides with the given string, output No solution. In the other case, output the list. The same address can be written in this list more than once. If there are several solutions, output any of them. Examples Input a@aa@a Output a@a,a@a Input a@a@a Output No solution Input @aa@a Output No solution Submitted Solution: ``` s = input() prev = 0 lis = [] start = 0 flag = 0 for i in range(len(s)): if s[i] == '@' and prev == 0: if i-prev<=0: flag = 1 break prev= i elif s[i] == '@': lis.append(s[start:prev+2]) start = prev+2 prev = i if flag: print("No solution") else: if '@' in s[start:] and s[len(s)-1]!='@': lis.append(s[start:]) for i in range(len(lis)-1): print(lis[i], end = ",") print(lis[len(lis)-1]) else: print("No solution") ```
instruction
0
24,148
6
48,296
No
output
1
24,148
6
48,297
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Email address in Berland is a string of the form A@B, where A and B are arbitrary strings consisting of small Latin letters. Bob is a system administrator in «Bersoft» company. He keeps a list of email addresses of the company's staff. This list is as a large string, where all addresses are written in arbitrary order, separated by commas. The same address can be written more than once. Suddenly, because of unknown reasons, all commas in Bob's list disappeared. Now Bob has a string, where all addresses are written one after another without any separators, and there is impossible to determine, where the boundaries between addresses are. Unfortunately, on the same day his chief asked him to bring the initial list of addresses. Now Bob wants to disjoin addresses in some valid way. Help him to do that. Input The first line contains the list of addresses without separators. The length of this string is between 1 and 200, inclusive. The string consists only from small Latin letters and characters «@». Output If there is no list of the valid (according to the Berland rules) email addresses such that after removing all commas it coincides with the given string, output No solution. In the other case, output the list. The same address can be written in this list more than once. If there are several solutions, output any of them. Examples Input a@aa@a Output a@a,a@a Input a@a@a Output No solution Input @aa@a Output No solution Submitted Solution: ``` string=input() if len(string)==1: print('No solution') exit() lst=string.split('@') middle=lst[1:-1] if not( lst[0].isalpha() and lst[-1].isalpha()): print('No solution') exit() if len(lst)==2: print(string) exit() if not all(list(map(lambda x:len(x)>1 and x.isalpha(),middle))): print('No solution') exit() first=lst[0] emails=[] for i in middle: last=i[0] emails.append(first+'@'+last) first=i[1:] emails.append(first+'@'+lst[-1]) print(','.join(emails)) ```
instruction
0
24,149
6
48,298
No
output
1
24,149
6
48,299
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Email address in Berland is a string of the form A@B, where A and B are arbitrary strings consisting of small Latin letters. Bob is a system administrator in «Bersoft» company. He keeps a list of email addresses of the company's staff. This list is as a large string, where all addresses are written in arbitrary order, separated by commas. The same address can be written more than once. Suddenly, because of unknown reasons, all commas in Bob's list disappeared. Now Bob has a string, where all addresses are written one after another without any separators, and there is impossible to determine, where the boundaries between addresses are. Unfortunately, on the same day his chief asked him to bring the initial list of addresses. Now Bob wants to disjoin addresses in some valid way. Help him to do that. Input The first line contains the list of addresses without separators. The length of this string is between 1 and 200, inclusive. The string consists only from small Latin letters and characters «@». Output If there is no list of the valid (according to the Berland rules) email addresses such that after removing all commas it coincides with the given string, output No solution. In the other case, output the list. The same address can be written in this list more than once. If there are several solutions, output any of them. Examples Input a@aa@a Output a@a,a@a Input a@a@a Output No solution Input @aa@a Output No solution Submitted Solution: ``` def main(): string = input() comps = string.split('@') ans = [] for i in range(len(comps)): if i == 0 or i == len(comps) - 1: if len(comps[i]) < 1: print("No solution") return else: if len(comps[i]) < 2: print("No solution") return for i in range(len(comps) - 1): if i == 0: ans.append(comps[i] + '@' + comps[i + 1][:1]) elif i == len(comps) - 2: ans.append(comps[i][1:] + '@' + comps[i + 1]) else: ans.append(comps[i][1:] + '@' + comps[i + 1][:1]) print(', '.join(ans)) main() ```
instruction
0
24,150
6
48,300
No
output
1
24,150
6
48,301
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Email address in Berland is a string of the form A@B, where A and B are arbitrary strings consisting of small Latin letters. Bob is a system administrator in «Bersoft» company. He keeps a list of email addresses of the company's staff. This list is as a large string, where all addresses are written in arbitrary order, separated by commas. The same address can be written more than once. Suddenly, because of unknown reasons, all commas in Bob's list disappeared. Now Bob has a string, where all addresses are written one after another without any separators, and there is impossible to determine, where the boundaries between addresses are. Unfortunately, on the same day his chief asked him to bring the initial list of addresses. Now Bob wants to disjoin addresses in some valid way. Help him to do that. Input The first line contains the list of addresses without separators. The length of this string is between 1 and 200, inclusive. The string consists only from small Latin letters and characters «@». Output If there is no list of the valid (according to the Berland rules) email addresses such that after removing all commas it coincides with the given string, output No solution. In the other case, output the list. The same address can be written in this list more than once. If there are several solutions, output any of them. Examples Input a@aa@a Output a@a,a@a Input a@a@a Output No solution Input @aa@a Output No solution Submitted Solution: ``` s=input() if s[0]!="@" and s[len(s)-1]!="@": exit=s[::-1] exit=len(exit)-exit.index("@")-1 mas=[] res="" t=True for i in range(len(s)): res=res+s[i] if (s[i]=="@"): if i!=exit: t=False if (s[i+1]=="@"): break continue else: t=True if t==False: t=True mas.append(res) res="" if i+1==len(s): mas.append(res) if t==True: print(",".join(mas)) else: print("No solution") else: print("No solution") ```
instruction
0
24,151
6
48,302
No
output
1
24,151
6
48,303
Provide tags and a correct Python 3 solution for this coding contest problem. Haiku is a genre of Japanese traditional poetry. A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syllables). A haiku masterpiece contains a description of a moment in those three phrases. Every word is important in a small poem, which is why haiku are rich with symbols. Each word has a special meaning, a special role. The main principle of haiku is to say much using a few words. To simplify the matter, in the given problem we will consider that the number of syllable in the phrase is equal to the number of vowel letters there. Only the following letters are regarded as vowel letters: "a", "e", "i", "o" and "u". Three phases from a certain poem are given. Determine whether it is haiku or not. Input The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The i-th line contains the i-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailing spaces in phrases are allowed. Every phrase has at least one non-space character. See the example for clarification. Output Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes). Examples Input on codeforces beta round is running a rustling of keys Output YES Input how many gallons of edo s rain did you drink cuckoo Output NO
instruction
0
24,380
6
48,760
Tags: implementation, strings Correct Solution: ``` print('YES' if [sum(s.count(x) for x in "aeiou") for s in [input() for _ in range(3)]]==[5,7,5] else 'NO') ```
output
1
24,380
6
48,761
Provide tags and a correct Python 3 solution for this coding contest problem. Haiku is a genre of Japanese traditional poetry. A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syllables). A haiku masterpiece contains a description of a moment in those three phrases. Every word is important in a small poem, which is why haiku are rich with symbols. Each word has a special meaning, a special role. The main principle of haiku is to say much using a few words. To simplify the matter, in the given problem we will consider that the number of syllable in the phrase is equal to the number of vowel letters there. Only the following letters are regarded as vowel letters: "a", "e", "i", "o" and "u". Three phases from a certain poem are given. Determine whether it is haiku or not. Input The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The i-th line contains the i-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailing spaces in phrases are allowed. Every phrase has at least one non-space character. See the example for clarification. Output Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes). Examples Input on codeforces beta round is running a rustling of keys Output YES Input how many gallons of edo s rain did you drink cuckoo Output NO
instruction
0
24,381
6
48,762
Tags: implementation, strings Correct Solution: ``` import sys import os from collections import Counter def changeStdioToFile(): path = os.path.dirname(os.path.abspath(__file__)) sys.stdin = open(f'{path}/input.txt', 'r') sys.stdout = open(f'{path}/output.txt', 'w') #changeStdioToFile() t = 1 # t = int(input()) for _ in range(t): flag = False for i in (5, 7, 5): c = Counter(input()) if sum(c.get(w, 0) for w in 'aeiou') != i: flag = True print("YES" if not flag else "NO") ```
output
1
24,381
6
48,763
Provide tags and a correct Python 3 solution for this coding contest problem. Haiku is a genre of Japanese traditional poetry. A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syllables). A haiku masterpiece contains a description of a moment in those three phrases. Every word is important in a small poem, which is why haiku are rich with symbols. Each word has a special meaning, a special role. The main principle of haiku is to say much using a few words. To simplify the matter, in the given problem we will consider that the number of syllable in the phrase is equal to the number of vowel letters there. Only the following letters are regarded as vowel letters: "a", "e", "i", "o" and "u". Three phases from a certain poem are given. Determine whether it is haiku or not. Input The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The i-th line contains the i-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailing spaces in phrases are allowed. Every phrase has at least one non-space character. See the example for clarification. Output Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes). Examples Input on codeforces beta round is running a rustling of keys Output YES Input how many gallons of edo s rain did you drink cuckoo Output NO
instruction
0
24,382
6
48,764
Tags: implementation, strings Correct Solution: ``` s1=input() s2=input() s3=input() c1=s1.count('a')+s1.count('e')+s1.count('i')+s1.count('o')+s1.count('u') c2=s2.count('a')+s2.count('e')+s2.count('i')+s2.count('o')+s2.count('u') c3=s3.count('a')+s3.count('e')+s3.count('i')+s3.count('o')+s3.count('u') if(c1==5 and c2==7 and c3==5): print("YES") else: print("NO") ```
output
1
24,382
6
48,765
Provide tags and a correct Python 3 solution for this coding contest problem. Haiku is a genre of Japanese traditional poetry. A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syllables). A haiku masterpiece contains a description of a moment in those three phrases. Every word is important in a small poem, which is why haiku are rich with symbols. Each word has a special meaning, a special role. The main principle of haiku is to say much using a few words. To simplify the matter, in the given problem we will consider that the number of syllable in the phrase is equal to the number of vowel letters there. Only the following letters are regarded as vowel letters: "a", "e", "i", "o" and "u". Three phases from a certain poem are given. Determine whether it is haiku or not. Input The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The i-th line contains the i-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailing spaces in phrases are allowed. Every phrase has at least one non-space character. See the example for clarification. Output Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes). Examples Input on codeforces beta round is running a rustling of keys Output YES Input how many gallons of edo s rain did you drink cuckoo Output NO
instruction
0
24,383
6
48,766
Tags: implementation, strings Correct Solution: ``` a=input().replace(' ','') b=input().replace(' ','') c=input().replace(' ','') l=list('aeiou') f,d,e=0,0,0 for i in a: if i in l: f+=1 for i in b: if i in l: d+=1 for i in c: if i in l: e+=1 if(f==5 and d==7 and e==5): print("YES") else: print("NO") ```
output
1
24,383
6
48,767
Provide tags and a correct Python 3 solution for this coding contest problem. Haiku is a genre of Japanese traditional poetry. A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syllables). A haiku masterpiece contains a description of a moment in those three phrases. Every word is important in a small poem, which is why haiku are rich with symbols. Each word has a special meaning, a special role. The main principle of haiku is to say much using a few words. To simplify the matter, in the given problem we will consider that the number of syllable in the phrase is equal to the number of vowel letters there. Only the following letters are regarded as vowel letters: "a", "e", "i", "o" and "u". Three phases from a certain poem are given. Determine whether it is haiku or not. Input The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The i-th line contains the i-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailing spaces in phrases are allowed. Every phrase has at least one non-space character. See the example for clarification. Output Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes). Examples Input on codeforces beta round is running a rustling of keys Output YES Input how many gallons of edo s rain did you drink cuckoo Output NO
instruction
0
24,384
6
48,768
Tags: implementation, strings Correct Solution: ``` # import sys # sys.stdin=open('input.in','r') # sys.stdout=open('output.out','w') l=['a','e','i','o','u'] t1=t2=t3=0 s1=input().strip() s2=input().strip() s3=input().strip() for x in s1: if x in l: t1+=1 for x in s2: if x in l: t2+=1 for x in s3: if x in l: t3+=1 if t1==5 and t2==7 and t3==5: print('YES') else: print('NO') ```
output
1
24,384
6
48,769