var
	i : longint;
	ans, j : int64;
	c : char;
	p : longint;
	s  :string;

	curpos : longint;

begin
	assign(input, 'brackets.in');
	reset(input);
	assign(output, 'brackets.out');
	rewrite(output);
	p := 0;
	curpos := 0;
	ans:= 0;
	while not eoln do begin
		read(c);
		inc(curpos);
		s := s + c;
//		writeln(erroutput, 'i = ', i, ' ', s);
		if (c = '(') then 
			p := p + 1
		else 
			p := p - 1;

		if (p = 0) then begin
			inc(i);
			continue;
		end;
		i := curpos;
		j := curpos;
		while not eoln do begin
			read(c);
			inc(curpos);
			s := s + c;
			inc(j);
			if (c = '(') then 
				p := p + 1
			else 
				p := p - 1;
			if p = 0 then break;
		end;
//		writeln(erroutput, i, ' ', j, ' ', s);
		ans := ans + (j - i + 1) * (j - i) div 2;
		if eoln then break;
	end;
//	writeln(erroutput, i);
	ans := ans + ((int64(curpos) + 1) * (curpos + 2)) div 2;
	if (curpos > 5000) then exit;
	writeln(ans);
end.