url
stringlengths 49
92
| description
stringlengths 22
4.78k
| cases
listlengths 0
6
|
---|---|---|
https://atcoder.jp/contests/abc260/tasks/abc260_e | Problem Statement
You are given an integer
M
and
N
pairs of integers
(A_1, B_1), (A_2, B_2), \dots, (A_N, B_N)
.
For all
i
, it holds that
1 \leq A_i \lt B_i \leq M
.
A sequence
S
is said to be a
good sequence
if the following conditions are satisfied:
S
is a contiguous subsequence of the sequence
(1,2,3,..., M)
.
For all
i
,
S
contains at least one of
A_i
and
B_i
.
Let
f(k)
be the number of possible good sequences of length
k
.
Enumerate
f(1), f(2), \dots, f(M)
. | [
{
"input": "3 5\n1 3\n1 4\n2 5\n",
"output": "0 1 3 2 1\n"
},
{
"input": "1 2\n1 2\n",
"output": "2 1\n"
},
{
"input": "5 9\n1 5\n1 7\n5 6\n5 8\n2 6\n",
"output": "0 0 1 2 4 4 3 2 1\n"
}
] |
https://atcoder.jp/contests/abc260/tasks/abc260_f | Problem Statement
We have a simple undirected graph
G
with
(S+T)
vertices and
M
edges. The vertices are numbered
1
through
(S+T)
, and the edges are numbered
1
through
M
. Edge
i
connects Vertices
u_i
and
v_i
.
Here, vertex sets
V_1 = \lbrace 1, 2,\dots, S\rbrace
and
V_2 = \lbrace S+1, S+2, \dots, S+T \rbrace
are both independent sets.
A cycle of length
4
is called a 4-cycle.
If
G
contains a 4-cycle, choose any of them and print the vertices in the cycle. You may print the vertices in any order.
If
G
does not contain a 4-cycle, print
-1
.
What is an independent set?
An independent set of a graph
G
is a set
V'
of some of the vertices in
G
such that no two vertices of
V'
have an edge between them. | [
{
"input": "2 3 5\n1 3\n1 4\n1 5\n2 4\n2 5\n",
"output": "1 2 4 5\n"
},
{
"input": "3 2 4\n1 4\n1 5\n2 5\n3 5\n",
"output": "-1\n"
},
{
"input": "4 5 9\n3 5\n1 8\n3 7\n1 9\n4 6\n2 7\n4 8\n1 7\n2 9\n",
"output": "1 7 2 9\n"
}
] |
https://atcoder.jp/contests/abc260/tasks/abc260_g | Problem Statement
We have an
N \times N
grid. The square at the
i
-th row from the top and
j
-th column from the left in this grid is called
(i,j)
.
Each square of the grid has at most one piece.
The state of the grid is given by
N
strings
S_i
:
if the
j
-th character of
S_i
is
O
, then
(i,j)
has a piece on it;
if the
j
-th character of
S_i
is
X
, then
(i,j)
has no piece on it.
You are given an integer
M
. Using this
M
, we define that a piece
P
placed at
(s,t)
covers a square
(u,v)
if all of the following conditions are satisfied:
s \le u \le N
t \le v \le N
(u - s) + \frac{(v - t)}{2} < M
For each of
Q
squares
(X_i,Y_i)
, find how many pieces cover the square. | [
{
"input": "4 2\nOXXX\nXXXX\nXXXX\nXXXX\n6\n1 1\n1 4\n2 2\n2 3\n3 1\n4 4\n",
"output": "1\n1\n1\n0\n0\n0\n"
},
{
"input": "5 10\nOOOOO\nOOOOO\nOOOOO\nOOOOO\nOOOOO\n5\n1 1\n2 3\n3 4\n4 2\n5 5\n",
"output": "1\n6\n12\n8\n25\n"
},
{
"input": "8 5\nOXXOXXOX\nXOXXOXOX\nXOOXOOXO\nOXOOXOXO\nOXXOXXOX\nXOXXOXOX\nXOOXOOXO\nOXOOXOXO\n6\n7 2\n8 1\n4 5\n8 8\n3 4\n1 7\n",
"output": "5\n3\n9\n14\n5\n3\n"
}
] |
https://atcoder.jp/contests/abc260/tasks/abc260_h | Problem Statement
There are
N
balls numbered
1
through
N
. Ball
i
is painted in Color
a_i
.
For a permutation
P = (P_1, P_2, \dots, P_N)
of
(1, 2, \dots, N)
, let us define
C(P)
as follows:
The number of pairs of adjacent balls with different colors when Balls
P_1, P_2, \dots, P_N
are lined up in a row in this order.
Let
S_N
be the set of all permutations of
(1, 2, \dots, N)
. Also, let us define
F(k)
by:
\displaystyle F(k) = \left(\sum_{P \in S_N}C(P)^k \right) \bmod 998244353
.
Enumerate
F(1), F(2), \dots, F(M)
. | [
{
"input": "3 4\n1 1 2\n",
"output": "8 12 20 36\n"
},
{
"input": "2 1\n1 1\n",
"output": "0\n"
},
{
"input": "10 5\n3 1 4 1 5 9 2 6 5 3\n",
"output": "30481920 257886720 199419134 838462446 196874334\n"
}
] |
https://atcoder.jp/contests/arc144/tasks/arc144_a | Problem Statement
For a positive integer
x
, let
f(x)
be the sum of its digit. For example,
f(144) = 1+4+4 = 9
and
f(1)=1
.
You are given a positive integer
N
. Find the following positive integers
M
and
x
:
The maximum positive integer
M
for which there exists a positive integer
x
such that
f(x)=N
and
f(2x)=M
.
The minimum positive integer
x
such that
f(x)=N
and
f(2x)=M
for the
M
above. | [
{
"input": "3\n",
"output": "6\n3\n"
},
{
"input": "6\n",
"output": "12\n24\n"
},
{
"input": "100\n",
"output": "200\n4444444444444444444444444\n"
}
] |
https://atcoder.jp/contests/arc144/tasks/arc144_b | Problem Statement
You are given positive integers
a
and
b
such that
a\leq b
, and a sequence of positive integers
A = (A_1, A_2, \ldots, A_N)
.
On this sequence, you can perform the following operation any number of times (possibly zero):
Choose distinct indices
i, j
(
1\leq i, j \leq N
). Add
a
to
A_i
and subtract
b
from
A_j
.
Find the maximum possible value of
\min(A_1, A_2, \ldots, A_N)
after your operations. | [
{
"input": "3 2 2\n1 5 9\n",
"output": "5\n"
},
{
"input": "3 2 3\n11 1 2\n",
"output": "3\n"
},
{
"input": "3 1 100\n8 5 6\n",
"output": "5\n"
},
{
"input": "6 123 321\n10 100 1000 10000 100000 1000000\n",
"output": "90688\n"
}
] |
https://atcoder.jp/contests/arc144/tasks/arc144_c | Problem Statement
You are given positive integers
N
and
K
.
Find the lexicographically smallest permutation
A = (A_1, A_2, \ldots, A_N)
of the integers from
1
through
N
that satisfies the following condition:
\lvert A_i - i\rvert \geq K
for all
i
(
1\leq i\leq N
).
If there is no such permutation, print
-1
.
What is lexicographical order on sequences?
The following is an algorithm to determine the lexicographical order between different sequences
S
and
T
.
Below, let
S_i
denote the
i
-th element of
S
. Also, if
S
is lexicographically smaller than
T
, we will denote that fact as
S \lt T
; if
S
is lexicographically larger than
T
, we will denote that fact as
S \gt T
.
Let
L
be the smaller of the lengths of
S
and
T
. For each
i=1,2,\dots,L
, we check whether
S_i
and
T_i
are the same.
If there is an
i
such that
S_i \neq T_i
, let
j
be the smallest such
i
. Then, we compare
S_j
and
T_j
. If
S_j
is less than
T_j
(as a number), we determine that
S \lt T
and quit; if
S_j
is greater than
T_j
, we determine that
S \gt T
and quit.
If there is no
i
such that
S_i \neq T_i
, we compare the lengths of
S
and
T
. If
S
is shorter than
T
, we determine that
S \lt T
and quit; if
S
is longer than
T
, we determine that
S \gt T
and quit. | [
{
"input": "3 1\n",
"output": "2 3 1\n"
},
{
"input": "8 3\n",
"output": "4 5 6 7 8 1 2 3\n"
},
{
"input": "8 6\n",
"output": "-1\n"
}
] |
https://atcoder.jp/contests/arc144/tasks/arc144_d | Problem Statement
You are given positive integers
N
and
K
. Find the number, modulo
998244353
, of integer sequences
\bigl(f(0), f(1), \ldots, f(2^N-1)\bigr)
that satisfy all of the following conditions:
0\leq f(x)\leq K
for all non-negative integers
x
(
0\leq x \leq 2^N-1
).
f(x) + f(y) = f(x \,\mathrm{AND}\, y) + f(x \,\mathrm{OR}\, y)
for all non-negative integers
x
and
y
(
0\leq x, y \leq 2^N-1
)
Here,
\mathrm{AND}
and
\mathrm{OR}
denote the bitwise AND and OR, respectively. | [
{
"input": "2 1\n",
"output": "6\n"
},
{
"input": "2 2\n",
"output": "19\n"
},
{
"input": "100 123456789123456789\n",
"output": "34663745\n"
}
] |
https://atcoder.jp/contests/arc144/tasks/arc144_e | Problem Statement
You are given a directed graph
G
with
N
vertices and
M
edges. The vertices are numbered
1, 2, \ldots, N
. The
i
-th edge is directed from Vertex
a_i
to Vertex
b_i
, where
a_i < b_i
.
The
beautifulness
of a sequence of positive integers
W = (W_1, W_2, \ldots, W_N)
is defined as the maximum positive integer
x
that satisfies the following:
For every path
(v_1, \ldots, v_k)
(
v_1 = 1, v_k = N
) from Vertex
1
to Vertex
N
in
G
,
\sum_{i=1}^k W_{v_i}
is a multiple of
x
.
You are given an integer sequence
A = (A_1, A_2, \ldots, A_N)
. Find the maximum beautifulness of a sequence of positive integers
W = (W_1, \ldots, W_N)
such that
A_i \neq -1 \implies W_i = A_i
. If the maximum beautifulness does not exist, print
-1
. | [
{
"input": "4 4\n1 2\n1 3\n2 4\n3 4\n-1 3 7 -1\n",
"output": "4\n"
},
{
"input": "4 5\n1 2\n1 3\n2 4\n3 4\n1 4\n-1 3 7 -1\n",
"output": "1\n"
},
{
"input": "4 4\n1 2\n1 3\n2 4\n3 4\n3 -1 -1 7\n",
"output": "-1\n"
},
{
"input": "5 5\n1 3\n3 5\n2 3\n3 4\n1 4\n2 -1 3 -1 4\n",
"output": "9\n"
}
] |
https://atcoder.jp/contests/arc144/tasks/arc144_f | Problem Statement
You are given a positive integer
m
, a non-negative integer
a
(
0\leq a < m
), and a sequence of positive integers
A = (A_1, \ldots, A_N)
.
A set
X
of positive integers is defined as
X = \{x>0\mid x\equiv a \pmod{m}\}
.
Alice and Bob will play a game against each other. They will alternate turns performing the following operation, with Alice going first:
Choose a pair
(i,x)
of an index
i
(
1\leq i\leq N
) and a positite integer
x\in X
such that
x\leq A_i
. Change
A_i
to
A_i - x
. If there is no such
(i, x)
, the current player loses and the game ends.
Find the number, modulo
998244353
, of pairs
(i, x)
that Alice can choose in her first turn so that she wins if both players play optimally in subsequent turns. | [
{
"input": "3 1 0\n5 6 7\n",
"output": "3\n"
},
{
"input": "5 10 3\n5 9 18 23 27\n",
"output": "3\n"
},
{
"input": "4 10 8\n100 101 102 103\n",
"output": "0\n"
},
{
"input": "5 2 1\n111111111111111 222222222222222 333333333333333 444444444444444 555555555555555\n",
"output": "943937640\n"
}
] |
https://atcoder.jp/contests/abc259/tasks/abc259_a | Problem Statement
Takahashi had his
N
-th birthday, when he was
T
centimeters tall.
Additionally, we know the following facts:
In each year between Takahashi's birth (
0
-th birthday) and his
X
-th birthday, his height increased by
D
centimeters. More formally, for each
i = 1, 2, \ldots, X
, his height increased by
D
centimeters between his
(i-1)
-th birthday and his
i
-th birthday.
Between Takahashi's
X
-th birthday and his
N
-th birthday, his height did not change.
Find Takahashi's height on his
M
-th birthday, in centimeters. | [
{
"input": "38 20 17 168 3\n",
"output": "168\n"
},
{
"input": "1 0 1 3 2\n",
"output": "1\n"
},
{
"input": "100 10 100 180 1\n",
"output": "90\n"
}
] |
https://atcoder.jp/contests/abc259/tasks/abc259_b | Problem Statement
In an
xy
-coordinate plane whose
x
-axis is oriented to the right and whose
y
-axis is oriented upwards, rotate a point
(a, b)
around the origin
d
degrees counterclockwise and find the new coordinates of the point. | [
{
"input": "2 2 180\n",
"output": "-2 -2\n"
},
{
"input": "5 0 120\n",
"output": "-2.49999999999999911182 4.33012701892219364908\n"
},
{
"input": "0 0 11\n",
"output": "0.00000000000000000000 0.00000000000000000000\n"
},
{
"input": "15 5 360\n",
"output": "15.00000000000000177636 4.99999999999999555911\n"
},
{
"input": "-505 191 278\n",
"output": "118.85878514480690171240 526.66743699786547949770\n"
}
] |
https://atcoder.jp/contests/abc259/tasks/abc259_c | Problem Statement
You are given two strings
S
and
T
.
Determine whether it is possible to make
S
equal
T
by performing the following operation some number of times (possibly zero).
Between two consecutive equal characters in
S
, insert a character equal to these characters.
That is, take the following three steps.
Let
N
be the current length of
S
, and
S = S_1S_2\ldots S_N
.
Choose an integer
i
between
1
and
N-1
(inclusive) such that
S_i = S_{i+1}
. (If there is no such
i
, do nothing and terminate the operation now, skipping step 3.)
Insert a single copy of the character
S_i(= S_{i+1})
between the
i
-th and
(i+1)
-th characters of
S
. Now,
S
is a string of length
N+1
:
S_1S_2\ldots S_i S_i S_{i+1} \ldots S_N
. | [
{
"input": "abbaac\nabbbbaaac\n",
"output": "Yes\n"
},
{
"input": "xyzz\nxyyzz\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/abc259/tasks/abc259_d | Problem Statement
You are given
N
circles on the
xy
-coordinate plane.
For each
i = 1, 2, \ldots, N
, the
i
-th circle is centered at
(x_i, y_i)
and has a radius of
r_i
.
Determine whether it is possible to get from
(s_x, s_y)
to
(t_x, t_y)
by only passing through points that lie on the circumference of at least one of the
N
circles. | [
{
"input": "4\n0 -2 3 3\n0 0 2\n2 0 2\n2 3 1\n-3 3 3\n",
"output": "Yes\n"
},
{
"input": "3\n0 1 0 3\n0 0 1\n0 0 2\n0 0 3\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/abc259/tasks/abc259_e | Problem Statement
There are
N
integers
a_1,\ldots,a_N
written on a whiteboard.
Here,
a_i
can be represented as
a_i = p_{i,1}^{e_{i,1}} \times \ldots \times p_{i,m_i}^{e_{i,m_i}}
using
m_i
prime numbers
p_{i,1} \lt \ldots \lt p_{i,m_i}
and positive integers
e_{i,1},\ldots,e_{i,m_i}
.
You will choose one of the
N
integers to replace it with
1
.
Find the number of values that can be the least common multiple of the
N
integers after the replacement. | [
{
"input": "4\n1\n7 2\n2\n2 2\n5 1\n1\n5 1\n2\n2 1\n7 1\n",
"output": "3\n"
},
{
"input": "1\n1\n998244353 1000000000\n",
"output": "1\n"
}
] |
https://atcoder.jp/contests/abc259/tasks/abc259_f | Problem Statement
You are given a tree with
N
vertices.
For each
i = 1, 2, \ldots, N-1
, the
i
-th edge connects Vertex
u_i
and Vertex
v_i
and has a weight
w_i
.
Consider choosing some of the
N-1
edges (possibly none or all).
Here, for each
i = 1, 2, \ldots, N
, one may choose at most
d_i
edges incident to Vertex
i
.
Find the maximum possible total weight of the chosen edges. | [
{
"input": "7\n1 2 1 0 2 1 1\n1 2 8\n2 3 9\n2 4 10\n2 5 -3\n5 6 8\n5 7 3\n",
"output": "28\n"
},
{
"input": "20\n0 2 0 1 2 1 0 0 3 0 1 1 1 1 0 0 3 0 1 2\n4 9 583\n4 6 -431\n5 9 325\n17 6 131\n17 2 -520\n2 16 696\n5 7 662\n17 15 845\n7 8 307\n13 7 849\n9 19 242\n20 6 909\n7 11 -775\n17 18 557\n14 20 95\n18 10 646\n4 3 -168\n1 3 -917\n11 12 30\n",
"output": "2184\n"
}
] |
https://atcoder.jp/contests/abc259/tasks/abc259_g | Problem Statement
There are
H \times W
cards on a grid of squares with
H
rows and
W
columns.
For each pair of integers
(i, j)
such that
1 \leq i \leq H, 1 \leq j \leq W
, the card at the
i
-th row and
j
-th column has an integer
A_{i, j}
written on it.
Takahashi and Aoki will cooperate to play a game, which consists of the following steps.
First, Takahashi chooses some of the
H
rows (possibly none or all) and places a red token on each card in the chosen rows.
Second, Aoki chooses some of the
W
columns (possibly none or all) and places a blue token on each card in the chosen columns.
Now, they compute their score as follows.
If there is a card with a negative integer that has both red and blue tokens placed on it, the play is a "total failure"; the score is
-10^{100}
.
Otherwise, they collect all cards that have one or more tokens placed on them. The score is the sum of the integers written on the collected cards.
Find their maximum possible score. | [
{
"input": "2 3\n-9 5 1\n6 -2 4\n",
"output": "9\n"
},
{
"input": "15 20\n-14 74 -48 38 -51 43 5 37 -39 -29 80 -44 -55 59 17 89 -37 -68 38 -16\n14 31 43 -73 49 -7 -65 13 -40 -45 36 88 -54 -43 99 87 -94 57 -22 31\n-85 67 -46 23 95 68 55 17 -56 51 -38 64 32 -19 65 -62 76 66 -53 -16\n35 -78 -41 35 -51 -85 24 -22 45 -53 82 -30 39 19 -52 -3 -11 -67 -33 71\n-75 45 -80 -42 -31 94 59 -58 39 -26 -94 -60 98 -1 21 25 0 -86 37 4\n-41 66 -53 -55 55 98 23 33 -3 -27 7 -53 -64 68 -33 -8 -99 -15 50 40\n66 53 -65 5 -49 81 45 1 33 19 0 20 -46 -82 14 -15 -13 -65 68 -65\n50 -66 63 -71 84 51 -91 45 100 76 -7 -55 45 -72 18 40 -42 73 69 -36\n59 -65 -30 89 -10 43 7 72 93 -70 23 86 81 16 25 -63 73 16 34 -62\n22 -88 27 -69 82 -54 -92 32 -72 -95 28 -25 28 -55 97 87 91 17 21 -95\n62 39 -65 -16 -84 51 62 -44 -60 -70 8 69 -7 74 79 -12 62 -86 6 -60\n-72 -6 -79 -28 39 -42 -80 -17 -95 -28 -66 66 36 86 -68 91 -23 70 58 2\n-19 -20 77 0 65 -94 -30 76 55 57 -8 59 -43 -6 -15 -83 8 29 16 34\n79 40 86 -92 88 -70 -94 -21 50 -3 -42 -35 -79 91 96 -87 -93 -6 46 27\n-94 -49 71 37 91 47 97 1 21 32 -100 -4 -78 -47 -36 -84 -61 86 -51 -9\n",
"output": "1743\n"
}
] |
https://atcoder.jp/contests/abc259/tasks/abc259_h | Problem Statement
We have a grid of squares with
N
rows arranged vertically and
N
columns arranged horizontally. The square at the
i
-th row from the top and
j
-th column from the left has an integer label
a_{i,j}
.
Consider paths obtained by starting on one of the squares and going
right or down
to an adjacent square zero or more times. Find the number, modulo
998244353
, of such paths that start and end on squares with the same label.
Two paths are distinguished when they visit different sets of squares (including the starting and ending squares). | [
{
"input": "2\n1 3\n3 1\n",
"output": "6\n"
}
] |
https://atcoder.jp/contests/ahc012/tasks/ahc012_a | Problem Statement
There is a circular cake with a radius of
10^4
centered at the origin and
N
strawberries on top of it.
The center of the
i
-th strawberry is at the coordinates
(x_i, y_i)
and satisfies
x_i^2+y_i^2<10^8
.
Takahashi can cut the cake in at most
K
straight lines (not segments), which may intersect each other.
You should specify the line to be cut as a straight line passing through two different integer coordinates
(p_x,p_y)
and
(q_x,q_y)
satisfying
-10^9\leq p_x,p_y,q_x,q_y\leq 10^9
.
The two specified points can be outside of the cake.
Because he is clumsy, he cannot stop or curve a single cut in the middle of the cut.
For each
d=1,2,\cdots,10
, you are given the number
a_d
of attendees who have been participating in AtCoder's contests for
d
years.
Let
b_d
be the number of pieces with
d
strawberries on them.
Then we can distribute
\sum_{d=1}^{10} \min(a_d,b_d)
pieces to attendees.
Here, the
i
-th strawberry belongs to a piece if and only if its center
(x_i, y_i)
is contained inside (excluding the circumference) of the piece.
If a strawberry is cut in a straight line that passes through its center, it belongs to no pieces. | [
{
"input": "2835 100\n51 3 44 99 1 87 83 19 10 90\n484 -7595\n606 -4986\n-70 3067\n3481 -4705\n-3464 -3044\n1329 -4256\n-3512 -5340\n-2544 6126\n3435 7021\n-7712 -6197\n-3097 569\n7192 1127\n-1048 1879\n4813 -3083\n-5549 6929\n-442 2382\n2945 3994\n6014 -7099\n7351 -3206\n957 2312\n4759 3636\n5006 2830\n1295 -3571\n8639 4466\n1737 1871\n430 1351\n-1131 -7028\n-9734 -306\n-2399 -1120\n8091 -3904\n7981 353\n3857 3265\n1904 -9009\n8580 -2444\n-8069 3327\n2134 -1889\n6814 -7227\n-179 4070\n-133 2159\n8408 -3895\n8310 -2805\n-2613 8307\n4909 -6786\n-4757 -1665\n-5655 -4694\n3044 -833\n1461 661\n-854 6814\n-3173 -1271\n-3234 -220\n-5572 325\n-5581 -3338\n2073 -5006\n422 5252\n-2123 -671\n1847 8702\n-5892 -5104\n1619 3729\n-9533 -1758\n-3949 3323\n-4690 6069\n1307 3679\n692 5468\n2131 1579\n8492 1546\n-3285 4628\n-8716 -1213\n6372 7303\n714 2324\n5838 6861\n-180 -2797\n5641 6136\n1976 -6215\n-768 -1353\n3284 -3719\n-6839 -979\n8686 -1972\n-6309 -2519\n7714 6148\n-3269 -2754\n-3864 6951\n-1476 4044\n-3462 -3473\n285 -8593\n1045 1832\n-4038 -2488\n7024 -2583\n581 -6553\n4012 -603\n1743 2227\n-5344 5418\n-9502 2454\n-2278 3759\n-3898 7095\n-6842 7212\n5318 -168\n-1041 -8572\n-6728 4202\n8340 4797\n8947 -4407\n-4883 7131\n4883 -4575\n8155 -3350\n1337 -3654\n2731 4752\n8004 581\n3637 -1668\n3117 2523\n6308 -5224\n1031 -3502\n7048 7078\n-6094 2876\n691 -7417\n-3923 -7061\n-9026 293\n3689 4085\n1127 5962\n-5618 -6061\n4512 1564\n-3236 -416\n-9460 -1675\n-1781 -1921\n1000 -6263\n2347 -931\n5882 -1002\n4695 -7875\n-4233 8852\n5700 -2382\n2714 -3241\n833 -3597\n-2848 7445\n-4746 220\n-7733 69\n4069 4537\n5890 -628\n-4376 -506\n3673 -5994\n59 1952\n-3549 -3144\n6102 -4773\n8469 1581\n-119 -5423\n3140 1067\n-5032 -5506\n2167 7041\n8073 -1435\n-374 -2695\n7844 -5181\n-7466 -1752\n3583 8122\n3894 1046\n4404 8547\n2572 5333\n-604 2975\n-6043 2805\n6815 -4786\n-5082 -6474\n2265 5421\n2611 -8621\n1525 -7317\n886 -7918\n-3432 93\n2259 -2986\n8365 -5457\n1268 7771\n6070 7406\n572 5620\n-6655 7069\n2267 3706\n4556 7775\n-5495 7411\n5334 -7307\n-5830 -387\n-1892 9533\n-1734 2547\n8411 4917\n-3810 -9224\n1231 6809\n-3521 4389\n-6775 3016\n-2915 -3517\n-4003 -6182\n7243 -4020\n-4508 8789\n-6377 5081\n-8719 945\n94 7427\n-4343 8041\n-444 2336\n-921 6102\n-5733 -8028\n5068 -3973\n8188 3444\n6691 5820\n-472 4302\n-4325 2035\n31 4050\n1195 -1493\n-4449 -3249\n-7105 2594\n100 -7939\n-131 -6275\n6447 -5086\n8140 -2242\n3221 -2699\n-2133 -6591\n7061 6651\n864 -2899\n113 -1002\n1239 5103\n-1473 -5647\n1996 3502\n-3456 -5403\n-831 549\n5292 -6128\n-5918 -2771\n-696 1730\n3585 -4084\n5533 4160\n2593 -9621\n-7496 -3938\n1734 -6794\n2902 3181\n-2717 3180\n-512 -7886\n6223 -1167\n-1286 3422\n1801 -6794\n3584 -4937\n3525 -4695\n2767 6928\n-5305 -6483\n8921 622\n-5089 -6415\n-5350 5347\n9501 1920\n9836 -1130\n9322 -610\n7368 1792\n-8854 684\n5263 634\n9745 -2189\n6505 -6709\n368 2849\n640 -3474\n5569 6104\n4445 3906\n5034 -7551\n6811 -3802\n-5521 4781\n2307 7752\n-1732 -7612\n-2209 -4026\n1744 -9669\n583 1510\n3002 -3923\n853 -4109\n-8095 -5239\n810 -3038\n-2391 -1461\n-1660 -2831\n1435 -6926\n-130 -7227\n-8130 4368\n1509 7772\n-376 -158\n7070 139\n-5171 6804\n9864 1591\n4115 -7775\n835 -9598\n6096 2407\n-7583 -3626\n-5921 -5804\n-1659 4965\n-7193 -1156\n3016 3731\n4376 5446\n-1108 2092\n-3797 4911\n-1452 -5699\n3886 -7050\n5482 5842\n5026 2916\n3987 -8923\n6021 -7861\n8050 -932\n545 3371\n-4028 -1019\n6324 -3122\n3355 -1963\n-5626 -2598\n-2071 -5233\n-2592 550\n-5070 2481\n7228 2359\n-105 124\n4905 2229\n-4811 4553\n-4346 -7282\n4672 5592\n7698 3543\n5413 -394\n-3083 6660\n-3342 5661\n1644 -3381\n-8694 4422\n7176 1813\n-1357 -4772\n4888 -8283\n5421 -139\n-3194 -2871\n-3594 8066\n-714 1683\n-460 2945\n7877 1689\n2061 -7126\n-2069 -4295\n-5083 6772\n1759 -5464\n2117 1121\n-2916 231\n8877 1459\n-1068 174\n4440 3887\n673 -8471\n44 -9313\n-8919 -595\n325 8643\n-7507 6048\n-8207 -2424\n2045 -353\n-2108 -1003\n2316 2005\n4795 -8111\n1063 -3218\n1007 -8575\n-7056 900\n4002 6028\n8788 -3367\n-4555 -4040\n-784 -9781\n2002 1661\n3718 -7921\n1003 -1914\n4321 -4046\n-38 8258\n-4811 3576\n-108 6798\n2202 5751\n2000 1885\n-7163 1462\n3707 -8395\n-600 9201\n5838 -757\n-8035 -5000\n-4188 7193\n943 132\n7533 3216\n-5676 -2787\n-1412 -5504\n7094 3408\n3168 5455\n4378 -617\n7105 -1537\n-9907 876\n5938 -1555\n-6648 1451\n5489 6309\n9755 -2135\n-4082 7369\n-9156 -1877\n-5755 -145\n5332 -7101\n5097 5930\n-2044 2465\n-3435 -8595\n-7635 1214\n-1148 -6573\n-493 -8289\n3125 -3779\n1306 -7910\n-5449 -1364\n-7339 -116\n-2634 5518\n-4164 2102\n-1674 997\n4578 -530\n2629 9096\n-6624 -5881\n6782 1720\n2950 6478\n7929 3591\n-964 -2817\n-5302 2261\n-732 -2244\n-7592 -6213\n4974 -4631\n7955 601\n5650 5313\n8606 -4090\n-2211 335\n-6181 -7186\n-2798 8941\n-7497 -4914\n-1219 2425\n358 5731\n-5255 -376\n-3120 -6978\n2113 -6864\n4033 -2347\n229 6090\n-3875 6737\n-3936 2093\n-2081 -4954\n-9810 -1162\n2811 2994\n300 2430\n-5611 992\n-7621 -3362\n-2504 1025\n3141 7788\n-5949 -2616\n-2778 6223\n-3849 -435\n2325 -1444\n-8120 2179\n4142 -5562\n-4028 7335\n2800 6132\n-6529 875\n1675 -8211\n-5876 6727\n7974 4582\n616 8127\n4461 -4761\n-1302 9500\n-8472 4445\n6569 2265\n9472 -2322\n1605 -1618\n-2176 -2973\n4690 8034\n9103 -2571\n4836 4983\n-6922 -4820\n7278 -6031\n199 889\n9316 -2252\n4889 -8138\n2662 -8199\n5282 -1003\n418 -8764\n-1991 -6508\n-6103 3370\n1430 8525\n6899 -219\n2424 -5170\n4990 -3250\n-2620 -6879\n4087 6718\n-3944 8901\n-1010 -457\n3324 -2628\n-9166 2361\n-7209 4107\n-1008 7907\n360 234\n3069 -9372\n6667 -5651\n-4814 -2494\n-3839 6851\n5569 -3517\n-2216 -2802\n8980 -2023\n-3643 -8503\n-1495 -9560\n872 5001\n-3605 4014\n3011 3482\n-8228 4275\n9379 3275\n4032 6124\n-1126 4767\n-8680 2441\n2087 2805\n5793 564\n2199 -848\n-9136 -1667\n-271 932\n-3110 3639\n-5886 6986\n2462 2555\n-3256 3227\n-1772 4640\n2516 4615\n2178 3478\n-4454 4277\n-2065 -2415\n4750 -6829\n836 -5043\n-2385 -6092\n-2239 -3159\n3788 -7084\n-6583 -1759\n-6341 -216\n-2348 3387\n-1122 6448\n3530 -1624\n6538 6413\n975 2432\n6379 -5109\n7457 786\n8243 2713\n6529 -384\n-2269 7019\n2284 8286\n1292 -9642\n-4422 7329\n4057 -7640\n6886 -3538\n4899 -384\n3930 -3952\n3195 -3354\n-3279 -7536\n-1249 7291\n3086 9235\n-2276 -5436\n8128 -3303\n-7579 519\n-3463 3673\n-614 4788\n-891 -5576\n-4160 -4908\n-8860 3853\n-5419 6641\n4832 8500\n-2453 8702\n1006 -566\n-183 2979\n8747 -362\n8536 -928\n-239 -2220\n-963 8477\n-3760 4470\n3255 1859\n2617 -5734\n-6633 6312\n709 2688\n6885 2213\n-6227 -6645\n-9314 733\n-2706 8666\n-5530 -775\n7451 -3906\n-6711 1164\n2815 6155\n855 3136\n9035 -1183\n3192 8991\n238 9937\n-1460 665\n9363 2694\n9777 1016\n1566 3836\n7143 -6240\n4529 885\n-4321 3994\n-7984 -3886\n3041 6996\n-1070 -4141\n2962 3508\n8250 2866\n-7973 5079\n6502 -6373\n-6696 -6916\n2863 5224\n-6177 2508\n8144 1257\n-273 -8025\n-7646 1944\n6089 5771\n7617 4969\n-835 7359\n5819 972\n-3802 7047\n4123 -4918\n-763 -8312\n5294 -3728\n1856 5518\n-6951 -5467\n6121 -5432\n-4717 -5808\n-3146 1564\n183 -2014\n5286 -8053\n7086 -474\n927 8709\n7845 -608\n3320 2680\n2204 9702\n3737 229\n-1220 -9656\n2667 3760\n5364 2181\n-1635 6892\n7366 -5144\n53 -9139\n-8113 -5138\n-1229 -4723\n-376 131\n-1170 -4474\n-39 1244\n-292 3468\n6274 7534\n-4850 2808\n-7196 -3589\n3185 398\n728 7785\n1258 -5500\n5418 530\n-3137 7401\n7281 -263\n2188 -1139\n-1212 7230\n-2788 -8745\n-7823 2964\n-6019 -4153\n7851 2416\n-1076 2253\n214 2872\n-5341 -1441\n5393 -3559\n746 8539\n7562 5189\n4413 -5006\n-4447 7342\n3700 -7923\n-5185 405\n-4123 828\n-4061 -5427\n-2853 -4257\n5643 -3314\n344 -883\n9323 -1809\n-6078 2332\n4867 3683\n6738 -4060\n-7009 2420\n-714 -5753\n3099 -6086\n-334 -6916\n-7344 -329\n-2760 9053\n8449 1850\n-167 7914\n-742 13\n-8496 -4251\n4337 -2838\n-8154 -427\n387 -9469\n1514 9549\n2645 7455\n9075 3502\n-3457 -4703\n4549 239\n5269 745\n-6607 -3646\n5348 4434\n4113 7276\n-5566 -2818\n3268 -970\n-3793 -9017\n-4693 3379\n669 -6980\n-5126 3937\n5684 -2072\n-6899 -148\n3303 -723\n2095 -5814\n5454 1695\n3419 5011\n6407 3121\n-9184 659\n5377 7655\n5293 -3963\n-4219 8493\n7339 -196\n-5978 7344\n8175 -287\n-5073 -5033\n-25 3107\n4451 -6970\n-1638 -1575\n-2899 2153\n-6514 1704\n-4607 1591\n8050 2620\n6905 6060\n-1166 -3057\n2281 -753\n-2096 7699\n2980 -1148\n233 5773\n2068 -1174\n6828 -792\n-1543 6580\n-4174 -7457\n-7619 3467\n489 -7170\n-717 -3783\n5373 6745\n4243 641\n7252 1058\n-9190 -2247\n-9416 -2747\n-256 2108\n381 -6646\n-3594 -3689\n-6119 -3529\n904 3678\n-987 -423\n-8049 -1600\n-6563 -7365\n-7070 2543\n-1311 -121\n2335 -6854\n-5264 3730\n-4111 4961\n7850 -1080\n2609 -355\n-5430 -4820\n-2753 8617\n-2942 4833\n-4665 5771\n4165 -5936\n8593 4660\n-3821 -6953\n885 9249\n6968 4048\n9058 -4163\n3832 -5315\n-4904 3924\n7820 -1596\n-5325 7876\n2095 -1222\n-5451 -5281\n-6787 7166\n-810 5632\n-2362 -2732\n7334 -5081\n-5196 2932\n1756 7350\n6509 -6211\n-8812 -1920\n-3758 4749\n550 -8188\n7134 6771\n-9185 2315\n-2752 7063\n4528 5234\n-3660 -3865\n-126 6998\n-9359 2489\n1392 -1669\n3700 9166\n-4600 1722\n7767 5688\n-236 1414\n-1140 -702\n-3991 8769\n6046 -3424\n-2874 -5375\n2418 7255\n7874 -3193\n2340 -7983\n-2063 -8609\n-6487 -2292\n2725 -9526\n3570 31\n-4742 8375\n-7068 2022\n-3699 -5016\n-3216 -3452\n-112 6561\n3050 8853\n-789 -9576\n1214 -5325\n-1613 4386\n8769 481\n-3017 8426\n1641 9279\n-7101 -885\n548 -991\n724 5566\n437 4525\n-5161 -1755\n-7738 3089\n-2341 -65\n3694 9146\n5329 7214\n8011 -1192\n-1471 5709\n8411 -4039\n-7746 6246\n1066 5073\n-7888 293\n2129 -1790\n1414 -928\n-6684 -6359\n736 1222\n1778 -6163\n-9047 -2717\n33 -7801\n6813 -4439\n-728 4463\n-1126 5000\n-7346 -6649\n4702 -1906\n-3393 -3238\n7403 -4067\n7152 5618\n-2326 -6443\n-2589 -7946\n-4088 1963\n-2212 2157\n-2284 7985\n-5065 5756\n6571 -1024\n-4065 -2812\n-4862 1197\n-6001 -1852\n6689 5216\n-2684 -9147\n-9263 3335\n-4554 5736\n3720 -9281\n-638 8205\n-919 -5529\n4170 5639\n-9064 1784\n-8416 -2782\n2783 9514\n-7060 -2094\n-2528 4690\n1165 8694\n-5356 -7124\n1663 7960\n-5159 -3901\n-5785 -7071\n-2282 -7660\n-5248 2617\n7061 245\n5044 3711\n-3980 -6733\n8077 4265\n-4876 7528\n-6296 2260\n8082 322\n161 2565\n-3090 -279\n-832 1236\n-6759 -2850\n-1481 6192\n-6794 5180\n7676 -566\n5197 19\n2591 -3862\n2814 -2401\n-4791 -8448\n5287 5396\n6962 2907\n990 -2071\n-3106 1837\n-7690 -6308\n-4417 -7419\n2187 4319\n-4511 6640\n-5036 -1853\n-4214 -3625\n-243 -2039\n-3260 4052\n-4249 -7880\n-5772 4016\n-1666 60\n3861 -8436\n175 1207\n-79 -9170\n3559 -1163\n3897 -1019\n-5816 -5037\n-1006 -1898\n5111 -5956\n5386 -2797\n7536 -3493\n-1179 2496\n1355 -9551\n-3066 -628\n-1104 3089\n5113 8458\n-45 4501\n-1457 542\n-7946 5972\n-5072 2948\n6986 455\n-8776 -3642\n-723 2210\n8735 94\n3861 3200\n-9299 -2920\n-3560 -6600\n3087 2594\n4460 -91\n2697 -702\n3202 444\n-6940 -2553\n-7396 6520\n634 -5352\n3384 2324\n6879 -4031\n-4905 3089\n-4090 -7325\n1289 -3075\n5714 -1837\n-4045 -6456\n-3251 -7477\n5849 4238\n4007 -6023\n-2725 7902\n4859 -158\n-836 3245\n7493 -5732\n-1801 -2714\n-1373 2145\n2406 6182\n-9139 1573\n-1927 4659\n4391 2067\n-1403 -6007\n3820 -7500\n420 -599\n-2687 4037\n4569 -2936\n-6743 4411\n-2400 -8641\n-3187 -5160\n-8355 1127\n1511 3013\n-4832 5092\n2034 -8305\n7676 -6331\n3044 6097\n-8506 3165\n-5902 4866\n-6586 -3067\n8032 4877\n7026 -6784\n-434 -6267\n-3665 -2800\n-5584 -5490\n2675 -5147\n2224 -1397\n2149 3969\n1127 3856\n-153 3052\n167 5904\n-6148 -613\n-4330 1165\n-1335 -9902\n-6514 308\n1374 7422\n-2521 7145\n-4982 2926\n-543 8870\n-6976 -4774\n4653 853\n358 743\n1859 5359\n673 -8793\n-4687 -6302\n-5685 5926\n-243 6637\n404 -3953\n6491 -4797\n-6909 -5574\n2538 1814\n-4375 858\n1758 6459\n1402 -1422\n2649 -6403\n5071 6157\n4533 7909\n5865 -2381\n-145 1678\n8026 -5245\n6550 -5067\n4550 6275\n-292 1838\n8332 -2926\n3767 9206\n1810 2678\n5351 5474\n-1709 3490\n-8939 4367\n-3402 2890\n1593 1513\n-9874 -980\n88 -1181\n3584 -7395\n-3428 -128\n4464 -2547\n-5556 2363\n-1868 3436\n-5133 1777\n-3404 1021\n-701 -2378\n-1907 1481\n1950 -1838\n-6392 3262\n-1739 -1944\n4100 -6298\n-2627 -6276\n-294 -9918\n-6990 7094\n-1222 5131\n-5191 3759\n-4551 -8292\n19 -850\n5804 6567\n-8304 3356\n1689 1018\n3433 4181\n286 1748\n9554 1983\n8849 -3758\n-6142 -972\n6573 4038\n-6164 2982\n8131 182\n-6911 4313\n-8489 4992\n4292 -2608\n2070 -3151\n-3448 4750\n-9007 2050\n3253 -2829\n169 -7595\n-555 -8502\n-535 2346\n-1907 -7017\n-8469 -1475\n-4849 3442\n3771 3030\n-3706 -3809\n-6743 -1980\n7758 4982\n5209 -4891\n-5162 -246\n-3362 -2016\n-3174 -7718\n-250 -1954\n2306 4714\n-2099 -3708\n371 7107\n6080 -831\n-8328 964\n-1356 -7576\n-2518 -2449\n3723 -5771\n3457 -3306\n-1862 -4778\n6770 2399\n-148 2929\n-831 5408\n-1891 -3868\n1059 690\n-6764 3945\n71 8655\n1747 8557\n-3438 -205\n-4651 5495\n-7029 3032\n-6803 2169\n-3520 -4964\n-7103 -5597\n6333 1110\n-3098 -4225\n-585 -1455\n1869 9720\n-2119 -8311\n-2752 4662\n-8570 -5061\n-100 -9291\n2622 -7149\n-8018 -4004\n-4858 4135\n3345 4796\n8461 -1363\n2313 -175\n-6735 -4323\n-3304 3097\n-3294 3524\n7315 -4856\n-4187 4664\n999 -6893\n-7367 4128\n-6215 506\n8968 321\n814 3818\n5526 1753\n-1499 -1394\n8256 -2925\n-6594 -5841\n-2805 -8641\n-9099 1455\n-3140 4220\n801 -3577\n3129 8682\n-7798 -218\n9126 649\n-1376 -6759\n-4469 2968\n193 7928\n2070 -1155\n-2962 7631\n417 2022\n-2853 -9167\n-1709 2056\n2325 1631\n9795 -470\n8726 1460\n1821 -6338\n8141 2131\n988 -1199\n-3451 -8162\n-2490 -5863\n-2472 -4812\n-524 -1559\n-6445 -1496\n62 6267\n-3139 8907\n9531 3016\n-52 5108\n2982 5008\n-1414 1309\n-7989 -3823\n-4591 4791\n3109 3279\n-1422 -1569\n-8380 4135\n-4847 -6601\n-8894 3503\n1099 2302\n2454 -8811\n6676 -7374\n6615 1729\n1374 -6715\n-5234 -6672\n5393 7881\n6293 -6643\n-919 -269\n-8956 2651\n-8916 -3417\n-4991 4537\n-3770 -1859\n-6807 -5860\n-4791 3298\n4775 -4470\n-4357 -6084\n4067 -2144\n-5821 4219\n-452 -437\n5061 -4903\n-7749 -1487\n-6017 1398\n2015 -8881\n4137 -89\n-4427 -1314\n-1737 8951\n2294 4854\n-109 -4098\n-9322 -1997\n-5432 7913\n-662 7234\n-4082 -7775\n-5726 -460\n4958 -96\n4374 -943\n5630 -6899\n7438 2869\n-3013 -8645\n-6477 -3708\n5921 -1834\n6533 -233\n-5205 4091\n1277 -6874\n958 -5533\n6883 4509\n-1748 6888\n8786 -316\n3250 -8061\n-9028 2740\n-5805 4021\n-2285 8909\n-8957 349\n5924 2110\n3243 -340\n3040 -6309\n-1627 -588\n-5517 -2037\n-8359 -3919\n-5856 6340\n3724 712\n-2661 2419\n-5651 6708\n495 3241\n2314 2164\n7848 -5252\n-4021 -1321\n7078 2630\n1133 -4323\n-4615 8570\n-6710 1938\n2111 7811\n-4616 -4418\n6920 -3920\n-7314 -3205\n-1950 1785\n-2096 -1581\n-5310 90\n4807 2492\n9038 3640\n-3165 -4827\n6083 3977\n5709 6250\n-4175 6889\n-3332 2252\n6587 1309\n1889 6779\n5609 -2808\n2032 -1019\n-9316 1701\n-8706 -2536\n125 -481\n-4604 8428\n634 5832\n-5464 -5540\n-9887 -1152\n-190 -7628\n-6309 4675\n-2527 -2861\n-4890 5435\n711 -118\n8875 699\n-1788 -7803\n-1996 4485\n6857 4118\n-5641 387\n-3370 -7820\n4184 2145\n8931 -2580\n573 -7035\n-6680 199\n-5481 190\n8455 3485\n6078 6442\n3378 5732\n-4685 -4063\n2609 -1790\n1712 9395\n8174 1925\n8475 -1026\n1164 -844\n-3327 -2262\n-401 -8849\n-7984 -5952\n2811 9119\n-1543 -7272\n-583 -9712\n3580 -6317\n-6695 -4568\n-1777 -4262\n-8493 -5083\n-1166 -1800\n1965 -3847\n5867 -4956\n-6436 5164\n4935 5708\n-2597 7851\n3001 8588\n5427 -2023\n3071 931\n-217 -20\n2346 895\n-6586 -3119\n8098 1662\n1165 -4283\n3085 6125\n266 1193\n-7057 6569\n-3113 -1365\n776 -3783\n-1630 9712\n-3918 -8821\n-3946 8284\n-5184 -5096\n4349 -5272\n-566 -7077\n8090 3735\n3291 -4374\n8809 196\n-4018 1931\n1452 -3532\n5412 -6057\n3361 1079\n-3099 -4249\n-1470 4323\n-5699 6722\n-202 3697\n-3286 -6667\n1199 -3785\n949 7425\n-6822 -3679\n-2926 7198\n-4945 -4554\n2495 -5712\n8396 3330\n1059 -1295\n-4844 -7522\n8094 4247\n-1426 3952\n-2121 843\n-87 2351\n-4239 -7575\n-5486 -5118\n-4005 7020\n1852 -3343\n-2028 1946\n-4665 3205\n3610 2769\n-1469 -1219\n5601 -5828\n843 -7182\n2316 3964\n-9 5899\n1551 -5745\n-4519 -7621\n-4765 -2295\n-1238 2886\n-2115 7464\n5640 5285\n-8219 783\n-7587 3427\n2798 2813\n5477 7400\n6140 5435\n8863 -3705\n-8220 -3363\n-1623 -2384\n7923 -68\n4185 -2098\n-2055 -5803\n3429 5217\n7715 -3218\n-7379 790\n-2620 -7432\n4466 -4276\n9679 21\n5621 -1328\n4413 4110\n1117 647\n7093 2474\n-6883 2039\n7334 -3345\n-9719 -337\n5165 7712\n-3313 -6189\n5603 -8107\n1585 -2719\n-7595 -4423\n-5121 -3264\n-8371 3024\n-2960 936\n-2841 5916\n-5609 6047\n2835 4424\n-2712 5382\n2839 5539\n8911 3063\n-1760 -4593\n-8322 -2264\n-7363 -4240\n2207 -3409\n-964 -4311\n-4235 1011\n-4109 -325\n3395 3282\n-7813 910\n8096 2424\n752 -3320\n142 7968\n-1929 9648\n-3739 -3976\n7874 2260\n-2364 -8611\n-2303 -9447\n-532 -7429\n-4000 3225\n-5616 -4621\n2468 -976\n1348 -7687\n-3368 2523\n8138 3728\n1142 -5545\n2071 -4660\n-1736 7092\n-550 5128\n-7900 3582\n3244 8357\n5501 7181\n852 3066\n1687 3477\n4984 6633\n6280 -491\n6929 3004\n7919 -856\n5030 -8567\n-7536 -256\n-5452 8030\n-4758 7397\n4318 6219\n-7028 2098\n7386 -3621\n189 696\n5397 -7969\n-1124 -9150\n-4766 5145\n2270 8949\n-3209 -983\n-3500 -6703\n-7595 2727\n-9386 2037\n-1228 9245\n5387 -4928\n-1144 -6249\n-2773 9471\n825 -8457\n3994 -214\n-6103 1523\n6873 -2873\n-921 5905\n-6131 -363\n3842 -5215\n-5226 1352\n7856 -5562\n-3552 570\n1780 -7169\n1943 9473\n-1294 -3398\n-6415 2741\n-6895 -3752\n-1889 4954\n5254 554\n8097 -3845\n-4869 -1340\n-4736 -635\n-8454 -379\n-3059 -4309\n3691 740\n2105 4750\n-8633 1374\n-768 -3402\n-5957 7933\n-2134 648\n2935 6742\n-7749 5019\n839 4387\n840 -4747\n1592 8818\n9629 -1783\n-3737 -3316\n-3979 -6698\n-5326 -6075\n-7504 3636\n-5664 1472\n-487 8283\n7967 -4121\n-5013 3499\n7776 5891\n-677 -8486\n3072 5111\n-6332 -2068\n-8697 -3237\n-274 2298\n-6288 -5025\n6446 -2815\n-131 -3817\n8824 1817\n9983 183\n5598 -299\n-4155 -6736\n82 5723\n-2280 3544\n3026 -5248\n-1008 3210\n-3183 -5734\n-6471 -3840\n8589 3144\n-4883 6781\n684 -4208\n-3287 8030\n8085 2567\n6506 -2242\n478 -8521\n125 6460\n1370 -2203\n-2881 -9112\n911 774\n4258 -6717\n-6432 5404\n4835 -569\n-2470 1672\n3650 6398\n2541 -8650\n-8053 -3010\n-8816 4367\n1277 -7211\n6504 -137\n359 -9698\n3402 4383\n3277 5795\n-9397 -610\n-7570 6048\n-210 8528\n-4039 5441\n-429 -89\n2751 4934\n908 5416\n5723 2613\n3242 684\n-1981 -4368\n-3836 7761\n-6303 -1152\n-5287 -1159\n82 1294\n-1224 2502\n-425 5221\n8627 -2828\n-4666 -3571\n-5185 -7640\n7484 -4842\n426 -2828\n4026 2508\n156 8911\n-6410 -3140\n5708 4617\n-5327 -5904\n6684 -5509\n-7547 -2636\n5840 5032\n-1719 -5328\n-7467 326\n1787 -889\n-226 7103\n5126 6302\n-6535 -3019\n-5618 4988\n-9150 3698\n3343 -1957\n-966 3521\n-2169 4340\n2486 2076\n6064 -2373\n-658 -1698\n-970 7909\n-7122 6862\n3637 -1739\n-7564 -6099\n-3247 -8030\n1780 2342\n5475 121\n-491 -6248\n-1749 1093\n8283 -3223\n4888 4162\n7182 3091\n7451 -705\n-1350 14\n-5468 2269\n6843 3702\n3645 -629\n1038 -9738\n-8759 -4572\n1959 -7428\n-3320 -5492\n7111 4710\n5157 1808\n1137 1523\n6909 285\n-3681 6348\n2362 -4660\n3924 8238\n-5111 -4326\n4445 343\n-6974 -6038\n2357 1066\n-3666 5851\n-3985 6506\n2047 4292\n-3820 -1389\n7848 -2829\n-3277 -4758\n-3595 3444\n2028 8121\n2356 -5617\n-5927 1947\n2233 1463\n-2068 -2556\n3361 3629\n-1870 -5347\n-8198 -4767\n2006 7910\n855 2503\n-8631 3995\n7700 5964\n-111 -1500\n5567 -8211\n-4784 -4601\n-2297 801\n8144 434\n-6665 6581\n6846 6223\n1664 16\n2412 -3984\n5086 867\n-5223 -6234\n4934 4631\n2534 -4696\n-5394 -638\n5597 -6604\n9864 1551\n5685 -2909\n-2314 4994\n-3545 4622\n-1106 -3388\n5909 -203\n2506 5847\n3416 6513\n-4978 -5647\n6997 -7092\n2502 9149\n-4299 6068\n-6797 1900\n-7249 1537\n5150 2595\n7557 315\n1730 235\n-1137 -7053\n-436 992\n1108 -4238\n4023 -3762\n1453 5863\n2507 -651\n6466 -1505\n-2534 6435\n-978 5421\n-7867 1253\n5599 5966\n-3252 -1250\n4140 3993\n-5625 -6322\n-908 6564\n1571 -5301\n653 -8344\n-1727 -4453\n6737 -1164\n-5905 2876\n4380 2240\n-2878 -3608\n-4653 -237\n7339 -6129\n-527 5396\n2370 -2478\n3660 -439\n-444 -8947\n-7171 3567\n769 -4325\n-4012 2266\n-8372 3084\n-4329 6451\n5825 -5615\n9056 2616\n7183 -4236\n-5665 -2232\n2052 -4586\n3191 3550\n-3140 4579\n2106 -829\n-6686 986\n3205 -2933\n1378 -8127\n-4935 2492\n8134 3667\n-233 -5761\n-6400 1588\n395 -5243\n1135 -654\n-3879 -4170\n-579 1959\n8725 -698\n5866 307\n6075 -7560\n-2957 -825\n-6174 -6065\n-7226 6376\n1284 2845\n-6317 1696\n-5453 2148\n-103 7928\n2177 -6896\n-9087 -2234\n-4709 8398\n-8128 301\n-6731 -4549\n1794 -3162\n700 -6484\n6727 -1922\n-828 4484\n-1815 -9314\n-7672 4926\n6926 3268\n-8911 1066\n-21 -406\n-8104 -4806\n-5585 3538\n9085 3993\n8190 -2727\n4983 -8495\n7130 5652\n-2022 -3370\n-3289 -1025\n-8959 884\n-3592 9254\n7957 -4696\n1221 -8264\n-8011 3030\n3656 1110\n2806 -5060\n-2117 6067\n3374 -7368\n-1910 -3820\n-1497 8659\n1462 -1775\n189 -3471\n9584 302\n-2472 5780\n2809 5385\n-7921 -70\n4412 -6132\n660 1207\n-857 6035\n-8506 367\n1687 -3250\n-3075 1690\n-2005 -322\n3169 -2211\n-41 4209\n461 -1673\n4749 -7769\n7407 -5791\n1562 5385\n4917 -7596\n-872 -6358\n6697 2884\n4217 -8228\n2420 -8587\n-9078 -2223\n1055 -4218\n-6772 -159\n-9479 2231\n-2082 3066\n-8365 -1206\n4430 6494\n-2843 2327\n344 -964\n-8772 407\n-6464 2004\n3158 -685\n4780 -5970\n-4412 -3872\n2244 -5005\n-5003 6518\n7537 -6036\n-7390 3231\n107 6227\n-347 5065\n-2936 -4902\n45 6678\n4600 -8005\n169 5361\n1301 -591\n-5154 8074\n897 -3443\n7247 1369\n3987 901\n4679 -826\n-2945 -1865\n-3890 -5228\n1220 -2304\n6999 1795\n-9446 744\n7815 4212\n8586 3340\n-1313 1263\n-633 8299\n3748 -1154\n9780 -296\n6493 3755\n-7405 3541\n6134 2179\n-6319 -3348\n6210 7626\n724 3773\n-1207 -714\n4527 5800\n7592 -5376\n-2416 -1152\n7958 379\n-3094 -470\n-7999 4372\n-5750 -1440\n-2994 -9217\n-7146 -4412\n4031 6196\n7455 4329\n-6049 7610\n3866 -4052\n1544 2135\n9206 986\n3551 2902\n-3837 -2080\n-1481 -5937\n-6054 -5208\n3225 107\n7578 -3559\n9478 -2056\n-5584 4676\n270 9208\n-6391 -5948\n-6510 -6459\n-9561 -2191\n-446 -9586\n-9446 261\n3527 -2008\n-944 2006\n-311 -2515\n-6908 -1647\n-1315 6046\n8309 -4248\n9870 -1210\n8016 -4421\n-1356 -2490\n7823 -1074\n-3566 8105\n3067 -8992\n-1827 -1182\n2099 -2391\n-5953 2574\n4962 2637\n2478 7294\n2546 -6583\n9317 977\n-5652 -661\n-3758 -813\n-93 -6521\n898 9747\n6978 -1218\n1073 9907\n-9288 -1086\n3827 -4371\n2206 2758\n7428 1691\n-5011 -3099\n-4298 838\n-3256 -7701\n-8150 5043\n426 -4174\n6895 4344\n-4357 -40\n5182 -3392\n-9136 -1273\n3402 -4554\n8579 3212\n7684 562\n868 5309\n-6309 -6986\n286 -5154\n2405 393\n8536 7\n8452 3691\n479 8356\n-3904 7020\n951 9545\n-1472 5865\n2065 9357\n-630 1683\n5732 -739\n-5294 -1535\n-3039 -9064\n5596 8208\n2949 1406\n4441 2010\n258 -4524\n3859 116\n-4948 -5976\n8753 -4310\n2130 940\n-3510 6624\n-3682 -2013\n-7440 6117\n5505 1142\n-8515 1993\n-7842 4128\n-3213 5112\n-6238 -3732\n-4341 -1246\n4343 -7406\n9381 2577\n1082 -4003\n1062 -2173\n-587 602\n3890 -2752\n7195 -1933\n-2310 5737\n5362 4848\n-501 4323\n6987 -2215\n5721 -2590\n-1035 9826\n-1141 -8175\n-538 -9813\n-6749 -7299\n4062 -1775\n-7730 2884\n-6372 1214\n-2442 1341\n-4317 -3195\n7761 -4585\n6159 2767\n675 9304\n-5272 4719\n-1169 -6089\n-4999 -99\n1424 5441\n-6868 3929\n-4020 2903\n-2014 -1584\n5099 2026\n-3528 5223\n283 -6911\n4631 -1050\n564 -4021\n4638 2049\n4672 -8377\n-2027 8256\n3352 365\n-3209 -8306\n3505 -2481\n-8929 3501\n-2561 5478\n-5274 7157\n-700 -5159\n2609 -8060\n-4178 2413\n9193 1905\n-3495 6876\n-2302 1045\n-6110 3669\n-3180 -9459\n-8261 -2792\n-2229 -1665\n-4242 2662\n-9658 -429\n33 626\n2449 -7453\n-6304 -4111\n-1067 -3750\n6894 5508\n-3581 2274\n-770 -9867\n7176 3277\n-6048 -7615\n9783 -608\n3114 6948\n5258 4769\n3803 383\n8197 5325\n777 -2617\n-142 1315\n8199 -3079\n7559 455\n7870 3603\n-6488 -6914\n-3233 4941\n2660 -7554\n2736 -2989\n-7637 -2121\n-171 -8320\n-4182 -7556\n-5491 -1358\n8463 -880\n4833 -8282\n-2243 -8950\n-1947 -9244\n7859 -3862\n6632 1588\n-974 7725\n1086 -775\n6835 618\n-410 -2461\n-8158 2956\n2907 -4081\n24 4430\n717 -729\n-1221 7749\n8516 1227\n-5583 -6187\n-6133 3398\n-1582 -1803\n6922 -1958\n928 5543\n-6286 3729\n3359 5545\n-2183 -7247\n-1731 -6367\n-2040 -1787\n-48 4320\n6687 -7071\n-1044 -2532\n-892 9947\n592 -2842\n-8221 -5627\n4305 7731\n-4743 7770\n152 -8544\n4452 -4083\n-7757 6288\n7219 5873\n2279 -4649\n9043 973\n-6813 6692\n-5295 637\n-4862 -993\n-185 3303\n-289 -1542\n6494 5671\n2520 -7592\n8840 -4373\n8686 -2695\n-4773 -6453\n5154 4288\n-129 -655\n-4320 2378\n-6387 559\n-5225 70\n7172 3320\n686 -3983\n-6711 7025\n8953 -3526\n536 7095\n3378 7885\n-5981 2197\n5088 2357\n-1612 -7989\n5217 8349\n7095 -3427\n7457 -527\n-52 7059\n8326 -683\n-8448 3425\n-1379 -1860\n3083 4484\n3933 5052\n-6989 -2968\n3672 -4239\n4317 -5233\n3411 -2281\n-4002 8135\n845 -9327\n969 1567\n-8101 -117\n-3749 -6470\n3344 746\n5896 3369\n6658 6585\n-7446 1214\n-2171 4219\n-6204 -3935\n8639 -1384\n7543 -2292\n1933 2233\n5267 -891\n-1208 -5405\n-5306 658\n-8128 -5409\n3948 -3023\n-7820 -3930\n9554 -1233\n-3109 1322\n1332 -1476\n-6522 -668\n1047 -5449\n-2095 -8614\n1271 -7099\n-1405 1092\n48 1682\n802 8599\n-8425 -4848\n2163 -6826\n-214 -5036\n-4536 -1883\n6217 3008\n1574 -95\n-252 -2698\n-9367 1907\n-4517 7250\n-6509 1907\n-2555 -1824\n4235 5045\n-7689 3679\n-3765 -3223\n-6601 -2525\n2301 2823\n-2564 3840\n597 -9099\n-225 2073\n-3309 2189\n-9418 -609\n3089 57\n-7930 2927\n4052 3262\n760 9223\n-8764 1808\n-7772 1384\n-5443 1991\n-6437 -5215\n6559 -1521\n7794 -2654\n2974 2610\n3054 -162\n-4443 -6765\n1579 903\n-3236 -2974\n3335 5143\n3233 -1386\n-9340 1656\n-6457 7067\n-1171 -5793\n1833 -3112\n316 -4658\n-397 2545\n-7254 5213\n-3013 -9357\n3581 -7869\n-2092 -9432\n-126 -9427\n3584 -1857\n-3075 -4637\n-5089 -4935\n-2027 -7238\n782 -1338\n-8618 -4982\n-1479 -9046\n4770 7721\n7313 1194\n201 3467\n4850 6099\n-449 -2273\n-912 -2738\n-625 4463\n-704 -1727\n773 -5717\n-4191 5881\n3370 3500\n2706 9488\n-3154 -805\n-5411 -7957\n2411 9300\n1404 -188\n-1027 8017\n-2902 242\n197 1112\n2905 -3356\n-5323 -6766\n5425 -350\n5854 -7801\n3057 3322\n2633 8183\n7999 -1865\n6656 4704\n-3697 -1583\n-355 6557\n8332 -4715\n5227 6322\n8112 42\n-4557 6207\n8047 232\n-6348 -6153\n4393 4471\n5481 4882\n-2051 4421\n-54 -9534\n-4986 -1555\n-5016 2138\n-9640 -431\n-1779 -4701\n4894 5877\n2767 3048\n-7936 -4457\n7466 -4055\n2526 -7602\n-2329 -2040\n-4903 1966\n2630 8729\n8728 3273\n-3619 -2726\n6037 636\n-3930 -2093\n-1345 6109\n3746 -979\n-4667 -3141\n1355 610\n5431 -8279\n54 -3035\n4339 1964\n-5382 -839\n-4144 7054\n6644 1572\n-5956 2493\n-8803 1729\n7114 -2461\n-4921 -2225\n-4880 1526\n-2137 995\n-1672 -1557\n-1263 8260\n-3947 -5176\n-2318 1981\n8274 2736\n-8139 2412\n2223 -4418\n-5230 -3158\n48 4347\n1313 7374\n-6846 -3859\n7776 1268\n-2102 3352\n-63 -914\n-4597 -8005\n8204 -4869\n8016 149\n-4341 5802\n-7420 6048\n-3183 -3326\n6676 5938\n6786 -7162\n-5836 5837\n6220 5503\n4199 -5197\n-8428 -936\n-2759 9383\n-1903 -6871\n391 -5591\n6245 -1237\n-8187 -5385\n-2674 -3775\n8117 -1889\n2542 239\n3099 -560\n-3547 1124\n3224 453\n4038 -8040\n3722 7262\n-5789 -2587\n4279 -7429\n-8308 -5505\n3085 7164\n-2197 -6002\n5236 5391\n2619 5559\n-8089 -3859\n8744 -1317\n-1763 240\n-6972 -2065\n-3910 1334\n3281 -6937\n1022 2529\n-3400 -8183\n-5742 214\n4603 7156\n1619 2446\n2475 2342\n-1984 6390\n82 -1689\n-5310 5938\n-4053 -8952\n-8855 1340\n-3890 -818\n5009 6378\n-6201 -5403\n-1592 -4051\n-2435 -333\n652 1910\n1966 5681\n7621 4594\n-6348 -1106\n8693 -456\n-246 404\n5483 -7436\n-683 -6184\n-8184 4359\n1668 3516\n-7449 4777\n2444 7383\n-8066 5895\n-3228 1889\n-5322 4551\n9030 -4244\n4420 2525\n1253 1535\n2421 279\n403 7849\n-7604 1757\n8491 -4328\n-1675 -7426\n4775 -402\n-6710 -1213\n5056 5517\n8959 1692\n-7929 4013\n4284 -4536\n-8208 903\n-3965 6823\n-1302 -5203\n7995 -1746\n-3664 2931\n62 -3687\n-2415 7274\n-1373 9207\n-2314 1225\n8271 2920\n-6029 -3654\n-5616 -7291\n9505 -1122\n-369 -482\n3386 -7623\n4806 -676\n5239 -1280\n656 -4933\n3257 -7347\n-5218 1901\n-1280 6146\n-3355 -7707\n-447 3235\n8652 -4099\n367 2167\n892 -530\n-6002 609\n6463 -3469\n2967 4879\n-5217 -725\n8614 -197\n823 5937\n-8968 -355\n4299 8675\n1073 5917\n8503 -1839\n2926 52\n1008 -5709\n8533 -4936\n6469 5696\n-716 1932\n-2119 -9195\n-2251 8233\n7420 -956\n-1777 -9509\n-5061 1251\n-1169 -7334\n6103 5293\n6300 7363\n3199 -2237\n7388 5712\n6448 4098\n-5453 4370\n-5456 1405\n7169 -2407\n9038 -1500\n-8019 2366\n6744 -6904\n6243 482\n607 -5851\n2765 2104\n8365 4144\n7869 2797\n-5938 5546\n-4398 -5655\n-6807 -5528\n554 6683\n486 9166\n-7259 5143\n808 1637\n-8960 4133\n-1145 9027\n-3357 -7424\n-1019 -854\n1332 7617\n5811 4433\n6013 -7537\n3454 -8504\n-8554 -3866\n3592 -7560\n6319 -827\n9805 650\n-4122 3382\n1029 2127\n2458 -1365\n-6178 -869\n4648 -2546\n6280 -5119\n592 1545\n-2821 -2052\n4581 -3015\n2048 -53\n4247 7363\n3168 1212\n-5061 5371\n9883 1467\n8584 4982\n-1734 -2696\n5215 -3852\n-2801 -643\n-6866 6767\n-3962 5599\n4661 -3478\n-2330 -6419\n-3770 -1844\n4847 -8692\n-1772 8439\n694 -6086\n-2966 -4639\n3055 -5740\n4656 58\n-7660 -4216\n-4400 481\n8354 5386\n459 -9973\n-449 2592\n-4463 -3639\n7363 -4693\n-8797 1134\n8892 -4537\n8772 -4459\n-326 2504\n4249 3853\n4616 -7632\n-3277 1021\n-3341 3312\n7893 -1950\n8566 2419\n133 4174\n-3672 -6971\n-569 -5469\n-640 8582\n3120 -473\n5372 -3940\n-5724 -7885\n1527 927\n-319 9559\n2087 5124\n-9913 -429\n5471 -5188\n4954 -2733\n-6820 -2873\n6112 -7099\n4326 2962\n2649 -1448\n2794 -1660\n807 7642\n4853 3477\n-2016 3466\n5553 -1964\n-9711 2024\n-2990 8700\n6618 -541\n-6109 -6504\n-5922 -182\n-1038 -3726\n-184 -611\n-4261 -6604\n-5047 -6155\n8111 1105\n-4045 8849\n8015 -3338\n2954 9072\n4361 8662\n-387 -1954\n-9030 -318\n-6143 -6777\n3482 -3435\n3705 7732\n-7044 -6914\n4425 5239\n862 1195\n7279 -3241\n-5342 -1956\n2552 -7816\n-7499 1841\n3766 3099\n6486 -2614\n-5362 -3284\n4221 6116\n4015 5135\n3868 -1562\n2567 2742\n-6416 3267\n-6882 -4875\n-8926 -980\n7787 3965\n-343 -1765\n2899 -3612\n7008 -4454\n4378 2642\n-3091 -3343\n-458 5488\n4477 3139\n4209 -208\n-1689 7726\n5999 2015\n1253 -3344\n2313 -443\n1095 -3277\n-3349 5578\n6678 -6101\n-5885 7473\n-1477 4215\n7408 4806\n-936 -8522\n898 -79\n-7873 -3171\n-6951 -4410\n9695 -1778\n3205 1578\n722 -2320\n-1507 5501\n4511 -8542\n-1428 -709\n-6160 139\n-5221 -8349\n-1401 2309\n-2985 524\n321 -9692\n3348 9330\n-4637 -7967\n4885 2173\n-2476 -6245\n-3554 5410\n-6180 1096\n-5326 -2105\n-7099 6477\n4781 -790\n-7564 -1595\n-1592 9284\n-6233 -4578\n4118 4409\n4092 -3350\n-4556 4368\n-4757 -5074\n5842 -4306\n-1238 5808\n731 2166\n-7250 -658\n842 -1165\n-4620 -5\n433 -7497\n3728 7842\n3179 -5256\n3998 1995\n2712 2422\n-4556 4337\n7980 -875\n5741 -5605\n5798 -1090\n7704 -581\n-343 5793\n5608 7558\n3678 2159\n6972 5109\n-8416 785\n6136 6690\n-1717 9161\n-444 -774\n5018 7308\n-719 1951\n-5621 -2616\n4615 6617\n5132 1834\n5817 -86\n-1012 -6671\n-6368 6537\n164 -2168\n2399 1707\n2984 397\n6680 -5081\n-4137 6380\n-2091 -5150\n-596 8486\n-5609 6794\n-358 8506\n-2780 5389\n1189 -587\n6590 7238\n-2327 -2971\n3314 -690\n1676 -6709\n4081 -1080\n9093 511\n1154 -7353\n3724 -8413\n6973 -3639\n-7018 1505\n-9704 -400\n-7674 4407\n-2501 3208\n7833 1816\n2661 -6438\n-990 7249\n-1794 3437\n2816 3583\n-6065 3690\n-4444 192\n14 5466\n2801 -5994\n-2373 4871\n-3804 6898\n-2272 9551\n8780 -899\n3422 -2304\n-5008 2599\n-5793 -5327\n-8560 -445\n3594 -4903\n-1979 -5987\n5698 6801\n1612 812\n-3727 -4434\n3126 4235\n-5550 3214\n-4249 -6274\n-4950 -7309\n683 4075\n-3417 6134\n-4482 -6826\n-229 3953\n5831 5351\n-7268 -4930\n-287 -8696\n8515 -2226\n2274 -6885\n5102 7821\n426 8721\n-1998 730\n2565 2635\n-760 -3195\n1699 -9652\n7937 -3479\n1795 -4461\n-9037 2226\n5828 4804\n-3237 4220\n-2588 -8667\n4455 -821\n-8066 -4858\n3204 9094\n2041 -8895\n-7997 270\n-2124 5069\n-1763 -6088\n-224 4970\n4240 -3053\n5218 6387\n-7853 160\n-3487 -3553\n5125 -3531\n-3147 -8125\n-4993 -222\n2464 730\n3677 -3078\n-2216 -6971\n1869 -3536\n652 7741\n6251 -4728\n-5526 -3260\n-681 -432\n9329 -483\n-6237 -1080\n-1848 -676\n-1635 9599\n7912 -5813\n-2583 -5502\n3984 -4092\n-745 -1671\n6097 804\n5956 7180\n-2495 1377\n-2105 -1665\n1409 -6302\n-7951 -5463\n1664 -719\n-5930 8010\n-7254 6425\n-8740 -4382\n-1562 -7409\n4648 3809\n-9439 -320\n-5246 -6632\n-5437 8028\n9779 -508\n388 8436\n-9508 -372\n-6575 1246\n6217 6835\n237 -3799\n4271 -5613\n5256 -7221\n-4182 8413\n1142 -424\n4563 965\n7519 532\n-2373 -6425\n1114 8176\n2241 7455\n4785 -1982\n-5344 -2072\n9370 48\n-7986 5640\n1102 1689\n-1225 8347\n3417 2665\n3277 -2149\n-6940 534\n-2271 8789\n769 -1740\n-717 -8165\n-6553 4814\n-107 6378\n-6632 6065\n-2924 -2754\n3405 -5425\n1931 -664\n2227 -2045\n-8970 227\n-7846 4254\n-1037 3871\n4694 2079\n6840 -6074\n3758 2852\n-9324 -1579\n-1742 -6023\n-1 1397\n-597 -2877\n-6747 5466\n3429 3283\n-1930 -9546\n-366 -8247\n2023 -3135\n5685 -5575\n-75 -5923\n4662 2826\n-3802 1663\n-1178 -6076\n4606 -7290\n-384 -8426\n6498 -5488\n1911 -3324\n-5762 6081\n2835 4233\n2732 3463\n-7943 5574\n-8355 -1249\n-6032 -7961\n-6289 -4261\n-4913 -1929\n1215 6849\n-6839 -463\n-1656 293\n3083 3366\n-149 7212\n-3620 -4026\n334 1229\n2528 -5304\n-3190 -9436\n8690 422\n1009 -4775\n-959 -2756\n4953 7346\n7393 2750\n956 -4087\n4146 -6199\n-3686 -8811\n7661 2578\n-3721 -5126\n-1644 4991\n1926 -7706\n-9019 -65\n-7826 -1382\n-5864 -7490\n8774 3746\n-8162 -547\n2804 -8884\n8083 -3502\n6713 7100\n7534 4669\n-1190 8416\n8155 3345\n8956 1627\n-6898 -5960\n3953 -7248\n1574 -1796\n-3304 7002\n-3882 54\n3637 2906\n1396 -543\n6970 2848\n-3564 -4711\n3174 969\n",
"output": "30\n-1812 -1984 -9663 5131\n-2586 7859 7423 -4798\n193 8457 -300 2680\n-149 -9041 6425 84\n3329 -5601 -2055 -5156\n4701 3753 -2852 -2578\n-1417 -9909 -5593 -5639\n-7013 2309 -7622 6652\n-5296 -5647 -9646 -1031\n-1275 8332 6134 1727\n-6996 2724 933 4067\n1134 3022 -9377 2501\n6487 -7016 -6730 4775\n9141 -7928 7794 -4177\n-5164 -3440 -2341 -6820\n-5940 2165 -1255 6089\n1691 -1616 347 -8205\n-7966 -6024 -2883 5136\n6899 3888 1191 6179\n-762 7446 2182 2919\n-6843 1720 -8636 -9995\n-2997 -6378 4359 -2044\n-7094 2392 2381 558\n-3241 7718 -2179 -1519\n-358 247 -547 -5282\n-376 -1900 7187 3663\n7470 1828 4310 -103\n-2289 7865 8712 -1962\n-6942 -5180 -1909 326\n3266 3617 3585 1090\n"
}
] |
https://atcoder.jp/contests/abc258/tasks/abc258_a | Problem Statement
AtCoder Beginner Contest usually starts at 21:00 JST and lasts for
100
minutes.
You are given an integer
K
between
0
and
100
(inclusive). Print the time
K
minutes after 21:00 in the
HH:MM
format, where
HH
denotes the hour on the
24
-hour clock and
MM
denotes the minute. If the hour or the minute has just one digit, append a
0
to the beginning to represent it as a
2
-digit integer. | [
{
"input": "63\n",
"output": "22:03\n"
},
{
"input": "45\n",
"output": "21:45\n"
},
{
"input": "100\n",
"output": "22:40\n"
}
] |
https://atcoder.jp/contests/abc258/tasks/abc258_b | Problem Statement
You are given a positive integer
N
.
We have a grid with
N
rows and
N
columns, where the square at the
i
-th row from the top and
j
-th column from the left has a digit
A_{i,j}
written on it.
Assume that the upper and lower edges of this grid are connected, as well as the left and right edges. In other words, all of the following holds.
(N,i)
is just above
(1,i)
, and
(1,i)
is just below
(N,i)
.
(1\le i\le N)
.
(i,N)
is just to the left of
(i,1)
, and
(i,1)
is just to the right of
(i,N)
.
(1\le i\le N)
.
Takahashi will first choose one of the following eight directions: up, down, left, right, and the four diagonal directions. Then, he will start on a square of his choice and repeat moving one square in the chosen direction
N-1
times.
In this process, Takahashi visits
N
squares. Find the greatest possible value of the integer that is obtained by arranging the digits written on the squares visited by Takahashi from left to right in the order visited by him. | [
{
"input": "4\n1161\n1119\n7111\n1811\n",
"output": "9786\n"
},
{
"input": "10\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n1111111111\n",
"output": "1111111111\n"
}
] |
https://atcoder.jp/contests/abc258/tasks/abc258_c | Problem Statement
You are given positive integers
N
and
Q
, and a string
S
of length
N
consisting of lowercase English letters.
Process
Q
queries. Each query is of one of the following two types.
1 x
: Perform the following
x
times in a row: delete the last character of
S
and append it to the beginning.
2 x
: Print the
x
-th character of
S
. | [
{
"input": "3 3\nabc\n2 2\n1 1\n2 2\n",
"output": "b\na\n"
},
{
"input": "10 8\ndsuccxulnl\n2 4\n2 7\n1 2\n2 7\n1 1\n1 2\n1 3\n2 5\n",
"output": "c\nu\nc\nu\n"
}
] |
https://atcoder.jp/contests/abc258/tasks/abc258_d | Problem Statement
We have a video game consisting of
N
stages. The
i
-th stage
(1 \leq i \leq N)
is composed of a movie lasting
A_i
minutes and gameplay lasting
B_i
minutes.
To clear the
i
-th stage for the first time, one must watch the movie and do the gameplay for that stage. For the second and subsequent times, one may skip the movie and do just the gameplay.
In the beginning, only the
1
-st stage is unlocked, and clearing the
i
-th stage
(1 \leq i \leq N - 1)
unlocks the
(i+1)
-th stage.
Find the shortest time needed to clear a stage
X
times in total. Here, if the same stage is cleared multiple times, all of them count. | [
{
"input": "3 4\n3 4\n2 3\n4 2\n",
"output": "18\n"
},
{
"input": "10 1000000000\n3 3\n1 6\n4 7\n1 8\n5 7\n9 9\n2 4\n6 4\n5 1\n3 1\n",
"output": "1000000076\n"
}
] |
https://atcoder.jp/contests/abc258/tasks/abc258_e | Problem Statement
10^{100}
potatoes are coming from a conveyor belt one by one. The weights of the potatoes are described by a sequence
W = (W_0, \dots, W_{N-1})
of length
N
: the weight of the
i
-th potato coming is
W_{(i-1) \bmod N}
, where
(i-1) \bmod N
denotes the remainder when
i - 1
is divided by
N
.
Takahashi will prepare an empty box and then pack the potatoes in order, as follows.
Pack the incoming potato into the box. If the total weight of the potatoes in the box is now
X
or greater, seal that box and prepare a new empty box.
You are given
Q
queries. In the
i
-th query
(1 \leq i \leq Q)
, given a positive integer
K_i
, find the number of potatoes in the
K_i
-th box to be sealed. It can be proved that, under the Constraints of the problem, there will be at least
K_i
sealed boxes. | [
{
"input": "3 2 5\n3 4 1\n1\n2\n",
"output": "2\n3\n"
},
{
"input": "10 5 20\n5 8 5 9 8 7 4 4 8 2\n1\n1000\n1000000\n1000000000\n1000000000000\n",
"output": "4\n5\n5\n5\n5\n"
}
] |
https://atcoder.jp/contests/abc258/tasks/abc258_f | Problem Statement
The roads in the Kingdom of AtCoder, which lies on the xy-plane, are the lines
x=n
and
y=n
for all integers
n
.
Among them, the lines
x=Bn
and
y=Bn
for all integers
n
are main roads.
When Takahashi is at
(x,y)
, he can move to
(x,y-1)
,
(x,y+1)
,
(x+1,y)
, or
(x-1,y)
.
Each move takes
1
second along a main road and
K
seconds otherwise.
Find the minimum number of seconds Takahashi needs to get from
(S_x, S_y)
to
(G_x, G_y)
.
You will have
T
test cases to solve. | [
{
"input": "4\n3 4 2 2 4 4\n5 6 2 3 2 3\n1 1000000000 0 0 1000000000 1000000000\n1000000000 1000000000 500000000 500000000 1000000000 1000000000\n",
"output": "10\n0\n2000000000\n500000000500000000\n"
},
{
"input": "10\n928184439 674654465 203937094 186855052 851783856 805293696\n55480262 448852233 823161539 786348805 550018803 322680316\n891870741 235679524 32164572 497841190 620600021 96487871\n321502816 428964257 499656016 521484999 717623189 824784374\n144040837 680268887 76238777 371138006 350230937 78690135\n768922620 799628518 403830696 60449731 218880692 88319939\n482031503 121412614 472330444 284479575 949635609 427232765\n389524418 132987043 656496997 678732442 23028233 488463974\n857778764 629964237 714551548 739330018 579247790 874251485\n461612428 535402609 555160129 833592114 44418273 287363785\n",
"output": "177606591118701316\n6205925075792263\n30320747646118343\n84136273267803188\n83764071874751489\n118960470930399064\n2929499649126153\n16403238161749820\n84995699148879437\n71771264361119335\n"
}
] |
https://atcoder.jp/contests/abc258/tasks/abc258_g | Problem Statement
You are given a simple undirected graph
G
with
N
vertices.
G
is given as the
N \times N
adjacency matrix
A
. That is, there is an edge between Vertices
i
and
j
if
A_{i,j}
is
1
, and there is not if
A_{i,j}
is
0
.
Find the number of triples of integers
(i,j,k)
satisfying
1 \le i < j < k \le N
such that there is an edge between Vertices
i
and
j
, an edge between Vertices
j
and
k
, and an edge between Vertices
i
and
k
. | [
{
"input": "4\n0011\n0011\n1101\n1110\n",
"output": "2\n"
},
{
"input": "10\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n",
"output": "0\n"
}
] |
https://atcoder.jp/contests/abc258/tasks/abc258_h | Problem Statement
Find the number, modulo
998244353
, of sequences
X
that satisfy all of the following conditions.
Every term in
X
is a positive
odd number
.
The sum of the terms in
X
is
S
.
The prefix sums of
X
contain none of
A_1, \dots, A_N
. Formally, if we define
Y_i = X_1 + \dots + X_i
for each
i
, then
Y_i \neq A_j
holds for all integers
i
and
j
such that
1 \leq i \leq |X|
and
1 \leq j \leq N
. | [
{
"input": "3 7\n2 4 5\n",
"output": "3\n"
},
{
"input": "5 60\n10 20 30 40 50\n",
"output": "37634180\n"
},
{
"input": "10 1000000000000000000\n1 2 4 8 16 32 64 128 256 512\n",
"output": "75326268\n"
}
] |
https://atcoder.jp/contests/arc143/tasks/arc143_a | Problem Statement
Three non-negative integers
A
,
B
, and
C
are written on a blackboard.
You can perform the following two operations any number of times in any order.
Subtract
1
from two of the written integers of your choice.
Subtract
1
from all of the written integers.
Your objective is to make all the numbers on the blackboard
0
.
Determine whether it is achievable. If it is, find the minimum number of times you need to perform an operation to achieve it. | [
{
"input": "2 2 3\n",
"output": "3\n"
},
{
"input": "0 0 1\n",
"output": "-1\n"
},
{
"input": "0 0 0\n",
"output": "0\n"
}
] |
https://atcoder.jp/contests/arc143/tasks/arc143_b | Problem Statement
Find the number of ways, modulo
998244353
, to fill the squares of an
N \times N
grid using each integer from
1
to
N^2
once so that every square satisfies at least one of the following conditions.
In the same column, there is a square containing a number greater than that of the concerned square.
In the same row, there is a square containing a number less than that of the concerned square. | [
{
"input": "2\n",
"output": "8\n"
},
{
"input": "5\n",
"output": "704332752\n"
},
{
"input": "100\n",
"output": "927703658\n"
}
] |
https://atcoder.jp/contests/arc143/tasks/arc143_c | Problem Statement
There are
N
piles of pebbles. Initially, the
i
-th pile has
A_i
pebbles.
Takahashi and Aoki will play a game using these piles.
They will alternately perform the following operation, with Takahashi going first, and the one who becomes unable to do so loses the game.
Choose one or more piles, and remove the following number of pebbles from each chosen pile:
X
pebbles if this operation is performed by Takahashi, and
Y
pebbles if performed by Aoki.
Here, a pile with an insufficient number of pebbles cannot be chosen.
Determine the winner of the game if both players play optimally. | [
{
"input": "2 1 1\n3 3\n",
"output": "First\n"
},
{
"input": "2 1 2\n3 3\n",
"output": "Second\n"
}
] |
https://atcoder.jp/contests/arc143/tasks/arc143_d | Problem Statement
We have two sequences
A_1,\ldots, A_M
and
B_1,\ldots,B_M
consisting of intgers between
1
and
N
(inclusive).
For a string of length
M
consisting of
0
and
1
, consider the following undirected graph with
2N
vertices and
(M+N)
edges corresponding to that string.
If the
i
-th character of the string is
0
, the
i
-th edge connects Vertex
A_i
and Vertex
(B_i+N)
.
If the
i
-th character of the string is
1
, the
i
-th edge connects Vertex
B_i
and Vertex
(A_i+N)
.
The
(j+M)
-th edge connects Vertex
j
and Vertex
(j+N)
.
Here,
i
and
j
are integers such that
1 \leq i \leq M
and
1 \leq j \leq N
,
and the vertices are numbered
1
to
2N
.
Find one string of length
M
consisting of
0
and
1
such that the corresponding undirected graph has the minimum number of bridges.
Notes on bridges
A bridge is an edge of a graph whose removal increases the number of connected components. | [
{
"input": "2 2\n1 1\n2 2\n",
"output": "01\n"
},
{
"input": "6 7\n1 1 2 3 4 4 5\n2 3 3 4 5 6 6\n",
"output": "0100010\n"
}
] |
https://atcoder.jp/contests/arc143/tasks/arc143_e | Problem Statement
We have a tree with
N
vertices.
The vertices are numbered
1
to
N
,
and the
i
-th edge connects Vertex
A_i
and Vertex
B_i
.
Additionally, each vertex has a reversi piece on it.
The status of the piece on each vertex is given by a string
S
:
if the
i
-th character of
S
is
B
, the piece on Vertex
i
is placed with the black side up;
if the
i
-th character of
S
is
W
, the piece on Vertex
i
is placed with the white side up.
Determine whether it is possible to perform the operation below
N
times to remove the pieces from all vertices.
If it is possible, find the lexicographically smallest possible sequence
P_1, P_2, \ldots, P_N
such that Vertices
P_1, P_2, \ldots, P_N
can be chosen in this order during the process.
Choose a vertex containing a piece with the white side up, and remove the piece from that vertex.
Then, flip all pieces on the vertices adjacent to that vertex.
Notes on reversi pieces
A reversi piece has a black side and a white side, and flipping it changes which side faces up.
What is the lexicographical order on sequences?
The following is an algorithm to determine the lexicographical order between different sequences
S
and
T
.
Below, let
S_i
denote the
i
-th element of
S
. Also, if
S
is lexicographically smaller than
T
, we will denote that fact as
S \lt T
; if
S
is lexicographically larger than
T
, we will denote that fact as
S \gt T
.
Let
L
be the smaller of the lengths of
S
and
T
. For each
i=1,2,\dots,L
, we check whether
S_i
and
T_i
are the same.
If there is an
i
such that
S_i \neq T_i
, let
j
be the smallest such
i
. Then, we compare
S_j
and
T_j
. If
S_j
is less than
T_j
(as a number), we determine that
S \lt T
and quit; if
S_j
is greater than
T_j
, we determine that
S \gt T
and quit.
If there is no
i
such that
S_i \neq T_i
, we compare the lengths of
S
and
T
. If
S
is shorter than
T
, we determine that
S \lt T
and quit; if
S
is longer than
T
, we determine that
S \gt T
and quit. | [
{
"input": "4\n1 2\n2 3\n3 4\nWBWW\n",
"output": "1 2 4 3 \n"
},
{
"input": "4\n1 2\n2 3\n3 4\nBBBB\n",
"output": "-1\n"
}
] |
https://atcoder.jp/contests/arc143/tasks/arc143_f | Problem Statement
Given a positive integer
N
, find the number, modulo
998244353
, of subsets
S
of
\{1, 2, \ldots, N\}
that satisfy the following condition.
Every positive integer at most
N
can be represented as the sum of some distinct elements of
S
, and there are at most two such representations. | [
{
"input": "3\n",
"output": "2\n"
},
{
"input": "5\n",
"output": "5\n"
},
{
"input": "1000\n",
"output": "742952024\n"
}
] |
https://atcoder.jp/contests/abc257/tasks/abc257_a | Problem Statement
Find the
X
-th character from the beginning of the string that is obtained by concatenating these characters:
N
copies of
A
's,
N
copies of
B
's, …, and
N
copies of
Z
's, in this order. | [
{
"input": "1 3\n",
"output": "C\n"
},
{
"input": "2 12\n",
"output": "F\n"
}
] |
https://atcoder.jp/contests/abc257/tasks/abc257_b | Problem Statement
There are
N
squares, indexed Square
1
, Square
2
, …, Square
N
, arranged in a row from left to right.
Also, there are
K
pieces. The
i
-th piece from the left is initially placed on Square
A_i
.
Now, we will perform
Q
operations against them.
The
i
-th operation is as follows:
If the
L_i
-th piece from the left is on its rightmost square, do nothing.
Otherwise, move the
L_i
-th piece from the left one square right if there is no piece on the next square on the right; if there is, do nothing.
Print the index of the square on which the
i
-th piece from the left is after the
Q
operations have ended, for each
i=1,2,\ldots,K
. | [
{
"input": "5 3 5\n1 3 4\n3 3 1 1 2\n",
"output": "2 4 5\n"
},
{
"input": "2 2 2\n1 2\n1 2\n",
"output": "1 2\n"
},
{
"input": "10 6 9\n1 3 5 7 8 9\n1 2 3 4 5 6 5 6 2\n",
"output": "2 5 6 7 9 10\n"
}
] |
https://atcoder.jp/contests/abc257/tasks/abc257_c | Problem Statement
There are
N
people, each of whom is either a child or an adult. The
i
-th person has a weight of
W_i
.
Whether each person is a child or an adult is specified by a string
S
of length
N
consisting of
0
and
1
.
If the
i
-th character of
S
is
0
, then the
i
-th person is a child; if it is
1
, then the
i
-th person is an adult.
When Takahashi the robot is given a real number
X
,
Takahashi judges a person with a weight less than
X
to be a child and a person with a weight more than or equal to
X
to be an adult.
For a real value
X
, let
f(X)
be the number of people whom Takahashi correctly judges whether they are children or adults.
Find the maximum value of
f(X)
for all real values of
X
. | [
{
"input": "5\n10101\n60 45 30 40 80\n",
"output": "4\n"
},
{
"input": "3\n000\n1 2 3\n",
"output": "3\n"
},
{
"input": "5\n10101\n60 50 50 50 60\n",
"output": "4\n"
}
] |
https://atcoder.jp/contests/abc257/tasks/abc257_d | Problem Statement
There are
N
trampolines on a two-dimensional planar town where Takahashi lives. The
i
-th trampoline is located at the point
(x_i, y_i)
and has a power of
P_i
. Takahashi's jumping ability is denoted by
S
. Initially,
S=0
. Every time Takahashi trains,
S
increases by
1
.
Takahashi can jump from the
i
-th to the
j
-th trampoline if and only if:
P_iS\geq |x_i - x_j| +|y_i - y_j|
.
Takahashi's objective is to become able to choose a starting trampoline such that he can reach any trampoline from the chosen one with some jumps.
At least how many times does he need to train to achieve his objective? | [
{
"input": "4\n-10 0 1\n0 0 5\n10 0 1\n11 0 1\n",
"output": "2\n"
},
{
"input": "7\n20 31 1\n13 4 3\n-10 -15 2\n34 26 5\n-2 39 4\n0 -50 1\n5 -20 2\n",
"output": "18\n"
}
] |
https://atcoder.jp/contests/abc257/tasks/abc257_e | Problem Statement
Takahashi has an integer
x
. Initially,
x=0
.
Takahashi may do the following operation any number of times.
Choose an integer
i\ (1\leq i \leq 9)
. Pay
C_i
yen (the currency in Japan) to replace
x
with
10x + i
.
Takahashi has a budget of
N
yen. Find the maximum possible value of the final
x
resulting from operations without exceeding the budget. | [
{
"input": "5\n5 4 3 3 2 5 3 5 3\n",
"output": "95\n"
},
{
"input": "20\n1 1 1 1 1 1 1 1 1\n",
"output": "99999999999999999999\n"
}
] |
https://atcoder.jp/contests/abc257/tasks/abc257_f | Problem Statement
There are
N
towns
numbered Town
1
, Town
2
,
\ldots
, Town
N
.
There are also
M
Teleporters
, each of which connects two towns bidirectionally so that a person can travel from one to the other in one minute.
The
i
-th Teleporter connects Town
U_i
and Town
V_i
bidirectionally.
However, for some of the Teleporters, one of the towns it connects is undetermined;
U_i=0
means that one of the towns the
i
-th Teleporter connects is Town
V_i
,
but the other end is undetermined.
For
i=1,2,\ldots,N
, answer the following question.
When the Teleporters with undetermined ends are all determined to be connected to Town
i
,
how many minutes is required at minimum to travel from Town
1
to Town
N
?
If it is impossible to travel from Towns
1
to
N
using Teleporters only, print
-1
instead. | [
{
"input": "3 2\n0 2\n1 2\n",
"output": "-1 -1 2\n"
},
{
"input": "5 5\n1 2\n1 3\n3 4\n4 5\n0 2\n",
"output": "3 3 3 3 2\n"
}
] |
https://atcoder.jp/contests/abc257/tasks/abc257_g | Problem Statement
You are given two strings
S
and
T
consisting of lowercase English letters.
Find the minimum positive integer
k
such that you can choose (not necessarily distinct)
k
prefixes of
S
so that their concatenation coincides with
T
.
In other words, find the minimum positive integer
k
such that
there exists a
k
-tuple
(a_1,a_2,\ldots, a_k)
of integers between
1
and
|S|
such that
T=S_{a_1}+S_{a_2}+\cdots +S_{a_k}
,
where
S_i
denotes the substring of
S
from the
1
-st through the
i
-th characters and
+
denotes the concatenation of strings.
If it is impossible to make it coincide with
T
, print
-1
instead. | [
{
"input": "aba\nababaab\n",
"output": "3\n"
},
{
"input": "atcoder\nac\n",
"output": "-1\n"
}
] |
https://atcoder.jp/contests/abc257/tasks/abc257_h | Problem Statement
The six-sided dice speciality shop "Saikoroya" sells
N
dice. The
i
-th die (singular of dice) has
A_{i,1},A_{i,2},\ldots,A_{i,6}
written on its each side, and has a price of
C_i
.
Takahashi is going to choose exactly
K
of them and buy them.
Currently, "Saikoroya" is conducting a promotion: Takahashi may roll each of the purchased dice once and claim money whose amount is equal to the square of the sum of the numbers shown by the dice. Here, each die shows one of the six numbers uniformly at random and independently.
Maximize the expected value of (the amount of money he claims) - (the sum of money he pays for the purchased
K
dice) by properly choosing
K
dice to buy. Print the maximized expected value modulo
998244353
.
Definition of the expected value modulo
998244353
We can prove that the sought expected value is always a rational number.
Moreover, under the Constraints of this problem, the sought expected value can be expressed by an irreducible fraction
\frac{y}{x}
where
x
is indivisible by
998244353
.
In this case, we can uniquely determine the integer
z
between
0
and
998244352
(inclusive) such that
xz \equiv y \pmod{998244353}
. Print such
z
. | [
{
"input": "3 2\n1 2 3\n1 1 1 1 1 1\n2 2 2 2 2 2\n3 3 3 3 3 3\n",
"output": "20\n"
},
{
"input": "10 5\n2 5 6 5 2 1 7 9 7 2\n5 5 2 4 7 6\n2 2 8 7 7 9\n8 1 9 6 10 8\n8 6 10 3 3 9\n1 10 5 8 1 10\n7 8 4 8 6 5\n1 10 2 5 1 7\n7 4 1 4 5 4\n5 10 1 5 1 2\n5 1 2 3 6 2\n",
"output": "1014\n"
}
] |
https://atcoder.jp/contests/arc142/tasks/arc142_a | Problem Statement
For a positive integer
x
, let
f(x)
be the answer to the question below.
The following operation on
x
can be performed zero or more times.
Let
x'
be the integer obtained by reversing the decimal notation of
x
. Then, replace
x
with
x'
. If
x
now has one or more leading zeros, delete them so that it begins with a non-zero digit.
For example, from
x=1420
, you get
x=241
after one operation,
x=142
after two operations, and
x=241
after three operations.
Find the minimum possible value of
x
after operations.
Find the number of integers
x
such that
1 \leq x \leq N
and
f(x)=K
. | [
{
"input": "1420 142\n",
"output": "3\n"
},
{
"input": "1419 142\n",
"output": "2\n"
},
{
"input": "6 19\n",
"output": "0\n"
}
] |
https://atcoder.jp/contests/arc142/tasks/arc142_b | Problem Statement
We have an
N \times N
grid. Let
(i,j)
denote the square at the
i
-th row from the top and
j
-th column from the left in this grid.
Find one way to write an integer on every square to satisfy the conditions below.
Each integer between
1
and
N^2
is written exactly once.
For every pair of integers
i,j\, (1 \leq i,j \leq N)
, the square
(i,j)
satisfies the following.
Among the squares horizontally, vertically, or diagonally adjacent to
(i,j)
(there are at most eight of them), let
a
and
b
be the number of squares with integers larger than and smaller than that of
(i,j)
, respectively. Then,
a \neq b
holds.
Under the Constraints of this problem, it can be proved that such a way to write integers always exists. | [
{
"input": "2\n",
"output": "1 2\n3 4\n"
},
{
"input": "3\n",
"output": "1 2 3\n5 4 6\n7 8 9\n"
}
] |
https://atcoder.jp/contests/arc142/tasks/arc142_c | Problem Statement
There is a tree with
N
vertices, numbered
1, \ldots, N
.
For each pair of integers
u,v\, (1 \leq u,v \leq N)
, the distance
d_{u,v}
between Vertices
u, v
is defined as the following.
The number of edges contained in the shortest path connecting Vertices
u
and
v
.
You are allowed to ask between
0
and
2N
questions (inclusive) in the following form.
Ask the distance
d_{u,v}
between Vertices
u,v
for integers
u,v
of your choice such that
1\leq u,v \leq N
and
u+v>3
.
Find the distance
d_{1,2}
between Vertices
1,2
. | [] |
https://atcoder.jp/contests/arc142/tasks/arc142_d | Problem Statement
We have a tree with
N
vertices, numbered
1, \ldots, N
.
For each
i=1,\ldots,N-1
, the
i
-th edge connects Vertex
a_i
and Vertex
b_i
.
An operation on this tree when at most one piece is put on each vertex is defined as follows.
Simultaneously move every piece to one of the vertices adjacent to the one occupied by the piece.
An operation is said to be
good
when the conditions below are satisfied.
Each edge is traversed by at most one piece.
Each vertex will be occupied by at most one piece after the operation.
Takahashi will put a piece on one or more vertices of his choice. Among the
2^N-1
ways to put pieces, find the number of ones that satisfy the condition below, modulo
998244353
.
For every non-negative integer
K
, the following holds.
It is possible to perform a good operation
K
times.
Let
S_K
be the set of vertices occupied by pieces just after
K
good operations. Then,
S_K
is unique. | [
{
"input": "3\n1 2\n1 3\n",
"output": "2\n"
},
{
"input": "7\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n",
"output": "0\n"
},
{
"input": "19\n9 14\n2 13\n1 3\n17 19\n13 18\n12 19\n4 5\n2 10\n4 9\n8 11\n3 15\n6 8\n8 10\n6 19\n9 13\n11 15\n7 17\n16 17\n",
"output": "100\n"
}
] |
https://atcoder.jp/contests/arc142/tasks/arc142_e | Problem Statement
There are
N
wizards, numbered
1, \ldots, N
.
Wizard
i
has a strength of
a_i
and plans to defeat a monster with a strength of
b_i
.
You can perform the following operation any number of times.
Increase the strength of any wizard of your choice by
1
.
A pair of Wizard
i
and Wizard
j
(let us call this pair
(i, j)
) is said to be
good
when at least one of the following conditions is satisfied.
Wizard
i
has a strength of at least
b_i
and Wizard
j
has a strength of at least
b_j
.
Wizard
i
has a strength of at least
b_j
and Wizard
j
has a strength of at least
b_i
.
Your objective is to make the pair
(x_i, y_i)
good for every
i=1, \ldots, M
.
Find the minimum number of operations needed to achieve it. | [
{
"input": "5\n1 5\n2 4\n3 3\n4 2\n5 1\n3\n1 4\n2 5\n3 5\n",
"output": "2\n"
},
{
"input": "4\n1 1\n1 1\n1 1\n1 1\n3\n1 2\n2 3\n3 4\n",
"output": "0\n"
},
{
"input": "9\n1 1\n2 4\n5 5\n7 10\n9 3\n9 13\n10 9\n3 9\n2 9\n7\n1 5\n2 5\n1 6\n2 4\n3 4\n4 9\n8 9\n",
"output": "22\n"
}
] |
https://atcoder.jp/contests/arc142/tasks/arc142_f | Problem Statement
Two wizards,
X
and
Y
, are fighting with a monster.
Initially, each of the wizards has a magic power of
0
. They know the following two spells.
Spell
1
: Increases the caster's magic power by
1
.
Spell
2
: Deals damage equal to the caster's magic power to the monster.
After each wizard uses a spell
N
times, they will withdraw from the battle.
For each
i=1, \ldots, N
, they must use one of the following combinations of spells for their
i
-th spells.
X
casts Spell
a_i
, and
Y
casts Spell
b_i
.
X
casts Spell
c_i
, and
Y
casts Spell
d_i
.
Find the maximum total damage that can be dealt to the monster before the withdrawal. | [
{
"input": "3\n1 1 2 2\n2 1 2 2\n2 1 1 1\n",
"output": "3\n"
},
{
"input": "5\n2 2 2 2\n2 2 2 2\n2 2 2 2\n2 2 2 2\n2 2 2 2\n",
"output": "0\n"
},
{
"input": "8\n1 1 2 2\n2 2 2 1\n1 1 2 1\n1 1 2 2\n2 1 1 1\n1 2 1 2\n2 1 1 2\n2 1 2 1\n",
"output": "20\n"
},
{
"input": "20\n2 1 2 1\n2 1 1 1\n1 2 1 1\n2 2 1 2\n2 2 2 1\n1 1 2 1\n1 2 2 2\n2 2 2 1\n1 1 1 2\n1 2 1 2\n1 2 2 2\n2 1 1 2\n2 1 1 1\n1 2 1 2\n1 2 1 2\n1 1 1 2\n1 1 2 1\n2 2 1 1\n1 2 2 2\n2 1 1 2\n",
"output": "138\n"
}
] |
https://atcoder.jp/contests/abc256/tasks/abc256_a | Problem Statement
Given
N
, print
2^N
. | [
{
"input": "3\n",
"output": "8\n"
},
{
"input": "30\n",
"output": "1073741824\n"
}
] |
https://atcoder.jp/contests/abc256/tasks/abc256_b | Problem Statement
Takahashi is trying to create a game inspired by baseball, but he is having difficulty writing the code.
Write a program for Takahashi that solves the following problem.
There are
4
squares called Square
0
, Square
1
, Square
2
, and Square
3
. Initially, all squares are empty.
There is also an integer
P
; initially,
P = 0
.
Given a sequence of positive integers
A = (A_1, A_2, \dots, A_N)
, perform the following operations for
i = 1, 2, \dots, N
in this order:
Put a piece on Square
0
.
Advance every piece on the squares
A_i
squares ahead. In other words, if Square
x
has a piece, move the piece to Square
(x + A_i)
.
If, however, the destination square does not exist (i.e.
x + A_i
is greater than or equal to
4
) for a piece, remove it. Add to
P
the number of pieces that have been removed.
Print the value of
P
after all the operations have been performed. | [
{
"input": "4\n1 1 3 2\n",
"output": "3\n"
},
{
"input": "3\n1 1 1\n",
"output": "0\n"
},
{
"input": "10\n2 2 4 1 1 1 4 2 2 1\n",
"output": "8\n"
}
] |
https://atcoder.jp/contests/abc256/tasks/abc256_c | Problem Statement
You are given six integers:
h_1, h_2, h_3, w_1, w_2
, and
w_3
.
Consider writing a
positive
integer on each square of a
3 \times 3
grid so that all of the following conditions are satisfied:
For
i=1,2,3
, the sum of numbers written in the
i
-th row from the top is
h_i
.
For
j=1,2,3
, the sum of numbers written in the
j
-th column from the left is
w_i
.
For example, if
(h_1, h_2, h_3) = (5, 13, 10)
and
(w_1, w_2, w_3) = (6, 13, 9)
, then all of the following three ways satisfy the conditions. (There are other ways to satisfy the conditions.)
How many ways are there to write numbers to satisfy the conditions? | [
{
"input": "3 4 6 3 3 7\n",
"output": "1\n"
},
{
"input": "3 4 5 6 7 8\n",
"output": "0\n"
},
{
"input": "5 13 10 6 13 9\n",
"output": "120\n"
},
{
"input": "20 25 30 22 29 24\n",
"output": "30613\n"
}
] |
https://atcoder.jp/contests/abc256/tasks/abc256_d | Problem Statement
For real numbers
L
and
R
, let us denote by
[L,R)
the set of real numbers greater than or equal to
L
and less than
R
. Such a set is called a right half-open interval.
You are given
N
right half-open intervals
[L_i,R_i)
. Let
S
be their union. Represent
S
as a union of the minimum number of right half-open intervals. | [
{
"input": "3\n10 20\n20 30\n40 50\n",
"output": "10 30\n40 50\n"
},
{
"input": "3\n10 40\n30 60\n20 50\n",
"output": "10 60\n"
}
] |
https://atcoder.jp/contests/abc256/tasks/abc256_e | Problem Statement
There are
N
people numbered
1
through
N
.
Takahashi has decided to choose a sequence
P = (P_1, P_2, \dots, P_N)
that is a permutation of integers from
1
through
N
, and give a candy to Person
P_1
, Person
P_2
,
\dots
, and Person
P_N
, in this order.
Since Person
i
dislikes Person
X_i
, if Takahashi gives a candy to Person
X_i
prior to Person
i
, then Person
i
gains frustration of
C_i
; otherwise, Person
i
's frustration is
0
.
Takahashi may arbitrarily choose
P
. What is the minimum possible sum of their frustration? | [
{
"input": "3\n2 3 2\n1 10 100\n",
"output": "10\n"
},
{
"input": "8\n7 3 5 5 8 4 1 2\n36 49 73 38 30 85 27 45\n",
"output": "57\n"
}
] |
https://atcoder.jp/contests/abc256/tasks/abc256_f | Problem Statement
You are given
N
,
Q
, and
A=(A_1,\ldots,A_N)
.
Process
Q
queries, each of which is of one of the following two kinds:
1 x v
: update
A_x
to
v
.
2 x
: let
B_i=\sum_{j=1}^{i}A_j
,
C_i=\sum_{j=1}^{i}B_j
, and
D_i=\sum_{j=1}^{i}C_j
. Print
D_x
modulo
998244353
. | [
{
"input": "3 3\n1 2 3\n2 3\n1 2 0\n2 3\n",
"output": "15\n9\n"
},
{
"input": "2 1\n998244353 998244353\n2 1\n",
"output": "0\n"
}
] |
https://atcoder.jp/contests/abc256/tasks/abc256_g | Problem Statement
There is a regular
N
-gon with side length
D
.
Starting from a vertex, we place black or white stones on the circumference at intervals of
1
. As a result, each edge of the
N
-gon will have
(D+1)
stones on it, for a total of
ND
stones.
How many ways are there to place stones so that all edges have the same number of white stones on them? Find the count modulo
998244353
. | [
{
"input": "3 2\n",
"output": "10\n"
},
{
"input": "299792458 3141\n",
"output": "138897974\n"
}
] |
https://atcoder.jp/contests/abc256/tasks/abc256_h | Problem Statement
You are given
N
,
Q
, and
A=(a_1,\ldots,a_N)
.
Process
Q
queries described below. Each query is of one of the following three kinds:
1 L R x
: for
i=L,L+1,\dots,R
, update the value of
a_i
to
\displaystyle \left\lfloor \frac{a_i}{x} \right\rfloor
.
2 L R y
: for
i=L,L+1,\dots,R
, update the value of
a_i
to
y
.
3 L R
: print
\displaystyle\sum_{i=L}^R a_i
. | [
{
"input": "3 5\n2 5 6\n3 1 3\n1 2 3 2\n3 1 2\n2 1 2 3\n3 1 3\n",
"output": "13\n4\n9\n"
},
{
"input": "6 11\n10 3 5 20 6 7\n3 1 6\n1 2 4 3\n3 1 3\n2 1 4 10\n3 3 6\n1 3 6 2\n2 1 4 5\n3 1 6\n2 1 3 100\n1 2 5 6\n3 1 4\n",
"output": "51\n12\n33\n26\n132\n"
}
] |
https://atcoder.jp/contests/abc255/tasks/abc255_a | Problem Statement
Given integers
R
,
C
, and a
2 \times 2
matrix
A
, print
A_{R,C}
. | [
{
"input": "1 2\n1 0\n0 1\n",
"output": "0\n"
},
{
"input": "2 2\n1 2\n3 4\n",
"output": "4\n"
},
{
"input": "2 1\n90 80\n70 60\n",
"output": "70\n"
}
] |
https://atcoder.jp/contests/abc255/tasks/abc255_b | Problem Statement
There are
N
people numbered
1, 2, \dots, N
in the
xy
-plane. Person
i
is at the coordinates
(X_i, Y_i)
.
K
of these people, Persons
A_1, A_2, \dots, A_K
, will receive lights of the same strength.
When a person at coordinates
(x, y)
has a light of strength
R
, it lights up the interior of a circle of radius
R
centered at
(x, y)
(including the boundary).
Find the minimum strength of the lights needed for every person to be lit by at least one light. | [
{
"input": "4 2\n2 3\n0 0\n0 1\n1 2\n2 0\n",
"output": "2.23606797749978969\n"
},
{
"input": "2 1\n2\n-100000 -100000\n100000 100000\n",
"output": "282842.712474619009\n"
},
{
"input": "8 3\n2 6 8\n-17683 17993\n93038 47074\n58079 -57520\n-41515 -89802\n-72739 68805\n24324 -73073\n71049 72103\n47863 19268\n",
"output": "130379.280458974768\n"
}
] |
https://atcoder.jp/contests/abc255/tasks/abc255_c | Problem Statement
You are given an integer
X
. The following action on this integer is called an
operation
.
Choose and do one of the following.
Add
1
to
X
.
Subtract
1
from
X
.
The terms in the arithmetic progression
S
with
N
terms whose initial term is
A
and whose common difference is
D
are called
good numbers
.
Consider performing zero or more operations to make
X
a good number. Find the minimum number of operations required to do so. | [
{
"input": "6 2 3 3\n",
"output": "1\n"
},
{
"input": "0 0 0 1\n",
"output": "0\n"
},
{
"input": "998244353 -10 -20 30\n",
"output": "998244363\n"
},
{
"input": "-555555555555555555 -1000000000000000000 1000000 1000000000000\n",
"output": "444445\n"
}
] |
https://atcoder.jp/contests/abc255/tasks/abc255_d | Problem Statement
You are given a sequence of length
N
:
A=(A_1,A_2,\dots,A_N)
. The following action on this sequence is called an
operation
.
First, choose an integer
i
such that
1 \le i \le N
.
Next, choose and do one of the following.
Add
1
to
A_i
.
Subtract
1
from
A_i
.
Answer
Q
questions.
The
i
-th question is the following.
Consider performing zero or more operations to change every element of
A
to
X_i
. Find the minimum number of operations required to do so. | [
{
"input": "5 3\n6 11 2 5 5\n5\n20\n0\n",
"output": "10\n71\n29\n"
},
{
"input": "10 5\n1000000000 314159265 271828182 141421356 161803398 0 777777777 255255255 536870912 998244353\n555555555\n321654987\n1000000000\n789456123\n0\n",
"output": "3316905982\n2811735560\n5542639502\n4275864946\n4457360498\n"
}
] |
https://atcoder.jp/contests/abc255/tasks/abc255_e | Problem Statement
You are given a sequence of
N-1
integers
S = (S_1, S_2, \ldots, S_{N-1})
, and
M
distinct integers
X_1, X_2, \ldots, X_M
, which are called
lucky numbers
.
A sequence of
N
integers
A = (A_1, A_2, \ldots, A_N)
satisfying the following condition is called a
good sequence
.
A_i + A_{i+1} = S_i
holds for every
i = 1, 2, \ldots, N-1
.
Find the maximum possible number of terms that are lucky numbers in a good sequence
A
, that is, the maximum possible number of integers
i
between
1
and
N
such that
A_i \in \lbrace X_1, X_2, \ldots, X_M \rbrace
. | [
{
"input": "9 2\n2 3 3 4 -4 -7 -4 -1\n-1 5\n",
"output": "4\n"
},
{
"input": "20 10\n-183260318 206417795 409343217 238245886 138964265 -415224774 -499400499 -313180261 283784093 498751662 668946791 965735441 382033304 177367159 31017484 27914238 757966050 878978971 73210901\n-470019195 -379631053 -287722161 -231146414 -84796739 328710269 355719851 416979387 431167199 498905398\n",
"output": "8\n"
}
] |
https://atcoder.jp/contests/abc255/tasks/abc255_f | Problem Statement
Consider a
binary tree
with
N
vertices numbered
1, 2, \ldots, N
. Here, a binary tree is a rooted tree where each vertex has at most two children. Specifically, each vertex in a binary tree has at most one
left child
and at most one
right child
.
Determine whether there exists a binary tree rooted at Vertex
1
satisfying the conditions below, and present such a tree if it exists.
The depth-first traversal of the tree in
pre-order
is
(P_1, P_2, \ldots, P_N)
.
The depth-first traversal of the tree in
in-order
is
(I_1, I_2, \ldots, I_N)
. | [
{
"input": "6\n1 3 5 6 4 2\n3 5 1 4 6 2\n",
"output": "3 6\n0 0\n0 5\n0 0\n0 0\n4 2\n"
},
{
"input": "2\n2 1\n1 2\n",
"output": "-1\n"
}
] |
https://atcoder.jp/contests/abc255/tasks/abc255_g | Problem Statement
Takahashi and Aoki will play a game against each other using
N
piles of stones.
Initially, for each
i = 1, 2, \ldots, N
, the
i
-th pile is composed of
A_i
stones.
The players alternately perform the following action, with Takahashi going first.
Choose a pile with at least one stone remaining, and remove one or more stones.
However, there are
M
forbidden moves.
For each
i = 1, 2, \ldots, M
, it is not allowed to remove exactly
Y_i
stones from a pile composed of exactly
X_i
stones.
The first player to become unable to perform the action loses, resulting in the other player's victory.
Which player will win when both players employ the optimal strategy for the victory? | [
{
"input": "3 4\n1 2 4\n2 1\n3 3\n3 1\n1 1\n",
"output": "Takahashi\n"
},
{
"input": "1 5\n5\n5 1\n5 2\n5 3\n5 4\n5 5\n",
"output": "Aoki\n"
}
] |
https://atcoder.jp/contests/abc255/tasks/abc255_h | Problem Statement
There are
N
trees. On Day
0
, each tree bears no fruits.
On the morning of Day
1
and subsequent days, the
i
-th tree bears
i
new fruits for each
i = 1, 2, \ldots, N
.
Takahashi will perform
Q
harvesting.
For each
i = 1, 2, \ldots, Q
, the
i
-th harvesting takes place on the night of Day
D_i
, collecting all fruits remaining on the
L_i
-th through
R_i
-th trees at that point.
For each of the
Q
harvesting, print the number of fruits Takahashi will collect, modulo
998244353
. | [
{
"input": "5 3\n2 2 3\n3 3 4\n5 1 5\n",
"output": "10\n15\n50\n"
},
{
"input": "711741968710511029 1\n82803157126515475 516874290286751784 588060532191410838\n",
"output": "603657470\n"
}
] |
https://atcoder.jp/contests/abc254/tasks/abc254_a | Problem Statement
You are given an integer
N
at least
100
. Print the last two digits of
N
.
Strictly speaking, print the tens and ones digits of
N
in this order. | [
{
"input": "254\n",
"output": "54\n"
},
{
"input": "101\n",
"output": "01\n"
}
] |
https://atcoder.jp/contests/abc254/tasks/abc254_b | Problem Statement
Find the
N
integer sequences
A_0,\ldots,A_{N-1}
defined as follows.
For each
i
(0\leq i \leq N-1)
, the length of
A_i
is
i+1
.
For each
i
and
j
(0\leq i \leq N-1, 0 \leq j \leq i)
, the
(j+1)
-th term of
A_i
, denoted by
a_{i,j}
, is defined as follows.
a_{i,j}=1
, if
j=0
or
j=i
.
a_{i,j} = a_{i-1,j-1} + a_{i-1,j}
, otherwise. | [
{
"input": "3\n",
"output": "1\n1 1\n1 2 1\n"
},
{
"input": "10\n",
"output": "1\n1 1\n1 2 1\n1 3 3 1\n1 4 6 4 1\n1 5 10 10 5 1\n1 6 15 20 15 6 1\n1 7 21 35 35 21 7 1\n1 8 28 56 70 56 28 8 1\n1 9 36 84 126 126 84 36 9 1\n"
}
] |
https://atcoder.jp/contests/abc254/tasks/abc254_c | Problem Statement
We have a sequence of length
N
:
A=(a_1,\ldots,a_N)
. Additionally, you are given an integer
K
.
You can perform the following operation zero or more times.
Choose an integer
i
such that
1 \leq i \leq N-K
, then swap the values of
a_i
and
a_{i+K}
.
Determine whether it is possible to sort
A
in ascending order. | [
{
"input": "5 2\n3 4 1 3 4\n",
"output": "Yes\n"
},
{
"input": "5 3\n3 4 1 3 4\n",
"output": "No\n"
},
{
"input": "7 5\n1 2 3 4 5 5 10\n",
"output": "Yes\n"
}
] |
https://atcoder.jp/contests/abc254/tasks/abc254_d | Problem Statement
You are given an integer
N
. Find the number of pairs
(i,j)
of positive integers at most
N
that satisfy the following condition:
i \times j
is a square number. | [
{
"input": "4\n",
"output": "6\n"
},
{
"input": "254\n",
"output": "896\n"
}
] |
https://atcoder.jp/contests/abc254/tasks/abc254_e | Problem Statement
We have a simple undirected graph with
N
vertices and
M
edges. The vertices are numbered
1,\ldots,N
. For each
i=1,\ldots,M
, the
i
-th edge connects Vertex
a_i
and Vertex
b_i
. Additionally,
the degree of each vertex is at most
3
.
For each
i=1,\ldots,Q
, answer the following query.
Find the sum of indices of vertices whose distances from Vertex
x_i
are at most
k_i
. | [
{
"input": "6 5\n2 3\n3 4\n3 5\n5 6\n2 6\n7\n1 1\n2 2\n2 0\n2 3\n4 1\n6 0\n4 3\n",
"output": "1\n20\n2\n20\n7\n6\n20\n"
}
] |
https://atcoder.jp/contests/abc254/tasks/abc254_f | Problem Statement
You are given a positive integer
N
and sequences of
N
positive integers each:
A=(A_1,A_2,\dots,A_N)
and
B=(B_1,B_2,\dots,B_N)
.
We have an
N \times N
grid. The square at the
i
-th row from the top and the
j
-th column from the left is called the square
(i,j)
. For each pair of integers
(i,j)
such that
1 \le i,j \le N
, the square
(i,j)
has the integer
A_i + B_j
written on it. Process
Q
queries of the following form.
You are given a quadruple of integers
h_1,h_2,w_1,w_2
such that
1 \le h_1 \le h_2 \le N,1 \le w_1 \le w_2 \le N
. Find the greatest common divisor of the integers contained in the rectangle region whose top-left and bottom-right corners are
(h_1,w_1)
and
(h_2,w_2)
, respectively. | [
{
"input": "3 5\n3 5 2\n8 1 3\n1 2 2 3\n1 3 1 3\n1 1 1 1\n2 2 2 2\n3 3 1 1\n",
"output": "2\n1\n11\n6\n10\n"
},
{
"input": "1 1\n9\n100\n1 1 1 1\n",
"output": "109\n"
}
] |
https://atcoder.jp/contests/abc254/tasks/abc254_g | Problem Statement
There is a complex composed of
N
10^9
-story skyscrapers. The skyscrapers are numbered
1
to
N
, and the floors are numbered
1
to
10^9
.
From any floor of any skyscraper, one can use a skybridge to get to the same floor of any other skyscraper in one minute.
Additionally, there are
M
elevators. The
i
-th elevator runs between Floor
B_i
and Floor
C_i
of Skyscraper
A_i
. With this elevator, one can get from Floor
x
to Floor
y
of Skyscraper
A_i
in
|x-y|
minutes, for every pair of integers
x,y
such that
B_i \le x,y \le C_i
.
Answer the following
Q
queries.
Determine whether it is possible to get from Floor
Y_i
of Skyscraper
X_i
to Floor
W_i
of Skyscraper
Z_i
, and find the shortest time needed to get there if it is possible. | [
{
"input": "3 4 3\n1 2 10\n2 3 7\n3 9 14\n3 1 3\n1 3 3 14\n3 1 2 7\n1 100 1 101\n",
"output": "12\n7\n-1\n"
},
{
"input": "1 1 1\n1 1 2\n1 1 1 2\n",
"output": "1\n"
}
] |
https://atcoder.jp/contests/abc254/tasks/abc254_h | Problem Statement
You are given multisets with
N
non-negative integers each:
A=\{ a_1,\ldots,a_N \}
and
B=\{ b_1,\ldots,b_N \}
.
You can perform the operations below any number of times in any order.
Choose a non-negative integer
x
in
A
. Delete one instance of
x
from
A
and add one instance of
2x
instead.
Choose a non-negative integer
x
in
A
. Delete one instance of
x
from
A
and add one instance of
\left\lfloor \frac{x}{2} \right\rfloor
instead. (
\lfloor x \rfloor
is the greatest integer not exceeding
x
.)
Your objective is to make
A
and
B
equal (as multisets).
Determine whether it is achievable, and find the minimum number of operations needed to achieve it if it is achievable. | [
{
"input": "3\n3 4 5\n2 4 6\n",
"output": "2\n"
},
{
"input": "1\n0\n1\n",
"output": "-1\n"
}
] |
https://atcoder.jp/contests/past202206-open/tasks/past202206_a | Problem Statement
A hare and a tortoise are in a race. The first to run
X
meters wins.
The hare runs
A
meters per second, and the tortoise runs
B
meters per second.
However, at
\frac{X}{2}
meters from the start, the hare stops running and sleeps for
C
seconds. Then, it wakes up and continues running
A
meters per second.
Find the winner of the race. If the two finish simultaneously, report that fact. | [
{
"input": "100 5 3 15\n",
"output": "Tortoise\n"
},
{
"input": "240 6 2 80\n",
"output": "Tie\n"
},
{
"input": "10000 100 1 1000\n",
"output": "Hare\n"
}
] |
https://atcoder.jp/contests/past202206-open/tasks/past202206_b | Problem Statement
You are given a string
S
consisting of lowercase English letters.
Now you will write, for every integer
i
such that
1 \le i \le |S|-1
, a two-letter string obtained by concatenating the
i
-th and the
(i+1)
-th characters of
S
.
Find the string that you will write the most times. If there are multiple such strings, find the lexicographically smallest one. | [
{
"input": "abcab\n",
"output": "ab\n"
},
{
"input": "zyxwv\n",
"output": "wv\n"
},
{
"input": "iiiiiiiiiiiiiiiiiiiiiiiiiiiiii\n",
"output": "ii\n"
}
] |
https://atcoder.jp/contests/past202206-open/tasks/past202206_c | Problem Statement
For integers
N
and
M
, let us define
S_{N,M}
as follows.
S_{N,M}
is a string of length
M
consisting of
o
and
x
.
The
k
-th character from the beginning of
S_{N,M}
is
o
if
N^k≤10^9
and
x
otherwise.
Given the integers
N
and
M
, print
S_{N,M}
. | [
{
"input": "1000 5\n",
"output": "oooxx\n"
},
{
"input": "2 30\n",
"output": "ooooooooooooooooooooooooooooox\n"
},
{
"input": "31622 30\n",
"output": "ooxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"
}
] |
https://atcoder.jp/contests/past202206-open/tasks/past202206_d | Problem Statement
We have pairs of lowercase English letters
(a_1,b_1),(a_2,b_2),\dots,(a_N,b_N)
.
Two lowercase English letters
u
and
v
are said to be
similar
if there exists
i
such that
(u,v)=(a_i,b_i)
or
(u,v)=(b_i,a_i)
.
Two strings
U
and
V
with the same length are said to be
similar
if
U
and
V
satisfy the following condition:
You can make
U
equal
V
by repeatedly (possibly zero times) choosing one of the characters of
U
and replacing it with a similar character.
Given strings
S
and
T
with the same length, determine if
S
and
T
are similar. | [
{
"input": "1\nm n\nman\nnan\n",
"output": "Yes\n"
},
{
"input": "1\nm n\nman\nmen\n",
"output": "No\n"
},
{
"input": "3\na b\na e\nd e\nabc\nedc\n",
"output": "Yes\n"
},
{
"input": "1\na b\nxyz\nxyz\n",
"output": "Yes\n"
}
] |
https://atcoder.jp/contests/past202206-open/tasks/past202206_e | Problem Statement
Find the
N
-th term of the sequence
A
constructed as follows.
Initially,
A
is empty.
For every integer
i
from
1
through
10^{100}
in ascending order, do the following.
If
i \ge 2
, append
i,i-1,\dots,2
in this order to the end of
A
.
Then, append
1,2,\dots,i
in this order to the end of
A
. | [
{
"input": "10\n",
"output": "4\n"
},
{
"input": "1\n",
"output": "1\n"
},
{
"input": "123456789012345678\n",
"output": "268452372\n"
}
] |
https://atcoder.jp/contests/past202206-open/tasks/past202206_f | Problem Statement
Takahashi is playing with a shooter video game. The game screen has a grid with
H
horizontal rows and
W
vertical columns. The square at the
i
-th
(1 \leq i \leq H)
row from the top and
j
-th
(1 \leq j \leq W)
column from the left in the grid is called
(i, j)
. Each square is either an
empty square
or a
brick square
. Each brick square is painted in the color represented by a positive integer.
The state of Square
(i, j)
is expressed by a non-negative integer
S_{i, j}
. If
S_{i,j} = 0
, then the square is an empty square; if
S_{i, j}
is a positive integer, then the square is a brick square of color
S_{i, j}
.
Let us call a brick square in the row other than the
H
-th row from the top a
floating brick
if the adjacent square below is an empty square. Initially, there is no floating brick.
Now, Takahashi will do
N
operations, the
i
-th
(1 \leq i \leq N)
of which is as follows:
Shoot Square
(r_i, c_i)
. If the square is an empty square, nothing happens; if it is a brick square, it changes to an empty square.
Then, all the floating bricks fall. Strictly speaking, the following operation is performed until there is no floating brick:
Choose one floating brick and swap that square with the adjacent square below.
Print the state of each square after the
N
operations have finished, in the same format as
S_{i, j}
. | [
{
"input": "3 3\n0 1 0\n1 2 0\n3 4 4\n1\n3 2\n",
"output": "0 0 0\n1 1 0\n3 2 4\n"
},
{
"input": "1 1\n1\n1\n1 1\n",
"output": "0\n"
},
{
"input": "2 3\n18459 0 35959\n150312 573935 612940\n3\n2 3\n1 2\n1 1\n",
"output": "0 0 0\n150312 573935 35959\n"
}
] |
https://atcoder.jp/contests/past202206-open/tasks/past202206_g | Problem Statement
You are given an undirected graph with
N
vertices and
N-1
edges. The
i
-th
(1 \leq i \leq N-1)
edge connects Vertex
A_i
and Vertex
B_i
.
Determine whether the given graph is a tree. | [
{
"input": "4\n1 3\n3 4\n2 3\n",
"output": "Yes\n"
},
{
"input": "4\n1 2\n2 3\n1 3\n",
"output": "No\n"
}
] |
https://atcoder.jp/contests/past202206-open/tasks/past202206_h | Problem Statement
Takahashi has
N
snacks.
For
i = 1, 2, \ldots, N
, the
i
-th snack has a weight of
w_i
and a tastiness of
v_i
.
Takahashi is going to choose any number (possibly
0
) of the
N
snacks to take on tomorrow's school trip.
Takahashi has two knapsacks. Every snack he takes on the school trip should fit in one of the two knapsacks.
Here, the sum of weights of snacks in the first knapsack should be at most
A
,
and the sum of weights of snacks in the second knapsack should be at most
B
.
Find the maximum possible total tastiness of snacks that he can take on the school trip. | [
{
"input": "6 8 9\n2 6\n4 1\n5 9\n3 1\n5 3\n5 8\n",
"output": "24\n"
},
{
"input": "20 70 60\n7 94\n18 33\n14 26\n10 1\n9 57\n2 80\n19 74\n16 10\n15 18\n10 38\n13 90\n12 23\n3 3\n8 11\n18 10\n3 42\n3 66\n3 90\n10 2\n5 45\n",
"output": "772\n"
}
] |
https://atcoder.jp/contests/past202206-open/tasks/past202206_i | Problem Statement
You are given a rectangular grid with
H
horizontal rows and
W
vertical columns. The square at the
i
-th row from the top and the
j
-th column from the left is called Sqaure
(i, j)
.
Each square is either a "square without a wall" or a "square with a wall". The initial state of Square
(i, j)
is represented by
S_{i,j}
, which means:
.
: it is a square without a wall.
s
: it is a square without a wall, and Snuke is there.
a
: it is a square without a wall, and there is a cargo in it.
g
: it is a square without a wall, and is a destination of the cargo.
#
: it is a square with a wall, which cannot be visited.
It is guaranteed that there is exactly one cargo, one destination, and one Snuke in the grid. Snuke's objective is to carry the cargo to the destination.
Snuke can do one of the following moves any number of times:
Move to a square, without the cargo or a wall, vertically or horizontally adjacent to Snuke's current square.
Push the cargo in the square vertically or horizontally adjacent to Snuke's current square to the next square without a wall in the direction of the cargo from Snuke, and move to the square that the cargo was originally in.
Print the minimum number of moves required for Snuke to achieve the objective. If the objective is unachievable, print
-1
instead. | [
{
"input": "3 3\ns..\n.a.\n..g\n",
"output": "5\n"
},
{
"input": "4 4\ns...\n.a#.\n....\n###g\n",
"output": "13\n"
},
{
"input": "4 4\n...a\n.s..\n..g.\n....\n",
"output": "-1\n"
}
] |
https://atcoder.jp/contests/past202206-open/tasks/past202206_j | Problem Statement
You eat an apple every Saturday and Sunday. You do not eat one any other day.
Given two dates
S
and
T
in
YYYY-MM-DD
format, find the number of apples you eat between
S
and
T
(inclusive).
Here are some facts that may be useful.
January
1
,
2022
is Saturday.
The year
X
is a leap year if and only if one of the following is satisfied.
X
is a multiple of
4
but not a multiple of
100
X
is a multiple of
400
What is
YYYY-MM-DD
format?
YYYY-MM-DD
format is a concatenation of a
4
-digit integer representing the year, a
2
-digit integer representing the month, and a
2
-digit integer representing the day, in this order, separated by
-
.
Here, the month and the day are zero-padded to two digits.
For example, January
23
,
4567
in
YYYY-MM-DD
format is
4567-01-23
. | [
{
"input": "2022-01-01\n2022-01-08\n",
"output": "3\n"
},
{
"input": "2024-02-26\n2024-03-02\n",
"output": "1\n"
},
{
"input": "2022-01-01\n9999-12-31\n",
"output": "832544\n"
}
] |
https://atcoder.jp/contests/past202206-open/tasks/past202206_k | Problem Statement
You are given two strings
S
and
T
.
Find the number of strings that are subsequences of at least one of
S
and
T
, modulo
998244353
.
Here, a string
A
is said to be a subsequence of string
B
when the length of
A
is at least
1
and
A
can result from removing zero or more characters from
B
. For example,
atcoder
and
ac
are subsequences of
atcoder
, while
atcoderr
and
ca
are not. | [
{
"input": "abc\nbca\n",
"output": "10\n"
},
{
"input": "aa\naaaaa\n",
"output": "5\n"
},
{
"input": "xzyyzxxzyy\nyzxyzyxzyx\n",
"output": "758\n"
}
] |
https://atcoder.jp/contests/past202206-open/tasks/past202206_l | Problem Statement
You are given strings
S
and
T
consisting of lowercase English letters. You can do the following operation between
0
and
K
times: choose one of the characters of
S
and replace it with any lowercase English letter.
What is the length of the longest possible string that is a subsequence of
S
after the replacements and also a subsequence of
T
?
Here, a string
x
is said to be a subsequence of a string
y
if
x
can result from removing zero or more characters from
y
and concatenating the remaining strings without changing the order. | [
{
"input": "strength\nslang\n1\n",
"output": "4\n"
},
{
"input": "asdbvaklwebjkalhakslhgweqwbq\nobqweogkmawgjkoanboebeoqejkazxcnmvqse\n10\n",
"output": "19\n"
}
] |
https://atcoder.jp/contests/past202206-open/tasks/past202206_m | Problem Statement
Takahashi and Aoki will play a match where the first to win
N
games wins. The two players are equally skilled, and each of them wins a game with probability
\frac{1}{2}
, independently of the outcomes of the other games. There are no draws.
A reversal is said to occur when the player with more wins changes in two games, as in going from
2-1
to
2-3
(now Aoki is in the lead).
Find the expected value of the number of reversals until one player wins the match, modulo
998244353
(see Notes). | [
{
"input": "2\n",
"output": "748683265\n"
},
{
"input": "4\n",
"output": "405536769\n"
},
{
"input": "621998\n",
"output": "76706976\n"
}
] |
https://atcoder.jp/contests/past202206-open/tasks/past202206_n | Problem Statement
There is a grid with
H
horizontal rows and
W
vertical columns. The square at the
i
-th row from the top and the
j
-th column from the left is called
(i, j)
.
The state of each square is either an "empty square" or a "square with a wall". Initially, every square is an empty square.
Ms. A wants to travel on the grid from
(1, 1)
to
(H, W)
. When Ms. A is at
(i, j)
, she may move to one of
(i+1,j),(i,j+1),(i-1,j)
, and
(i,j-1)
. She cannot go outside the grid or move to the square with a wall.
Ms. B has decided to choose some of the squares to build walls so that it is impossible for Ms. A to reach
(H, W)
no matter how she moves.
It costs Ms. B
c_{i, j}
yen (the currency in Japan) to build a wall on
(i, j)
. She cannot build a wall on
(1, 1)
or
(H, W)
.
What is the minimum cost Ms. B has to pay so that the condition is satisfied? Also, print the way of building walls to achieve the minimum cost. | [
{
"input": "2 3\n0 6 4\n2 3 0\n",
"output": "7\n..#\n.#.\n"
},
{
"input": "4 3\n0 9 2\n9 3 9\n2 3 9\n3 9 0\n",
"output": "7\n..#\n.#.\n#..\n...\n"
},
{
"input": "2 2\n0 1000000000\n1000000000 0\n",
"output": "2000000000\n.#\n#.\n"
}
] |
https://atcoder.jp/contests/past202206-open/tasks/past202206_o | Problem Statement
There is a coordinate plane
P
.
Consider performing operations of plotting points in this plane and deleting them. Initially, no points are plotted in
P
.
Process a total of
Q
queries in the following forms in the given order.
+
x
y
Plot a point at
(x,y)
in
P
.
-
x
y
Delete a point plotted at
(x,y)
in
P
.
After processing each query, answer the following question.
Consider all (unordered) pairs of points currently plotted in
P
; there are
\frac{k(k-1)}{2}
such pairs, where
k
is the current number of points plotted in
P
.
Find the sum of the following value (which is always an integer) over all those pairs modulo
998244353
: the doubled area of the triangle whose vertices are the origin (the point
(0,0)
) and the points in the pair (if these three points lie on the same line, the area is assumed to be
0
). | [
{
"input": "5\n+ 2 3\n+ -1 2\n+ 1 -2\n- -1 2\n+ -1 -1\n",
"output": "0\n7\n14\n7\n11\n"
},
{
"input": "10\n+ 100000 100000\n+ 100000 -100000\n+ 100000 100000\n+ 100000 -100000\n+ 100000 100000\n- 100000 100000\n- 100000 -100000\n- 100000 100000\n- 100000 -100000\n- 100000 100000\n",
"output": "0\n35112940\n70225880\n140451760\n210677640\n140451760\n70225880\n35112940\n0\n0\n"
},
{
"input": "10\n+ -5010 51358\n+ 95817 96893\n+ 19668 -58533\n- 95817 96893\n- -5010 51358\n+ 90155 -74912\n- 90155 -74912\n+ -83888 -29953\n- -83888 -29953\n+ 72565 37307\n",
"output": "0\n415181651\n660233626\n716858814\n0\n808940340\n0\n508110143\n0\n988223809\n"
}
] |
https://atcoder.jp/contests/arc141/tasks/arc141_a | Problem Statement
For a positive integer
n
, let
\mathrm{str}(n)
be the string representing
n
in decimal.
We say that a positive integer
n
is
periodic
when there exists a positive integer
m
such that
\mathrm{str}(n)
is the concatenation of two or more copies of
\mathrm{str}(m)
. For example,
11
,
1212
, and
123123123
are periodic.
You are given a positive integer
N
at least
11
. Find the greatest periodic number at most
N
. It can be proved that there is at least one periodic number at most
N
.
You will get
T
test cases to solve. | [
{
"input": "3\n1412\n23\n498650499498649123\n",
"output": "1313\n22\n498650498650498650\n"
}
] |
https://atcoder.jp/contests/arc141/tasks/arc141_b | Problem Statement
You are given positive integers
N
and
M
.
Find the number of sequences
A=(A_1,\ A_2,\ \dots,\ A_N)
of
N
positive integers that satisfy the following conditions, modulo
998244353
.
1 \leq A_1 < A_2 < \dots < A_N \leq M
.
B_1 < B_2 < \dots < B_N
, where
B_i = A_1 \oplus A_2 \oplus \dots \oplus A_i
.
Here,
\oplus
denotes bitwise
\mathrm{XOR}
.
What is bitwise
\mathrm{XOR}
?
The bitwise
\mathrm{XOR}
of non-negative integers
A
and
B
,
A \oplus B
, is defined as follows:
When
A \oplus B
is written in base two, the digit in the
2^k
's place (
k \geq 0
) is
1
if exactly one of
A
and
B
is
1
, and
0
otherwise.
For example, we have
3 \oplus 5 = 6
(in base two:
011 \oplus 101 = 110
).
Generally, the bitwise
\mathrm{XOR}
of
k
non-negative integers
p_1, p_2, p_3, \dots, p_k
is defined as
(\dots ((p_1 \oplus p_2) \oplus p_3) \oplus \dots \oplus p_k)
. We can prove that this value does not depend on the order of
p_1, p_2, p_3, \dots, p_k
. | [
{
"input": "2 4\n",
"output": "5\n"
},
{
"input": "4 4\n",
"output": "0\n"
},
{
"input": "10 123456789\n",
"output": "205695670\n"
}
] |
https://atcoder.jp/contests/arc141/tasks/arc141_c | Problem Statement
A string of length
2N
,
S=S_1S_2\dots S_{2N}
, is said to be a
parenthesis sequence
when
S
is composed of
N
(
s and
N
)
s.
Additionally, a parenthesis sequence
S
is said to be
correct
when it is one of the following.
An empty string.
The concatenation of
(
,
A
,
)
in this order, where
A
is a correct parenthesis sequence.
The concatenation of
A
,
B
in this order, where
A
and
B
are non-empty correct parenthesis sequences.
You are given two permutations
P=(P_1,\ P_2,\ \dots,\ P_{2N})
and
Q=(Q_1,\ Q_2,\ \dots,\ Q_{2N})
of the integers from
1
to
2N
.
Determine whether there exists a parenthesis sequence
S=S_1S_2\dots S_{2N}
that satisfies the following conditions.
P
is the lexicographically smallest permutation
p
of the integers from
1
to
2N
such that
S_{p_1}S_{p_2}\dots S_{p_{2N}}
is a correct parenthesis sequence.
Q
is the lexicographically largest permutation
p
of the integers from
1
to
2N
such that
S_{p_1}S_{p_2}\dots S_{p_{2N}}
is a correct parenthesis sequence.
If such a parenthesis sequence exists, find one. | [
{
"input": "2\n1 2 4 3\n4 3 1 2\n",
"output": "())(\n"
},
{
"input": "2\n1 3 2 4\n4 3 2 1\n",
"output": "-1\n"
},
{
"input": "3\n2 1 5 3 4 6\n6 5 3 4 2 1\n",
"output": "-1\n"
}
] |
https://atcoder.jp/contests/arc141/tasks/arc141_d | Problem Statement
We say that a set
S
of positive integers is
good
when, for any
a,\ b \in S\ (a\neq b)
,
b
is not a multiple of
a
.
You are given a set of
N
integers between
1
and
2M
(inclusive):
S=\lbrace A_1,\ A_2,\ \dots,\ A_N\rbrace
.
For each
i=1,\ 2,\ \dots,\ N
, determine whether there exists a good set with
M
elements that is a subset of
S
containing
A_i
. | [
{
"input": "5 3\n1 2 3 4 5\n",
"output": "No\nYes\nYes\nYes\nYes\n"
},
{
"input": "4 4\n2 4 6 8\n",
"output": "No\nNo\nNo\nNo\n"
},
{
"input": "13 10\n2 3 4 6 7 9 10 11 13 15 17 19 20\n",
"output": "No\nNo\nYes\nYes\nYes\nYes\nYes\nYes\nYes\nYes\nYes\nYes\nNo\n"
}
] |
https://atcoder.jp/contests/arc141/tasks/arc141_e | Problem Statement
There is an undirected graph with
N^2
vertices. Initially, it has no edges. For each pair of integers
(i,\ j)
such that
0 \leq i,\ j < N
, the graph has a corresponding vertex called
(i,\ j)
.
You will get
Q
queries, which should be processed in order. The
i
-th query, which gives you four integers
a_i,\ b_i,\ c_i,\ d_i
, is as follows.
For each
k
(0 \leq k < N)
, add an edge between two vertices
((a_i+k) \bmod N,\ (b_i+k) \bmod N)
and
((c_i+k) \bmod N,\ (d_i+k) \bmod N)
. Then, print the current number of connected components in the graph. | [
{
"input": "3 3\n0 0 1 2\n2 0 0 0\n1 1 2 2\n",
"output": "6\n4\n4\n"
},
{
"input": "4 3\n0 0 2 2\n2 3 1 2\n1 1 3 3\n",
"output": "14\n11\n11\n"
},
{
"input": "6 5\n0 0 1 1\n1 2 3 4\n1 1 5 3\n2 0 1 5\n5 0 3 3\n",
"output": "31\n27\n21\n21\n19\n"
}
] |
https://atcoder.jp/contests/arc141/tasks/arc141_f | Problem Statement
You are given
N
srings
S_i\ (1\le i \le N)
consisting of
A
,
B
,
C
,
D
.
Consider the operation below on a string
T
consisting of
A
,
B
,
C
,
D
.
Repeat the following until
T
contains none of the strings
S_i
as a substring.
Choose an
S_i
and one of its occurrences in
T
, remove that occurrence from
T
, and concatenate the remaining parts.
What is a substring?
A substring of a string is its contiguous subsequence. For example,
A
,
AB
, and
BC
are substrings of
ABC
, while
BA
and
AC
are not.
We say that the string
T
is
bad
when multiple strings can result from the operation above.
Determine whether a bad string exists. | [
{
"input": "3\nA\nB\nC\n",
"output": "No\n"
},
{
"input": "1\nABA\n",
"output": "Yes\n"
},
{
"input": "4\nCBA\nACB\nAD\nCAB\n",
"output": "Yes\n"
}
] |
https://atcoder.jp/contests/abc253/tasks/abc253_a | Problem Statement
Given integers
a
,
b
, and
c
, determine if
b
is the median of these integers. | [
{
"input": "5 3 2\n",
"output": "Yes\n"
},
{
"input": "2 5 3\n",
"output": "No\n"
},
{
"input": "100 100 100\n",
"output": "Yes\n"
}
] |
https://atcoder.jp/contests/abc253/tasks/abc253_b | Problem Statement
There is a grid with
H
horizontal rows and
W
vertical columns, in which two distinct squares have a piece.
The state of the squares is represented by
H
strings
S_1, \dots, S_H
of length
W
.
S_{i, j} =
o
means that there is a piece in the square at the
i
-th row from the top and
j
-th column from the left;
S_{i, j} =
-
means that the square does not have a piece. Here,
S_{i, j}
denotes the
j
-th character of the string
S_i
.
Consider repeatedly moving one of the pieces to one of the four adjacent squares. It is not allowed to move the piece outside the grid. How many moves are required at minimum for the piece to reach the square with the other piece? | [
{
"input": "2 3\n--o\no--\n",
"output": "3\n"
},
{
"input": "5 4\n-o--\n----\n----\n----\n-o--\n",
"output": "4\n"
}
] |
https://atcoder.jp/contests/abc253/tasks/abc253_c | Problem Statement
We have a multiset of integers
S
, which is initially empty.
Given
Q
queries, process them in order.
Each query is of one of the following types.
1 x
: Insert an
x
into
S
.
2 x c
: Remove an
x
from
S
m
times, where
m = \mathrm{min}(c,(
the number of
x
's contained in
S))
.
3
: Print
(
maximum value of
S)-(
minimum value of
S)
. It is guaranteed that
S
is not empty when this query is given. | [
{
"input": "8\n1 3\n1 2\n3\n1 2\n1 7\n3\n2 2 3\n3\n",
"output": "1\n5\n4\n"
},
{
"input": "4\n1 10000\n1 1000\n2 100 3\n1 10\n",
"output": "\n"
}
] |
https://atcoder.jp/contests/abc253/tasks/abc253_d | Problem Statement
Find the sum of integers between
1
and
N
(inclusive) that are not multiples of
A
or
B
. | [
{
"input": "10 3 5\n",
"output": "22\n"
},
{
"input": "1000000000 314 159\n",
"output": "495273003954006262\n"
}
] |
https://atcoder.jp/contests/abc253/tasks/abc253_e | Problem Statement
How many integer sequences
A=(A_1,\ldots,A_N)
of length
N
satisfy all the conditions below?
1\le A_i \le M
(1 \le i \le N)
|A_i - A_{i+1}| \geq K
(1 \le i \le N - 1)
Since the count can be enormous, find it modulo
998244353
. | [
{
"input": "2 3 1\n",
"output": "6\n"
},
{
"input": "3 3 2\n",
"output": "2\n"
},
{
"input": "100 1000 500\n",
"output": "657064711\n"
}
] |
https://atcoder.jp/contests/abc253/tasks/abc253_f | Problem Statement
We have an
N \times M
matrix, whose elements are initially all
0
.
Process
Q
given queries. Each query is in one of the following formats.
1 l r x
: Add
x
to every element in the
l
-th,
(l+1)
-th,
\ldots
, and
r
-th column.
2 i x
: Replace every element in the
i
-th row with
x
.
3 i j
: Print the
(i, j)
-th element. | [
{
"input": "3 3 9\n1 1 2 1\n3 2 2\n2 3 2\n3 3 3\n3 3 1\n1 2 3 3\n3 3 2\n3 2 3\n3 1 2\n",
"output": "1\n2\n2\n5\n3\n4\n"
},
{
"input": "1 1 10\n1 1 1 1000000000\n1 1 1 1000000000\n1 1 1 1000000000\n1 1 1 1000000000\n1 1 1 1000000000\n1 1 1 1000000000\n1 1 1 1000000000\n1 1 1 1000000000\n1 1 1 1000000000\n3 1 1\n",
"output": "9000000000\n"
},
{
"input": "10 10 10\n1 1 8 5\n2 2 6\n3 2 1\n3 4 7\n1 5 9 7\n3 3 2\n3 2 8\n2 8 10\n3 8 8\n3 1 10\n",
"output": "6\n5\n5\n13\n10\n0\n"
}
] |
https://atcoder.jp/contests/abc253/tasks/abc253_g | Problem Statement
For an integer
N
greater than or equal to
2
, there are
\frac{N(N - 1)}{2}
pairs of integers
(x, y)
such that
1 \leq x \lt y \leq N
.
Consider the sequence of these pairs sorted in the increasing lexicographical order. Let
(x_1, y_1), \dots, (x_{R - L + 1}, y_{R - L + 1})
be its
L
-th,
(L+1)
-th,
\ldots
, and
R
-th elements, respectively. On a sequence
A = (1, \dots, N)
, We will perform the following operation for
i = 1, \dots, R-L+1
in this order:
Swap
A_{x_i}
and
A_{y_i}
.
Find the final
A
after all the operations.
We say that
(a, b)
is smaller than
(c, d)
in the lexicographical order if and only if one of the following holds:
a \lt c
a = c
and
b \lt d | [
{
"input": "5 3 6\n",
"output": "5 1 2 3 4\n"
},
{
"input": "10 12 36\n",
"output": "1 10 9 8 7 4 3 2 5 6\n"
}
] |
https://atcoder.jp/contests/abc253/tasks/abc253_h | Problem Statement
We have a graph
G
with
N
vertices numbered
1
through
N
and
0
edges. You are given sequences
u=(u_1,u_2,\ldots,u_M),v=(v_1,v_2,\ldots,v_M)
of length
M
.
You will perform the following operation
(N-1)
times.
Choose
i
(1 \leq i \leq M)
uniformly at random. Add to
G
an undirected edge connecting Vertices
u_i
and
v_i
.
Note that the operation above will add a new edge connecting Vertices
u_i
and
v_i
even if
G
already has one or more edges between them. In other words, the resulting
G
may contain multiple edges.
For each
K=1,2,\ldots,N-1
, find the probability, modulo
998244353
, that
G
is a forest after the
K
-th operation.
What is a forest?
An undirected graph without a cycle is called a forest. A forest is not necessarily connected.
Definition of probability modulo
998244353
We can prove that the sought probability is always a rational number. Moreover, under the Constraints of this problem, it is guaranteed that, when the sought probability is represented by an irreducible fraction
\frac{y}{x}
,
x
is indivisible by
998244353
.
Then, we can uniquely determine an integer
z
between
0
and
998244352
(inclusive) such that
xz \equiv y \pmod{998244353}
. Print this
z
. | [
{
"input": "3 2\n1 2\n2 3\n",
"output": "1\n499122177\n"
},
{
"input": "4 5\n1 2\n1 2\n1 4\n2 3\n2 4\n",
"output": "1\n758665709\n918384805\n"
}
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.