Initially written for Yandex competition hosted at kaggle