#!/bin/perl
die "need the shift as argument\n" unless @ARGV;
my $shift = shift(@ARGV);
my $fresh = 1;
while(<STDIN>)
{
	chomp();
	if($fresh)
	{
		if(/^(\d+):(\d+):(\d+),(\d+)(\s*-->\s*)(\d+):(\d+):(\d+),(\d+)\s*$/)
		{
			my $sep = $5;
			my $from = sec($1,$2,$3,$4);
			my $to = sec($6,$7,$8,$9);
			print STDERR "$from -> $to\n";
			print hms($from+$shift).$sep.hms($to+$shift)."\n";
			$fresh = 0;
		}
		else{ print $_."\n"; }
	}
	else
	{
		if(//){ $fresh = 1; }
		print $_."\n";
	}
}

sub sec
{
	my ($h, $m, $s, $sf) = @_;
	$ss = "$s.$sf";
	return ($h*60+$m)*60+$ss
}

sub hms
{
	my $sec = shift;
	if($sec < 0){ $sec = 0; }
	my $h = int($sec/3600+0.00001);
	$sec -= $h*3600;
	my $m = int($sec/60+0.00001);
	$sec -= $m*60;
	my $s = int($sec+0.00001);
	$sec -= $s;
	my $sf = int(1000*$sec+0.00001);
	return sprintf("%02i:%02i:%02i,%03i", $h, $m, $s, $sf);
}
