Advertisement
Guest User

Untitled

a guest
Nov 11th, 2015
542
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. import random
  2. import sys
  3. def lb(x):
  4. r = 1
  5. while x&r == 0:
  6. r = r*2
  7. return r
  8. def pos(l, v):
  9. f = lambda x : lb(x-v) if x != v else 2**420
  10. k = sorted(l, key=f)
  11. for i in xrange(len(k)-1):
  12. r, s, t = abs(k[i+1]-k[i]), f(k[i]), f(k[i+1])
  13. if r % (2*s) != s or r > 2*t-s:
  14. return False
  15. return True
  16. l = map(int,raw_input())
  17. l.sort()
  18. for i in xrange(1,len(l)):
  19. if l[i] == l[i-1]:
  20. print 'Invalid'
  21. sys.exit(0)
  22. if pos(l,l[0]) or pos(l,l[-1]):
  23. print 'Valid'
  24. else:
  25. print 'Invalid'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement