Language: C++

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

#define MAX 500012

int n;
char buf[MAX];


string s;


//#define MOD1 1000000007
//#define MOD2 1000000009

valarray<long long int> MOD1;
valarray<long long int> MOD2;
vector<valarray<long long int> > p2;
vector<valarray<long long int> > vv;
vector<int> ps;
map<long long int, int> mp;
long long int ppow(long long int i, long long int j, long long int MOD) {
	long long int ret = 1;
	while (j) {
		if (j & 1LL)ret *= i;
		if (ret >= MOD)ret %= MOD;
		j >>= 1LL;
	}
	return ret;
}

valarray<long long int> calc(int dif) {
	valarray<long long int> ret;
	ret.resize(2, 0);
	for (int j = 0; j < 2; j++) {
		if (dif < 0) {
			ret[j]=ppow(ppow(MOD1[j], abs(dif),MOD2[j]), MOD2[j] - 2,MOD2[j]);
		}
		else {
			ret[j] = ppow(MOD1[j], abs(dif), MOD2[j]);
		}
	}
	return ret;
}

int main() {
	MOD1.resize(2);
	MOD2.resize(2);
	p2.push_back(valarray<long long int>());
	p2.back().resize(2);
	p2.back()[0] = p2.back()[1] = 1;
	MOD1[0] = 1000000007;
	MOD2[0] = 1000000009;
	MOD1[1] = 1000000009;
	MOD2[1] = 1000000007;
	p2[0] %= MOD2;
	for (int i = 1; i < MAX; i++) {
		p2.push_back(p2.back());
		p2[i] *= MOD1;
		p2[i] %= MOD2;
	}
	cin >> n;
	scanf("%s", buf);
	s = buf;
	int pos = MAX/2;
	valarray<long long int> hs;
	hs.resize(2);
	hs[0] = hs[1] = 0;
	vv.push_back(hs);
	ps.push_back(pos);
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '<') {
			pos--;
		}
		if (s[i] == '>') {
			pos++;
		}
		if (s[i] == '+') {
			hs += p2[pos];
		}
		if (s[i] == '-') {
			hs -= p2[pos];
			hs += MOD2;
		}
		hs %= MOD2;
		vv.push_back(hs);
		ps.push_back(pos);
	}
	long long int way = 0;
	for (int i = vv.size() - 1; i >= 0; i--) {
		auto want = vv[i] + vv.back()*calc(-MAX/2+ps[i]);
		want = want%MOD2;
		way += mp[want[0] * MOD1[0] + want[1]];
		//cerr << "dbg " << way << endl;
		mp[vv[i][0]*MOD1[0]+vv[i][1]]++;
	}
	printf("%lld\n", way);
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:92:29: error: no match for 'operator=' (operand types are 'std::_Expr<std::__detail::_BinClos<std::__plus, std::_ValArray, std::_Expr, long long int, std::__detail::_BinClos<std::__multiplies, std::_ValArray, std::_ValArray, long long int, long long int> >, long long int>' and 'std::_Expr<std::__detail::_BinClos<std::__modulus, std::_Expr, std::_ValArray, std::__detail::_BinClos<std::__plus, std::_ValArray, std::_Expr, long long int, std::__detail::_BinClos<std::__multiplies, std::_ValArray, std::_ValArray, long long int, long long int> >, long long int>, long long int>')
   92 |                 want = want%MOD2;
      |                             ^~~~
In file included from /usr/include/c++/14/valarray:605,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:166,
                 from a.cc:1:
/usr/include/c++/14/bits/valarray_after.h:164:11: note: candidate: 'std::_Expr<std::__detail::_BinClos<std::__plus, std::_ValArray, std::_Expr, long long int, std::__detail::_BinClos<std::__multiplies, std::_ValArray, std::_ValArray, long long int, long long int> >, long long int>& std::_Expr<std::__detail::_BinClos<std::__plus, std::_ValArray, std::_Expr, long long int, std::__detail::_BinClos<std::__multiplies, std::_ValArray, std::_ValArray, long long int, long long int> >, long long int>::operator=(const std::_Expr<std::__detail::_BinClos<std::__plus, std::_ValArray, std::_Expr, long long int, std::__detail::_BinClos<std::__multiplies, std::_ValArray, std::_ValArray, long long int, long long int> >, long long int>&)' (deleted)
  164 |     class _Expr
      |           ^~~~~
/usr/include/c++/14/bits/valarray_after.h:164:11: note:   no known conversion for argument 1 from 'std::_Expr<std::__detail::_BinClos<std::__modulus, std::_Expr, std::_ValArray, std::__detail::_BinClos<std::__plus, std::_ValArray, std::_Expr, long long int, std::__detail::_BinClos<std::__multiplies, std::_ValArray, std::_ValArray, long long int, long long int> >, long long int>, long long int>' to 'const std::_Expr<std::__detail::_BinClos<std::__plus, std::_ValArray, std::_Expr, long long int, std::__detail::_BinClos<std::__multiplies, std::_ValArray, std::_ValArray, long long int, long long int> >, long long int>&'
/usr/include/c++/14/bits/valarray_after.h:164:11: note: candidate: 'std::_Expr<std::__detail::_BinClos<std::__plus, std::_ValArray, std::_Expr, long long int, std::__detail::_BinClos<std::__multiplies, std::_ValArray, std::_ValArray, long long int, long long int> >, long long int>& std::_Expr<std::__detail::_BinClos<std::__plus, std::_ValArray, std::_Expr, long long int, std::__detail::_BinClos<std::__multiplies, std::_ValArray, std::_ValArray, long long int, long long int> >, long long int>::operator=(std::_Expr<std::__detail::_BinClos<std::__plus, std::_ValArray, std::_Expr, long long int, std::__detail::_BinClos<std::__multiplies, std::_ValArray, std::_ValArray, long long int, long long int> >, long long int>&&)' (deleted)
/usr/include/c++/14/bits/valarray_after.h:164:11: note:   no known conversion for argument 1 from 'std::_Expr<std::__detail::_BinClos<std::__modulus, std::_Expr, std::_ValArray, std::__detail::_BinClos<std::__plus, std::_ValArray, std::_Expr, long long int, std::__detail::_BinClos<std::__multiplies, std::_ValArray, std::_ValArray, long long int, long long int> >, long long int>, long long int>' to 'std::_Expr<std::__detail::_BinClos<std::__plus, std::_ValArray, std::_Expr, long long int, std::__detail::_BinClos<std::__multiplies, std::_ValArray, std::_ValArray, long long int, long long int> >, long long int>&&'