time limit per test3 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Let’s call a positive integer composite if it has at least one divisor other than 1 and itself. For example:
the following numbers are composite: 1024, 4, 6, 9;
the following numbers are not composite: 13, 1, 2, 3, 37.
You are given a positive integer n. Find two composite integers a,b such that a−b=n.
It can be proven that solution always exists.
Input
The input contains one integer n (1≤n≤107): the given integer.
Output
Print two composite integers a,b (2≤a,b≤109,a−b=n).
It can be proven, that solution always exists.
If there are several possible solutions, you can print any.
Examples
inputCopy
1
outputCopy
9 8
inputCopy
512
outputCopy
4608 4096
#include
using namespace std;
int t,n;
int main()
{
cin>>n;
if(n==1)cout<<9<<" "<<8<<endl;
else
cout<<3*n<<" "<<2*n<<endl;
return 0;
}
time limit per test3 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
You are given a positive integer m and two integer sequence: a=[a1,a2,…,an] and b=[b1,b2,…,bn]. Both of these sequence have a length n.
Permutation is a sequence of n different positive integers from 1 to n. For example, these sequences are permutations: [1], [1,2], [2,1], [6,7,3,4,1,2,5]. These are not: [0], [1,1], [2,3].
You need to find the non-negative integer x, and increase all elements of ai by x, modulo m (i.e. you want to change ai to (ai+x)modm), so it would be possible to rearrange elements of a to make it equal b, among them you need to find the smallest possible x.
In other words, you need to find the smallest non-negative integer x, for which it is possible to find some permutation p=[p1,p2,…,pn], such that for all 1≤i≤n, (ai+x)modm=bpi, where ymodm — remainder of division of y by m.
For example, if m=3, a=[0,0,2,1],b=[2,0,1,1], you can choose x=1, and a will be equal to [1,1,0,2] and you can rearrange it to make it equal [2,0,1,1], which is equal to b.
Input
The first line contains two integers n,m (1≤n≤2000,1≤m≤109): number of elemens in arrays and m.
The second line contains n integers a1,a2,…,an (0≤ai The third line contains n integers b1,b2,…,bn (0≤bi It is guaranteed that there exists some non-negative integer x, such that it would be possible to find some permutation p1,p2,…,pn such that (ai+x)modm=bpi. Output Examples time limit per test3 seconds Also, you are given a positive integer k Let’s call integer b1,b2,…,bm beautiful if bi=bi+k for each i, such that 1≤i≤m−k. You need to find the smallest beautiful integer y, such that y≥x. Input The next line of input contains n digits a1,a2,…,an (a1≠0, 0≤ai≤9): digits of x. Output In the next line print m digits b1,b2,…,bm (b1≠0, 0≤bi≤9): digits of y. Examples time limit per test3 seconds Given diagram is a histogram with n columns of lengths a1,a2,…,an (a1≥a2≥…≥an≥1). Young diagram for a=[3,2,2,2,1]. Input The next line of input contains n integers a1,a2,…,an (1≤ai≤300000,ai≥ai+1): the lengths of columns. Output Example
Print one integer, the smallest non-negative integer x, such that it would be possible to find some permutation p1,p2,…,pn such that (ai+x)modm=bpi for all 1≤i≤n.
inputCopy
4 3
0 0 2 1
2 0 1 1
outputCopy
1
inputCopy
3 2
0 0 0
1 1 1
outputCopy
1
inputCopy
5 10
0 0 0 1 2
2 1 0 0 0
outputCopy
0#include
C. Long Beautiful Integer
memory limit per test256 megabytes
inputstandard input
outputstandard output
You are given an integer x of n digits a1,a2,…,an, which make up its decimal notation in order from left to right.
The first line of input contains two integers n,k (2≤n≤200000,1≤k
In the first line print one integer m: the number of digits in y.
inputCopy
3 2
353
outputCopy
3
353
inputCopy
4 2
1234
outputCopy
4
1313#include
D. Domino for Young
memory limit per test256 megabytes
inputstandard input
outputstandard output
You are given a Young diagram.
Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a 1×2 or 2×1 rectangle.
The first line of input contain one integer n (1≤n≤300000): the number of columns in the given histogram.
Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram.
inputCopy
5
3 2 2 2 1
outputCopy
4
Note
Some of the possible solutions for the example:#include