Chain length is too long It seems me, that the chain is too long.

Probably this is the reason, why the chain falls sometimes.

By how many links I should shorten the length?

P.S. Probably the reason for it, that my 52T sprocket had broken and I replaced it by 50T sprocket.

PHOTO UPDATED after adjusting tension on a B-Screw on rear derailleur.
You can determine the proper chain length by following the technique used to size chains when they are installed - in a modify way, as you will have a joined chain.

Before doing that make sure the B-screw is adjusted correctly so that the upper jockey wheel is not hitting the largest sprocket.

Put the rear derailleur on the largest sprocket, take a couple of chain links and pull the chain taught (it may help if you have someone hold the derailleur cage to remove its tension. You should be able to pull two plates together so that they would be joinable with 2 links (one inner, one outer) of axtra chain between them.

I'd also check the spring tension in your derailleur, both the A pivot where the cage rotates and the B pivot where the derailleur rotates on the hanger.