Problem F. Travel Through Time

HDU - 6337