A Linear-Time Algorithm for the Copy Number