added lecture12's codes.