The formula is always
1/v - 1/u = 1/f
magnification is m = v/u = h'/h
1. Distances u , v , f measured against the direction of rays from object are negative. If object on the left, lens on the right side, then u is negative. Focal length for convex lens is +ve. Focal length for concave lens is negative.
2. Distances or heights h or h' of objects and images which are erect (+Y direction) are positive. Inverted lengths h' or h in -y direction are negative.
Substitute +ve or negative sign along with numerical values.
One good thing, you can do, call U, V, F, H, H' to be always positive and equal to |u|, | v | ,....
Then for a concave lens, u = - U, v = - V, f = -F. h = H, h' = H'
For a convex lens for real image, h = H, h' = -H' f = F, u = -U, v = -V.
Make a table of all signs for all virtual and real images for all lenses. Then you will understand it.