message stringlengths 2 11.9k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 137 108k | cluster float64 18 18 | __index_level_0__ int64 274 217k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter, he receives an electric shock. He can make guesses which letter is selected, but for each incorrect guess he receives an electric shock too. The show ends when Valentin guesses the selected letter correctly.
Valentin can't keep in mind everything, so he could guess the selected letter much later than it can be uniquely determined and get excessive electric shocks. Excessive electric shocks are those which Valentin got after the moment the selected letter can be uniquely determined. You should find out the number of excessive electric shocks.
Input
The first line contains a single integer n (1 ≤ n ≤ 105) — the number of actions Valentin did.
The next n lines contain descriptions of his actions, each line contains description of one action. Each action can be of one of three types:
1. Valentin pronounced some word and didn't get an electric shock. This action is described by the string ". w" (without quotes), in which "." is a dot (ASCII-code 46), and w is the word that Valentin said.
2. Valentin pronounced some word and got an electric shock. This action is described by the string "! w" (without quotes), in which "!" is an exclamation mark (ASCII-code 33), and w is the word that Valentin said.
3. Valentin made a guess about the selected letter. This action is described by the string "? s" (without quotes), in which "?" is a question mark (ASCII-code 63), and s is the guess — a lowercase English letter.
All words consist only of lowercase English letters. The total length of all words does not exceed 105.
It is guaranteed that last action is a guess about the selected letter. Also, it is guaranteed that Valentin didn't make correct guesses about the selected letter before the last action. Moreover, it's guaranteed that if Valentin got an electric shock after pronouncing some word, then it contains the selected letter; and also if Valentin didn't get an electric shock after pronouncing some word, then it does not contain the selected letter.
Output
Output a single integer — the number of electric shocks that Valentin could have avoided if he had told the selected letter just after it became uniquely determined.
Examples
Input
5
! abc
. ad
. b
! cd
? c
Output
1
Input
8
! hello
! codeforces
? c
. o
? d
? h
. l
? e
Output
2
Input
7
! ababahalamaha
? a
? b
? a
? b
? a
? h
Output
0
Note
In the first test case after the first action it becomes clear that the selected letter is one of the following: a, b, c. After the second action we can note that the selected letter is not a. Valentin tells word "b" and doesn't get a shock. After that it is clear that the selected letter is c, but Valentin pronounces the word cd and gets an excessive electric shock.
In the second test case after the first two electric shocks we understand that the selected letter is e or o. Valentin tries some words consisting of these letters and after the second word it's clear that the selected letter is e, but Valentin makes 3 more actions before he makes a correct hypothesis.
In the third example the selected letter can be uniquely determined only when Valentin guesses it, so he didn't get excessive electric shocks.
Submitted Solution:
```
import math,sys,bisect,heapq
from collections import defaultdict,Counter,deque
from itertools import groupby,accumulate
#sys.setrecursionlimit(200000000)
int1 = lambda x: int(x) - 1
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda: map(int,input().split())
alele = lambda: list(map(int, input().split()))
ilelec = lambda: map(int1,input().split())
alelec = lambda: list(map(int1, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
#MOD = 1000000000 + 7
def Y(c): print(["NO","YES"][c])
def y(c): print(["no","yes"][c])
def Yy(c): print(["No","Yes"][c])
extra = -1;s = set();mark = {}
for _ in range(int(input())):
a,b = input().split(" ")
if len(s) == 1 or len(mark) == 25:
if a!='.':
extra += 1
continue
if a == '!':
if not(s):
s = set(b)
else:
c = set(b)
l = []
for i in c:
if i in s:
l.append(i)
new_s = set()
#print(l)
for i in s:
if i in l:
new_s.add(i)
else:
mark[i] = 1
s = new_s.copy()
elif a == '.':
c = set(b)
l = []
for i in c:
mark[i] = 1
if i in s:
l.append(i)
new_s = set()
#print(l)
for i in s:
if i not in l:
new_s.add(i)
s = new_s.copy()
else:
mark[b] = 1
t = set()
for i in s:
if mark.get(i,-1) == -1:
t.add(i)
s = t.copy()
#print(s,mark,len(mark))
print(max(0,extra))
``` | instruction | 0 | 100,040 | 18 | 200,080 |
Yes | output | 1 | 100,040 | 18 | 200,081 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter, he receives an electric shock. He can make guesses which letter is selected, but for each incorrect guess he receives an electric shock too. The show ends when Valentin guesses the selected letter correctly.
Valentin can't keep in mind everything, so he could guess the selected letter much later than it can be uniquely determined and get excessive electric shocks. Excessive electric shocks are those which Valentin got after the moment the selected letter can be uniquely determined. You should find out the number of excessive electric shocks.
Input
The first line contains a single integer n (1 ≤ n ≤ 105) — the number of actions Valentin did.
The next n lines contain descriptions of his actions, each line contains description of one action. Each action can be of one of three types:
1. Valentin pronounced some word and didn't get an electric shock. This action is described by the string ". w" (without quotes), in which "." is a dot (ASCII-code 46), and w is the word that Valentin said.
2. Valentin pronounced some word and got an electric shock. This action is described by the string "! w" (without quotes), in which "!" is an exclamation mark (ASCII-code 33), and w is the word that Valentin said.
3. Valentin made a guess about the selected letter. This action is described by the string "? s" (without quotes), in which "?" is a question mark (ASCII-code 63), and s is the guess — a lowercase English letter.
All words consist only of lowercase English letters. The total length of all words does not exceed 105.
It is guaranteed that last action is a guess about the selected letter. Also, it is guaranteed that Valentin didn't make correct guesses about the selected letter before the last action. Moreover, it's guaranteed that if Valentin got an electric shock after pronouncing some word, then it contains the selected letter; and also if Valentin didn't get an electric shock after pronouncing some word, then it does not contain the selected letter.
Output
Output a single integer — the number of electric shocks that Valentin could have avoided if he had told the selected letter just after it became uniquely determined.
Examples
Input
5
! abc
. ad
. b
! cd
? c
Output
1
Input
8
! hello
! codeforces
? c
. o
? d
? h
. l
? e
Output
2
Input
7
! ababahalamaha
? a
? b
? a
? b
? a
? h
Output
0
Note
In the first test case after the first action it becomes clear that the selected letter is one of the following: a, b, c. After the second action we can note that the selected letter is not a. Valentin tells word "b" and doesn't get a shock. After that it is clear that the selected letter is c, but Valentin pronounces the word cd and gets an excessive electric shock.
In the second test case after the first two electric shocks we understand that the selected letter is e or o. Valentin tries some words consisting of these letters and after the second word it's clear that the selected letter is e, but Valentin makes 3 more actions before he makes a correct hypothesis.
In the third example the selected letter can be uniquely determined only when Valentin guesses it, so he didn't get excessive electric shocks.
Submitted Solution:
```
# reading input from stdin
numActions = int(input())
actions = []
for i in range(numActions):
tempStr = input()
if tempStr[0] == '!':
action = 'shock'
elif tempStr[0] == '.':
action = 'none'
else:
action = 'guess'
string = tempStr[2:len(tempStr)]
actions.append([action, string])
# algorithm
shockList = set()
cleanList = set()
numExtraShocks = 0
for i in range(len(actions)):
action = actions[i][0]
string = actions[i][1]
if action == 'shock':
if len(shockList) == 1:
numExtraShocks += 1
for letter in string:
if i == 0:
shockList.add(letter)
elif letter not in cleanList and letter not in shockList:
cleanList.add(letter)
newShockList = shockList.copy()
for i in range(len(list(shockList))):
string1 = list(shockList)[i]
for letter1 in string1:
if letter1 not in string:
newShockList.remove(letter1)
cleanList.add(letter1)
shockList = newShockList.copy()
elif action == 'none':
for letter in string:
if letter in shockList:
shockList.remove(letter)
cleanList.add(letter)
elif action == 'guess':
if i != len(actions) - 1:
if string[0] in shockList:
shockList.remove(string[0])
cleanList.add(string[0])
if len(shockList) == 1 and i != len(actions) - 1:
numExtraShocks += 1
print(numExtraShocks)
``` | instruction | 0 | 100,041 | 18 | 200,082 |
No | output | 1 | 100,041 | 18 | 200,083 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter, he receives an electric shock. He can make guesses which letter is selected, but for each incorrect guess he receives an electric shock too. The show ends when Valentin guesses the selected letter correctly.
Valentin can't keep in mind everything, so he could guess the selected letter much later than it can be uniquely determined and get excessive electric shocks. Excessive electric shocks are those which Valentin got after the moment the selected letter can be uniquely determined. You should find out the number of excessive electric shocks.
Input
The first line contains a single integer n (1 ≤ n ≤ 105) — the number of actions Valentin did.
The next n lines contain descriptions of his actions, each line contains description of one action. Each action can be of one of three types:
1. Valentin pronounced some word and didn't get an electric shock. This action is described by the string ". w" (without quotes), in which "." is a dot (ASCII-code 46), and w is the word that Valentin said.
2. Valentin pronounced some word and got an electric shock. This action is described by the string "! w" (without quotes), in which "!" is an exclamation mark (ASCII-code 33), and w is the word that Valentin said.
3. Valentin made a guess about the selected letter. This action is described by the string "? s" (without quotes), in which "?" is a question mark (ASCII-code 63), and s is the guess — a lowercase English letter.
All words consist only of lowercase English letters. The total length of all words does not exceed 105.
It is guaranteed that last action is a guess about the selected letter. Also, it is guaranteed that Valentin didn't make correct guesses about the selected letter before the last action. Moreover, it's guaranteed that if Valentin got an electric shock after pronouncing some word, then it contains the selected letter; and also if Valentin didn't get an electric shock after pronouncing some word, then it does not contain the selected letter.
Output
Output a single integer — the number of electric shocks that Valentin could have avoided if he had told the selected letter just after it became uniquely determined.
Examples
Input
5
! abc
. ad
. b
! cd
? c
Output
1
Input
8
! hello
! codeforces
? c
. o
? d
? h
. l
? e
Output
2
Input
7
! ababahalamaha
? a
? b
? a
? b
? a
? h
Output
0
Note
In the first test case after the first action it becomes clear that the selected letter is one of the following: a, b, c. After the second action we can note that the selected letter is not a. Valentin tells word "b" and doesn't get a shock. After that it is clear that the selected letter is c, but Valentin pronounces the word cd and gets an excessive electric shock.
In the second test case after the first two electric shocks we understand that the selected letter is e or o. Valentin tries some words consisting of these letters and after the second word it's clear that the selected letter is e, but Valentin makes 3 more actions before he makes a correct hypothesis.
In the third example the selected letter can be uniquely determined only when Valentin guesses it, so he didn't get excessive electric shocks.
Submitted Solution:
```
def main():
n = int(input())
yes = set(list(map(chr, range(97, 123))))
no = set()
cnt = 0
for i in range(n):
mark, word = [x for x in input().split()]
tmp_yes = set()
tmp_no = set()
if (mark == '!'):
if (len(yes) == 1):
cnt += 1
for c in word:
tmp_yes.add(c)
yes = yes & tmp_yes
elif (mark == '.'):
for c in word:
tmp_no.add(c)
no = no | tmp_no
elif (mark == '?' and i != n-1):
if (len(yes) == 1):
cnt += 1
tmp_no.add(word)
no = no | tmp_no
for c in (yes & no):
yes.remove(c)
no.add(c)
print(yes)
print(no)
print(cnt)
main()
``` | instruction | 0 | 100,042 | 18 | 200,084 |
No | output | 1 | 100,042 | 18 | 200,085 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter, he receives an electric shock. He can make guesses which letter is selected, but for each incorrect guess he receives an electric shock too. The show ends when Valentin guesses the selected letter correctly.
Valentin can't keep in mind everything, so he could guess the selected letter much later than it can be uniquely determined and get excessive electric shocks. Excessive electric shocks are those which Valentin got after the moment the selected letter can be uniquely determined. You should find out the number of excessive electric shocks.
Input
The first line contains a single integer n (1 ≤ n ≤ 105) — the number of actions Valentin did.
The next n lines contain descriptions of his actions, each line contains description of one action. Each action can be of one of three types:
1. Valentin pronounced some word and didn't get an electric shock. This action is described by the string ". w" (without quotes), in which "." is a dot (ASCII-code 46), and w is the word that Valentin said.
2. Valentin pronounced some word and got an electric shock. This action is described by the string "! w" (without quotes), in which "!" is an exclamation mark (ASCII-code 33), and w is the word that Valentin said.
3. Valentin made a guess about the selected letter. This action is described by the string "? s" (without quotes), in which "?" is a question mark (ASCII-code 63), and s is the guess — a lowercase English letter.
All words consist only of lowercase English letters. The total length of all words does not exceed 105.
It is guaranteed that last action is a guess about the selected letter. Also, it is guaranteed that Valentin didn't make correct guesses about the selected letter before the last action. Moreover, it's guaranteed that if Valentin got an electric shock after pronouncing some word, then it contains the selected letter; and also if Valentin didn't get an electric shock after pronouncing some word, then it does not contain the selected letter.
Output
Output a single integer — the number of electric shocks that Valentin could have avoided if he had told the selected letter just after it became uniquely determined.
Examples
Input
5
! abc
. ad
. b
! cd
? c
Output
1
Input
8
! hello
! codeforces
? c
. o
? d
? h
. l
? e
Output
2
Input
7
! ababahalamaha
? a
? b
? a
? b
? a
? h
Output
0
Note
In the first test case after the first action it becomes clear that the selected letter is one of the following: a, b, c. After the second action we can note that the selected letter is not a. Valentin tells word "b" and doesn't get a shock. After that it is clear that the selected letter is c, but Valentin pronounces the word cd and gets an excessive electric shock.
In the second test case after the first two electric shocks we understand that the selected letter is e or o. Valentin tries some words consisting of these letters and after the second word it's clear that the selected letter is e, but Valentin makes 3 more actions before he makes a correct hypothesis.
In the third example the selected letter can be uniquely determined only when Valentin guesses it, so he didn't get excessive electric shocks.
Submitted Solution:
```
from sys import stdin
n = int(stdin.readline().rstrip('\n'))
not_in_ans = set()
in_ans = set()
count = 0
f = False
for i in range(n):
line = stdin.readline().rstrip('\n').split()
if line[0] == chr(46): # .
if len(in_ans) == 0:
not_in_ans |= set(line[1])
else:
in_ans -= set(line[1])
in_ans -= not_in_ans
not_in_ans = set()
if len(in_ans) == 1:
f = True
elif line[0] == chr(33): # !
if f:
count += 1
else:
if len(in_ans) == 0:
in_ans = set(line[1])
if len(in_ans) == 1:
f = True
in_ans &= set(line[1])
elif line[0] == chr(63): # ?
if f and i + 1 != n:
count += 1
else:
if i + 1 != n:
in_ans -= set(line[1])
if len(in_ans) == 1:
f = True
print(count)
``` | instruction | 0 | 100,043 | 18 | 200,086 |
No | output | 1 | 100,043 | 18 | 200,087 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter, he receives an electric shock. He can make guesses which letter is selected, but for each incorrect guess he receives an electric shock too. The show ends when Valentin guesses the selected letter correctly.
Valentin can't keep in mind everything, so he could guess the selected letter much later than it can be uniquely determined and get excessive electric shocks. Excessive electric shocks are those which Valentin got after the moment the selected letter can be uniquely determined. You should find out the number of excessive electric shocks.
Input
The first line contains a single integer n (1 ≤ n ≤ 105) — the number of actions Valentin did.
The next n lines contain descriptions of his actions, each line contains description of one action. Each action can be of one of three types:
1. Valentin pronounced some word and didn't get an electric shock. This action is described by the string ". w" (without quotes), in which "." is a dot (ASCII-code 46), and w is the word that Valentin said.
2. Valentin pronounced some word and got an electric shock. This action is described by the string "! w" (without quotes), in which "!" is an exclamation mark (ASCII-code 33), and w is the word that Valentin said.
3. Valentin made a guess about the selected letter. This action is described by the string "? s" (without quotes), in which "?" is a question mark (ASCII-code 63), and s is the guess — a lowercase English letter.
All words consist only of lowercase English letters. The total length of all words does not exceed 105.
It is guaranteed that last action is a guess about the selected letter. Also, it is guaranteed that Valentin didn't make correct guesses about the selected letter before the last action. Moreover, it's guaranteed that if Valentin got an electric shock after pronouncing some word, then it contains the selected letter; and also if Valentin didn't get an electric shock after pronouncing some word, then it does not contain the selected letter.
Output
Output a single integer — the number of electric shocks that Valentin could have avoided if he had told the selected letter just after it became uniquely determined.
Examples
Input
5
! abc
. ad
. b
! cd
? c
Output
1
Input
8
! hello
! codeforces
? c
. o
? d
? h
. l
? e
Output
2
Input
7
! ababahalamaha
? a
? b
? a
? b
? a
? h
Output
0
Note
In the first test case after the first action it becomes clear that the selected letter is one of the following: a, b, c. After the second action we can note that the selected letter is not a. Valentin tells word "b" and doesn't get a shock. After that it is clear that the selected letter is c, but Valentin pronounces the word cd and gets an excessive electric shock.
In the second test case after the first two electric shocks we understand that the selected letter is e or o. Valentin tries some words consisting of these letters and after the second word it's clear that the selected letter is e, but Valentin makes 3 more actions before he makes a correct hypothesis.
In the third example the selected letter can be uniquely determined only when Valentin guesses it, so he didn't get excessive electric shocks.
Submitted Solution:
```
'''input
5
. abcdefghijklmnopqrstuvwxy
? b
? c
? d
? z
'''
t = [0] * 26
n = int(input())
if n == 1:
print(0)
quit()
for i in range(n-1):
x, y = input().split()
if x == '!':
if 1 in t:
c = [ord(p) - 97 for p in set(y)]
for i in range(26):
if t[i] != 1 or i not in c:
t[i] = -1
else:
for l in set(y):
if t[ord(l) - 97] == 0:
t[ord(l) - 97] = 1
elif x == '.':
for l in set(y):
t[ord(l) - 97] = -1
else:
t[ord(y) - 97] = -1
# print(t)
if t.count(1) == 1 or (t.count(0) == 1 and max(t) == 0):
break
e = 0
for _ in range(i+1, n-1):
x, y = input().split()
if x == '!' or x == '?':
e += 1
print(e)
``` | instruction | 0 | 100,044 | 18 | 200,088 |
No | output | 1 | 100,044 | 18 | 200,089 |
Provide a correct Python 3 solution for this coding contest problem.
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key.
To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string:
* The `0` key: a letter `0` will be inserted to the right of the string.
* The `1` key: a letter `1` will be inserted to the right of the string.
* The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted.
Sig has launched the editor, and pressed these keys N times in total. As a result, the editor displays a string s. Find the number of such ways to press the keys, modulo 10^9 + 7.
Constraints
* 1 ≦ N ≦ 5000
* 1 ≦ |s| ≦ N
* s consists of the letters `0` and `1`.
Input
The input is given from Standard Input in the following format:
N
s
Output
Print the number of the ways to press the keys N times in total such that the editor displays the string s in the end, modulo 10^9+7.
Examples
Input
3
0
Output
5
Input
300
1100100
Output
519054663
Input
5000
01000001011101000100001101101111011001000110010101110010000
Output
500886057 | instruction | 0 | 100,223 | 18 | 200,446 |
"Correct Solution:
```
N = int(input())
S = input()
mod = 10**9 + 7
M=len(S)
DP = [[0]*(N+1) for i in range(N+1)]
DP[0][0] = 1
for i in range(1,N+1):
for j in range(N+1):
if j>0 and j<N:
DP[i][j] = DP[i-1][j-1] + 2*DP[i-1][j+1]
elif j==0:
DP[i][j] = DP[i-1][j] + 2*DP[i-1][j+1]
else:
DP[i][j] = DP[i-1][j-1]
DP[i][j] %= mod
print(DP[N][M])
``` | output | 1 | 100,223 | 18 | 200,447 |
Provide a correct Python 3 solution for this coding contest problem.
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key.
To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string:
* The `0` key: a letter `0` will be inserted to the right of the string.
* The `1` key: a letter `1` will be inserted to the right of the string.
* The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted.
Sig has launched the editor, and pressed these keys N times in total. As a result, the editor displays a string s. Find the number of such ways to press the keys, modulo 10^9 + 7.
Constraints
* 1 ≦ N ≦ 5000
* 1 ≦ |s| ≦ N
* s consists of the letters `0` and `1`.
Input
The input is given from Standard Input in the following format:
N
s
Output
Print the number of the ways to press the keys N times in total such that the editor displays the string s in the end, modulo 10^9+7.
Examples
Input
3
0
Output
5
Input
300
1100100
Output
519054663
Input
5000
01000001011101000100001101101111011001000110010101110010000
Output
500886057 | instruction | 0 | 100,224 | 18 | 200,448 |
"Correct Solution:
```
n=int(input())
p=[0]*5001
p[len(input())]=1
while n:
p=[((2*p[j-1]if j else p[j])+p[j+1])%(10**9+7)for j in range(n)]
n=n-1
print(p[0])
``` | output | 1 | 100,224 | 18 | 200,449 |
Provide a correct Python 3 solution for this coding contest problem.
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key.
To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string:
* The `0` key: a letter `0` will be inserted to the right of the string.
* The `1` key: a letter `1` will be inserted to the right of the string.
* The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted.
Sig has launched the editor, and pressed these keys N times in total. As a result, the editor displays a string s. Find the number of such ways to press the keys, modulo 10^9 + 7.
Constraints
* 1 ≦ N ≦ 5000
* 1 ≦ |s| ≦ N
* s consists of the letters `0` and `1`.
Input
The input is given from Standard Input in the following format:
N
s
Output
Print the number of the ways to press the keys N times in total such that the editor displays the string s in the end, modulo 10^9+7.
Examples
Input
3
0
Output
5
Input
300
1100100
Output
519054663
Input
5000
01000001011101000100001101101111011001000110010101110010000
Output
500886057 | instruction | 0 | 100,225 | 18 | 200,450 |
"Correct Solution:
```
N = int(input())
s = input()
mod = 10 ** 9 + 7
def main():
dp = [[0 for _ in range(N+1)] for _ in range(2)]
dp[0][0] = 1
for i in range(N):
for j in range(N):
dp[(i+1)%2][j] = 0
for j in range(N):
dp[(i+1)%2][j+1] = (dp[(i+1)%2][j+1] + dp[i%2][j] * 2) % mod
if j-1 >= 0:
dp[(i+1)%2][j-1] = (dp[(i+1)%2][j-1] + dp[i%2][j]) % mod
else:
dp[(i+1)%2][j] = (dp[(i+1)%2][j] + dp[i%2][j]) % mod
pow2 = pow(2, len(s), mod)
inv_pow2 = pow(pow2, mod-2, mod)
print((dp[N%2][len(s)] * inv_pow2) % mod)
if __name__=='__main__':
main()
``` | output | 1 | 100,225 | 18 | 200,451 |
Provide a correct Python 3 solution for this coding contest problem.
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key.
To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string:
* The `0` key: a letter `0` will be inserted to the right of the string.
* The `1` key: a letter `1` will be inserted to the right of the string.
* The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted.
Sig has launched the editor, and pressed these keys N times in total. As a result, the editor displays a string s. Find the number of such ways to press the keys, modulo 10^9 + 7.
Constraints
* 1 ≦ N ≦ 5000
* 1 ≦ |s| ≦ N
* s consists of the letters `0` and `1`.
Input
The input is given from Standard Input in the following format:
N
s
Output
Print the number of the ways to press the keys N times in total such that the editor displays the string s in the end, modulo 10^9+7.
Examples
Input
3
0
Output
5
Input
300
1100100
Output
519054663
Input
5000
01000001011101000100001101101111011001000110010101110010000
Output
500886057 | instruction | 0 | 100,226 | 18 | 200,452 |
"Correct Solution:
```
n = int(input())
s = len(input())
mod = 10**9+7
dp = [[0]*(n+1) for _ in range(n+1)]
dp[0][0] = 1
for i in range(1,n+1):
dp[i][0] = (dp[i-1][0] + dp[i-1][1])%mod
for j in range(1,min(n,i+1)):
dp[i][j] = (dp[i-1][j-1]*2 + dp[i-1][j+1])%mod
dp[i][n] = dp[i-1][n-1]*2%mod
s2 = pow(2,s,mod)
rev = pow(s2,mod-2,mod)
print(dp[n][s]*rev%mod)
``` | output | 1 | 100,226 | 18 | 200,453 |
Provide a correct Python 3 solution for this coding contest problem.
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key.
To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string:
* The `0` key: a letter `0` will be inserted to the right of the string.
* The `1` key: a letter `1` will be inserted to the right of the string.
* The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted.
Sig has launched the editor, and pressed these keys N times in total. As a result, the editor displays a string s. Find the number of such ways to press the keys, modulo 10^9 + 7.
Constraints
* 1 ≦ N ≦ 5000
* 1 ≦ |s| ≦ N
* s consists of the letters `0` and `1`.
Input
The input is given from Standard Input in the following format:
N
s
Output
Print the number of the ways to press the keys N times in total such that the editor displays the string s in the end, modulo 10^9+7.
Examples
Input
3
0
Output
5
Input
300
1100100
Output
519054663
Input
5000
01000001011101000100001101101111011001000110010101110010000
Output
500886057 | instruction | 0 | 100,227 | 18 | 200,454 |
"Correct Solution:
```
N=int(input())
m=len(input())
mod=10**9+7
dp=[[0 for j in range(i+2)] for i in range(N+1)]
dp[N][m]=1
for i in range(N-1,-1,-1):
for j in range(1,i+2):
dp[i][j]=(2*dp[i+1][j-1]+dp[i+1][j+1])%mod
dp[i][0]=(dp[i+1][0]+dp[i+1][1])%mod
print(dp[0][0])
``` | output | 1 | 100,227 | 18 | 200,455 |
Provide a correct Python 3 solution for this coding contest problem.
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key.
To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string:
* The `0` key: a letter `0` will be inserted to the right of the string.
* The `1` key: a letter `1` will be inserted to the right of the string.
* The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted.
Sig has launched the editor, and pressed these keys N times in total. As a result, the editor displays a string s. Find the number of such ways to press the keys, modulo 10^9 + 7.
Constraints
* 1 ≦ N ≦ 5000
* 1 ≦ |s| ≦ N
* s consists of the letters `0` and `1`.
Input
The input is given from Standard Input in the following format:
N
s
Output
Print the number of the ways to press the keys N times in total such that the editor displays the string s in the end, modulo 10^9+7.
Examples
Input
3
0
Output
5
Input
300
1100100
Output
519054663
Input
5000
01000001011101000100001101101111011001000110010101110010000
Output
500886057 | instruction | 0 | 100,228 | 18 | 200,456 |
"Correct Solution:
```
N = int(input())
s = len(input())
mod = 10**9 + 7
dp = [1] + [0]*N
for i in range(N):
dp = [dp[0] + dp[1]] + [(i + 2*j) % mod for i, j in zip(dp[2:] + [0],dp[:-1])]
print(dp[s]*pow(2**s, mod - 2, mod)%mod)
``` | output | 1 | 100,228 | 18 | 200,457 |
Provide a correct Python 3 solution for this coding contest problem.
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key.
To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string:
* The `0` key: a letter `0` will be inserted to the right of the string.
* The `1` key: a letter `1` will be inserted to the right of the string.
* The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted.
Sig has launched the editor, and pressed these keys N times in total. As a result, the editor displays a string s. Find the number of such ways to press the keys, modulo 10^9 + 7.
Constraints
* 1 ≦ N ≦ 5000
* 1 ≦ |s| ≦ N
* s consists of the letters `0` and `1`.
Input
The input is given from Standard Input in the following format:
N
s
Output
Print the number of the ways to press the keys N times in total such that the editor displays the string s in the end, modulo 10^9+7.
Examples
Input
3
0
Output
5
Input
300
1100100
Output
519054663
Input
5000
01000001011101000100001101101111011001000110010101110010000
Output
500886057 | instruction | 0 | 100,229 | 18 | 200,458 |
"Correct Solution:
```
n = int(input())
s = len(input())
mod = 10**9+7
dp = [[0]*(n+1) for _ in range(n+1)]
dp[0][0] = 1
for i in range(1,n+1):
dp[i][0] = (dp[i-1][0] + dp[i-1][1])%mod
for j in range(1,n):
dp[i][j] = (dp[i-1][j-1]*2 + dp[i-1][j+1])%mod
dp[i][n] = dp[i-1][n-1]*2%mod
s2 = pow(2,s,mod)
rev = pow(s2,mod-2,mod)
print(dp[n][s]*rev%mod)
``` | output | 1 | 100,229 | 18 | 200,459 |
Provide a correct Python 3 solution for this coding contest problem.
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key.
To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string:
* The `0` key: a letter `0` will be inserted to the right of the string.
* The `1` key: a letter `1` will be inserted to the right of the string.
* The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted.
Sig has launched the editor, and pressed these keys N times in total. As a result, the editor displays a string s. Find the number of such ways to press the keys, modulo 10^9 + 7.
Constraints
* 1 ≦ N ≦ 5000
* 1 ≦ |s| ≦ N
* s consists of the letters `0` and `1`.
Input
The input is given from Standard Input in the following format:
N
s
Output
Print the number of the ways to press the keys N times in total such that the editor displays the string s in the end, modulo 10^9+7.
Examples
Input
3
0
Output
5
Input
300
1100100
Output
519054663
Input
5000
01000001011101000100001101101111011001000110010101110010000
Output
500886057 | instruction | 0 | 100,230 | 18 | 200,460 |
"Correct Solution:
```
N=int(input())
s=input()
l=len(s)
dp=[[0]*(N+2) for i in range(N)]
dp[0][1]=2
dp[0][0]=1
mod=10**9+7
for i in range(N-1):
for j in range(i+2):
if j==0:
dp[i+1][j+1]+=2*dp[i][j]
dp[i+1][j+1]%=mod
dp[i+1][j]+=dp[i][j]
dp[i+1][j]%=mod
continue
dp[i+1][j+1]+=2*dp[i][j]
dp[i+1][j+1]%=mod
dp[i+1][j-1]+=dp[i][j]
dp[i+1][j-1]%=mod
t=pow(2,(mod-2),mod)
t=pow(t,l,mod)
print((dp[-1][l]*t)%mod)
``` | output | 1 | 100,230 | 18 | 200,461 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key.
To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string:
* The `0` key: a letter `0` will be inserted to the right of the string.
* The `1` key: a letter `1` will be inserted to the right of the string.
* The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted.
Sig has launched the editor, and pressed these keys N times in total. As a result, the editor displays a string s. Find the number of such ways to press the keys, modulo 10^9 + 7.
Constraints
* 1 ≦ N ≦ 5000
* 1 ≦ |s| ≦ N
* s consists of the letters `0` and `1`.
Input
The input is given from Standard Input in the following format:
N
s
Output
Print the number of the ways to press the keys N times in total such that the editor displays the string s in the end, modulo 10^9+7.
Examples
Input
3
0
Output
5
Input
300
1100100
Output
519054663
Input
5000
01000001011101000100001101101111011001000110010101110010000
Output
500886057
Submitted Solution:
```
MOD = 10**9 + 7
n = int(input())
s = input().rstrip()
m = len(s)
dp = [[0] * (n + 3) for _ in range(n + 3)]
dp[0][0] = 1
for i in range(1, n + 1):
dp[0][i] += dp[0][i-1]
dp[0][i] %= MOD
for j in range(i + 1):
# Delete
dp[j-1][i] += dp[j][i-1]
# Add
dp[j+1][i] += dp[j][i-1] * 2
dp[j+1][i] %= MOD
div2 = pow(2, MOD-2, MOD)
ans = dp[m][n]
for i in range(m):
ans *= div2
ans %= MOD
print(ans)
``` | instruction | 0 | 100,231 | 18 | 200,462 |
Yes | output | 1 | 100,231 | 18 | 200,463 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key.
To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string:
* The `0` key: a letter `0` will be inserted to the right of the string.
* The `1` key: a letter `1` will be inserted to the right of the string.
* The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted.
Sig has launched the editor, and pressed these keys N times in total. As a result, the editor displays a string s. Find the number of such ways to press the keys, modulo 10^9 + 7.
Constraints
* 1 ≦ N ≦ 5000
* 1 ≦ |s| ≦ N
* s consists of the letters `0` and `1`.
Input
The input is given from Standard Input in the following format:
N
s
Output
Print the number of the ways to press the keys N times in total such that the editor displays the string s in the end, modulo 10^9+7.
Examples
Input
3
0
Output
5
Input
300
1100100
Output
519054663
Input
5000
01000001011101000100001101101111011001000110010101110010000
Output
500886057
Submitted Solution:
```
N=int(input())
s=input()
K=len(s)
mod=10**9+7
dp=[]
for i in range(N+1):
dp.append([0]*(i+1))
dp[0][0]=1
for i in range(N):
for j in range(i+1):
if j>=1:
dp[i+1][j-1]+=dp[i][j]
else:
dp[i+1][j]+=dp[i][j]
dp[i+1][j+1]+=2*dp[i][j]
dp[i+1][j-1]%=mod
dp[i+1][j+1]%=mod
def power(x,y):
if y==0:
return 1
if y==1:
return x%mod
if y==2:
return (x*x)%mod
if y%2:
return (power(power(x,(y-1)//2),2)*x)%mod
else:
return power(power(x,y//2),2)
a=power(2,K)
inv=power(a,mod-2)
print((dp[N][K]*inv)%mod)
``` | instruction | 0 | 100,232 | 18 | 200,464 |
Yes | output | 1 | 100,232 | 18 | 200,465 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key.
To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string:
* The `0` key: a letter `0` will be inserted to the right of the string.
* The `1` key: a letter `1` will be inserted to the right of the string.
* The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted.
Sig has launched the editor, and pressed these keys N times in total. As a result, the editor displays a string s. Find the number of such ways to press the keys, modulo 10^9 + 7.
Constraints
* 1 ≦ N ≦ 5000
* 1 ≦ |s| ≦ N
* s consists of the letters `0` and `1`.
Input
The input is given from Standard Input in the following format:
N
s
Output
Print the number of the ways to press the keys N times in total such that the editor displays the string s in the end, modulo 10^9+7.
Examples
Input
3
0
Output
5
Input
300
1100100
Output
519054663
Input
5000
01000001011101000100001101101111011001000110010101110010000
Output
500886057
Submitted Solution:
```
n = int(input())
s = input()
l = len(s)
mod = 10**9+7
dp = [[0 for i in range(j+1)] for j in range(n+1)]
dp[0][0] = 1
for i in range(1,n+1):
if i == 1:
dp[1][0] = 1
else:
dp[i][0] = dp[i-1][1]*2+dp[i-1][0]
dp[i][0] %= mod
for j in range(1,i+1):
if j < i-1:
dp[i][j] = 2*dp[i-1][j+1]
dp[i][j] += dp[i-1][j-1]
dp[i][j] %= mod
print(dp[n][l])
``` | instruction | 0 | 100,233 | 18 | 200,466 |
Yes | output | 1 | 100,233 | 18 | 200,467 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key.
To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string:
* The `0` key: a letter `0` will be inserted to the right of the string.
* The `1` key: a letter `1` will be inserted to the right of the string.
* The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted.
Sig has launched the editor, and pressed these keys N times in total. As a result, the editor displays a string s. Find the number of such ways to press the keys, modulo 10^9 + 7.
Constraints
* 1 ≦ N ≦ 5000
* 1 ≦ |s| ≦ N
* s consists of the letters `0` and `1`.
Input
The input is given from Standard Input in the following format:
N
s
Output
Print the number of the ways to press the keys N times in total such that the editor displays the string s in the end, modulo 10^9+7.
Examples
Input
3
0
Output
5
Input
300
1100100
Output
519054663
Input
5000
01000001011101000100001101101111011001000110010101110010000
Output
500886057
Submitted Solution:
```
N=int(input())
s=input()
l=len(s)
dp=[[0]*(N+2) for i in range(N)]
dp[0][1]=2
dp[0][0]=1
mod=10**9+7
for i in range(N-1):
for j in range(i+2):
if j==0:
dp[i+1][j+1]+=2*dp[i][j]
dp[i+1][j+1]%=mod
dp[i+1][j]+=dp[i][j]
dp[i+1][j]%=mod
continue
dp[i+1][j+1]+=2*dp[i][j]
dp[i+1][j+1]%=mod
dp[i+1][j-1]+=dp[i][j]
dp[i+1][j-1]%=mod
t=pow(2,(mod-2),mod)
t=pow(t,l,mod)
print((dp[-1][l]*t)%mod)
``` | instruction | 0 | 100,236 | 18 | 200,472 |
No | output | 1 | 100,236 | 18 | 200,473 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key.
To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string:
* The `0` key: a letter `0` will be inserted to the right of the string.
* The `1` key: a letter `1` will be inserted to the right of the string.
* The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted.
Sig has launched the editor, and pressed these keys N times in total. As a result, the editor displays a string s. Find the number of such ways to press the keys, modulo 10^9 + 7.
Constraints
* 1 ≦ N ≦ 5000
* 1 ≦ |s| ≦ N
* s consists of the letters `0` and `1`.
Input
The input is given from Standard Input in the following format:
N
s
Output
Print the number of the ways to press the keys N times in total such that the editor displays the string s in the end, modulo 10^9+7.
Examples
Input
3
0
Output
5
Input
300
1100100
Output
519054663
Input
5000
01000001011101000100001101101111011001000110010101110010000
Output
500886057
Submitted Solution:
```
n=int(input())
s=input()
m=len(s)
mod=10**9+7
dp=[[0]*(n+1) for i in range(n+1)]
dp[0][0]=1
for i in range(1,n+1):
for j in range(n+1):
if j==0:
dp[i][j]+=dp[i-1][j]+dp[i-1][j+1]
elif j==n:
dp[i][j]+=dp[i-1][j-1]*2
else:
dp[i][j]+=dp[i-1][j-1]*2+dp[i-1][j+1]
dp[i][j]%=mod
def div(a,b):
return (a*pow(b,mod-2,mod))%mod
print(div(dp[n][m],pow(2,m)))
``` | instruction | 0 | 100,237 | 18 | 200,474 |
No | output | 1 | 100,237 | 18 | 200,475 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the `0` key, the `1` key and the backspace key.
To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string:
* The `0` key: a letter `0` will be inserted to the right of the string.
* The `1` key: a letter `1` will be inserted to the right of the string.
* The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted.
Sig has launched the editor, and pressed these keys N times in total. As a result, the editor displays a string s. Find the number of such ways to press the keys, modulo 10^9 + 7.
Constraints
* 1 ≦ N ≦ 5000
* 1 ≦ |s| ≦ N
* s consists of the letters `0` and `1`.
Input
The input is given from Standard Input in the following format:
N
s
Output
Print the number of the ways to press the keys N times in total such that the editor displays the string s in the end, modulo 10^9+7.
Examples
Input
3
0
Output
5
Input
300
1100100
Output
519054663
Input
5000
01000001011101000100001101101111011001000110010101110010000
Output
500886057
Submitted Solution:
```
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
N=I()
s=input()
t=len(s)
#文字数が同じなら通り数は一緒なので文字数だけ見る
dp=[[0]*(N+1) for _ in range(N+1)]
#i回操作して,j文字になる
dp[0][0]=1
for i in range(N):
for j in range(i+1):
if j!=0:
dp[i+1][j-1]=(dp[i+1][j-1] + dp[i][j])%mod
else:
dp[i+1][0]=(dp[i+1][0]+dp[i][0])%mod
dp[i+1][j+1]=(dp[i+1][j+1] + 2*dp[i][j])%mod
temp=pow(2,t,mod)
ans=(dp[-1][t]*pow(temp,mod-2,mod))%mod
print(ans)
main()
``` | instruction | 0 | 100,238 | 18 | 200,476 |
No | output | 1 | 100,238 | 18 | 200,477 |
Provide a correct Python 3 solution for this coding contest problem.
Hiroshi:? D-C'KOPUA
Peter: What's wrong, Dr. David? I'm used to shouting something I don't understand, but I'm not even writing it today.
Hiroshi: Here.
<image>
Peter: What? This table ... oh, there was something like this in the qualifying question. Replacing characters using a table reduces the number of characters. I don't think I'm willing to give the same problem in the qualifying and the final and cut corners.
Hiroshi: It's the other way around.
Peter: Reverse? I see, is it a problem to get the shortened string back? That means that you can replace the letters "? D-C'KOPUA" from "letter" to "sign" using this table ...
11111 00011 11101 00010 11110 01010 01110 01111 10100 00000
Hiroshi: Umm. Next is this.
<image>
Peter: Yeah, there was also a table like this. Since this is used in reverse, you can replace "sign" with "character". But at first it is "11111", but it's not in the table, right?
Hiroshi: In that case, try making it shorter or connecting it to the back.
Peter: Then shorten it ... Oh, there is "111". Then it is "P" at first. Then, the rest is "11", but since this does not fit exactly, you can borrow one character from the next "00011" and make it "110".
Hiroshi: That's right. In other words, it's "E".
Peter: That's what remains of "0011", so I borrowed this from the next and changed it to "00111" and said "T" ... I've done it all. You should throw away the last "0000", right?
<image>
Hiroshi: That's right. Next is this.
? D-C'?-C'-LMGZN? FNJKN- WEYN? P'QMRWLPZLKKTPOVRGDI
Hiroshi: Furthermore, this is it.
? P'QNPY? IXX? IXXK.BI -G? R'RPP'RPOVWDMW? SWUVG'-LCMGQ
Hiroshi: Let's finish it.
? P'QMDUEQ GADKOQ? SWUVG'-LCMG? X? IGX, PUL.? UL.VNQQI
Peter: It's a hassle. Doctor, please make your own program this time.
So, instead of the doctor, create a program that replaces the above sentence.
Input
Given multiple datasets. For each dataset, one string (a string of 200 characters or less consisting of the characters contained in the table) is given on one line. Please process until the end of the input. The number of datasets does not exceed 200.
Output
For each data set, output the converted character string on one line.
Example
Input
?D-C'KOPUA
Output
PETER POTTER | instruction | 0 | 100,239 | 18 | 200,478 |
"Correct Solution:
```
import sys
def cv1(c):
o=ord(c)
if 65<=o<=90:
return format(o-65,"05b")
elif o==32:
return "11010"
elif o==46:
return "11011"
elif o==44:
return "11100"
elif o==45:
return "11101"
elif o==39:
return "11110"
elif o==63:
return "11111"
d={"101":" ",
"000000":"'",
"000011":",",
"10010001":"-",
"010001":".",
"000001":"?",
"100101":"A",
"10011010":"B",
"0101":"C",
"0001":"D",
"110":"E",
"01001":"F",
"10011011":"G",
"010000":"H",
"0111":"I",
"10011000":"J",
"0110":"K",
"00100":"L",
"10011001":"M",
"10011110":"N",
"00101":"O",
"111":"P",
"10011111":"Q",
"1000":"R",
"00110":"S",
"00111":"T",
"10011100":"U",
"10011101":"V",
"000010":"W",
"10010010":"X",
"10010011":"Y",
"10010000":"Z"
}
sk=sorted(d.keys(),key=lambda x:len(x))
for t in sys.stdin:
cn=0
st=""
ta="".join([cv1(i) for i in t[:-1]])
tmp=""
for i in ta:
tmp+=i
if tmp in d:
st+=d[tmp]
tmp=""
print(st)
``` | output | 1 | 100,239 | 18 | 200,479 |
Provide a correct Python 3 solution for this coding contest problem.
Hiroshi:? D-C'KOPUA
Peter: What's wrong, Dr. David? I'm used to shouting something I don't understand, but I'm not even writing it today.
Hiroshi: Here.
<image>
Peter: What? This table ... oh, there was something like this in the qualifying question. Replacing characters using a table reduces the number of characters. I don't think I'm willing to give the same problem in the qualifying and the final and cut corners.
Hiroshi: It's the other way around.
Peter: Reverse? I see, is it a problem to get the shortened string back? That means that you can replace the letters "? D-C'KOPUA" from "letter" to "sign" using this table ...
11111 00011 11101 00010 11110 01010 01110 01111 10100 00000
Hiroshi: Umm. Next is this.
<image>
Peter: Yeah, there was also a table like this. Since this is used in reverse, you can replace "sign" with "character". But at first it is "11111", but it's not in the table, right?
Hiroshi: In that case, try making it shorter or connecting it to the back.
Peter: Then shorten it ... Oh, there is "111". Then it is "P" at first. Then, the rest is "11", but since this does not fit exactly, you can borrow one character from the next "00011" and make it "110".
Hiroshi: That's right. In other words, it's "E".
Peter: That's what remains of "0011", so I borrowed this from the next and changed it to "00111" and said "T" ... I've done it all. You should throw away the last "0000", right?
<image>
Hiroshi: That's right. Next is this.
? D-C'?-C'-LMGZN? FNJKN- WEYN? P'QMRWLPZLKKTPOVRGDI
Hiroshi: Furthermore, this is it.
? P'QNPY? IXX? IXXK.BI -G? R'RPP'RPOVWDMW? SWUVG'-LCMGQ
Hiroshi: Let's finish it.
? P'QMDUEQ GADKOQ? SWUVG'-LCMG? X? IGX, PUL.? UL.VNQQI
Peter: It's a hassle. Doctor, please make your own program this time.
So, instead of the doctor, create a program that replaces the above sentence.
Input
Given multiple datasets. For each dataset, one string (a string of 200 characters or less consisting of the characters contained in the table) is given on one line. Please process until the end of the input. The number of datasets does not exceed 200.
Output
For each data set, output the converted character string on one line.
Example
Input
?D-C'KOPUA
Output
PETER POTTER | instruction | 0 | 100,240 | 18 | 200,480 |
"Correct Solution:
```
en='ABCDEFGHIJKLMNOPQRSTUVWXYZ'+' .,-\'?'
de={
'101':' ','000000':'\'','000011':',','10010001':'-','010001':'.','000001':'?',
'100101':'A','10011010':'B','0101':'C','0001':'D','110':'E','01001':'F',
'10011011':'G','010000':'H','0111':'I','10011000':'J','0110':'K','00100':'L',
'10011001':'M','10011110':'N','00101':'O','111':'P','10011111':'Q','1000':'R',
'00110':'S','00111':'T','10011100':'U','10011101':'V','000010':'W','10010010':'X',
'10010011':'Y','10010000':'Z'
}
while 1:
try:s=input()
except:break
a=b=c=''
for x in s:a+=str(bin(en.index(x)))[2:].zfill(5)
for x in a:
b+=x
if b in de:c+=de[b];b=''
print(c)
``` | output | 1 | 100,240 | 18 | 200,481 |
Provide a correct Python 3 solution for this coding contest problem.
Hiroshi:? D-C'KOPUA
Peter: What's wrong, Dr. David? I'm used to shouting something I don't understand, but I'm not even writing it today.
Hiroshi: Here.
<image>
Peter: What? This table ... oh, there was something like this in the qualifying question. Replacing characters using a table reduces the number of characters. I don't think I'm willing to give the same problem in the qualifying and the final and cut corners.
Hiroshi: It's the other way around.
Peter: Reverse? I see, is it a problem to get the shortened string back? That means that you can replace the letters "? D-C'KOPUA" from "letter" to "sign" using this table ...
11111 00011 11101 00010 11110 01010 01110 01111 10100 00000
Hiroshi: Umm. Next is this.
<image>
Peter: Yeah, there was also a table like this. Since this is used in reverse, you can replace "sign" with "character". But at first it is "11111", but it's not in the table, right?
Hiroshi: In that case, try making it shorter or connecting it to the back.
Peter: Then shorten it ... Oh, there is "111". Then it is "P" at first. Then, the rest is "11", but since this does not fit exactly, you can borrow one character from the next "00011" and make it "110".
Hiroshi: That's right. In other words, it's "E".
Peter: That's what remains of "0011", so I borrowed this from the next and changed it to "00111" and said "T" ... I've done it all. You should throw away the last "0000", right?
<image>
Hiroshi: That's right. Next is this.
? D-C'?-C'-LMGZN? FNJKN- WEYN? P'QMRWLPZLKKTPOVRGDI
Hiroshi: Furthermore, this is it.
? P'QNPY? IXX? IXXK.BI -G? R'RPP'RPOVWDMW? SWUVG'-LCMGQ
Hiroshi: Let's finish it.
? P'QMDUEQ GADKOQ? SWUVG'-LCMG? X? IGX, PUL.? UL.VNQQI
Peter: It's a hassle. Doctor, please make your own program this time.
So, instead of the doctor, create a program that replaces the above sentence.
Input
Given multiple datasets. For each dataset, one string (a string of 200 characters or less consisting of the characters contained in the table) is given on one line. Please process until the end of the input. The number of datasets does not exceed 200.
Output
For each data set, output the converted character string on one line.
Example
Input
?D-C'KOPUA
Output
PETER POTTER | instruction | 0 | 100,241 | 18 | 200,482 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0111
"""
import sys
from sys import stdin
input = stdin.readline
def solve(data):
txt = ''
for d in data:
txt += rev_decoder[d]
result = ''
while txt:
match = False
for k in rev_encoder.keys():
if txt.startswith(k):
match = True
result += rev_encoder[k]
txt = txt[len(k):]
break
if match is False:
break
return result
# AOJ 0088?????????
encoder = {' ':'101', "'":'000000', ',':'000011', '-':'10010001', '.':'010001', '?':'000001', 'A':'100101', 'B':'10011010',
'C':'0101','D':'0001', 'E':'110', 'F':'01001', 'G':'10011011', 'H':'010000', 'I':'0111','J':'10011000',
'K':'0110', 'L':'00100', 'M':'10011001', 'N':'10011110', 'O':'00101', 'P':'111', 'Q':'10011111', 'R':'1000',
'S':'00110', 'T':'00111', 'U':'10011100', 'V':'10011101', 'W':'000010', 'X':'10010010', 'Y':'10010011', 'Z':'10010000'
}
rev_encoder = dict(zip(encoder.values(), encoder.keys()))
decoder = {'00000':'A', '00001':'B', '00010':'C', '00011':'D', '00100':'E', '00101':'F', '00110':'G', '00111':'H',
'01000':'I', '01001':'J', '01010':'K', '01011':'L', '01100':'M', '01101':'N', '01110':'O', '01111':'P',
'10000':'Q', '10001':'R', '10010':'S', '10011':'T', '10100':'U', '10101':'V', '10110':'W', '10111':'X',
'11000':'Y', '11001':'Z', '11010':' ', '11011':'.', '11100':',', '11101':'-', '11110':"'", '11111':'?'
}
rev_decoder = dict(zip(decoder.values(), decoder.keys()))
def main(args):
for data in sys.stdin:
result = solve(data.strip('\n'))
print(result)
if __name__ == '__main__':
main(sys.argv[1:])
``` | output | 1 | 100,241 | 18 | 200,483 |
Provide a correct Python 3 solution for this coding contest problem.
Hiroshi:? D-C'KOPUA
Peter: What's wrong, Dr. David? I'm used to shouting something I don't understand, but I'm not even writing it today.
Hiroshi: Here.
<image>
Peter: What? This table ... oh, there was something like this in the qualifying question. Replacing characters using a table reduces the number of characters. I don't think I'm willing to give the same problem in the qualifying and the final and cut corners.
Hiroshi: It's the other way around.
Peter: Reverse? I see, is it a problem to get the shortened string back? That means that you can replace the letters "? D-C'KOPUA" from "letter" to "sign" using this table ...
11111 00011 11101 00010 11110 01010 01110 01111 10100 00000
Hiroshi: Umm. Next is this.
<image>
Peter: Yeah, there was also a table like this. Since this is used in reverse, you can replace "sign" with "character". But at first it is "11111", but it's not in the table, right?
Hiroshi: In that case, try making it shorter or connecting it to the back.
Peter: Then shorten it ... Oh, there is "111". Then it is "P" at first. Then, the rest is "11", but since this does not fit exactly, you can borrow one character from the next "00011" and make it "110".
Hiroshi: That's right. In other words, it's "E".
Peter: That's what remains of "0011", so I borrowed this from the next and changed it to "00111" and said "T" ... I've done it all. You should throw away the last "0000", right?
<image>
Hiroshi: That's right. Next is this.
? D-C'?-C'-LMGZN? FNJKN- WEYN? P'QMRWLPZLKKTPOVRGDI
Hiroshi: Furthermore, this is it.
? P'QNPY? IXX? IXXK.BI -G? R'RPP'RPOVWDMW? SWUVG'-LCMGQ
Hiroshi: Let's finish it.
? P'QMDUEQ GADKOQ? SWUVG'-LCMG? X? IGX, PUL.? UL.VNQQI
Peter: It's a hassle. Doctor, please make your own program this time.
So, instead of the doctor, create a program that replaces the above sentence.
Input
Given multiple datasets. For each dataset, one string (a string of 200 characters or less consisting of the characters contained in the table) is given on one line. Please process until the end of the input. The number of datasets does not exceed 200.
Output
For each data set, output the converted character string on one line.
Example
Input
?D-C'KOPUA
Output
PETER POTTER | instruction | 0 | 100,242 | 18 | 200,484 |
"Correct Solution:
```
while 1:
try:
s=input()
s_c=""
c1=[" ",".",",","-","'","?"]
for i in s:
if 64<ord(i)<91:
s_c+=str(bin(ord(i)-65)[2:]).zfill(5)
else:
s_c+=str(bin(c1.index(i)+26)[2:]).zfill(5)
ch_3=["101","110","111"]
re_3=[" ","E","P"]
ch_4=["0101","0001","0111","0110","1000"]
re_4=["C","D","I","K","R"]
ch_5=["01001","00100","00101","00110","00111"]
re_5=["F","L","O","S","T"]
ch_6=["000000","000011","010001","000001","100101","010000","000010"]
re_6=["'",",",".","?","A","H","W"]
ch_8=["10010001","10011010","10011011","10011000","10011001","10011110","10011111","10011100","10011101","10010010","10010011","10010000"]
re_8=["-","B","G","J","M","N","Q","U","V","X","Y","Z"]
ans=""
while 1:
if len(s_c)==0 or len(s_c)<5 and int(s_c)==0:break
elif s_c[:3] in ch_3:
ans+=re_3[ch_3.index(s_c[:3])]
s_c=s_c[3:]
elif s_c[:4] in ch_4:
ans+=re_4[ch_4.index(s_c[:4])]
s_c=s_c[4:]
elif s_c[:5] in ch_5:
ans+=re_5[ch_5.index(s_c[:5])]
s_c=s_c[5:]
elif s_c[:6] in ch_6:
ans+=re_6[ch_6.index(s_c[:6])]
s_c=s_c[6:]
elif s_c[:8] in ch_8:
ans+=re_8[ch_8.index(s_c[:8])]
s_c=s_c[8:]
else:
s_c+="0"
print(ans)
except:break
``` | output | 1 | 100,242 | 18 | 200,485 |
Provide a correct Python 3 solution for this coding contest problem.
Hiroshi:? D-C'KOPUA
Peter: What's wrong, Dr. David? I'm used to shouting something I don't understand, but I'm not even writing it today.
Hiroshi: Here.
<image>
Peter: What? This table ... oh, there was something like this in the qualifying question. Replacing characters using a table reduces the number of characters. I don't think I'm willing to give the same problem in the qualifying and the final and cut corners.
Hiroshi: It's the other way around.
Peter: Reverse? I see, is it a problem to get the shortened string back? That means that you can replace the letters "? D-C'KOPUA" from "letter" to "sign" using this table ...
11111 00011 11101 00010 11110 01010 01110 01111 10100 00000
Hiroshi: Umm. Next is this.
<image>
Peter: Yeah, there was also a table like this. Since this is used in reverse, you can replace "sign" with "character". But at first it is "11111", but it's not in the table, right?
Hiroshi: In that case, try making it shorter or connecting it to the back.
Peter: Then shorten it ... Oh, there is "111". Then it is "P" at first. Then, the rest is "11", but since this does not fit exactly, you can borrow one character from the next "00011" and make it "110".
Hiroshi: That's right. In other words, it's "E".
Peter: That's what remains of "0011", so I borrowed this from the next and changed it to "00111" and said "T" ... I've done it all. You should throw away the last "0000", right?
<image>
Hiroshi: That's right. Next is this.
? D-C'?-C'-LMGZN? FNJKN- WEYN? P'QMRWLPZLKKTPOVRGDI
Hiroshi: Furthermore, this is it.
? P'QNPY? IXX? IXXK.BI -G? R'RPP'RPOVWDMW? SWUVG'-LCMGQ
Hiroshi: Let's finish it.
? P'QMDUEQ GADKOQ? SWUVG'-LCMG? X? IGX, PUL.? UL.VNQQI
Peter: It's a hassle. Doctor, please make your own program this time.
So, instead of the doctor, create a program that replaces the above sentence.
Input
Given multiple datasets. For each dataset, one string (a string of 200 characters or less consisting of the characters contained in the table) is given on one line. Please process until the end of the input. The number of datasets does not exceed 200.
Output
For each data set, output the converted character string on one line.
Example
Input
?D-C'KOPUA
Output
PETER POTTER | instruction | 0 | 100,243 | 18 | 200,486 |
"Correct Solution:
```
encoder = {
"A": "00000",
"B": "00001",
"C": "00010",
"D": "00011",
"E": "00100",
"F": "00101",
"G": "00110",
"H": "00111",
"I": "01000",
"J": "01001",
"K": "01010",
"L": "01011",
"M": "01100",
"N": "01101",
"O": "01110",
"P": "01111",
"Q": "10000",
"R": "10001",
"S": "10010",
"T": "10011",
"U": "10100",
"V": "10101",
"W": "10110",
"X": "10111",
"Y": "11000",
"Z": "11001",
" ": "11010",
".": "11011",
",": "11100",
"-": "11101",
"'": "11110",
"?": "11111"
}
decoder={
"101":" ",
"000000":"'",
"000011":",",
"10010001":"-",
"010001":".",
"000001":"?",
"100101":"A",
"10011010":"B",
"0101":"C",
"0001":"D",
"110":"E",
"01001":"F",
"10011011":"G",
"010000":"H",
"0111":"I",
"10011000":"J",
"0110":"K",
"00100":"L",
"10011001":"M",
"10011110":"N",
"00101":"O",
"111":"P",
"10011111":"Q",
"1000":"R",
"00110":"S",
"00111":"T",
"10011100":"U",
"10011101":"V",
"000010":"W",
"10010010":"X",
"10010011":"Y",
"10010000":"Z"
}
def encode(strings):
retval=""
for s in strings:
retval+=encoder[s]
return retval
def decode(strings):
for i in range(len(strings)+10):
if strings[:i:] in decoder:
return decoder[strings[:i:]]+decode(strings[i::])
return ""
while True:
try:
print(decode(encode(input())))
except EOFError:
break
``` | output | 1 | 100,243 | 18 | 200,487 |
Provide a correct Python 3 solution for this coding contest problem.
Hiroshi:? D-C'KOPUA
Peter: What's wrong, Dr. David? I'm used to shouting something I don't understand, but I'm not even writing it today.
Hiroshi: Here.
<image>
Peter: What? This table ... oh, there was something like this in the qualifying question. Replacing characters using a table reduces the number of characters. I don't think I'm willing to give the same problem in the qualifying and the final and cut corners.
Hiroshi: It's the other way around.
Peter: Reverse? I see, is it a problem to get the shortened string back? That means that you can replace the letters "? D-C'KOPUA" from "letter" to "sign" using this table ...
11111 00011 11101 00010 11110 01010 01110 01111 10100 00000
Hiroshi: Umm. Next is this.
<image>
Peter: Yeah, there was also a table like this. Since this is used in reverse, you can replace "sign" with "character". But at first it is "11111", but it's not in the table, right?
Hiroshi: In that case, try making it shorter or connecting it to the back.
Peter: Then shorten it ... Oh, there is "111". Then it is "P" at first. Then, the rest is "11", but since this does not fit exactly, you can borrow one character from the next "00011" and make it "110".
Hiroshi: That's right. In other words, it's "E".
Peter: That's what remains of "0011", so I borrowed this from the next and changed it to "00111" and said "T" ... I've done it all. You should throw away the last "0000", right?
<image>
Hiroshi: That's right. Next is this.
? D-C'?-C'-LMGZN? FNJKN- WEYN? P'QMRWLPZLKKTPOVRGDI
Hiroshi: Furthermore, this is it.
? P'QNPY? IXX? IXXK.BI -G? R'RPP'RPOVWDMW? SWUVG'-LCMGQ
Hiroshi: Let's finish it.
? P'QMDUEQ GADKOQ? SWUVG'-LCMG? X? IGX, PUL.? UL.VNQQI
Peter: It's a hassle. Doctor, please make your own program this time.
So, instead of the doctor, create a program that replaces the above sentence.
Input
Given multiple datasets. For each dataset, one string (a string of 200 characters or less consisting of the characters contained in the table) is given on one line. Please process until the end of the input. The number of datasets does not exceed 200.
Output
For each data set, output the converted character string on one line.
Example
Input
?D-C'KOPUA
Output
PETER POTTER | instruction | 0 | 100,244 | 18 | 200,488 |
"Correct Solution:
```
en='ABCDEFGHIJKLMNOPQRSTUVWXYZ'+' .,-\'?'
de={
'101':' ','000000':'\'','000011':',','10010001':'-','010001':'.','000001':'?',
'100101':'A','10011010':'B','0101':'C','0001':'D','110':'E','01001':'F',
'10011011':'G','010000':'H','0111':'I','10011000':'J','0110':'K','00100':'L',
'10011001':'M','10011110':'N','00101':'O','111':'P','10011111':'Q','1000':'R',
'00110':'S','00111':'T','10011100':'U','10011101':'V','000010':'W','10010010':'X',
'10010011':'Y','10010000':'Z'
}
while 1:
try:s=input()
except:break
a=b=c=''
for x in s:a+=str(bin(en.index(x)))[2:].zfill(5)
for i in range(len(a)):
b+=a[i]
if b in de:c+=de[b];b=''
print(c)
``` | output | 1 | 100,244 | 18 | 200,489 |
Provide a correct Python 3 solution for this coding contest problem.
Hiroshi:? D-C'KOPUA
Peter: What's wrong, Dr. David? I'm used to shouting something I don't understand, but I'm not even writing it today.
Hiroshi: Here.
<image>
Peter: What? This table ... oh, there was something like this in the qualifying question. Replacing characters using a table reduces the number of characters. I don't think I'm willing to give the same problem in the qualifying and the final and cut corners.
Hiroshi: It's the other way around.
Peter: Reverse? I see, is it a problem to get the shortened string back? That means that you can replace the letters "? D-C'KOPUA" from "letter" to "sign" using this table ...
11111 00011 11101 00010 11110 01010 01110 01111 10100 00000
Hiroshi: Umm. Next is this.
<image>
Peter: Yeah, there was also a table like this. Since this is used in reverse, you can replace "sign" with "character". But at first it is "11111", but it's not in the table, right?
Hiroshi: In that case, try making it shorter or connecting it to the back.
Peter: Then shorten it ... Oh, there is "111". Then it is "P" at first. Then, the rest is "11", but since this does not fit exactly, you can borrow one character from the next "00011" and make it "110".
Hiroshi: That's right. In other words, it's "E".
Peter: That's what remains of "0011", so I borrowed this from the next and changed it to "00111" and said "T" ... I've done it all. You should throw away the last "0000", right?
<image>
Hiroshi: That's right. Next is this.
? D-C'?-C'-LMGZN? FNJKN- WEYN? P'QMRWLPZLKKTPOVRGDI
Hiroshi: Furthermore, this is it.
? P'QNPY? IXX? IXXK.BI -G? R'RPP'RPOVWDMW? SWUVG'-LCMGQ
Hiroshi: Let's finish it.
? P'QMDUEQ GADKOQ? SWUVG'-LCMG? X? IGX, PUL.? UL.VNQQI
Peter: It's a hassle. Doctor, please make your own program this time.
So, instead of the doctor, create a program that replaces the above sentence.
Input
Given multiple datasets. For each dataset, one string (a string of 200 characters or less consisting of the characters contained in the table) is given on one line. Please process until the end of the input. The number of datasets does not exceed 200.
Output
For each data set, output the converted character string on one line.
Example
Input
?D-C'KOPUA
Output
PETER POTTER | instruction | 0 | 100,245 | 18 | 200,490 |
"Correct Solution:
```
to_bin = dict(zip([chr(i) for i in range(ord("A"), ord("Z") + 1)] + [" ", ".", ",", "-", "'", "?"],
[bin(i)[2:7].zfill(5) for i in range(2 ** 5)]))
to_chr = {"101": " ", "000000": "'", "000011": ",", "10010001": "-", "010001": ".", "000001": "?", "100101": "A",
"10011010": "B",
"0101": "C", "0001": "D", "110": "E", "01001": "F", "10011011": "G", "010000": "H", "0111": "I",
"10011000": "J",
"0110": "K", "00100": "L", "10011001": "M", "10011110": "N", "00101": "O", "111": "P", "10011111": "Q",
"1000": "R",
"00110": "S", "00111": "T", "10011100": "U", "10011101": "V", "000010": "W", "10010010": "X", "10010011": "Y",
"10010000": "Z"}
while 1:
try:
N=list(input())
first = ""
for i in N:
if i in to_bin:first +=to_bin[i]
first = list(first)
key=""
answer = ""
for j in first:
key +=j
if key in to_chr:
answer +=to_chr[key]
key = ""
print(answer)
except:break
``` | output | 1 | 100,245 | 18 | 200,491 |
Provide a correct Python 3 solution for this coding contest problem.
Hiroshi:? D-C'KOPUA
Peter: What's wrong, Dr. David? I'm used to shouting something I don't understand, but I'm not even writing it today.
Hiroshi: Here.
<image>
Peter: What? This table ... oh, there was something like this in the qualifying question. Replacing characters using a table reduces the number of characters. I don't think I'm willing to give the same problem in the qualifying and the final and cut corners.
Hiroshi: It's the other way around.
Peter: Reverse? I see, is it a problem to get the shortened string back? That means that you can replace the letters "? D-C'KOPUA" from "letter" to "sign" using this table ...
11111 00011 11101 00010 11110 01010 01110 01111 10100 00000
Hiroshi: Umm. Next is this.
<image>
Peter: Yeah, there was also a table like this. Since this is used in reverse, you can replace "sign" with "character". But at first it is "11111", but it's not in the table, right?
Hiroshi: In that case, try making it shorter or connecting it to the back.
Peter: Then shorten it ... Oh, there is "111". Then it is "P" at first. Then, the rest is "11", but since this does not fit exactly, you can borrow one character from the next "00011" and make it "110".
Hiroshi: That's right. In other words, it's "E".
Peter: That's what remains of "0011", so I borrowed this from the next and changed it to "00111" and said "T" ... I've done it all. You should throw away the last "0000", right?
<image>
Hiroshi: That's right. Next is this.
? D-C'?-C'-LMGZN? FNJKN- WEYN? P'QMRWLPZLKKTPOVRGDI
Hiroshi: Furthermore, this is it.
? P'QNPY? IXX? IXXK.BI -G? R'RPP'RPOVWDMW? SWUVG'-LCMGQ
Hiroshi: Let's finish it.
? P'QMDUEQ GADKOQ? SWUVG'-LCMG? X? IGX, PUL.? UL.VNQQI
Peter: It's a hassle. Doctor, please make your own program this time.
So, instead of the doctor, create a program that replaces the above sentence.
Input
Given multiple datasets. For each dataset, one string (a string of 200 characters or less consisting of the characters contained in the table) is given on one line. Please process until the end of the input. The number of datasets does not exceed 200.
Output
For each data set, output the converted character string on one line.
Example
Input
?D-C'KOPUA
Output
PETER POTTER | instruction | 0 | 100,246 | 18 | 200,492 |
"Correct Solution:
```
# -*- coding: utf-8 -*-
import sys
import os
import math
import re
import random
tableA = {
"A": "00000",
"B": "00001",
"C": "00010",
"D": "00011",
"E": "00100",
"F": "00101",
"G": "00110",
"H": "00111",
"I": "01000",
"J": "01001",
"K": "01010",
"L": "01011",
"M": "01100",
"N": "01101",
"O": "01110",
"P": "01111",
"Q": "10000",
"R": "10001",
"S": "10010",
"T": "10011",
"U": "10100",
"V": "10101",
"W": "10110",
"X": "10111",
"Y": "11000",
"Z": "11001",
" ": "11010",
".": "11011",
",": "11100",
"-": "11101",
"'": "11110",
"?": "11111"}
tableB = {
"101": " ",
"000000": "'",
"000011": ",",
"10010001": "-",
"010001": ".",
"000001": "?",
"100101": "A",
"10011010": "B",
"0101": "C",
"0001": "D",
"110": "E",
"01001": "F",
"10011011": "G",
"010000": "H",
"0111": "I",
"10011000": "J",
"0110": "K",
"00100": "L",
"10011001": "M",
"10011110": "N",
"00101": "O",
"111": "P",
"10011111": "Q",
"1000": "R",
"00110": "S",
"00111": "T",
"10011100": "U",
"10011101": "V",
"000010": "W",
"10010010": "X",
"10010011": "Y",
"10010000": "Z"}
def my_solve(s):
s = s.strip('\n')
lst = []
for c in s:
lst.append(tableA[c])
s = ''.join(lst)
tmp, ans = '', ''
for c in s:
tmp += c
if tmp in tableB:
ans += tableB[tmp]
tmp = ''
return ans
for s in sys.stdin:
s = s.strip('\n')
#if s == '':
# break
print(my_solve(s))
# while True:
# try:
# s = input()
# except:
# break
#
# print(my_solve(s))
``` | output | 1 | 100,246 | 18 | 200,493 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Hiroshi:? D-C'KOPUA
Peter: What's wrong, Dr. David? I'm used to shouting something I don't understand, but I'm not even writing it today.
Hiroshi: Here.
<image>
Peter: What? This table ... oh, there was something like this in the qualifying question. Replacing characters using a table reduces the number of characters. I don't think I'm willing to give the same problem in the qualifying and the final and cut corners.
Hiroshi: It's the other way around.
Peter: Reverse? I see, is it a problem to get the shortened string back? That means that you can replace the letters "? D-C'KOPUA" from "letter" to "sign" using this table ...
11111 00011 11101 00010 11110 01010 01110 01111 10100 00000
Hiroshi: Umm. Next is this.
<image>
Peter: Yeah, there was also a table like this. Since this is used in reverse, you can replace "sign" with "character". But at first it is "11111", but it's not in the table, right?
Hiroshi: In that case, try making it shorter or connecting it to the back.
Peter: Then shorten it ... Oh, there is "111". Then it is "P" at first. Then, the rest is "11", but since this does not fit exactly, you can borrow one character from the next "00011" and make it "110".
Hiroshi: That's right. In other words, it's "E".
Peter: That's what remains of "0011", so I borrowed this from the next and changed it to "00111" and said "T" ... I've done it all. You should throw away the last "0000", right?
<image>
Hiroshi: That's right. Next is this.
? D-C'?-C'-LMGZN? FNJKN- WEYN? P'QMRWLPZLKKTPOVRGDI
Hiroshi: Furthermore, this is it.
? P'QNPY? IXX? IXXK.BI -G? R'RPP'RPOVWDMW? SWUVG'-LCMGQ
Hiroshi: Let's finish it.
? P'QMDUEQ GADKOQ? SWUVG'-LCMG? X? IGX, PUL.? UL.VNQQI
Peter: It's a hassle. Doctor, please make your own program this time.
So, instead of the doctor, create a program that replaces the above sentence.
Input
Given multiple datasets. For each dataset, one string (a string of 200 characters or less consisting of the characters contained in the table) is given on one line. Please process until the end of the input. The number of datasets does not exceed 200.
Output
For each data set, output the converted character string on one line.
Example
Input
?D-C'KOPUA
Output
PETER POTTER
Submitted Solution:
```
#! python.exe
dic = {}
for idx, c in enumerate("ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"):
dic[c] = str(format(idx,'b').zfill(5))
decode = {"101" : " ", "0101" : "C", "0110" : "K", "00110" : "S",
"000000" : "'", "0001" : "D", "00100" : "L", "00111" : "T",
"000011" : ",", "110" : "E", "10011001" : "M", "10011100" : "U",
"10010001" : "-", "01001" : "F", "10011110" : "N", "10011101" : "V",
"010001" : ".", "10011011" : "G", "00101" : "O", "000010" : "W",
"000001" : "?", "010000" : "H", "111" : "P", "10010010" : "X",
"100101" : "A", "0111" : "I", "10011111" : "Q", "10010011" : "Y",
"10011010" : "B", "10011000" : "J", "1000" : "R", "10010000" : "Z"}
#print(dic)
while True:
try:
line = input()
except:
break
s = ""
for c in line:
s += dic[c]
ans = ""
while len(s) > 5 or s.count("1") :
for key in decode:
n = len(key)
if s[0:n] == key:
ans += decode[key]
s = s[n:]
break
# print(ans, s)
print(ans)
``` | instruction | 0 | 100,247 | 18 | 200,494 |
Yes | output | 1 | 100,247 | 18 | 200,495 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Hiroshi:? D-C'KOPUA
Peter: What's wrong, Dr. David? I'm used to shouting something I don't understand, but I'm not even writing it today.
Hiroshi: Here.
<image>
Peter: What? This table ... oh, there was something like this in the qualifying question. Replacing characters using a table reduces the number of characters. I don't think I'm willing to give the same problem in the qualifying and the final and cut corners.
Hiroshi: It's the other way around.
Peter: Reverse? I see, is it a problem to get the shortened string back? That means that you can replace the letters "? D-C'KOPUA" from "letter" to "sign" using this table ...
11111 00011 11101 00010 11110 01010 01110 01111 10100 00000
Hiroshi: Umm. Next is this.
<image>
Peter: Yeah, there was also a table like this. Since this is used in reverse, you can replace "sign" with "character". But at first it is "11111", but it's not in the table, right?
Hiroshi: In that case, try making it shorter or connecting it to the back.
Peter: Then shorten it ... Oh, there is "111". Then it is "P" at first. Then, the rest is "11", but since this does not fit exactly, you can borrow one character from the next "00011" and make it "110".
Hiroshi: That's right. In other words, it's "E".
Peter: That's what remains of "0011", so I borrowed this from the next and changed it to "00111" and said "T" ... I've done it all. You should throw away the last "0000", right?
<image>
Hiroshi: That's right. Next is this.
? D-C'?-C'-LMGZN? FNJKN- WEYN? P'QMRWLPZLKKTPOVRGDI
Hiroshi: Furthermore, this is it.
? P'QNPY? IXX? IXXK.BI -G? R'RPP'RPOVWDMW? SWUVG'-LCMGQ
Hiroshi: Let's finish it.
? P'QMDUEQ GADKOQ? SWUVG'-LCMG? X? IGX, PUL.? UL.VNQQI
Peter: It's a hassle. Doctor, please make your own program this time.
So, instead of the doctor, create a program that replaces the above sentence.
Input
Given multiple datasets. For each dataset, one string (a string of 200 characters or less consisting of the characters contained in the table) is given on one line. Please process until the end of the input. The number of datasets does not exceed 200.
Output
For each data set, output the converted character string on one line.
Example
Input
?D-C'KOPUA
Output
PETER POTTER
Submitted Solution:
```
L = { " ": "101",
"'": "000000",
",": "000011",
"-": "10010001",
".": "010001",
"?": "000001",
"A": "100101",
"B": "10011010",
"C": "0101",
"D": "0001",
"E": "110",
"F": "01001",
"G": "10011011",
"H": "010000",
"I": "0111",
"J": "10011000",
"K": "0110",
"L": "00100",
"M": "10011001",
"N": "10011110",
"O": "00101",
"P": "111",
"Q": "10011111",
"R": "1000",
"S": "00110",
"T": "00111",
"U": "10011100",
"V": "10011101",
"W": "000010",
"X": "10010010",
"Y": "10010011",
"Z": "10010000" }
T = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"
de = dict()
for i in range(32):
s = "{:05b}".format(i)
ch = T[i]
de[ch] = s
de2 = dict()
for k, v in L.items():
de2[v] = k
while True:
try:
t = input()
except:
break
codebit = ""
for i in t:
codebit += de[i]
s = ""
while True:
if len(codebit) == 0:
break
if len(codebit) < 6 and int(codebit,2) == 0:
break
for k in range(3,9):
if codebit[:k] in de2:
s += de2[codebit[:k]]
codebit = codebit[k:]
break
print(s)
``` | instruction | 0 | 100,248 | 18 | 200,496 |
Yes | output | 1 | 100,248 | 18 | 200,497 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Hiroshi:? D-C'KOPUA
Peter: What's wrong, Dr. David? I'm used to shouting something I don't understand, but I'm not even writing it today.
Hiroshi: Here.
<image>
Peter: What? This table ... oh, there was something like this in the qualifying question. Replacing characters using a table reduces the number of characters. I don't think I'm willing to give the same problem in the qualifying and the final and cut corners.
Hiroshi: It's the other way around.
Peter: Reverse? I see, is it a problem to get the shortened string back? That means that you can replace the letters "? D-C'KOPUA" from "letter" to "sign" using this table ...
11111 00011 11101 00010 11110 01010 01110 01111 10100 00000
Hiroshi: Umm. Next is this.
<image>
Peter: Yeah, there was also a table like this. Since this is used in reverse, you can replace "sign" with "character". But at first it is "11111", but it's not in the table, right?
Hiroshi: In that case, try making it shorter or connecting it to the back.
Peter: Then shorten it ... Oh, there is "111". Then it is "P" at first. Then, the rest is "11", but since this does not fit exactly, you can borrow one character from the next "00011" and make it "110".
Hiroshi: That's right. In other words, it's "E".
Peter: That's what remains of "0011", so I borrowed this from the next and changed it to "00111" and said "T" ... I've done it all. You should throw away the last "0000", right?
<image>
Hiroshi: That's right. Next is this.
? D-C'?-C'-LMGZN? FNJKN- WEYN? P'QMRWLPZLKKTPOVRGDI
Hiroshi: Furthermore, this is it.
? P'QNPY? IXX? IXXK.BI -G? R'RPP'RPOVWDMW? SWUVG'-LCMGQ
Hiroshi: Let's finish it.
? P'QMDUEQ GADKOQ? SWUVG'-LCMG? X? IGX, PUL.? UL.VNQQI
Peter: It's a hassle. Doctor, please make your own program this time.
So, instead of the doctor, create a program that replaces the above sentence.
Input
Given multiple datasets. For each dataset, one string (a string of 200 characters or less consisting of the characters contained in the table) is given on one line. Please process until the end of the input. The number of datasets does not exceed 200.
Output
For each data set, output the converted character string on one line.
Example
Input
?D-C'KOPUA
Output
PETER POTTER
Submitted Solution:
```
# -*- coding: utf-8 -*-
import sys
import os
import math
import re
import random
tableA = {
"A": "00000",
"B": "00001",
"C": "00010",
"D": "00011",
"E": "00100",
"F": "00101",
"G": "00110",
"H": "00111",
"I": "01000",
"J": "01001",
"K": "01010",
"L": "01011",
"M": "01100",
"N": "01101",
"O": "01110",
"P": "01111",
"Q": "10000",
"R": "10001",
"S": "10010",
"T": "10011",
"U": "10100",
"V": "10101",
"W": "10110",
"X": "10111",
"Y": "11000",
"Z": "11001",
" ": "11010",
".": "11011",
",": "11100",
"-": "11101",
"'": "11110",
"?": "11111"}
tableB = {
"101": " ",
"000000": "'",
"000011": ",",
"10010001": "-",
"010001": ".",
"000001": "?",
"100101": "A",
"10011010": "B",
"0101": "C",
"0001": "D",
"110": "E",
"01001": "F",
"10011011": "G",
"010000": "H",
"0111": "I",
"10011000": "J",
"0110": "K",
"00100": "L",
"10011001": "M",
"10011110": "N",
"00101": "O",
"111": "P",
"10011111": "Q",
"1000": "R",
"00110": "S",
"00111": "T",
"10011100": "U",
"10011101": "V",
"000010": "W",
"10010010": "X",
"10010011": "Y",
"10010000": "Z"}
def my_solve(s):
lst = []
for c in s:
lst.append(tableA[c])
s = ''.join(lst)
tmp, ans = '', ''
for c in s:
tmp += c
if tmp in tableB:
ans += tableB[tmp]
tmp = ''
return ans
while True:
try:
s = input()
except:
break
print(my_solve(s))
``` | instruction | 0 | 100,249 | 18 | 200,498 |
Yes | output | 1 | 100,249 | 18 | 200,499 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Hiroshi:? D-C'KOPUA
Peter: What's wrong, Dr. David? I'm used to shouting something I don't understand, but I'm not even writing it today.
Hiroshi: Here.
<image>
Peter: What? This table ... oh, there was something like this in the qualifying question. Replacing characters using a table reduces the number of characters. I don't think I'm willing to give the same problem in the qualifying and the final and cut corners.
Hiroshi: It's the other way around.
Peter: Reverse? I see, is it a problem to get the shortened string back? That means that you can replace the letters "? D-C'KOPUA" from "letter" to "sign" using this table ...
11111 00011 11101 00010 11110 01010 01110 01111 10100 00000
Hiroshi: Umm. Next is this.
<image>
Peter: Yeah, there was also a table like this. Since this is used in reverse, you can replace "sign" with "character". But at first it is "11111", but it's not in the table, right?
Hiroshi: In that case, try making it shorter or connecting it to the back.
Peter: Then shorten it ... Oh, there is "111". Then it is "P" at first. Then, the rest is "11", but since this does not fit exactly, you can borrow one character from the next "00011" and make it "110".
Hiroshi: That's right. In other words, it's "E".
Peter: That's what remains of "0011", so I borrowed this from the next and changed it to "00111" and said "T" ... I've done it all. You should throw away the last "0000", right?
<image>
Hiroshi: That's right. Next is this.
? D-C'?-C'-LMGZN? FNJKN- WEYN? P'QMRWLPZLKKTPOVRGDI
Hiroshi: Furthermore, this is it.
? P'QNPY? IXX? IXXK.BI -G? R'RPP'RPOVWDMW? SWUVG'-LCMGQ
Hiroshi: Let's finish it.
? P'QMDUEQ GADKOQ? SWUVG'-LCMG? X? IGX, PUL.? UL.VNQQI
Peter: It's a hassle. Doctor, please make your own program this time.
So, instead of the doctor, create a program that replaces the above sentence.
Input
Given multiple datasets. For each dataset, one string (a string of 200 characters or less consisting of the characters contained in the table) is given on one line. Please process until the end of the input. The number of datasets does not exceed 200.
Output
For each data set, output the converted character string on one line.
Example
Input
?D-C'KOPUA
Output
PETER POTTER
Submitted Solution:
```
encode = ["00000", "00001", "00010", "00011", "00100", "00101", "00110", "00111",
"01000", "01001", "01010", "01011", "01100", "01101", "01110", "01111",
"10000", "10001", "10010", "10011", "10100", "10101", "10110", "10111",
"11000", "11001", "11010", "11011", "11100", "11101", "11110", "11111"]
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"
alphabet = list(alphabet)
decode = ["101", "000000", "000011", "10010001", "010001", "000001", "100101", "10011010",
"0101", "0001", "110", "01001", "10011011", "010000", "0111", "10011000",
"0110", "00100", "10011001", "10011110", "00101", "111", "10011111", "1000",
"00110", "00111", "10011100", "10011101", "000010", "10010010", "10010011", "10010000"]
alphabet2 = " ',-.?ABCDEFGHIJKLMNOPQRSTUVWXYZ"
alphabet2 = list(alphabet2)
while 1:
try:
sentence = list(input())
except EOFError:
break
list1 = []
for sen in sentence:
list1.append(encode[alphabet.index(sen)])
sentence1 = ''.join(l for l in list1)
sentence1 = list(sentence1)
tmp = ""
list2 = []
while sentence1 != []:
tmp += sentence1.pop(0)
if tmp in decode:
num = decode.index(tmp)
list2.append(alphabet2[num])
tmp = ""
print(''.join(l for l in list2))
``` | instruction | 0 | 100,250 | 18 | 200,500 |
Yes | output | 1 | 100,250 | 18 | 200,501 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Hiroshi:? D-C'KOPUA
Peter: What's wrong, Dr. David? I'm used to shouting something I don't understand, but I'm not even writing it today.
Hiroshi: Here.
<image>
Peter: What? This table ... oh, there was something like this in the qualifying question. Replacing characters using a table reduces the number of characters. I don't think I'm willing to give the same problem in the qualifying and the final and cut corners.
Hiroshi: It's the other way around.
Peter: Reverse? I see, is it a problem to get the shortened string back? That means that you can replace the letters "? D-C'KOPUA" from "letter" to "sign" using this table ...
11111 00011 11101 00010 11110 01010 01110 01111 10100 00000
Hiroshi: Umm. Next is this.
<image>
Peter: Yeah, there was also a table like this. Since this is used in reverse, you can replace "sign" with "character". But at first it is "11111", but it's not in the table, right?
Hiroshi: In that case, try making it shorter or connecting it to the back.
Peter: Then shorten it ... Oh, there is "111". Then it is "P" at first. Then, the rest is "11", but since this does not fit exactly, you can borrow one character from the next "00011" and make it "110".
Hiroshi: That's right. In other words, it's "E".
Peter: That's what remains of "0011", so I borrowed this from the next and changed it to "00111" and said "T" ... I've done it all. You should throw away the last "0000", right?
<image>
Hiroshi: That's right. Next is this.
? D-C'?-C'-LMGZN? FNJKN- WEYN? P'QMRWLPZLKKTPOVRGDI
Hiroshi: Furthermore, this is it.
? P'QNPY? IXX? IXXK.BI -G? R'RPP'RPOVWDMW? SWUVG'-LCMGQ
Hiroshi: Let's finish it.
? P'QMDUEQ GADKOQ? SWUVG'-LCMG? X? IGX, PUL.? UL.VNQQI
Peter: It's a hassle. Doctor, please make your own program this time.
So, instead of the doctor, create a program that replaces the above sentence.
Input
Given multiple datasets. For each dataset, one string (a string of 200 characters or less consisting of the characters contained in the table) is given on one line. Please process until the end of the input. The number of datasets does not exceed 200.
Output
For each data set, output the converted character string on one line.
Example
Input
?D-C'KOPUA
Output
PETER POTTER
Submitted Solution:
```
# -*- coding: utf-8 -*-
import sys
import os
import math
import re
tableA = {
"A":"00000",
"B":"00001",
"C":"00010",
"D":"00011",
"E":"00100",
"F":"00101",
"G":"00110",
"H":"00111",
"I":"01000",
"J":"01001",
"K":"01010",
"L":"01011",
"M":"01100",
"N":"01101",
"O":"01110",
"P":"01111",
"Q":"10000",
"R":"10001",
"S":"10010",
"T":"10011",
"U":"10100",
"V":"10101",
"W":"10110",
"X":"10111",
"Y":"11000",
"Z":"11001",
" ":"11010",
".":"11011",
",":"11100",
"-":"11101",
"'":"11110",
"?":"11111"}
tableB = {
"101":" ",
"000000":"'",
"000011":",",
"10010001":"-",
"010001":".",
"000001":"?",
"100101":"A",
"10011010":"B",
"0101":"C",
"0001":"D",
"110":"E",
"01001":"F",
"10011011":"G",
"010000":"H",
"0111":"I",
"10011000":"J",
"0110":"K",
"00100":"L",
"10011001":"M",
"10011110":"N",
"00101":"O",
"111":"P",
"10011111":"Q",
"1000":"R",
"00110":"S",
"00111":"T",
"10011100":"U",
"10011101":"V",
"000010":"W",
"10010010":"X",
"10010011":"Y",
"10010000":"Z"}
for s in sys.stdin:
s = s.strip()
s = "".join(map(lambda c: tableA[c], s))
tmp, ans = '', ''
for c in s:
tmp += c
if tmp in tableB:
ans += tableB[tmp]
tmp = ''
print(ans)
``` | instruction | 0 | 100,251 | 18 | 200,502 |
No | output | 1 | 100,251 | 18 | 200,503 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Hiroshi:? D-C'KOPUA
Peter: What's wrong, Dr. David? I'm used to shouting something I don't understand, but I'm not even writing it today.
Hiroshi: Here.
<image>
Peter: What? This table ... oh, there was something like this in the qualifying question. Replacing characters using a table reduces the number of characters. I don't think I'm willing to give the same problem in the qualifying and the final and cut corners.
Hiroshi: It's the other way around.
Peter: Reverse? I see, is it a problem to get the shortened string back? That means that you can replace the letters "? D-C'KOPUA" from "letter" to "sign" using this table ...
11111 00011 11101 00010 11110 01010 01110 01111 10100 00000
Hiroshi: Umm. Next is this.
<image>
Peter: Yeah, there was also a table like this. Since this is used in reverse, you can replace "sign" with "character". But at first it is "11111", but it's not in the table, right?
Hiroshi: In that case, try making it shorter or connecting it to the back.
Peter: Then shorten it ... Oh, there is "111". Then it is "P" at first. Then, the rest is "11", but since this does not fit exactly, you can borrow one character from the next "00011" and make it "110".
Hiroshi: That's right. In other words, it's "E".
Peter: That's what remains of "0011", so I borrowed this from the next and changed it to "00111" and said "T" ... I've done it all. You should throw away the last "0000", right?
<image>
Hiroshi: That's right. Next is this.
? D-C'?-C'-LMGZN? FNJKN- WEYN? P'QMRWLPZLKKTPOVRGDI
Hiroshi: Furthermore, this is it.
? P'QNPY? IXX? IXXK.BI -G? R'RPP'RPOVWDMW? SWUVG'-LCMGQ
Hiroshi: Let's finish it.
? P'QMDUEQ GADKOQ? SWUVG'-LCMG? X? IGX, PUL.? UL.VNQQI
Peter: It's a hassle. Doctor, please make your own program this time.
So, instead of the doctor, create a program that replaces the above sentence.
Input
Given multiple datasets. For each dataset, one string (a string of 200 characters or less consisting of the characters contained in the table) is given on one line. Please process until the end of the input. The number of datasets does not exceed 200.
Output
For each data set, output the converted character string on one line.
Example
Input
?D-C'KOPUA
Output
PETER POTTER
Submitted Solution:
```
import string
s = {i : "{:05b}".format(c) for i, c in zip(string.ascii_uppercase+" .,-'?", range(32))}
code = {'101': ' ', '000000': "'", '000011': ',', '10010001': '-',
'010001': '.', '000001': '?', '100101': 'A', '10011010': 'B',
'0101': 'C', '0001': 'D', '110': 'E', '01001': 'F', '10011011': 'G',
'010000': 'H', '0111': 'I', '10011000': 'J', '0110': 'K', '00100': 'L',
'10011001': 'M', '10011110': 'N', '00101': 'O', '111': 'P', '10011111': 'Q',
'1000': 'R', '00110': 'S', '00111': 'T', '10011100': 'U', '10011101': 'V',
'000010': 'W', '10010010': 'X', '10010011': 'Y', '10010000': 'Z'}
while True:
try:
data = input()
except:
break
d = ''.join(s[c] for c in data)
ans = ""
a, i = 0, 3
while a+i != len(d):
i = 3
while True:
if code.get(d[a:a+i], None) is not None:
ans += code[d[a:a+i]]
a += i
break
i += 1
print(ans)
``` | instruction | 0 | 100,252 | 18 | 200,504 |
No | output | 1 | 100,252 | 18 | 200,505 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Hiroshi:? D-C'KOPUA
Peter: What's wrong, Dr. David? I'm used to shouting something I don't understand, but I'm not even writing it today.
Hiroshi: Here.
<image>
Peter: What? This table ... oh, there was something like this in the qualifying question. Replacing characters using a table reduces the number of characters. I don't think I'm willing to give the same problem in the qualifying and the final and cut corners.
Hiroshi: It's the other way around.
Peter: Reverse? I see, is it a problem to get the shortened string back? That means that you can replace the letters "? D-C'KOPUA" from "letter" to "sign" using this table ...
11111 00011 11101 00010 11110 01010 01110 01111 10100 00000
Hiroshi: Umm. Next is this.
<image>
Peter: Yeah, there was also a table like this. Since this is used in reverse, you can replace "sign" with "character". But at first it is "11111", but it's not in the table, right?
Hiroshi: In that case, try making it shorter or connecting it to the back.
Peter: Then shorten it ... Oh, there is "111". Then it is "P" at first. Then, the rest is "11", but since this does not fit exactly, you can borrow one character from the next "00011" and make it "110".
Hiroshi: That's right. In other words, it's "E".
Peter: That's what remains of "0011", so I borrowed this from the next and changed it to "00111" and said "T" ... I've done it all. You should throw away the last "0000", right?
<image>
Hiroshi: That's right. Next is this.
? D-C'?-C'-LMGZN? FNJKN- WEYN? P'QMRWLPZLKKTPOVRGDI
Hiroshi: Furthermore, this is it.
? P'QNPY? IXX? IXXK.BI -G? R'RPP'RPOVWDMW? SWUVG'-LCMGQ
Hiroshi: Let's finish it.
? P'QMDUEQ GADKOQ? SWUVG'-LCMG? X? IGX, PUL.? UL.VNQQI
Peter: It's a hassle. Doctor, please make your own program this time.
So, instead of the doctor, create a program that replaces the above sentence.
Input
Given multiple datasets. For each dataset, one string (a string of 200 characters or less consisting of the characters contained in the table) is given on one line. Please process until the end of the input. The number of datasets does not exceed 200.
Output
For each data set, output the converted character string on one line.
Example
Input
?D-C'KOPUA
Output
PETER POTTER
Submitted Solution:
```
import sys
def cv1(c):
o=ord(c)
if 65<=o<=90:
return format(o-65,"05b")
elif o==32:
return "11010"
elif o==46:
return "11011"
elif o==44:
return "11100"
elif o==45:
return "11101"
elif o==39:
return "11110"
elif o==63:
return "11111"
d={"101":" ",
"000000":"'",
"000011":",",
"10010001":"-",
"010001":".",
"000001":"?",
"100101":"A",
"10011010":"B",
"0101":"C",
"0001":"D",
"110":"E",
"01001":"F",
"10011011":"G",
"010000":"H",
"0111":"I",
"10011000":"J",
"0110":"K",
"00100":"L",
"10011001":"M",
"10011110":"N",
"00101":"O",
"111":"P",
"10011111":"Q",
"1000":"R",
"00110":"S",
"00111":"T",
"10011100":"U",
"10011101":"V",
"000010":"W",
"10010010":"X",
"10010011":"Y",
"10010000":"Z"
}
sk=sorted(d.keys(),key=lambda x:len(x))
for t in sys.stdin:
t=t.strip("\n")
cn=0
st=[]
ta="".join([cv1(i) for i in t])
#print(ta)
while 1:
for (j,i) in enumerate(sk):
if ta[cn:cn+len(i)]==i:
st.extend([d[i]])
cn+=len(i)
break
if j==31:break
print("".join(st))
``` | instruction | 0 | 100,253 | 18 | 200,506 |
No | output | 1 | 100,253 | 18 | 200,507 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Hiroshi:? D-C'KOPUA
Peter: What's wrong, Dr. David? I'm used to shouting something I don't understand, but I'm not even writing it today.
Hiroshi: Here.
<image>
Peter: What? This table ... oh, there was something like this in the qualifying question. Replacing characters using a table reduces the number of characters. I don't think I'm willing to give the same problem in the qualifying and the final and cut corners.
Hiroshi: It's the other way around.
Peter: Reverse? I see, is it a problem to get the shortened string back? That means that you can replace the letters "? D-C'KOPUA" from "letter" to "sign" using this table ...
11111 00011 11101 00010 11110 01010 01110 01111 10100 00000
Hiroshi: Umm. Next is this.
<image>
Peter: Yeah, there was also a table like this. Since this is used in reverse, you can replace "sign" with "character". But at first it is "11111", but it's not in the table, right?
Hiroshi: In that case, try making it shorter or connecting it to the back.
Peter: Then shorten it ... Oh, there is "111". Then it is "P" at first. Then, the rest is "11", but since this does not fit exactly, you can borrow one character from the next "00011" and make it "110".
Hiroshi: That's right. In other words, it's "E".
Peter: That's what remains of "0011", so I borrowed this from the next and changed it to "00111" and said "T" ... I've done it all. You should throw away the last "0000", right?
<image>
Hiroshi: That's right. Next is this.
? D-C'?-C'-LMGZN? FNJKN- WEYN? P'QMRWLPZLKKTPOVRGDI
Hiroshi: Furthermore, this is it.
? P'QNPY? IXX? IXXK.BI -G? R'RPP'RPOVWDMW? SWUVG'-LCMGQ
Hiroshi: Let's finish it.
? P'QMDUEQ GADKOQ? SWUVG'-LCMG? X? IGX, PUL.? UL.VNQQI
Peter: It's a hassle. Doctor, please make your own program this time.
So, instead of the doctor, create a program that replaces the above sentence.
Input
Given multiple datasets. For each dataset, one string (a string of 200 characters or less consisting of the characters contained in the table) is given on one line. Please process until the end of the input. The number of datasets does not exceed 200.
Output
For each data set, output the converted character string on one line.
Example
Input
?D-C'KOPUA
Output
PETER POTTER
Submitted Solution:
```
# -*- coding: utf-8 -*-
import sys
import os
import math
import re
tableA = {
"A":"00000",
"B":"00001",
"C":"00010",
"D":"00011",
"E":"00100",
"F":"00101",
"G":"00110",
"H":"00111",
"I":"01000",
"J":"01001",
"K":"01010",
"L":"01011",
"M":"01100",
"N":"01101",
"O":"01110",
"P":"01111",
"Q":"10000",
"R":"10001",
"S":"10010",
"T":"10011",
"U":"10100",
"V":"10101",
"W":"10110",
"X":"10111",
"Y":"11000",
"Z":"11001",
" ":"11010",
".":"11011",
",":"11100",
"-":"11101",
"'":"11110",
"?":"11111"}
tableB = {
"101":" ",
"000000":"'",
"000011":",",
"10010001":"-",
"010001":".",
"000001":"?",
"100101":"A",
"10011010":"B",
"0101":"C",
"0001":"D",
"110":"E",
"01001":"F",
"10011011":"G",
"010000":"H",
"0111":"I",
"10011000":"J",
"0110":"K",
"00100":"L",
"10011001":"M",
"10011110":"N",
"00101":"O",
"111":"P",
"10011111":"Q",
"1000":"R",
"00110":"S",
"00111":"T",
"10011100":"U",
"10011101":"V",
"000010":"W",
"10010010":"X",
"10010011":"Y",
"10010000":"Z"}
for s in sys.stdin:
s = s.strip()
lst = []
for c in s:
lst.append(tableA[c])
s = ''.join(lst)
s = s.zfill(5)
#print('encoded', s)
tmp, ans = '', ''
for c in s:
tmp += c
if tmp in tableB:
ans += tableB[tmp]
tmp = ''
print(ans)
``` | instruction | 0 | 100,254 | 18 | 200,508 |
No | output | 1 | 100,254 | 18 | 200,509 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them.
In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2 × 2 square, such that from the four letters of this square you can make word "face".
You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap.
Input
The first line contains two space-separated integers, n and m (1 ≤ n, m ≤ 50) — the height and the width of the image, respectively.
Next n lines define the image. Each line contains m lowercase Latin letters.
Output
In the single line print the number of faces on the image.
Examples
Input
4 4
xxxx
xfax
xcex
xxxx
Output
1
Input
4 2
xx
cf
ae
xx
Output
1
Input
2 3
fac
cef
Output
2
Input
1 4
face
Output
0
Note
In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column:
<image>
In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column.
In the third sample two faces are shown:
<image>
In the fourth sample the image has no faces on it.
Submitted Solution:
```
n, m = [int(x) for x in input().split()]
a = []
for i in range(n):
a.append(input())
#print(a)
res = 0
z = ["face", "faec", "feac", "feca", "fcae", "fcea", "eafc", "eacf", "ecaf", "ecfa", "efac", "efca", "acfe", "acef", "aecf", "aefc", "afce", "afec", "cafe", "caef", "ceaf", "cefa", "cfea", "cfae"]
for i in range(1, n):
for j in range(1, m):
if a[i][j]+a[i][j-1]+a[i-1][j]+a[i-1][j-1] in z:
res += 1
print(res)
``` | instruction | 0 | 100,728 | 18 | 201,456 |
Yes | output | 1 | 100,728 | 18 | 201,457 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan wants to write a letter to his friend. The letter is a string s consisting of lowercase Latin letters.
Unfortunately, when Ivan started writing the letter, he realised that it is very long and writing the whole letter may take extremely long time. So he wants to write the compressed version of string s instead of the string itself.
The compressed version of string s is a sequence of strings c1, s1, c2, s2, ..., ck, sk, where ci is the decimal representation of number ai (without any leading zeroes) and si is some string consisting of lowercase Latin letters. If Ivan writes string s1 exactly a1 times, then string s2 exactly a2 times, and so on, the result will be string s.
The length of a compressed version is |c1| + |s1| + |c2| + |s2|... |ck| + |sk|. Among all compressed versions Ivan wants to choose a version such that its length is minimum possible. Help Ivan to determine minimum possible length.
Input
The only line of input contains one string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 8000).
Output
Output one integer number — the minimum possible length of a compressed version of s.
Examples
Input
aaaaaaaaaa
Output
3
Input
abcab
Output
6
Input
cczabababab
Output
7
Note
In the first example Ivan will choose this compressed version: c1 is 10, s1 is a.
In the second example Ivan will choose this compressed version: c1 is 1, s1 is abcab.
In the third example Ivan will choose this compressed version: c1 is 2, s1 is c, c2 is 1, s2 is z, c3 is 4, s3 is ab.
Submitted Solution:
```
# D
# s = input()
# t = input()
#
# count_q = s.count('?')
# set_t = set(t)
#
# c_s = {i: s.count(i) for i in set_t}
# c_s['?'] = s.count('?')
#
# c_t = {i: t.count(i) for i in set_t}
#
# max_n = sum(c_s.values()) // sum(c_t.values())
# for i in set_t:
# c_s[i] -= (c_t[i] * max_n)
#
# while True:
# ss = c_s['?']
# for i in c_s.values():
# if i < 0:
# ss += i
#
# if ss >= 0:
# break
# elif ss < 0:
# for i in set_t:
# c_s[i] += c_t[i]
#
# for i in set_t:
# if c_s[i] < 0:
# s = s.replace('?', i, -c_s[i])
# s = s.replace('?', 'a')
#
# print(s)
# n, m = map(int, input().split())
# n, m = 3, 3
# a = ['1 2',
# '1 3',
# '3 2']
# N = [set() for _ in range(n+1)]
#
# for i in range(m):
# # v, u = map(int, input().split())
# v, u = map(int, a[i].split())
# N[v].add(u)
#
# print(N)
strs = input()
res = []
while len(strs) > 0:
n = 1
# print('s ', strs)
for i in range(1, len(strs) // 2 + 1):
# print(strs[i:], strs[:i], i)
p = strs[:i]
if strs[i:].startswith(p):
while strs[i:].startswith(p):
i += len(p)
n += 1
strs = strs[i:]
# print(res)
res.append((n, p))
break
else:
if len(res) > 0 and res[-1][0] == 1:
pp = res.pop()
res.append((1, pp[1] + strs[0]))
else:
res.append((1, strs[0]))
strs = strs[1:]
size_res = 0
for i in res:
size_res += len(str(i[0]))
size_res += len(i[1])
# print(res)
print(size_res)
``` | instruction | 0 | 100,850 | 18 | 201,700 |
No | output | 1 | 100,850 | 18 | 201,701 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan wants to write a letter to his friend. The letter is a string s consisting of lowercase Latin letters.
Unfortunately, when Ivan started writing the letter, he realised that it is very long and writing the whole letter may take extremely long time. So he wants to write the compressed version of string s instead of the string itself.
The compressed version of string s is a sequence of strings c1, s1, c2, s2, ..., ck, sk, where ci is the decimal representation of number ai (without any leading zeroes) and si is some string consisting of lowercase Latin letters. If Ivan writes string s1 exactly a1 times, then string s2 exactly a2 times, and so on, the result will be string s.
The length of a compressed version is |c1| + |s1| + |c2| + |s2|... |ck| + |sk|. Among all compressed versions Ivan wants to choose a version such that its length is minimum possible. Help Ivan to determine minimum possible length.
Input
The only line of input contains one string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 8000).
Output
Output one integer number — the minimum possible length of a compressed version of s.
Examples
Input
aaaaaaaaaa
Output
3
Input
abcab
Output
6
Input
cczabababab
Output
7
Note
In the first example Ivan will choose this compressed version: c1 is 10, s1 is a.
In the second example Ivan will choose this compressed version: c1 is 1, s1 is abcab.
In the third example Ivan will choose this compressed version: c1 is 2, s1 is c, c2 is 1, s2 is z, c3 is 4, s3 is ab.
Submitted Solution:
```
from sys import stdin, stdout
EPS = 10 ** (-20)
INF = float('inf')
sze = 26
s = stdin.readline().strip()
dp = [INF for i in range(len(s) + 10)]
dp[0] = 2
dp.append(0)
for i in range(1, len(s)):
dp[i] = i + 2
for z in range(i):
q = s[z: i + 1]
dividers = []
for j in range(1, int((i - z + 1) ** 0.5) + 1):
if not (i - z + 1) % j:
dividers.append(j)
if i - z + 1 == int((i - z + 1) ** 0.5):
dividers = list(set(dividers))
for v in dividers:
label = 1
ind = 0
while ind < len(q):
if q[ind: ind + v] != q[:v]:
label = 0
ind += v
if label:
dp[i] = min(dp[i], dp[z - 1] + len(str(len(q) // v)) + v)
stdout.write(str(dp[len(s) - 1]))
``` | instruction | 0 | 100,851 | 18 | 201,702 |
No | output | 1 | 100,851 | 18 | 201,703 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Ivan wants to write a letter to his friend. The letter is a string s consisting of lowercase Latin letters.
Unfortunately, when Ivan started writing the letter, he realised that it is very long and writing the whole letter may take extremely long time. So he wants to write the compressed version of string s instead of the string itself.
The compressed version of string s is a sequence of strings c1, s1, c2, s2, ..., ck, sk, where ci is the decimal representation of number ai (without any leading zeroes) and si is some string consisting of lowercase Latin letters. If Ivan writes string s1 exactly a1 times, then string s2 exactly a2 times, and so on, the result will be string s.
The length of a compressed version is |c1| + |s1| + |c2| + |s2|... |ck| + |sk|. Among all compressed versions Ivan wants to choose a version such that its length is minimum possible. Help Ivan to determine minimum possible length.
Input
The only line of input contains one string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 8000).
Output
Output one integer number — the minimum possible length of a compressed version of s.
Examples
Input
aaaaaaaaaa
Output
3
Input
abcab
Output
6
Input
cczabababab
Output
7
Note
In the first example Ivan will choose this compressed version: c1 is 10, s1 is a.
In the second example Ivan will choose this compressed version: c1 is 1, s1 is abcab.
In the third example Ivan will choose this compressed version: c1 is 2, s1 is c, c2 is 1, s2 is z, c3 is 4, s3 is ab.
Submitted Solution:
```
# D
# s = input()
# t = input()
#
# count_q = s.count('?')
# set_t = set(t)
#
# c_s = {i: s.count(i) for i in set_t}
# c_s['?'] = s.count('?')
#
# c_t = {i: t.count(i) for i in set_t}
#
# max_n = sum(c_s.values()) // sum(c_t.values())
# for i in set_t:
# c_s[i] -= (c_t[i] * max_n)
#
# while True:
# ss = c_s['?']
# for i in c_s.values():
# if i < 0:
# ss += i
#
# if ss >= 0:
# break
# elif ss < 0:
# for i in set_t:
# c_s[i] += c_t[i]
#
# for i in set_t:
# if c_s[i] < 0:
# s = s.replace('?', i, -c_s[i])
# s = s.replace('?', 'a')
#
# print(s)
# n, m = map(int, input().split())
# n, m = 3, 3
# a = ['1 2',
# '1 3',
# '3 2']
# N = [set() for _ in range(n+1)]
#
# for i in range(m):
# # v, u = map(int, input().split())
# v, u = map(int, a[i].split())
# N[v].add(u)
#
# print(N)
strs = input()
res = []
while len(strs) > 0:
temp = []
# print('s ', strs)
for i in range(len(strs) // 2 + 1, 0, - 1):
n = 1
# print(strs[i:], strs[:i], i)
p = strs[:i]
if strs[i:].startswith(p):
while strs[i:].startswith(p):
i += len(p)
n += 1
temp.append((n, p))
# print(temp)
if len(temp) > 0:
m = max(temp, key=lambda x: (x[0] * len(x[1])) - (len(str(x[0]) + x[1])))
off = m[0] * len(m[1])
res.append(m)
strs = strs[off:]
else:
if len(res) > 0 and res[-1][0] == 1:
pp = res.pop()
res.append((1, pp[1] + strs[0]))
else:
res.append((1, strs[0]))
strs = strs[1:]
size_res = 0
for i in res:
size_res += len(str(i[0]))
size_res += len(i[1])
print(size_res)
``` | instruction | 0 | 100,852 | 18 | 201,704 |
No | output | 1 | 100,852 | 18 | 201,705 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Are you going to Scarborough Fair?
Parsley, sage, rosemary and thyme.
Remember me to one who lives there.
He once was the true love of mine.
Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.
Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.
Although the girl wants to help, Willem insists on doing it by himself.
Grick gave Willem a string of length n.
Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.
Grick wants to know the final string after all the m operations.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 100).
The second line contains a string s of length n, consisting of lowercase English letters.
Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
Output
Output string s after performing m operations described above.
Examples
Input
3 1
ioi
1 1 i n
Output
noi
Input
5 3
wxhak
3 3 h x
1 5 x a
1 3 w g
Output
gaaak
Note
For the second example:
After the first operation, the string is wxxak.
After the second operation, the string is waaak.
After the third operation, the string is gaaak.
Submitted Solution:
```
n, m = map(int, input().split())
s = input()
for i in range(m):
l,r,c1,c2 = map(str,input().split())
l = int(l)
r = int(r)
l -=1
r -=1
j = l
while j <= r:
if s[j] == c1:
s = s[:j] + c2 + s[j+1:]
j += 1
print(s)
``` | instruction | 0 | 100,878 | 18 | 201,756 |
Yes | output | 1 | 100,878 | 18 | 201,757 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Are you going to Scarborough Fair?
Parsley, sage, rosemary and thyme.
Remember me to one who lives there.
He once was the true love of mine.
Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.
Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.
Although the girl wants to help, Willem insists on doing it by himself.
Grick gave Willem a string of length n.
Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.
Grick wants to know the final string after all the m operations.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 100).
The second line contains a string s of length n, consisting of lowercase English letters.
Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
Output
Output string s after performing m operations described above.
Examples
Input
3 1
ioi
1 1 i n
Output
noi
Input
5 3
wxhak
3 3 h x
1 5 x a
1 3 w g
Output
gaaak
Note
For the second example:
After the first operation, the string is wxxak.
After the second operation, the string is waaak.
After the third operation, the string is gaaak.
Submitted Solution:
```
n,m=map(int,input().split())
s=list(input())
for i in range(m):
x=input()
r,c=map(int,x[:-4].split())
for j in range(r-1,c):
if s[j]==x[-3]:
s[j]=x[-1]
print(''.join(s))
``` | instruction | 0 | 100,879 | 18 | 201,758 |
Yes | output | 1 | 100,879 | 18 | 201,759 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Are you going to Scarborough Fair?
Parsley, sage, rosemary and thyme.
Remember me to one who lives there.
He once was the true love of mine.
Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.
Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.
Although the girl wants to help, Willem insists on doing it by himself.
Grick gave Willem a string of length n.
Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.
Grick wants to know the final string after all the m operations.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 100).
The second line contains a string s of length n, consisting of lowercase English letters.
Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
Output
Output string s after performing m operations described above.
Examples
Input
3 1
ioi
1 1 i n
Output
noi
Input
5 3
wxhak
3 3 h x
1 5 x a
1 3 w g
Output
gaaak
Note
For the second example:
After the first operation, the string is wxxak.
After the second operation, the string is waaak.
After the third operation, the string is gaaak.
Submitted Solution:
```
n,m=[int(i) for i in input().split()]
s=list(input())
#print(s)
for i in range(m):
l,r,c1,c2=[i for i in input().split()]
l=int(l)
r=int(r)
for i in range(l-1,r):
if s[i]==c1: s[i]=c2
print(''.join(s))
``` | instruction | 0 | 100,880 | 18 | 201,760 |
Yes | output | 1 | 100,880 | 18 | 201,761 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Are you going to Scarborough Fair?
Parsley, sage, rosemary and thyme.
Remember me to one who lives there.
He once was the true love of mine.
Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.
Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.
Although the girl wants to help, Willem insists on doing it by himself.
Grick gave Willem a string of length n.
Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.
Grick wants to know the final string after all the m operations.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 100).
The second line contains a string s of length n, consisting of lowercase English letters.
Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
Output
Output string s after performing m operations described above.
Examples
Input
3 1
ioi
1 1 i n
Output
noi
Input
5 3
wxhak
3 3 h x
1 5 x a
1 3 w g
Output
gaaak
Note
For the second example:
After the first operation, the string is wxxak.
After the second operation, the string is waaak.
After the third operation, the string is gaaak.
Submitted Solution:
```
a=list(map(int,input().split()))
n=a[0]
m=a[1]
s=input()
for t in range(0,m):
l,r,c1,c2=input().split()
l=int(l)
r=int(r)
print("s[l-1:r] ",s[l-1:r])
s=s[0:l-1]+s[l-1:r].replace(c1,c2)+s[r:]
print(s)
``` | instruction | 0 | 100,883 | 18 | 201,766 |
No | output | 1 | 100,883 | 18 | 201,767 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Are you going to Scarborough Fair?
Parsley, sage, rosemary and thyme.
Remember me to one who lives there.
He once was the true love of mine.
Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.
Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.
Although the girl wants to help, Willem insists on doing it by himself.
Grick gave Willem a string of length n.
Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.
Grick wants to know the final string after all the m operations.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 100).
The second line contains a string s of length n, consisting of lowercase English letters.
Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
Output
Output string s after performing m operations described above.
Examples
Input
3 1
ioi
1 1 i n
Output
noi
Input
5 3
wxhak
3 3 h x
1 5 x a
1 3 w g
Output
gaaak
Note
For the second example:
After the first operation, the string is wxxak.
After the second operation, the string is waaak.
After the third operation, the string is gaaak.
Submitted Solution:
```
n,m = map(int,input().split())
k = list(input())
for i in range(m):
l = input().split()
for j in range(int(l[0])-1,int(l[1])):
if k[j]==l[2]:
k[j]=l[3]
print(*k)
``` | instruction | 0 | 100,884 | 18 | 201,768 |
No | output | 1 | 100,884 | 18 | 201,769 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Are you going to Scarborough Fair?
Parsley, sage, rosemary and thyme.
Remember me to one who lives there.
He once was the true love of mine.
Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.
Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.
Although the girl wants to help, Willem insists on doing it by himself.
Grick gave Willem a string of length n.
Willem needs to do m operations, each operation has four parameters l, r, c1, c2, which means that all symbols c1 in range [l, r] (from l-th to r-th, including l and r) are changed into c2. String is 1-indexed.
Grick wants to know the final string after all the m operations.
Input
The first line contains two integers n and m (1 ≤ n, m ≤ 100).
The second line contains a string s of length n, consisting of lowercase English letters.
Each of the next m lines contains four parameters l, r, c1, c2 (1 ≤ l ≤ r ≤ n, c1, c2 are lowercase English letters), separated by space.
Output
Output string s after performing m operations described above.
Examples
Input
3 1
ioi
1 1 i n
Output
noi
Input
5 3
wxhak
3 3 h x
1 5 x a
1 3 w g
Output
gaaak
Note
For the second example:
After the first operation, the string is wxxak.
After the second operation, the string is waaak.
After the third operation, the string is gaaak.
Submitted Solution:
```
n,k=list(map(int,input().split()))
s=input()
p=''
for i in range(k):
l,r,c1,c2=input().split()
for j in range(len(s)):
if j in range(int(l)-1,int(r)):
if s[j]==c1:
p+=c2
else:
p+=s[j]
print(p)
``` | instruction | 0 | 100,885 | 18 | 201,770 |
No | output | 1 | 100,885 | 18 | 201,771 |
Provide a correct Python 3 solution for this coding contest problem.
D: Shiritori Compression
problem
Ebi-chan and Kana-chan did a shiritori. Ebi-chan is looking at the memo of the word that came out in Shiritori.
Ebi-chan wants to remove redundant continuous subsequences from this word sequence w_1, w_2, ..., w_N until they no longer exist. The redundant continuous subsequence that Ebi-chan thinks is defined as follows.
* The continuous subsequence w_i, ..., w_ {j-1} is redundant when i, j satisfying the following is present.
* For the subscripts i, j with i <j, the first letters of the words w_i and w_j are equal.
At this time, Ebi-chan removes words with subscript i or more and j-1 or less.
For example, consider the following word string:
* apple → editor → random → me → edge
It is compressed as follows:
* apple → edge
Since the first letter of editor and edge matches with e, the words from editor to just before edge (me) are stripped.
Please note that Ebi-chan's criteria do not consider the same trailing character to be redundant. For example, in the compressed word string above, the last letter of apple and edge is both e, but this does not remove the word.
The following examples are also possible.
* orange → eel → luck
* banana → at → tomb → bus → sound → does → some
* peach → hero → owl → loop → proof → fish → he
Each of these can be compressed as follows: Note that in each case, the last word is saved.
* orange → eel → luck
* Already compressed.
* bus → some
* You can compress banana to bus and sound to some.
* peach → he
* You can also compress proof → fish → he, but note that the number of words after compression is different.
Ebi-chan's memos are given, so please output the minimum value L of the length (number of words) of the word string obtained by compressing them.
You can assume that "the same word appears multiple times" or "the first letter of a word does not match the last letter of the previous word" does not occur.
Input format
N
w_1
...
w_N
The number of words N is given on the first line, and the i-th word is given on the 1 + i line.
Constraint
* 1 \ leq N \ leq 10 ^ 5
* 1 \ leq $ \ sum_ {i = 1} ^ N $ | w_i | \ leq 10 ^ 6
* Each letter of w_i is lowercase
Output format
Print L on one line. No other extra characters should be included.
Input example 1
7
banana
at
tomb
bus
sound
does does
some
Output example 1
2
This is the example given above.
Input example 2
7
peach
hero
owl
loop
proof
fish
he
Output example 2
2
Another example given above.
Example
Input
7
banana
at
tomb
bus
sound
does
some
Output
2 | instruction | 0 | 101,159 | 18 | 202,318 |
"Correct Solution:
```
from collections import deque
N = int(input())
idxs = [deque() for i in range(26)]
def ctoi(c):
return ord(c) - ord('a')
cs = []
for i in range(N):
c = input()[0]
cs.append(c)
ci = ctoi(c)
idxs[ci].append(i)
dp = [i for i in range(N)]
dp[0] = 0
for i in range(N):
c = cs[i]
ci = ctoi(c)
if i > 0:
dp[i] = min(dp[i],dp[i-1]+1)
if len(idxs[ci]) < 2: continue
idxs[ci].popleft()
pi = idxs[ci][0]
dp[pi] = dp[i]
#print(dp)
print(dp[-1] + 1)
``` | output | 1 | 101,159 | 18 | 202,319 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya once wrote a sad love song and shared it to Vasya. The song is a string consisting of lowercase English letters. Vasya made up q questions about this song. Each question is about a subsegment of the song starting from the l-th letter to the r-th letter. Vasya considers a substring made up from characters on this segment and repeats each letter in the subsegment k times, where k is the index of the corresponding letter in the alphabet. For example, if the question is about the substring "abbcb", then Vasya repeats letter 'a' once, each of the letters 'b' twice, letter 'c" three times, so that the resulting string is "abbbbcccbb", its length is 10. Vasya is interested about the length of the resulting string.
Help Petya find the length of each string obtained by Vasya.
Input
The first line contains two integers n and q (1≤ n≤ 100 000, 1≤ q ≤ 100 000) — the length of the song and the number of questions.
The second line contains one string s — the song, consisting of n lowercase letters of English letters.
Vasya's questions are contained in the next q lines. Each line contains two integers l and r (1 ≤ l ≤ r ≤ n) — the bounds of the question.
Output
Print q lines: for each question print the length of the string obtained by Vasya.
Examples
Input
7 3
abacaba
1 3
2 5
1 7
Output
4
7
11
Input
7 4
abbabaa
1 3
5 7
6 6
2 4
Output
5
4
1
5
Input
13 7
sonoshikumiwo
1 5
2 10
7 7
1 13
4 8
2 5
3 9
Output
82
125
9
191
62
63
97
Note
In the first example Vasya is interested in three questions. In the first question Vasya considers the substring "aba", that transforms to "abba", so the answer is equal to 4. In the second question Vasya considers "baca", that transforms to "bbaccca", so the answer is 7. In the third question Vasya considers the string "abacaba",that transforms to "abbacccabba" of length 11.
Submitted Solution:
```
n, q=map(int, input().split())
s=input()
alp={'a':1, 'b':2, 'c':3, 'd':4, 'e':5, 'f':6, 'g':7, 'h':8, 'i':9, 'j':10, 'k':11, 'l':12, 'm':13, 'n':14, 'o':15, 'p':16, 'q':17, 'r':18, 's':19, 't':20, 'u':21, 'v':22, 'w':23, 'x':24, 'y':25, 'z':26}
li=[0]
sum=0
for i in range(n):
sum+=alp[s[i]]
li.append(sum)
for i in range(q):
x, y=map(int, input().split())
print(li[y]-li[x-1])
``` | instruction | 0 | 101,460 | 18 | 202,920 |
Yes | output | 1 | 101,460 | 18 | 202,921 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya once wrote a sad love song and shared it to Vasya. The song is a string consisting of lowercase English letters. Vasya made up q questions about this song. Each question is about a subsegment of the song starting from the l-th letter to the r-th letter. Vasya considers a substring made up from characters on this segment and repeats each letter in the subsegment k times, where k is the index of the corresponding letter in the alphabet. For example, if the question is about the substring "abbcb", then Vasya repeats letter 'a' once, each of the letters 'b' twice, letter 'c" three times, so that the resulting string is "abbbbcccbb", its length is 10. Vasya is interested about the length of the resulting string.
Help Petya find the length of each string obtained by Vasya.
Input
The first line contains two integers n and q (1≤ n≤ 100 000, 1≤ q ≤ 100 000) — the length of the song and the number of questions.
The second line contains one string s — the song, consisting of n lowercase letters of English letters.
Vasya's questions are contained in the next q lines. Each line contains two integers l and r (1 ≤ l ≤ r ≤ n) — the bounds of the question.
Output
Print q lines: for each question print the length of the string obtained by Vasya.
Examples
Input
7 3
abacaba
1 3
2 5
1 7
Output
4
7
11
Input
7 4
abbabaa
1 3
5 7
6 6
2 4
Output
5
4
1
5
Input
13 7
sonoshikumiwo
1 5
2 10
7 7
1 13
4 8
2 5
3 9
Output
82
125
9
191
62
63
97
Note
In the first example Vasya is interested in three questions. In the first question Vasya considers the substring "aba", that transforms to "abba", so the answer is equal to 4. In the second question Vasya considers "baca", that transforms to "bbaccca", so the answer is 7. In the third question Vasya considers the string "abacaba",that transforms to "abbacccabba" of length 11.
Submitted Solution:
```
letters = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w',
'x', 'y', 'z')
n, q = map(int, input().split())
s = input()
sums = [0]
for k in range(len(s)):
sums.append(sums[k]+letters.index(s[k])+1)
for i in range(q):
l, r = map(int, input().split())
print(sums[r]-sums[l-1])
``` | instruction | 0 | 101,461 | 18 | 202,922 |
Yes | output | 1 | 101,461 | 18 | 202,923 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya once wrote a sad love song and shared it to Vasya. The song is a string consisting of lowercase English letters. Vasya made up q questions about this song. Each question is about a subsegment of the song starting from the l-th letter to the r-th letter. Vasya considers a substring made up from characters on this segment and repeats each letter in the subsegment k times, where k is the index of the corresponding letter in the alphabet. For example, if the question is about the substring "abbcb", then Vasya repeats letter 'a' once, each of the letters 'b' twice, letter 'c" three times, so that the resulting string is "abbbbcccbb", its length is 10. Vasya is interested about the length of the resulting string.
Help Petya find the length of each string obtained by Vasya.
Input
The first line contains two integers n and q (1≤ n≤ 100 000, 1≤ q ≤ 100 000) — the length of the song and the number of questions.
The second line contains one string s — the song, consisting of n lowercase letters of English letters.
Vasya's questions are contained in the next q lines. Each line contains two integers l and r (1 ≤ l ≤ r ≤ n) — the bounds of the question.
Output
Print q lines: for each question print the length of the string obtained by Vasya.
Examples
Input
7 3
abacaba
1 3
2 5
1 7
Output
4
7
11
Input
7 4
abbabaa
1 3
5 7
6 6
2 4
Output
5
4
1
5
Input
13 7
sonoshikumiwo
1 5
2 10
7 7
1 13
4 8
2 5
3 9
Output
82
125
9
191
62
63
97
Note
In the first example Vasya is interested in three questions. In the first question Vasya considers the substring "aba", that transforms to "abba", so the answer is equal to 4. In the second question Vasya considers "baca", that transforms to "bbaccca", so the answer is 7. In the third question Vasya considers the string "abacaba",that transforms to "abbacccabba" of length 11.
Submitted Solution:
```
def solve(l ,r):
return miku[r] - miku[l - 1]
n, q = map(int, input().split())
s = input()
miku = [0] * (n + 1)
for i in range(1, n + 1):
miku[i] += miku[i - 1] + ord(s[i - 1]) - 96
for i in range(q):
l, r = map(int, input().split())
print(solve(l, r))
``` | instruction | 0 | 101,462 | 18 | 202,924 |
Yes | output | 1 | 101,462 | 18 | 202,925 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Petya once wrote a sad love song and shared it to Vasya. The song is a string consisting of lowercase English letters. Vasya made up q questions about this song. Each question is about a subsegment of the song starting from the l-th letter to the r-th letter. Vasya considers a substring made up from characters on this segment and repeats each letter in the subsegment k times, where k is the index of the corresponding letter in the alphabet. For example, if the question is about the substring "abbcb", then Vasya repeats letter 'a' once, each of the letters 'b' twice, letter 'c" three times, so that the resulting string is "abbbbcccbb", its length is 10. Vasya is interested about the length of the resulting string.
Help Petya find the length of each string obtained by Vasya.
Input
The first line contains two integers n and q (1≤ n≤ 100 000, 1≤ q ≤ 100 000) — the length of the song and the number of questions.
The second line contains one string s — the song, consisting of n lowercase letters of English letters.
Vasya's questions are contained in the next q lines. Each line contains two integers l and r (1 ≤ l ≤ r ≤ n) — the bounds of the question.
Output
Print q lines: for each question print the length of the string obtained by Vasya.
Examples
Input
7 3
abacaba
1 3
2 5
1 7
Output
4
7
11
Input
7 4
abbabaa
1 3
5 7
6 6
2 4
Output
5
4
1
5
Input
13 7
sonoshikumiwo
1 5
2 10
7 7
1 13
4 8
2 5
3 9
Output
82
125
9
191
62
63
97
Note
In the first example Vasya is interested in three questions. In the first question Vasya considers the substring "aba", that transforms to "abba", so the answer is equal to 4. In the second question Vasya considers "baca", that transforms to "bbaccca", so the answer is 7. In the third question Vasya considers the string "abacaba",that transforms to "abbacccabba" of length 11.
Submitted Solution:
```
from bisect import insort,bisect_right,bisect_left
from sys import stdout, stdin, setrecursionlimit
from math import sqrt,ceil,floor,factorial,gcd,log2,log10
from io import BytesIO, IOBase
from collections import *
from itertools import *
from random import *
from string import *
from queue import *
from heapq import *
from re import *
from os import *
####################################---fast-input-output----#########################################
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 = read(self._fd, max(fstat(self._fd).st_size, 8192))
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 = read(self._fd, max(fstat(self._fd).st_size, 8192))
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:
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")
stdin, stdout = IOWrapper(stdin), IOWrapper(stdout)
graph, mod, szzz = {}, 10**9 + 7, lambda: sorted(zzz())
def getStr(): return input()
def getInt(): return int(input())
def listStr(): return list(input())
def getStrs(): return input().split()
def isInt(s): return '0' <= s[0] <= '9'
def input(): return stdin.readline().strip()
def zzz(): return [int(i) for i in input().split()]
def output(answer, end='\n'): stdout.write(str(answer) + end)
def lcd(xnum1, xnum2): return (xnum1 * xnum2 // gcd(xnum1, xnum2))
def getPrimes(N = 10**5):
SN = int(sqrt(N))
sieve = [i for i in range(N+1)]
sieve[1] = 0
for i in sieve:
if i > SN:
break
if i == 0:
continue
for j in range(2*i, N+1, i):
sieve[j] = 0
prime = [i for i in range(N+1) if sieve[i] != 0]
return prime
def primeFactor(n,prime=getPrimes()):
lst = []
mx=int(sqrt(n))+1
for i in prime:
if i>mx:break
while n%i==0:
lst.append(i)
n//=i
if n>1:
lst.append(n)
return lst
dx = [-1, 1, 0, 0, 1, -1, 1, -1]
dy = [0, 0, 1, -1, 1, -1, -1, 1]
daysInMounth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
#################################################---Some Rule For Me To Follow---#################################
"""
--instants of Reading problem continuously try to understand them.
--If you Know some-one , Then you probably don't know him !
--Try & again try, maybe you're just one statement away!
"""
##################################################---START-CODING---###############################################
# num = getInt()
# for _ in range(num):
# n,x,t=zzz()
# p=(t//x)
# ans = p*(n-p) + (p*(p-1)//2)
# print(ans)
n,q=zzz()
arr = getStr()
s=[]
for i in range(n):
s.append((ord(arr[i])-96))
s=[0]+list(accumulate(s))
for _ in range(q):
l,r=zzz()
print(s[r]-s[l-1])
``` | instruction | 0 | 101,463 | 18 | 202,926 |
Yes | output | 1 | 101,463 | 18 | 202,927 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.