Language: C++

#include<bits/stdc++.h>
using namespace std;

const int N = 2e5 + 5;
//const int mod = 1e9 + 7;
typedef long long ll;
#define mp make_pair

char c;
string s;
int n,i,ans;
map < pair < int , int > , int > M;


struct hash{
    ll t,a,b,x,bol,X,mod;
    hash() { t=b=x=X=mod=0; a=bol=1; }
    void f(){ 
        for(t=X,i=mod-2; i ; i>>=1){
            if(i & 1) bol = bol*t % mod;
            t = t*t % mod;
        }
        for(i=n-1; i>=0 ;i--){
            c = s[i];
            if(c == '-') x--;
            if(c == '+') x++;
            if(c == '>') x *= X;
            if(c == '<') x *= bol; 
            x = (x % mod + mod) % mod;
        }
    }
            
    void g(){   
        if(c == '+') b -= a;
        if(c == '-') b += a;    
        if(c == '>') a *= bol;                  
        if(c == '<') a *= X;                                
        a = (a % mod + mod) % mod;                                  
        b = (b % mod + mod) % mod;      
        t = (a*x + b) % mod;                            
    }                                                               
};                                                                              
                                                                                            
int main(){                                                                                             
    cin >> n >> s;                                                                                                  
                                                                                                                            
    struct hash h1,h2;                      
    h1.mod = 1e9+7;  h1.X=10000003; h1.f();
    h2.mod = 1e9+9;  h2.X=1000007; h2.f();
                                    
    M[mp(0,0)] = 1;                         
    for(i=n-1; i>=0 ;i--){                          
        c = s[i];                                           
        h1.g(); h2.g();                                             
                                                                            
        ans += M[mp(h1.t,h2.t)];                                                    
        M[mp(h1.b,h2.b)]++;                                                             
    }

    cout << ans;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:47:12: error: reference to 'hash' is ambiguous
   47 |     struct hash h1,h2;
      |            ^~~~
In file included from /usr/include/c++/14/string_view:50,
                 from /usr/include/c++/14/bits/basic_string.h:47,
                 from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/functional_hash.h:59:12: note: candidates are: 'template<class _Tp> struct std::hash'
   59 |     struct hash;
      |            ^~~~
a.cc:15:8: note:                 'struct hash'
   15 | struct hash{
      |        ^~~~
a.cc:48:8: error: request for member 'mod' in 'h1', which is of non-class type 'int'
   48 |     h1.mod = 1e9+7;  h1.X=10000003; h1.f();
      |        ^~~
a.cc:48:25: error: request for member 'X' in 'h1', which is of non-class type 'int'
   48 |     h1.mod = 1e9+7;  h1.X=10000003; h1.f();
      |                         ^
a.cc:48:40: error: request for member 'f' in 'h1', which is of non-class type 'int'
   48 |     h1.mod = 1e9+7;  h1.X=10000003; h1.f();
      |                                        ^
a.cc:49:8: error: request for member 'mod' in 'h2', which is of non-class type 'int'
   49 |     h2.mod = 1e9+9;  h2.X=1000007; h2.f();
      |        ^~~
a.cc:49:25: error: request for member 'X' in 'h2', which is of non-class type 'int'
   49 |     h2.mod = 1e9+9;  h2.X=1000007; h2.f();
      |                         ^
a.cc:49:39: error: request for member 'f' in 'h2', which is of non-class type 'int'
   49 |     h2.mod = 1e9+9;  h2.X=1000007; h2.f();
      |                                       ^
a.cc:54:12: error: request for member 'g' in 'h1', which is of non-class type 'int'
   54 |         h1.g(); h2.g();
      |            ^
a.cc:54:20: error: request for member 'g' in 'h2', which is of non-class type 'int'
   54 |         h1.g(); h2.g();
      |                    ^
a.cc:56:24: error: request for member 't' in 'h1', which is of non-class type 'int'
   56 |         ans += M[mp(h1.t,h2.t)];
      |                        ^
a.cc:56:29: error: request for member 't' in 'h2', which is of non-class type 'int'
   56 |         ans += M[mp(h1.t,h2.t)];
      |                             ^
a.cc:57:17: error: request for member 'b' in 'h1', which is of non-class type 'int'
   57 |         M[mp(h1.b,h2.b)]++;
      |                 ^
a.cc:57:22: error: request for member 'b' in 'h2', which is of non-class type 'int'
   57 |         M[mp(h1.b,h2.b)]++;
      |                      ^