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;

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

//↓0-originか1-originでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-origin昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-origin昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-origin降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-origin降順
//rep2 -> 第二引数 m から n 回繰り返し ex) m=5 n=3 なら i=5,i=6,i=7 まで
#define rep2(i,m,n) for(int i = ((int)(m)); i < ((int)(n))+((int)(m)); i++)
#define SIZE(x) ((int)((x).size()))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<int,int> PII;
template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

/* 円周率は M_PI を使おうね */
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;

/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    //cout << fixed << setprecision(10);

    string s;
    cin >> s;
        int cnt = 0, cnt2 = 0;
        rep(i, s.size()) {
            if(s[i]=='(') cnt++;
            else if(s[i]==')') cnt = max(cnt-1, 0);
            else if(s[i]=='*') chmax(cnt2, cnt);
        }
        cout << cnt2 << '\n';
    
}

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

int main(){
	string s;
	cin >> s;
	int c=0;
	for(int i=0;i<s.length();i++){
		if(s[i]=='(') c++;
		else if(s[i]==')') c--;
		else{
			cout << c << endl;
			return 0;
		}
	}
  return 0;
}

C++: // Last Change: 12/05/2019 20:05:04.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  string S;
  cin >> S;

  int lb, rb;
  lb = rb = 0;
  ll cnt = 0;
  for (auto &x : S) {
    if (x == '(') {
      ++lb;
    } else if (x == ')') {
      ++rb;
    } else {
      cnt += lb - rb;
    }
  }
  cout << cnt << endl;
}

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

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

C++: #include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
const int mod=998244353;
int main(){
    string s;
    cin>>s;
    ll cnt=0;
    ll ans=0;
    rep(i,s.size()){
        if(s[i]=='(')cnt++;
        else if(s[i]==')')cnt=max(cnt-1,0LL);
        else ans=max(ans,cnt);
    }
    cout<<ans<<endl;
}

C++: #include<bits/stdc++.h>

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)

using namespace std;

long long count(string &s,int ptr,int dir,char c) {
  long long cnt = 0;
  ptr += dir;
  while( 0 <= ptr && ptr < (int)s.size() ) {
    if( s[ptr] == c ) ++cnt;
    else              --cnt;
    ptr += dir;
  }
  return cnt;
}

int main() {
  string s;
  getline(cin,s);
  long long cnt = 0;
  int ptr = -1;
  rep(i,(int)s.size()) if( s[i] == '*' ) { ptr = i; break; }
  cout << max(0LL,min(count(s,ptr,-1,'('),count(s,ptr,+1,')'))) << endl;
  return 0;
}

C++: #include <bits/stdc++.h> 
using namespace std;
typedef long long ll; const ll MM = 1000000000;ll mod = MM + 7;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;

int main() {
    string s; cin >> s;
    int count_a = 0, count_b = 0, j;
    rep(i, s.size()) {
        if(s[i] == '*') {
            j = i+1;
            break;
        }
        if(s[i] == '(') count_a++;
        if(s[i] == ')') count_a--;
    }
    for(int k = j; k<s.size(); k++) {
        if(s[k] == ')') count_b++;
    }
    cout << min(count_a, count_b) << endl;
}

C++: #include "bits//stdc++.h"
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

int main() {
	string S;
	cin >> S;
	int p = 0;
	int ans = 0;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == '(') {
			p++;
		}
		else if (S[i] == ')') {
			p--;
		}
		else {
			ans = p;
		}
	}
	cout << ans << endl;
}