There's a myth about Max Martin's melodic math that all phrase repetitions must be precise. That's not true--while repetitions are very close, Max 'tolerates' two kinds of melodic variations on the core motif: 1. Variations that allow lyrical flexibility WITHOUT harming the integrity of the core motif. 2. Variations that change the melodic function of the phrase and allow it to fit into a melodic structure (e.g., ABAC). Those have more freedom to tweak core notes but it still has to sound like a repetition. Here's an example from Taylor Swift's "Shake It Off" (2014).
Top40 Theory provides advanced music theory and composition knowledge, as well as consulting/coaching services, to pop songwriters and producers. You can follow Top40 Theory’s Twitter,Instagram, and Facebook page, as well as join the mailing list via the form located in the sidebar, to receive updates about new posts and other pop music theory related musings. You can also join the growing community of highly accomplished songwriters, producers, theorists, and composers at the Top40 Theory Facebook group.