Couldn't you come up with better names for f and b, and what's their purpose, really?
It seems you use them as flag - while it's much easier to use a single boolean flag and just check whether it's true or false. Like this:
bool f = false;
[...]
// if((digitalRead(A0) == HIGH) && f==b) // if(digitalRead(A0)) or if(!digitalRead(A0))
if((digitalRead(A0) == HIGH) && !f) // if(digitalRead(A0)) or if(!digitalRead(A0))
{
timer = millis();
// f = f+1;
f = true;
}
// if((!digitalRead(A0))&& f==b+1)
if((!digitalRead(A0)) && f)
{
timef = millis() - timer;
// f = f-1;
f = false;
timenow = millis();
}
Now give f a more descriptive name and your code has become a lot more readable. Also do a CTRL-T in the IDE to fix your indentation.