def stirling(n, k, d=None, kind=2, signed=False):
 n = as_int(n)
 k = as_int(k)
 if (n < 0):
  raise ValueError('n must be nonnegative')
 if (k > n):
  return S.Zero
 if d:
  return _stirling2(((n - d) + 1), ((k - d) + 1))
 elif signed:
  return (((-1) ** (n - k)) * _stirling1(n, k))
 if (kind == 1):
  return _stirling1(n, k)
 elif (kind == 2):
  return _stirling2(n, k)
 else:
  raise ValueError(('kind must be 1 or 2, not %s' % k))

def stirling ( n , k , d = None , kind = 2 , signed = False ) : n = as_int ( n ) k = as_int ( k ) if ( n < 0 ) : raise ValueError ( 'n must be nonnegative' ) if ( k > n ) : return S . Zero if d : return _stirling2 ( ( ( n - d ) + 1 ) , ( ( k - d ) + 1 ) ) elif signed : return ( ( ( - 1 ) ** ( n - k ) ) * _stirling1 ( n , k ) ) if ( kind == 1 ) : return _stirling1 ( n , k ) elif ( kind == 2 ) : return _stirling2 ( n , k ) else : raise ValueError ( ( 'kind must be 1 or 2, not %s' % k ) )
return stirling number s of the first or second kind .