import java.util.*;
import java.io.*;

public class theblackpearl_dk {
	BufferedReader br;
	PrintWriter out;
	StringTokenizer stok;

	String nextToken() throws IOException {
		while (stok == null || !stok.hasMoreTokens()) {
			String s = br.readLine();
			if (s == null) {
				return null;
			}
			stok = new StringTokenizer(s);
		}
		return stok.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	char nextChar() throws IOException {
		return (char) (br.read());
	}

	String nextLine() throws IOException {
		return br.readLine();
	}
	
	void solve() throws IOException {
		String s = nextLine();
		int l = 0;
		int r = 0;
		char let;int kol = 0;
		long len, ans = 0;
		while (r < s.length() && s.charAt(r) == '?') r++;
		if (r == s.length()) {
			len = (r - l);
			ans += len * (len + 1) / 2;
			out.println(ans);
			return;
		}
		let = s.charAt(r);
		while (r < s.length() && (s.charAt(r) == '?' || s.charAt(r) == let)) {
			
			if (s.charAt(r) == let) kol++;
			r++;
		}
		r--;
		int prevl = -1, prevr = -1;
		while (true) {
			len = (r - l + 1);
			ans += len * (len + 1) / 2;
			if (prevl != -1 && prevr >= l) {
				len = (prevr - l + 1);
				ans -= len * (len + 1) / 2;
			}
			prevl = l;
			prevr = r;
			while (kol > 0) {
				if (s.charAt(l) == let) kol--;
				l++;
			} 
			r++;
			while (r < s.length() && s.charAt(r) == '?') r++;
			if (r == s.length()) {
				r--;
				len = (r - l + 1);
				ans += len * (len + 1) / 2;
				if (prevr >= l) {
					len = (prevr - l + 1);
					ans -= len * (len + 1) / 2;
				}
				out.println(ans);
				return;
			}
			let = s.charAt(r);
			while (r < s.length() && (s.charAt(r) == '?' || s.charAt(r) == let)) {
				if (s.charAt(r) == let) kol++;
				r++;
			}
			r--;
		}
	}

	void run() throws IOException {
		 br = new BufferedReader(new FileReader("theblackpearl.in"));
		 out = new PrintWriter("theblackpearl.out");
		// br = new BufferedReader(new InputStreamReader(System.in));
		// out = new PrintWriter(System.out);
		solve();
		br.close();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		// Localea.setDefault(Locale.US);
		new theblackpearl_dk().run();
	}
}