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.
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`.
Constraints
* |S|=3
* S consists of `a`, `b` and `c`.
Input
Input is given from Standard Input in the following format:
S
Output
If S can be obtained by permuting `abc`, print `Yes`; otherwise, print `No`.
Examples
Input
bac
Output
Yes
Input
bab
Output
No
Input
abc
Output
Yes
Input
aaa
Output
No
Submitted Solution:
```
s = input()
s = list(s)
s.sort()
if (s == "abc"):
print("Yes")
else :
print("No")
``` | instruction | 0 | 78,957 | 18 | 157,914 |
No | output | 1 | 78,957 | 18 | 157,915 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`.
Constraints
* |S|=3
* S consists of `a`, `b` and `c`.
Input
Input is given from Standard Input in the following format:
S
Output
If S can be obtained by permuting `abc`, print `Yes`; otherwise, print `No`.
Examples
Input
bac
Output
Yes
Input
bab
Output
No
Input
abc
Output
Yes
Input
aaa
Output
No
Submitted Solution:
```
s = input()
m = {}
flag = False
for c in s:
if c not in m:
m[c] = 1
else:
print('No')
flag = True
if not flag:
print('Yes')
``` | instruction | 0 | 78,958 | 18 | 157,916 |
No | output | 1 | 78,958 | 18 | 157,917 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`.
Constraints
* |S|=3
* S consists of `a`, `b` and `c`.
Input
Input is given from Standard Input in the following format:
S
Output
If S can be obtained by permuting `abc`, print `Yes`; otherwise, print `No`.
Examples
Input
bac
Output
Yes
Input
bab
Output
No
Input
abc
Output
Yes
Input
aaa
Output
No
Submitted Solution:
```
s = input()
print("Yes" s.count("a") == 1 and s.count("b") == 1 and s.count("c") == 1 else "No")
``` | instruction | 0 | 78,959 | 18 | 157,918 |
No | output | 1 | 78,959 | 18 | 157,919 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`.
Constraints
* |S|=3
* S consists of `a`, `b` and `c`.
Input
Input is given from Standard Input in the following format:
S
Output
If S can be obtained by permuting `abc`, print `Yes`; otherwise, print `No`.
Examples
Input
bac
Output
Yes
Input
bab
Output
No
Input
abc
Output
Yes
Input
aaa
Output
No
Submitted Solution:
```
lst1 = list(input())
iflen(lst1) != 3:
print("No")
exit()
for i in ["a","b","c"]:
if not i in lst1:
print("No")
exit()
print("Yes")
``` | instruction | 0 | 78,960 | 18 | 157,920 |
No | output | 1 | 78,960 | 18 | 157,921 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters.
Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s.
Given the name of the contest, print the abbreviation of the name.
Constraints
* The length of s is between 1 and 100, inclusive.
* The first character in s is an uppercase English letter.
* The second and subsequent characters in s are lowercase English letters.
Input
The input is given from Standard Input in the following format:
AtCoder s Contest
Output
Print the abbreviation of the name of the contest.
Examples
Input
AtCoder Beginner Contest
Output
ABC
Input
AtCoder Snuke Contest
Output
ASC
Input
AtCoder X Contest
Output
AXC | instruction | 0 | 78,993 | 18 | 157,986 |
"Correct Solution:
```
# A
s = input()
print("A"+ s[8]+ "C")
``` | output | 1 | 78,993 | 18 | 157,987 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters.
Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s.
Given the name of the contest, print the abbreviation of the name.
Constraints
* The length of s is between 1 and 100, inclusive.
* The first character in s is an uppercase English letter.
* The second and subsequent characters in s are lowercase English letters.
Input
The input is given from Standard Input in the following format:
AtCoder s Contest
Output
Print the abbreviation of the name of the contest.
Examples
Input
AtCoder Beginner Contest
Output
ABC
Input
AtCoder Snuke Contest
Output
ASC
Input
AtCoder X Contest
Output
AXC | instruction | 0 | 78,994 | 18 | 157,988 |
"Correct Solution:
```
X=input()
print(X[0]+X[8]+X[-7])
``` | output | 1 | 78,994 | 18 | 157,989 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters.
Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s.
Given the name of the contest, print the abbreviation of the name.
Constraints
* The length of s is between 1 and 100, inclusive.
* The first character in s is an uppercase English letter.
* The second and subsequent characters in s are lowercase English letters.
Input
The input is given from Standard Input in the following format:
AtCoder s Contest
Output
Print the abbreviation of the name of the contest.
Examples
Input
AtCoder Beginner Contest
Output
ABC
Input
AtCoder Snuke Contest
Output
ASC
Input
AtCoder X Contest
Output
AXC | instruction | 0 | 78,995 | 18 | 157,990 |
"Correct Solution:
```
print("A%sC"%input()[8])
``` | output | 1 | 78,995 | 18 | 157,991 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters.
Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s.
Given the name of the contest, print the abbreviation of the name.
Constraints
* The length of s is between 1 and 100, inclusive.
* The first character in s is an uppercase English letter.
* The second and subsequent characters in s are lowercase English letters.
Input
The input is given from Standard Input in the following format:
AtCoder s Contest
Output
Print the abbreviation of the name of the contest.
Examples
Input
AtCoder Beginner Contest
Output
ABC
Input
AtCoder Snuke Contest
Output
ASC
Input
AtCoder X Contest
Output
AXC | instruction | 0 | 78,996 | 18 | 157,992 |
"Correct Solution:
```
s = input()
print("A" + str(s[8]) + "C")
``` | output | 1 | 78,996 | 18 | 157,993 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters.
Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s.
Given the name of the contest, print the abbreviation of the name.
Constraints
* The length of s is between 1 and 100, inclusive.
* The first character in s is an uppercase English letter.
* The second and subsequent characters in s are lowercase English letters.
Input
The input is given from Standard Input in the following format:
AtCoder s Contest
Output
Print the abbreviation of the name of the contest.
Examples
Input
AtCoder Beginner Contest
Output
ABC
Input
AtCoder Snuke Contest
Output
ASC
Input
AtCoder X Contest
Output
AXC | instruction | 0 | 78,997 | 18 | 157,994 |
"Correct Solution:
```
s = input()[8]
print("A{0}C".format(s))
``` | output | 1 | 78,997 | 18 | 157,995 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters.
Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s.
Given the name of the contest, print the abbreviation of the name.
Constraints
* The length of s is between 1 and 100, inclusive.
* The first character in s is an uppercase English letter.
* The second and subsequent characters in s are lowercase English letters.
Input
The input is given from Standard Input in the following format:
AtCoder s Contest
Output
Print the abbreviation of the name of the contest.
Examples
Input
AtCoder Beginner Contest
Output
ABC
Input
AtCoder Snuke Contest
Output
ASC
Input
AtCoder X Contest
Output
AXC | instruction | 0 | 78,998 | 18 | 157,996 |
"Correct Solution:
```
S = input().split()
print('A'+S[1][0]+'C')
``` | output | 1 | 78,998 | 18 | 157,997 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters.
Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s.
Given the name of the contest, print the abbreviation of the name.
Constraints
* The length of s is between 1 and 100, inclusive.
* The first character in s is an uppercase English letter.
* The second and subsequent characters in s are lowercase English letters.
Input
The input is given from Standard Input in the following format:
AtCoder s Contest
Output
Print the abbreviation of the name of the contest.
Examples
Input
AtCoder Beginner Contest
Output
ABC
Input
AtCoder Snuke Contest
Output
ASC
Input
AtCoder X Contest
Output
AXC | instruction | 0 | 78,999 | 18 | 157,998 |
"Correct Solution:
```
S = list(str(input()))
print('A'+ S[8] +'C')
``` | output | 1 | 78,999 | 18 | 157,999 |
Provide a correct Python 3 solution for this coding contest problem.
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters.
Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s.
Given the name of the contest, print the abbreviation of the name.
Constraints
* The length of s is between 1 and 100, inclusive.
* The first character in s is an uppercase English letter.
* The second and subsequent characters in s are lowercase English letters.
Input
The input is given from Standard Input in the following format:
AtCoder s Contest
Output
Print the abbreviation of the name of the contest.
Examples
Input
AtCoder Beginner Contest
Output
ABC
Input
AtCoder Snuke Contest
Output
ASC
Input
AtCoder X Contest
Output
AXC | instruction | 0 | 79,000 | 18 | 158,000 |
"Correct Solution:
```
print("A%cC"%input()[8])
``` | output | 1 | 79,000 | 18 | 158,001 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters.
Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s.
Given the name of the contest, print the abbreviation of the name.
Constraints
* The length of s is between 1 and 100, inclusive.
* The first character in s is an uppercase English letter.
* The second and subsequent characters in s are lowercase English letters.
Input
The input is given from Standard Input in the following format:
AtCoder s Contest
Output
Print the abbreviation of the name of the contest.
Examples
Input
AtCoder Beginner Contest
Output
ABC
Input
AtCoder Snuke Contest
Output
ASC
Input
AtCoder X Contest
Output
AXC
Submitted Solution:
```
S = input()
print(S[0]+S[8]+S[-7])
``` | instruction | 0 | 79,001 | 18 | 158,002 |
Yes | output | 1 | 79,001 | 18 | 158,003 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters.
Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s.
Given the name of the contest, print the abbreviation of the name.
Constraints
* The length of s is between 1 and 100, inclusive.
* The first character in s is an uppercase English letter.
* The second and subsequent characters in s are lowercase English letters.
Input
The input is given from Standard Input in the following format:
AtCoder s Contest
Output
Print the abbreviation of the name of the contest.
Examples
Input
AtCoder Beginner Contest
Output
ABC
Input
AtCoder Snuke Contest
Output
ASC
Input
AtCoder X Contest
Output
AXC
Submitted Solution:
```
a, s, c = input().split()
print('A'+s[0]+'C')
``` | instruction | 0 | 79,002 | 18 | 158,004 |
Yes | output | 1 | 79,002 | 18 | 158,005 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters.
Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s.
Given the name of the contest, print the abbreviation of the name.
Constraints
* The length of s is between 1 and 100, inclusive.
* The first character in s is an uppercase English letter.
* The second and subsequent characters in s are lowercase English letters.
Input
The input is given from Standard Input in the following format:
AtCoder s Contest
Output
Print the abbreviation of the name of the contest.
Examples
Input
AtCoder Beginner Contest
Output
ABC
Input
AtCoder Snuke Contest
Output
ASC
Input
AtCoder X Contest
Output
AXC
Submitted Solution:
```
x = input()
print('A' + x[8] + 'C')
``` | instruction | 0 | 79,003 | 18 | 158,006 |
Yes | output | 1 | 79,003 | 18 | 158,007 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters.
Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s.
Given the name of the contest, print the abbreviation of the name.
Constraints
* The length of s is between 1 and 100, inclusive.
* The first character in s is an uppercase English letter.
* The second and subsequent characters in s are lowercase English letters.
Input
The input is given from Standard Input in the following format:
AtCoder s Contest
Output
Print the abbreviation of the name of the contest.
Examples
Input
AtCoder Beginner Contest
Output
ABC
Input
AtCoder Snuke Contest
Output
ASC
Input
AtCoder X Contest
Output
AXC
Submitted Solution:
```
s = input().split()
print(f"A{s[1][0]}C")
``` | instruction | 0 | 79,004 | 18 | 158,008 |
Yes | output | 1 | 79,004 | 18 | 158,009 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters.
Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s.
Given the name of the contest, print the abbreviation of the name.
Constraints
* The length of s is between 1 and 100, inclusive.
* The first character in s is an uppercase English letter.
* The second and subsequent characters in s are lowercase English letters.
Input
The input is given from Standard Input in the following format:
AtCoder s Contest
Output
Print the abbreviation of the name of the contest.
Examples
Input
AtCoder Beginner Contest
Output
ABC
Input
AtCoder Snuke Contest
Output
ASC
Input
AtCoder X Contest
Output
AXC
Submitted Solution:
```
_, s, _ = input().split()
print(s[0].upper())
``` | instruction | 0 | 79,005 | 18 | 158,010 |
No | output | 1 | 79,005 | 18 | 158,011 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters.
Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s.
Given the name of the contest, print the abbreviation of the name.
Constraints
* The length of s is between 1 and 100, inclusive.
* The first character in s is an uppercase English letter.
* The second and subsequent characters in s are lowercase English letters.
Input
The input is given from Standard Input in the following format:
AtCoder s Contest
Output
Print the abbreviation of the name of the contest.
Examples
Input
AtCoder Beginner Contest
Output
ABC
Input
AtCoder Snuke Contest
Output
ASC
Input
AtCoder X Contest
Output
AXC
Submitted Solution:
```
a, x, c = input().split()
print("{}{}{}".format(a, x[0], c))
``` | instruction | 0 | 79,006 | 18 | 158,012 |
No | output | 1 | 79,006 | 18 | 158,013 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters.
Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s.
Given the name of the contest, print the abbreviation of the name.
Constraints
* The length of s is between 1 and 100, inclusive.
* The first character in s is an uppercase English letter.
* The second and subsequent characters in s are lowercase English letters.
Input
The input is given from Standard Input in the following format:
AtCoder s Contest
Output
Print the abbreviation of the name of the contest.
Examples
Input
AtCoder Beginner Contest
Output
ABC
Input
AtCoder Snuke Contest
Output
ASC
Input
AtCoder X Contest
Output
AXC
Submitted Solution:
```
print(input()[0] + input()[0] + input()[0])
``` | instruction | 0 | 79,007 | 18 | 158,014 |
No | output | 1 | 79,007 | 18 | 158,015 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters.
Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s.
Given the name of the contest, print the abbreviation of the name.
Constraints
* The length of s is between 1 and 100, inclusive.
* The first character in s is an uppercase English letter.
* The second and subsequent characters in s are lowercase English letters.
Input
The input is given from Standard Input in the following format:
AtCoder s Contest
Output
Print the abbreviation of the name of the contest.
Examples
Input
AtCoder Beginner Contest
Output
ABC
Input
AtCoder Snuke Contest
Output
ASC
Input
AtCoder X Contest
Output
AXC
Submitted Solution:
```
a, b, c = list(map(str, input().split()))
print(a,end='')
print(b[0],end ='')
print(c)
``` | instruction | 0 | 79,008 | 18 | 158,016 |
No | output | 1 | 79,008 | 18 | 158,017 |
Provide a correct Python 3 solution for this coding contest problem.
Create a program that converts data based on the given conversion table.
The characters used in the data are letters or numbers, and the letters are case sensitive. There is no regularity in the order of the characters that appear in the conversion table.
The conversion table has two characters (not a string), one before and one after, with a space in between. The conversion method is to convert the character before the line in the conversion table to the character after each time it appears in the data and output it. It is converted only once, and even if the converted character becomes the character to be converted again, it is not converted. Characters that do not appear in the conversion table are not converted and are output as they are.
In the input file, the conversion table (first n + 1 line) is followed by the data to be converted (n + 2nd line and after). The number of lines in the conversion table is n on the first line, each line of the following n lines is two characters with a blank, and then the number of lines of data to be converted on the n + second line m, and each line of the following m lines. Is a single character. Let m ≤ 105. Output should be one line without blanks or line breaks as in the output example.
Input example
---
3
A a
0 5
5 4
Ten
A
B
C
0
1
Four
Five
a
b b
A
Output example
aBC5144aba
input
The input consists of multiple datasets. Input ends when n is 0. The number of datasets does not exceed 5.
output
For each data set, the converted character string is output on one line.
Example
Input
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
0
Output
aBC5144aba
aBC5144aba | instruction | 0 | 79,046 | 18 | 158,092 |
"Correct Solution:
```
import sys
s=sys.stdin
while 1:
n=int(s.readline())
if n==0:break
d={}
for _ in[0]*n:
k,v=s.readline().strip().split()
d[k]=v
a=''
for _ in[0]*int(s.readline()):
e=s.readline().strip()
a+=d[e]if e in d else e
print(a)
``` | output | 1 | 79,046 | 18 | 158,093 |
Provide a correct Python 3 solution for this coding contest problem.
Create a program that converts data based on the given conversion table.
The characters used in the data are letters or numbers, and the letters are case sensitive. There is no regularity in the order of the characters that appear in the conversion table.
The conversion table has two characters (not a string), one before and one after, with a space in between. The conversion method is to convert the character before the line in the conversion table to the character after each time it appears in the data and output it. It is converted only once, and even if the converted character becomes the character to be converted again, it is not converted. Characters that do not appear in the conversion table are not converted and are output as they are.
In the input file, the conversion table (first n + 1 line) is followed by the data to be converted (n + 2nd line and after). The number of lines in the conversion table is n on the first line, each line of the following n lines is two characters with a blank, and then the number of lines of data to be converted on the n + second line m, and each line of the following m lines. Is a single character. Let m ≤ 105. Output should be one line without blanks or line breaks as in the output example.
Input example
---
3
A a
0 5
5 4
Ten
A
B
C
0
1
Four
Five
a
b b
A
Output example
aBC5144aba
input
The input consists of multiple datasets. Input ends when n is 0. The number of datasets does not exceed 5.
output
For each data set, the converted character string is output on one line.
Example
Input
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
0
Output
aBC5144aba
aBC5144aba | instruction | 0 | 79,047 | 18 | 158,094 |
"Correct Solution:
```
n=int(input())
while(n!=0):
list={}
sum=""
for i in range(n):
a,b=input().split()
list[a]=b.rstrip()
n=int(input())
for i in range(n):
s=input().rstrip()
if s in list:
sum+=list[s]
else:
sum+=s
print(sum)
n=int(input())
``` | output | 1 | 79,047 | 18 | 158,095 |
Provide a correct Python 3 solution for this coding contest problem.
Create a program that converts data based on the given conversion table.
The characters used in the data are letters or numbers, and the letters are case sensitive. There is no regularity in the order of the characters that appear in the conversion table.
The conversion table has two characters (not a string), one before and one after, with a space in between. The conversion method is to convert the character before the line in the conversion table to the character after each time it appears in the data and output it. It is converted only once, and even if the converted character becomes the character to be converted again, it is not converted. Characters that do not appear in the conversion table are not converted and are output as they are.
In the input file, the conversion table (first n + 1 line) is followed by the data to be converted (n + 2nd line and after). The number of lines in the conversion table is n on the first line, each line of the following n lines is two characters with a blank, and then the number of lines of data to be converted on the n + second line m, and each line of the following m lines. Is a single character. Let m ≤ 105. Output should be one line without blanks or line breaks as in the output example.
Input example
---
3
A a
0 5
5 4
Ten
A
B
C
0
1
Four
Five
a
b b
A
Output example
aBC5144aba
input
The input consists of multiple datasets. Input ends when n is 0. The number of datasets does not exceed 5.
output
For each data set, the converted character string is output on one line.
Example
Input
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
0
Output
aBC5144aba
aBC5144aba | instruction | 0 | 79,048 | 18 | 158,096 |
"Correct Solution:
```
while True:
x = int(input())
if x == 0:
break
dcl = {}
for i in range(x):
inp = list(map(str, input().split()))
dcl[inp[0]] = inp[1]
ans = ""
x = int(input())
for i in range(x):
y = str(input()[0])
if y in dcl:
ans += dcl[y]
else:
ans += y
print(ans)
``` | output | 1 | 79,048 | 18 | 158,097 |
Provide a correct Python 3 solution for this coding contest problem.
Create a program that converts data based on the given conversion table.
The characters used in the data are letters or numbers, and the letters are case sensitive. There is no regularity in the order of the characters that appear in the conversion table.
The conversion table has two characters (not a string), one before and one after, with a space in between. The conversion method is to convert the character before the line in the conversion table to the character after each time it appears in the data and output it. It is converted only once, and even if the converted character becomes the character to be converted again, it is not converted. Characters that do not appear in the conversion table are not converted and are output as they are.
In the input file, the conversion table (first n + 1 line) is followed by the data to be converted (n + 2nd line and after). The number of lines in the conversion table is n on the first line, each line of the following n lines is two characters with a blank, and then the number of lines of data to be converted on the n + second line m, and each line of the following m lines. Is a single character. Let m ≤ 105. Output should be one line without blanks or line breaks as in the output example.
Input example
---
3
A a
0 5
5 4
Ten
A
B
C
0
1
Four
Five
a
b b
A
Output example
aBC5144aba
input
The input consists of multiple datasets. Input ends when n is 0. The number of datasets does not exceed 5.
output
For each data set, the converted character string is output on one line.
Example
Input
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
0
Output
aBC5144aba
aBC5144aba | instruction | 0 | 79,049 | 18 | 158,098 |
"Correct Solution:
```
import sys
while True:
n = int(sys.stdin.readline().rstrip())
if n == 0:
break;
x = {}
for i in range(n):
k,v = sys.stdin.readline().rstrip().split()
x[k] = v
y = []
for i in range(int(sys.stdin.readline().rstrip())):
a = sys.stdin.readline().rstrip()
if a in x:
y.append(x[a])
else:
y.append(a)
print(''.join(y))
``` | output | 1 | 79,049 | 18 | 158,099 |
Provide a correct Python 3 solution for this coding contest problem.
Create a program that converts data based on the given conversion table.
The characters used in the data are letters or numbers, and the letters are case sensitive. There is no regularity in the order of the characters that appear in the conversion table.
The conversion table has two characters (not a string), one before and one after, with a space in between. The conversion method is to convert the character before the line in the conversion table to the character after each time it appears in the data and output it. It is converted only once, and even if the converted character becomes the character to be converted again, it is not converted. Characters that do not appear in the conversion table are not converted and are output as they are.
In the input file, the conversion table (first n + 1 line) is followed by the data to be converted (n + 2nd line and after). The number of lines in the conversion table is n on the first line, each line of the following n lines is two characters with a blank, and then the number of lines of data to be converted on the n + second line m, and each line of the following m lines. Is a single character. Let m ≤ 105. Output should be one line without blanks or line breaks as in the output example.
Input example
---
3
A a
0 5
5 4
Ten
A
B
C
0
1
Four
Five
a
b b
A
Output example
aBC5144aba
input
The input consists of multiple datasets. Input ends when n is 0. The number of datasets does not exceed 5.
output
For each data set, the converted character string is output on one line.
Example
Input
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
0
Output
aBC5144aba
aBC5144aba | instruction | 0 | 79,050 | 18 | 158,100 |
"Correct Solution:
```
import sys
s=sys.stdin
f=lambda:s.readline()
while 1:
n=int(f())
if n==0:break
d={}
for _ in[0]*n:
k,v=f().strip().split()
d[k]=v
a=''
for _ in[0]*int(f()):
e=f().strip()
a+=d[e]if e in d else e
print(a)
``` | output | 1 | 79,050 | 18 | 158,101 |
Provide a correct Python 3 solution for this coding contest problem.
Create a program that converts data based on the given conversion table.
The characters used in the data are letters or numbers, and the letters are case sensitive. There is no regularity in the order of the characters that appear in the conversion table.
The conversion table has two characters (not a string), one before and one after, with a space in between. The conversion method is to convert the character before the line in the conversion table to the character after each time it appears in the data and output it. It is converted only once, and even if the converted character becomes the character to be converted again, it is not converted. Characters that do not appear in the conversion table are not converted and are output as they are.
In the input file, the conversion table (first n + 1 line) is followed by the data to be converted (n + 2nd line and after). The number of lines in the conversion table is n on the first line, each line of the following n lines is two characters with a blank, and then the number of lines of data to be converted on the n + second line m, and each line of the following m lines. Is a single character. Let m ≤ 105. Output should be one line without blanks or line breaks as in the output example.
Input example
---
3
A a
0 5
5 4
Ten
A
B
C
0
1
Four
Five
a
b b
A
Output example
aBC5144aba
input
The input consists of multiple datasets. Input ends when n is 0. The number of datasets does not exceed 5.
output
For each data set, the converted character string is output on one line.
Example
Input
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
0
Output
aBC5144aba
aBC5144aba | instruction | 0 | 79,051 | 18 | 158,102 |
"Correct Solution:
```
if __name__ == '__main__':
# ??????????????\???
while True:
conv_num = int(input().strip())
if conv_num == 0:
break
conv_dict = {}
for i in range(conv_num):
from_ch, to_ch = input().strip().split(' ')
conv_dict[from_ch] = to_ch
text_len = int(input().strip())
orig_txt = [input().strip() for _ in range(text_len)]
# ???????????????
converted_txt = []
for c in orig_txt:
if c in conv_dict:
converted_txt.append(conv_dict[c])
else:
converted_txt.append(c)
# ???????????¨???
print('{0}'.format(''.join(map(str, converted_txt))))
``` | output | 1 | 79,051 | 18 | 158,103 |
Provide a correct Python 3 solution for this coding contest problem.
Create a program that converts data based on the given conversion table.
The characters used in the data are letters or numbers, and the letters are case sensitive. There is no regularity in the order of the characters that appear in the conversion table.
The conversion table has two characters (not a string), one before and one after, with a space in between. The conversion method is to convert the character before the line in the conversion table to the character after each time it appears in the data and output it. It is converted only once, and even if the converted character becomes the character to be converted again, it is not converted. Characters that do not appear in the conversion table are not converted and are output as they are.
In the input file, the conversion table (first n + 1 line) is followed by the data to be converted (n + 2nd line and after). The number of lines in the conversion table is n on the first line, each line of the following n lines is two characters with a blank, and then the number of lines of data to be converted on the n + second line m, and each line of the following m lines. Is a single character. Let m ≤ 105. Output should be one line without blanks or line breaks as in the output example.
Input example
---
3
A a
0 5
5 4
Ten
A
B
C
0
1
Four
Five
a
b b
A
Output example
aBC5144aba
input
The input consists of multiple datasets. Input ends when n is 0. The number of datasets does not exceed 5.
output
For each data set, the converted character string is output on one line.
Example
Input
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
0
Output
aBC5144aba
aBC5144aba | instruction | 0 | 79,052 | 18 | 158,104 |
"Correct Solution:
```
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect
while(True):
after_string_list = []
before_string_list = []
convert_list = {}
n = int(input())
if n == 0:
break
for i in range(n):
convert = list(input().split())
convert_list[convert[0]] = convert[1]
m = int(input())
for i in range(m):
before_string_list.append(input().rstrip())
for c in before_string_list:
if c in convert_list:
after_string_list.append(convert_list[c])
else:
after_string_list.append(c)
print("".join(after_string_list))
``` | output | 1 | 79,052 | 18 | 158,105 |
Provide a correct Python 3 solution for this coding contest problem.
Create a program that converts data based on the given conversion table.
The characters used in the data are letters or numbers, and the letters are case sensitive. There is no regularity in the order of the characters that appear in the conversion table.
The conversion table has two characters (not a string), one before and one after, with a space in between. The conversion method is to convert the character before the line in the conversion table to the character after each time it appears in the data and output it. It is converted only once, and even if the converted character becomes the character to be converted again, it is not converted. Characters that do not appear in the conversion table are not converted and are output as they are.
In the input file, the conversion table (first n + 1 line) is followed by the data to be converted (n + 2nd line and after). The number of lines in the conversion table is n on the first line, each line of the following n lines is two characters with a blank, and then the number of lines of data to be converted on the n + second line m, and each line of the following m lines. Is a single character. Let m ≤ 105. Output should be one line without blanks or line breaks as in the output example.
Input example
---
3
A a
0 5
5 4
Ten
A
B
C
0
1
Four
Five
a
b b
A
Output example
aBC5144aba
input
The input consists of multiple datasets. Input ends when n is 0. The number of datasets does not exceed 5.
output
For each data set, the converted character string is output on one line.
Example
Input
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
0
Output
aBC5144aba
aBC5144aba | instruction | 0 | 79,053 | 18 | 158,106 |
"Correct Solution:
```
#!/home/minamo/.pyenv/versions/3.6.1/bin/python
# vim: ft=python
# coding: utf-8
def registerDictionaryFromTheNumberOf(counts):
dictionary = {}
for i in range(counts):
key, value = input().split(" ")
dictionary[key] = value
return dictionary
def readCharacterBeforeConversionAsManyAs(counts):
readString = ""
for i in range(counts):
readString += input().rstrip()
return readString
def convertCharactersByThe(dictionary, target):
converted = ""
for index in range(len(list(target))):
if target[index] in dictionary:
converted += dictionary[target[index]]
else:
converted += target[index]
return converted
while True:
dictionaryCounts = int(input())
if dictionaryCounts == 0:
break
dictionary = registerDictionaryFromTheNumberOf(dictionaryCounts)
original = readCharacterBeforeConversionAsManyAs(int(input()))
converted = convertCharactersByThe(dictionary, original)
print(converted)
``` | output | 1 | 79,053 | 18 | 158,107 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Create a program that converts data based on the given conversion table.
The characters used in the data are letters or numbers, and the letters are case sensitive. There is no regularity in the order of the characters that appear in the conversion table.
The conversion table has two characters (not a string), one before and one after, with a space in between. The conversion method is to convert the character before the line in the conversion table to the character after each time it appears in the data and output it. It is converted only once, and even if the converted character becomes the character to be converted again, it is not converted. Characters that do not appear in the conversion table are not converted and are output as they are.
In the input file, the conversion table (first n + 1 line) is followed by the data to be converted (n + 2nd line and after). The number of lines in the conversion table is n on the first line, each line of the following n lines is two characters with a blank, and then the number of lines of data to be converted on the n + second line m, and each line of the following m lines. Is a single character. Let m ≤ 105. Output should be one line without blanks or line breaks as in the output example.
Input example
---
3
A a
0 5
5 4
Ten
A
B
C
0
1
Four
Five
a
b b
A
Output example
aBC5144aba
input
The input consists of multiple datasets. Input ends when n is 0. The number of datasets does not exceed 5.
output
For each data set, the converted character string is output on one line.
Example
Input
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
0
Output
aBC5144aba
aBC5144aba
Submitted Solution:
```
while 1:
n = int(input())
if n == 0:
break
dic = dict()
for i in range(0,n):
w1,w2 = input().split()
dic[w1] = w2
n = int(input())
s = ""
for i in range(0,n):
w = input()[0]
if dic.get(w) != None:
s += dic.get(w)
else:
s += w
print(s)
``` | instruction | 0 | 79,054 | 18 | 158,108 |
Yes | output | 1 | 79,054 | 18 | 158,109 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Create a program that converts data based on the given conversion table.
The characters used in the data are letters or numbers, and the letters are case sensitive. There is no regularity in the order of the characters that appear in the conversion table.
The conversion table has two characters (not a string), one before and one after, with a space in between. The conversion method is to convert the character before the line in the conversion table to the character after each time it appears in the data and output it. It is converted only once, and even if the converted character becomes the character to be converted again, it is not converted. Characters that do not appear in the conversion table are not converted and are output as they are.
In the input file, the conversion table (first n + 1 line) is followed by the data to be converted (n + 2nd line and after). The number of lines in the conversion table is n on the first line, each line of the following n lines is two characters with a blank, and then the number of lines of data to be converted on the n + second line m, and each line of the following m lines. Is a single character. Let m ≤ 105. Output should be one line without blanks or line breaks as in the output example.
Input example
---
3
A a
0 5
5 4
Ten
A
B
C
0
1
Four
Five
a
b b
A
Output example
aBC5144aba
input
The input consists of multiple datasets. Input ends when n is 0. The number of datasets does not exceed 5.
output
For each data set, the converted character string is output on one line.
Example
Input
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
0
Output
aBC5144aba
aBC5144aba
Submitted Solution:
```
import sys
while True:
n = int(input())
if n == 0:
break;
x = {}
for i in range(n):
k,v = sys.stdin.readline().rstrip().split()
x[k] = v
y = []
for i in range(int(sys.stdin.readline().rstrip())):
a = sys.stdin.readline().rstrip()
if a in x:
y.append(x[a])
else:
y.append(a)
print(''.join(y))
``` | instruction | 0 | 79,055 | 18 | 158,110 |
Yes | output | 1 | 79,055 | 18 | 158,111 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Create a program that converts data based on the given conversion table.
The characters used in the data are letters or numbers, and the letters are case sensitive. There is no regularity in the order of the characters that appear in the conversion table.
The conversion table has two characters (not a string), one before and one after, with a space in between. The conversion method is to convert the character before the line in the conversion table to the character after each time it appears in the data and output it. It is converted only once, and even if the converted character becomes the character to be converted again, it is not converted. Characters that do not appear in the conversion table are not converted and are output as they are.
In the input file, the conversion table (first n + 1 line) is followed by the data to be converted (n + 2nd line and after). The number of lines in the conversion table is n on the first line, each line of the following n lines is two characters with a blank, and then the number of lines of data to be converted on the n + second line m, and each line of the following m lines. Is a single character. Let m ≤ 105. Output should be one line without blanks or line breaks as in the output example.
Input example
---
3
A a
0 5
5 4
Ten
A
B
C
0
1
Four
Five
a
b b
A
Output example
aBC5144aba
input
The input consists of multiple datasets. Input ends when n is 0. The number of datasets does not exceed 5.
output
For each data set, the converted character string is output on one line.
Example
Input
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
0
Output
aBC5144aba
aBC5144aba
Submitted Solution:
```
import sys
f=lambda:sys.stdin.readline()
while 1:
n=int(f())
if n==0:break
d={}
for _ in[0]*n:
k,v=f().strip().split()
d[k]=v
a=''
for _ in[0]*int(f()):
e=f().strip()
a+=d[e]if e in d else e
print(a)
``` | instruction | 0 | 79,056 | 18 | 158,112 |
Yes | output | 1 | 79,056 | 18 | 158,113 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Create a program that converts data based on the given conversion table.
The characters used in the data are letters or numbers, and the letters are case sensitive. There is no regularity in the order of the characters that appear in the conversion table.
The conversion table has two characters (not a string), one before and one after, with a space in between. The conversion method is to convert the character before the line in the conversion table to the character after each time it appears in the data and output it. It is converted only once, and even if the converted character becomes the character to be converted again, it is not converted. Characters that do not appear in the conversion table are not converted and are output as they are.
In the input file, the conversion table (first n + 1 line) is followed by the data to be converted (n + 2nd line and after). The number of lines in the conversion table is n on the first line, each line of the following n lines is two characters with a blank, and then the number of lines of data to be converted on the n + second line m, and each line of the following m lines. Is a single character. Let m ≤ 105. Output should be one line without blanks or line breaks as in the output example.
Input example
---
3
A a
0 5
5 4
Ten
A
B
C
0
1
Four
Five
a
b b
A
Output example
aBC5144aba
input
The input consists of multiple datasets. Input ends when n is 0. The number of datasets does not exceed 5.
output
For each data set, the converted character string is output on one line.
Example
Input
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
0
Output
aBC5144aba
aBC5144aba
Submitted Solution:
```
while 1:
n=int(input())
if n==0:break
d={}
for _ in[0]*n:
k,v=input().strip().split()
d[k]=v
a=''
for _ in[0]*int(input()):
e=input().strip()
a+=d[e]if e in d else e
print(a)
``` | instruction | 0 | 79,057 | 18 | 158,114 |
Yes | output | 1 | 79,057 | 18 | 158,115 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Create a program that converts data based on the given conversion table.
The characters used in the data are letters or numbers, and the letters are case sensitive. There is no regularity in the order of the characters that appear in the conversion table.
The conversion table has two characters (not a string), one before and one after, with a space in between. The conversion method is to convert the character before the line in the conversion table to the character after each time it appears in the data and output it. It is converted only once, and even if the converted character becomes the character to be converted again, it is not converted. Characters that do not appear in the conversion table are not converted and are output as they are.
In the input file, the conversion table (first n + 1 line) is followed by the data to be converted (n + 2nd line and after). The number of lines in the conversion table is n on the first line, each line of the following n lines is two characters with a blank, and then the number of lines of data to be converted on the n + second line m, and each line of the following m lines. Is a single character. Let m ≤ 105. Output should be one line without blanks or line breaks as in the output example.
Input example
---
3
A a
0 5
5 4
Ten
A
B
C
0
1
Four
Five
a
b b
A
Output example
aBC5144aba
input
The input consists of multiple datasets. Input ends when n is 0. The number of datasets does not exceed 5.
output
For each data set, the converted character string is output on one line.
Example
Input
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
0
Output
aBC5144aba
aBC5144aba
Submitted Solution:
```
import sys
while True:
n = int(input())
if n == 0:
break;
x = {}
for i in range(n):
k,v = sys.stdin.readline().rstrip().split()
x[k] = v
y = []
for i in range(int(input())):
a = input()
if a in x:
y.append(x[a])
else:
y.append(a)
print(''.join(y))
``` | instruction | 0 | 79,058 | 18 | 158,116 |
No | output | 1 | 79,058 | 18 | 158,117 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Create a program that converts data based on the given conversion table.
The characters used in the data are letters or numbers, and the letters are case sensitive. There is no regularity in the order of the characters that appear in the conversion table.
The conversion table has two characters (not a string), one before and one after, with a space in between. The conversion method is to convert the character before the line in the conversion table to the character after each time it appears in the data and output it. It is converted only once, and even if the converted character becomes the character to be converted again, it is not converted. Characters that do not appear in the conversion table are not converted and are output as they are.
In the input file, the conversion table (first n + 1 line) is followed by the data to be converted (n + 2nd line and after). The number of lines in the conversion table is n on the first line, each line of the following n lines is two characters with a blank, and then the number of lines of data to be converted on the n + second line m, and each line of the following m lines. Is a single character. Let m ≤ 105. Output should be one line without blanks or line breaks as in the output example.
Input example
---
3
A a
0 5
5 4
Ten
A
B
C
0
1
Four
Five
a
b b
A
Output example
aBC5144aba
input
The input consists of multiple datasets. Input ends when n is 0. The number of datasets does not exceed 5.
output
For each data set, the converted character string is output on one line.
Example
Input
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
0
Output
aBC5144aba
aBC5144aba
Submitted Solution:
```
import sys
f = sys.stdin
n = int(f.readline())
converter = {}
for _ in range(n):
pre, post = f.readline().strip().split()
converter[pre] = post
m = int(f.readline())
for _ in range(m):
c = f.readline().strip()
print(converter[c] if c in converter else c, end='')
print()
``` | instruction | 0 | 79,059 | 18 | 158,118 |
No | output | 1 | 79,059 | 18 | 158,119 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Create a program that converts data based on the given conversion table.
The characters used in the data are letters or numbers, and the letters are case sensitive. There is no regularity in the order of the characters that appear in the conversion table.
The conversion table has two characters (not a string), one before and one after, with a space in between. The conversion method is to convert the character before the line in the conversion table to the character after each time it appears in the data and output it. It is converted only once, and even if the converted character becomes the character to be converted again, it is not converted. Characters that do not appear in the conversion table are not converted and are output as they are.
In the input file, the conversion table (first n + 1 line) is followed by the data to be converted (n + 2nd line and after). The number of lines in the conversion table is n on the first line, each line of the following n lines is two characters with a blank, and then the number of lines of data to be converted on the n + second line m, and each line of the following m lines. Is a single character. Let m ≤ 105. Output should be one line without blanks or line breaks as in the output example.
Input example
---
3
A a
0 5
5 4
Ten
A
B
C
0
1
Four
Five
a
b b
A
Output example
aBC5144aba
input
The input consists of multiple datasets. Input ends when n is 0. The number of datasets does not exceed 5.
output
For each data set, the converted character string is output on one line.
Example
Input
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
0
Output
aBC5144aba
aBC5144aba
Submitted Solution:
```
while True:
n = int(input())
if n == 0:
break
conversion = {}
for i in range(n):
before, after = input().split()
conversion[before] = after
m = int(input())
answer = []
for i in range(m):
char = input()
if char in conversion:
answer.append(conversion[char])
else:
answer.append(char)
for w in answer:
print(w, end="")
print()
``` | instruction | 0 | 79,060 | 18 | 158,120 |
No | output | 1 | 79,060 | 18 | 158,121 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Create a program that converts data based on the given conversion table.
The characters used in the data are letters or numbers, and the letters are case sensitive. There is no regularity in the order of the characters that appear in the conversion table.
The conversion table has two characters (not a string), one before and one after, with a space in between. The conversion method is to convert the character before the line in the conversion table to the character after each time it appears in the data and output it. It is converted only once, and even if the converted character becomes the character to be converted again, it is not converted. Characters that do not appear in the conversion table are not converted and are output as they are.
In the input file, the conversion table (first n + 1 line) is followed by the data to be converted (n + 2nd line and after). The number of lines in the conversion table is n on the first line, each line of the following n lines is two characters with a blank, and then the number of lines of data to be converted on the n + second line m, and each line of the following m lines. Is a single character. Let m ≤ 105. Output should be one line without blanks or line breaks as in the output example.
Input example
---
3
A a
0 5
5 4
Ten
A
B
C
0
1
Four
Five
a
b b
A
Output example
aBC5144aba
input
The input consists of multiple datasets. Input ends when n is 0. The number of datasets does not exceed 5.
output
For each data set, the converted character string is output on one line.
Example
Input
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
3
A a
0 5
5 4
10
A
B
C
0
1
4
5
a
b
A
0
Output
aBC5144aba
aBC5144aba
Submitted Solution:
```
while True:
n = int(input())
if n == 0:
break
pre = ""
post = ""
for _ in range(n):
l = input().split()
pre += l[0]
post += l[1]
m = int(input())
data = ""
for _ in range(m):
data += input()
print(data.translate(str.maketrans(pre, post)), end="")
``` | instruction | 0 | 79,061 | 18 | 158,122 |
No | output | 1 | 79,061 | 18 | 158,123 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This problem is different with hard version only by constraints on total answers length
It is an interactive problem
Venya joined a tour to the madhouse, in which orderlies play with patients the following game. Orderlies pick a string s of length n, consisting only of lowercase English letters. The player can ask two types of queries:
* ? l r – ask to list all substrings of s[l..r]. Substrings will be returned in random order, and in every substring, all characters will be randomly shuffled.
* ! s – guess the string picked by the orderlies. This query can be asked exactly once, after that the game will finish. If the string is guessed correctly, the player wins, otherwise he loses.
The player can ask no more than 3 queries of the first type.
To make it easier for the orderlies, there is an additional limitation: the total number of returned substrings in all queries of the first type must not exceed (n+1)^2.
Venya asked you to write a program, which will guess the string by interacting with the orderlies' program and acting by the game's rules.
Your program should immediately terminate after guessing the string using a query of the second type. In case your program guessed the string incorrectly, or it violated the game rules, it will receive verdict Wrong answer.
Note that in every test case the string is fixed beforehand and will not change during the game, which means that the interactor is not adaptive.
Input
First line contains number n (1 ≤ n ≤ 100) — the length of the picked string.
Interaction
You start the interaction by reading the number n.
To ask a query about a substring from l to r inclusively (1 ≤ l ≤ r ≤ n), you should output
? l r
on a separate line. After this, all substrings of s[l..r] will be returned in random order, each substring exactly once. In every returned substring all characters will be randomly shuffled.
In the case, if you ask an incorrect query, ask more than 3 queries of the first type or there will be more than (n+1)^2 substrings returned in total, you will receive verdict Wrong answer.
To guess the string s, you should output
! s
on a separate line.
After printing each query, do not forget to flush the output. Otherwise, you will get Idleness limit exceeded. To flush the output, you can use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
If you received - (dash) as an answer to any query, you need to terminate your program with exit code 0 (for example, by calling exit(0)). This means that there was an error in the interaction protocol. If you don't terminate with exit code 0, you can receive any unsuccessful verdict.
Hack format
To hack a solution, use the following format:
The first line should contain one integer n (1 ≤ n ≤ 100) — the length of the string, and the following line should contain the string s.
Example
Input
4
a
aa
a
cb
b
c
c
Output
? 1 2
? 3 4
? 4 4
! aabc
Submitted Solution:
```
from sys import stdout
class String2:
def __init__(self, s, b=None):
if b is not None:
self.b = b
return
self.b = [0] * 26
for i in s:
self.b[ord(i) - ord('a')] += 1
def __add__(self, other):
b = self.b.copy()
for i in range(26):
b[i] += other.b[i]
return String2('', b)
def __sub__(self, other):
b = self.b.copy()
for i in range(26):
b[i] -= other.b[i]
return b
def __mul__(self, other):
ans = String2('', self.b)
for i in range(26):
ans.b[i] *= other
return ans
def req(l, r, k=0):
print('?', l, r)
v = [''.join(sorted(input())) for i in range((r - l + 1) * (r - l + 2) // 2)]
stdout.flush()
return v
def compute(v):
bukvi = [[0] * (n + 2) for _ in range(26)]
for el in v:
cur = len(el)
for e in el:
bukvi[ord(e) - ord('a')][cur] += 1
return bukvi
def compute2(bukvi):
bukvis = [set() for i in range(n + 2)]
for i in range(26):
prev = bukvi[i][1]
for j in range(1, n // 2 + n % 2 + 1):
while bukvi[i][j] != prev:
bukvis[j].add(chr(ord('a') + i))
prev += 1
return bukvis
def solve(va, va2):
for i in va2:
va.remove(i)
va.sort(key=len)
s = va[0]
for i in range(1, len(va)):
for j in range(26):
if va[i].count(chr(ord('a') + j)) != va[i - 1].count(chr(ord('a') + j)):
s += chr(ord('a') + j)
return s
def check(v, s, s2, f):
s3 = String2(v[0])
for i in range(1, len(v)):
s3 = s3 + String2(v[i])
le = len(v[0])
cur = String2('', String2('', f - String2(s)) - String2(s2)) * le
for i in range(le - 2):
cur = cur + (String2(s[i]) * (i + 1)) + (String2(s2[-i]) * (i + 1))
cur = cur + (String2(s[le - 2]) * (le - 1)) + (String2(s[le - 1]) * le)
e = cur - s3
for i in range(26):
if e[i]:
return chr(ord('a') + i)
def main():
if n == 1:
va = req(1, 1)
print('!', va[0])
return
elif n == 2:
va2 = req(1, 1)
va3 = req(2, 2)
print('!', va2[0] + va3[0])
return
elif n == 3:
va = req(1, 1)
va2 = req(2, 2)
va3 = req(3, 3)
print('!', va[0] + va2[0] + va3[0])
return
va = req(1, n)
va2 = req(1, max(n // 2 + n % 2, 2))
va3 = req(2, max(n // 2 + n % 2, 2))
# bukvi2 = compute(va2)
# bukvi3 = compute(va3)
ma = [[] for i in range(n * 2)]
for i in va:
ma[len(i)].append(i)
a = String2(''.join(ma[1]))
s = solve(va2, va3)
s2 = ''
for i in range(2, n // 2 + 1):
s2 = check(ma[i], s, s2, a) + s2
se = String2('', a - String2(s)) - String2(s2)
for i in range(len(se)):
if se[i]:
s += chr(ord('a') + i)
break
print('!', s + s2)
n = int(input())
main()
``` | instruction | 0 | 79,286 | 18 | 158,572 |
No | output | 1 | 79,286 | 18 | 158,573 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This problem is different with hard version only by constraints on total answers length
It is an interactive problem
Venya joined a tour to the madhouse, in which orderlies play with patients the following game. Orderlies pick a string s of length n, consisting only of lowercase English letters. The player can ask two types of queries:
* ? l r – ask to list all substrings of s[l..r]. Substrings will be returned in random order, and in every substring, all characters will be randomly shuffled.
* ! s – guess the string picked by the orderlies. This query can be asked exactly once, after that the game will finish. If the string is guessed correctly, the player wins, otherwise he loses.
The player can ask no more than 3 queries of the first type.
To make it easier for the orderlies, there is an additional limitation: the total number of returned substrings in all queries of the first type must not exceed (n+1)^2.
Venya asked you to write a program, which will guess the string by interacting with the orderlies' program and acting by the game's rules.
Your program should immediately terminate after guessing the string using a query of the second type. In case your program guessed the string incorrectly, or it violated the game rules, it will receive verdict Wrong answer.
Note that in every test case the string is fixed beforehand and will not change during the game, which means that the interactor is not adaptive.
Input
First line contains number n (1 ≤ n ≤ 100) — the length of the picked string.
Interaction
You start the interaction by reading the number n.
To ask a query about a substring from l to r inclusively (1 ≤ l ≤ r ≤ n), you should output
? l r
on a separate line. After this, all substrings of s[l..r] will be returned in random order, each substring exactly once. In every returned substring all characters will be randomly shuffled.
In the case, if you ask an incorrect query, ask more than 3 queries of the first type or there will be more than (n+1)^2 substrings returned in total, you will receive verdict Wrong answer.
To guess the string s, you should output
! s
on a separate line.
After printing each query, do not forget to flush the output. Otherwise, you will get Idleness limit exceeded. To flush the output, you can use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
If you received - (dash) as an answer to any query, you need to terminate your program with exit code 0 (for example, by calling exit(0)). This means that there was an error in the interaction protocol. If you don't terminate with exit code 0, you can receive any unsuccessful verdict.
Hack format
To hack a solution, use the following format:
The first line should contain one integer n (1 ≤ n ≤ 100) — the length of the string, and the following line should contain the string s.
Example
Input
4
a
aa
a
cb
b
c
c
Output
? 1 2
? 3 4
? 4 4
! aabc
Submitted Solution:
```
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
n = I()
l = 1
r = n
print("?",l,r)
sys.stdin.flush()
if n == 1:
print("!",input())
return
s1 = defaultdict(lambda : 0)
for i in range((n*(n+1))>>1):
s = input()
s1[s] += 1
r = n >> 1
m = r-l+1
print("?",l,r)
sys.stdin.flush()
for i in range((m*(m+1))>>1):
s = input()
s1[s] -= 1
l = r + 1
r = n
m = r-l+1
print("?",l,r)
sys.stdin.flush()
for i in range((m*(m+1))>>1):
s = input()
s1[s] -= 1
l = (n >> 1)-1
r = l+1
t = [[] for i in range(n+1)]
for i,j in s1.items():
if j:
t[len(i)].append(i)
print("!",t[1])
ans = t[2][0][0]+t[2][0][1]
for k in range(3,n+1):
for s in t[k]:
if s[1:] == ans:
ans = s[0]+ans
elif s[:-1] == ans:
ans += s[-1]
print("!",ans)
return
#Solve
if __name__ == "__main__":
solve()
``` | instruction | 0 | 79,287 | 18 | 158,574 |
No | output | 1 | 79,287 | 18 | 158,575 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This problem is different with hard version only by constraints on total answers length
It is an interactive problem
Venya joined a tour to the madhouse, in which orderlies play with patients the following game. Orderlies pick a string s of length n, consisting only of lowercase English letters. The player can ask two types of queries:
* ? l r – ask to list all substrings of s[l..r]. Substrings will be returned in random order, and in every substring, all characters will be randomly shuffled.
* ! s – guess the string picked by the orderlies. This query can be asked exactly once, after that the game will finish. If the string is guessed correctly, the player wins, otherwise he loses.
The player can ask no more than 3 queries of the first type.
To make it easier for the orderlies, there is an additional limitation: the total number of returned substrings in all queries of the first type must not exceed (n+1)^2.
Venya asked you to write a program, which will guess the string by interacting with the orderlies' program and acting by the game's rules.
Your program should immediately terminate after guessing the string using a query of the second type. In case your program guessed the string incorrectly, or it violated the game rules, it will receive verdict Wrong answer.
Note that in every test case the string is fixed beforehand and will not change during the game, which means that the interactor is not adaptive.
Input
First line contains number n (1 ≤ n ≤ 100) — the length of the picked string.
Interaction
You start the interaction by reading the number n.
To ask a query about a substring from l to r inclusively (1 ≤ l ≤ r ≤ n), you should output
? l r
on a separate line. After this, all substrings of s[l..r] will be returned in random order, each substring exactly once. In every returned substring all characters will be randomly shuffled.
In the case, if you ask an incorrect query, ask more than 3 queries of the first type or there will be more than (n+1)^2 substrings returned in total, you will receive verdict Wrong answer.
To guess the string s, you should output
! s
on a separate line.
After printing each query, do not forget to flush the output. Otherwise, you will get Idleness limit exceeded. To flush the output, you can use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
If you received - (dash) as an answer to any query, you need to terminate your program with exit code 0 (for example, by calling exit(0)). This means that there was an error in the interaction protocol. If you don't terminate with exit code 0, you can receive any unsuccessful verdict.
Hack format
To hack a solution, use the following format:
The first line should contain one integer n (1 ≤ n ≤ 100) — the length of the string, and the following line should contain the string s.
Example
Input
4
a
aa
a
cb
b
c
c
Output
? 1 2
? 3 4
? 4 4
! aabc
Submitted Solution:
```
mod = 1000000007
eps = 10**-9
def main():
import sys
from collections import Counter
input = sys.stdin.readline
def ask(l, r):
print(*["?", l, r])
sys.stdout.flush()
N = int(input())
ask(1, N)
ret1 = []
for _ in range(N * (N+1) // 2):
s = input().rstrip('\n')
if s == "-":
exit()
ret1.append("".join(sorted(s)))
if N == 1:
ans = ret1[0]
print("!", ans)
sys.stdout.flush()
exit()
ask(1, N-1)
ret2 = []
for _ in range(N * (N - 1) // 2):
s = input().rstrip('\n')
if s == "-":
exit()
ret2.append("".join(sorted(s)))
dic1 = [{} for _ in range(N+1)]
dic2 = [{} for _ in range(N+1)]
for s in ret1:
L = len(s)
if L == N:
S_all = s
if s in dic1[L]:
dic1[L][s] += 1
else:
dic1[L][s] = 1
for s in ret2:
L = len(s)
if s in dic2[L]:
dic2[L][s] += 1
else:
dic2[L][s] = 1
right = [""] * (N+1)
for L in range(N-1, 0, -1):
for s in dic1[L]:
if s not in dic2[L]:
right[L] = s
break
if dic1[L][s] != dic2[L][s]:
right[L] = s
break
ans = [""] * N
dic = {chr(i+97): 0 for i in range(26)}
for L in range(1, N):
C = Counter(right[L])
for i in range(26):
s = chr(i+97)
if dic[s] != C[s]:
ans[-L] = s
dic[s] += 1
break
#print(ans, L, right[L])
C = Counter(S_all)
for i in range(26):
s = chr(i + 97)
if dic[s] != C[s]:
ans[0] = s
dic[s] += 1
break
print("!", "".join(ans))
sys.stdout.flush()
if __name__ == '__main__':
main()
``` | instruction | 0 | 79,288 | 18 | 158,576 |
No | output | 1 | 79,288 | 18 | 158,577 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This problem is different with hard version only by constraints on total answers length
It is an interactive problem
Venya joined a tour to the madhouse, in which orderlies play with patients the following game. Orderlies pick a string s of length n, consisting only of lowercase English letters. The player can ask two types of queries:
* ? l r – ask to list all substrings of s[l..r]. Substrings will be returned in random order, and in every substring, all characters will be randomly shuffled.
* ! s – guess the string picked by the orderlies. This query can be asked exactly once, after that the game will finish. If the string is guessed correctly, the player wins, otherwise he loses.
The player can ask no more than 3 queries of the first type.
To make it easier for the orderlies, there is an additional limitation: the total number of returned substrings in all queries of the first type must not exceed (n+1)^2.
Venya asked you to write a program, which will guess the string by interacting with the orderlies' program and acting by the game's rules.
Your program should immediately terminate after guessing the string using a query of the second type. In case your program guessed the string incorrectly, or it violated the game rules, it will receive verdict Wrong answer.
Note that in every test case the string is fixed beforehand and will not change during the game, which means that the interactor is not adaptive.
Input
First line contains number n (1 ≤ n ≤ 100) — the length of the picked string.
Interaction
You start the interaction by reading the number n.
To ask a query about a substring from l to r inclusively (1 ≤ l ≤ r ≤ n), you should output
? l r
on a separate line. After this, all substrings of s[l..r] will be returned in random order, each substring exactly once. In every returned substring all characters will be randomly shuffled.
In the case, if you ask an incorrect query, ask more than 3 queries of the first type or there will be more than (n+1)^2 substrings returned in total, you will receive verdict Wrong answer.
To guess the string s, you should output
! s
on a separate line.
After printing each query, do not forget to flush the output. Otherwise, you will get Idleness limit exceeded. To flush the output, you can use:
* fflush(stdout) or cout.flush() in C++;
* System.out.flush() in Java;
* flush(output) in Pascal;
* stdout.flush() in Python;
* see documentation for other languages.
If you received - (dash) as an answer to any query, you need to terminate your program with exit code 0 (for example, by calling exit(0)). This means that there was an error in the interaction protocol. If you don't terminate with exit code 0, you can receive any unsuccessful verdict.
Hack format
To hack a solution, use the following format:
The first line should contain one integer n (1 ≤ n ≤ 100) — the length of the string, and the following line should contain the string s.
Example
Input
4
a
aa
a
cb
b
c
c
Output
? 1 2
? 3 4
? 4 4
! aabc
Submitted Solution:
```
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
n = I()
l = 1
r = n
print("?",l,r)
sys.stdin.flush()
if n == 1:
print("!",input())
return
s1 = defaultdict(lambda : 0)
for i in range((n*(n+1))>>1):
s = input()
s1[s] += 1
r = n >> 1
m = r-l+1
print("?",l,r)
sys.stdin.flush()
for i in range((m*(m+1))>>1):
s = input()
s1[s] -= 1
l = r + 1
r = n
m = r-l+1
print("?",l,r)
sys.stdin.flush()
for i in range((m*(m+1))>>1):
s = input()
s1[s] -= 1
print("!",s1)
l = (n >> 1)-1
r = l+1
t = [[] for i in range(n+1)]
for i,j in s1.items():
if j:
t[len(i)].append(i)
ans = t[2][0][0]+t[2][0][1]
for k in range(3,n+1):
for s in t[k]:
if s[1:] == ans:
ans = s[0]+ans
elif s[:-1] == ans:
ans += s[-1]
print("!",ans)
return
#Solve
if __name__ == "__main__":
solve()
``` | instruction | 0 | 79,289 | 18 | 158,578 |
No | output | 1 | 79,289 | 18 | 158,579 |
Provide a correct Python 3 solution for this coding contest problem.
You have obtained the Izua Japanese dictionary, which is the official language of Izua, and the Izua alphabet (list of letters). There are N types of letters in the Izua alphabet. The order of the words that appear in the Izua Japanese dictionary is in the alphabetical order of Izua.
Looking at the dictionary, I found that every word in the dictionary is N letters and contains N kinds of letters one by one. Upon further investigation, I found that the dictionary contained all possible arrangements of the N characters.
From this discovery, you can see what number a word appears in the dictionary. Use this knowledge to surprise people in Izua. First, arrange the N types of letters one by one in alphabetical order. Next, ask them to repeat the operation of changing the order of any two characters R times. You can guess the number of the finished word in the Izua Japanese dictionary. In preparation for that, create a program that finds the location of words in the Japanese dictionary. However, the first word in alphabetical order is the 0th word.
input
The input consists of multiple datasets. The end of the input is indicated by a single zero line. Each dataset is given in the following format.
N
R
s1 t1
s2 t2
::
sR tR
The first line is given the number of characters that make up the alphabet N (1 ≤ N ≤ 100000), and the second line is given the number of times R (0 ≤ R ≤ 50) to have the characters replaced. The following R line is given the set of character positions to be swapped. si and ti (1 ≤ si <ti ≤ N) represent the i-th swapping of the si and ti characters counting from the beginning. si and ti are separated by a single space.
The number of datasets does not exceed 100.
output
For each data set, the number indicating the number of the word obtained at the end of the replacement in the Japanese dictionary is output on one line. However, the value to be output can be very large, so instead output the remainder divided by 1,000,000,007.
Example
Input
3
2
1 2
2 3
4
2
2 3
2 4
0
Output
3
4 | instruction | 0 | 79,849 | 18 | 159,698 |
"Correct Solution:
```
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def main():
MOD = 10**9 + 7
def query(k0):
s = 0
k = k0
while k:
s += data[k]
k -= k & -k
k = k0
while k <= N:
data[k] += 1
k += k & -k
return s % MOD
L = 100000
fact = [1]*(L+1)
rfact = [1]*(L+1)
r = 1
for i in range(2, L+1):
fact[i] = r = i * r % MOD
rfact[i] = r = pow(fact[i], MOD-2, MOD)
for i in range(L, 0, -1):
rfact[i-1] = r = i * r % MOD
while 1:
N = int(readline())
if N == 0:
break
R = int(readline())
*S, = range(N)
for i in range(R):
s, t = map(int, readline().split()); s -= 1; t -= 1
S[s], S[t] = S[t], S[s]
data = [0]*(N+1)
write("%d\n" % (sum(fact[N-1-i] * (e - query(e+1)) % MOD for i, e in enumerate(S)) % MOD))
main()
``` | output | 1 | 79,849 | 18 | 159,699 |
Provide a correct Python 3 solution for this coding contest problem.
You have obtained the Izua Japanese dictionary, which is the official language of Izua, and the Izua alphabet (list of letters). There are N types of letters in the Izua alphabet. The order of the words that appear in the Izua Japanese dictionary is in the alphabetical order of Izua.
Looking at the dictionary, I found that every word in the dictionary is N letters and contains N kinds of letters one by one. Upon further investigation, I found that the dictionary contained all possible arrangements of the N characters.
From this discovery, you can see what number a word appears in the dictionary. Use this knowledge to surprise people in Izua. First, arrange the N types of letters one by one in alphabetical order. Next, ask them to repeat the operation of changing the order of any two characters R times. You can guess the number of the finished word in the Izua Japanese dictionary. In preparation for that, create a program that finds the location of words in the Japanese dictionary. However, the first word in alphabetical order is the 0th word.
input
The input consists of multiple datasets. The end of the input is indicated by a single zero line. Each dataset is given in the following format.
N
R
s1 t1
s2 t2
::
sR tR
The first line is given the number of characters that make up the alphabet N (1 ≤ N ≤ 100000), and the second line is given the number of times R (0 ≤ R ≤ 50) to have the characters replaced. The following R line is given the set of character positions to be swapped. si and ti (1 ≤ si <ti ≤ N) represent the i-th swapping of the si and ti characters counting from the beginning. si and ti are separated by a single space.
The number of datasets does not exceed 100.
output
For each data set, the number indicating the number of the word obtained at the end of the replacement in the Japanese dictionary is output on one line. However, the value to be output can be very large, so instead output the remainder divided by 1,000,000,007.
Example
Input
3
2
1 2
2 3
4
2
2 3
2 4
0
Output
3
4 | instruction | 0 | 79,850 | 18 | 159,700 |
"Correct Solution:
```
def solve():
from sys import stdin
m = 1000000007
f_i = stdin
while True:
N = int(f_i.readline())
if N == 0:
break
w = list(range(N))
R = int(f_i.readline())
for i in range(R):
s, t = map(int, f_i.readline().split())
s -= 1
t -= 1
w[s], w[t] = w[t], w[s]
s = [(i, c) for i, c in enumerate(w) if i != c]
s.sort(reverse=True)
a = 1
f = 1
cnt = 0
for c1, i in zip(w[::-1], range(N - 1, -1, -1)):
if c1 > i:
l = c1
n = c1 - i - 1
else:
l = i
n = 0
for j, c2 in s:
if j <= i:
break
else:
if j < l:
n -= 1
if c2 < c1:
n += 1
cnt = (cnt + (n * a) % m) % m
a = (a * f) % m
f += 1
print(cnt)
solve()
``` | output | 1 | 79,850 | 18 | 159,701 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have obtained the Izua Japanese dictionary, which is the official language of Izua, and the Izua alphabet (list of letters). There are N types of letters in the Izua alphabet. The order of the words that appear in the Izua Japanese dictionary is in the alphabetical order of Izua.
Looking at the dictionary, I found that every word in the dictionary is N letters and contains N kinds of letters one by one. Upon further investigation, I found that the dictionary contained all possible arrangements of the N characters.
From this discovery, you can see what number a word appears in the dictionary. Use this knowledge to surprise people in Izua. First, arrange the N types of letters one by one in alphabetical order. Next, ask them to repeat the operation of changing the order of any two characters R times. You can guess the number of the finished word in the Izua Japanese dictionary. In preparation for that, create a program that finds the location of words in the Japanese dictionary. However, the first word in alphabetical order is the 0th word.
input
The input consists of multiple datasets. The end of the input is indicated by a single zero line. Each dataset is given in the following format.
N
R
s1 t1
s2 t2
::
sR tR
The first line is given the number of characters that make up the alphabet N (1 ≤ N ≤ 100000), and the second line is given the number of times R (0 ≤ R ≤ 50) to have the characters replaced. The following R line is given the set of character positions to be swapped. si and ti (1 ≤ si <ti ≤ N) represent the i-th swapping of the si and ti characters counting from the beginning. si and ti are separated by a single space.
The number of datasets does not exceed 100.
output
For each data set, the number indicating the number of the word obtained at the end of the replacement in the Japanese dictionary is output on one line. However, the value to be output can be very large, so instead output the remainder divided by 1,000,000,007.
Example
Input
3
2
1 2
2 3
4
2
2 3
2 4
0
Output
3
4
Submitted Solution:
```
class BIT:
MAX_IDX = 100001
def __init__(self):
self.bit = [0 for i in range(self.MAX_IDX+1)]
def update(self,idx,v):
while idx <= self.MAX_IDX:
self.bit[idx] += v
idx += idx & (-idx)
def sum(self,idx):
res = 0
while idx > 0:
res += self.bit[idx]
idx -= idx & (-idx)
return res
MAX_IDX = 100001
MOD_V = 1000000007
dp = [0 for i in range(MAX_IDX)]
dp[0] = 1
while 1:
N = int(input())
if N == 0:break
bit = BIT()
izua=[i for i in range(N+1)]
for i in range(1,N+1):
if dp[i] == 0:
dp[i] = (dp[i-1]*i) % MOD_V
R = int(input())
for i in range(R):#swap
s,t = list(map(int,input().split()))
w = izua[t]
izua[t] = izua[s]
izua[s] = w
res = 0
for i in range(N,0,-1):
res += (bit.sum(izua[i])*dp[N-i]) % MOD_V
bit.update(izua[i],1)
print (res%MOD_V)
``` | instruction | 0 | 79,851 | 18 | 159,702 |
No | output | 1 | 79,851 | 18 | 159,703 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have obtained the Izua Japanese dictionary, which is the official language of Izua, and the Izua alphabet (list of letters). There are N types of letters in the Izua alphabet. The order of the words that appear in the Izua Japanese dictionary is in the alphabetical order of Izua.
Looking at the dictionary, I found that every word in the dictionary is N letters and contains N kinds of letters one by one. Upon further investigation, I found that the dictionary contained all possible arrangements of the N characters.
From this discovery, you can see what number a word appears in the dictionary. Use this knowledge to surprise people in Izua. First, arrange the N types of letters one by one in alphabetical order. Next, ask them to repeat the operation of changing the order of any two characters R times. You can guess the number of the finished word in the Izua Japanese dictionary. In preparation for that, create a program that finds the location of words in the Japanese dictionary. However, the first word in alphabetical order is the 0th word.
input
The input consists of multiple datasets. The end of the input is indicated by a single zero line. Each dataset is given in the following format.
N
R
s1 t1
s2 t2
::
sR tR
The first line is given the number of characters that make up the alphabet N (1 ≤ N ≤ 100000), and the second line is given the number of times R (0 ≤ R ≤ 50) to have the characters replaced. The following R line is given the set of character positions to be swapped. si and ti (1 ≤ si <ti ≤ N) represent the i-th swapping of the si and ti characters counting from the beginning. si and ti are separated by a single space.
The number of datasets does not exceed 100.
output
For each data set, the number indicating the number of the word obtained at the end of the replacement in the Japanese dictionary is output on one line. However, the value to be output can be very large, so instead output the remainder divided by 1,000,000,007.
Example
Input
3
2
1 2
2 3
4
2
2 3
2 4
0
Output
3
4
Submitted Solution:
```
class BIT:
MAX_IDX = 100001
def __init__(self):
self.bit = [0 for i in range(self.MAX_IDX+1)]
def update(self,idx,v):
while idx <= self.MAX_IDX:
self.bit[idx] += v
idx += idx & (-idx)
def sum(self,idx):
res = 0
while idx > 0:
res += self.bit[idx]
idx -= idx & (-idx)
return res
MAX_IDX = 100001
dp = [0 for i in range(MAX_IDX)]
dp[0] = 1
while 1:
N = int(input())
if N == 0:break
bit = BIT()
izua=[i for i in range(N+1)]
for i in range(1,N+1):
if dp[i] == 0:
dp[i] = (dp[i-1]*i) #% 1000000007
R = int(input())
for i in range(R):#swap
s,t = list(map(int,input().split()))
w = izua[t]
izua[t] = izua[s]
izua[s] = w
res = 0
for i in range(N,0,-1):
res += (bit.sum(izua[i])*dp[N-i]) % 1000000007
bit.update(izua[i],1)
print (res)
``` | instruction | 0 | 79,852 | 18 | 159,704 |
No | output | 1 | 79,852 | 18 | 159,705 |
Provide a correct Python 3 solution for this coding contest problem.
Airport Codes
Airport code
In the Kingdom of JAG, airport codes are assigned to each domestic airport for identification.
Airport codes are assigned according to the following rules based on the name of the airport in lowercase English alphabet:
1. Extract the first letter of the name and the letter immediately after the vowel (a, i, u, e, o) in order.
2. If the extracted character string is less than k characters, use it as the airport code, and if it is k characters or more, use the first k characters of the extracted character string as the airport code.
For example, when k = 3, haneda is assigned the code hnd, oookayama is assigned the code ooo, and tsu is assigned the code t.
However, with this code assignment method, the same code may be assigned even at airports with different names, which causes confusion. Given a list of airport names, determine if all airport codes can be different, find the minimum k that can make all airport codes different if possible, and if not possible. Create a program to convey this.
Input
The input consists of 100 or less datasets. Each dataset is given in the following format.
> n
> s1
> ...
> sn
The number of airports n (2 ≤ n ≤ 50) is given as an integer on the first line, and the name si of the airport is given as a string on each of the following n lines. Airport names consist only of lowercase English alphabets from'a'to'z', all with 1 to 50 characters. Also, the names of the airports given are all different. That is, when 1 ≤ i <j ≤ n, si ≠ sj is satisfied.
The end of the input is indicated by a line consisting of only one zero.
Output
For each dataset, if all airports can be assigned different airport codes, output such a minimum k on one line. If not possible, output -1 on one line.
Sample Input
3
haneda
oookayama
tsu
2
azusa
azishirabe
2
snuke
snake
Four
haneda
honda
hanamaki
hawaii
0
Output for Sample Input
1
Four
-1
3
Example
Input
3
haneda
oookayama
tsu
2
azusa
azishirabe
2
snuke
snake
4
haneda
honda
hanamaki
hawaii
0
Output
1
4
-1
3 | instruction | 0 | 79,882 | 18 | 159,764 |
"Correct Solution:
```
boin = set(['a', 'i', 'u', 'e', 'o'])
def convert(name):
s = name[0]
for i, c in enumerate(name[1:], 1):
if name[i - 1] in boin:
s += name[i]
return s
while True:
n = int(input())
if n == 0:
break
names = [input() for _ in range(n)]
conv = [convert(n) for n in names]
l = sum([len(c) for c in conv])
ans = -1
for k in range(1, l + 1):
short = set([c[:k] for c in conv])
if len(short) == n:
ans = k
break
print(ans)
``` | output | 1 | 79,882 | 18 | 159,765 |
Provide a correct Python 3 solution for this coding contest problem.
Airport Codes
Airport code
In the Kingdom of JAG, airport codes are assigned to each domestic airport for identification.
Airport codes are assigned according to the following rules based on the name of the airport in lowercase English alphabet:
1. Extract the first letter of the name and the letter immediately after the vowel (a, i, u, e, o) in order.
2. If the extracted character string is less than k characters, use it as the airport code, and if it is k characters or more, use the first k characters of the extracted character string as the airport code.
For example, when k = 3, haneda is assigned the code hnd, oookayama is assigned the code ooo, and tsu is assigned the code t.
However, with this code assignment method, the same code may be assigned even at airports with different names, which causes confusion. Given a list of airport names, determine if all airport codes can be different, find the minimum k that can make all airport codes different if possible, and if not possible. Create a program to convey this.
Input
The input consists of 100 or less datasets. Each dataset is given in the following format.
> n
> s1
> ...
> sn
The number of airports n (2 ≤ n ≤ 50) is given as an integer on the first line, and the name si of the airport is given as a string on each of the following n lines. Airport names consist only of lowercase English alphabets from'a'to'z', all with 1 to 50 characters. Also, the names of the airports given are all different. That is, when 1 ≤ i <j ≤ n, si ≠ sj is satisfied.
The end of the input is indicated by a line consisting of only one zero.
Output
For each dataset, if all airports can be assigned different airport codes, output such a minimum k on one line. If not possible, output -1 on one line.
Sample Input
3
haneda
oookayama
tsu
2
azusa
azishirabe
2
snuke
snake
Four
haneda
honda
hanamaki
hawaii
0
Output for Sample Input
1
Four
-1
3
Example
Input
3
haneda
oookayama
tsu
2
azusa
azishirabe
2
snuke
snake
4
haneda
honda
hanamaki
hawaii
0
Output
1
4
-1
3 | instruction | 0 | 79,883 | 18 | 159,766 |
"Correct Solution:
```
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import re
def enc(s):
repatter = re.compile(r"[aiueo]")
ans = s[0]
for i in range(len(s)):
if i < len(s)-1 and repatter.match(s[i]):
ans += s[i+1]
return ans
def max_str(s):
ans = len(s[0])
for i in s:
ans = max(ans, len(i))
return ans
def func(s, mn, k):
if mn < k:
return -1
ss = []
for i in s:
ss.append(i[:k])
for i in range(len(ss)-1):
pp = ss.pop(0)
if pp in ss:
return func(s, mn, k+1)
return k
if __name__ == "__main__":
while True:
n = int(input())
if n is 0:
break
s = []
for i in range(n):
s.append(enc(input()))
print(func(s, max_str(s), 1))
``` | output | 1 | 79,883 | 18 | 159,767 |
Provide a correct Python 3 solution for this coding contest problem.
Airport Codes
Airport code
In the Kingdom of JAG, airport codes are assigned to each domestic airport for identification.
Airport codes are assigned according to the following rules based on the name of the airport in lowercase English alphabet:
1. Extract the first letter of the name and the letter immediately after the vowel (a, i, u, e, o) in order.
2. If the extracted character string is less than k characters, use it as the airport code, and if it is k characters or more, use the first k characters of the extracted character string as the airport code.
For example, when k = 3, haneda is assigned the code hnd, oookayama is assigned the code ooo, and tsu is assigned the code t.
However, with this code assignment method, the same code may be assigned even at airports with different names, which causes confusion. Given a list of airport names, determine if all airport codes can be different, find the minimum k that can make all airport codes different if possible, and if not possible. Create a program to convey this.
Input
The input consists of 100 or less datasets. Each dataset is given in the following format.
> n
> s1
> ...
> sn
The number of airports n (2 ≤ n ≤ 50) is given as an integer on the first line, and the name si of the airport is given as a string on each of the following n lines. Airport names consist only of lowercase English alphabets from'a'to'z', all with 1 to 50 characters. Also, the names of the airports given are all different. That is, when 1 ≤ i <j ≤ n, si ≠ sj is satisfied.
The end of the input is indicated by a line consisting of only one zero.
Output
For each dataset, if all airports can be assigned different airport codes, output such a minimum k on one line. If not possible, output -1 on one line.
Sample Input
3
haneda
oookayama
tsu
2
azusa
azishirabe
2
snuke
snake
Four
haneda
honda
hanamaki
hawaii
0
Output for Sample Input
1
Four
-1
3
Example
Input
3
haneda
oookayama
tsu
2
azusa
azishirabe
2
snuke
snake
4
haneda
honda
hanamaki
hawaii
0
Output
1
4
-1
3 | instruction | 0 | 79,884 | 18 | 159,768 |
"Correct Solution:
```
# coding: utf-8
import sys
def coding(s):
t = ''
flag = True
for i in s:
if flag:
t += i
flag = False
if i == 'a' or i == 'i' or i == 'u' or i == 'e' or i == 'o':
flag = True;
return t
def pre_possible(ls):
flag = False
for i in range(len(ls)):
for j in range(i+1,len(ls)):
if ls[i] == ls[j]:
flag = True
return flag
def possible(ls,k):
flag = True
for i in range(len(ls)):
for j in range(i+1,len(ls)):
if len(ls[i]) < k or len(ls[j]) < k:
if ls[i] == ls[j]:
flag = False
break
else:
continue
if ls[i][0:k] == ls[j][0:k]:
flag = False
break
if not(flag):
break
return flag
if __name__ == '__main__':
while(1):
n = int(input());
if n == 0:
break
l = []
for i in range(n):
l.append(input())
nl = []
for i in l:
nl.append(coding(i))
sz = min([len(i) for i in l])
ll = 0
hh = 50
if pre_possible(nl):
print(-1)
continue
while True:
mid = (ll + hh) // 2
if ll == mid:
print(hh)
break
if possible(nl,mid):
hh = mid
else:
ll = mid
``` | output | 1 | 79,884 | 18 | 159,769 |
Provide a correct Python 3 solution for this coding contest problem.
Airport Codes
Airport code
In the Kingdom of JAG, airport codes are assigned to each domestic airport for identification.
Airport codes are assigned according to the following rules based on the name of the airport in lowercase English alphabet:
1. Extract the first letter of the name and the letter immediately after the vowel (a, i, u, e, o) in order.
2. If the extracted character string is less than k characters, use it as the airport code, and if it is k characters or more, use the first k characters of the extracted character string as the airport code.
For example, when k = 3, haneda is assigned the code hnd, oookayama is assigned the code ooo, and tsu is assigned the code t.
However, with this code assignment method, the same code may be assigned even at airports with different names, which causes confusion. Given a list of airport names, determine if all airport codes can be different, find the minimum k that can make all airport codes different if possible, and if not possible. Create a program to convey this.
Input
The input consists of 100 or less datasets. Each dataset is given in the following format.
> n
> s1
> ...
> sn
The number of airports n (2 ≤ n ≤ 50) is given as an integer on the first line, and the name si of the airport is given as a string on each of the following n lines. Airport names consist only of lowercase English alphabets from'a'to'z', all with 1 to 50 characters. Also, the names of the airports given are all different. That is, when 1 ≤ i <j ≤ n, si ≠ sj is satisfied.
The end of the input is indicated by a line consisting of only one zero.
Output
For each dataset, if all airports can be assigned different airport codes, output such a minimum k on one line. If not possible, output -1 on one line.
Sample Input
3
haneda
oookayama
tsu
2
azusa
azishirabe
2
snuke
snake
Four
haneda
honda
hanamaki
hawaii
0
Output for Sample Input
1
Four
-1
3
Example
Input
3
haneda
oookayama
tsu
2
azusa
azishirabe
2
snuke
snake
4
haneda
honda
hanamaki
hawaii
0
Output
1
4
-1
3 | instruction | 0 | 79,885 | 18 | 159,770 |
"Correct Solution:
```
V = {"a", "i", "u", "e", "o"}
while True:
N = int(input())
if N==0:
exit()
L = []
maxs = 0
for _ in range(N):
s = input()
s_ = s[0]
for i in range(len(s)-1):
if s[i] in V:
s_ += s[i+1]
maxs = max(maxs, len(s_))
L.append(s_ + "."*(51-len(s_)))
L.sort()
k = 1
for s1, s2 in zip(L[:-1], L[1:]):
while k != 51 and s1[:k] == s2[:k]:
k += 1
if k==51:
print(-1)
else:
print(k)
``` | output | 1 | 79,885 | 18 | 159,771 |
Provide a correct Python 3 solution for this coding contest problem.
Airport Codes
Airport code
In the Kingdom of JAG, airport codes are assigned to each domestic airport for identification.
Airport codes are assigned according to the following rules based on the name of the airport in lowercase English alphabet:
1. Extract the first letter of the name and the letter immediately after the vowel (a, i, u, e, o) in order.
2. If the extracted character string is less than k characters, use it as the airport code, and if it is k characters or more, use the first k characters of the extracted character string as the airport code.
For example, when k = 3, haneda is assigned the code hnd, oookayama is assigned the code ooo, and tsu is assigned the code t.
However, with this code assignment method, the same code may be assigned even at airports with different names, which causes confusion. Given a list of airport names, determine if all airport codes can be different, find the minimum k that can make all airport codes different if possible, and if not possible. Create a program to convey this.
Input
The input consists of 100 or less datasets. Each dataset is given in the following format.
> n
> s1
> ...
> sn
The number of airports n (2 ≤ n ≤ 50) is given as an integer on the first line, and the name si of the airport is given as a string on each of the following n lines. Airport names consist only of lowercase English alphabets from'a'to'z', all with 1 to 50 characters. Also, the names of the airports given are all different. That is, when 1 ≤ i <j ≤ n, si ≠ sj is satisfied.
The end of the input is indicated by a line consisting of only one zero.
Output
For each dataset, if all airports can be assigned different airport codes, output such a minimum k on one line. If not possible, output -1 on one line.
Sample Input
3
haneda
oookayama
tsu
2
azusa
azishirabe
2
snuke
snake
Four
haneda
honda
hanamaki
hawaii
0
Output for Sample Input
1
Four
-1
3
Example
Input
3
haneda
oookayama
tsu
2
azusa
azishirabe
2
snuke
snake
4
haneda
honda
hanamaki
hawaii
0
Output
1
4
-1
3 | instruction | 0 | 79,886 | 18 | 159,772 |
"Correct Solution:
```
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
rr = []
while True:
n = I()
if n == 0:
break
a = [S() for _ in range(n)]
b = []
for s in a:
t = s[0]
for i in range(len(s)-1):
if s[i] in 'aiueo':
t += s[i+1]
b.append(t)
r = -1
for k in range(1,51):
s = set()
f = True
for t in b:
if t[:k] in s:
f = False
break
s.add(t[:k])
if f:
r = k
break
rr.append(r)
return '\n'.join(map(str, rr))
print(main())
``` | output | 1 | 79,886 | 18 | 159,773 |
Provide a correct Python 3 solution for this coding contest problem.
Airport Codes
Airport code
In the Kingdom of JAG, airport codes are assigned to each domestic airport for identification.
Airport codes are assigned according to the following rules based on the name of the airport in lowercase English alphabet:
1. Extract the first letter of the name and the letter immediately after the vowel (a, i, u, e, o) in order.
2. If the extracted character string is less than k characters, use it as the airport code, and if it is k characters or more, use the first k characters of the extracted character string as the airport code.
For example, when k = 3, haneda is assigned the code hnd, oookayama is assigned the code ooo, and tsu is assigned the code t.
However, with this code assignment method, the same code may be assigned even at airports with different names, which causes confusion. Given a list of airport names, determine if all airport codes can be different, find the minimum k that can make all airport codes different if possible, and if not possible. Create a program to convey this.
Input
The input consists of 100 or less datasets. Each dataset is given in the following format.
> n
> s1
> ...
> sn
The number of airports n (2 ≤ n ≤ 50) is given as an integer on the first line, and the name si of the airport is given as a string on each of the following n lines. Airport names consist only of lowercase English alphabets from'a'to'z', all with 1 to 50 characters. Also, the names of the airports given are all different. That is, when 1 ≤ i <j ≤ n, si ≠ sj is satisfied.
The end of the input is indicated by a line consisting of only one zero.
Output
For each dataset, if all airports can be assigned different airport codes, output such a minimum k on one line. If not possible, output -1 on one line.
Sample Input
3
haneda
oookayama
tsu
2
azusa
azishirabe
2
snuke
snake
Four
haneda
honda
hanamaki
hawaii
0
Output for Sample Input
1
Four
-1
3
Example
Input
3
haneda
oookayama
tsu
2
azusa
azishirabe
2
snuke
snake
4
haneda
honda
hanamaki
hawaii
0
Output
1
4
-1
3 | instruction | 0 | 79,887 | 18 | 159,774 |
"Correct Solution:
```
while True:
n = int(input())
if n==0:
break
s = []
maxlen = 0
for i in range(n):
st = input()
stt = ""
for j in range(len(st)):
if j==0 or st[j-1] in "aiueo":
stt += st[j]
s.append(stt)
maxlen = max(maxlen, len(stt))
ans = -1
k = 1
while k<=maxlen:
code = set()
for e in s:
code.add(e[:k])
if len(code)==len(s):
ans = k
break
k += 1
print(ans)
``` | output | 1 | 79,887 | 18 | 159,775 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.