実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
N 問の問題からなるコンテストが開催され、i\ (1\leq i\leq N) 問目の配点は A_i 点でした。
すぬけくんはこのコンテストに参加し、B_1,B_2,\ldots,B_M 問目の M 問を解きました。 すぬけくんの総得点を求めてください。
ただし、総得点とは解いた問題の配点の総和を意味するものとします。
制約
- 1\leq M \leq N \leq 100
- 1\leq A_i \leq 100
- 1\leq B_1 < B_2 < \ldots < B_M \leq N
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 A_2 \dots A_N B_1 B_2 \dots B_M
出力
答えを整数として出力せよ。
入力例 1
3 2 10 20 30 1 3
出力例 1
40
すぬけくんは 1 問目と 3 問目を解きました。 配点はそれぞれ 10 点と 30 点なので、総得点は 10+30=40 点です。
入力例 2
4 1 1 1 1 100 4
出力例 2
100
入力例 3
8 4 22 75 26 45 72 81 47 29 4 6 7 8
出力例 3
202
Score : 100 points
Problem Statement
There was a contest with N problems. The i-th (1\leq i\leq N) problem was worth A_i points.
Snuke took part in this contest and solved M problems: the B_1-th, B_2-th, \ldots, and B_M-th ones. Find his total score.
Here, the total score is defined as the sum of the points for the problems he solved.
Constraints
- 1\leq M \leq N \leq 100
- 1\leq A_i \leq 100
- 1\leq B_1 < B_2 < \ldots < B_M \leq N
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N M A_1 A_2 \dots A_N B_1 B_2 \dots B_M
Output
Print the answer as an integer.
Sample Input 1
3 2 10 20 30 1 3
Sample Output 1
40
Snuke solved the 1-st and 3-rd problems, which are worth 10 and 30 points, respectively. Thus, the total score is 10+30=40 points.
Sample Input 2
4 1 1 1 1 100 4
Sample Output 2
100
Sample Input 3
8 4 22 75 26 45 72 81 47 29 4 6 7 8
Sample Output 3
202
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 100 点
問題文
下の画像で示す図において、a 番の点と b 番の点が線で直接結ばれているかを答えてください。

制約
- 1 \leq a \lt b \leq 10
- a, b は整数
入力
入力は以下の形式で標準入力から与えられる。
a b
出力
a 番の点と b 番の点が線で直接結ばれている場合は Yes を出力し、結ばれていない場合は No を出力せよ。
ジャッジは英大文字と英小文字を厳密に区別することに注意せよ。
入力例 1
4 5
出力例 1
Yes
問題文で示した図において、4 番の点と 5 番の点は線で直接結ばれています。
よって、Yes を出力します。
入力例 2
3 5
出力例 2
No
問題文で示した図において、3 番の点と 5 番の点は線で直接結ばれていません。
よって、No を出力します。
入力例 3
1 10
出力例 3
Yes
Score : 100 points
Problem Statement
In the figure shown in the image below, are the points numbered a and b directly connected by a line segment?

Constraints
- 1 \leq a \lt b \leq 10
- a and b are integers.
Input
Input is given from Standard Input in the following format:
a b
Output
If the points numbered a and b are directly connected by a line segment, print Yes; otherwise, print No.
The judge is case-sensitive: be sure to print uppercase and lowercase letters correctly.
Sample Input 1
4 5
Sample Output 1
Yes
In the figure shown in the Problem Statement, the points numbered 4 and 5 are directly connected by a line segment.
Thus, Yes should be printed.
Sample Input 2
3 5
Sample Output 2
No
In the figure shown in the Problem Statement, the points numbered 3 and 5 are not directly connected by a line segment.
Thus, No should be printed.
Sample Input 3
1 10
Sample Output 3
Yes
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
直線上に 7 個の点 A, B, C, D, E, F, G がこの順に並んでいます。(下の図も参考にしてください)
隣り合う点の距離は次の通りです。
- 点 A と点 B の距離は 3
- 点 B と点 C の距離は 1
- 点 C と点 D の距離は 4
- 点 D と点 E の距離は 1
- 点 E と点 F の距離は 5
- 点 F と点 G の距離は 9

2 つの英大文字 p, q が与えられます。p, q は A,B,C,D,E,F,G のいずれかで、 p \neq q が成り立ちます。
点 p と点 q の間の距離を答えてください。
制約
- p, q は
A,B,C,D,E,F,Gのいずれか - p \neq q
入力
入力は以下の形式で標準入力から与えられる。
p q
出力
点 p と点 q の間の距離を出力せよ。
入力例 1
A C
出力例 1
4
点 A と点 C の距離は 3 + 1 = 4 です。
入力例 2
G B
出力例 2
20
点 G と点 B の距離は 9 + 5 + 1 + 4 + 1 = 20 です。
入力例 3
C F
出力例 3
10
Score : 200 points
Problem Statement
There are 7 points A, B, C, D, E, F, and G on a straight line, in this order. (See also the figure below.)
The distances between adjacent points are as follows.
- Between A and B: 3
- Between B and C: 1
- Between C and D: 4
- Between D and E: 1
- Between E and F: 5
- Between F and G: 9

You are given two uppercase English letters p and q. Each of p and q is A, B, C, D, E, F, or G, and it holds that p \neq q.
Find the distance between the points p and q.
Constraints
- Each of p and q is
A,B,C,D,E,F, orG. - p \neq q
Input
The input is given from Standard Input in the following format:
p q
Output
Print the distance between the points p and q.
Sample Input 1
A C
Sample Output 1
4
The distance between the points A and C is 3 + 1 = 4.
Sample Input 2
G B
Sample Output 2
20
The distance between the points G and B is 9 + 5 + 1 + 4 + 1 = 20.
Sample Input 3
C F
Sample Output 3
10
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
ある日、高橋くんはあるウェブサイトに対して N 回の操作を行いました。
i 回目 (1\leq i\leq N) の操作は文字列 S _ i で表され、次の 4 つのうちいずれかです。
- S _ i=
loginである。高橋くんはログイン操作を行い、高橋くんがウェブサイトにログインした状態になる。 - S _ i=
logoutである。高橋くんはログアウト操作を行い、高橋くんがウェブサイトにログインしていない状態になる。 - S _ i=
publicである。高橋くんはウェブサイトの公開ページにアクセスする。 - S _ i=
privateである。高橋くんはウェブサイトの非公開ページにアクセスする。
高橋くんがログインしていない状態で非公開ページにアクセスした時、またその時に限り、ウェブサイトは認証エラーを返します。
ログインした状態でさらにログイン操作をしたり、ログインしていない状態でさらにログアウト操作をしてもエラーにはなりません。 また、認証エラーが返されたあとも、高橋くんは操作を続けることができます。
はじめ、高橋くんはログインしていない状態です。
N 回の操作のうち、高橋くんが認証エラーを受け取った回数を出力してください。
制約
- 1\leq N\leq100
- N は整数
- S _ i は
login,logout,public,privateのいずれか (1\leq i\leq N)
入力
入力は以下の形式で標準入力から与えられる。
N S _ 1 S _ 2 \vdots S _ N
出力
高橋くんが認証エラーを受け取った回数を出力せよ。
入力例 1
6 login private public logout private public
出力例 1
1
高橋くんが行うそれぞれの操作の結果は以下のようになります。
- 高橋くんがウェブサイトにログインした状態になる。
- 高橋くんは非公開ページにアクセスする。高橋くんは現在ログインしているので、エラーは返されない。
- 高橋くんは公開ページにアクセスする。
- 高橋くんがウェブサイトにログインしていない状態になる。
- 高橋くんは非公開ページにアクセスする。高橋くんは現在ログインしていないので、認証エラーが返される。
- 高橋くんは公開ページにアクセスする。
高橋くんが認証エラーを受け取るのは 5 回目の操作のみなので、1 を出力してください。
入力例 2
4 private private private logout
出力例 2
3
連続で非公開ページにアクセスしようとした場合、操作のたびに認証エラーを受け取ります。
ログインしていない状態からさらにログアウト操作をした場合には認証エラーは返されないことに注意してください。
入力例 3
20 private login private logout public logout logout logout logout private login login private login private login public private logout private
出力例 3
3
Score : 200 points
Problem Statement
One day, Takahashi performed N operations on a certain web site.
The i‑th operation (1 \le i \le N) is represented by a string S_i, which is one of the following:
- S _ i=
login: He performs a login operation and becomes logged in to the site. - S _ i=
logout: He performs a logout operation and becomes not logged in to the site. - S _ i=
public: He accesses a public page of the site. - S _ i=
private: He accesses a private page of the site.
The site returns an authentication error if and only if he accesses a private page while he is not logged in.
Logging in again while already logged in, or logging out again while already logged out, does not cause an error. Even after an authentication error is returned, he continues performing the remaining operations.
Initially, he is not logged in.
Print the number of operations among the N operations at which he receives an authentication error.
Constraints
- 1 \le N \le 100
- N is an integer.
- Each S_i is one of
login,logout,public,private. (1 \le i \le N)
Input
The input is given from Standard Input in the following format:
N S_1 S_2 \vdots S_N
Output
Print the number of times Takahashi receives an authentication error.
Sample Input 1
6 login private public logout private public
Sample Output 1
1
The result of each operation is as follows:
- Takahashi becomes logged in.
- He accesses a private page. He is logged in, so no error is returned.
- He accesses a public page.
- He becomes logged out.
- He accesses a private page. He is not logged in, so an authentication error is returned.
- He accesses a public page.
An authentication error occurs only at the 5th operation, so print 1.
Sample Input 2
4 private private private logout
Sample Output 2
3
If he tries to access private pages consecutively while not logged in, he receives an authentication error for each such operation.
Note that logging out again while already logged out does not cause an authentication error.
Sample Input 3
20 private login private logout public logout logout logout logout private login login private login private login public private logout private
Sample Output 3
3
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 300 点
問題文
10 進法で表記したときに 0,2 のみからなる正整数のうち、 K 番目に小さいものを求めてください。
制約
- K は 1 以上 10^{18} 以下の整数
入力
入力は以下の形式で標準入力から与えられる。
K
出力
答えを整数として出力せよ。
ただし、たとえ答えが大きな整数であっても、求める答えを正確に整数として出力する必要がある。たとえば、 2.34e+22 のような指数表記や、 0523 のような先頭に不要な 0 を付けたような表記は許されない。
入力例 1
3
出力例 1
22
10 進法で表記した時に 0,2 のみからなる正整数を小さい方から並べると、 2,20,22,\dots となります。
このうち K=3 番目である 22 を出力してください。
入力例 2
11
出力例 2
2022
入力例 3
923423423420220108
出力例 3
220022020000202020002022022000002020002222002200002022002200
たとえ答えが大きな整数であっても、求める答えを正確に整数として出力する必要があることに注意してください。
Score : 300 points
Problem Statement
Among the positive integers that consist of 0's and 2's when written in base 10, find the K-th smallest integer.
Constraints
- K is an integer between 1 and 10^{18} (inclusive).
Input
Input is given from Standard Input in the following format:
K
Output
Print the answer as an integer.
Here, the exact value must be printed as an integer, even if it is big. Exponential notations such as 2.34e+22, for example, or unnecessary leading zeros such as 0523 are not allowed.
Sample Input 1
3
Sample Output 1
22
The positive integers that consist of 0's and 2's when written in base 10 are 2,20,22,\dots in ascending order.
The (K=) 3-rd of them, which is 22, should be printed.
Sample Input 2
11
Sample Output 2
2022
Sample Input 3
923423423420220108
Sample Output 3
220022020000202020002022022000002020002222002200002022002200
Note that the exact value of the answer must be printed as an integer, even if it is big.