<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def maxCtxContextualRule(maxCtx, st, chain):
 """Calculate usMaxContext based on a contextual feature rule."""


    if not chain:
        return max(maxCtx, st.GlyphCount)
    elif chain == 'Reverse':
        return max(maxCtx, st.GlyphCount + st.LookAheadGlyphCount)
    return max(maxCtx, st.InputGlyphCount + st.LookAheadGlyphCount)