Problem:
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

B - Cube Coloring

Problem Statement

Great painter Cubic is famous for using cubes for his art. Now, he is engaged in a new work of art. He tries to form an $X \times Y \times Z$ rectangular parallelepiped by arranging and piling up many $1 \times 1 \times 1$ cubes such that the adjacent surfaces of cubes are fully shared.

Of course, he won't finish his work only arranging and piling up cubes. The position of each cube is denoted by $(0,0,0)$ through $(X-1,Y-1,Z-1)$ as by the ordinary coordinate system, and Cubic calls the cube $(A,B,C)$ the origin cube. Then, he paints a pattern on the rectangular parallelepiped with different colors according to the distance between each cube and the origin cube. He paints all cubes regardless of whether or not a cube is visible externally. This is his artistic policy. He uses Manhattan distance as the distance between cubes. The Manhattan distance between two cubes $(x_1,y_1,z_1)$ and $(x_2,y_2,z_2)$ is defined as $|x_1-x_2| + |y_1-y_2| + |z_1-z_2|$.

On the current work, Cubic decides to use $N$ colors, which are numbered from $1$ to $N$. He paints a cube with the $(i+1)$-th color if the distance $D$ between the cube and the origin cube satisfies $D \equiv i \pmod{N}$.

Cubic wants to estimate the consumption of each color in order to prepare for the current work. He asks a great programmer, you, to write a program calculating the number of cubes that will be painted by each color.

Input

The input contains seven integers $X$, $Y$, $Z$, $A$, $B$, $C$, and $N$. All integers are in one line and separated by a single space. Three integers $X$, $Y$, and $Z$ ($1 \leq X, Y, Z \leq 10^6$) represent the length of each side of the rectangular parallelepiped that Cubic tries to form. Three integers $A$, $B$, and $C$ ($0 \leq A \lt X$, $0 \leq B \lt Y$, $0 \leq C \lt Z$) represent the position of the origin cube. The number of kinds of colors is denoted by $N$ ($1 \leq N \leq 1{,}000$).

Output

The output contains $N$ integers in one line. The $i$-th integer ($1 \leq i \leq N$) represents the number of the cubes that will be painted by the $i$-th color. All integers must be separated by a single space.

Sample Input 1

2 2 2 0 0 0 5

Output for the Sample Input 1

1 3 3 1 0

Sample Input 2

4 3 3 1 1 1 3

Output for the Sample Input 2

13 10 13

Sample Input 3

2000 2000 2000 1000 1000 1000 1

Output for the Sample Input 3

8000000000

Solution in C++11 (judge verdict: Accepted)

#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"

int N;
int X, Y, Z, A, B, C;
vector<long long int>getx() {
	vector<long long int>cs(X);
	cs[A] = 0;
	{
		int nc = 0;
		for (int x = A + 1; x < X; ++x) {
			nc++;
			nc %= N;
			cs[x] = nc;
		}
	}
	{
		int nc = 0;
		for (int x = A - 1; x >= 0; --x) {
			nc++;
			nc %= N;
			cs[x] = nc;
		}
	}
	vector<long long int>nums;
	for (int i = 0; i < N; ++i) {
		nums.emplace_back(count(cs.begin(), cs.end(), i));
	}
	vector<long long int>nums2(N);
	nums2[0] = 1;
	vector<long long int>ans(N);
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			ans[(i + j) % N] += nums[i] * nums2[j];
		}
	}
	
	return ans;
}
vector<long long int>getxy() {
	vector<long long int>cs(Y);
	cs[B] = 0;
	{
		int nc = 0;
		for (int y = B + 1;y < Y; ++y) {
			nc++;
			nc %= N;
			cs[y] = nc;
		}
	}
	{
		int nc = 0;
		for (int y = B - 1; y >= 0; --y) {
			nc++;
			nc %= N;
			cs[y] = nc;
		}
	}
	vector<long long int>nums;
	for (int i = 0; i < N; ++i) {
		nums.emplace_back(count(cs.begin(), cs.end(), i));
	}
	vector<long long int>nums2(getx());
	vector<long long int>ans(N);
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			ans[(i + j) % N] += nums[i] * nums2[j];
		}
	}
	return ans;
}
vector<long long int>getxyz() {
	vector<long long int>cs(Z);
	cs[C] = 0;
	{
		int nc = 0;
		for (int z = C + 1; z < Z; ++z) {
			nc++;
			nc %= N;
			cs[z] = nc;
		}
	}
	{
		int nc = 0;
		for (int z = C - 1; z >= 0; --z) {
			nc++;
			nc %= N;
			cs[z] = nc;
		}
	}
	vector<long long int>nums;
	for (int i = 0; i < N; ++i) {
		nums.emplace_back(count(cs.begin(), cs.end(), i));
	}
	vector<long long int>nums2(getxy());
	vector<long long int>ans(N);
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			ans[(i + j) % N] += nums[i] * nums2[j];
		}
	}
	return ans;
}

int main() { 
	cin >> X >> Y >> Z >> A >> B >> C;
	cin >> N;
	vector<long long int>ans=getxyz();
	for (int i = 0; i < N; ++i) {
		cout << ans[i];
		if (i != N - 1)cout << " ";
		else cout << endl;
	}

	return 0;
}