#!/bin/python
from itertools import combinations

def check_if_t(s):
    chars = list(set(s))
    flag = False
    if s == "".join([chars[i%len(chars)] for i in range(len(s))]) or s == "".join([chars[::-1][i%len(chars)] for i in range(len(s))]):
        flag = True
    return flag

n = input()
s = raw_input()
chars = combinations(set(s),2)
try:
    print max(map(len,filter(check_if_t,["".join([j for j in s if j == k[0] or j == k[1]]) for k in chars])))
except:
    print 0
@@ -95,24 +95,19 @@
     
-flag = False%0A   
+return True
  if 
@@ -128,26 +128,17 @@
 chars%5Bi%25
-len(chars)
+2
 %5D for i 
@@ -191,18 +191,9 @@
 %5D%5Bi%25
-len(chars)
+2
 %5D fo
@@ -218,45 +218,19 @@
 ))%5D)
-:%0A        flag = True%0A    return flag
+ else False
 %0A%0An 

Clean up check_if_t() (#24)