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
|
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
* the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";
* the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
Input
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
Output
Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
Examples
Input
hellno
Output
hell no
Input
abacaba
Output
abacaba
Input
asdfasdf
Output
asd fasd f
|
instruction
| 0
| 8,093
| 6
| 16,186
|
Tags: dp, greedy, implementation
Correct Solution:
```
s = input()
d = ['a', 'e', 'i', 'o', 'u']
st = []
for i in range(len(s)):
if s[i] in d:
st = []
print(s[i], end="")
continue
st.append(s[i])
if st == [s[i], s[i], s[i]]:
st = st[1:]
print(s[i], end='')
elif len(st) == 3:
st = [s[i]]
print(" " + s[i], end="")
else:
print(s[i], end='')
```
|
output
| 1
| 8,093
| 6
| 16,187
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
* the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";
* the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
Input
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
Output
Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
Examples
Input
hellno
Output
hell no
Input
abacaba
Output
abacaba
Input
asdfasdf
Output
asd fasd f
|
instruction
| 0
| 8,094
| 6
| 16,188
|
Tags: dp, greedy, implementation
Correct Solution:
```
s=input()
l='aeiou'
i=2
while(i<len(s)):
if(s[i]!=s[i-1] or s[i]!=s[i-2] or s[i-1]!=s[i-2]) and (s[i] not in l) and (s[i-1] not in l) and (s[i-2] not in l) :
s=s[:i]+" "+s[i:]
i+=2
i+=1
print(s)
```
|
output
| 1
| 8,094
| 6
| 16,189
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
* the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";
* the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
Input
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
Output
Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
Examples
Input
hellno
Output
hell no
Input
abacaba
Output
abacaba
Input
asdfasdf
Output
asd fasd f
Submitted Solution:
```
"""
Author - Satwik Tiwari .
"""
#===============================================================================================
#importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from functools import cmp_to_key
# from itertools import *
from heapq import *
from math import gcd, factorial,floor,ceil,sqrt,log2
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
#==============================================================================================
#fast I/O region
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
# inp = lambda: sys.stdin.readline().rstrip("\r\n")
#===============================================================================================
### START ITERATE RECURSION ###
from types import GeneratorType
def iterative(f, stack=[]):
def wrapped_func(*args, **kwargs):
if stack: return f(*args, **kwargs)
to = f(*args, **kwargs)
while True:
if type(to) is GeneratorType:
stack.append(to)
to = next(to)
continue
stack.pop()
if not stack: break
to = stack[-1].send(to)
return to
return wrapped_func
#### END ITERATE RECURSION ####
#===============================================================================================
#some shortcuts
def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def out(var): sys.stdout.write(str(var)) #for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
# def graph(vertex): return [[] for i in range(0,vertex+1)]
def testcase(t):
for pp in range(t):
solve(pp)
def google(p):
print('Case #'+str(p)+': ',end='')
def lcm(a,b): return (a*b)//gcd(a,b)
def modInverse(b):
g = gcd(b, mod)
if (g != 1):
# print("Inverse doesn't exist")
return -1
else:
# If b and m are relatively prime,
# then modulo inverse is b^(m-2) mode m
return pow(b, mod - 2, mod)
def power(x, y, p) :
y%=(p-1) #not so sure about this. used when y>p-1. if p is prime.
res = 1 # Initialize result
x = x % p # Update x if it is more , than or equal to p
if (x == 0) :
return 0
while (y > 0) :
if ((y & 1) == 1) : # If y is odd, multiply, x with result
res = (res * x) % p
y = y >> 1 # y = y/2
x = (x * x) % p
return res
def isPrime(n) :
if (n <= 1) : return False
if (n <= 3) : return True
if (n % 2 == 0 or n % 3 == 0) : return False
i = 5
while(i * i <= n) :
if (n % i == 0 or n % (i + 2) == 0) :
return False
i = i + 6
return True
inf = pow(10,20)
mod = 10**9+7
#===============================================================================================
# code here ;))
vow = {'a','e','i','o','u'}
def chck(a,b,c):
temp = [a,b,c]
if(len(set(temp)) < 2):
return False
# print(temp)
for i in temp:
if(i in vow):
return False
if(i == ' '): return False
return True
def solve(case):
s = list(inp())
ans = []
for i in range(len(s)):
if(s[i] in vow):
ans.append(s[i])
continue
if(i > 1 and chck(s[i],ans[-1],ans[-2])):
ans.append(' ')
ans.append(s[i])
print(''.join(ans))
testcase(1)
# testcase(int(inp()))
```
|
instruction
| 0
| 8,095
| 6
| 16,190
|
Yes
|
output
| 1
| 8,095
| 6
| 16,191
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
* the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";
* the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
Input
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
Output
Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
Examples
Input
hellno
Output
hell no
Input
abacaba
Output
abacaba
Input
asdfasdf
Output
asd fasd f
Submitted Solution:
```
a = input()
x =2
while x<len(a):
if a[x]!= 'a' and a[x]!= 'e' and a[x]!= 'i' and a[x]!= 'o' and a[x]!= 'u' and a[x]!= ' ':
if a[x-1]!= 'a' and a[x-1]!= 'e' and a[x-1]!= 'i' and a[x-1]!= 'o' and a[x-1]!= 'u' and a[x-1]!= ' ' and a[x-2]!= 'a' and a[x-2]!= 'e' and a[x-2]!= 'i' and a[x-2]!= 'o' and a[x-2]!= 'u' and a[x-2]!= ' ':
if a[x-2]!=a[x] or a[x]!=a[x-1]:
a = a[0:x]+' '+a[x:]
x+=1
x+=1
print(a)
```
|
instruction
| 0
| 8,096
| 6
| 16,192
|
Yes
|
output
| 1
| 8,096
| 6
| 16,193
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
* the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";
* the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
Input
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
Output
Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
Examples
Input
hellno
Output
hell no
Input
abacaba
Output
abacaba
Input
asdfasdf
Output
asd fasd f
Submitted Solution:
```
def sogl(a):
glas = ['u', 'a', 'i', 'e', 'o']
for letter in glas:
if letter == a:
return False
return True
def xor(a,b,c):
j = 0
if a==b:
j+=1
if a==c:
j+=1
if j == 2:
return False
else:
return True
line = input()
let = 0
for i in range(0, len(line)):
#test1=sogl(line[i])
#test2 = let
#test3 = xor(line[i], line[i-1], line[i-2])
if (sogl(line[i])) and (let<2):
let += 1
print(line[i], end='')
elif (sogl(line[i])) and (let==2) and (xor(line[i], line[i-1], line[i-2])):
let = 1
print(' ',end='')
print(line[i], end='')
elif (sogl(line[i])) and (let==2) and not(xor(line[i], line[i-1], line[i-2])):
print(line[i], end='')
else:
let = 0
print(line[i], end='')
```
|
instruction
| 0
| 8,097
| 6
| 16,194
|
Yes
|
output
| 1
| 8,097
| 6
| 16,195
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
* the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";
* the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
Input
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
Output
Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
Examples
Input
hellno
Output
hell no
Input
abacaba
Output
abacaba
Input
asdfasdf
Output
asd fasd f
Submitted Solution:
```
s = input()
vows = ['a', 'e', 'u', 'i', 'o']
i = 0
s1 = ''
while i < (len(s)-2):
if s[i] not in vows and s[i+1] not in vows and s[i+2] not in vows:
if s[i] != s[i+1] or s[i+1] != s[i+2]:
s1+=s[i: i+2] + ' '
i+=2
else:
s1+=s[i]
i+=1
else:
s1+=s[i]
i+=1
s1+=s[i:]
print (s1)
```
|
instruction
| 0
| 8,098
| 6
| 16,196
|
Yes
|
output
| 1
| 8,098
| 6
| 16,197
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
* the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";
* the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
Input
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
Output
Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
Examples
Input
hellno
Output
hell no
Input
abacaba
Output
abacaba
Input
asdfasdf
Output
asd fasd f
Submitted Solution:
```
# Задачка C
# гласные
vowels = 'aeiou'
word = input()
consonants = word[0] not in vowels
duplicates = 0
result = ''
term = word[0]
for p, w in zip(word, word[1:]):
if w not in vowels: consonants += 1
else:
consonants = duplicates = 0
if consonants > 0: duplicates += p==w
if consonants > 2 and duplicates != consonants-1:
result += term + ' ' + w
consonants = duplicates = 0
term = ''
else:
term += w
result += term
if result.startswith(' '): result == result[1:]
print(result)
```
|
instruction
| 0
| 8,099
| 6
| 16,198
|
No
|
output
| 1
| 8,099
| 6
| 16,199
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
* the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";
* the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
Input
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
Output
Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
Examples
Input
hellno
Output
hell no
Input
abacaba
Output
abacaba
Input
asdfasdf
Output
asd fasd f
Submitted Solution:
```
s = input()
g = {'a', 'e', 'i', 'o', 'u'}
l = 0
lc = ""
for ch in s:
if ch not in g and lc != ch:
l+=1
else: l=0
if l>2 and lc != ch:
print(" ", end="")
l = 1
lc = ch
print(ch, end="")
```
|
instruction
| 0
| 8,100
| 6
| 16,200
|
No
|
output
| 1
| 8,100
| 6
| 16,201
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
* the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";
* the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
Input
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
Output
Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
Examples
Input
hellno
Output
hell no
Input
abacaba
Output
abacaba
Input
asdfasdf
Output
asd fasd f
Submitted Solution:
```
import re
s = list(input())
#s = list("orfyaenanabsdfckumulsbolo")
vowels = "aeiou"
c = ""
sections = []
for i in range(len(s)):
if s[i] in vowels:
sections.append(c)
sections.append(s[i])
c = ""
elif i == len(s) - 1:
c += s[i]
sections.append(c)
else:
c += s[i]
new = []
for i in range(len(sections)):
blurb = sections[i]
length = len(blurb)
if length >= 4 and length % 2 == 0:
for j in range(length // 2):
if j == (length // 2) - 1:
new.append(blurb)
else:
new.append(blurb[:2] + " ")
blurb = blurb[2:]
elif length >= 4 and length % 2 != 0:
for j in range(length // 2):
if j == (length // 2) - 1:
new.append(blurb)
else:
new.append(blurb[:2] + " ")
blurb = blurb[2:]
elif length >= 3:
new.append(blurb[:2] + " ")
new.append(blurb[2:])
else:
new.append(blurb)
t = ""
new_s = t.join(new)
print(new_s)
```
|
instruction
| 0
| 8,101
| 6
| 16,202
|
No
|
output
| 1
| 8,101
| 6
| 16,203
|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
* the following words have typos: "hellno", "hackcerrs" and "backtothefutttture";
* the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
Input
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
Output
Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
Examples
Input
hellno
Output
hell no
Input
abacaba
Output
abacaba
Input
asdfasdf
Output
asd fasd f
Submitted Solution:
```
def Dif(string):
if s.count(s[0]) != len(s):
return True
else:
return False
s = input()
s1 = ''
b = False
for i in range(len(s)):
if s[i] != 'a' and s[i] != 'e' and s[i] != 'i' and s[i] != 'o' and s[i] != 'u':
s1 += s[i]
if len(s1) > 2 and Dif(s1):
b = True
break
else:
s1 = ''
if b:
s1 = ''
s2 = ''
for i in range(len(s)):
if s[i] == 'a' or s[i] == 'e' or s[i] == 'i' or s[i] == 'o' or s[i] == 'u':
if len(s1) > 0 and s1[-1] == ' ':
s1 = s1[:len(s1) - 1:] + s[i]
else:
s1 += s[i]
s2 = ''
else:
s2 += s[i]
s1 += s[i]
if len(s2) > 1 and Dif(s2):
s1 += ' '
s2 = ''
s = s1
print(s)
```
|
instruction
| 0
| 8,102
| 6
| 16,204
|
No
|
output
| 1
| 8,102
| 6
| 16,205
|
Provide tags and a correct Python 3 solution for this coding contest problem.
When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc.
Login is an arbitrary sequence of lower and uppercase latin letters, digits and underline symbols («_»). However, in order to decrease the number of frauds and user-inattention related issues, it is prohibited to register a login if it is similar with an already existing login. More precisely, two logins s and t are considered similar if we can transform s to t via a sequence of operations of the following types:
* transform lowercase letters to uppercase and vice versa;
* change letter «O» (uppercase latin letter) to digit «0» and vice versa;
* change digit «1» (one) to any letter among «l» (lowercase latin «L»), «I» (uppercase latin «i») and vice versa, or change one of these letters to other.
For example, logins «Codeforces» and «codef0rces» as well as «OO0OOO00O0OOO0O00OOO0OO_lol» and «OO0OOO0O00OOO0O00OO0OOO_1oI» are considered similar whereas «Codeforces» and «Code_forces» are not.
You're given a list of existing logins with no two similar amonst and a newly created user login. Check whether this new login is similar with any of the existing ones.
Input
The first line contains a non-empty string s consisting of lower and uppercase latin letters, digits and underline symbols («_») with length not exceeding 50 — the login itself.
The second line contains a single integer n (1 ≤ n ≤ 1 000) — the number of existing logins.
The next n lines describe the existing logins, following the same constraints as the user login (refer to the first line of the input). It's guaranteed that no two existing logins are similar.
Output
Print «Yes» (without quotes), if user can register via this login, i.e. none of the existing logins is similar with it.
Otherwise print «No» (without quotes).
Examples
Input
1_wat
2
2_wat
wat_1
Output
Yes
Input
000
3
00
ooA
oOo
Output
No
Input
_i_
3
__i_
_1_
I
Output
No
Input
La0
3
2a0
La1
1a0
Output
No
Input
abc
1
aBc
Output
No
Input
0Lil
2
LIL0
0Ril
Output
Yes
Note
In the second sample case the user wants to create a login consisting of three zeros. It's impossible due to collision with the third among the existing.
In the third sample case the new login is similar with the second one.
|
instruction
| 0
| 8,120
| 6
| 16,240
|
Tags: *special, strings
Correct Solution:
```
s1 = input()
abc = 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM'
for y in range(0, 26):
s1 = s1.replace(abc[y], abc[y + 26])
s1 = s1.replace("O", "0")
s1 = s1.replace("L", "1")
s1 = s1.replace("I", "1")
n=int(input())
d=[]
d.append(s1)
for i in range(0,n):
s=input()
for y in range(0,26):
s = s.replace(abc[y],abc[y+26])
s = s.replace("O", "0")
s = s.replace("L","1")
s = s.replace("I","1")
if not s in d:
d.append(s)
if len(d) != n + 1:
print('No')
else:
print('Yes')
```
|
output
| 1
| 8,120
| 6
| 16,241
|
Provide tags and a correct Python 3 solution for this coding contest problem.
When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc.
Login is an arbitrary sequence of lower and uppercase latin letters, digits and underline symbols («_»). However, in order to decrease the number of frauds and user-inattention related issues, it is prohibited to register a login if it is similar with an already existing login. More precisely, two logins s and t are considered similar if we can transform s to t via a sequence of operations of the following types:
* transform lowercase letters to uppercase and vice versa;
* change letter «O» (uppercase latin letter) to digit «0» and vice versa;
* change digit «1» (one) to any letter among «l» (lowercase latin «L»), «I» (uppercase latin «i») and vice versa, or change one of these letters to other.
For example, logins «Codeforces» and «codef0rces» as well as «OO0OOO00O0OOO0O00OOO0OO_lol» and «OO0OOO0O00OOO0O00OO0OOO_1oI» are considered similar whereas «Codeforces» and «Code_forces» are not.
You're given a list of existing logins with no two similar amonst and a newly created user login. Check whether this new login is similar with any of the existing ones.
Input
The first line contains a non-empty string s consisting of lower and uppercase latin letters, digits and underline symbols («_») with length not exceeding 50 — the login itself.
The second line contains a single integer n (1 ≤ n ≤ 1 000) — the number of existing logins.
The next n lines describe the existing logins, following the same constraints as the user login (refer to the first line of the input). It's guaranteed that no two existing logins are similar.
Output
Print «Yes» (without quotes), if user can register via this login, i.e. none of the existing logins is similar with it.
Otherwise print «No» (without quotes).
Examples
Input
1_wat
2
2_wat
wat_1
Output
Yes
Input
000
3
00
ooA
oOo
Output
No
Input
_i_
3
__i_
_1_
I
Output
No
Input
La0
3
2a0
La1
1a0
Output
No
Input
abc
1
aBc
Output
No
Input
0Lil
2
LIL0
0Ril
Output
Yes
Note
In the second sample case the user wants to create a login consisting of three zeros. It's impossible due to collision with the third among the existing.
In the third sample case the new login is similar with the second one.
|
instruction
| 0
| 8,121
| 6
| 16,242
|
Tags: *special, strings
Correct Solution:
```
def norm(s):
d = ord('A') - ord('a')
s11 = ''
for i in range(len(s)):
if ord('a') <= ord(s[i]) <= ord('z'):
s11 += chr(ord(s[i]) + d)
else:
s11 += s[i]
s = s11
s = s.replace('O', '0')
s = s.replace('L', '1')
s = s.replace('I', '1')
return s
s = norm(input())
n = int(input())
ok = True
for i in range(n):
s1 = input()
if norm(s1) == s:
ok = False
break
if ok:
print('Yes')
else:
print('No')
```
|
output
| 1
| 8,121
| 6
| 16,243
|
Provide tags and a correct Python 3 solution for this coding contest problem.
When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc.
Login is an arbitrary sequence of lower and uppercase latin letters, digits and underline symbols («_»). However, in order to decrease the number of frauds and user-inattention related issues, it is prohibited to register a login if it is similar with an already existing login. More precisely, two logins s and t are considered similar if we can transform s to t via a sequence of operations of the following types:
* transform lowercase letters to uppercase and vice versa;
* change letter «O» (uppercase latin letter) to digit «0» and vice versa;
* change digit «1» (one) to any letter among «l» (lowercase latin «L»), «I» (uppercase latin «i») and vice versa, or change one of these letters to other.
For example, logins «Codeforces» and «codef0rces» as well as «OO0OOO00O0OOO0O00OOO0OO_lol» and «OO0OOO0O00OOO0O00OO0OOO_1oI» are considered similar whereas «Codeforces» and «Code_forces» are not.
You're given a list of existing logins with no two similar amonst and a newly created user login. Check whether this new login is similar with any of the existing ones.
Input
The first line contains a non-empty string s consisting of lower and uppercase latin letters, digits and underline symbols («_») with length not exceeding 50 — the login itself.
The second line contains a single integer n (1 ≤ n ≤ 1 000) — the number of existing logins.
The next n lines describe the existing logins, following the same constraints as the user login (refer to the first line of the input). It's guaranteed that no two existing logins are similar.
Output
Print «Yes» (without quotes), if user can register via this login, i.e. none of the existing logins is similar with it.
Otherwise print «No» (without quotes).
Examples
Input
1_wat
2
2_wat
wat_1
Output
Yes
Input
000
3
00
ooA
oOo
Output
No
Input
_i_
3
__i_
_1_
I
Output
No
Input
La0
3
2a0
La1
1a0
Output
No
Input
abc
1
aBc
Output
No
Input
0Lil
2
LIL0
0Ril
Output
Yes
Note
In the second sample case the user wants to create a login consisting of three zeros. It's impossible due to collision with the third among the existing.
In the third sample case the new login is similar with the second one.
|
instruction
| 0
| 8,122
| 6
| 16,244
|
Tags: *special, strings
Correct Solution:
```
s,n=input(),int(input())
s=s.replace('O','0')
s=s.replace('o','0')
for _ in range(n):
stp=''
a=input()
if len(a)==len(s):
for i in range(len(a)):
if a[i] in '1lILi' and s[i] in '1lILi':
stp+=a[i]
else:
stp+=s[i]
a=a.replace('O','0')
a=a.replace('o','0')
stp=stp.lower()
a=a.lower()
if a==stp:
print('No')
break
else: print('Yes')
```
|
output
| 1
| 8,122
| 6
| 16,245
|
Provide tags and a correct Python 3 solution for this coding contest problem.
When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc.
Login is an arbitrary sequence of lower and uppercase latin letters, digits and underline symbols («_»). However, in order to decrease the number of frauds and user-inattention related issues, it is prohibited to register a login if it is similar with an already existing login. More precisely, two logins s and t are considered similar if we can transform s to t via a sequence of operations of the following types:
* transform lowercase letters to uppercase and vice versa;
* change letter «O» (uppercase latin letter) to digit «0» and vice versa;
* change digit «1» (one) to any letter among «l» (lowercase latin «L»), «I» (uppercase latin «i») and vice versa, or change one of these letters to other.
For example, logins «Codeforces» and «codef0rces» as well as «OO0OOO00O0OOO0O00OOO0OO_lol» and «OO0OOO0O00OOO0O00OO0OOO_1oI» are considered similar whereas «Codeforces» and «Code_forces» are not.
You're given a list of existing logins with no two similar amonst and a newly created user login. Check whether this new login is similar with any of the existing ones.
Input
The first line contains a non-empty string s consisting of lower and uppercase latin letters, digits and underline symbols («_») with length not exceeding 50 — the login itself.
The second line contains a single integer n (1 ≤ n ≤ 1 000) — the number of existing logins.
The next n lines describe the existing logins, following the same constraints as the user login (refer to the first line of the input). It's guaranteed that no two existing logins are similar.
Output
Print «Yes» (without quotes), if user can register via this login, i.e. none of the existing logins is similar with it.
Otherwise print «No» (without quotes).
Examples
Input
1_wat
2
2_wat
wat_1
Output
Yes
Input
000
3
00
ooA
oOo
Output
No
Input
_i_
3
__i_
_1_
I
Output
No
Input
La0
3
2a0
La1
1a0
Output
No
Input
abc
1
aBc
Output
No
Input
0Lil
2
LIL0
0Ril
Output
Yes
Note
In the second sample case the user wants to create a login consisting of three zeros. It's impossible due to collision with the third among the existing.
In the third sample case the new login is similar with the second one.
|
instruction
| 0
| 8,123
| 6
| 16,246
|
Tags: *special, strings
Correct Solution:
```
def is_similar(one, two):
one = one.lower()
two = two.lower()
one = one.replace('o', '0')
one = one.replace('i', '1')
one = one.replace('l', '1')
two = two.replace('o', '0')
two = two.replace('i', '1')
two = two.replace('l', '1')
return one == two
have_similar = False
newlogin = input()
counter = int(input())
for i in range(0, counter):
login = input()
if is_similar(newlogin, login):
have_similar = True
break
if have_similar:
print("No")
else:
print("Yes")
```
|
output
| 1
| 8,123
| 6
| 16,247
|
Provide tags and a correct Python 3 solution for this coding contest problem.
When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc.
Login is an arbitrary sequence of lower and uppercase latin letters, digits and underline symbols («_»). However, in order to decrease the number of frauds and user-inattention related issues, it is prohibited to register a login if it is similar with an already existing login. More precisely, two logins s and t are considered similar if we can transform s to t via a sequence of operations of the following types:
* transform lowercase letters to uppercase and vice versa;
* change letter «O» (uppercase latin letter) to digit «0» and vice versa;
* change digit «1» (one) to any letter among «l» (lowercase latin «L»), «I» (uppercase latin «i») and vice versa, or change one of these letters to other.
For example, logins «Codeforces» and «codef0rces» as well as «OO0OOO00O0OOO0O00OOO0OO_lol» and «OO0OOO0O00OOO0O00OO0OOO_1oI» are considered similar whereas «Codeforces» and «Code_forces» are not.
You're given a list of existing logins with no two similar amonst and a newly created user login. Check whether this new login is similar with any of the existing ones.
Input
The first line contains a non-empty string s consisting of lower and uppercase latin letters, digits and underline symbols («_») with length not exceeding 50 — the login itself.
The second line contains a single integer n (1 ≤ n ≤ 1 000) — the number of existing logins.
The next n lines describe the existing logins, following the same constraints as the user login (refer to the first line of the input). It's guaranteed that no two existing logins are similar.
Output
Print «Yes» (without quotes), if user can register via this login, i.e. none of the existing logins is similar with it.
Otherwise print «No» (without quotes).
Examples
Input
1_wat
2
2_wat
wat_1
Output
Yes
Input
000
3
00
ooA
oOo
Output
No
Input
_i_
3
__i_
_1_
I
Output
No
Input
La0
3
2a0
La1
1a0
Output
No
Input
abc
1
aBc
Output
No
Input
0Lil
2
LIL0
0Ril
Output
Yes
Note
In the second sample case the user wants to create a login consisting of three zeros. It's impossible due to collision with the third among the existing.
In the third sample case the new login is similar with the second one.
|
instruction
| 0
| 8,124
| 6
| 16,248
|
Tags: *special, strings
Correct Solution:
```
def convert(s):
s = s.lower()
s = s.replace("0", "o")
s = s.replace("1", "l")
s = s.replace("i", "l")
return s
s = input()
s = convert(s)
n = int(input())
for i in range(n):
s1 = convert(input())
if s == s1:
print("No")
exit(0)
print("Yes")
```
|
output
| 1
| 8,124
| 6
| 16,249
|
Provide tags and a correct Python 3 solution for this coding contest problem.
When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc.
Login is an arbitrary sequence of lower and uppercase latin letters, digits and underline symbols («_»). However, in order to decrease the number of frauds and user-inattention related issues, it is prohibited to register a login if it is similar with an already existing login. More precisely, two logins s and t are considered similar if we can transform s to t via a sequence of operations of the following types:
* transform lowercase letters to uppercase and vice versa;
* change letter «O» (uppercase latin letter) to digit «0» and vice versa;
* change digit «1» (one) to any letter among «l» (lowercase latin «L»), «I» (uppercase latin «i») and vice versa, or change one of these letters to other.
For example, logins «Codeforces» and «codef0rces» as well as «OO0OOO00O0OOO0O00OOO0OO_lol» and «OO0OOO0O00OOO0O00OO0OOO_1oI» are considered similar whereas «Codeforces» and «Code_forces» are not.
You're given a list of existing logins with no two similar amonst and a newly created user login. Check whether this new login is similar with any of the existing ones.
Input
The first line contains a non-empty string s consisting of lower and uppercase latin letters, digits and underline symbols («_») with length not exceeding 50 — the login itself.
The second line contains a single integer n (1 ≤ n ≤ 1 000) — the number of existing logins.
The next n lines describe the existing logins, following the same constraints as the user login (refer to the first line of the input). It's guaranteed that no two existing logins are similar.
Output
Print «Yes» (without quotes), if user can register via this login, i.e. none of the existing logins is similar with it.
Otherwise print «No» (without quotes).
Examples
Input
1_wat
2
2_wat
wat_1
Output
Yes
Input
000
3
00
ooA
oOo
Output
No
Input
_i_
3
__i_
_1_
I
Output
No
Input
La0
3
2a0
La1
1a0
Output
No
Input
abc
1
aBc
Output
No
Input
0Lil
2
LIL0
0Ril
Output
Yes
Note
In the second sample case the user wants to create a login consisting of three zeros. It's impossible due to collision with the third among the existing.
In the third sample case the new login is similar with the second one.
|
instruction
| 0
| 8,125
| 6
| 16,250
|
Tags: *special, strings
Correct Solution:
```
def transf(s):
return s.lower().replace('o', '0').replace('l', '1').replace('i', '1')
def check():
s = input()
n = int(input())
for i in range(n):
l = input()
if len(s) != len(l):
continue
if transf(s) == transf(l):
return 'No'
return 'Yes'
print(check())
```
|
output
| 1
| 8,125
| 6
| 16,251
|
Provide tags and a correct Python 3 solution for this coding contest problem.
When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc.
Login is an arbitrary sequence of lower and uppercase latin letters, digits and underline symbols («_»). However, in order to decrease the number of frauds and user-inattention related issues, it is prohibited to register a login if it is similar with an already existing login. More precisely, two logins s and t are considered similar if we can transform s to t via a sequence of operations of the following types:
* transform lowercase letters to uppercase and vice versa;
* change letter «O» (uppercase latin letter) to digit «0» and vice versa;
* change digit «1» (one) to any letter among «l» (lowercase latin «L»), «I» (uppercase latin «i») and vice versa, or change one of these letters to other.
For example, logins «Codeforces» and «codef0rces» as well as «OO0OOO00O0OOO0O00OOO0OO_lol» and «OO0OOO0O00OOO0O00OO0OOO_1oI» are considered similar whereas «Codeforces» and «Code_forces» are not.
You're given a list of existing logins with no two similar amonst and a newly created user login. Check whether this new login is similar with any of the existing ones.
Input
The first line contains a non-empty string s consisting of lower and uppercase latin letters, digits and underline symbols («_») with length not exceeding 50 — the login itself.
The second line contains a single integer n (1 ≤ n ≤ 1 000) — the number of existing logins.
The next n lines describe the existing logins, following the same constraints as the user login (refer to the first line of the input). It's guaranteed that no two existing logins are similar.
Output
Print «Yes» (without quotes), if user can register via this login, i.e. none of the existing logins is similar with it.
Otherwise print «No» (without quotes).
Examples
Input
1_wat
2
2_wat
wat_1
Output
Yes
Input
000
3
00
ooA
oOo
Output
No
Input
_i_
3
__i_
_1_
I
Output
No
Input
La0
3
2a0
La1
1a0
Output
No
Input
abc
1
aBc
Output
No
Input
0Lil
2
LIL0
0Ril
Output
Yes
Note
In the second sample case the user wants to create a login consisting of three zeros. It's impossible due to collision with the third among the existing.
In the third sample case the new login is similar with the second one.
|
instruction
| 0
| 8,126
| 6
| 16,252
|
Tags: *special, strings
Correct Solution:
```
def normalize_login(login):
return login \
.lower() \
.replace("o", "0") \
.replace("i", "1") \
.replace("l", "1")
new_login = normalize_login(input())
n = int(input())
logins = []
for i in range(0, n):
login = normalize_login(input())
logins.append(login)
print("No" if new_login in logins else "Yes")
```
|
output
| 1
| 8,126
| 6
| 16,253
|
Provide tags and a correct Python 3 solution for this coding contest problem.
When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc.
Login is an arbitrary sequence of lower and uppercase latin letters, digits and underline symbols («_»). However, in order to decrease the number of frauds and user-inattention related issues, it is prohibited to register a login if it is similar with an already existing login. More precisely, two logins s and t are considered similar if we can transform s to t via a sequence of operations of the following types:
* transform lowercase letters to uppercase and vice versa;
* change letter «O» (uppercase latin letter) to digit «0» and vice versa;
* change digit «1» (one) to any letter among «l» (lowercase latin «L»), «I» (uppercase latin «i») and vice versa, or change one of these letters to other.
For example, logins «Codeforces» and «codef0rces» as well as «OO0OOO00O0OOO0O00OOO0OO_lol» and «OO0OOO0O00OOO0O00OO0OOO_1oI» are considered similar whereas «Codeforces» and «Code_forces» are not.
You're given a list of existing logins with no two similar amonst and a newly created user login. Check whether this new login is similar with any of the existing ones.
Input
The first line contains a non-empty string s consisting of lower and uppercase latin letters, digits and underline symbols («_») with length not exceeding 50 — the login itself.
The second line contains a single integer n (1 ≤ n ≤ 1 000) — the number of existing logins.
The next n lines describe the existing logins, following the same constraints as the user login (refer to the first line of the input). It's guaranteed that no two existing logins are similar.
Output
Print «Yes» (without quotes), if user can register via this login, i.e. none of the existing logins is similar with it.
Otherwise print «No» (without quotes).
Examples
Input
1_wat
2
2_wat
wat_1
Output
Yes
Input
000
3
00
ooA
oOo
Output
No
Input
_i_
3
__i_
_1_
I
Output
No
Input
La0
3
2a0
La1
1a0
Output
No
Input
abc
1
aBc
Output
No
Input
0Lil
2
LIL0
0Ril
Output
Yes
Note
In the second sample case the user wants to create a login consisting of three zeros. It's impossible due to collision with the third among the existing.
In the third sample case the new login is similar with the second one.
|
instruction
| 0
| 8,127
| 6
| 16,254
|
Tags: *special, strings
Correct Solution:
```
def rep(data):
data = data.replace("0", "@@@")
data = data.replace("o", "@@@")
data = data.replace("1", "!!!")
data = data.replace("l", "!!!")
data = data.replace("i", "!!!")
return data
login_usr = rep(input().lower())
count_log = int(input())
data_log = list(map(rep, [input().lower() for i in range(count_log)]))
for data in data_log:
if data == login_usr:
count_log = 0
break
else:
count_log = 1
if count_log:
print("Yes")
else:
print("No")
```
|
output
| 1
| 8,127
| 6
| 16,255
|
Provide tags and a correct Python 3 solution for this coding contest problem.
per nextum in unam tum XI conscribementis fac sic
vestibulo perlegementum da varo.
morde varo.
seqis cumula varum.
cis
per nextum in unam tum XI conscribementis fac sic
seqis decumulamenta da varo.
varum privamentum fodementum da aresulto.
varum tum III elevamentum tum V multiplicamentum da bresulto.
aresultum tum bresultum addementum da resulto.
si CD tum resultum non praestantiam fac sic
dictum sic f(%d) = %.2f cis tum varum tum resultum egresso describe.
novumversum egresso scribe.
cis
si CD tum resultum praestantiam fac sic
dictum sic f(%d) = MAGNA NIMIS! cis tum varum egresso describe.
novumversum egresso scribe.
cis
cis
Input
The input consists of several integers, one per line. Each integer is between -50 and 50, inclusive.
Output
As described in the problem statement.
Example
Input
0
1
-2
-3
-4
-5
-6
-7
-8
-9
10
Output
f(10) = MAGNA NIMIS!
f(-9) = -3642.00
f(-8) = -2557.17
f(-7) = -1712.35
f(-6) = -1077.55
f(-5) = -622.76
f(-4) = -318.00
f(-3) = -133.27
f(-2) = -38.59
f(1) = 6.00
f(0) = 0.00
|
instruction
| 0
| 8,495
| 6
| 16,990
|
Tags: *special
Correct Solution:
```
import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left
from types import GeneratorType
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
import os
self.os = os
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
self.os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
import time
start_time = time.time()
import collections as col
import math, string
from functools import reduce
def getInts():
return [int(s) for s in input().split()]
def getInt():
return int(input())
def getStrs():
return [s for s in input().split()]
def getStr():
return input()
def listStr():
return list(input())
MOD = 10**9+7
"""
"""
def solve():
A = []
for i in range(11):
A.append(getInt())
A = A[::-1]
def f_(x): return math.sqrt(abs(x))+5*(x**3)
for a in A:
y = f_(a)
if y > 400:
print("f({}) =".format(a),"MAGNA NIMIS!")
else:
print("f({}) =".format(a),"%.2f"%y)
return
#for _ in range(getInt()):
solve()
```
|
output
| 1
| 8,495
| 6
| 16,991
|
Provide tags and a correct Python 3 solution for this coding contest problem.
per nextum in unam tum XI conscribementis fac sic
vestibulo perlegementum da varo.
morde varo.
seqis cumula varum.
cis
per nextum in unam tum XI conscribementis fac sic
seqis decumulamenta da varo.
varum privamentum fodementum da aresulto.
varum tum III elevamentum tum V multiplicamentum da bresulto.
aresultum tum bresultum addementum da resulto.
si CD tum resultum non praestantiam fac sic
dictum sic f(%d) = %.2f cis tum varum tum resultum egresso describe.
novumversum egresso scribe.
cis
si CD tum resultum praestantiam fac sic
dictum sic f(%d) = MAGNA NIMIS! cis tum varum egresso describe.
novumversum egresso scribe.
cis
cis
Input
The input consists of several integers, one per line. Each integer is between -50 and 50, inclusive.
Output
As described in the problem statement.
Example
Input
0
1
-2
-3
-4
-5
-6
-7
-8
-9
10
Output
f(10) = MAGNA NIMIS!
f(-9) = -3642.00
f(-8) = -2557.17
f(-7) = -1712.35
f(-6) = -1077.55
f(-5) = -622.76
f(-4) = -318.00
f(-3) = -133.27
f(-2) = -38.59
f(1) = 6.00
f(0) = 0.00
|
instruction
| 0
| 8,496
| 6
| 16,992
|
Tags: *special
Correct Solution:
```
stack = []
for _ in range(11):
stack += int(input()),
while stack:
v = stack.pop()
a = abs(v) ** (1/2)
b = v **3 * 5
r = a + b
if r > 400:
print('f({}) = MAGNA NIMIS!'.format(v))
else:
print('f({}) = {:.2f}'.format(v, r))
```
|
output
| 1
| 8,496
| 6
| 16,993
|
Provide tags and a correct Python 3 solution for this coding contest problem.
per nextum in unam tum XI conscribementis fac sic
vestibulo perlegementum da varo.
morde varo.
seqis cumula varum.
cis
per nextum in unam tum XI conscribementis fac sic
seqis decumulamenta da varo.
varum privamentum fodementum da aresulto.
varum tum III elevamentum tum V multiplicamentum da bresulto.
aresultum tum bresultum addementum da resulto.
si CD tum resultum non praestantiam fac sic
dictum sic f(%d) = %.2f cis tum varum tum resultum egresso describe.
novumversum egresso scribe.
cis
si CD tum resultum praestantiam fac sic
dictum sic f(%d) = MAGNA NIMIS! cis tum varum egresso describe.
novumversum egresso scribe.
cis
cis
Input
The input consists of several integers, one per line. Each integer is between -50 and 50, inclusive.
Output
As described in the problem statement.
Example
Input
0
1
-2
-3
-4
-5
-6
-7
-8
-9
10
Output
f(10) = MAGNA NIMIS!
f(-9) = -3642.00
f(-8) = -2557.17
f(-7) = -1712.35
f(-6) = -1077.55
f(-5) = -622.76
f(-4) = -318.00
f(-3) = -133.27
f(-2) = -38.59
f(1) = 6.00
f(0) = 0.00
|
instruction
| 0
| 8,501
| 6
| 17,002
|
Tags: *special
Correct Solution:
```
lip = ['0.00', '6.00', '-3642.00', '-2557.17', '-1712.35', '-1077.55', '-622.76', '-318.00', '-133.27', '-38.59', 'MAGNA NIMIS!']
s = []
for i in range(11):
s.append(int(input()))
s.reverse()
#print(s)
for i in range(0, 11):
a = s[i]**3*5
b = abs(s[i])**0.5
ans = a + b
print ('f(' + str(s[i]) + ") = ", end='')
if (ans < 400):
print('{:.2f}'.format(ans))
else:
print(' MAGNA NIMIS!')
```
|
output
| 1
| 8,501
| 6
| 17,003
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.
There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not.
Input
The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font:
<image>
Output
Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes).
Examples
Input
AHA
Output
YES
Input
Z
Output
NO
Input
XO
Output
NO
|
instruction
| 0
| 8,642
| 6
| 17,284
|
Tags: implementation
Correct Solution:
```
symmetric = 'AHIMOTUVWXY'
s = input()
if s == s[::-1] and all([x in symmetric for x in s]):
print('YES')
else:
print('NO')
```
|
output
| 1
| 8,642
| 6
| 17,285
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.
There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not.
Input
The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font:
<image>
Output
Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes).
Examples
Input
AHA
Output
YES
Input
Z
Output
NO
Input
XO
Output
NO
|
instruction
| 0
| 8,643
| 6
| 17,286
|
Tags: implementation
Correct Solution:
```
'''input
XO
'''
s = input()
if all(s[x] == s[~x] for x in range(len(s)//2)):
if any(y not in "AHIMOTUVWXY" for y in s[:len(s)//2+1]):
print("NO")
else:
print("YES")
else:
print("NO")
```
|
output
| 1
| 8,643
| 6
| 17,287
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.
There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not.
Input
The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font:
<image>
Output
Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes).
Examples
Input
AHA
Output
YES
Input
Z
Output
NO
Input
XO
Output
NO
|
instruction
| 0
| 8,644
| 6
| 17,288
|
Tags: implementation
Correct Solution:
```
def palindrome(n):
for i in range(0,len(n)):
if n[i] != n[-(i+1)]:
return 0
return 1
lessgo = ['a','h','i','m','o','t','u','v','w','x','y']
i = list(input())
for j in range(len(i)):
i[j] = i[j].lower()
mir = 1
for j in range(len(i)):
if i[j] not in lessgo:
mir = 0
if palindrome(i) == 1 and mir == 1:
print("YES")
else:
print("NO")
```
|
output
| 1
| 8,644
| 6
| 17,289
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.
There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not.
Input
The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font:
<image>
Output
Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes).
Examples
Input
AHA
Output
YES
Input
Z
Output
NO
Input
XO
Output
NO
|
instruction
| 0
| 8,645
| 6
| 17,290
|
Tags: implementation
Correct Solution:
```
s = input()
print('YES' if all(ch in 'AHIMOTUVWXY' for ch in s) and s==s[::-1] else 'NO')
```
|
output
| 1
| 8,645
| 6
| 17,291
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.
There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not.
Input
The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font:
<image>
Output
Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes).
Examples
Input
AHA
Output
YES
Input
Z
Output
NO
Input
XO
Output
NO
|
instruction
| 0
| 8,646
| 6
| 17,292
|
Tags: implementation
Correct Solution:
```
n=input()
i=0
k=len(n)-1
_b=True
while i<=k and _b:
if n[i]==n[k] and n[i] in ['A','H','I','M','O','T','U','V','W','X','Y']:
_b=True
i+=1
k-=1
else:
_b=False
if _b: print('YES')
else: print('NO')
```
|
output
| 1
| 8,646
| 6
| 17,293
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.
There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not.
Input
The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font:
<image>
Output
Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes).
Examples
Input
AHA
Output
YES
Input
Z
Output
NO
Input
XO
Output
NO
|
instruction
| 0
| 8,647
| 6
| 17,294
|
Tags: implementation
Correct Solution:
```
n=list(input())
m=n+[]
m.reverse()
l=['A','H','I','M','O','T','U','V','W','X','Y']
if(m==n ):
e=0
for i in range(len(n)):
if n[i] not in l:
print("NO")
e=1
break
if(e==0):
print("YES")
else:
print("NO")
```
|
output
| 1
| 8,647
| 6
| 17,295
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.
There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not.
Input
The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font:
<image>
Output
Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes).
Examples
Input
AHA
Output
YES
Input
Z
Output
NO
Input
XO
Output
NO
|
instruction
| 0
| 8,648
| 6
| 17,296
|
Tags: implementation
Correct Solution:
```
s = input()
a = ['A','H','I','M','O','T','U','V','W','X','Y']
a = set(a)
count = 0
if len(s)%2 == 0:
for i in range(int(len(s)/2)):
if s[i] == s[len(s)-i-1] and s[i] in a:
count = count + 1
else :
if s[int(len(s)/2)] in a:
for i in range(int(len(s)/2)):
if s[i] == s[len(s)-i-1] and s[i] in a:
count = count + 1
if count == int(len(s)/2) and s[0] in a :
print("YES")
else:
print("NO")
```
|
output
| 1
| 8,648
| 6
| 17,297
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?
The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.
There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not.
Input
The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font:
<image>
Output
Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes).
Examples
Input
AHA
Output
YES
Input
Z
Output
NO
Input
XO
Output
NO
|
instruction
| 0
| 8,649
| 6
| 17,298
|
Tags: implementation
Correct Solution:
```
def ic(s):
ss=set('AHIMOTUVWXY')
m=len(s)//2+1
for c in range(m):
if s[c]!=s[-(c+1)] or s[c] not in ss:
return 0
return 1
s='YES' if ic(input()) else 'NO'
print(s)
```
|
output
| 1
| 8,649
| 6
| 17,299
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Each employee of the "Blake Techologies" company uses a special messaging app "Blake Messenger". All the stuff likes this app and uses it constantly. However, some important futures are missing. For example, many users want to be able to search through the message history. It was already announced that the new feature will appear in the nearest update, when developers faced some troubles that only you may help them to solve.
All the messages are represented as a strings consisting of only lowercase English letters. In order to reduce the network load strings are represented in the special compressed form. Compression algorithm works as follows: string is represented as a concatenation of n blocks, each block containing only equal characters. One block may be described as a pair (li, ci), where li is the length of the i-th block and ci is the corresponding letter. Thus, the string s may be written as the sequence of pairs <image>.
Your task is to write the program, that given two compressed string t and s finds all occurrences of s in t. Developers know that there may be many such occurrences, so they only ask you to find the number of them. Note that p is the starting position of some occurrence of s in t if and only if tptp + 1...tp + |s| - 1 = s, where ti is the i-th character of string t.
Note that the way to represent the string in compressed form may not be unique. For example string "aaaa" may be given as <image>, <image>, <image>...
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 200 000) — the number of blocks in the strings t and s, respectively.
The second line contains the descriptions of n parts of string t in the format "li-ci" (1 ≤ li ≤ 1 000 000) — the length of the i-th part and the corresponding lowercase English letter.
The second line contains the descriptions of m parts of string s in the format "li-ci" (1 ≤ li ≤ 1 000 000) — the length of the i-th part and the corresponding lowercase English letter.
Output
Print a single integer — the number of occurrences of s in t.
Examples
Input
5 3
3-a 2-b 4-c 3-a 2-c
2-a 2-b 1-c
Output
1
Input
6 1
3-a 6-b 7-a 4-c 8-e 2-a
3-a
Output
6
Input
5 5
1-h 1-e 1-l 1-l 1-o
1-w 1-o 1-r 1-l 1-d
Output
0
Note
In the first sample, t = "aaabbccccaaacc", and string s = "aabbc". The only occurrence of string s in string t starts at position p = 2.
In the second sample, t = "aaabbbbbbaaaaaaacccceeeeeeeeaa", and s = "aaa". The occurrences of s in t start at positions p = 1, p = 10, p = 11, p = 12, p = 13 and p = 14.
|
instruction
| 0
| 8,687
| 6
| 17,374
|
Tags: data structures, hashing, implementation, string suffix structures, strings
Correct Solution:
```
#!/usr/bin/env python3
def cal_last(s):
n = len(s)
last = [-1]*(n+1)
i,j = 0,-1
while i<n:
while j!=-1 and s[i]!=s[j]:
j=last[j]
i,j = i+1,j+1
last[i] = j
return last
def kmp(p,t,last):
m = len(p)
n = len(t)
i = j = 0
rl = []
while i<n:
while j!=-1 and t[i]!=p[j]:
j=last[j]
i,j = i+1,j+1
if j>=m:
rl.append(i)
j=last[j]
return rl
def solve1(p,t):
pn,pc = p[0]
return sum([tn-pn+1 for tn,tc in t if tn>=pn and tc==pc])
def solve2(p,t):
return sum([t[i][0]>=p[0][0] and t[i][1]==p[0][1] and t[i+1][0]>=p[1][0] and t[i+1][1]==p[1][1] for i in range(len(t)-1)])
def compact(s):
t = [[int(s[0][:-2]),s[0][-1]]]
for i in range(1,len(s)):
n = int(s[i][:-2])
c = s[i][-1]
if c == t[-1][-1]:
t[-1][0] += n
else:
t.append([n,c])
return t
def f(p,t):
tt,pp = compact(t),compact(p)
if len(pp)==1:
return solve1(pp,tt)
if len(pp)==2:
return solve2(pp,tt)
last = cal_last(pp[1:-1])
ml = kmp(pp[1:-1],tt,last)
x = len(pp)-2
n = len(tt)
return sum([i-x>0 and tt[i-x-1][0]>=pp[0][0] and tt[i-x-1][1]==pp[0][1] and i<n and tt[i][0]>=pp[-1][0] and tt[i][1]==pp[-1][1] for i in ml])
_ = input()
t = input().split()
p = input().split()
print(f(p,t))
```
|
output
| 1
| 8,687
| 6
| 17,375
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Each employee of the "Blake Techologies" company uses a special messaging app "Blake Messenger". All the stuff likes this app and uses it constantly. However, some important futures are missing. For example, many users want to be able to search through the message history. It was already announced that the new feature will appear in the nearest update, when developers faced some troubles that only you may help them to solve.
All the messages are represented as a strings consisting of only lowercase English letters. In order to reduce the network load strings are represented in the special compressed form. Compression algorithm works as follows: string is represented as a concatenation of n blocks, each block containing only equal characters. One block may be described as a pair (li, ci), where li is the length of the i-th block and ci is the corresponding letter. Thus, the string s may be written as the sequence of pairs <image>.
Your task is to write the program, that given two compressed string t and s finds all occurrences of s in t. Developers know that there may be many such occurrences, so they only ask you to find the number of them. Note that p is the starting position of some occurrence of s in t if and only if tptp + 1...tp + |s| - 1 = s, where ti is the i-th character of string t.
Note that the way to represent the string in compressed form may not be unique. For example string "aaaa" may be given as <image>, <image>, <image>...
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 200 000) — the number of blocks in the strings t and s, respectively.
The second line contains the descriptions of n parts of string t in the format "li-ci" (1 ≤ li ≤ 1 000 000) — the length of the i-th part and the corresponding lowercase English letter.
The second line contains the descriptions of m parts of string s in the format "li-ci" (1 ≤ li ≤ 1 000 000) — the length of the i-th part and the corresponding lowercase English letter.
Output
Print a single integer — the number of occurrences of s in t.
Examples
Input
5 3
3-a 2-b 4-c 3-a 2-c
2-a 2-b 1-c
Output
1
Input
6 1
3-a 6-b 7-a 4-c 8-e 2-a
3-a
Output
6
Input
5 5
1-h 1-e 1-l 1-l 1-o
1-w 1-o 1-r 1-l 1-d
Output
0
Note
In the first sample, t = "aaabbccccaaacc", and string s = "aabbc". The only occurrence of string s in string t starts at position p = 2.
In the second sample, t = "aaabbbbbbaaaaaaacccceeeeeeeeaa", and s = "aaa". The occurrences of s in t start at positions p = 1, p = 10, p = 11, p = 12, p = 13 and p = 14.
|
instruction
| 0
| 8,688
| 6
| 17,376
|
Tags: data structures, hashing, implementation, string suffix structures, strings
Correct Solution:
```
def ziped(a):
p = []
for i in a:
x = int(i.split('-')[0])
y = i.split('-')[1]
if len(p) > 0 and p[-1][1] == y:
p[-1][0] += x
else:
p.append([x, y])
return p
def solve(a, b , c):
ans = 0
if len(b) == 1:
for token in a:
if c(token, b[0]):
ans += token[0] - b[0][0] + 1
return ans
if len(b) == 2:
for i in range(len(a) - 1):
if c(a[i], b[0]) and c(a[i + 1], b[-1]):
ans += 1
return ans
v = b[1 : -1] + [[100500, '#']] + a
p = [0] * len(v)
for i in range(1, len(v)):
j = p[i - 1]
while j > 0 and v[i] != v[j]:
j = p[j - 1]
if v[i] == v[j]:
j += 1
p[i] = j
for i in range(len(v) - 1):
if p[i] == len(b) - 2 and c(v[i - p[i]], b[0]) and c(v[i + 1], b[-1]):
ans += 1
return ans
n, m = map(int, input().split())
a = ziped(input().split())
b = ziped(input().split())
print(solve(a, b, lambda x, y: x[1] == y[1] and x[0] >= y[0]))
```
|
output
| 1
| 8,688
| 6
| 17,377
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Each employee of the "Blake Techologies" company uses a special messaging app "Blake Messenger". All the stuff likes this app and uses it constantly. However, some important futures are missing. For example, many users want to be able to search through the message history. It was already announced that the new feature will appear in the nearest update, when developers faced some troubles that only you may help them to solve.
All the messages are represented as a strings consisting of only lowercase English letters. In order to reduce the network load strings are represented in the special compressed form. Compression algorithm works as follows: string is represented as a concatenation of n blocks, each block containing only equal characters. One block may be described as a pair (li, ci), where li is the length of the i-th block and ci is the corresponding letter. Thus, the string s may be written as the sequence of pairs <image>.
Your task is to write the program, that given two compressed string t and s finds all occurrences of s in t. Developers know that there may be many such occurrences, so they only ask you to find the number of them. Note that p is the starting position of some occurrence of s in t if and only if tptp + 1...tp + |s| - 1 = s, where ti is the i-th character of string t.
Note that the way to represent the string in compressed form may not be unique. For example string "aaaa" may be given as <image>, <image>, <image>...
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 200 000) — the number of blocks in the strings t and s, respectively.
The second line contains the descriptions of n parts of string t in the format "li-ci" (1 ≤ li ≤ 1 000 000) — the length of the i-th part and the corresponding lowercase English letter.
The second line contains the descriptions of m parts of string s in the format "li-ci" (1 ≤ li ≤ 1 000 000) — the length of the i-th part and the corresponding lowercase English letter.
Output
Print a single integer — the number of occurrences of s in t.
Examples
Input
5 3
3-a 2-b 4-c 3-a 2-c
2-a 2-b 1-c
Output
1
Input
6 1
3-a 6-b 7-a 4-c 8-e 2-a
3-a
Output
6
Input
5 5
1-h 1-e 1-l 1-l 1-o
1-w 1-o 1-r 1-l 1-d
Output
0
Note
In the first sample, t = "aaabbccccaaacc", and string s = "aabbc". The only occurrence of string s in string t starts at position p = 2.
In the second sample, t = "aaabbbbbbaaaaaaacccceeeeeeeeaa", and s = "aaa". The occurrences of s in t start at positions p = 1, p = 10, p = 11, p = 12, p = 13 and p = 14.
|
instruction
| 0
| 8,689
| 6
| 17,378
|
Tags: data structures, hashing, implementation, string suffix structures, strings
Correct Solution:
```
def main():
input()
ts = []
for _ in 0, 1:
tmp = input().split()
a, x, l = tmp[0][-1], 0, []
for st in tmp:
y = int(st[:-2])
b = st[-1]
if a != b:
l.append(((x, a)))
x, a = y, b
else:
x += y
l.append(((x, a)))
ts.append(l)
t, s = ts
res, m, x, a, y, b = 0, len(s), *s[0], *s[-1]
if m == 1:
res = sum(y - x + 1 for y, b in t if a == b and x <= y)
elif m == 2:
i, u = 0, ' '
for j, v in t:
if a == u and b == v and x <= i and y <= j:
res += 1
i, u = j, v
else:
t[:0] = s[1: -1] + [(0, ' ')]
tmp = [0] * len(t)
for i, j in zip(range(1, len(t)), tmp):
while j > 0 and t[i] != t[j]:
j = tmp[j - 1]
tmp[i] = j + 1 if t[i] == t[j] else j
m -= 2
del tmp[-1]
for i, q in enumerate(tmp):
if q == m:
i, u, j, v = *t[i - q], *t[i + 1]
if a == u and b == v and x <= i and y <= j:
res += 1
print(res)
if __name__ == '__main__':
main()
```
|
output
| 1
| 8,689
| 6
| 17,379
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Each employee of the "Blake Techologies" company uses a special messaging app "Blake Messenger". All the stuff likes this app and uses it constantly. However, some important futures are missing. For example, many users want to be able to search through the message history. It was already announced that the new feature will appear in the nearest update, when developers faced some troubles that only you may help them to solve.
All the messages are represented as a strings consisting of only lowercase English letters. In order to reduce the network load strings are represented in the special compressed form. Compression algorithm works as follows: string is represented as a concatenation of n blocks, each block containing only equal characters. One block may be described as a pair (li, ci), where li is the length of the i-th block and ci is the corresponding letter. Thus, the string s may be written as the sequence of pairs <image>.
Your task is to write the program, that given two compressed string t and s finds all occurrences of s in t. Developers know that there may be many such occurrences, so they only ask you to find the number of them. Note that p is the starting position of some occurrence of s in t if and only if tptp + 1...tp + |s| - 1 = s, where ti is the i-th character of string t.
Note that the way to represent the string in compressed form may not be unique. For example string "aaaa" may be given as <image>, <image>, <image>...
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 200 000) — the number of blocks in the strings t and s, respectively.
The second line contains the descriptions of n parts of string t in the format "li-ci" (1 ≤ li ≤ 1 000 000) — the length of the i-th part and the corresponding lowercase English letter.
The second line contains the descriptions of m parts of string s in the format "li-ci" (1 ≤ li ≤ 1 000 000) — the length of the i-th part and the corresponding lowercase English letter.
Output
Print a single integer — the number of occurrences of s in t.
Examples
Input
5 3
3-a 2-b 4-c 3-a 2-c
2-a 2-b 1-c
Output
1
Input
6 1
3-a 6-b 7-a 4-c 8-e 2-a
3-a
Output
6
Input
5 5
1-h 1-e 1-l 1-l 1-o
1-w 1-o 1-r 1-l 1-d
Output
0
Note
In the first sample, t = "aaabbccccaaacc", and string s = "aabbc". The only occurrence of string s in string t starts at position p = 2.
In the second sample, t = "aaabbbbbbaaaaaaacccceeeeeeeeaa", and s = "aaa". The occurrences of s in t start at positions p = 1, p = 10, p = 11, p = 12, p = 13 and p = 14.
|
instruction
| 0
| 8,690
| 6
| 17,380
|
Tags: data structures, hashing, implementation, string suffix structures, strings
Correct Solution:
```
def ziped(a):
p = []
for i in a:
x = int(i.split('-')[0])
y = i.split('-')[1]
if len(p) > 0 and p[-1][1] == y:
p[-1][0] += x
else:
p.append([x, y])
return p
def solve(a, b , c):
ans = 0
if len(b) == 1:
for token in a:
#print("token",token)
if c(token, b[0]):
ans += token[0] - b[0][0] + 1
return ans
if len(b) == 2:
for i in range(len(a) - 1):
if c(a[i], b[0]) and c(a[i + 1], b[-1]):
ans += 1
return ans
v = b[1 : -1] + [[100500, '#']] + a
p = [0] * len(v)
for i in range(1, len(v)):
j = p[i - 1]
while j > 0 and v[i] != v[j]:
j = p[j - 1]
if v[i] == v[j]:
j += 1
p[i] = j
for i in range(len(v) - 1):
if p[i] == len(b) - 2 and c(v[i - p[i]], b[0]) and c(v[i + 1], b[-1]):
ans += 1
return ans
n, m = map(int, input().split())
a = ziped(input().split())
b = ziped(input().split())
print(solve(a, b, lambda x, y: x[1] == y[1] and x[0] >= y[0]))
```
|
output
| 1
| 8,690
| 6
| 17,381
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Each employee of the "Blake Techologies" company uses a special messaging app "Blake Messenger". All the stuff likes this app and uses it constantly. However, some important futures are missing. For example, many users want to be able to search through the message history. It was already announced that the new feature will appear in the nearest update, when developers faced some troubles that only you may help them to solve.
All the messages are represented as a strings consisting of only lowercase English letters. In order to reduce the network load strings are represented in the special compressed form. Compression algorithm works as follows: string is represented as a concatenation of n blocks, each block containing only equal characters. One block may be described as a pair (li, ci), where li is the length of the i-th block and ci is the corresponding letter. Thus, the string s may be written as the sequence of pairs <image>.
Your task is to write the program, that given two compressed string t and s finds all occurrences of s in t. Developers know that there may be many such occurrences, so they only ask you to find the number of them. Note that p is the starting position of some occurrence of s in t if and only if tptp + 1...tp + |s| - 1 = s, where ti is the i-th character of string t.
Note that the way to represent the string in compressed form may not be unique. For example string "aaaa" may be given as <image>, <image>, <image>...
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 200 000) — the number of blocks in the strings t and s, respectively.
The second line contains the descriptions of n parts of string t in the format "li-ci" (1 ≤ li ≤ 1 000 000) — the length of the i-th part and the corresponding lowercase English letter.
The second line contains the descriptions of m parts of string s in the format "li-ci" (1 ≤ li ≤ 1 000 000) — the length of the i-th part and the corresponding lowercase English letter.
Output
Print a single integer — the number of occurrences of s in t.
Examples
Input
5 3
3-a 2-b 4-c 3-a 2-c
2-a 2-b 1-c
Output
1
Input
6 1
3-a 6-b 7-a 4-c 8-e 2-a
3-a
Output
6
Input
5 5
1-h 1-e 1-l 1-l 1-o
1-w 1-o 1-r 1-l 1-d
Output
0
Note
In the first sample, t = "aaabbccccaaacc", and string s = "aabbc". The only occurrence of string s in string t starts at position p = 2.
In the second sample, t = "aaabbbbbbaaaaaaacccceeeeeeeeaa", and s = "aaa". The occurrences of s in t start at positions p = 1, p = 10, p = 11, p = 12, p = 13 and p = 14.
|
instruction
| 0
| 8,691
| 6
| 17,382
|
Tags: data structures, hashing, implementation, string suffix structures, strings
Correct Solution:
```
def compress(bstr):
pk, pc = None, None
for block in bstr:
if pc is None:
pk, pc = block
elif pc == block[1]:
pk += block[0]
else:
yield pk, pc
pk, pc = block
if pc is not None:
yield pk, pc
def find1(text, query):
(bk, bc), = query
return sum(k-bk+1 for k, c in text if c == bc and k >= bk)
class Query:
def __init__(self, query):
self._query = query
self._len = len(query)
self._suffixes = {}
def precompute(self):
for i in range(self._len-1):
self._suffix(i)
def _suffix(self, i, pblock=None):
if not i:
return None
if pblock is None and i is not None:
pblock = self._query[i]
if (i, pblock) in self._suffixes:
return self._suffixes[i, pblock]
else:
sfx = self.next(self._suffix(i-1), pblock)
self._suffixes[i, pblock] = sfx
return sfx
def _match(self, i, block):
if i == 0 or i == self._len -1:
return (block[1] == self._query[i][1]
and block[0] >= self._query[i][0])
else:
return block == self._query[i]
def next(self, i, block, pblock=None):
while True:
if i is None:
return 0 if self._match(0, block) else None
elif i < self._len-1:
if self._match(i+1, block):
return i+1
else:
i = self._suffix(i)
else:
i = self._suffix(i, pblock)
pblock = None
def is_match(self, i):
return i == self._len-1
def find2(text, query):
qobj = Query(query)
qobj.precompute()
i = None
pblock = None
c = 0
for block in text:
i, pblock = qobj.next(i, block, pblock), block
if qobj.is_match(i):
c += 1
return c
def find(text, query):
text = list(compress(text))
query = list(compress(query))
return (find1 if len(query) == 1 else find2)(text, query)
def parse_block(s):
k, c = s.split('-')
return int(k), c
def get_input():
n, m = map(int, input().split())
text = list(map(parse_block, input().split()))
assert len(text) == n
query = list(map(parse_block, input().split()))
assert len(query) == m
return text, query
if __name__ == '__main__':
print(find(*get_input()))
```
|
output
| 1
| 8,691
| 6
| 17,383
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Each employee of the "Blake Techologies" company uses a special messaging app "Blake Messenger". All the stuff likes this app and uses it constantly. However, some important futures are missing. For example, many users want to be able to search through the message history. It was already announced that the new feature will appear in the nearest update, when developers faced some troubles that only you may help them to solve.
All the messages are represented as a strings consisting of only lowercase English letters. In order to reduce the network load strings are represented in the special compressed form. Compression algorithm works as follows: string is represented as a concatenation of n blocks, each block containing only equal characters. One block may be described as a pair (li, ci), where li is the length of the i-th block and ci is the corresponding letter. Thus, the string s may be written as the sequence of pairs <image>.
Your task is to write the program, that given two compressed string t and s finds all occurrences of s in t. Developers know that there may be many such occurrences, so they only ask you to find the number of them. Note that p is the starting position of some occurrence of s in t if and only if tptp + 1...tp + |s| - 1 = s, where ti is the i-th character of string t.
Note that the way to represent the string in compressed form may not be unique. For example string "aaaa" may be given as <image>, <image>, <image>...
Input
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 200 000) — the number of blocks in the strings t and s, respectively.
The second line contains the descriptions of n parts of string t in the format "li-ci" (1 ≤ li ≤ 1 000 000) — the length of the i-th part and the corresponding lowercase English letter.
The second line contains the descriptions of m parts of string s in the format "li-ci" (1 ≤ li ≤ 1 000 000) — the length of the i-th part and the corresponding lowercase English letter.
Output
Print a single integer — the number of occurrences of s in t.
Examples
Input
5 3
3-a 2-b 4-c 3-a 2-c
2-a 2-b 1-c
Output
1
Input
6 1
3-a 6-b 7-a 4-c 8-e 2-a
3-a
Output
6
Input
5 5
1-h 1-e 1-l 1-l 1-o
1-w 1-o 1-r 1-l 1-d
Output
0
Note
In the first sample, t = "aaabbccccaaacc", and string s = "aabbc". The only occurrence of string s in string t starts at position p = 2.
In the second sample, t = "aaabbbbbbaaaaaaacccceeeeeeeeaa", and s = "aaa". The occurrences of s in t start at positions p = 1, p = 10, p = 11, p = 12, p = 13 and p = 14.
|
instruction
| 0
| 8,692
| 6
| 17,384
|
Tags: data structures, hashing, implementation, string suffix structures, strings
Correct Solution:
```
def compress(bstr):
pk, pc = None, None
for block in bstr:
if pc is None:
pk, pc = block
elif pc == block[1]:
pk += block[0]
else:
yield pk, pc
pk, pc = block
if pc is not None:
yield pk, pc
def find1(text, query):
(bk, bc), = query
return sum(k-bk+1 for k, c in text if c == bc and k >= bk)
class Query:
def __init__(self, query):
self._query = query
self._len = len(query)
self._suffixes = [None]
def _suffix(self, i, pblock=None):
if i is None:
return None
for j in range(len(self._suffixes), min(i+1, self._len-1)):
self._suffixes.append(
self.next(self._suffixes[j-1], self._query[j]))
if i < self._len - 1:
return self._suffixes[i]
else:
return self.next(self._suffixes[i-1], pblock)
def _match(self, i, block):
if i == 0 or i == self._len -1:
return (block[1] == self._query[i][1]
and block[0] >= self._query[i][0])
else:
return block == self._query[i]
def next(self, i, block, pblock=None):
while True:
if i is None:
return 0 if self._match(0, block) else None
elif i < self._len-1:
if self._match(i+1, block):
return i+1
else:
i = self._suffix(i)
else:
i = self._suffix(i, pblock)
pblock = None
def is_match(self, i):
return i == self._len-1
def find2(text, query):
qobj = Query(query)
i = None
pblock = None
c = 0
for block in text:
i, pblock = qobj.next(i, block, pblock), block
if qobj.is_match(i):
c += 1
return c
def find(text, query):
text = list(compress(text))
query = list(compress(query))
return (find1 if len(query) == 1 else find2)(text, query)
def parse_block(s):
k, c = s.split('-')
return int(k), c
def get_input():
n, m = map(int, input().split())
text = list(map(parse_block, input().split()))
assert len(text) == n
query = list(map(parse_block, input().split()))
assert len(query) == m
return text, query
if __name__ == '__main__':
print(find(*get_input()))
```
|
output
| 1
| 8,692
| 6
| 17,385
|
Provide tags and a correct Python 3 solution for this coding contest problem.
This problem is different from the hard version. In this version Ujan makes exactly one exchange. You can hack this problem only if you solve both problems.
After struggling and failing many times, Ujan decided to try to clean up his house again. He decided to get his strings in order first.
Ujan has two distinct strings s and t of length n consisting of only of lowercase English characters. He wants to make them equal. Since Ujan is lazy, he will perform the following operation exactly once: he takes two positions i and j (1 ≤ i,j ≤ n, the values i and j can be equal or different), and swaps the characters s_i and t_j. Can he succeed?
Note that he has to perform this operation exactly once. He has to perform this operation.
Input
The first line contains a single integer k (1 ≤ k ≤ 10), the number of test cases.
For each of the test cases, the first line contains a single integer n (2 ≤ n ≤ 10^4), the length of the strings s and t.
Each of the next two lines contains the strings s and t, each having length exactly n. The strings consist only of lowercase English letters. It is guaranteed that strings are different.
Output
For each test case, output "Yes" if Ujan can make the two strings equal and "No" otherwise.
You can print each letter in any case (upper or lower).
Example
Input
4
5
souse
houhe
3
cat
dog
2
aa
az
3
abc
bca
Output
Yes
No
No
No
Note
In the first test case, Ujan can swap characters s_1 and t_4, obtaining the word "house".
In the second test case, it is not possible to make the strings equal using exactly one swap of s_i and t_j.
|
instruction
| 0
| 9,204
| 6
| 18,408
|
Tags: strings
Correct Solution:
```
k = int(input())
for _ in range(k):
n = int(input())
s0 = input()
t0 = input()
s = [s0[i] for i in range(n)]
t = [t0[i] for i in range(n)]
ans = "Yes"
ansArr = []
for i in range(n):
if s[i] == t[i]:
continue
elif s[i] in s[i+1:]:
ind = s.index(s[i], i+1, n)
ansArr += [[ind+1, i+1]]
s[ind], t[i] = t[i], s[ind]
elif s[i] in t[i+1:]:
ind = t.index(s[i], i+1, n)
ansArr += [[i+1+1, ind+1]]
s[i+1], t[ind] = t[ind], s[i+1]
ansArr += [[i+1+1, i+1]]
s[i+1], t[i] = t[i], s[i+1]
else:
ans = "No"
break
print(ans)
if ans == "Yes":
print(len(ansArr))
for item in ansArr:
print(item[0], item[1])
```
|
output
| 1
| 9,204
| 6
| 18,409
|
Provide tags and a correct Python 3 solution for this coding contest problem.
This problem is different from the hard version. In this version Ujan makes exactly one exchange. You can hack this problem only if you solve both problems.
After struggling and failing many times, Ujan decided to try to clean up his house again. He decided to get his strings in order first.
Ujan has two distinct strings s and t of length n consisting of only of lowercase English characters. He wants to make them equal. Since Ujan is lazy, he will perform the following operation exactly once: he takes two positions i and j (1 ≤ i,j ≤ n, the values i and j can be equal or different), and swaps the characters s_i and t_j. Can he succeed?
Note that he has to perform this operation exactly once. He has to perform this operation.
Input
The first line contains a single integer k (1 ≤ k ≤ 10), the number of test cases.
For each of the test cases, the first line contains a single integer n (2 ≤ n ≤ 10^4), the length of the strings s and t.
Each of the next two lines contains the strings s and t, each having length exactly n. The strings consist only of lowercase English letters. It is guaranteed that strings are different.
Output
For each test case, output "Yes" if Ujan can make the two strings equal and "No" otherwise.
You can print each letter in any case (upper or lower).
Example
Input
4
5
souse
houhe
3
cat
dog
2
aa
az
3
abc
bca
Output
Yes
No
No
No
Note
In the first test case, Ujan can swap characters s_1 and t_4, obtaining the word "house".
In the second test case, it is not possible to make the strings equal using exactly one swap of s_i and t_j.
|
instruction
| 0
| 9,205
| 6
| 18,410
|
Tags: strings
Correct Solution:
```
Q = int(input())
Query = []
for _ in range(Q):
N = int(input())
S1 = list(input())
S2 = list(input())
Query.append((N, S1, S2))
for N, S1, S2 in Query:
C = []
for i in range(N):
s1, s2 = S1[i], S2[i]
if s1 != s2:
C.append((s1, s2))
if len(C) == 0:
print('Yes')
elif len(C) == 2:
if C[0][0] == C[1][0] and C[0][1] == C[1][1]:
print('Yes')
else:
print("No")
else:
print("No")
```
|
output
| 1
| 9,205
| 6
| 18,411
|
Provide tags and a correct Python 3 solution for this coding contest problem.
This problem is different from the hard version. In this version Ujan makes exactly one exchange. You can hack this problem only if you solve both problems.
After struggling and failing many times, Ujan decided to try to clean up his house again. He decided to get his strings in order first.
Ujan has two distinct strings s and t of length n consisting of only of lowercase English characters. He wants to make them equal. Since Ujan is lazy, he will perform the following operation exactly once: he takes two positions i and j (1 ≤ i,j ≤ n, the values i and j can be equal or different), and swaps the characters s_i and t_j. Can he succeed?
Note that he has to perform this operation exactly once. He has to perform this operation.
Input
The first line contains a single integer k (1 ≤ k ≤ 10), the number of test cases.
For each of the test cases, the first line contains a single integer n (2 ≤ n ≤ 10^4), the length of the strings s and t.
Each of the next two lines contains the strings s and t, each having length exactly n. The strings consist only of lowercase English letters. It is guaranteed that strings are different.
Output
For each test case, output "Yes" if Ujan can make the two strings equal and "No" otherwise.
You can print each letter in any case (upper or lower).
Example
Input
4
5
souse
houhe
3
cat
dog
2
aa
az
3
abc
bca
Output
Yes
No
No
No
Note
In the first test case, Ujan can swap characters s_1 and t_4, obtaining the word "house".
In the second test case, it is not possible to make the strings equal using exactly one swap of s_i and t_j.
|
instruction
| 0
| 9,206
| 6
| 18,412
|
Tags: strings
Correct Solution:
```
import sys
import itertools
import math
import collections
from collections import Counter
#########################
# imgur.com/Pkt7iIf.png #
#########################
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 * 2, n + 1, p):
prime[i] = False
p += 1
prime[0] = prime[1] = False
r = [p for p in range(n + 1) if prime[p]]
return r
def divs(n, start=1):
r = []
for i in range(start, int(math.sqrt(n) + 1)):
if (n % i == 0):
if (n / i == i):
r.append(i)
else:
r.extend([i, n // i])
return r
def ceil(n, k): return n // k + (n % k != 0)
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(map(int, input().split()))
def lcm(a, b): return abs(a * b) // math.gcd(a, b)
def prr(a, sep=' '): print(sep.join(map(str, a)))
def dd(): return collections.defaultdict(int)
def pos(s):
return ord(s) - 97
t = ii()
for _ in range(t):
n = ii()
a = input()
b = input()
if a == b:
print('Yes\n1\n1 1\n')
continue
c = Counter(a + b)
if any(c[i] % 2 for i in c):
print('No')
continue
a = [i for i in a]
b = [i for i in b]
swaps = []
for i in range(n - 1):
if a[i] != b[i]:
f = 1
for j in range(i + 1, n):
if a[i] == a[j]:
a[j], b[i] = b[i], a[j]
swaps.append(f'{j + 1} {i + 1}')
f = 0
break
if f:
for j in range(i + 1, n):
if a[i] == b[j]:
a[i + 1], b[j] = b[j], a[i + 1]
a[i + 1], b[i] = b[i], a[i + 1]
swaps.append(f'{i + 2} {j + 1}')
swaps.append(f'{i + 2} {i + 1}')
break
print('Yes')
print(len(swaps))
prr(swaps, '\n')
```
|
output
| 1
| 9,206
| 6
| 18,413
|
Provide tags and a correct Python 3 solution for this coding contest problem.
This problem is different from the hard version. In this version Ujan makes exactly one exchange. You can hack this problem only if you solve both problems.
After struggling and failing many times, Ujan decided to try to clean up his house again. He decided to get his strings in order first.
Ujan has two distinct strings s and t of length n consisting of only of lowercase English characters. He wants to make them equal. Since Ujan is lazy, he will perform the following operation exactly once: he takes two positions i and j (1 ≤ i,j ≤ n, the values i and j can be equal or different), and swaps the characters s_i and t_j. Can he succeed?
Note that he has to perform this operation exactly once. He has to perform this operation.
Input
The first line contains a single integer k (1 ≤ k ≤ 10), the number of test cases.
For each of the test cases, the first line contains a single integer n (2 ≤ n ≤ 10^4), the length of the strings s and t.
Each of the next two lines contains the strings s and t, each having length exactly n. The strings consist only of lowercase English letters. It is guaranteed that strings are different.
Output
For each test case, output "Yes" if Ujan can make the two strings equal and "No" otherwise.
You can print each letter in any case (upper or lower).
Example
Input
4
5
souse
houhe
3
cat
dog
2
aa
az
3
abc
bca
Output
Yes
No
No
No
Note
In the first test case, Ujan can swap characters s_1 and t_4, obtaining the word "house".
In the second test case, it is not possible to make the strings equal using exactly one swap of s_i and t_j.
|
instruction
| 0
| 9,207
| 6
| 18,414
|
Tags: strings
Correct Solution:
```
import sys
input = lambda: sys.stdin.readline().strip()
k = int(input())
for i in range(k):
n = int(input())
s = list(input())
t = list(input())
res = []
for i in range(n):
try:
found = s.index(s[i], i+1)
s[found], t[i] = t[i], s[found]
res.append((found, i))
except:
try:
found = t.index(s[i], i)
t[found], s[found] = s[found], t[found]
res.append((found, found))
s[found], t[i] = t[i], s[found]
res.append((found, i))
except:
print('No')
break
else:
print('Yes')
print(len(res))
for i in res:
print(i[0]+1, i[1]+1)
```
|
output
| 1
| 9,207
| 6
| 18,415
|
Provide tags and a correct Python 3 solution for this coding contest problem.
This problem is different from the hard version. In this version Ujan makes exactly one exchange. You can hack this problem only if you solve both problems.
After struggling and failing many times, Ujan decided to try to clean up his house again. He decided to get his strings in order first.
Ujan has two distinct strings s and t of length n consisting of only of lowercase English characters. He wants to make them equal. Since Ujan is lazy, he will perform the following operation exactly once: he takes two positions i and j (1 ≤ i,j ≤ n, the values i and j can be equal or different), and swaps the characters s_i and t_j. Can he succeed?
Note that he has to perform this operation exactly once. He has to perform this operation.
Input
The first line contains a single integer k (1 ≤ k ≤ 10), the number of test cases.
For each of the test cases, the first line contains a single integer n (2 ≤ n ≤ 10^4), the length of the strings s and t.
Each of the next two lines contains the strings s and t, each having length exactly n. The strings consist only of lowercase English letters. It is guaranteed that strings are different.
Output
For each test case, output "Yes" if Ujan can make the two strings equal and "No" otherwise.
You can print each letter in any case (upper or lower).
Example
Input
4
5
souse
houhe
3
cat
dog
2
aa
az
3
abc
bca
Output
Yes
No
No
No
Note
In the first test case, Ujan can swap characters s_1 and t_4, obtaining the word "house".
In the second test case, it is not possible to make the strings equal using exactly one swap of s_i and t_j.
|
instruction
| 0
| 9,208
| 6
| 18,416
|
Tags: strings
Correct Solution:
```
tc = int(input())
for t in range(tc) :
n = int(input())
s = [char for char in input()]
t = [char for char in input()]
freq = {}
for i in range(n) :
if s[i] in freq.keys() :
freq[s[i]] += 1
else :
freq[s[i]] = 1
if t[i] in freq.keys() :
freq[t[i]] += 1
else :
freq[t[i]] = 1
isPossible = True
for key in freq.keys() :
if freq[key] % 2 != 0 :
isPossible = False
if isPossible == False :
print("No")
continue
print("Yes")
moves = []
for i in range(n) :
if s[i] == t[i] :
continue
else :
found = False
for j in range(i+1, n) :
if s[j] == s[i] :
moves.append((j, i))
s[j] = t[i]
t[i] = s[i]
found = True
break
if found :
continue
for j in range(i+1, n) :
if t[j] == s[i] :
moves.append((j, j))
temp = s[j]
s[j] = t[j]
t[j] = temp
moves.append((j, i))
s[j] = t[i]
t[i] = s[i]
break
print(len(moves))
for i, j in moves :
print(str(i+1) + " " + str(j+1))
```
|
output
| 1
| 9,208
| 6
| 18,417
|
Provide tags and a correct Python 3 solution for this coding contest problem.
This problem is different from the hard version. In this version Ujan makes exactly one exchange. You can hack this problem only if you solve both problems.
After struggling and failing many times, Ujan decided to try to clean up his house again. He decided to get his strings in order first.
Ujan has two distinct strings s and t of length n consisting of only of lowercase English characters. He wants to make them equal. Since Ujan is lazy, he will perform the following operation exactly once: he takes two positions i and j (1 ≤ i,j ≤ n, the values i and j can be equal or different), and swaps the characters s_i and t_j. Can he succeed?
Note that he has to perform this operation exactly once. He has to perform this operation.
Input
The first line contains a single integer k (1 ≤ k ≤ 10), the number of test cases.
For each of the test cases, the first line contains a single integer n (2 ≤ n ≤ 10^4), the length of the strings s and t.
Each of the next two lines contains the strings s and t, each having length exactly n. The strings consist only of lowercase English letters. It is guaranteed that strings are different.
Output
For each test case, output "Yes" if Ujan can make the two strings equal and "No" otherwise.
You can print each letter in any case (upper or lower).
Example
Input
4
5
souse
houhe
3
cat
dog
2
aa
az
3
abc
bca
Output
Yes
No
No
No
Note
In the first test case, Ujan can swap characters s_1 and t_4, obtaining the word "house".
In the second test case, it is not possible to make the strings equal using exactly one swap of s_i and t_j.
|
instruction
| 0
| 9,209
| 6
| 18,418
|
Tags: strings
Correct Solution:
```
for _ in range(int(input())):
n=int(input())
a=list(input())
b=list(input())
ans=[]
d1=dict()
d2=dict()
for i in range(n):
try:
d1[a[i]].add(i)
except:
d1[a[i]]=set([(i)])
try:
d2[b[i]].add(i)
except:
d2[b[i]]=set([i])
# print(d1)
f1=0
count=0
for i in range(n):
d1[a[i]].remove(i)
d2[b[i]].remove(i)
if a[i]!=b[i]:
flag=0
for j in d1[a[i]]:
if a[j]!=b[j] :
ans.append([j+1,i+1])
count+=1
d1[a[j]].remove(j)
a[j],b[i]=b[i],a[j]
try:
d1[a[j]].add(j)
except:
d1[a[j]]=set([(j)])
try:
d2[b[j]].add(j)
except:
d2[b[j]]=set([j])
flag=1
break
if flag==0:
if a[i] in d2:
for j in d2[a[i]]:
if a[j]!=b[j]:
ans.append([j+1,j+1])
d1[a[j]].remove(j)
d2[b[j]].remove(j)
a[j],b[j]=b[j],a[j]
count+=2
# print(a,b)
try:
d1[a[j]].add(j)
except:
d1[a[j]]=set([(j)])
try:
d2[b[j]].add(j)
except:
d2[b[j]]=set([j])
d1[a[j]].remove(j)
ans.append([j+1,i+1])
a[j],b[i]=b[i],a[j]
# print(i,j,a,b)
try:
d1[a[j]].add(j)
except:
d1[a[j]]=set([(j)])
try:
d2[b[j]].add(j)
except:
d2[b[j]]=set([j])
flag=1
break
if flag==0 or count>1:
f1=1
break
if f1==0:
print("Yes")
# print(len(ans))
#for i in ans:
# print(*i)
else:
print("No")
# print(a)
# print(b)
```
|
output
| 1
| 9,209
| 6
| 18,419
|
Provide tags and a correct Python 3 solution for this coding contest problem.
This problem is different from the hard version. In this version Ujan makes exactly one exchange. You can hack this problem only if you solve both problems.
After struggling and failing many times, Ujan decided to try to clean up his house again. He decided to get his strings in order first.
Ujan has two distinct strings s and t of length n consisting of only of lowercase English characters. He wants to make them equal. Since Ujan is lazy, he will perform the following operation exactly once: he takes two positions i and j (1 ≤ i,j ≤ n, the values i and j can be equal or different), and swaps the characters s_i and t_j. Can he succeed?
Note that he has to perform this operation exactly once. He has to perform this operation.
Input
The first line contains a single integer k (1 ≤ k ≤ 10), the number of test cases.
For each of the test cases, the first line contains a single integer n (2 ≤ n ≤ 10^4), the length of the strings s and t.
Each of the next two lines contains the strings s and t, each having length exactly n. The strings consist only of lowercase English letters. It is guaranteed that strings are different.
Output
For each test case, output "Yes" if Ujan can make the two strings equal and "No" otherwise.
You can print each letter in any case (upper or lower).
Example
Input
4
5
souse
houhe
3
cat
dog
2
aa
az
3
abc
bca
Output
Yes
No
No
No
Note
In the first test case, Ujan can swap characters s_1 and t_4, obtaining the word "house".
In the second test case, it is not possible to make the strings equal using exactly one swap of s_i and t_j.
|
instruction
| 0
| 9,210
| 6
| 18,420
|
Tags: strings
Correct Solution:
```
k = int(input())
for _ in range(k):
n = int(input())
s = list(input().strip())
t = list(input().strip())
d = {}
for i in range(n):
if s[i]!=t[i]:
try:
d[(s[i],t[i])] += 1
except:
d[(s[i],t[i])] = 1
if len(d)==1 and list(d.values())[0]==2:
print('Yes')
else:
print('No')
```
|
output
| 1
| 9,210
| 6
| 18,421
|
Provide tags and a correct Python 3 solution for this coding contest problem.
This problem is different from the hard version. In this version Ujan makes exactly one exchange. You can hack this problem only if you solve both problems.
After struggling and failing many times, Ujan decided to try to clean up his house again. He decided to get his strings in order first.
Ujan has two distinct strings s and t of length n consisting of only of lowercase English characters. He wants to make them equal. Since Ujan is lazy, he will perform the following operation exactly once: he takes two positions i and j (1 ≤ i,j ≤ n, the values i and j can be equal or different), and swaps the characters s_i and t_j. Can he succeed?
Note that he has to perform this operation exactly once. He has to perform this operation.
Input
The first line contains a single integer k (1 ≤ k ≤ 10), the number of test cases.
For each of the test cases, the first line contains a single integer n (2 ≤ n ≤ 10^4), the length of the strings s and t.
Each of the next two lines contains the strings s and t, each having length exactly n. The strings consist only of lowercase English letters. It is guaranteed that strings are different.
Output
For each test case, output "Yes" if Ujan can make the two strings equal and "No" otherwise.
You can print each letter in any case (upper or lower).
Example
Input
4
5
souse
houhe
3
cat
dog
2
aa
az
3
abc
bca
Output
Yes
No
No
No
Note
In the first test case, Ujan can swap characters s_1 and t_4, obtaining the word "house".
In the second test case, it is not possible to make the strings equal using exactly one swap of s_i and t_j.
|
instruction
| 0
| 9,211
| 6
| 18,422
|
Tags: strings
Correct Solution:
```
for i in range(int(input())):
n=int(input())
s1=list(input())
s2=list(input())
ans="No"
x=-1
for j in range(n):
if(s1[j]!=s2[j]):
x=j
break
if(x==-1):
a=[0]*26
b=[0]*26
for j in range(n):
a[ord(s1[j])-97]+=1
b[ord(s2[j])-97]+=1
for j in range(26):
if(a[j]>1):
ans="Yes"
print(ans)
else:
aa=""
bb=""
for j in range(n):
if(s1[j]!=s2[j]):
aa+=s1[j]
bb+=s2[j]
if(len(aa)==2):
if(aa[0]==aa[1] and bb[0]==bb[1]):
print("Yes")
else:
print("No")
else:
print("No")
```
|
output
| 1
| 9,211
| 6
| 18,423
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Vera adores poems. All the poems Vera knows are divided into quatrains (groups of four lines) and in each quatrain some lines contain rhymes.
Let's consider that all lines in the poems consist of lowercase Latin letters (without spaces). Letters "a", "e", "i", "o", "u" are considered vowels.
Two lines rhyme if their suffixes that start from the k-th vowels (counting from the end) match. If a line has less than k vowels, then such line can't rhyme with any other line. For example, if k = 1, lines commit and hermit rhyme (the corresponding suffixes equal it), and if k = 2, they do not rhyme (ommit ≠ ermit).
Today on a literature lesson Vera learned that quatrains can contain four different schemes of rhymes, namely the following ones (the same letters stand for rhyming lines):
* Clerihew (aabb);
* Alternating (abab);
* Enclosed (abba).
If all lines of a quatrain pairwise rhyme, then the quatrain can belong to any rhyme scheme (this situation is represented by aaaa).
If all quatrains of a poem belong to the same rhyme scheme, then we can assume that the whole poem belongs to this rhyme scheme. If in each quatrain all lines pairwise rhyme, then the rhyme scheme of the poem is aaaa. Let us note that it doesn't matter whether lines from different quatrains rhyme with each other or not. In other words, it is possible that different quatrains aren't connected by a rhyme.
Vera got a long poem as a home task. The girl has to analyse it and find the poem rhyme scheme. Help Vera cope with the task.
Input
The first line contains two integers n and k (1 ≤ n ≤ 2500, 1 ≤ k ≤ 5) — the number of quatrains in the poem and the vowel's number, correspondingly. Next 4n lines contain the poem. Each line is not empty and only consists of small Latin letters. The total length of the lines does not exceed 104.
If we assume that the lines are numbered starting from 1, then the first quatrain contains lines number 1, 2, 3, 4; the second one contains lines number 5, 6, 7, 8; and so on.
Output
Print the rhyme scheme of the poem as "aabb", "abab", "abba", "aaaa"; or "NO" if the poem does not belong to any of the above mentioned schemes.
Examples
Input
1 1
day
may
sun
fun
Output
aabb
Input
1 1
day
may
gray
way
Output
aaaa
Input
2 1
a
a
a
a
a
a
e
e
Output
aabb
Input
2 1
day
may
sun
fun
test
hill
fest
thrill
Output
NO
Note
In the last sample both quatrains have rhymes but finding the common scheme is impossible, so the answer is "NO".
|
instruction
| 0
| 9,265
| 6
| 18,530
|
Tags: implementation
Correct Solution:
```
#!/usr/bin/python3
N,K = [int(x) for x in input().strip().split()]
#"aabb", "abab", "abba", "aaaa";
vowels = ['a','e','i','o','u']
schm = []
def check(val):
for x in schm:
if x == val or x == 4:continue
return False
return True
def parse(line):
k = K
for x in range(-1,-len(line)-1,-1):
if line[x] in vowels: k -= 1
if k == 0:
return line[x:]
print("NO")
exit(0)
for x in range(N):
lines = []
for y in range(4):
lines += [parse(input().strip().split()[0])]
if lines[0] == lines[1] == lines[2] == lines[3]:schm += [4]
elif lines[0] == lines[1] and lines[2] == lines[3]:schm += [1]
elif lines[0] == lines[2] and lines[1] == lines[3]:schm += [2]
elif lines[0] == lines[3] and lines[1] == lines[2]:schm += [3]
else:
print("NO")
exit(0)
if check(4):print("aaaa")
elif check(1):print("aabb")
elif check(2):print("abab")
elif check(3):print("abba")
else:print("NO")
```
|
output
| 1
| 9,265
| 6
| 18,531
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Vera adores poems. All the poems Vera knows are divided into quatrains (groups of four lines) and in each quatrain some lines contain rhymes.
Let's consider that all lines in the poems consist of lowercase Latin letters (without spaces). Letters "a", "e", "i", "o", "u" are considered vowels.
Two lines rhyme if their suffixes that start from the k-th vowels (counting from the end) match. If a line has less than k vowels, then such line can't rhyme with any other line. For example, if k = 1, lines commit and hermit rhyme (the corresponding suffixes equal it), and if k = 2, they do not rhyme (ommit ≠ ermit).
Today on a literature lesson Vera learned that quatrains can contain four different schemes of rhymes, namely the following ones (the same letters stand for rhyming lines):
* Clerihew (aabb);
* Alternating (abab);
* Enclosed (abba).
If all lines of a quatrain pairwise rhyme, then the quatrain can belong to any rhyme scheme (this situation is represented by aaaa).
If all quatrains of a poem belong to the same rhyme scheme, then we can assume that the whole poem belongs to this rhyme scheme. If in each quatrain all lines pairwise rhyme, then the rhyme scheme of the poem is aaaa. Let us note that it doesn't matter whether lines from different quatrains rhyme with each other or not. In other words, it is possible that different quatrains aren't connected by a rhyme.
Vera got a long poem as a home task. The girl has to analyse it and find the poem rhyme scheme. Help Vera cope with the task.
Input
The first line contains two integers n and k (1 ≤ n ≤ 2500, 1 ≤ k ≤ 5) — the number of quatrains in the poem and the vowel's number, correspondingly. Next 4n lines contain the poem. Each line is not empty and only consists of small Latin letters. The total length of the lines does not exceed 104.
If we assume that the lines are numbered starting from 1, then the first quatrain contains lines number 1, 2, 3, 4; the second one contains lines number 5, 6, 7, 8; and so on.
Output
Print the rhyme scheme of the poem as "aabb", "abab", "abba", "aaaa"; or "NO" if the poem does not belong to any of the above mentioned schemes.
Examples
Input
1 1
day
may
sun
fun
Output
aabb
Input
1 1
day
may
gray
way
Output
aaaa
Input
2 1
a
a
a
a
a
a
e
e
Output
aabb
Input
2 1
day
may
sun
fun
test
hill
fest
thrill
Output
NO
Note
In the last sample both quatrains have rhymes but finding the common scheme is impossible, so the answer is "NO".
|
instruction
| 0
| 9,266
| 6
| 18,532
|
Tags: implementation
Correct Solution:
```
from sys import stdin
read = stdin.readline
n,k = map(int,read().split())
r = 0
vowel = {'a','e','i','o','u'}
def cmp(a,b,k,vowel):
l = 0
for x,y in zip(reversed(a),reversed(b)):
if x != y:
return False
l += (x in vowel)
if l == k:
return True
return False
im = True
for s in range(n):
a,b,c,d = read(),read(),read(),read()
l = 0
for i,x in enumerate(reversed(a),start=1):
l += (x in vowel)
if l == k:
break
else:
print('NO')
break
b2,b3,b4 = (a[-i:] == b[-i:]),(a[-i:] == c[-i:]),(a[-i:] == d[-i:])
if b2 + b3 + b4 == 3:
continue
elif b2 + b3 + b4 == 1:
if b2 and (r == 1 or r == 0) and cmp(c,d,k,vowel):
r = 1
continue
elif b3 and (r==2 or r == 0) and cmp(b,d,k,vowel):
r = 2
continue
elif b4 and (r == 3 or r == 0) and cmp(b,c,k,vowel):
r = 3
continue
print('NO')
break
else:
print(['aaaa','aabb','abab','abba'][r])
```
|
output
| 1
| 9,266
| 6
| 18,533
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Vera adores poems. All the poems Vera knows are divided into quatrains (groups of four lines) and in each quatrain some lines contain rhymes.
Let's consider that all lines in the poems consist of lowercase Latin letters (without spaces). Letters "a", "e", "i", "o", "u" are considered vowels.
Two lines rhyme if their suffixes that start from the k-th vowels (counting from the end) match. If a line has less than k vowels, then such line can't rhyme with any other line. For example, if k = 1, lines commit and hermit rhyme (the corresponding suffixes equal it), and if k = 2, they do not rhyme (ommit ≠ ermit).
Today on a literature lesson Vera learned that quatrains can contain four different schemes of rhymes, namely the following ones (the same letters stand for rhyming lines):
* Clerihew (aabb);
* Alternating (abab);
* Enclosed (abba).
If all lines of a quatrain pairwise rhyme, then the quatrain can belong to any rhyme scheme (this situation is represented by aaaa).
If all quatrains of a poem belong to the same rhyme scheme, then we can assume that the whole poem belongs to this rhyme scheme. If in each quatrain all lines pairwise rhyme, then the rhyme scheme of the poem is aaaa. Let us note that it doesn't matter whether lines from different quatrains rhyme with each other or not. In other words, it is possible that different quatrains aren't connected by a rhyme.
Vera got a long poem as a home task. The girl has to analyse it and find the poem rhyme scheme. Help Vera cope with the task.
Input
The first line contains two integers n and k (1 ≤ n ≤ 2500, 1 ≤ k ≤ 5) — the number of quatrains in the poem and the vowel's number, correspondingly. Next 4n lines contain the poem. Each line is not empty and only consists of small Latin letters. The total length of the lines does not exceed 104.
If we assume that the lines are numbered starting from 1, then the first quatrain contains lines number 1, 2, 3, 4; the second one contains lines number 5, 6, 7, 8; and so on.
Output
Print the rhyme scheme of the poem as "aabb", "abab", "abba", "aaaa"; or "NO" if the poem does not belong to any of the above mentioned schemes.
Examples
Input
1 1
day
may
sun
fun
Output
aabb
Input
1 1
day
may
gray
way
Output
aaaa
Input
2 1
a
a
a
a
a
a
e
e
Output
aabb
Input
2 1
day
may
sun
fun
test
hill
fest
thrill
Output
NO
Note
In the last sample both quatrains have rhymes but finding the common scheme is impossible, so the answer is "NO".
|
instruction
| 0
| 9,267
| 6
| 18,534
|
Tags: implementation
Correct Solution:
```
n, k = map(int, input().split())
def get_suffix(line):
position = 0
for _ in range(k):
position -= 1
while -position <= len(line) and line[position] not in 'aeiou':
position -= 1
if -position > len(line):
return ''
return line[position:]
common_rhyme_type = 'aaaa'
for _ in range(n):
s1, s2, s3, s4 = [get_suffix(input()) for _ in range(4)]
if '' in (s1, s2, s3, s4):
print('NO')
break
if s1 == s2 == s3 == s4:
rhyme_type = 'aaaa'
elif s1 == s2 and s3 == s4:
rhyme_type = 'aabb'
elif s1 == s3 and s2 == s4:
rhyme_type = 'abab'
elif s1 == s4 and s2 == s3:
rhyme_type = 'abba'
else:
print('NO')
break
if rhyme_type != 'aaaa':
if common_rhyme_type != 'aaaa' and rhyme_type != common_rhyme_type:
print('NO')
break
else:
common_rhyme_type = rhyme_type
else:
print(common_rhyme_type)
```
|
output
| 1
| 9,267
| 6
| 18,535
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Vera adores poems. All the poems Vera knows are divided into quatrains (groups of four lines) and in each quatrain some lines contain rhymes.
Let's consider that all lines in the poems consist of lowercase Latin letters (without spaces). Letters "a", "e", "i", "o", "u" are considered vowels.
Two lines rhyme if their suffixes that start from the k-th vowels (counting from the end) match. If a line has less than k vowels, then such line can't rhyme with any other line. For example, if k = 1, lines commit and hermit rhyme (the corresponding suffixes equal it), and if k = 2, they do not rhyme (ommit ≠ ermit).
Today on a literature lesson Vera learned that quatrains can contain four different schemes of rhymes, namely the following ones (the same letters stand for rhyming lines):
* Clerihew (aabb);
* Alternating (abab);
* Enclosed (abba).
If all lines of a quatrain pairwise rhyme, then the quatrain can belong to any rhyme scheme (this situation is represented by aaaa).
If all quatrains of a poem belong to the same rhyme scheme, then we can assume that the whole poem belongs to this rhyme scheme. If in each quatrain all lines pairwise rhyme, then the rhyme scheme of the poem is aaaa. Let us note that it doesn't matter whether lines from different quatrains rhyme with each other or not. In other words, it is possible that different quatrains aren't connected by a rhyme.
Vera got a long poem as a home task. The girl has to analyse it and find the poem rhyme scheme. Help Vera cope with the task.
Input
The first line contains two integers n and k (1 ≤ n ≤ 2500, 1 ≤ k ≤ 5) — the number of quatrains in the poem and the vowel's number, correspondingly. Next 4n lines contain the poem. Each line is not empty and only consists of small Latin letters. The total length of the lines does not exceed 104.
If we assume that the lines are numbered starting from 1, then the first quatrain contains lines number 1, 2, 3, 4; the second one contains lines number 5, 6, 7, 8; and so on.
Output
Print the rhyme scheme of the poem as "aabb", "abab", "abba", "aaaa"; or "NO" if the poem does not belong to any of the above mentioned schemes.
Examples
Input
1 1
day
may
sun
fun
Output
aabb
Input
1 1
day
may
gray
way
Output
aaaa
Input
2 1
a
a
a
a
a
a
e
e
Output
aabb
Input
2 1
day
may
sun
fun
test
hill
fest
thrill
Output
NO
Note
In the last sample both quatrains have rhymes but finding the common scheme is impossible, so the answer is "NO".
|
instruction
| 0
| 9,268
| 6
| 18,536
|
Tags: implementation
Correct Solution:
```
n, k = map(int, input().split())
ve = 'aeiou'
abba, aabb, abab = 1, 1, 1
for j in range(n):
a = ['']*4
for i in range(4):
a[i] = input()
l = len(a[i])
curr = 0
while l > 0 and curr < k:
l -= 1
if a[i][l] in ve:
curr += 1
if curr == k:
a[i] = a[i][l:]
else:
a[i] = str(i)
if a[0] == a[3] and a[1] == a[2]:
abba = abba and 1
else:
abba = 0
if a[0] == a[1] and a[2] == a[3]:
aabb = aabb and 1
else:
aabb = 0
if a[0] == a[2] and a[1] == a[3]:
abab = abab and 1
else:
abab = 0
if abba and aabb and abab:
print('aaaa')
elif not(abba or aabb or abab):
print('NO')
elif abba:
print('abba')
elif abab:
print('abab')
elif aabb:
print('aabb')
# Made By Mostafa_Khaled
```
|
output
| 1
| 9,268
| 6
| 18,537
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Vera adores poems. All the poems Vera knows are divided into quatrains (groups of four lines) and in each quatrain some lines contain rhymes.
Let's consider that all lines in the poems consist of lowercase Latin letters (without spaces). Letters "a", "e", "i", "o", "u" are considered vowels.
Two lines rhyme if their suffixes that start from the k-th vowels (counting from the end) match. If a line has less than k vowels, then such line can't rhyme with any other line. For example, if k = 1, lines commit and hermit rhyme (the corresponding suffixes equal it), and if k = 2, they do not rhyme (ommit ≠ ermit).
Today on a literature lesson Vera learned that quatrains can contain four different schemes of rhymes, namely the following ones (the same letters stand for rhyming lines):
* Clerihew (aabb);
* Alternating (abab);
* Enclosed (abba).
If all lines of a quatrain pairwise rhyme, then the quatrain can belong to any rhyme scheme (this situation is represented by aaaa).
If all quatrains of a poem belong to the same rhyme scheme, then we can assume that the whole poem belongs to this rhyme scheme. If in each quatrain all lines pairwise rhyme, then the rhyme scheme of the poem is aaaa. Let us note that it doesn't matter whether lines from different quatrains rhyme with each other or not. In other words, it is possible that different quatrains aren't connected by a rhyme.
Vera got a long poem as a home task. The girl has to analyse it and find the poem rhyme scheme. Help Vera cope with the task.
Input
The first line contains two integers n and k (1 ≤ n ≤ 2500, 1 ≤ k ≤ 5) — the number of quatrains in the poem and the vowel's number, correspondingly. Next 4n lines contain the poem. Each line is not empty and only consists of small Latin letters. The total length of the lines does not exceed 104.
If we assume that the lines are numbered starting from 1, then the first quatrain contains lines number 1, 2, 3, 4; the second one contains lines number 5, 6, 7, 8; and so on.
Output
Print the rhyme scheme of the poem as "aabb", "abab", "abba", "aaaa"; or "NO" if the poem does not belong to any of the above mentioned schemes.
Examples
Input
1 1
day
may
sun
fun
Output
aabb
Input
1 1
day
may
gray
way
Output
aaaa
Input
2 1
a
a
a
a
a
a
e
e
Output
aabb
Input
2 1
day
may
sun
fun
test
hill
fest
thrill
Output
NO
Note
In the last sample both quatrains have rhymes but finding the common scheme is impossible, so the answer is "NO".
|
instruction
| 0
| 9,269
| 6
| 18,538
|
Tags: implementation
Correct Solution:
```
n,k=list(map(int,input().split()))
l=[]
for i in range(4*n):
l.append(input())
poss=0
lst=[]
for i in l:
c=0
n=len(i)
for j in range(n-1,-1,-1):
if(i[j]=='a' or i[j]=='e' or i[j]=='i' or i[j]=='o' or i[j]=='u'):
c+=1
else: continue
if(c==k):
lst.append(i[j:])
break
if(c<k): poss=1; break;
if(poss==1):
print("NO")
else:
n=len(lst)
ch=[]
ans=-1
pos=0
for i in range(0,n,4):
s1=lst[i]
s2=lst[i+1]; s3=lst[i+2]; s4=lst[i+3];
if(s1==s2 and s2==s3 and s3==s4):
ch.append([1,2,3,4])
elif(s1!=s2):
if(s1==s3 and s2==s4):
ch.append([2])
if(ans!=-1 and ans!=2): pos=1; break
ans=2
elif(s1==s4 and s2==s3):
ch.append([3])
if(ans!=-1 and ans!=3): pos=1; break
ans=3
else: pos=1; break
else:
if(s3==s4):
ch.append([1])
if(ans!=-1 and ans!=1): pos=1; break
ans=1
else: pos=1; break
if(pos==1):
print("NO")
else:
if(ans==-1):
print("aaaa")
elif(ans==2):
print("abab")
elif(ans==3):
print("abba")
elif(ans==1): print("aabb")
```
|
output
| 1
| 9,269
| 6
| 18,539
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Vera adores poems. All the poems Vera knows are divided into quatrains (groups of four lines) and in each quatrain some lines contain rhymes.
Let's consider that all lines in the poems consist of lowercase Latin letters (without spaces). Letters "a", "e", "i", "o", "u" are considered vowels.
Two lines rhyme if their suffixes that start from the k-th vowels (counting from the end) match. If a line has less than k vowels, then such line can't rhyme with any other line. For example, if k = 1, lines commit and hermit rhyme (the corresponding suffixes equal it), and if k = 2, they do not rhyme (ommit ≠ ermit).
Today on a literature lesson Vera learned that quatrains can contain four different schemes of rhymes, namely the following ones (the same letters stand for rhyming lines):
* Clerihew (aabb);
* Alternating (abab);
* Enclosed (abba).
If all lines of a quatrain pairwise rhyme, then the quatrain can belong to any rhyme scheme (this situation is represented by aaaa).
If all quatrains of a poem belong to the same rhyme scheme, then we can assume that the whole poem belongs to this rhyme scheme. If in each quatrain all lines pairwise rhyme, then the rhyme scheme of the poem is aaaa. Let us note that it doesn't matter whether lines from different quatrains rhyme with each other or not. In other words, it is possible that different quatrains aren't connected by a rhyme.
Vera got a long poem as a home task. The girl has to analyse it and find the poem rhyme scheme. Help Vera cope with the task.
Input
The first line contains two integers n and k (1 ≤ n ≤ 2500, 1 ≤ k ≤ 5) — the number of quatrains in the poem and the vowel's number, correspondingly. Next 4n lines contain the poem. Each line is not empty and only consists of small Latin letters. The total length of the lines does not exceed 104.
If we assume that the lines are numbered starting from 1, then the first quatrain contains lines number 1, 2, 3, 4; the second one contains lines number 5, 6, 7, 8; and so on.
Output
Print the rhyme scheme of the poem as "aabb", "abab", "abba", "aaaa"; or "NO" if the poem does not belong to any of the above mentioned schemes.
Examples
Input
1 1
day
may
sun
fun
Output
aabb
Input
1 1
day
may
gray
way
Output
aaaa
Input
2 1
a
a
a
a
a
a
e
e
Output
aabb
Input
2 1
day
may
sun
fun
test
hill
fest
thrill
Output
NO
Note
In the last sample both quatrains have rhymes but finding the common scheme is impossible, so the answer is "NO".
|
instruction
| 0
| 9,270
| 6
| 18,540
|
Tags: implementation
Correct Solution:
```
def find(s,k):
ek=0
sw=""
vow=set()
vow.add('a')
vow.add('e')
vow.add('i')
vow.add('o')
vow.add('u')
for i in range(len(s)-1,-1,-1):
if s[i] in vow:
ek+=1
sw+=s[i]
if ek==k:
return sw
return "-1"
n,k=map(int,input().split())
l=[]
tot=[]
res=[]
f=0
for i in range(4*n):
u=input()
l.append(find(u,k))
for i in range(n):
a=[]
for j in range(4):
a.append(l[i*4+j])
#print(a)
if "-1" in a or len(set(a))>2:
f=1
break
s=set(a)
sw=""
e=0
e1=0
for j in s:
for i in range(len(a)):
if a[i]==j:
e+=1
sw+="a"
else:
e1+=1
sw+="b"
break
if e==4 or e1==4:
res.append(sw)
continue
elif e==2 and e1==2:
tot.append(sw)
else:
f=1
break
if f==1:
print("NO")
else:
f=0
for i in range(len(tot)):
if tot[i]!=tot[i-1]:
f=1
break
if f==1:
print("NO")
elif len(tot)==0 and len(res)>0:
print("aaaa")
else:
tot[0]=list(tot[0])
if tot[0][0]=='b':
for i in range(len(tot[0])):
if tot[0][i]=='a':
tot[0][i]='b'
else:
tot[0][i]='a'
print(*tot[0],sep="")
```
|
output
| 1
| 9,270
| 6
| 18,541
|
Provide tags and a correct Python 3 solution for this coding contest problem.
Vera adores poems. All the poems Vera knows are divided into quatrains (groups of four lines) and in each quatrain some lines contain rhymes.
Let's consider that all lines in the poems consist of lowercase Latin letters (without spaces). Letters "a", "e", "i", "o", "u" are considered vowels.
Two lines rhyme if their suffixes that start from the k-th vowels (counting from the end) match. If a line has less than k vowels, then such line can't rhyme with any other line. For example, if k = 1, lines commit and hermit rhyme (the corresponding suffixes equal it), and if k = 2, they do not rhyme (ommit ≠ ermit).
Today on a literature lesson Vera learned that quatrains can contain four different schemes of rhymes, namely the following ones (the same letters stand for rhyming lines):
* Clerihew (aabb);
* Alternating (abab);
* Enclosed (abba).
If all lines of a quatrain pairwise rhyme, then the quatrain can belong to any rhyme scheme (this situation is represented by aaaa).
If all quatrains of a poem belong to the same rhyme scheme, then we can assume that the whole poem belongs to this rhyme scheme. If in each quatrain all lines pairwise rhyme, then the rhyme scheme of the poem is aaaa. Let us note that it doesn't matter whether lines from different quatrains rhyme with each other or not. In other words, it is possible that different quatrains aren't connected by a rhyme.
Vera got a long poem as a home task. The girl has to analyse it and find the poem rhyme scheme. Help Vera cope with the task.
Input
The first line contains two integers n and k (1 ≤ n ≤ 2500, 1 ≤ k ≤ 5) — the number of quatrains in the poem and the vowel's number, correspondingly. Next 4n lines contain the poem. Each line is not empty and only consists of small Latin letters. The total length of the lines does not exceed 104.
If we assume that the lines are numbered starting from 1, then the first quatrain contains lines number 1, 2, 3, 4; the second one contains lines number 5, 6, 7, 8; and so on.
Output
Print the rhyme scheme of the poem as "aabb", "abab", "abba", "aaaa"; or "NO" if the poem does not belong to any of the above mentioned schemes.
Examples
Input
1 1
day
may
sun
fun
Output
aabb
Input
1 1
day
may
gray
way
Output
aaaa
Input
2 1
a
a
a
a
a
a
e
e
Output
aabb
Input
2 1
day
may
sun
fun
test
hill
fest
thrill
Output
NO
Note
In the last sample both quatrains have rhymes but finding the common scheme is impossible, so the answer is "NO".
|
instruction
| 0
| 9,271
| 6
| 18,542
|
Tags: implementation
Correct Solution:
```
n, k = map(int, input().split())
ve = 'aeiou'
abba, aabb, abab = 1, 1, 1
for j in range(n):
a = ['']*4
for i in range(4):
a[i] = input()
l = len(a[i])
curr = 0
while l > 0 and curr < k:
l -= 1
if a[i][l] in ve:
curr += 1
if curr == k:
a[i] = a[i][l:]
else:
a[i] = str(i)
if a[0] == a[3] and a[1] == a[2]:
abba = abba and 1
else:
abba = 0
if a[0] == a[1] and a[2] == a[3]:
aabb = aabb and 1
else:
aabb = 0
if a[0] == a[2] and a[1] == a[3]:
abab = abab and 1
else:
abab = 0
if abba and aabb and abab:
print('aaaa')
elif not(abba or aabb or abab):
print('NO')
elif abba:
print('abba')
elif abab:
print('abab')
elif aabb:
print('aabb')
```
|
output
| 1
| 9,271
| 6
| 18,543
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.