Article snapshot taken from Wikipedia with creative commons attribution-sharealike license.
Give it a read and then ask your questions in the chat.
We can research this topic together.
The scoring in the team competition and in the all-around was the same, as for gymnastics events at the previous Olympics (there was no team, portable apparatus event, however). But apart from two performances:a compulsory and an optional, which counted for both the team competition and the all-around, a gymnast, who competed in an apparatus final should show one's skills once more on the respective apparatus. For the final score ("Total" column in tables below), the compulsory routine's mark was added to the optional routine's, the result was divided by two ("Prelim" column) and added to the third routine's mark ("Final" column).