1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <string>


int main() {
    int number_of_games;
    std::string price;
    std::string price1;
    std::string last_price;
    long long res=0;

    std::cin >> number_of_games;
    while(number_of_games--) {
        std::cin >> price;
        if(last_price.size() < price.size() || (last_price.size() == price.size() && last_price < price)) {
            // do nothing
        } else if(last_price.size() == price.size() && last_price >= price) {
            price.push_back('0');
            res++;
        } else if(last_price.substr(0, price.size()) < price) {
            res += last_price.size() - price.size();
            price.append(std::string(last_price.size() - price.size(), '0'));
        } else if(last_price.substr(0, price.size()) == price && last_price.substr(price.size(), std::string::npos) != std::string(last_price.size() - price.size(), '9')){
            res += last_price.size() - price.size();
            price.append(last_price.substr(price.size(), std::string::npos));
            std::string::reverse_iterator i;
            for(i=price.rbegin(); *i == '9'; ++i) {
                *i = '0';
            }
            char c = *i;
            *i = c+1;
        } else {
            res += last_price.size() - price.size()+1;
            price.append(std::string(last_price.size() - price.size()+1, '0'));
        }
        last_price = price;
    }
    std::cout << res << std::endl;
    return 0;
}