Implementation for sigmod 2013 programming contest