You are on page 1of 8

# Chandan gave his son a cube with side N.

## The N X N X N cube is made up of small 1 X 1 X 1

cubes.
Chandan's son is extremely notorious just like him. So he dropped the cube inside a tank filled
with Coke. The cube got totally immersed in that tank. His son was somehow able to take out the
cube from the tank. But sooner his son realized that the cube had gone all dirty because of the
coke. Since Chandan did not like dirty stuffs so his son decided to scrap off all the smaller cubes
that got dirty in the process. A cube that had coke on any one of its six faces was considered to
be dirty and scrapped off. After completing this cumbersome part his son decided to calculate
volume of the scrapped off material. Since Chandan's son is weak in maths he is unable to do it
alone.
Help him in calculating the required volume.
Input:
The first line contains T denoting the number of test cases. Then T lines follow each line
contains N that is the side of cube.
Output:
For each case output the required volume.
Constraints:

1 T 100

1 N 109

Note:
There is no hole or space between 2 smaller cubes.

Sample Input
2
1
3
Sample Output
1
26
Explanation
For the first test case : There is only 1 small cube in a 1 x 1 x 1 cube. This cube gets coke on all of
its 6 faces so it needs to be scrapped off. Volume of material that gets scrapped is 1 x 1 x 1 = 1.

Once upon a time, the Earth was a flat rectangular landmass. And there was no life. It was then
that the sky lit up with meteorites falling from out of space. Wherever they fell on the planet, a
river was born, which flowed in all 4 directions (North, East, West, South), till the waters reached
the edge of the Earth and simply fell off into space.
Now, these rivers criss-crossed and divided the one huge landmass (Pangaea) into many smaller
landmasses. Now the lifeless (there was no life, remember?), want to know the number of
landmasses on the planet after all the meteorites have fallen. They also want to know the area of
the smallest and largest landmass. Can you help the lifeless in this question?

Input:
First line contains T which is the number of test cases.
First line of every test case contains 3 integers N, M, Q where N and M are coordinates of the
bottom right corner of the planet and Q is the number of meteorites.
The next Q lines contains the coordinates X, Y where each of the meteorites fell.

Output:
For each test case, output a line containing 3 integers indicating the number of regions, the
minimum area and the maximum area.

Constraints:

1 T 10

2 N, M 105

0 Q 105

1XN

1YM

Scoring:

## Original Constraints : (40 pts)

Note:

The Earth can be assumed to be a rectangle with top left point as (1,1) and bottom right
point (N,M).

## More than one meteorite may have landed at some point.

The rivers may be assumed to be flowing in very thin straight lines parallel to the edges
of the planet.

Sample Input
1
5 5 2
2 3
4 4
Sample Output
9 1 4
Explanation
Refer to image below showing all the regions with individual areas.

Problem
Editorial
My Submissions
Shil has an array of N elements A1 , A2, ... ,AN . He also has an integer K. He wants to find out
value of Square Sum for every i from 1 to N-K+1.
The value of Square Sum for certain i is defined as 1 j K (j2 Ai+j-1).
Input:
First line of input consists of two integers N and K. Next line consists of N integers A1 , A2, ... ,AN.
Output:
Output N-K+1 integers where ith integer corresponds to Square Sum of i. Print Square Sum
modulus 109+7.

Constraints:

1 K N 106

1 Ai 109

Sample Input
6 3
6 9 10 10 4 6
Sample Output
132 139 86 80

Problem
Editorial
My Submissions
Dilku was thinking about the first time he met his girl... It was indeed a walk to remember. The
romantic weather and her silly talks. He was completely mesmarized. Those were the days!..
Today is his girl's birthday and he wants to make it special for her. He wants to again take her on
a "special walk" that they would remember for the lifetime.
The city in which Dilku lives is represented as an unweighted directed graph with N nodes and M
edges. A "special walk" in the graph starting at node u is a simple path that begins and ends at
the same node u.

Formally, A special walk is path u , a1 , a2 , a3 ,..., ai ,.... , u where ai are distinct and not equal to
u for all i.
Now since Dilku is really nervous about taking his girl out, he needs your help. For every node in
the given graph, tell whether it is possible for Dilku to take his girl on a "special walk" starting at
that node.
Input:
First line of a two space separated integers denoting N and M, the number of nodes and number
of directed edges in the corresponding graph.
Following M lines contain two space separated integers u v denoting a directed edge in the
graph from vertex numbered u to vertex numbered v.
Output:
Print N space separated integers, where ith integer can be either 1 or 0 depicting whether it is
possible to go on a special walk starting at node i or not.
Constraints:

1 N 105

1 M 2 105

1 u, v N

Sample Input
5 5
1 2
2 3
3 4
4 5
4 2
Sample Output
0 1 1 1 0
Explanation
In the given graph , there is just one directed cycle : 2-->3-->4-->2. Hence, for all nodes on this
cycle, the answer is yes and for others the answer is no.

Problem
Editorial
My Submissions
Kevin thinks that array A is beautiful if

## It doesn't contain any bad numbers.

There doesn't exist any number x and tuple (y1, y2, ..., yK) such that Ax = Ay1 Ay2 ...
AyK (yi < x).

Kevin knows M bad numbers Bi. Kevin also knows that 1 isn't a bad number. Now he wants to
find lexicographically smallest beautiful array.
Input format:
The first line of the input contains three numbers N, K, M. The next line contains M integers - B i.
Output format:
Output N integers - lexicographically smallest beautiful array.
Constraints:

2 N, K 2 104

0 M 2 104

0 Bi 109

Sample Input