Efficient Algorithm for Box Folding