Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := NewIo()
	defer io.Flush()
	S := io.NextLine()
	cnt := 0
	for _, s := range S {
		if s == '(' {
			cnt++
		} else if s == ')' {
			cnt--
		} else {
			io.Println(cnt)
			break
		}
	}
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    string S; cin >> S;
    
    int star = (int)S.find('*');
    int l = 0, r = 0;
    for(int i = 0; i < star;i++){
        if(S[i] == '(') l+=1;
        else l = max(0,l-1);
    }
    for(int i = (int)S.length()-1; i > star;i--){
        if(S[i] == ')') r+=1;
        else r = max(0,r-1);
    }
    res = min(l,r);
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    
    return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main() {
	string s; cin >> s;
	int ans = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '*') {
			cout << ans << endl; return 0;
		}
		if (s[i] == '(')ans++;
		else if (s[i] == ')')ans--;
	}
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;

void solve() {
	string s; cin >> s;
	int n = s.length();
	int loc;
	rep(i, n) {
		if (s[i] == '*')loc = i;
	}
	int ans = 0;
	rep(i, loc) {
		Rep(j, loc + 1, n) {
			if (s[i] != '(' || s[j] != ')')continue;
			int c = 0;
			for (int k = i + 1; k <= j-1; k++) {
				if (s[k] == '(')c++;
				else if (s[k] == ')')c--;
				if (c < 0)break;
			}
			if (c == 0)ans++;
		}
	}
	cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin>>s;
    std::deque<char> deq;
    for (int i=0;i<s.size();i++) {
        deq.emplace_back(s.at(i));
    }
    auto itr=find(deq.begin(),deq.end(),'*');
    int dis=distance(deq.begin(),itr);
    int left=dis;
    int right=dis;
    int count=0;
    while (left>0) {
        left--;
        if (deq[left]=='(') {
            int flag=0;
            while (right<s.size()) {
                right++;
                if (deq[right]==')'&&flag==0) {
                    count++;
                    break;
                } else if (deq[right]=='(') {
                    flag++;
                } else if (deq[right]==')'&&flag!=0) {
                    flag--;
                }
            }
        }
    }
    cout<<count<<endl;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	string S;
	cin >> S;
	int n = S.size();
	int res = 0;
	for (int i = 0; i < n; i++) {
		if (S[i] == '*') break;
		res += S[i] == '(' ? 1 : -1;
	}
	cout << res << endl;
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

int main()
{
  //queue<char> q;
  bool flag = true;
  int cnt = 0;
  int m = 0;
  string ch;

  cin >> ch;
  for(int i = 0;i < ch.size();i++){

    if(flag && ch[i] == '(') cnt++;
    if(flag && ch[i] == ')') cnt--;
    
    if(ch[i] == '*') flag = false;
    if(!flag && ch[i] == ')'){
      if(m > cnt) continue;
      m++;
    }
  }
  cout << min(cnt, m) << endl;
  return 0;
}