A valid postal code $\mbox{P}$ have to fullfil both below requirements: 

$\mbox{P}$ must be a number in the range from 100000 to 9999 inclusive.  
$\mbox{P}$ must not contain more than one alternating repetitive digit pair.

Alternating repetitive digits are digits which repeat immediately after the next digit. In other words, an alternating repetitive digit pair is formed by two equal digits that have just a single digit between them. 

For example:

121426 # Here, 1 is an alternating repetitive digit.
523563 # Here, NO digit is an alternating repetitive digit.
552523 # Here, both 2 and 5 are alternating repetitive digits.

Your task is to provide two regular expressions regex_integer_in_range and regex_alternating_repetitive_digit_pair. Where:

regex_integer_in_range should match only integers range from 100000 to 9999 inclusive

regex_alternating_repetitive_digit_pair should find alternating repetitive digits pairs in a given string.

Both these regular expressions will be used by the provided code template to check if the input string $\mbox{P}$ is a valid postal code using the following expression:

(bool(re.match(regex_integer_in_range, P)) 
and len(re.findall(regex_alternating_repetitive_digit_pair, P)) < 2)

Input Format

Locked stub code in the editor reads a single string denoting $\mbox{P}$ from stdin and uses provided expression and your regular expressions to validate if $\mbox{P}$ is a valid postal code.

Output Format

You are not responsible for printing anything to stdout. Locked stub code in the editor does that.

Sample Input 0
110000

Sample Output 0
False

Explanation 0

1 1 0000 : (0, 0) and (0, 0) are two alternating digit pairs. Hence, it is an invalid postal code.

Note: 

A score of $\mbox{0}$ will be awarded for using 'if' conditions in your code. 

You have to pass all the testcases to get a positive score.

Difficulty: MEDIUM_HARD

Starter code:

Solutions:
import re
s = input()
try:
	condition1 = bool(int(s) in range(100000, 1000000))
except ValueError:
	condition1 = False
lista = []
for i in range(4):
	lista.extend(re.findall('([0-9])[0-9]\\1', s[i:i + 3]))
print(bool(condition1 and len(lista) < 2))


import re
s = input()
m = re.match('^[1-9]\\d{5}$', s)
itr = re.finditer('(?=((\\d)\\d\\2))', s)
print(bool(m) and len([1 for m in itr]) <= 1)


import re
p = input().lstrip('0')
is_num = p.isnumeric()
tmp = p
l = re.search('(\\d)[^\\1]\\1', tmp)
n = 0
while is_num and len(p) == 6 and (l != None) and (tmp != '') and (n < 2):
	n += 1
	i = l.start()
	tmp = tmp[i + 1:]
	l = re.search('(\\d)[^\\1]\\1', tmp)
res = ['False', 'True']
print(res[is_num and len(p) == 6 and (n < 2)])


import re
s = input()
check = re.findall('(?=(\\d)\\d\\1)', s)
if len(check) < 2 and len(s) == 6 and re.match('[0-9]', s):
	print('True')
else:
	print('False')


import re
postcode = input()
aantal = re.findall('(?=(\\d)\\d\\1)', postcode)
valid = re.match('^[1-9]\\d{5}$', postcode)
print((len(aantal) < 2 and valid) and 'True' or 'False')


import re
postal = input()
print(bool(not len(re.findall('(\\d)(?=\\d\\1)', postal)) > 1 and re.match('[1-9]\\d{5}$', postal)))


import re
s = input().strip()
print(bool(re.fullmatch('[1-9]\\d{5}', s)) and (not bool(re.search('((\\d)(?=.\\2).*){2}', s))))


import re
txt = input().strip()
t2 = txt[:-2]
t1 = txt[2:]
z = filter(lambda l: l[0] == l[1], zip(t1, t2))
cnt = len(list(z))
ret = cnt <= 1
ret2 = re.match('^\\d{6}$', txt) != None
print(ret and ret2)


import re
postal_code = input()
print(re.match('^\\d+$', postal_code) != None and 100000 <= int(postal_code) <= 999999 and (len(list(filter(None, map(lambda x: x[0] == x[1], list(zip(postal_code, postal_code[2:])))))) <= 1))


import re

def validZipcode(s):
	return s.isdigit() and len(s) == 6 and (s[0] != '0') and (alternative(s) <= 1)

def alternative(s):
	c = 0
	for i in range(4):
		c += s[i] == s[i + 2]
	return c
s = input()
print(validZipcode(s))


postalcode = input()
d = postalcode.isdigit()
l = len(postalcode) == 6
results = []
for i in range(2, len(postalcode)):
	results.append(postalcode[i - 2] == postalcode[i])
x = results.count(True)
y = x == 0 or x == 1
print(d and l and y)


def in_range(p):
	return p.isdigit() and 100000 <= int(p) <= 999999

def is_alt_rep(p):
	l = []
	for i in range(len(p) - 2):
		l.append(p[i] == p[i + 2])
	return l.count(True)

def is_valid(p):
	return in_range(p) and is_alt_rep(p) <= 1

def main():
	p = input()
	print(is_valid(p))
main()


r = input()
try:
	k = int(r) > 100000 and int(r) < 999999
except ValueError:
	k = False
try:
	tests = sorted([r[0] != r[2], r[1] != r[3], r[2] != r[4], r[3] != r[5]])
except IndexError:
	k = False
	tests = [False, False]
print(tests[1] and k)


import re
postalcode = input()
validrange = re.search('^[1-9]\\d{5}$', postalcode)
alternatingdigits = re.search('(\\d)(\\d)\\1\\2', postalcode)
print(validrange != None and alternatingdigits == None)


def check(s, c):
	for i in range(len(s) - 2):
		a = [True, False][s[i] == s[i + 2]]
		c = [c, c + 1][a == False]
	return [True, False][c > 1]
n = input()
flag = [False, True][len(n) == 6 and n.isdigit() == True]
print([check(n, 0), 'False'][flag == False])


import re
pin = re.search('^[1-9][0-9]{5}$', input())
try:
	check = [pin.group()[i] == pin.group()[i + 2] for i in range(4)]
	print(bool(pin) and check.count(True) <= 1)
except:
	print(False)


l = input()
lg = list(l)
d = 1
for i in range(0, len(lg)):
	d *= (0, 1)[lg[i] >= '0' and lg[i] <= '9']
n = (0, l)[d == 1]
n = int(n)
lg.append('1')
lg.append('1')
lg.append('1')
lg.append('1')
lg.append('1')
lg.append('1')
a = (0, 1)[n >= 100000]
b = (0, 1)[n <= 999999]
p = [1] * 10
p[0] = (0, 1)[lg[0] == lg[2]]
p[1] = (0, 1)[lg[2] == lg[4]]
p[2] = (0, 1)[lg[1] == lg[3]]
p[3] = (0, 1)[lg[3] == lg[5]]
c = (0, 1)[p[0] + p[1] + p[2] + p[3] <= 1]
x = ('False', 'True')[a * b * c * d == 1]
print(x)


import re
s = input()
print(bool(re.match('^[1-9]\\d{5}$', s) and (not re.search('((.)(?=.\\2)){2,}', s))))


import re
s = input()
print(bool(re.match('^[1-9]\\d{5}$', s) and len(re.findall('(.)(?=.\\1)', s)) <= 1))


import sys
try:
	zip = sys.stdin.readline()
	zi = int(zip)
except ValueError:
	print(False)
else:
	pairLocations = [(x, x + 2) for x in range(len(zip) - 2)]
	print(int(zip) > 100000 and int(zip) < 999999 and (sum([zip[f] == zip[s] for (f, s) in pairLocations]) == 1 or sum([zip[f] == zip[s] for (f, s) in pairLocations]) == 0))


QQ = input()
valid = True
length = len(QQ)
valid = valid and length == 6
valid = valid and QQ[0] in '123456789'
s = QQ.split()[0]
i = 2
j = 0
count = []
while i < len(s):
	count.append(s[j] == s[i])
	i += 1
	j += 1
valid = valid and count.count(True) <= 1
print(valid)


def test(s):
	l = []
	for i in range(len(s) - 2):
		l.append(s[i] is s[i + 2])
	return [False, True][s.isnumeric() and len(s) is 6 and (s[0] is not '0') and (l.count(True) <= 1)]
print(test(input()))


import re
try:
	P = input().strip()
	ard_reg = re.compile('(\\d)(?=\\d\\1)')
	pairs = set()
	for m in ard_reg.finditer(P):
		pairs.add(m.start())
		pairs.add(m.start() + 2)
	ARD = int(len(pairs) / 2)
	print(int(P) > 100000 and int(P) < 999999 and (ARD <= 1))
except ValueError:
	print('False')


import re

def checkpostalcode(p):
	while p.isdigit() and int(p) >= 100000 and (int(p) <= 999999) and (not bool(re.match('.*(.)(.)\\1\\2', p))):
		print('True')
		return
	print('False')
x = input().strip()
checkpostalcode(x)


import re
p = input().strip()
range_check = bool(re.match('^[1-9][0-9]{5}$', p))
repeat_check = len(re.findall('(?=([0-9])[0-9]\\1)', p))
print(range_check == True and repeat_check < 2)


import re
P = input()
print(bool(re.match('^\\d{6}$', P)) and len(re.findall('(\\d)(?=\\d\\1)', P)) <= 1)


import re
s = input()
print(bool(re.match('[1-9][0-9]{5}$', s)) and len(re.findall('([0-9])(?=.\\1)', s)) < 2)


import re
p = input()
re_a = re.compile('^[1-9][0-9]{5}$')
re_b = re.compile('(?=(\\d)\\d\\1)')
print(bool(re_a.match(p)) and len(re_b.findall(p)) < 2)


s = input()
n = len(s)
nb = 0
ok = True
for i in range(n):
	ok = ok and s[i].isdigit()
for i in range(n - 2):
	nb += s[i] == s[i + 2]
print(ok and n == 6 and (s[0] != '0') and (nb < 2))


num = input()
l = list(filter(lambda x: x[0] == x[1], list(zip(num[::2], num[2::2]))))
l += list(filter(lambda x: x[0] == x[1], list(zip(num[1::2], num[3::2]))))
print(not bool((len(l) or 1) - 1) and num.isdigit() and (int(num) >= 100000) and (int(num) <= 999999))


ty = input()
check = ord(ty[0]) > 48 and ord(ty[0]) < 58 and (ord(ty[1]) >= 48) and (ord(ty[1]) < 58) and (ord(ty[2]) >= 48) and (ord(ty[2]) < 58) and (ord(ty[3]) >= 48) and (ord(ty[3]) < 58) and (ord(ty[4]) >= 48) and (ord(ty[4]) < 58) and (ord(ty[5]) >= 48) and (ord(ty[5]) < 58)
time = False
while check == True:
	tyu = int(ty)
	t = tyu % 1000000
	a = int(t / 10000)
	b = int(t / 100 % 100)
	c = int(t % 100)
	d = 0
	e = 0
	d = abs(a - b)
	e = abs(c - b)
	f = int(d % 10)
	g = int(d / 10)
	h = int(e % 10)
	i = int(e / 10)
	j = f * g
	k = g * h
	l = h * i
	m = i * f
	n = j * k
	o = k * l
	p = l * m
	q = j * m
	time = (not not o or not not n or (not not p) or (not not q)) and (tyu >= 100000 and tyu <= 999999) and (len(ty) == 6)
	break
print(time == True)


import re
pattern = re.compile('.*(\\d).\\1.*')
p = input()
print(p.isdigit() and int(p) > 100000 and (int(p) < 999999) and (len(re.findall('(?=(\\d).\\1)', p)) < 2))


import re
p = input()
r0 = re.findall('\\d', p)
r1 = re.findall('(\\d)\\d(\\d)', p)
r2 = re.findall('\\d(\\d)\\d(\\d)', p)
r3 = re.findall('\\d\\d(\\d)\\d(\\d)', p)
rs = r1 + r2 + r3
st = list(set(rs))
l0 = len(r0)
l1 = len(rs)
l2 = len(st)
print(6 == l0 and 4 == l1 and (l1 == l2 or l1 == l2 + 1))


import re
n = input().strip()
print(bool(re.match('^[1-9][0-9]{5}$', n) and len(re.findall('([0-9])(?=[0-9]\\1)', n)) < 2))


import re
code = re.compile('^[1-9]\\d{5}$')
rep = re.compile('^(\\d)\\d\\1$')
C = input().strip()
vC = bool(code.match(C))
vCs = list(map(bool, map(rep.match, [C[i:i + 3] for i in range(4)])))
print(vC and vCs.count(True) < 2)


import re
p = input()
matches = re.finditer('(?=((\\d)\\d\\2))', p)
print(len(p) == 6 and p.isdigit() and (p[0] != 0) and (len(list((match.group(0) for match in matches))) < 2))


import random
sd = random.randint(0, 1)
sd == 0 and print(True)
sd == 1 and print(False)


import sys, re
p = input()
print(re.match('^[1-9][0-9]{5}$', p) != None and [ord(p[i]) - ord(p[i + 2]) for i in range(4)].count(0) <= 1)


import re
P = input()
print(bool(re.match('^[1-9]\\d{5}$', P)) and len(re.findall('(\\d)(?=\\d\\1)', P)) <= 1)


s = input()

def alternating(i):
	return s[i] != s[i + 2]
nonalt = list(filter(alternating, range(len(s) - 2)))

def isDigit(i):
	return s[i] in '0123456789' and (i in nonalt or i > len(s) - 3)
valid = list(filter(isDigit, range(len(s))))
print(len(valid) >= len(s) - 1 and len(s) == 6)


a = input()
print(not (not a.isdigit() or int(a) < 100000 or int(a) > 999999 or (a[0] == a[2] and (a[1] == a[3] or a[2] == a[4] or a[3] == a[5])) or (a[1] == a[3] and (a[2] == a[4] or a[3] == a[5])) or (a[2] == a[4] and a[3] == a[5])))


__author__ = 'namii'
i = input()
valid_numbers = sum((i[0] == i[2], i[1] == i[3], i[2] == i[4], i[3] == i[5])) <= 1
try:
	in_range = 100000 <= int(i) <= 999999
except:
	in_range = False
print(valid_numbers and in_range)


def isValid(x):
	while len(x) != 6:
		return False
	while not all(('0' <= x[i] <= '9' for i in range(len(x)))):
		return False
	count = 0
	i = 0
	while i < 4:
		while x[i] == x[i + 2]:
			count += 1
			while count > 1:
				return False
			i += 1
			while i > 3:
				return True
		i += 1
	return count < 2
x = input()
print(isValid(x))


import re
regex_for_valid_post_code_ignoring_alternating_repeated_characters = re.compile('^[1-9]\\d{5}$')
regex_for_alternating_repeated_characters = re.compile('(?=(.).\\1)')
post_code = input()
print(bool(regex_for_valid_post_code_ignoring_alternating_repeated_characters.match(post_code)) and len(regex_for_alternating_repeated_characters.findall(post_code)) < 2)


def validar(p):
	res = []
	res.append(len(p) == 6)
	for i in range(len(p) - 2):
		res.append(not p[i] == p[i + 2])
	return res.count(False) <= 1 and p[0] != '0' and p.isdigit()
p = input()
print(validar(p))


import re

def main():
	line = str(input())
	while line[0] == '0' or len(line) > 6:
		print('False')
		return
	while len(re.findall('[^\\d]', line)) != 0:
		print('False')
		return
	matches = re.findall('(?=((\\d)\\d\\2))', line)
	count = 0
	for match in matches:
		while match[0] != '':
			count += 1
			break
	while count < 2:
		print('True')
		return
	print('False')
main()


import re
s = input()
print(len(list(re.findall('(?<=(?P<repeated>\\d))\\d(?=(?P=repeated))', s))) <= 1 and re.match('^[1-9]\\d{5}$', s) != None)


def isNumber(s):
	try:
		float(s)
		return True
	except ValueError:
		return False
num = input()
pairs = 0
for i in range(len(num) - 2):
	pairs += (0, 1)[num[i] == num[i + 2]]
print(('False', 'True')[(pairs < 2 and len(list(num)) == 6) and num.isdigit()])


import sys
stdin = sys.stdin
import re
line = stdin.readline().strip()
print(re.match('^[1-9][0-9]{5}$', line) != None and [ord(line[i]) - ord(line[i + 2]) for i in range(4)].count(0) <= 1)


s = input()
print(s.isdigit() and len(s) == 6 and (int(s) >= 100000) and (int(s) <= 999999) and ([s[i] == s[i + 2] for i in range(4)].count(True) <= 1))


import re
n = input()
alt = False
repeated = 0
for i in range(len(n) - 2):
	alt = alt and n[i] != n[i + 2]
for i in range(1, len(n) - 2):
	alt = alt and n[i] != n[i + 2]
for i in range(len(n) - 2):
	repeated += int(n[i] == n[i + 2])
for i in range(1, len(n) - 2):
	repeated += int(n[i] == n[i + 2])
print(n.isdigit() and repeated < 2 and (int(n) > 100000) and (int(n) < 999999))


ps = input()
try:
	p = int(ps)
	p1 = p >= 100000
	p2 = p <= 999999
	pp02 = ps[0] == ps[2]
	pp13 = ps[1] == ps[3]
	pp24 = ps[2] == ps[4]
	pp35 = ps[3] == ps[5]
	pp = len(list(filter(lambda x: x == True, [pp02, pp13, pp24, pp35]))) < 2
	print(p1 and p2 and pp)
except:
	print(False)


P = input()
dg = lambda y: int(P) % 10 ** y // 10 ** (y - 1)
valid = P.isdigit() and (100000 <= int(P) <= 999999 and sum([int(not dg(i) ^ dg(i + 2)) for i in range(1, 5)]) < 2)
print(valid)


P = input()
digit = P.isdigit() and True or False
interval = digit and len(P) == 6 and (int(P[0]) > 0) and True or False
condition = True
kol = 0
for i in range(len(P) - 2):
	kol = digit and interval and (int(P[i]) != int(P[i + 2])) and kol or kol + 1
	condition = kol < 2 and digit and interval and (int(P[i]) != int(P[i + 2])) and True or False
answer = digit and condition and interval and True or False
print(answer)


P = input()
valid = len(P) == 6
try:
	int(P)
except:
	valid = False
noRepeats = 0
for i in range(len(P) - 2):
	noRepeats += P[i] == P[i + 2]
valid = valid and noRepeats <= 1
print(valid)


from collections import Counter
P = input()
P_digits = Counter()
is_int = True
for start_index in range(len(P) - 2):
	try:
		P_digits[int(P[start_index]) - int(P[start_index + 2])] += 1
	except ValueError:
		is_int = False
		break
print(P_digits[0] < 2 and sum((x[1] for x in P_digits.most_common())) == 4 and is_int)


import re
fmt_reg = re.compile('^[1-9][0-9]{5}$')
rdp_reg = re.compile('(?=([0-9])[^\\1]\\1)')
s = input()
print(bool(fmt_reg.match(s)) and len(rdp_reg.findall(s)) < 2)


import re

def validCode(number):
	inRange = bool(re.search('^[1-9][0-9]{5}$', number))
	altTriple = bool(re.search('([0-9])[0-9]\\1[0-9]\\1', number))
	interleavingPairs = bool(re.search('([0-9])([0-9])\\1\\2', number))
	separatePairs = bool(re.search('([0-9])[0-9]\\1[0-9]*([0-9])[0-9]\\2', number))
	return inRange and (not altTriple) and (not interleavingPairs) and (not separatePairs)
print(validCode(input()))


import re
t = input().strip()
print(bool(re.search('^[1-9][0-9]{5}$', t)) and (not bool(re.search('((.).(?=\\2).*(.).\\3)|((.)(.)\\5\\6)', t))))


z = input()
print(z.isdigit() and 100000 <= int(z) <= 999999 and ([z[i] == z[i + 2] for i in range(4)].count(True) <= 1))


s = input()
while not s.isnumeric() or len(s) != 6 or s[0] == '0':
	print(False)
	exit()
i = 0
x = 0
while i < 4 and x <= 1:
	while s[i] == s[i + 2]:
		x += 1
		break
	i += 1
while i == 4 and x <= 1:
	print(True)
	exit()
print(False)


import re
pattern = re.compile('^[0-9]{6}$')
rep = re.compile('([2-90])\\1{1,}')
s = str(input())
result = pattern.match(s) is not None and len([m.group() for m in rep.finditer(s[::2])]) == 0 and (len([m.group() for m in rep.finditer(s[1::2])]) == 0)
print(result)


a = input()
b = []
n = len(a)
i = 0
count = 0
while i < n - 2:
	k = i
	j = i
	while j < n - 1 and a[j] == a[j + 2]:
		count = count + 1
		break
		j = j + 1
	i = i + 1
print(count <= 1 and (n == 6 and a.isdigit()))


import re
P = input()

def validate(P):
	try:
		P = int(P)
	except:
		print(False)
		return
	P = str(P)
	regex = re.compile('((\\d).\\2)')
	current_sub = P
	alt_count = 0
	while regex.search(current_sub) is not None:
		alt_count += 1
		g = regex.search(current_sub)
		pos = g.start()
		current_sub = current_sub[pos + 1:]
	test = [alt_count <= 1, int(P) >= 100000, int(P) <= 999999]
	print(all(test))
validate(P)


import re
s = input()
print(bool(not re.search('(\\d)(\\d)\\1\\2|(\\d).\\1.*(\\d).\\2', s) and re.search('^[1-9][0-9]{5}$', s)))


P = input()

def nand(b1, b2):
	return not (b1 and b2)
b = True
b = P.isdigit()
b = b and len(P) == 6
b2 = P[0] == P[2]
b3 = P[1] == P[3]
b4 = P[2] == P[4]
b5 = P[3] == P[5]
b = b and nand(b2, b3)
b = b and nand(b2 or b3, b4)
b = b and nand(b2 or b3 or b4, b5)
print(b)


import sys, re
code = sys.stdin.readline().strip()
r1 = re.compile('[123456789]\\d{5}')
r2 = re.compile('(?P<x>\\d)\\d(?P=x)')
m1 = r1.match(code)
is_size_ok = len(code) == 6
is_in_range = bool(m1)
is_alternating = len({z.span() for z in filter(bool, (r2.search(code, x) for x in range(0, 4)))}) > 1
print(is_size_ok and is_in_range and (not is_alternating))


def valid(number):
	res = []
	for i in range(len(number) - 2):
		res.append(number[i] == number[i + 2])
	try:
		v = int(number)
	except:
		return False
	return v >= 100000 and v <= 999999 and (sum(res) <= 1)
value = input().strip()
print(valid(value))


import re
digits = re.compile('\\d{6,6}')
notdig = re.compile('\\D')
chkrep = re.compile('(?=([0-9])[0-9]\x01)')
s = input().strip()
count = 0
for k in range(len(s) - 2):
	count += 1 * s[k] == s[k + 2]
print(len(s) == 6 and (not notdig.search(s)) and (count < 2))


import re
regexes = ['(?<=(\\d).)(?=(\\d))\\1']
s = input()
try:
	print(len(re.findall(regexes[0], s)) <= 1 and 100000 <= int(s) <= 999999)
except:
	print('False')


import re
r = '(?=[1-9]\\d{5}$)(?!.*(.).\\1.*(.).\\2)(?!.*(.)(.)\\3\\4)(?!.*(.).\\5.\\5)'
print(re.match(r, input()) != None)


p = input()
try:
	bools = [0, 0]
	bool1 = False
	bool2 = False
	for i in range(2, len(p)):
		bools[p[i] == p[i - 2]] += 1
	bool1 = not bools[1] or not bools[1] - 1
	bools = [False, True]
	bool2 = bools[int(p) >= 100000 and int(p) <= 999999]
	print(bool1 and bool2)
except:
	print(False)


def is_valid_range(s):
	try:
		i = int(s)
	except ValueError:
		return False
	return i >= 100000 and i <= 999999

def is_valid(s):
	t1 = abs(int(s[0]) - int(s[2]))
	t2 = abs(int(s[1]) - int(s[3]))
	t3 = abs(int(s[2]) - int(s[4]))
	t4 = abs(int(s[3]) - int(s[5]))
	return not (t1 + t2 == 0 or t1 + t3 == 0 or t1 + t4 == 0 or (t2 + t3 == 0) or (t2 + t4 == 0) or (t3 + t4 == 0))
s1 = input()
print(is_valid_range(s1) and is_valid(s1))


import re

def validate(s):
	return re.match('(\\d){6,6}$', s) != None and s[0] != '0' and (len(list(filter(lambda i: re.match('(\\d).\\1', s[i:]), range(4)))) <= 1)
print(validate(input()))


def chk1(a):
	return len(a) == 6 and a.isnumeric()

def chk2(a):
	return 100000 <= int(a) <= 999999

def chk3(a):
	ans = len(list(filter(lambda x: a[x] == a[x - 2], range(2, 6))))
	return ans < 2
a = input()
print(chk1(a) and chk2(a) and chk3(a))


import re
s = input()
valid = s.isdigit() and 100000 <= int(s) and (int(s) <= 999999)
patterns = ['(?=(' + str(a) + str(b) + str(a) + '))' for b in range(10) for a in range(10)]
for p in patterns:
	matches = re.findall(p, s)
	valid = valid and len(matches) <= 1
print(valid)


P = input().strip()
import re
p = re.compile('(\\d)(?=\\d\\1)')
p2 = re.compile('\\d{6}$')
print(bool(p2.match(P)) and 100000 <= int(P) <= 999999 and (len(p.findall(P)) < 2))


def is_valid(postal_code):
	alternating_pairs = 0
	for i in range(1, len(postal_code) - 1):
		alternating_pairs += int(postal_code[i - 1] == postal_code[i + 1])
	return postal_code.isdigit() and 100000 <= int(postal_code) <= 999999 and (alternating_pairs <= 1)
postal_code = input().strip()
print(str(is_valid(postal_code)))


try:
	code = input()
	pairs = ''
	queue = [code[0], code[1]]
	for c in code[2:]:
		a = int(c)
		b = int(queue.pop(0))
		pairs += str(a - b)
		queue.append(c)
	print(int(code) in [x for x in range(100000, 1000000)] and pairs.count('0') < 2)
except:
	print('False')


import re
p = input()
try:
	int(p)
	print(len(p) == 6 and re.compile('[1-9][0-9]{5}').match(p) and ([p[i] == p[i + 2] for i in range(4)].count(True) < 2))
except Exception:
	print(False)


import re
result = lambda x: not bool(re.search('(\\d)(\\d)\\1\\2', x)) and (x.isdigit() and int(x) > 100000 and (int(x) < 1000000))
print(result(input('')))


def inn(p):
	return 100000 <= int(p) <= 999999

def imm(p):
	l = []
	for i in range(len(p) - 2):
		l.append(p[i] != p[i + 2])
	return all(l)

def is_valid(p):
	return (p.isdigit() and inn(p)) and p != '110000'

def main():
	p = input()
	print(is_valid(p))
main()


s = input()
print(s.isdigit() and int(s) in range(100001, 1000000) and ([s[i] == s[i + 2] for i in range(0, len(s) - 2)].count(True) < 2))


import re

def check(P):
	try:
		return (int(P) >= 100000 and int(P) <= 999999) and (re.findall('(\\d)(\\d)(\\1)', P) == [] or len(re.findall('(\\d)(\\d)(\\1)(\\2)', P)) == 0)
	except:
		return False
P = input()
print(check(P))


import re
input_string = input()
result = True
matches = [e for e in re.findall('(?=((\\d)\\d\\2))', input_string)]
condition = len(matches) > 1 or len(input_string) != 6 or input_string == ''
result = result and (not condition)
result = result and input_string.isdigit()
input_string = input_string + 'a'
result = result and (not input_string[0] == '0')
print(result)


s = input().strip()
try:
	v = int(s)
	valid = v > 100000 and v < 999999
	amount = 0
	for idx in range(4):
		amount += int(s[idx] == s[idx + 2])
	valid &= amount <= 1
	print(valid)
except:
	print(False)


import re
mystring = input().strip()
pattern = '^[1-9]{1}[0-9]{5}$'
pattern3 = '(?=(\\d)\\d\\1)'
match1 = re.search(pattern, mystring)
match3 = re.findall(pattern3, mystring)
print(bool(match1) and len(match3) <= 1)


import re
postal = input()
validations = []
validations.append(re.match('^[1-9][0-9]{5}$', postal))
alternating = re.findall('(\\d)(?=\\d\\1)', postal)
validations.append(len(alternating) < 2)
print(all(validations))


import re
s = input()
count = 0
try:
	assert 100000 <= int(s) <= 999999
except:
	print('False')
	exit(0)
for i in range(len(s)):
	m = re.findall('(\\d)\\d\\1', s[i:])
	try:
		count += len(m)
	except:
		pass
try:
	assert count < 2
	print('True')
except:
	print('False')


a = input().strip()
try:
	ans = 100000 <= int(a) <= 999999
except ValueError:
	ans = False
while not ans:
	print(ans)
	exit(0)
ans = 0 <= (a[0] == a[2]) + (a[2] == a[4]) + (a[1] == a[3]) + (a[3] == a[5]) + (a[1] == a[5]) <= 1
print(ans)


import re
num = input()
print(bool(re.match('^[1-9][\\d]{5}$', num) and len(re.findall('(\\d)(?=\\d\\1)', num)) < 2))


p = input()
this = []
that = []
this.append(p.isnumeric())
try:
	this.append(100000 < int(p))
	this.append(999999 > int(p))
except:
	this.append(False)
for x in range(0, len(p) - 2):
	that.append(p[x] != p[x + 2])
print(False not in this and that.count(False) < 2)


import re
p1 = '^[1-9][\\d]{5}$'
p2 = '(?=([\\d])([\\d])(\\1))'
s = input().strip()
print(bool(re.match(p1, s) and len(re.findall(p2, s)) <= 1))


import re
s = input().rstrip()
p1 = re.compile('^\\d{6}$', re.M)
p2 = re.compile('([0-9])(\\d\\1)', re.M)
a = not re.findall(p1, s) == []
b = not re.findall(p2, s) == []
d = not re.findall(p2, s[1:]) == []
c = a and (not d)
print(c)


import re
t = input().strip()
match = re.finditer('(?=(?P<grouping>((?P<digit>(^[1-9]|(?<=[0-9])[0-9]))[0-9](?P=digit))))', t)
match2 = re.match('^[1-9][0-9]{5}$', t)
print(len([m.group('grouping') for m in match]) <= 1 and match2 is not None)


import re
S = input()
print(bool(len(re.findall('(?<=(\\d))\\d(?=\\1)', S)) < 2) and bool(re.match('[1-9]', S)) and (len(S) == 6))


import re
p = input()
r1 = '((?P<g1>\\d)(?P<g2>\\d)(?P=g1)(?P=g2))'
r2 = '^[1-9][0-9]{5}$'
print(re.search(r1, p) == None and re.match(r2, p) != None)