#include <stdio.h>
#include <math.h>

#define diy 365.25
#define R 6.371*1000000 				/* radius of the Earth */
#define pi 3.14159

double lat, lon, altitude, time; 			/* input lf */
int junk, yy, mh, dd, hh, mn, ss; 			/* input d */
int samples, duration, iyy, imh, idd, ihh, imn, iss; 	/* input data Stage 2 */

/* calculation data Stage 2 */
int pyy, pmh, pdd, phh, pmn, pss;
int pavinterval, avinterval, maxinterval, interval;

/* calculation data Stage 3 */
double plat, plon;
double total_sdist, sdist, a, hdist, total_hdist;

/* calculation data Stage 4 */
double elapsed_time, uspeed, pudist;
int update_time, uyy, umh, udd, uhh, umn, uss;

int
main(int argc, char **argv){
	
	/* !! skip first 6 lines !! */
	
	/* read inital value */
	scanf("%lf,%lf,%d,%lf,%lf,%4d-%2d-%2d,%2d:%2d:%2d",
		&lat, &lon, &junk, &altitude, &time, &yy, &mh, &dd, &hh, &mn, &ss);
	
	/* print Stage 1 */
	printf("Stage 1\n=======\n");
	printf("GPS trace commences                           : %04d-%02d-%02d, %02d:%02d:%02d\n\n",yy, mh, dd, hh, mn, ss);
	
	lat *= (pi/180);
	lon *= (pi/180);
	
	/* store inital values */
	iyy=yy;imh=mh;idd=dd;ihh=hh;imn=mn;iss=ss; 			/* starting time */
	pyy=yy;pmh=mh;pdd=dd;phh=hh;pmn=mn;pss=ss;plon=lon;plat=lat; 	/* previous line's data */
	pavinterval=0;total_sdist=0;total_hdist=0; 			/* distance and previous interval's to zero */
	uyy=yy;umh=mh;udd=dd;uhh=hh;umn=mn;uss=ss;pudist=0; 		/* initalising update itervals */
	samples = 1; 							/* read first sample */
	
	printf("Stage 4\n=======\n");
	
	/* scan rest of files */
	while(scanf("%lf,%lf,%d,%lf,%lf,%4d-%2d-%2d,%2d:%2d:%2d", &lat, &lon, &junk, &altitude, &time, &yy, &mh, &dd, &hh, &mn, &ss)==11){
		
		lat *= (pi/180);
		lon *= (pi/180);
		
		/* calculate interval */
		interval = ((((((yy-pyy)*diy + (dd-pdd))*24 + (hh-phh))*60 + (mn-pmn))*60 + (ss-pss)));		
		
		if (interval > maxinterval){
			maxinterval = interval;
			}
		
		/* !! simple distance formula !! */
		sdist = R*sqrt(((lon-plon)*cos((plat+lat)/2))*((lon-plon)*cos((plat+lat)/2)) + (plat-lat)*(plat-lat));
		total_sdist += sdist;
		
		/* !! haversine distance formula !! */
		a = sin((lat-plat)/2)*sin((lat-plat)/2) + cos(lat)*cos(plat)*sin((lon-plon)/2)*sin((lon-plon)/2);
		hdist = 2*R*atan2(sqrt(a),sqrt(1-a));
		total_hdist += hdist;
		
		/* speed update */
		/* !! */ update_time = ((((((yy-uyy)*diy + (dd-udd))*24 + (hh-uhh))*60 + (mn-umn))*60 + (ss-uss)));
		if (update_time>5*60){
			uspeed=((total_hdist-pudist)/(update_time))*3.6;
			printf("Period ending %04d-%02d-%02d, %02d:%02d:%02d, average %5.1lf km/hr \n", yy, mh, dd, hh, mn, ss, uspeed);
			uyy=yy;umh=mh;udd=dd;uhh=hh;umn=mn;uss=ss;pudist=total_hdist;
		}
		samples++;
		pyy=yy;pmh=mh;pdd=dd;phh=hh;pmn=mn;pss=ss;plon=lon;plat=lat;pavinterval=avinterval;

	}
		
	/* calculate duration of data */
	duration = ((((((yy-iyy)*diy + (dd-idd))*24 + (hh-ihh))*60 + (mn-imn))*60 + (ss-iss)));
	avinterval = duration/(samples-1);
		
	/* print Stage 2 */
	printf("\nStage 2\n=======\n");
	printf("GPS trace terminates                          : %04d-%02d-%02d, %02d:%02d:%02d\n",yy, mh, dd, hh, mn, ss);
	printf("GPS trace samples                             : %20d\n",samples);
	printf("GPS trace duration                            : %20d seconds (%.1lf hours)\n",duration,duration/(60.0*60.0));
	printf("Average interval between samples              : %20d seconds\n", avinterval);
	printf("Maximum interval between samples              : %20d seconds\n", maxinterval);
	
	/* print Stage 3 */
	printf("\nStage 3a\n=======\n");
	printf("Total distance travelled using simple rule    : %5d metres \n",(int)total_sdist);
	printf("Average speed over perios of trace            : %3.2lf m/sec \n",total_sdist/duration);
	printf("\nStage 3b\n=======\n");
	printf("Total distance travelled using haversine rule : %5d metres \n",(int)total_hdist);
	printf("Average speed over period of trace            : %3.2lf m/sec \n",total_sdist/duration);
	printf("Difference between simple and haversine       : %7.1e metres \n",total_sdist-total_hdist);
	
	
}