<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def critical_value(n, p):
 """ This function calculates the critical value given n and p, and confidence level = 1 - p. """

    dn = 1
    delta = 0.5
    res = ROOT.TMath.KolmogorovProb(dn * sqrt(n))
    while res > 1.0001 * p or res < 0.9999 * p:
        if (res > 1.0001 * p):
            dn = dn + delta
        if (res < 0.9999 * p):
            dn = dn - delta
        delta = delta / 2.
        res = ROOT.TMath.KolmogorovProb(dn * sqrt(n))
    return dn