|
| 1 | +#include <algorithm> |
| 2 | +#include <bitset> |
| 3 | +#include <cassert> |
| 4 | +#include <chrono> |
| 5 | +#include <cmath> |
| 6 | +#include <complex> |
| 7 | +#include <cstdio> |
| 8 | +#include <cstring> |
| 9 | +#include <ctime> |
| 10 | +#include <functional> |
| 11 | +#include <iomanip> |
| 12 | +#include <iostream> |
| 13 | +#include <iterator> |
| 14 | +#include <limits> |
| 15 | +#include <map> |
| 16 | +#include <numeric> |
| 17 | +#include <queue> |
| 18 | +#include <random> |
| 19 | +#include <set> |
| 20 | +#include <stack> |
| 21 | +#include <string> |
| 22 | +#include <tuple> |
| 23 | +#include <utility> |
| 24 | +#include <vector> |
| 25 | + |
| 26 | +#define int long long |
| 27 | +#define double long double |
| 28 | +#define ff first |
| 29 | +#define ss second |
| 30 | +#define endl '\n' |
| 31 | +#define ii pair<int, int> |
| 32 | +#define mp make_pair |
| 33 | +#define mt make_tuple |
| 34 | +#define DESYNC \ |
| 35 | + ios_base::sync_with_stdio(false); \ |
| 36 | + cin.tie(0); \ |
| 37 | + cout.tie(0) |
| 38 | +#define pb push_back |
| 39 | +#define vi vector<int> |
| 40 | +#define vii vector<ii> |
| 41 | +#define all(x) x.begin(), x.end() |
| 42 | +#define EPS 1e-9 |
| 43 | +#define INF 1e18 |
| 44 | +#define ROOT 1 |
| 45 | +#define curtime chrono::steady_clock::now().time_since_epoch().count |
| 46 | +#define rep(i, beg, n, s) for (int i = beg; i < n; i += s) |
| 47 | +using ll = long long; |
| 48 | +using namespace std; |
| 49 | +const double PI = acos(-1); |
| 50 | +const int M = 1000000007; |
| 51 | +// const int M = 998244353; |
| 52 | +mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); |
| 53 | +inline int mod(int n, int m = M) { |
| 54 | + int ret = n % m; |
| 55 | + if (ret < 0) ret += m; |
| 56 | + return ret; |
| 57 | +} |
| 58 | + |
| 59 | +int exp(int n, int k, int m = M) { |
| 60 | + if (k == 0) return 1; |
| 61 | + if (k == 1) return n; |
| 62 | + int ax = exp(n, k / 2, m); |
| 63 | + ax = mod(ax * ax, m); |
| 64 | + if (k % 2) ax = mod(ax * n, m); |
| 65 | + return ax; |
| 66 | +} |
| 67 | + |
| 68 | +int gcd(int a, int b) { |
| 69 | + if (a == 0) |
| 70 | + return b; |
| 71 | + else |
| 72 | + return gcd(b % a, a); |
| 73 | +} |
| 74 | + |
| 75 | +/* LIBRARY INCLUDES */ |
| 76 | + |
| 77 | +/* END OF LIBRARY INCLUDES */ |
| 78 | + |
| 79 | +/* TEMPLATE DEFINES */ |
| 80 | +// #define FILE_INPUT |
| 81 | +// #define PRINT_TEST_CASE |
| 82 | +#define MULTIPLE_TEST_CASE |
| 83 | + |
| 84 | +/* SOLUTION CODE */ |
| 85 | + |
| 86 | +void solution(int testcase) { |
| 87 | +#ifdef PRINT_TEST_CASE |
| 88 | + cout << "Case #" << testcase << ": "; |
| 89 | +#endif |
| 90 | + // Code starts here |
| 91 | + int n; |
| 92 | + cin >> n; |
| 93 | + string s; |
| 94 | + cin >> s; |
| 95 | + vi p(n + 1, 0); |
| 96 | + for (int i = 0; i < n; i++) { |
| 97 | + p[i + 1] = p[i] + (s[i] == '+' ? 1 : -1); |
| 98 | + } |
| 99 | + |
| 100 | + int ans = 0; |
| 101 | + for (int i = 0; i <= n; i++) { |
| 102 | + for (int j = i + 1; j <= n; j++) { |
| 103 | + if ((p[j] - p[i]) % 3 == 0 && p[j] <= p[i]) ans++; |
| 104 | + } |
| 105 | + } |
| 106 | + |
| 107 | + cout << ans << endl; |
| 108 | +} |
| 109 | + |
| 110 | +#ifdef FILE_INPUT |
| 111 | +freopen("equal.in", "r", stdin); |
| 112 | +freopen("equal.out", "w", stdout); |
| 113 | +#endif |
| 114 | + |
| 115 | +int32_t main() { |
| 116 | + DESYNC; |
| 117 | + int t = 1; |
| 118 | +#ifdef MULTIPLE_TEST_CASE |
| 119 | + cin >> t; |
| 120 | +#endif |
| 121 | + for (int _testcase = 1; _testcase <= t; _testcase++) solution(_testcase); |
| 122 | +} |
0 commit comments