Buet Iupc 2023 Problemset
Buet Iupc 2023 Problemset
https://toph.co/c/buet-inter-university-2023
Schedule
The contest will run for 5h0m0s.
Authors
The authors of this contest are Ahmed.032170, Anachor, Arghya, Iftekhar_Hakim,
longlongint, LUMBERJACK_MAN, N3710rD, neo11235, Sk_Sabit, tbs_sajal15, and
upobir.
Rules
This contest is formatted as per the official rules of ICPC Regional Programming
Contests.
You can use Bash 5.0, Brainf*ck, C# Mono 6.0, C++11 GCC 7.4, C++14 GCC 8.3, C++17
GCC 9.2, C++20 GCC 12.1, C11 GCC 12.1, C11 GCC 9.2, Common Lisp SBCL 2.0, Erlang
22.3, Free Pascal 3.0, Go 1.18, Grep 3.7, Haskell 8.6, Java 1.8, Kotlin 1.1, Lua 5.4, Node.js
10.16, Perl 5.30, PHP 7.2, PyPy 7.1 (2.7), PyPy 7.1 (3.6), Python 2.7, Python 3.11, Python
3.7, Ruby 2.7, Ruby 3.2, Rust 1.57, Swift 5.3, and Whitespace in this contest.
Notes
There are 12 challenges in this contest.
If you find any discrepencies between the printed copy and the problem statements in
Toph Arena, please rely on the later.
Input
T(1≤T≤10000)T(1\le
First line contains number of test cases T (1 ≤ T ≤ 10000).
T\le
Each testcase starts with an integer N (1 ≤ N ≤ 106 ).
N(1≤N≤106)N(1\le
10000)
N\le
A(A[1]…
The next line contains a string A(A[1] NN
10^6) … A[N ]) containing N characters, each
character is either ‘P’ or ‘C’. A[N])A(A[1]…
A[N])
The next line contains NN
N space separated integersV[1],V[2],….,V[N]V[1],V[2],….,V[N]
V [1], V [2], … ., V [N ], ifA[i]=‘P’A[i]
A[i] =
‘P ’ then V[i]V[i] on=ith day,
V [i] denotes interesting factor of the problem that you create ithi^{th}
else V[i]V[i]
V [i] denotes importance factor of the contest on ithi^{th}
ith day. ‘P’
1≤i≤N1\le
For all 1 ≤ V [i] ≤ 106
≤ i ≤ N , 11≤V[i]≤1061\le
i\le V[i]
If ii<ji A[i]=A[j]=‘P’A[i]
< jNand A[i] =\le V[i]≥V[j]V[i]
A[j] = ‘P ’ then V [i] ≥ V [j]
\lt = 10^6 \ge
A[j]that the sum of NN
It'sj guaranteed 106 .
all test cases does not exceed 10610^6
N overV[j]
=
Output ‘P’
For each case, output a single integer, which denotes the maximum satisfaction you
can get if you optimally place the problems in the contests.
•2 ≤ n ≤ 3 × 105
2≤n≤3×1052
\leq
•1
1≤k≤181\leq
≤ k ≤ 18
n
k
• \leq
00≤ai<2k0
≤ ai < 2k
\leq
3\leq
18
\times
a_i
Output10^5
<2^k
Output 2k2^k
2k space separated integersf0,f1,⋯ ,f2k−1f_0,
f0 , f1 , ⋯ fxf_x
, f2k −1 . where, fx is the number of
ways, modulo 998244353998244353 f_1,such that the score is xx
998244353, to partition x.
\cdots,
f_{2^k-1}
Samples
Input Output
4 2 0 4 0 3
1 1 2 3
Input Output
2 1 0 1
0 1
Input
First line of input will have a integer TT
T denoting the number of independent testcases.
Each testcase will start with a line containing one integer, nn
n denoting number of bags.
Next nn
n lines will contain the description of bags.
Each line will contain several space separated integers. They will start with an integer
kk
k denoting the number of stones in the bag. Nextkkk integers will denote the weights
PPP and
of the stones in the bag. Final line of the testcase will contain two integers QQQ
P//Q.
denoting the target fraction P
QP/
Constraints Q
•1
1≤T≤101
≤ T ≤ 10
\leq
•1 ≤ n ≤ 105
1≤n≤1051
T
\leq
• \leq
11≤k≤991
≤ k ≤ 99
n
10
\leq
• \leq
1≤1\leq 109
≤109\leq
1k ≤ weight of each stone ≤
10^5 10^9
• \leq ≤ P , Q ≤ 1018
11≤P,Q≤10181
99
\leq
• Product of (k
P, (k+1) 1012
+ 1) over all bags in a testcase will be at most 101210^{12}
Q (k+1)
Samples
Input Output
2 8
2 5
2 1 1
2 1 1
1 1
3
2 2 3
3 1 4 2
3 3 2 1
5 2
In the first testcase, among the nine possible combinations of picking stones, one picks
none of the stones and other eight picks stones in such a way that the average is
= 11 .
1=111
exactly 1
=
\frac
1
1
You can shuffle the given indices any number of times (possibly zero).
SSS
You have to find out the maximum length of a palindromic subsequence of string
after shuffling.
1≤∣S∣≤5001\le|
1 ≤ ∣S∣ ≤ 500
S|
00≤k≤∣S∣0
≤ k ≤ ∣S∣
\le500
\le
11≤ai≤∣S∣1\le
k ≤ ai ≤ ∣S∣
a_i\le
\le
||
Output
S|
S|
Output one line containing the output, the maximum length of any palindromic
subsequence after the operation.
Samples
Input Output
10010 2 5
1 2
11 1
Gvardiol will tackle Messi if the distance between them becomes strictly less than
unit. Gvardiol has a choice to foul Messi at a moment when Messi moves from a
position which is more than 1 unit away to a position which is exactly11
1 unit away from
Gvardiol. A dribble is a path on the field which Messi can take to move to coordinate
(0, 0) without getting tackled or fouled.
0)
Messi does not know if Gvardiol intends to foul or not. So to be safe, he plans his
(0,0)
dribble assuming that Gvardiol will foul him given the chance.
Messi wants to know the length of the shortest dribble which is not boring. It can be
proved that such a dribble exists under the given constraints.
Input
First line contains an integer TT ≤ T ≤ 5 × 104 ), the number of test cases.
(1≤T≤5×104)
T (1
Each of the next TT (1two space separated floating point numbersxx
T lines contains (2 ≤
x(2≤x≤100)
x ≤ 100) and vv (1<v≤100)
v (1 < v ≤ 100) \leq
. Both numbers have 55
5 digits after decimal. (2
(1 T \leq
\lt \leq x
Output 5
v \leq
for each case \times
Print the answer\leq 100)if
in a separate line. Your answer is considered correct
100) error does
its absolute or relative 10^4not) exceed10−610^{-6}
−6
10 . Formally, let your answer AAA
be ,
∣A−B∣
and the jury's answer be BB
B . Your answer is accepted if and only if ∣A−B∣max(1,B)
≤\leq
10−610^{-6}
−6
max(1,B) ≤ 10 .
\frac{\lvert
A-
B
\rvert}
Input
The first line of the input contains an integer tt
t denoting the number of test cases.
The next line of each test case contains 5 space separated integers.
• nn
n- The amount of chocolates to be bought.
• pp
p- The initial price of first type chocolate
• qq
q - The initial price of second type chocolate
• xx
x- The amount of price reduces after buying each chocolate of first type
• yy
y - The amount of price reduces after buying each chocolate of second type
Samples
Input Output
1 220
5 100 50 5 3
Constraints
11≤T≤1001
≤ T ≤ 100
\le
11≤L≤R≤10001
T ≤ L ≤ R ≤ 1000
\leq
\le
L
Output
100
\leq
R
Output one integer, the answer to the problem.
\leq
1000
Samples
Input Output
1 1
1 2
Constraints:
•2 ≤ N ≤ 109
2≤N≤1092\le
≤ M ≤ 105
• N\le10^9
11≤M≤1051\le
M\le
•1
1≤Ak≤N−11\le
≤ Ak ≤ N − 1
10^5
≤ Ck ≤ 109
A_k\le
•1
1≤Ck≤1091\le
•N
C_k\le
All values in input are integers.
-
10^9
1
Input
Input is given from Standard Input in the following format:
Samples
Input Output
4 2 11
2 3
3 5
Input Output
6 1 -1
3 4
There is no way to make all the cities connected, so we should print −1−1
−1.
Input
The first line of the input will contain an integer, T (1≤T≤100)T\
(1 ≤ T ≤ 100) which denotes the
number of test cases. (1\leq
T\leq
Each of the test cases starts with one integer N (1 ≤ N ≤ 106 ) describing the
N (1≤N≤106)N\
100)
number of posts. (1\leq
N\leq
The next line will containNN integersd1,
N space separated10^6) d1d2,
, d2d3,…,
, d3 , …dNd_1,\
, dN where did_i
di
7
d_2,\
denotes the distance of postiii from base.1≤di≤107,
1 ≤ di ≤ 10 di<di+1
, di < dfor
i+1 all
for1≤i<N1\leq
all 1 ≤ i <
N. d_i\leq d_3,
10^7,\ …,
The next line will contain NN
N more spaced_i P1, PP2,
separated \integers 1, PP3,…, PNP_1,\
2 , P3 , … , PN .
Troop currently stationed at post ii i should
< be stationedd_N P_2,\
atPiP_i
post Pi after all the
commands are given. 1≤Pi≤N
1 ≤ Pi ≤ and
N andall all
Pi are distinct1\leq
Pi are P_3,
, so PP
distinctfor
d_{i+1}\text{ P is a permutation of
length NN
N. P_i\leq all } …,
N\text{ and 1\leq \
It is guaranteed that the sum
all } of NN
N over all
i<test cases does not
P_N 106 .
exceed 10610^6
P_i\text{ are N
distinct}
y0=xy_0
Formally, let y0 =x
=
xn−1 ) where nn
n = ϕ(y
yn=ϕ(yn−1)y_n
and y n≥1n\ge
n is an integer and n ≥1
= 1
Find smallest nn
n such that yyn=1y_n
n =1
\phi(y_{n-1})
=
1 of a positive integer nn
Note: Euler totient function n is defined as the number of positive
integers ii
i less than or equal to nn gcd(n,i)=1gcd(n,i)
n such that gcd(n, i) = 1
=
1
Input
k(1 ≤ k ≤ 105 )
First line of input contains an integer k(1≤k≤105)k
( 1\le
Next line contains kk p1,p2,…
k prime numbers pk1 , p2 , … pk
pkp_1,
\lee
Next line contains kk
k integers ee1,e2,…
1 , e2 , p_2,
… k
10^5)
eke_1,e_2,…
6…
For each 11≤i≤k1\le
≤ i ≤ k , 22≤pi≤1062
≤ pi ≤ e_k10 p_k
i\le \le
It is guaranteed
k that p_i pip_i
each pi is pairwise distinct.
For each 1 ≤ i ≤ k , \le
1≤i≤k1\le ≤ ei ≤ 106
11≤ei≤1061
i\le 10^6
\le k
Then the kinput number e_iis calculated as x = ∏i=1 pei i
x=∏i=1kpieix
\le =\prod_{i
10^6 =
Output
1}
Print the smallest positive nn yyn=1y_n
n =1
n such that ^{k}
=
p_i^{e_i}
Since nn
n can be very large, output it modulo 1 998244353998244353
998244353
Input Output
1 4
11
1
This is not enough. You have to find the polygon with smallest area. Output the value
of the smallest area×2\times
×2. If it is impossible to construct such a polygon, output should
be −1-1
−1. 2
Input
First line of the input will have an integerTT(1 ≤ T ≤ 100), denoting the number of
T(1≤T≤100)
testcases. Each testcase is independent. (1
\le
TNN(1≤N≤500)
First line of each testcase will have an integer N (1 ≤ N ≤ 500), denoting the
number of points you have got. \le (1
\le
100)xix_i
Line ii
i of the nextNNN lines will have two integers yiy_i
N xi and yi (−104 ≤ xi , yi ≤ 104 )
(−104≤xi,yi≤104)
denoting the abscissa and ordinate ii (-10^4
i-th point respectively,
\le for ii=1,
= 1, 2, … , N .
500) \le 2,…,Ni=1,
4
Last line of each testcase will have an integerRR R(1≤R≤104)
(1 ≤ R x_i,
≤ 10 2, ), denoting the radius
of the circle. (1\le y_i \dots,
R \le N
Sum of NNN over all testcases will not exceed 500500
500.\le
10^4)
10^4)
Output
Print a separate line for each testcase. Lineiii of the output should have the output for
ii
i-th testcase. Output of the iii-th testcase is the value of2×A2
2 × A, whereAA
A is the area of
\times
the smallest possible convex polygon. If there is no possible convex polygon, output is
−1-1
−1. A
Following figures show the input of 1st testcase and the convex polygon with smallest
area. Here the area is 7272
72.
Input
NN(2≤N≤3×105)
The first line of the input will contain an integer, N (2 ≤ N ≤ 3 × 105 ) which
denotes the number of vertices of the tree. (2
\leq
Each of the nextN−1N
N − 1 lines will contain222 space-separated
N integersuiu_i viv_i
ui and (1≤ui,vi≤N)
vi (1 ≤
-
ui , vi ≤ N ), indicating an edge between verticesuiu_i vi . It is guaranteed (1
i andviv_i
u\leq that the
given edges form1a tree. 3 \leq
\times u_i,
The next line will contain an integer QQ ≤ Q ≤ 3 × 105 ), the number of queries.
(1≤Q≤3×105)
Q (1 v_i
10^5)
(1\leq \leq
Finally, each of the next QQ
Q line will contain
Q\leq33
3 integers RiR_i
Ri ,UiU_i
Ui and ViV_i
Vi(1≤Ri,Ui,Vi≤N)
(1 ≤ Ri , Ui , Vi ≤
N)
N ) — representing each query. 3\times (1
10 \leq
^ R_i,
Output
5) U_i,
Print the answer for each query in separate lines. V_i
Input Output
6 9
1 2 9
2 3
3 4
4 6
1 5
2
1 5 6
1 5 4
Input Output
10 27
2 1 23
3 2
4 3
5 3
6 4
7 2
8 4
9 8
10 7
2
1 10 4
9 1 9