First follow this tutorial
https://xdaforums.com/samsung-a-series-2017/how-to/samsung-sm-a520f-2017-kernel-source-t3557622
And then copy the ROM to the microsd card and download the ARM_64/ANDROID 7.1 Pico variant gapps from this web:
http://opengapps.org
And then copy it too to the microsd card. Then make a factory reset and manually format /data un the Format menu of TWRP
Next, flash the ROM, wipe Dalvik-Cache, flash the gapps, wipe Dalvik-Cache and if u want to root, first reboot the phone, wait until it starts, and then flash superSU zip.
And restart. DO NOT stop the process. Maybe the phone will last 5 minutes booting, just wait.
If u don't understand it, maybe you shouldn't be here installing a custom ROM.
But if you really want to, just tell me where do you have problems and i'll help