A - Weak Beats

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

01 からなる長さ 16 の文字列 S が与えられます。

2 以上 16 以下のすべての偶数 i について Si 文字目が 0 ならば Yes を、 そうでないならば No を出力してください。

制約

  • S01 からなる長さ 16 の文字列

入力

入力は以下の形式で標準入力から与えられる。

S

出力

2 以上 16 以下のすべての偶数 i について Si 文字目が 0 ならば Yes を、 そうでないならば No を出力せよ。


入力例 1

1001000000001010

出力例 1

No

S= 10010000000010104 文字目が 1 であるため、No を出力します。


入力例 2

1010100000101000

出力例 2

Yes

S= 1010100000101000 の偶数番目の文字はすべて 0 であるため、Yes を出力します。


入力例 3

1111111111111111

出力例 3

No

S の偶数文字目はすべて 1 となっています。 特に「すべて 0 」ではないため、No を出力します。

Score : 100 points

Problem Statement

You are given a string S of length 16 consisting of 0 and 1.

If the i-th character of S is 0 for every even number i from 2 through 16, print Yes; otherwise, print No.

Constraints

  • S is a string of length 16 consisting of 0 and 1.

Input

The input is given from Standard Input in the following format:

S

Output

If the i-th character of S is 0 for every even number i from 2 through 16, print Yes; otherwise, print No.


Sample Input 1

1001000000001010

Sample Output 1

No

The 4-th character of S= 1001000000001010 is 1, so you should print No.


Sample Input 2

1010100000101000

Sample Output 2

Yes

Every even-positioned character in S= 1010100000101000 is 0, so you should print Yes.


Sample Input 3

1111111111111111

Sample Output 3

No

Every even-positioned character in S is 1. Particularly, they are not all 0, so you should print No.

B - Exponential or Quadratic

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

2^n \gt n^2 ですか?

制約

  • n1 以上 10^9 以下の整数

入力

入力は以下の形式で標準入力から与えられる。

n

出力

2^n \gt n^2 なら Yes を、そうでないなら No を出力せよ。


入力例 1

5

出力例 1

Yes

2^5=32,\ 5^2=25 より 2^n \gt n^2 であるため、Yes を出力します。


入力例 2

2

出力例 2

No

n=2 の場合 2^n=n^2=2^2 となり、故に 2^n \gt n^2 ではありません。よって No を出力します。


入力例 3

623947744

出力例 3

Yes

Score : 100 points

Problem Statement

Does 2^n \gt n^2 hold?

Constraints

  • n is an integer between 1 and 10^9 (inclusive).

Input

Input is given from Standard Input in the following format:

n

Output

If 2^n \gt n^2, print Yes; otherwise, print No.


Sample Input 1

5

Sample Output 1

Yes

Since 2^5=32,\ 5^2=25, we have 2^n \gt n^2, so Yes should be printed.


Sample Input 2

2

Sample Output 2

No

For n=2, we have 2^n=n^2=2^2, so 2^n \gt n^2 does not hold. Thus, No should be printed.


Sample Input 3

623947744

Sample Output 3

Yes
C - Caesar Cipher

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

高橋君は英小文字からなる文字列 S を持っています。

高橋君は文字列 S に対して、下記の操作をちょうど 1 回行います。

  • まず、非負整数 K を選ぶ。
  • その後、S の各文字を K 個後ろの英小文字に変更する。

ただし、

  • a1 個後ろの英小文字は b であり、
  • b1 個後ろの英小文字は c であり、
  • c1 個後ろの英小文字は d であり、
  • \cdots
  • y1 個後ろの英小文字は z であり、
  • z1 個後ろの英小文字は a です。

例えば、b4 個後ろの英小文字は f であり、y3 個後ろの英小文字は b です。

文字列 T が与えられます。 高橋君が上記の操作によって ST に一致させることができるかを判定してください。

制約

  • ST はそれぞれ英小文字からなる長さ 1 以上 10^5 以下の文字列
  • S の長さと T の長さは等しい

入力

入力は以下の形式で標準入力から与えられる。

S
T

出力

高橋君が ST に一致させることができる場合は Yes と出力し、 できない場合は No と出力せよ。


入力例 1

abc
ijk

出力例 1

Yes

高橋君が K=8 を選ぶと、

  • a8 個後ろの i
  • b8 個後ろの j
  • c8 個後ろの k

それぞれ変更され、ST が一致します。
高橋君が ST に一致させることができるため Yes と出力します。


入力例 2

z
a

出力例 2

Yes

高橋君が K=1 を選ぶと ST が一致します。
z1 個後ろの英小文字は a であることに注意してください。


入力例 3

ppq
qqp

出力例 3

No

高橋君は非負整数 K をどのように選んでも ST に一致させることができません。 よって、No と出力します。


入力例 4

atcoder
atcoder

出力例 4

Yes

高橋君が K=0 を選ぶと ST が一致します。

Score : 200 points

Problem Statement

Takahashi has a string S consisting of lowercase English letters.

On this string, he will do the operation below just once.

  • First, choose a non-negative integer K.
  • Then, shift each character of S to the right by K (see below).

Here,

  • a shifted to the right by 1 is b;
  • b shifted to the right by 1 is c;
  • c shifted to the right by 1 is d;
  • \cdots
  • y shifted to the right by 1 is z;
  • z shifted to the right by 1 is a.

For example, b shifted to the right by 4 is f, and y shifted to the right by 3 is b.

You are given a string T. Determine whether Takahashi can make S equal T by the operation above.

Constraints

  • Each of S and T is a string of length between 1 and 10^5 (inclusive) consisting of lowercase English letters.
  • The lengths of S and T are equal.

Input

Input is given from Standard Input in the following format:

S
T

Output

If Takahashi can make S equal T, print Yes; if not, print No.


Sample Input 1

abc
ijk

Sample Output 1

Yes

When Takahashi chooses K=8,

  • a is shifted to the right by 8 and becomes i,
  • b is shifted to the right by 8 and becomes j,
  • c is shifted to the right by 8 and becomes k,

and now S and T are equal.
Therefore, he can make S equal T, so Yes should be printed.


Sample Input 2

z
a

Sample Output 2

Yes

Choosing K=1 makes S and T equal.
Note that the letter on the right of z is a.


Sample Input 3

ppq
qqp

Sample Output 3

No

There is no non-negative integer K that he can choose to make S equal T, so No should be printed.


Sample Input 4

atcoder
atcoder

Sample Output 4

Yes

Choosing K=0 makes S and T equal.

D - Two Languages

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

AtCoder 国の公用語は、高橋語と青木語の 2 つの言語です。

高橋語と青木語は、どちらもその言語に含まれる単語を表記するのに英小文字の一部を使います。 高橋語では長さ N の文字列 S に含まれる文字のみを使い、青木語では長さ M の文字列 T に含まれる文字のみを使います。

AtCoder 国の公用語に含まれる Q 個の単語 w _ 1,w _ 2,\ldots,w _ Q が与えられます。 それぞれの単語について、その単語に含まれる文字からその単語が次のうちどれに該当するか判定してください。

  • 高橋語の単語であることが確定する
  • 青木語の単語であることが確定する
  • どちらともいえない

制約

  • 1\le N\le26
  • 1\le M\le26
  • S は英小文字からなる長さ N の文字列
  • S に含まれる文字は先頭からアルファベット順で昇順に並んでいる
  • S に含まれる文字はすべて異なる
  • T は英小文字からなる長さ M の文字列
  • T に含まれる文字は先頭からアルファベット順で昇順に並んでいる
  • T に含まれる文字はすべて異なる
  • 1\le Q\le100
  • w _ i は英小文字からなる長さ 1 以上 100 以下の文字列 (1\le i\le Q)
  • w _ i は高橋語か青木語のどちらかの単語 (1\le i\le Q)
  • N,M,Q は整数

入力

入力は以下の形式で標準入力から与えられる。

N M
S
T
Q
w _ 1
w _ 2
\vdots
w _ Q

出力

Q 行にわたって出力せよ。 i 行目には、w _ i が高橋語の単語であることが確定するなら Takahashi 、青木語の単語であることが確定するなら Aoki 、どちらとも確定しないなら Unknown と出力せよ。


入力例 1

6 5
ahikst
aikot
5
asahi
okita
kiai
hash
it

出力例 1

Takahashi
Aoki
Unknown
Takahashi
Unknown

例えば、a, s, h, i はすべて高橋語で使われる文字で、h は青木語で使われる文字ではないので asahi は高橋語の単語であることが確定します。 よって、1 行目には Takahashi と出力してください。

i および t はどちらも高橋語でも青木語でも使われる文字なので it は高橋語の単語であるとも青木語の単語であるとも確定しません。 よって、5 行目には Unknown と出力してください。


入力例 2

7 6
ahiknst
ahikos
5
kioki
ohiki
tashi
nishi
kashi

出力例 2

Aoki
Aoki
Takahashi
Takahashi
Unknown

o は高橋語で使われる文字ではないので、はじめ 2 つの単語は青木語の単語であることが確定します。 よって、1 行目と 2 行目には Aoki と出力してください。

tn は青木語で使われる文字ではないので、続く 2 つの単語は高橋語の単語であることが確定します。 よって、3 行目と 4 行目には Takahashi と出力してください。

はじめ 4 つの単語については、末尾が shi なら高橋語、末尾が ki なら青木語という法則がありますが、k, a, s, h, i はいずれも高橋語と青木語の両方で使われる文字なので kashi がどちらの言語の単語であるかを使われている文字から確定させることはできません。 よって、5 行目には Unknown と出力してください。


入力例 3

13 11
defghiqsvwxyz
acejmoqrtwx
15
qhsqzhd
jcareec
wwqxqew
wxqxwex
jxxrtwa
trtqjxe
sqyggse
xxqwxew
xewwxxw
wwqxwex
xqqxqwq
qxxexxe
teqeroc
eeeqqee
vxdevyy

出力例 3

Takahashi
Aoki
Unknown
Unknown
Aoki
Aoki
Takahashi
Unknown
Unknown
Unknown
Unknown
Unknown
Aoki
Unknown
Takahashi

Score : 200 points

Problem Statement

The AtCoder country has two official languages: Takahashi-go and Aoki-go.

Both Takahashi-go and Aoki-go use some lowercase English letters to write words in those languages. Takahashi-go uses only the characters contained in a string S of length N, and Aoki-go uses only the characters contained in a string T of length M.

You are given Q words w _ 1,w _ 2,\ldots,w _ Q that are in the official languages of the AtCoder country. For each word, determine which of the following applies based on the characters contained in that word:

  • It is confirmed to be a word in Takahashi-go
  • It is confirmed to be a word in Aoki-go
  • Neither can be determined

Constraints

  • 1\le N\le26
  • 1\le M\le26
  • S is a string of length N consisting of lowercase English letters.
  • The characters in S are arranged in alphabetical order.
  • All characters in S are distinct.
  • T is a string of length M consisting of lowercase English letters.
  • The characters in T are arranged in alphabetical order.
  • All characters in T are distinct.
  • 1\le Q\le100
  • w _ i is a string of length at least 1 and at most 100 consisting of lowercase English letters. (1\le i\le Q)
  • w _ i is a word in Takahashi-go or Aoki-go. (1\le i\le Q)
  • N,M,Q are integers.

Input

The input is given from Standard Input in the following format:

N M
S
T
Q
w _ 1
w _ 2
\vdots
w _ Q

Output

Print Q lines. The i-th line should contain Takahashi if it is confirmed that w _ i is a word in Takahashi-go, Aoki if it is confirmed to be a word in Aoki-go, and Unknown if neither can be determined.


Sample Input 1

6 5
ahikst
aikot
5
asahi
okita
kiai
hash
it

Sample Output 1

Takahashi
Aoki
Unknown
Takahashi
Unknown

For example, all of a, s, h, i are used in Takahashi-go, and h is not used in Aoki-go, so it is confirmed that asahi is a word in Takahashi-go. Thus, print Takahashi on the first line.

Both i and t are used in both Takahashi-go and Aoki-go, so it cannot be determined whether it is a word in Takahashi-go or Aoki-go. Thus, print Unknown on the fifth line.


Sample Input 2

7 6
ahiknst
ahikos
5
kioki
ohiki
tashi
nishi
kashi

Sample Output 2

Aoki
Aoki
Takahashi
Takahashi
Unknown

o is not used in Takahashi-go, so the first two words are confirmed to be words in Aoki-go. Thus, print Aoki on the first and second lines.

t and n are not used in Aoki-go, so the following two words are confirmed to be words in Takahashi-go. Thus, print Takahashi on the third and fourth lines.

For the first four words, there is a rule that words ending in shi are Takahashi-go, and words ending in ki are Aoki-go. However, all of k, a, s, h, i are used in both Takahashi-go and Aoki-go, so it is impossible to determine which language the word kashi belongs to based on the characters used. Thus, print Unknown on the fifth line.


Sample Input 3

13 11
defghiqsvwxyz
acejmoqrtwx
15
qhsqzhd
jcareec
wwqxqew
wxqxwex
jxxrtwa
trtqjxe
sqyggse
xxqwxew
xewwxxw
wwqxwex
xqqxqwq
qxxexxe
teqeroc
eeeqqee
vxdevyy

Sample Output 3

Takahashi
Aoki
Unknown
Unknown
Aoki
Aoki
Takahashi
Unknown
Unknown
Unknown
Unknown
Unknown
Aoki
Unknown
Takahashi
E - Many Replacement

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 350

問題文

英小文字からなる長さ N の文字列 S が与えられます。

文字列 S に対して操作を Q 回行います。 i 回目 (1\leq i\leq Q) の操作は文字の組 (c _ i,d _ i) で表され、次のような操作に対応します。

  • S に含まれる文字 c _ i をすべて文字 d _ i で置き換える。

すべての操作が終わったあとの文字列 S を出力してください。

制約

  • 1\leq N\leq2\times10^5
  • S は英小文字からなる長さ N の文字列
  • 1\leq Q\leq2\times10^5
  • c _ i,d _ i は英小文字 (1\leq i\leq Q)
  • N,Q は整数

入力

入力は以下の形式で標準入力から与えられる。

N
S
Q
c _ 1 d _ 1
c _ 2 d _ 2
\vdots
c _ Q d _ Q

出力

すべての操作が終わったあとの S を出力せよ。


入力例 1

7
atcoder
4
r a
t e
d v
a r

出力例 1

recover

Satcoderatcodeaaecodeaaecovearecover と変化します。 たとえば、4 番目の操作では S={}aecovea に含まれる a1 文字目と 7 文字目)をすべて r に置き換えるので S={}recover となります。

すべての操作が終わったときには S={}recover となっているため、recover を出力してください。


入力例 2

3
abc
4
a a
s k
n n
z b

出力例 2

abc

c _ i=d _ i であるような操作や Sc _ i が含まれないような操作もあります。


入力例 3

34
supercalifragilisticexpialidocious
20
g c
l g
g m
c m
r o
s e
a a
o f
f s
e t
t l
d v
p k
v h
x i
h n
n j
i r
s i
u a

出力例 3

laklimamriiamrmrllrmlrkramrjimrial

Score: 350 points

Problem Statement

You are given a string S of length N consisting of lowercase English letters.

You will perform an operation Q times on the string S. The i-th operation (1\leq i\leq Q) is represented by a pair of characters (c _ i,d _ i), which corresponds to the following operation:

  • Replace all occurrences of the character c _ i in S with the character d _ i.

Print the string S after all operations are completed.

Constraints

  • 1\leq N\leq2\times10^5
  • S is a string of length N consisting of lowercase English letters.
  • 1\leq Q\leq2\times10^5
  • c _ i and d _ i are lowercase English letters (1\leq i\leq Q).
  • N and Q are integers.

Input

The input is given from Standard Input in the following format:

N
S
Q
c _ 1 d _ 1
c _ 2 d _ 2
\vdots
c _ Q d _ Q

Output

Print the string S after all operations are completed.


Sample Input 1

7
atcoder
4
r a
t e
d v
a r

Sample Output 1

recover

S changes as follows: atcoderatcodeaaecodeaaecovearecover. For example, in the fourth operation, all occurrences of a in S={}aecovea (the first and seventh characters) are replaced with r, resulting in S={}recover.

After all operations are completed, S={}recover, so print recover.


Sample Input 2

3
abc
4
a a
s k
n n
z b

Sample Output 2

abc

There may be operations where c _ i=d _ i or S does not contain c _ i.


Sample Input 3

34
supercalifragilisticexpialidocious
20
g c
l g
g m
c m
r o
s e
a a
o f
f s
e t
t l
d v
p k
v h
x i
h n
n j
i r
s i
u a

Sample Output 3

laklimamriiamrmrllrmlrkramrjimrial