Before my period comes I have a dark brown discharge that lasts for 4 days, after which comes the regular heavy flow of menstrual blood.The menstrual blood lasts for 8 days after the 5 days. so it takes total almost 14 days to purify from this cycle.I wonder whether I should pray or fast on those 4 days before heavy flow?

The conditions of hayz are that there should be continuity in the first three days such that one cannot say they are clean from bleeding even for 10 minutes. Therefore if the brown discharge at prior to regular flow has no continuity and comes on and off then you will have to follow the rules of istihadha within which you can pray and fast.

If the discharge is very little then you will follow the rules of istihadha qaleel for prayers which means prior to namaz, change the sanitary pad or if discharge has come onto your undergarments, change them and wash your private parts and do wudhu. Blood of istihadha invalidates wudhu as well hence if between two namaz discharge comes out then you have to redo your wudhu and if blood spreads to the outside of the vagina then it has to be washed as well.