Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
ある日、高橋君は A 時 B 分ちょうどに、青木君は C 時 D 分 1 秒に起きました。
高橋君の起床時刻が青木君より早いならば Takahashi を、そうでないならば Aoki を出力してください。
制約
- 0 \leq A \leq 23
- 0 \leq B \leq 59
- 0 \leq C \leq 23
- 0 \leq D \leq 59
- 入力はすべて整数である。
入力
入力は以下の形式で標準入力から与えられる。
A B C D
出力
高橋君の起床時刻が青木君より早いならば Takahashi を、そうでないならば Aoki を出力せよ。
入力例 1
7 0 6 30
出力例 1
Aoki
高橋君は 7 時ちょうどに、青木君は 6 時 30 分 1 秒に起きました。
青木君の起床時刻の方が早いため、Aoki を出力します。
入力例 2
7 30 7 30
出力例 2
Takahashi
高橋君は 7 時 30 分ちょうどに、青木君は 7 時 30 分 1 秒に起きました。
高橋君の起床時刻の方が 1 秒だけ早いため、Takahashi を出力します。
入力例 3
0 0 23 59
出力例 3
Takahashi
ある日の 0 時 0 分ちょうどはその日の 0 時 1 分の 1 分前であり、
その日の 23 時 59 分の 1 分後、すなわちいわゆる 24 時ちょうどのことではありません。
よって、高橋君の起床時刻の方が早く、Takahashi を出力します。
Score : 100 points
Problem Statement
One day, Takahashi got up at exactly B minutes past A o'clock (in 24-hour clock), and Aoki got up at exactly D minutes and 1 second past C o'clock.
If Takahashi got up earlier than Aoki, print Takahashi; otherwise, print Aoki.
Constraints
- 0 \leq A \leq 23
- 0 \leq B \leq 59
- 0 \leq C \leq 23
- 0 \leq D \leq 59
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
A B C D
Output
If Takahashi got up earlier than Aoki, print Takahashi; otherwise, print Aoki.
Sample Input 1
7 0 6 30
Sample Output 1
Aoki
Takahashi got up at 7 sharp, and Aoki got up at 30 minutes and 1 second past 6 o'clock.
Aoki was the first to get up, so Aoki should be printed.
Sample Input 2
7 30 7 30
Sample Output 2
Takahashi
Takahashi got up at exactly half past 7, and Aoki got up at 30 minutes and 1 second past 7 o'clock.
Just by one second, Takahashi was the first to get up, so Takahashi should be printed.
Sample Input 3
0 0 23 59
Sample Output 3
Takahashi
0:00 in a day is one minute before 0:01, not one minute past 23:59 ("24:00").
Thus, Takahashi was the first to get up, so Takahashi should be printed.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
N 問の問題が出題されるプログラミングコンテストがあります。 i = 1, 2, \ldots, N について、i 問目の配点は S_i です。
配点が X 以下である問題すべての配点の合計を出力してください。
制約
- 入力される値は全て整数
- 4 \leq N \leq 8
- 100 \leq S_i \leq 675
- 100 \leq X \leq 675
入力
入力は以下の形式で標準入力から与えられる。
N X S_1 S_2 \ldots S_N
出力
答えを出力せよ。
入力例 1
6 200 100 675 201 200 199 328
出力例 1
499
配点が 200 以下である問題は、1, 4, 5 問目の全 3 問であり、それらの配点の合計は S_1 + S_4 + S_5 = 100 + 200 + 199 = 499 です。
入力例 2
8 675 675 675 675 675 675 675 675 675
出力例 2
5400
入力例 3
8 674 675 675 675 675 675 675 675 675
出力例 3
0
Score : 100 points
Problem Statement
There is a programming contest with N problems. For each i = 1, 2, \ldots, N, the score for the i-th problem is S_i.
Print the total score for all problems with a score of X or less.
Constraints
- All input values are integers.
- 4 \leq N \leq 8
- 100 \leq S_i \leq 675
- 100 \leq X \leq 675
Input
The input is given from Standard Input in the following format:
N X S_1 S_2 \ldots S_N
Output
Print the answer.
Sample Input 1
6 200 100 675 201 200 199 328
Sample Output 1
499
Three problems have a score of 200 or less: the first, fourth, and fifth, for a total score of S_1 + S_4 + S_5 = 100 + 200 + 199 = 499.
Sample Input 2
8 675 675 675 675 675 675 675 675 675
Sample Output 2
5400
Sample Input 3
8 674 675 675 675 675 675 675 675 675
Sample Output 3
0
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
非負整数 A,B,C,D,E,F があり、A\times B\times C\geq D\times E\times F をみたしています。
(A\times B\times C)-(D\times E\times F) の値を 998244353 で割った余りを求めてください。
制約
- 0\leq A,B,C,D,E,F\leq 10^{18}
- A\times B\times C\geq D\times E\times F
- A,B,C,D,E,F は整数
入力
入力は以下の形式で標準入力から与えられる。
A B C D E F
出力
(A\times B\times C)-(D\times E\times F) を 998244353 で割った余りを整数で出力せよ。
入力例 1
2 3 5 1 2 4
出力例 1
22
A\times B\times C=2\times 3\times 5=30, D\times E\times F=1\times 2\times 4=8 より、
(A\times B\times C)-(D\times E\times F)=22 であり、これを 998244353 で割った余りである 22 を出力します。
入力例 2
1 1 1000000000 0 0 0
出力例 2
1755647
A\times B\times C=1000000000, D\times E\times F=0 より、
(A\times B\times C)-(D\times E\times F)=1000000000 であり、これを 998244353 で割った余りである 1755647 を出力します。
入力例 3
1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000
出力例 3
0
(A\times B\times C)-(D\times E\times F)=0 であり、これを 998244353 で割った余りである 0 を出力します。
Score : 200 points
Problem Statement
There are non-negative integers A, B, C, D, E, and F, which satisfy A\times B\times C\geq D\times E\times F.
Find the remainder when (A\times B\times C)-(D\times E\times F) is divided by 998244353.
Constraints
- 0\leq A,B,C,D,E,F\leq 10^{18}
- A\times B\times C\geq D\times E\times F
- A, B, C, D, E, and F are integers.
Input
The input is given from Standard Input in the following format:
A B C D E F
Output
Print the remainder when (A\times B\times C)-(D\times E\times F) is divided by 998244353, as an integer.
Sample Input 1
2 3 5 1 2 4
Sample Output 1
22
Since A\times B\times C=2\times 3\times 5=30 and D\times E\times F=1\times 2\times 4=8,
we have (A\times B\times C)-(D\times E\times F)=22. Divide this by 998244353 and print the remainder, which is 22.
Sample Input 2
1 1 1000000000 0 0 0
Sample Output 2
1755647
Since A\times B\times C=1000000000 and D\times E\times F=0,
we have (A\times B\times C)-(D\times E\times F)=1000000000. Divide this by 998244353 and print the remainder, which is 1755647.
Sample Input 3
1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000
Sample Output 3
0
We have (A\times B\times C)-(D\times E\times F)=0. Divide this by 998244353 and print the remainder, which is 0.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
N 人の学生が試験を受けました。学生には学生 1, 学生 2, \dots, 学生 N と番号がついていて、学生 i は a_i 点を取りました。
P 点未満の点数を取った学生は "不可" となり単位を取得できません。 "不可" となった学生の人数を答えてください。
制約
- 1 \leq N \leq 10^5
- 1 \leq P \leq 100
- 0 \leq a_i \leq 100 (1 \leq i \leq N)
- 入力はすべて整数である。
入力
入力は以下の形式で標準入力から与えられる。
N P a_1 a_2 \dots a_N
出力
"不可" となった学生の人数を出力せよ。
入力例 1
4 50 80 60 40 0
出力例 1
2
学生 1 は 80 点、学生 2 は 60 点と、 50 点以上の点数を取っているので "不可" とならず単位を取得できています。
一方、学生 3 は 40 点、学生 4 は 0 点で、 50 点を下回る点数を取っているので "不可" となります。よって答えは 2 人です。
入力例 2
3 90 89 89 89
出力例 2
3
入力例 3
2 22 6 37
出力例 3
1
Score : 200 points
Problem Statement
N students took an exam. The students are labeled as Student 1, Student 2, \dots, Student N, and Student i scored a_i points.
A student who scored less than P points are considered to have failed the exam and cannot earn the credit. Find the number of students who failed the exam.
Constraints
- 1 \leq N \leq 10^5
- 1 \leq P \leq 100
- 0 \leq a_i \leq 100 (1 \leq i \leq N)
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N P a_1 a_2 \dots a_N
Output
Print the number of students who failed the exam.
Sample Input 1
4 50 80 60 40 0
Sample Output 1
2
Students 1 and 2, who scored 80 and 60 points, respectively, succeeded in scoring at least 50 points to earn the credit.
On the other hand, Students 3 and 4, who scored 40 and 0 points, respectively, fell below 50 points and failed the exam. Thus, the answer is 2.
Sample Input 2
3 90 89 89 89
Sample Output 2
3
Sample Input 3
2 22 6 37
Sample Output 3
1
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
高橋君と青木君は、それぞれ N 個のボールに M 本のひもを取り付けたおもちゃを持っています。
高橋君のおもちゃにおいて、ボールには 1, \dots, N と番号が付けられており、i \, (1 \leq i \leq M) 本目のひもはボール A_i とボール B_i を結んでいます。
青木君のおもちゃにおいても同様に、ボールには 1, \dots, N と番号が付けられており、i \, (1 \leq i \leq M) 本目のひもはボール C_i とボール D_i を結んでいます。
それぞれのおもちゃにおいて、同一のボールを結ぶようなひもは存在せず、2 つのボールを 2 本以上の異なるひもが結んでいることはありません。
すぬけ君は、2 人のおもちゃが同じ形であるかどうか気になっています。
ここで、2 人のおもちゃが同じ形であるとは、以下の条件を満たす数列 P が存在することをいいます。
- P は (1, \dots, N) を並べ替えて得られる。
- 任意の 1 以上 N 以下の整数 i, j に対し、以下が成り立つ。
- 高橋君のおもちゃにおいてボール i, j がひもで繋がれていることと、青木君のおもちゃにおいてボール P_i, P_j がひもで繋がれていることは同値である。
2 人のおもちゃが同じ形であるなら Yes、そうでないなら No と出力してください。
制約
- 1 \leq N \leq 8
- 0 \leq M \leq \frac{N(N - 1)}{2}
- 1 \leq A_i \lt B_i \leq N \, (1 \leq i \leq M)
- (A_i, B_i) \neq (A_j, B_j) \, (i \neq j)
- 1 \leq C_i \lt D_i \leq N \, (1 \leq i \leq M)
- (C_i, D_i) \neq (C_j, D_j) \, (i \neq j)
- 入力は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 B_1 \vdots A_M B_M C_1 D_1 \vdots C_M D_M
出力
2 人のおもちゃが同じ形であるなら Yes、そうでないなら No と出力せよ。
入力例 1
4 4 1 2 1 3 1 4 3 4 1 3 1 4 2 3 3 4
出力例 1
Yes
高橋君のおもちゃは下図の左側のような形をしており、青木君のおもちゃは下図の右側のような形をしています。

次の図から、2 人のおもちゃが同じ形であることがわかります。例えば P = (3, 2, 1, 4) とすると問題文中の条件を満たします。

入力例 2
5 6 1 2 1 3 1 4 3 4 3 5 4 5 1 2 1 3 1 4 1 5 3 5 4 5
出力例 2
No
2 人のおもちゃは同じ形ではありません。

入力例 3
8 0
出力例 3
Yes
Score : 300 points
Problem Statement
Takahashi and Aoki each have a toy made by attaching M cords to N balls.
In Takahashi's toy, the balls are numbered 1, \dots, N, and the i-th cord ties Ball A_i and B_i.
Similarly, in Aoki's toy, the balls are numbered 1, \dots, N, and the i-th cord ties Ball C_i and D_i.
In each toy, no cord ties a ball to itself, and no two balls are tied by two or more different cords.
Snuke is wondering whether the two toys have the same shape.
Here, they are said to have the same shape when there is a sequence P that satisfies the conditions below.
- P is a permutation of (1, \dots, N).
- For every pair of integers i, j between 1 and N (inclusive), the following holds.
- Balls i and j in Takahashi's toy are tied by a cord if and only if Balls P_i and P_j in Aoki's toy are tied by a cord.
If the two toys have the same shape, print Yes; otherwise, print No.
Constraints
- 1 \leq N \leq 8
- 0 \leq M \leq \frac{N(N - 1)}{2}
- 1 \leq A_i \lt B_i \leq N \, (1 \leq i \leq M)
- (A_i, B_i) \neq (A_j, B_j) \, (i \neq j)
- 1 \leq C_i \lt D_i \leq N \, (1 \leq i \leq M)
- (C_i, D_i) \neq (C_j, D_j) \, (i \neq j)
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M A_1 B_1 \vdots A_M B_M C_1 D_1 \vdots C_M D_M
Output
If the two toys have the same shape, print Yes; otherwise, print No.
Sample Input 1
4 4 1 2 1 3 1 4 3 4 1 3 1 4 2 3 3 4
Sample Output 1
Yes
Takahashi's toy is illustrated on the left in the figure below, and Aoki's is illustrated on the right.

The following figure shows that the two toys have the same shape. The condition in the statement is satisfied when P = (3, 2, 1, 4), for example.

Sample Input 2
5 6 1 2 1 3 1 4 3 4 3 5 4 5 1 2 1 3 1 4 1 5 3 5 4 5
Sample Output 2
No
The two toys do not have the same shape.

Sample Input 3
8 0
Sample Output 3
Yes
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
非負整数 n が次の条件を満たすとき、n を 良い整数 と呼びます。
- n を 10 進法で表したときに、偶数の数字 (0, 2, 4, 6, 8) のみが登場する。
例えば 0、68 および 2024 は良い整数です。
整数 N が与えられます。良い整数のうち小さい方から N 番目の整数を求めてください。
制約
- 1 \leq N \leq 10^{12}
- N は整数
入力
入力は以下の形式で標準入力から与えられる。
N
出力
小さい方から N 番目の良い整数を出力せよ。
入力例 1
8
出力例 1
24
良い整数を小さい方から順に並べると 0, 2, 4, 6, 8, 20, 22, 24, 26, 28, \dots となります。
小さい方から 8 番目の良い整数は 24 なので、これを出力します。
入力例 2
133
出力例 2
2024
入力例 3
31415926535
出力例 3
2006628868244228
Score: 300 points
Problem Statement
A non-negative integer n is called a good integer when it satisfies the following condition:
- All digits in the decimal notation of n are even numbers (0, 2, 4, 6, and 8).
For example, 0, 68, and 2024 are good integers.
You are given an integer N. Find the N-th smallest good integer.
Constraints
- 1 \leq N \leq 10^{12}
- N is an integer.
Input
The input is given from Standard Input in the following format:
N
Output
Print the N-th smallest good integer.
Sample Input 1
8
Sample Output 1
24
The good integers in ascending order are 0, 2, 4, 6, 8, 20, 22, 24, 26, 28, \dots.
The eighth smallest is 24, which should be printed.
Sample Input 2
133
Sample Output 2
2024
Sample Input 3
31415926535
Sample Output 3
2006628868244228
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
この問題は インタラクティブな問題(あなたが作成したプログラムとジャッジプログラムが標準入出力を介して対話を行う形式の問題)です。
ジャッジが 0 と 1 のみからなる長さ N の文字列 S = S_1S_2\ldots S_N を持っています。 文字列 S は、S_1 = 0 および S_N = 1 を満たします。
あなたには S の長さ N が与えられますが、S 自体は与えられません。 その代わり、あなたはジャッジに対して以下の質問を 20 回まで行うことができます。
- 1 \leq i \leq N を満たす整数 i を選び、S_i の値を尋ねる。
1 \leq p \leq N-1 かつ S_p \neq S_{p+1} を満たす整数 p を 1 個出力してください。
なお、本問題の条件下でそのような整数 p が必ず存在することが示せます。
制約
- 2 \leq N \leq 2 \times 10^5
入出力
最初に、文字列 S の長さ N を標準入力から受け取ってください。
N
次に、あなたはジャッジに対して問題文中の質問を 20 回まで繰り返すことができます。
質問は、以下の形式で標準出力に出力してください。 ここで、i は 1 \leq i \leq N を満たす整数でなければなりません。
? i
これに対する応答として、S_i の値が次の形式で標準入力から与えられます。
S_i
ここで、S_i は 0 または 1 です。
問題文中の条件を満たす整数 p を見つけたら、解答を以下の形式で出力してください。 その後、ただちにプログラムを終了してください。
! p
答えが複数ある場合、どれを出力しても正解とみなされます。
注意点
- 出力を行うたびに、末尾に改行を入れて標準出力を flush してください。そうしなかった場合、ジャッジ結果が TLE となる可能性があります。
- 対話の途中で不正な出力を行った、あるいはプログラムが途中で終了した場合のジャッジ結果は不定です。
- 解答を出力したらただちにプログラムを終了してください。そうしない場合、ジャッジ結果は不定です。
- 文字列 S はあなたとジャッジの対話の開始時に固定され、あなたが行った質問などに応じて変更されることはありません。
入出力例
以下は、N = 7, S = 0010011 の場合の入出力例です。
| 入力 | 出力 | 説明 |
|---|---|---|
7 |
N が与えられます。 | |
? 1 |
S_1 が何かをジャッジに質問します。 | |
0 |
質問に対する答えとして S_1 = 0 がジャッジから返されます。 | |
? 6 |
S_6 が何かをジャッジに質問します。 | |
1 |
質問に対する答えとして S_6 = 1 がジャッジから返されます。 | |
? 5 |
S_5 が何かをジャッジに質問します。 | |
0 |
質問に対する答えとして S_5 = 0 がジャッジから返されます。 | |
! 5 |
問題文中の条件を満たす整数 p として、p = 5 を解答します。 | |
解答した p = 5 について、1 \leq p \leq N-1 かつ S_p \neq S_{p+1} が成り立ちます。 よって、この後ただちにプログラムを終了することで、正解と判定されます。
Score : 400 points
Problem Statement
This is an interactive task, where your program and the judge interact via Standard Input and Output.
The judge has a string of length N consisting of 0 and 1: S = S_1S_2\ldots S_N. Here, S_1 = 0 and S_N = 1.
You are given the length N of S, but not the contents of S. Instead, you can ask the judge at most 20 questions as follows.
- Choose an integer i such that 1 \leq i \leq N and ask the value of S_i.
Print an integer p such that 1 \leq p \leq N-1 and S_p \neq S_{p+1}.
It can be shown that such p always exists under the settings of this problem.
Constraints
- 2 \leq N \leq 2 \times 10^5
Input and Output
First, receive the length N of the string S from Standard Input:
N
Then, you get to ask the judge at most 20 questions as described in the problem statement.
Print each question to Standard Output in the following format, where i is an integer satisfying 1 \leq i \leq N:
? i
In response to this, the value of S_i will be given from Standard Input in the following format:
S_i
Here, S_i is 0 or 1.
When you find an integer p satisfying the condition in the problem statement, print it in the following format, and immediately quit the program:
! p
If multiple solutions exist, you may print any of them.
Notes
- Print a newline and flush Standard Output at the end of each message. Otherwise, you may get a TLE verdict.
- If there is malformed output during the interaction or your program quits prematurely, the verdict will be indeterminate.
- After printing the answer, immediately quit the program. Otherwise, the verdict will be indeterminate.
- The string S will be fixed at the start of the interaction and will not be changed according to your questions or other factors.
Sample Input and Output
In the following interaction, N = 7 and S = 0010011.
| Input | Output | Description |
|---|---|---|
7 |
N is given. | |
? 1 |
Ask the value of S_1. | |
0 |
The judge responds with S_1 = 0. | |
? 6 |
Ask the value of S_6. | |
1 |
The judge responds with S_6 = 1. | |
? 5 |
Ask the value of S_5. | |
0 |
The judge responds with S_5 = 0. | |
! 5 |
Present p = 5 as an integer satisfying the condition. | |
For the presented p = 5, we have 1 \leq p \leq N-1 and S_p \neq S_{p+1}. Thus, if the program immediately quits here, this case will be judged as correctly solved.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
3 次元空間内に N 個の直方体があります。
直方体同士は重なっていません。厳密には、相異なるどの 2 つの直方体の共通部分の体積も 0 です。
i 番目の直方体は、2 点 (X_{i,1},Y_{i,1},Z_{i,1}), (X_{i,2},Y_{i,2},Z_{i,2}) を結ぶ線分を対角線とし、辺は全ていずれかの座標軸に平行です。
各直方体について、他のいくつの直方体と面で接しているか求めてください。
厳密には、各 i に対し、1\leq j \leq N かつ j\neq i である j のうち、i 番目の直方体の表面と j 番目の直方体の表面の共通部分の面積が正であるものの個数を求めてください。
制約
- 1 \leq N \leq 10^5
- 0 \leq X_{i,1} < X_{i,2} \leq 100
- 0 \leq Y_{i,1} < Y_{i,2} \leq 100
- 0 \leq Z_{i,1} < Z_{i,2} \leq 100
- 直方体同士は体積が正の共通部分を持たない
- 入力は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N
X_{1,1} Y_{1,1} Z_{1,1} X_{1,2} Y_{1,2} Z_{1,2}
\vdots
X_{N,1} Y_{N,1} Z_{N,1} X_{N,2} Y_{N,2} Z_{N,2}
出力
答えを出力せよ。
入力例 1
4 0 0 0 1 1 1 0 0 1 1 1 2 1 1 1 2 2 2 3 3 3 4 4 4
出力例 1
1 1 0 0
1 番目の直方体と 2 番目の直方体は、2 点 (0,0,1),(1,1,1) を結ぶ線分を対角線とする長方形を共有しています。
1 番目の直方体と 3 番目の直方体は、点 (1,1,1) を共有していますが、面で接してはいません。
入力例 2
3 0 0 10 10 10 20 3 4 1 15 6 10 0 9 6 1 20 10
出力例 2
2 1 1
入力例 3
8 0 0 0 1 1 1 0 0 1 1 1 2 0 1 0 1 2 1 0 1 1 1 2 2 1 0 0 2 1 1 1 0 1 2 1 2 1 1 0 2 2 1 1 1 1 2 2 2
出力例 3
3 3 3 3 3 3 3 3
Score : 500 points
Problem Statement
There are N rectangular cuboids in a three-dimensional space.
These cuboids do not overlap. Formally, for any two different cuboids among them, their intersection has a volume of 0.
The diagonal of the i-th cuboid is a segment that connects two points (X_{i,1},Y_{i,1},Z_{i,1}) and (X_{i,2},Y_{i,2},Z_{i,2}), and its edges are all parallel to one of the coordinate axes.
For each cuboid, find the number of other cuboids that share a face with it.
Formally, for each i, find the number of j with 1\leq j \leq N and j\neq i such that the intersection of the surfaces of the i-th and j-th cuboids has a positive area.
Constraints
- 1 \leq N \leq 10^5
- 0 \leq X_{i,1} < X_{i,2} \leq 100
- 0 \leq Y_{i,1} < Y_{i,2} \leq 100
- 0 \leq Z_{i,1} < Z_{i,2} \leq 100
- Cuboids do not have an intersection with a positive volume.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N
X_{1,1} Y_{1,1} Z_{1,1} X_{1,2} Y_{1,2} Z_{1,2}
\vdots
X_{N,1} Y_{N,1} Z_{N,1} X_{N,2} Y_{N,2} Z_{N,2}
Output
Print the answer.
Sample Input 1
4 0 0 0 1 1 1 0 0 1 1 1 2 1 1 1 2 2 2 3 3 3 4 4 4
Sample Output 1
1 1 0 0
The 1-st and 2-nd cuboids share a rectangle whose diagonal is the segment connecting two points (0,0,1) and (1,1,1).
The 1-st and 3-rd cuboids share a point (1,1,1), but do not share a surface.
Sample Input 2
3 0 0 10 10 10 20 3 4 1 15 6 10 0 9 6 1 20 10
Sample Output 2
2 1 1
Sample Input 3
8 0 0 0 1 1 1 0 0 1 1 1 2 0 1 0 1 2 1 0 1 1 1 2 2 1 0 0 2 1 1 1 0 1 2 1 2 1 1 0 2 2 1 1 1 1 2 2 2
Sample Output 3
3 3 3 3 3 3 3 3
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
すぬけ君は高橋君と青木君にプレゼントを 1 個ずつ渡そうと考えています。
プレゼントの候補は N 種類あり、i 番目の候補は、高橋君にとって嬉しさ A_i 、青木君にとって嬉しさ B_i です。
高橋君と青木君はとても嫉妬深いので、相手がもらったプレゼントの自分にとっての嬉しさが、自分がもらったプレゼントの自分にとっての嬉しさより大きい場合、相手に嫉妬してけんかになってしまいます。
N^2 通りあるプレゼントの渡し方のうち、高橋君と青木君がけんかしないようなものは何通りありますか?
制約
- 1 \leq N \leq 2\times 10^5
- 0 \leq A_i \leq 10^9
- 0 \leq B_i \leq 10^9
- 入力に含まれる値は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N A_1 \ldots A_N B_1 \ldots B_N
出力
答えを出力せよ。
入力例 1
3 50 100 150 1 3 2
出力例 1
4
例えば高橋君に 1 番目の候補を、青木君に 2 番目の候補をプレゼントした場合、 青木君がもらったプレゼントの高橋君にとっての嬉しさが 100、 高橋君がもらったプレゼントの高橋君にとっての嬉しさは 50 なので、高橋君は青木君に嫉妬し、けんかしてしまいます。
また、例えば高橋君に 3 番目の候補を、青木君に 2 番目の候補をプレゼントした場合、2 人はけんかしません。
2 人に同じものをプレゼントしてもよいことに注意してください。
入力例 2
3 123456789 123456 123 987 987654 987654321
出力例 2
6
入力例 3
10 3 1 4 1 5 9 2 6 5 3 2 7 1 8 2 8 1 8 2 8
出力例 3
37
Score : 500 points
Problem Statement
Snuke is planning on giving one gift each to Takahashi and Aoki.
There are N candidates for the gifts. Takahashi's impression of the i-th candidate is A_i, and Aoki's impression of it is B_i.
The two are very jealous. If Takahashi's impression of the gift Aoki gets is greater than Takahashi's impression of the gift Takahashi gets, Takahashi gets jealous of Aoki and starts fighting, and vice versa.
Among the N^2 possible ways of giving the gifts, how many do not lead to fighting?
Constraints
- 1 \leq N \leq 2\times 10^5
- 0 \leq A_i \leq 10^9
- 0 \leq B_i \leq 10^9
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A_1 \ldots A_N B_1 \ldots B_N
Output
Print the answer.
Sample Input 1
3 50 100 150 1 3 2
Sample Output 1
4
For example, if we give the 1-st candidate to Takahashi and the 2-nd candidate to Aoki, Takahashi's impression of the gift Aoki gets is 100, while Takahashi's impression of the gift Takahashi gets is 50, so Takahashi gets jealous of Aoki and starts fighting.
As another example, if we give the 3-rd candidate to Takahashi and the 2-nd candidate to Aoki, the two will not start fighting.
Note that it is allowed to give the same gift to the two.
Sample Input 2
3 123456789 123456 123 987 987654 987654321
Sample Output 2
6
Sample Input 3
10 3 1 4 1 5 9 2 6 5 3 2 7 1 8 2 8 1 8 2 8
Sample Output 3
37