#include <cstdio>
#include <ctime>
#include <cstdlib>
#include <string>
using std::string;
struct Timestamper {
clock_t start;
Timestamper() : start(clock()) {}
~Timestamper() {
printf("Time=%.3fs\n", (clock() - start) * 1.0 / CLOCKS_PER_SEC);
}
};
template<typename T>
void calc1(T s) {
Timestamper t;
int ans = 0;
for (int i = 0; s[i]; i++)
for (int j = 0; s[j]; j++)
ans += s[i] == s[j];
printf("%d\n", ans);
}
template<typename T>
void calc2(T s) {
Timestamper t;
int ans = 0;
for (size_t i = 0; i < s.length(); i++)
for (size_t j = 0; j < s.length(); j++)
ans += s[i] == s[j];
printf("%d\n", ans);
}
const int MAXL = int(1.5e4);
char s[MAXL + 1];
int main() {
srand(123456);
for (int i = 0; i < MAXL; i++)
s[i] = 'a' + (rand() % 26);
s[MAXL] = 0;
calc1<const char*>(s);
calc1< char*>(s);
string str(s);
calc2<const string&>(str);
calc2<const string >(str);
calc2< string >(str);
calc2< string >(std::move(str));
return 0;
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGN0aW1lPgojaW5jbHVkZSA8Y3N0ZGxpYj4KI2luY2x1ZGUgPHN0cmluZz4KCnVzaW5nIHN0ZDo6c3RyaW5nOwoKc3RydWN0IFRpbWVzdGFtcGVyIHsKICBjbG9ja190IHN0YXJ0OwoKICBUaW1lc3RhbXBlcigpIDogc3RhcnQoY2xvY2soKSkge30KICB+VGltZXN0YW1wZXIoKSB7CiAgICBwcmludGYoIlRpbWU9JS4zZnNcbiIsIChjbG9jaygpIC0gc3RhcnQpICogMS4wIC8gQ0xPQ0tTX1BFUl9TRUMpOwogIH0KfTsKCnRlbXBsYXRlPHR5cGVuYW1lIFQ+CnZvaWQgY2FsYzEoVCBzKSB7CiAgVGltZXN0YW1wZXIgdDsKICBpbnQgYW5zID0gMDsKICBmb3IgKGludCBpID0gMDsgc1tpXTsgaSsrKQogIGZvciAoaW50IGogPSAwOyBzW2pdOyBqKyspCiAgICBhbnMgKz0gc1tpXSA9PSBzW2pd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