David and Sam had some games cards at a ratio of 4:5. Both later collected some more cards. As a result, David collected another 50% of his original number of cards and Sam collected 2 times his original number of cards. If Sam had 40 more game cards than David, how many cards did they have altogether in the end?