Language: C++

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(),(v).end())
typedef int64_t lint;
// lint mod = 998244353;
// lint mod = 1000000007;
template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

// https://ei1333.github.io/luzhiled/snippets/structure/trie.html
template< int char_size >
struct TrieNode {
  int nxt[char_size];

  int exist;
  vector< int > accept;

  array<int,char_size> hist;

  TrieNode() : exist(0) {
    memset(nxt, -1, sizeof(nxt));
    rep(c,char_size) hist[c]=0;
  }
};

template< int char_size, int margin >
struct Trie {
  using Node = TrieNode< char_size >;

  vector< Node > nodes;
  int root;

  Trie() : root(0) {
    nodes.push_back(Node());
  }

  void update_direct(int node, int id) {
    nodes[node].accept.push_back(id);
  }

  void update_child(int node, int child, int id, array<int,char_size> childhist) {
    ++nodes[node].exist;
    rep(c,char_size) nodes[node].hist[c]+=childhist[c];
  }

  array<int,char_size> add(const string &str, int str_index, int node_index, int id) {
    if(str_index == str.size()) {
      update_direct(node_index, id);
      array<int,char_size> hist;
      rep(c,char_size) hist[c]=0;
      return hist;
    } else {
      const int c = str[str_index] - margin;
      if(nodes[node_index].nxt[c] == -1) {
        nodes[node_index].nxt[c] = (int) nodes.size();
        nodes.push_back(Node());
      }
      auto childhist = add(str, str_index + 1, nodes[node_index].nxt[c], id);
      childhist[c]=1;
      update_child(node_index, nodes[node_index].nxt[c], id, childhist);
      return childhist;
    }
  }

  void add(const string &str, int id) {
    add(str, 0, 0, id);
  }

  void add(const string &str) {
    add(str, nodes[0].exist);
  }

  void query(const string &str, const function< void(array<int,char_size>) > &f, int str_index, int node_index) {
    if(str_index == str.size()) {
      f(nodes[node_index].hist);
      return;
    } else {
      const int c = str[str_index] - margin;
      if(nodes[node_index].nxt[c] == -1) return;
      query(str, f, str_index + 1, nodes[node_index].nxt[c]);
    }
  }

  void query(const string &str, const function< void(array<int,char_size>) > &f) {
    query(str, f, 0, 0);
  }

  int count() const {
    return (nodes[0].exist);
  }

  int size() const {
    return ((int) nodes.size());
  }

};

lint app() {
  Trie< 26, 'a' > trie;

  int n;
  cin>>n;

  vector<string> s(n);
  rep(i,n){
    string st;
    cin>>st;
    reverse(st.begin(),st.end());
    s[i]=st;
    trie.add(st);
  }

  lint ans=0;
  rep(i,min(n,1.5e5)){
    string q=s[i].substr(0,s[i].size()-1);
    char c=s[i].back();
    cout<<c<<endl;

    auto f=[&](array<int,26> hist){
      //rep(i,26) cout<<hist[i];
      //cout<<endl;
      //cout<<q<<' '<<c<<endl;
      ans+=hist[c-'a']-1;
    };
    trie.query(q,f);
  }
  return ans;
}

int main(){cout<<app()<<endl;return 0;}


Compiler output:
a.cc: In function 'lint app()':
a.cc:119:12: error: no matching function for call to 'min(int&, double)'
  119 |   rep(i,min(n,1.5e5)){
      |         ~~~^~~~~~~~~
a.cc:3:45: note: in definition of macro 'rep'
    3 | #define rep(i, n) for (int i = 0; i < (int)(n); i++)
      |                                             ^
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:119:12: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'double')
  119 |   rep(i,min(n,1.5e5)){
      |         ~~~^~~~~~~~~
a.cc:3:45: note: in definition of macro 'rep'
    3 | #define rep(i, n) for (int i = 0; i < (int)(n); i++)
      |                                             ^
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:119:12: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  119 |   rep(i,min(n,1.5e5)){
      |         ~~~^~~~~~~~~
a.cc:3:45: note: in definition of macro 'rep'
    3 | #define rep(i, n) for (int i = 0; i < (int)(n); i++)
      |                                             ^