#include <stdio.h>


int main(){

int menit;
int angkaangka[5];
for(int i=0;i<5; i++){
    scanf("%d", &angkaangka[i]);
}
//for(int i=0;i<5; i++){
//   printf("%d ", angkaangka[i]);
//}
int jam=angkaangka[2]-angkaangka[0];
//printf("total jam: %d\n", jam);
if(angkaangka[3]>angkaangka[1]){
    menit=angkaangka[3]-angkaangka[1];
}
else if(angkaangka[1]>angkaangka[3]){
    menit=60-(angkaangka[1]-angkaangka[3]);
    jam--;
}
else{
    menit=0;
}
//printf("total menit=%d\n", menit);
//printf("total k= %d\n", angkaangka[4]);
printf("%d\n", jam*60+menit-angkaangka[4]);





    return 0;
}
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
#define REP(i,n) for (int i=0; i<(n); i++)
#define SORT(c) sort((c).begin(),(c).end())
typedef vector<int> vi;
int main() {
	vi W(10),K(10);
	REP(i,10) scanf("%d",&W[i]);
	REP(i,10) scanf("%d",&K[i]);
	SORT(W); SORT(K);
	int w=0,k=0;
	REP(i,3) w+=W[9-i];
	REP(i,3) k+=K[9-i];
	printf("%d %d\n",w,k);
}