D.cpp

Anonymous
c_cpp
03/01/2026 2:25 AM
544 B
28
Indexable
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

// Time Complexity: O(n)
// Memory Complexity: O(n)

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);

	string s; cin >> s;
	int a = 0, ab = 0, abc = 0;
	for(auto &x : s) {
		if(x == 'A') a++;
		else if(x == 'B') {
			if(a > 0) ab++, a--;
		}
		else if(x == 'C') {
			if(ab > 0) abc++, ab--;
		}
	}
	cout << abc;

	return 0;
}
Editor is loading...
Leave a Comment