AMP code implementation


I found a simple guide for implementing Adsense codes into AMP version of my site.
-> head tags
-> sample ad codes

However, when I place it on my functions.php it either doesn't show anything or display unusual blank space, etc. Not consistent at all.

So I removed it from my site and came here to ask: Where exactly should I put the head tags and then the ad codes themselves?

(The page doesn't make any reference to the official AMP plugin so I thought it is not related to that plugin.
This is essentially a question of WordPress semantics, I assume)

Thanks in advance.