# Educational Codeforces Round 84 (Rated for Div. 2)

A. Sum of Odd Integers

time limit per test:2 seconds

memory limit per test:256 megabytes

input:standard input

output:standard output

You are given two integers n
n
and k
k
n
can be represented as a sum of k
k
distinct positive odd (not divisible by 2
2
) integers or not.

t
independent test cases.

Input

The first line of the input contains one integer t
t
(1≤t≤10 5
1≤t≤105
) — the number of test cases.

The next t
t
lines describe test cases. The only line of the test case contains two integers n
n
and k
k
(1≤n,k≤10 7
1≤n,k≤107
).

Output

For each test case, print the answer — “YES” (without quotes) if n
n
can be represented as a sum of k
k
distinct positive odd (not divisible by 2
2
) integers and “NO” otherwise.

Example

Input
Copy
6
3 1
4 2
10 3
10 2
16 4
16 5

Output
Copy
YES
YES
NO
YES
YES
NO

Note

In the first test case, you can represent 3
3
as 3
3
.

In the second test case, the only way to represent 4
4
is 1+3
1+3
.

In the third test case, you cannot represent 10
10
as the sum of three distinct positive odd integers.

In the fourth test case, you can represent 10
10
as 3+7
3+7
, for example.

In the fifth test case, you can represent 16
16
as 1+3+5+7
1+3+5+7
.

In the sixth test case, you cannot represent 16
16
as the sum of five distinct positive odd integers.

#include <bits/stdc++.h>

using namespace std;

#define LL long long
#define pb(x) push_back(x)
#define debug(x) cout<<"..........."<<x<<endl;
#define fi first
#define se second

const int N = 1e5+5;
const int M = 1e3+5;
const int mod = 1e9+7;
const int INF = 0x3f3f3f3f;

int main()
{
int t;

cin >> t;

while(t --)
{
LL n,k;

cin >> n >> k;

if((n%2 == 0 && k%2 == 0) || (n%2 == 1 && k%2 == 1))
{
if(n >= k*k)
cout << "YES" << '\n';
else
cout << "NO" << '\n';
}
else
cout << "NO" << '\n';
}

return 0;
}


B.

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5;

vector <int> a[N];
int vis[N];

int main()
{
int t;

cin >> t;

while(t --)
{
int n;

cin >> n;

for(int i = 1;i <= n;i ++)
{
a[i].clear();
vis[i] = 0;
}

int cnt = 0;
int m = 0;

for(int i = 1; i <= n; i ++)
{
int k;

cin >> k;

bool flag = 1;

for(int j = 0;j < k;j ++)
{
int x;
cin >> x;
a[i].push_back(x);
}

for(int j = 0;j < k;j ++)
{
int x = a[i][j];

if(!vis[x])
{
vis[x] = 1;
cnt ++ ;
flag = 0;
break;
}
}

if(flag)
m = i;
}

if(cnt == n)
cout << "OPTIMAL" << '\n';
else
{
cout << "IMPROVE" << '\n';

cout << m << ' ';

for(int i = 1;i <= n;i ++)
{
if(!vis[i])
{
cout << i << '\n';
break;
}
}
}
}

return 0;
}



C. Game with Chips

time limit per test:1 second

memory limit per test:256 megabytes

input:standard input

output:standard output

Petya has a rectangular Board of size n×m
n×m
. Initially, k
k
chips are placed on the board, i
i
-th chip is located in the cell at the intersection of sx i
sxi
-th row and sy i
syi
-th column.

In one action, Petya can move all the chips to the left, right, down or up by 1
1
cell.

If the chip was in the (x,y)
(x,y)
cell, then after the operation:
• left, its coordinates will be (x,y−1)
(x,y−1)
;
• right, its coordinates will be (x,y+1)
(x,y+1)
;
• down, its coordinates will be (x+1,y)
(x+1,y)
;
• up, its coordinates will be (x−1,y)
(x−1,y)
.

If the chip is located by the wall of the board, and the action chosen by Petya moves it towards the wall, then the chip remains in its current position.

Note that several chips can be located in the same cell.

For each chip, Petya chose the position which it should visit. Note that it’s not necessary for a chip to end up in this position.

Since Petya does not have a lot of free time, he is ready to do no more than 2nm
2nm
actions.

You have to find out what actions Petya should do so that each chip visits the position that Petya selected for it at least once. Or determine that it is not possible to do this in 2nm
2nm
actions.

Input

The first line contains three integers n,m,k
n,m,k
(1≤n,m,k≤200
1≤n,m,k≤200
) — the number of rows and columns of the board and the number of chips, respectively.

The next k
k
lines contains two integers each sx i ,sy i
sxi,syi
(1≤sx i ≤n,1≤sy i ≤m
1≤sxi≤n,1≤syi≤m
) — the starting position of the i
i
-th chip.

The next k
k
lines contains two integers each fx i ,fy i
fxi,fyi
(1≤fx i ≤n,1≤fy i ≤m
1≤fxi≤n,1≤fyi≤m
) — the position that the i
i
-chip should visit at least once.

Output

In the first line print the number of operations so that each chip visits the position that Petya selected for it at least once.

In the second line output the sequence of operations. To indicate operations left, right, down, and up, use the characters L,R,D,U
L,R,D,U
respectively.

If the required sequence does not exist, print -1 in the single line.

Examples

Input
Copy
3 3 2
1 2
2 1
3 3
3 2

Output
Copy
3
DRD

Input
Copy
5 4 3
3 4
3 1
3 3
5 3
1 3
1 4

Output
Copy
9
DDLUUUURR

#include <bits/stdc++.h>

using namespace std;

#define LL long long
#define pb(x) push_back(x)
#define debug(x) cout<<"..........."<<x<<endl;
#define fi first
#define se second

const int N = 205;
const int M = 1e3+5;
const int mod = 1e9+7;
const int INF = 0x3f3f3f3f;

int main()
{
int n,m, k ;

cin >> n >> m >> k ;

int x,y;

for(int i = 1; i <= k ; i ++)
cin >> x >> y >> x >> y;

string res =  "";

for(int i = 1; i <= n - 1; i ++)
res += 'U';
for(int i = 1; i <= m - 1; i ++)
res += 'L';

bool flag = 1;

for(int i = 1; i <= n; i ++)
{
for(int j = 1; j <= m - 1; j ++)
{
if(flag)
res += 'R';
else
res += 'L';
}

flag ^= 1;
res += 'D';
}

cout << res.size() << '\n' << res << '\n';

return 0;
}



©️2019 CSDN 皮肤主题: 游动-白 设计师: 上身试试