#define _LARGEFILE64_SOURCE
#include <stdio.h>
#include <stdint.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#include <math.h>

#define BSIZE (1 << 20)

int main (void)
{
    unsigned int stats[256];
    unsigned int stats2[256][256];
    int i, j, l, bread;
    uint8_t buffer[BSIZE];
    double tmean1, tmean2, rmean1, rmean2, t;
    int counter = 0;

    while (1) {
	bread = read (0, buffer, BSIZE);
	if (bread < BSIZE) {
	    printf ("Pas lu assez\n");
	    return 0;
	}
	memset (stats, 0, 256);
	memset (stats2, 0, 65536);
	for (i = 0; i < 256; i++) {
	    for (j = 0; j < 256; j++) {
		stats2[i][j] = 0;
	    }
	    stats[i] = 0;
	}
	for (l = 0; l < bread; l++) {
	    stats[buffer[l]]++;
	    if (l & 1) {
		stats2[buffer[l-1]][buffer[l]]++;
	    }
	}
	tmean1 = bread / 256.;
	tmean2 = bread / 65536.;
	rmean1 = rmean2 = 0;
	for (i = 0; i < 256; i++) {
	    for (j = 0; j < 256; j++) {
		t = (stats2[i][j] - tmean2);
		rmean2 += t * t;
	    }
	    t = (stats[i] - tmean1);
	    rmean1 += t * t;
	}
	rmean1 = sqrt (rmean1 / 256.);
	rmean2 = sqrt (rmean2 / 65536.);
	printf ("%d %f %f\n", counter, rmean1, rmean2);
	counter++;
	if (lseek64 (0, 10*(1 << 20), SEEK_CUR) == -1) {
	    printf ("lseek merdu\n");
	    return 0;
	}
    }
    return 0;
}
