za,zb,zc=map(int,input().split(":")) ha,hb,hc=map(int,input().split(":")) v=int(input()) a=za-ha b=zb-hb c=zc-hc a=a*3600 b=b*60 t=a+b+c print(t*v)