I would not put that code into the theme. Create a plugin with the following content:
<?php
/* Plugin Name: Millennial Media Ads */
add_action( 'show_ads', 'mma_show_ads' );
function mma_show_ads()
{
# copy your PHP code into this function.
}
In your theme choose the place where you want to show the ads and write:
do_action( 'show_ads' );
That’s all. The benefit is: If the ads don’t work some day, or the ad server was hijacked or whatever, you can just deactivate the plugin and all is fine.