Sam has twice as many books as Jim. If Sam gives 12 books to Jim, they will have the same number of books. How many books do they have altogether?