#include <vector>
#include <algorithm>
#include <iostream>
int main()
{
int arr[] = {3,5,4,12,1,4,7,2,6,5};
auto m = std::begin(arr);
while (m != std::end(arr))
{
m = std::max_element(m, std::end(arr));
std::cout << *(m++) << std::endl;
}
}
ICAgICNpbmNsdWRlIDx2ZWN0b3I+CiAgICAjaW5jbHVkZSA8YWxnb3JpdGhtPgogICAgI2luY2x1ZGUgPGlvc3RyZWFtPgoKICAgIGludCBtYWluKCkKICAgIHsKICAgICAgICBpbnQgYXJyW10gPSB7Myw1LDQsMTIsMSw0LDcsMiw2LDV9OwoKICAgICAgICBhdXRvIG0gPSBzdGQ6OmJlZ2luKGFycik7CiAgICAgICAgd2hpbGUgKG0gIT0gc3RkOjplbmQoYXJyKSkKICAgICAgICB7CiAgICAgICAgICAgIG0gPSBzdGQ6Om1heF9lbGVtZW50KG0sIHN0ZDo6ZW5kKGFycikpOwogICAgICAgICAgICBzdGQ6OmNvdXQgPDwgKihtKyspIDw8IHN0ZDo6ZW5kbDsKICAgICAgICB9CiAgICB9