Folding Cloth — step-by-step animation

A fold is a rigid 180° rotation. If it leaves a gap inside a column, that column's cells are pressed together.

Grader format. First line N M; then M lines T X.
Type T: 0=LA, 1=LU, 2=RA, 3=RU.  Constraint per step: 1 ≤ X < current columns.
—

Highlighted = the cells folded in the current step. Use the box above to animate any test case.