Help with speeding up this code

Hi, can you please format the code with three backticks at the start and at the end, as well as the correct indentations? It would make things much easier for us :slight_smile: