Matthew walks up and down a hill which is three kilometers each way. His dog, being slower, walks at half the speed. When Matthew reaches the top of the hill he turns around and walks down to meet his dog part way. Matthew continues walking to the bottom of the hill maintaining his speed. The dog follows him, also maintaining his speed. How far does the dog walk?