# your code goes here
import numpy as np, time
# simply check
def every(arr, val):
for e in arr:
if e != val:
return False
return True
# check with premature
def every_plus(arr, val):
for i in xrange(0, len(arr)/2+1):
if arr[i] != val or arr[-1 - i] != val:
return False
return True
count = 10**5
values = np.empty((count), dtype=np.uint8)
values.fill(0)
print values
## tests with filled by nulls
start_time = time.time()
print every(values, 0)
print time.time() - start_time, "seconds of non optimased check"
start_time = time.time()
print every_plus(values, 0)
print time.time() - start_time, "seconds of optimased check"
print len(filter(lambda x: x != 0, values)) == 0
print time.time() - start_time, "seconds of filter-based check"
values[count-1] = 1
print values
## tests with one in the end
start_time = time.time()
print every(values, 0)
print time.time() - start_time, "seconds of non optimased check"
start_time = time.time()
print every_plus(values, 0)
print time.time() - start_time, "seconds of optimased check"
print len(filter(lambda x: x == 0, values)) == 0
print time.time() - start_time, "seconds of filter-based check"
values[count-1] = 0
values[count/2] = 1
print values
## tests with one in the middle
start_time = time.time()
print every(values, 0)
print time.time() - start_time, "seconds of non optimased check"
start_time = time.time()
print every_plus(values, 0)
print time.time() - start_time, "seconds of optimased check"
print len(filter(lambda x: x == 0, values)) == 0
print time.time() - start_time, "seconds of filter-based check"
IyB5b3VyIGNvZGUgZ29lcyBoZXJlCgppbXBvcnQgbnVtcHkgYXMgbnAsIHRpbWUKCiMgc2ltcGx5IGNoZWNrCmRlZiBldmVyeShhcnIsIHZhbCk6Cglmb3IgZSBpbiBhcnI6CgkJaWYgZSAhPSB2YWw6CgkJCXJldHVybiBGYWxzZQoJcmV0dXJuIFRydWUKCiMgY2hlY2sgd2l0aCBwcmVtYXR1cmUKZGVmIGV2ZXJ5X3BsdXMoYXJyLCB2YWwpOgoJZm9yIGkgaW4geHJhbmdlKDAsIGxlbihhcnIpLzIrMSk6CgkJaWYgYXJyW2ldICE9IHZhbCBvciBhcnJbLTEgLSBpXSAhPSB2YWw6CgkJCXJldHVybiBGYWxzZQoJcmV0dXJuIFRydWUKCmNvdW50ID0gMTAqKjUKCnZhbHVlcyA9IG5w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