#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;
}
