# New Year Tree Decorations

Due to atheistic Soviet past, Christmas wasn’t officially celebrated in Russia for most of the twentieth century. As a result, the Russian traditions for Christmas and New Year mixed into one event celebrated on the New Year but including the tree, a Santa-like ‘Grandfather Frost’, presents and huge family reunions and dinner parties all over the country. Bying a Tree at the New Year and installing it in the house is a tradition. Usually the whole family decorates the tree on the New Year Eve. We hope that Codeforces is a big and loving family, so in this problem we are going to decorate a tree as well.

So, our decoration consists of n pieces, each piece is a piece of colored paper, its border is a closed polyline of a special shape. The pieces go one by one as is shown on the picture. The i-th piece is a polyline that goes through points: (0, 0), (0, y 0), (1, y 1), (2, y 2), …, (k, y k), (k, 0). The width of each piece equals k.

The figure to the left shows the decoration, the figure to the right shows the individual pieces it consists of.

The piece number 1 (shown red on the figure) is the outer piece (we see it completely), piece number 2 (shown yellow) follows it (we don’t see it completely as it is partially closed by the first piece) and so on. The programmers are quite curious guys, so the moment we hung a decoration on the New Year tree we started to wonder: what area of each piece can people see?

Input

The first line contains two integers, n and k (1 ≤ n, k ≤ 300). Each of the following n lines contains k + 1 integers — the description of the polyline. If the i-th line contains ontegers y i, 0, y i, 1, …, y i, k, that means that the polyline of the i-th piece goes through points (0, 0), (0, y i, 0), (1, y i, 1), (2, y i, 2), …, (k, y i, k), (k, 0) (1 ≤ y i, j ≤ 1000).

Output

Print n real numbers — for each polyline, the area of its visible part.

The answer will be considered correct if its relative or absolute error do not exceed 10 - 4.

Examples

input

2 22 1 21 2 1

output

3.0000000000000.500000000000

input

1 11 1

output

1.000000000000

input

4 12 77 25 56 4

output

4.5000000000001.2500000000000.0500000000000.016666666667

Solution:

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>

using namespace std;

const int MAX = 5005;
const int N = 610;
const int NN = 123456;
const double eps = 1e-10;

int py[N][N];
double x[NN], y[NN], xx[NN], yy[NN], ans[NN];

int main() {
int cnt, width;
scanf("%d %d", &cnt, &width);
for (int i = 0; i < cnt; i++)
for (int j = 0; j <= width; j++) scanf("%d", py[i] + j);
for (int i = 0; i < cnt; i++) ans[i] = 0.0;
for (int w = 0; w < width; w++) {
int n = 4;
x[0] = 0; y[0] = MAX;
x[1] = 0; y[1] = 0;
x[2] = 1; y[2] = 0;
x[3] = 1; y[3] = MAX;
double old_area = 0.0;
for (int id = 0; id < cnt; id++) {
int xa = 0, ya = py[id][w];
int xb = 1, yb = py[id][w + 1];
int a = yb - ya;
int b = xa - xb;
int c = -a * xa - b * ya;
int nn = 0;
for (int i = 0; i < n; i++) {
double z = a * x[i] + b * y[i] + c;
if (z < eps) {
xx[nn] = x[i];
yy[nn] = y[i];
nn++;
}
if (i < n - 1) {
double zz = a * x[i + 1] + b * y[i + 1] + c;
if ((z < -eps && zz > eps) || (zz < -eps && z > eps)) {
double aa = y[i + 1] - y[i];
double bb = x[i] - x[i + 1];
double cc = -aa * x[i] - bb * y[i];
double d = a * bb - b * aa;
double dx = (b * cc - c * bb) / d;
double dy = (c * aa - a * cc) / d;
xx[nn] = dx;
yy[nn] = dy;
nn++;
}
}
}
n = nn;
for (int i = 0; i < n; i++) {
x[i] = xx[i];
y[i] = yy[i];
}
double area = 0.0;
for (int i = 0; i < n - 1; i++) area += (x[i + 1] - x[i]) * (y[i + 1] + y[i]);
area *= 0.5;
ans[id] += area - old_area;
old_area = area;
}
}
for (int i = 0; i < cnt; i++) printf("%.17lf\n", ans[i]);
return 0;
}