def parse( inFile) :
i = inFile.getInts ( )
return tuple ( i[ 1 :3 ] +[ i[ 3 :] ] )
def solve( ( S, p, scores) ) :
bestunsurprising = 3 * p - 2 if ( p > 0 ) else 0
bestsurprising = 3 * p - 4 if ( p > 2 ) else p
return len ( [ score for score in scores if score >= bestunsurprising] ) + min ( S, len ( [ score for score in scores if bestunsurprising > score and score >= bestsurprising] ) )
if __name__ == "__main__" :
from GCJ import GCJ
GCJ( parse, solve, "/Users/lpebody/gcj/2012_q/" , "b" ) .run ( )
ZGVmIHBhcnNlKGluRmlsZSk6CiAgICBpID0gaW5GaWxlLmdldEludHMoKQogICAgcmV0dXJuIHR1cGxlKGlbMTozXStbaVszOl1dKQoKZGVmIHNvbHZlKChTLHAsc2NvcmVzKSk6CiAgICBiZXN0dW5zdXJwcmlzaW5nID0gMyAqIHAgLSAyIGlmIChwID4gMCkgZWxzZSAwCiAgICBiZXN0c3VycHJpc2luZyA9IDMgKiBwIC0gNCBpZiAocCA+IDIpIGVsc2UgcAogICAgcmV0dXJuIGxlbihbc2NvcmUgZm9yIHNjb3JlIGluIHNjb3JlcyBpZiBzY29yZSA+PSBiZXN0dW5zdXJwcmlzaW5nXSkgKyBtaW4oUyxsZW4oW3Njb3JlIGZvciBzY29yZSBpbiBzY29yZXMgaWYgYmVzdHVuc3VycHJpc2luZyA+IHNjb3JlIGFuZCBzY29yZSA+PSBiZXN0c3VycHJpc2luZ10pKQoKaWYgX19uYW1lX18gPT0gIl9fbWFpbl9fIjoKICAgIGZyb20gR0NKIGltcG9ydCBHQ0oKICAgIEdDSihwYXJzZSwgc29sdmUsICIvVXNlcnMvbHBlYm9keS9nY2ovMjAxMl9xLyIsICJiIikucnVuKCkKCiAgICAgICAgICAgIAo=