These accidentals are put at the beginning of a piece in the form of key signature and throughout the piece the notes affected are played automatically sharp or flat, as the case may be, unless contradicted by an accidental.