If you made the rankings in the Weakness Cup Online Competition, you can now claim your participation prize—a special code that can be redeemed for Ampharosite, Altarianite, Latiosite, and Latiasite Mega Stones now through August 30, 2017, at 23:59 UTC. Just log in to the Pokémon Global Link (PGL) using the game that you used to participate in the Weakness Cup and click here.
To redeem the code in your game, select Mystery Gift from the main menu, then select Receive Gift, and then select Get with Code/Password and follow the prompts to enter your special code. Be sure to enter the code in your copy of Pokémon Sun or Pokémon Moon before August 30, 2017, at 23:59 UTC. Visit the Online Competitions page for Weakness Cup Trainer and Pokémon rankings.
Source: Pokémon Global Link