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 <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    int idx = -1;
    for(int i = 0; i < s.size(); i++) if(s[i] == '*') idx = i;
    int pos = idx - 1;
    map<char, int> mp;
    while(pos >= 0)
    {
        mp[s[pos]]++;
        pos--;
    }
    int left = abs(mp['('] - mp[')']);
    pos = idx + 1;
    map<char,int > mp2;
    while(pos < s.size())
    {
        mp2[s[pos]]++;
        pos++;
    }
    int right = abs(mp2['('] - mp2[')']);
    cout << right << endl;
    return 0;
}

C++: #include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define pii pair<int, int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,n,0)
#define ALL(c) ((c).begin(),(c).end())
#define PB(a) push_back(a)
#define EMPB(...) emplace_back(__VA_ARGS__)
#define EMP(...) emplace(__VA_ARGS__)
#define MP(a,b) make_pair(a,b)
#define MT(...) make_tuple(__VA_ARGS__)
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define PW(n) (1LL<<(n))
using namespace std;
template <class T> inline bool CHMIN(T& a, T b) { if(a>b) { a=b; return 1; } return 0; }
template <class T> inline bool CHMAX(T& a, T b) { if(a<b) { a=b; return 1; } return 0; }
template <class T> inline void SORT(T& a) { sort(ALL(a)); }
template <class T> inline void REV(T& a) { reverse(ALL(a)); }
template <class T> inline void UNI(T& a) { SORT(a); a.erase(unique(ALL(a)),a.end()); }
template <class S, class T> ostream& operator<<(ostream& os, const pair<S,T> a) {
  return os << a.first << ' ' << a.second;
}
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

string s;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  cin >> s;
  int pos = -1;
  REP(i, s.size()) if (s[i] == '*') {
    pos = i;
  }
  int ans = 0;
  stack<int> st;
  REP(i, s.size()) if (s[i] != '*') {
    if (s[i] == '(') {
      st.push(i);
    } else {
      int l = st.top(); st.pop();
      ans += (l < pos && pos < i);
    }
  }
  cout << ans << endl;

  return 0;
}

C++: // #include <bitset>
// #include <cmath>
// #include <cstring>
// #include <deque>
// #include <functional>
// #include <iostream>
// #include <map>
// #include <numeric>
// #include <queue>
// #include <set>
// #include <stack>
// #include <stdlib.h>
// #include <string>
// #include <utility>
// #include <vector>
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
#define INF 1e9
using namespace std;
template<typename T> void cmin(T &a, T b) { a = min(a, b); }
template<typename T> void cmax(T &a, T b) { a = max(a, b); }

signed main() {
  string s;
  cin >> s;

  int idx, len = (int)s.size();
  rep(i, s.size()) if (s[i] == '*') idx = i;
  int left = idx - 1, right = idx + 1;
  int ans = 0;
  while (0 <= left && right < len) {
    if (s[left] == '(' && s[right] == ')') {
      ans++;
      left--;
      right++;
    }
    if (0 < left && s[left - 1] == '(' && s[left] == ')') left -= 2;
    if (right < len - 1 && s[right] == '(' && s[right + 1] == ')') right += 2;
  }

  cout << ans << endl;
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){
  string s;
  cin>>s;
  int n=s.size();
  int ans=0;
  auto calc=[&](string t){
    int o=0,tmp=0,app=0,f=1;
    for(int i=0;i<(int)t.size();i++){
      if(t[i]=='*'){
	app=1;
	tmp=o;
	continue;
      }
      if(t[i]=='(') o++;
      else o--;
      if(o<0){
	f=0;break;
      }
    }
    if(o||!app||!f) return;
    ans=max(ans,tmp);
  };
  for(int i=0;i<n;i++){
    for(int j=i+1;j<=n;j++){
      string t=s.substr(i,j-i);
      calc(t);
      
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

int f(string s){

    int n = (int)s.size();
    int d = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == '*') continue;

        if(s[i] == '(') d++;
        else d--;
        if(d < 0) return 0;
    }

    return (d == 0);
}

int main(){

    
        string s; cin >> s;
        int n = (int)s.size();
        int star_idx;
        for(int i = 0; i < n; i++){
            if(s[i] == '*'){
                star_idx = i;
                break;
            }
        }

        int ans = 0;
        for(int l = 0; l < star_idx; l++){

            string t = "";
            for(int i = l + 1; i < star_idx; i++) t = t + s[i];

            for(int r = star_idx + 1; r < n; r++){
                t = t += s[r - 1];
                if(s[l] == '(' && s[r] == ')') ans += f(t);
            }
        }

        cout << ans << endl;
    

    return 0;
}