Ralph and Sandra baked cookies. They gave half of all their cookies to their classmates. Then they gave half of what was left to their teachers. They then ate the remaining 12 cookies. How many had they made all together?