package main

import (
	"math"
)

/**
 * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
 *
 *
 * @param s string字符串
 * @return bool布尔型
 */
func isValidString(s string) bool {
	countC := 0
	countLeft := 0
	countRight := 0
	for _, v := range s {
		if string(v) == "(" {
			countLeft++
			continue
		}
		if string(v) == ")" {
			countRight++
			if countLeft+countC < countRight {
				return false
			}
			continue
		}
		if string(v) == "*" {
			countC++
		}
	}

	countC = 0
	countLeft = 0
	countRight = 0
	for i, _ := range s {
        c := string(s[len(s)-1-i])
		if c == "(" {
			countLeft++
			if countRight+countC < countLeft {
				return false
			}
			continue
		}
		if c == ")" {
			countRight++
			continue
		}
		if c == "*" {
			countC++
		}
	}

	return float64(countC) >= math.Abs(float64(countLeft-countRight))
}