Language: C++

#include<iostream>
#include<cstdlib>
using namespace std;

int charge(int in, int out);
int dist(int in, int out);
int checkhalf(int ih, int im, int oh, int om, int dis);
int half(int y);

int main(){
	while(1){
		int inic, inh, inm, outic, outh, outm, yen, kyori;
		cin >>inic;
		if(inic == 0) break;
		cin >>inh >>inm >>outic >>outh >>outm;
		
		yen = charge(inic, outic);
		kyori = dist(inic, outic);
		if(checkhalf(inh, inm, outh, outm, kyori)) yen = half(yen);
		
		cout <<yen <<endl;
	}
	return 0;
}

int charge(int in, int out){
	if(in == 1){
		if(out == 2) return 300;
		if(out == 3) return 500;
		if(out == 4) return 600;
		if(out == 5) return 700;
		if(out == 6) return 1350;
		if(out == 7) return 1650;
	} else if(in == 2){
		if(out == 1) return 300;
		if(out == 3) return 350;
		if(out == 4) return 450;
		if(out == 5) return 600;
		if(out == 6) return 1150;
		if(out == 7) return 1500;
	} else if(in == 3){
		if(out == 1) return 500;
		if(out == 2) return 350;
		if(out == 4) return 250;
		if(out == 5) return 400;
		if(out == 6) return 1000;
		if(out == 7) return 1350;
	} else if(in == 4){
		if(out == 1) return 600;
		if(out == 2) return 450;
		if(out == 3) return 250;
		if(out == 5) return 250;
		if(out == 6) return 850;
		if(out == 7) return 1300;
	} else if(in == 5){
		if(out == 1) return 700;
		if(out == 2) return 600;
		if(out == 3) return 400;
		if(out == 4) return 250;
		if(out == 6) return 600;
		if(out == 7) return 1150;
	} else if(in == 6){
		if(out == 1) return 1350;
		if(out == 2) return 1150;
		if(out == 3) return 1000;
		if(out == 4) return 850;
		if(out == 5) return 600;
		if(out == 7) return 500;
	} else if(in == 7){
		if(out == 1) return 1650;
		if(out == 2) return 1500;
		if(out == 3) return 1350;
		if(out == 4) return 1300;
		if(out == 5) return 1150;
		if(out == 6) return 500;
	}
}

int dist(int in, int out){
	if(in == 1){
		if(out == 2) return 6;
		if(out == 3) return 13;
		if(out == 4) return 18;
		if(out == 5) return 23;
		if(out == 6) return 43;
		if(out == 7) return 58;
	} else if(in == 2){
		if(out == 1) return 6;
		if(out == 3) return 7;
		if(out == 4) return 12;
		if(out == 5) return 17;
		if(out == 6) return 37;
		if(out == 7) return 52;
	} else if(in == 3){
		if(out == 1) return 13;
		if(out == 2) return 7;
		if(out == 4) return 5;
		if(out == 5) return 10;
		if(out == 6) return 30;
		if(out == 7) return 45;
	} else if(in == 4){
		if(out == 1) return 18;
		if(out == 2) return 12;
		if(out == 3) return 5;
		if(out == 5) return 5;
		if(out == 6) return 25;
		if(out == 7) return 40;
	} else if(in == 5){
		if(out == 1) return 23;
		if(out == 2) return 17;
		if(out == 3) return 10;
		if(out == 4) return 5;
		if(out == 6) return 20;
		if(out == 7) return 35;
	} else if(in == 6){
		if(out == 1) return 43;
		if(out == 2) return 37;
		if(out == 3) return 30;
		if(out == 4) return 25;
		if(out == 5) return 20;
		if(out == 7) return 15;
	} else if(in == 7){
		if(out == 1) return 58;
		if(out == 2) return 52;
		if(out == 3) return 45;
		if(out == 4) return 40;
		if(out == 5) return 35;
		if(out == 6) return 15;
	}
}

int checkhalf(int ih, int im, int oh, int om, int dis){
	int flag = 0;
	if(dis > 40){	//s£ª40kmæè·¢
		return 0;
	}
	
	if(ih > oh || (ih == oh && im > om)){	//úðÜ½¢¾
		if((ih > 17 || (ih == 17 && im >= 30)) && (ih < 19 || (ih == 19 && im <= 30))){	//üÁ½Ôª¼zÍÍàÅ
			if(oh < 17 || (oh == 17 && om < 30)){	//o½ÔªúðÜ½¢Å¼zÍÍO¾Á½
				return 1;
			}
		} else{
			return 0;
		}
		if(ih > 19 || (ih == 19 && im > 30)){	//üÁ½Ôª¼zÍÍæèàãÅ
			if((oh > 17 || (oh == 17 && om >= 30)) && (oh < 19 || (oh == 19 && om <= 30))){	//o½ÔªúðÜ½¢Å¼zÍÍà¾Á½
				return 1;
			}
		} else{
			return 0;
		}
	}
	
	if((ih < 17 || (ih == 17 && im <= 30)) && (oh > 17 || (oh == 17 && om >= 30)) && (oh < 19 || (oh == 19 && om < 30))){	//17æèO©1730ªÈOÉüèA17æèã©1730ªÈ~A©ÂA19æèO©1930ªæèOÉo½
		flag = 1;
	} else if((ih > 17 || (ih == 17 && im > 30)) && (ih < 19 || (ih == 19 && im <= 30)) && (oh > 19 || (oh == 19 && om >= 30))){	//àµ­ÍA17æèã©1730ªæèãA©ÂA19æèO©1930ªÈOÉüèA19æèã©1930ªÈ~Éo½
		flag = 1;
	}
	if(ih == oh && im == om && flag){	//flagª1ÅAüéÔÆoéÔª¯¶¾Á½
		flag = 0;
	}
	return flag;
}

int half(int y){
	int ans;
	double temp = y;
	temp /= 2.0;
	temp = ceil(temp);
	ans = (int)temp;
	if(ans % 50 != 0){
		ans = ans + abs((ans % 50) - 50);
	}
	return ans;
}

Compiler output:
a.cc: In function 'int half(int)':
a.cc:170:16: error: 'ceil' was not declared in this scope
  170 |         temp = ceil(temp);
      |                ^~~~
a.cc: In function 'int charge(int, int)':
a.cc:77:1: warning: control reaches end of non-void function [-Wreturn-type]
   77 | }
      | ^
a.cc: In function 'int dist(int, int)':
a.cc:130:1: warning: control reaches end of non-void function [-Wreturn-type]
  130 | }
      | ^