Harryxun/stf_run huggingface dataset:
import sys

a = []
for l in sys.stdin:
    if l == '\n':
        break
    else :
        a.append(l)

target = a[int(a[0])]
print(target)

outNum = []
i1 = 0
for item in range(0, int(a[0]) - 1):
    if i1 != 0:
        for i in range(0, len(target) - 1):
            flag = False
            if target.count(target[i]) == item.count(target[i]):
                print(item)
                flag = True
            else:
                break
        if flag:
            outNum.append(item)
    i1 = i1 + 1
    flag = False
print(len(outNum))      



### FIXED CODE ###

import sys
import collections

n=int(input())
a=[''.join(sorted(input())) for _ in range(n)]

ans = 0
for v in collections.Counter(a).values():
    if v != 1:
        ans += v * (v - 1) // 2
print(ans)
n, m, k =map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
ta=sum(a)
a.append(0)
tb=0
ans=0
j=0
for i in range(n+1):
    ta -= a[n-i]
    if ta>k:
        continue
    while tb + ta<k:

        if j ==n:
            ans=max(ans,n-i+j+1)
            break
        tb += b[j]
        ans=max(ans,n-i+j)
        j +=1

print(ans)


### FIXED CODE ###

n, m, k =map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
ta=sum(a)
a.append(0)
tb=0
ans=0
j=0
for i in range(n+1):
    ta -= a[n-i]
    if ta>k:
        continue
    while tb + ta<=k:

        if j ==m:
            ans=max(ans,n-i+j)
            break
        ans=max(ans,n-i+j)
        tb += b[j]
        j +=1

print(ans)
import numpy as np
N, M = map(int, input().split())
cities = {}
P = {}
Y = []
for i in range(M):
    p,y = map(int, input().split())
    cities[i] = (p,y)
    Y.append(y)

sorted_Y = sorted(Y)
sorted_P = {p:sorted(P[p].items(), key=lambda x:x[1]) for p in P}

P_i = np.zeros(N)
ans = {}
for i in sorted_Y:
    city = Y.index(i)+1
    ans[city] = i

for i in ans:
    p,y = cities[i]
    print('{0:06}{1:06}'.format(p, i))


### FIXED CODE ###

import numpy as np
N, M = map(int, input().split())
cities = {}
P = {}
Y = {}
for i in range(M):
    p,y = map(int, input().split())
    cities[i] = p
    Y[i] = y

ans = {}
sorted_Y = sorted(Y.items(), key=lambda x:x[1])
P_i = np.zeros(N)
for i,y in sorted_Y:
    p = cities[i]
    P_i[p-1] += 1
    ans[i] = (p, int(P_i[p-1]))

for i in range(M):
    print('{0:06}{1:06}'.format(ans[i][0], ans[i][1]))
import collections
import math

def combination(n, m):
    return math.factorial(n) / (math.factorial(n - m) * math.factorial(m))

N = int(input())
S = []
for n in range(N):
    S.append(str(input()))

ans = 0
Y=[]
for s in S:
    X = []
    for w in s:
        X.append(w)
        X.sort()
        y = ''.join(X)
    Y.append(y)

c = collections.Counter(Y)
C = c.most_common()

len_C = len(C)

for n in range(len_C):
    if C[n][1] == 1:
        del C[n]
    else:
        pass

len_C = len(C)

for m in range(len_C):
    ans += combination(C[m][1], 2)

print(round(ans))

### FIXED CODE ###

import collections
import math

def combination(n, m):
    return math.factorial(n) / (math.factorial(n - m) * math.factorial(m))

N = int(input())
S = []
for n in range(N):
    S.append(str(input()))

ans = 0
Y=[]
for s in S:
    X = []
    for w in s:
        X.append(w)
        X.sort()
        y = ''.join(X)
    Y.append(y)

c = collections.Counter(Y)
C = c.most_common()
len_C = len(C)

for n in range(len_C):
    if C[n][1] > 1:
        ans += combination(C[n][1], 2)
    else:
        pass

print(round(ans))
import numpy as np
import math as m

def main(**kwargs):
    r = -1

    for i in range(10 ** n - 1, 10 ** (n - 1) - 1, -1):
        stri = str(i)
        flg = True

        for s, c in zip(S, C):
            if stri[s-1] != str(c):
                flg = False
    
        if flg:
            r = i

    if n == 1 and S == np.array([1]) and C == np.array([0]):
        r = 0

    return r

if __name__ == "__main__":
    cin = np.array(input().split(" ")).astype("int")
    n, m, *_ = cin

    S = np.zeros(m, dtype="int")
    C = np.zeros(m, dtype="int")

    for i in range(m):
        cin = np.array(input().split(" ")).astype("int")
        S[i], C[i] = np.array(cin)
    
    cout = main(n=n, m=m, S=S, C=C)
    print(cout)

### FIXED CODE ###

import numpy as np
import math as m

def main(**kwargs):
    r = -1

    if n > 1:
        for i in range(10 ** n - 1, 10 ** (n - 1) - 1, -1):
            stri = str(i)
            flg = True

            for s, c in zip(S, C):
                if stri[s-1] != str(c):
                    flg = False
        
            if flg:
                r = i

    else:
        for i in range(9, -1, -1):
            stri = str(i)
            flg = True

            for s, c in zip(S, C):
                if stri[s-1] != str(c):
                    flg = False
        
            if flg:
                r = i
    
    return r

if __name__ == "__main__":
    cin = np.array(input().split(" ")).astype("int")
    n, m, *_ = cin

    S = np.zeros(m, dtype="int")
    C = np.zeros(m, dtype="int")

    for i in range(m):
        cin = np.array(input().split(" ")).astype("int")
        S[i], C[i] = np.array(cin)
    
    cout = main(n=n, m=m, S=S, C=C)
    print(cout)
S = list(map(str, input().split()))
S[3] = '8'
print(S)

### FIXED CODE ###

S = list(input())
S[3] = "8"
print("".join(S))
a = int(input())
b = [map(int,input().split()) for i in range(a) ]
c = [map(int,input().split()) for j in range(a) ]
e = 0
for k in range(a):
    d = b[k] - c[k]
    if d > 0:
        e += d
print(e)

### FIXED CODE ###

a = int(input())
b = map(int,input().split())
c = map(int,input().split())
b,c = list(b),list(c)
e = 0
for k in range(a):
    d = b[k] - c[k]
    if d > 0:
        e += d
print(e)
= input().split()
b = input().split()
c = input().split()
list_ans =(a,b,c)
N = int(input())
bingo_list=[]

for i in range(N):
    bingo = input()
    bingo_list.append(bingo)


#横ビンゴ判定
def bingo_row(p,q):
    row_total= 0
    #p 横のリスト　q 出た値のリスト
    for i in range(3):
        if p[i] in q:
            row_total +=1
        else:
            return False
    if row_total == 3:
        return True
#縦ビンゴ判定
def bingo_column(p,q,r,s):
    batu = 0
    #pqr横リスト　s bingo_list
    for i in range(3):
        
        if p[i]  in s and q[i] in s:
            if r[i] in s:
                return True
                break
            else:
                batu +=1 
        else:
            batu +=1
    if batu == 3:
        return False
#斜めビンゴ判定
def bingo_slash(p,q,r,s):
    if q[1] in s:
        if p[0] in s and r[2] in s:
            print('C')
            return True
        elif p[2] in s and r[0] in s:
            print('D')
            return True
        else:
            return False
    else:
        return False

    
total = 0
for i in list_ans:
    if bingo_row(i, bingo_list):
        print('Yes')
        break
    elif bingo_column(a,b,c,bingo_list):
        print('Yes')
        break
    elif bingo_slash(a,b,c,bingo_list):
        print('Yes')
        break
    else:
        total += 1
if total == 3:
    print('No')



### FIXED CODE ###

a = input().split()
b = input().split()
c = input().split()
list_ans =(a,b,c)
N = int(input())
bingo_list=[]

for i in range(N):
    bingo = input()
    bingo_list.append(bingo)


#横ビンゴ判定
def bingo_row(p,q):
    row_total= 0
    #p 横のリスト　q 出た値のリスト
    for i in range(3):
        if p[i] in q:
            row_total +=1
        else:
            return False
    if row_total == 3:
        return True
#縦ビンゴ判定
def bingo_column(p,q,r,s):
    batu = 0
    #pqr横リスト　s bingo_list
    for i in range(3):
        
        if p[i]  in s and q[i] in s:
            if r[i] in s:
                return True
                break
            else:
                batu +=1 
        else:
            batu +=1
    if batu == 3:
        return False
#斜めビンゴ判定
def bingo_slash(p,q,r,s):
    if q[1] in s:
        if p[0] in s and r[2] in s:
            return True
        elif p[2] in s and r[0] in s:
            return True
        else:
            return False
    else:
        return False

    
total = 0
for i in list_ans:
    if bingo_row(i, bingo_list):
        print('Yes')
        break
    elif bingo_column(a,b,c,bingo_list):
        print('Yes')
        break
    elif bingo_slash(a,b,c,bingo_list):
        print('Yes')
        break
    else:
        total += 1
if total == 3:
    print('No')
A,B,K=map(int, raw_input().split())
l=range(A,B+1)

if len(l)/2>=K:
	for i in l[:K]:
		print i
	for i in l[-K:]:
		print i
#elif len(l)/2<K and K<len(l):
#	for i in l[:K]:
#		print i
#	for i in l[ K-len(l):]:
#		print i
else:
	for i in l:
		print i

### FIXED CODE ###

A,B,K=map(int, raw_input().split())
c=set()
for i in range(A,min(B+1,A+K)):
	c.add(i)

for i in range(B,max(A-1,B-K),-1):
	c.add(i)


a=list(c)
a.sort()
for i in a:
	print i
N = int(input()) 
a = list(map(int, input().split()))
a[0:0] = [-1, -1, -1]
x=1
for i in range(3,N+2):
  b=a[0:i-1]
  x = x*((b.count(a[i]-1)-b.count(a[i])))
  if x=0:x=1
x = x % 1000000007
print(x)

### FIXED CODE ###

N = int(input()) 
a = list(map(int, input().split()))
b = [-1, -1, -1]
x=1
for i in range(N):
  x = x*b.count(a[i]-1) % 1000000007
  if b[0]==(a[i]-1):
    b[0]+=1
  elif b[1]==(a[i]-1):
    b[1]+=1
  else:
    b[2]+=1
print(x)
a = []
for i in range(0,4):
  a.append(input())
k =int(input())
if k <= (a[4] - a[0]):
  print("Yay!")
else:
  print(":(")
  



### FIXED CODE ###

a = []
for i in range(5):
  a.append(int(input()))
  
k =int(input())
if k >= (a[4] - a[0]):
  print('Yay!')
else:
  print(':(')
N, K = map(int, input().split())
D = set(map(int, input().split()))
safe = set(range(10)) - D

def test(N):
    return set((int(x) for x in str(N))) <= safe

def F(N):
    while N % 10:
        if text(N):
            return N
        N += 1
    N //= 10
    x = F(N)
    y = min(safe)
    return 10 * x + y

answer = F(N)
print(answer)



### FIXED CODE ###

N, K = map(int, input().split())
D = set(input().split())

while True:
    l = list(str(N))
    for x in l:
        if x in D:
            N += 1
            break
    else:
        print(N)
        exit()
N=int(input())
if N =<999:
    print("ABC")
else:
    print("ABD")

### FIXED CODE ###

N=int(input())
if N <= 999:
    print("ABC")
else:
    print("ABD")
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
// }}} End Header
int main() {
	ll sum=0;
	string n;
	cin >> n;
	rep(i, n.length()){
		sum+=n[i]-'0';
	}
	if(sum%9 == 0) puts("Yes");
	else puts("No");
	return 0;
}


### FIXED CODE ###

n = int(input())
if n%9 == 0: print("Yes")
else: print("No")
import sys

ERROR_INPUT = 'input is invalid'
ERROR_INPUT_NOT_UNIQUE = 'input is not unique'


def main():
    S = get_input1()
    T = get_input2()

    count = 0
    for t in T:
        if binary_search(S, t, 0, len(S), len(S) // 2):
            print(t)
            count += 1

    print(count)


def binary_search(li, key, left, right, mid):
    if li[mid] == key:
        return True
    elif li[mid] < key:
        left = mid + 1
    elif li[mid] > key:
        right = mid

    if left > right:
        return False
    mid = (left + right) // 2
    return binary_search(li, key, left, right, mid)


def get_input1():
    n = int(input())
    if n > 100000:
        print(ERROR_INPUT)
        sys.exit(1)

    li = []
    for x in input().split(' '):
        if int(x) < 0 or int(x) > 10 ** 9:
            print(ERROR_INPUT)
            sys.exit(1)
        li.append(int(x))

    return li


def get_input2():
    n = int(input())
    if n > 50000:
        print(ERROR_INPUT)
        sys.exit(1)

    li = []
    for x in input().split(' '):
        if int(x) < 0 or int(x) > 10 ** 9:
            print(ERROR_INPUT)
            sys.exit(1)
        elif int(x) in li:
            print(ERROR_INPUT_NOT_UNIQUE)
            sys.exit(1)
        li.append(int(x))

    return li


main()

### FIXED CODE ###

import array

def main():
    n1 = int(input())
    li1 = array.array('l', [int(x) for x in input().split()])
    n2 = int(input())
    li2 = array.array('l', [int(x) for x in input().split()])
    count = 0

    for l in li2:
        if binary_search(li1, l):
            count += 1

    print(count)


def binary_search(li, x):
    if len(li) == 0:
        return False
    
    mid = len(li)//2
    
    k = li[mid]
    if k == x:
        return True
    elif k > x:
        li = li[:mid]
    else:
        li = li[mid+1:]
        
    return binary_search(li, x)

if __name__=='__main__':
    main()
N = int(input())
S = input()
onlyb = 0
onlyw = 0
twotn = 0
flag = 0
ch =0
for i in range(N):
    if S[i] == ".":
        onlyb += 1
        ch = 0
        if flag != 0:
            twotn +=1
    else:
        onlyw += 1
        ch +=1
        flag = 1

print(min(onlyb,onlyw-ch,twotn))

### FIXED CODE ###

N=int(input())
for i in range(1,3501):
  for j in range(i,3501):
    if (4*i*j-N*(i+j))>0 and N*i*j%(4*i*j-N*(i+j))==0:
      k=N*i*j//(4*i*j-N*(i+j))
      print(i,j,k)
      break
  else:
    continue
  break
N = int(input())
A =[i for i in map(int, input().split())]

result = 1
for i in range(n):
    result *= a[i]
    if result > (10**18):
        print(-1)
        break
    else:
        continue
print(result)

### FIXED CODE ###

n = int(input())
a = [i for i in map(int, input().split())]
 
if a.count(0) != 0:
  print(0)
else:
  result = 1
  for i in range(n):
    result *= a[i]
    if result > (10**18):
      print(-1)
      break
    else:
      continue
  else:
    print(result)
lista=[]
t=0
ch=0
e=0
d=0
tflag=1
while True:
    try:
        lista.append(list(map(int,input().split())))
    except:
        break;

def func01(a,b,c):
    global t
    global ch
    global e
    global d
    if a+b>c:
        t+=1
        if a**2+b**2==c**2:
            ch+=1
        elif a**2+b**2>c**2:
            e+=1
        elif a**2+b**2<c**2:
            d+=1
    else tflag==0
while(tflag==1):
    for i in range(len(lista)):
        x=sorted(lista[i])
        func01(x[0],x[1],x[2])
print(t,ch,e,d)


### FIXED CODE ###

lista=[]
t=0
ch=0
e=0
d=0
tflag=1
while True:
    try:
        lista.append(list(map(int,input().split())))
    except:
        break;

def func01(a,b,c):
    global t
    global ch
    global e
    global d
    global tflag
    if a+b>c:
        t+=1
        if a**2+b**2==c**2:
            ch+=1
        elif a**2+b**2>c**2:
            e+=1
        elif a**2+b**2<c**2:
            d+=1
    else:
        tflag=0
        
i=0
for i in range(len(lista)):
    if len(lista)==i:
        break
    x=sorted(lista[i])
    func01(x[0],x[1],x[2])
    if tflag==0:
        break
    i+=1
print(t,ch,e,d)
def bin_tree( pri , li_pri , len_li ):
    #pri: どこに入れていいかわからない値段
    #li_pri: 値段のリスト(昇順)
    #len_li: リストの長さ
    lo = 0
    hi = len_li - 1
    while hi - lo > 1:
        mid = lo + (hi - lo) // 2
        guess = li_pri[mid]
        if guess >= pri:
            hi = mid
        else:
            lo = mid
    return lo

I = input().split()
N = int(I[0])
M = int(I[1])
# N: 品物の数
# M: 割引券の数
# A: 品物の値段行列
A = list(map(int , input().split()))
A.sort()

while M > 0:
    M -= 1
    pri = A.pop( N - 1 )
    pri = pri // 2
    if (pri < A[0]):
        ans = 0
    else:
        ans = bin_tree( pri , A , N - 1 ) + 1
    # ans: pri以上となる値段のうち最小のインデックス
    A[ans:ans] = [pri]    

F_pri = 0
for i in range(N):
    F_pri += A[i]
print(F_pri)

### FIXED CODE ###

def bin_tree( pri , li_pri , len_li ):
    #pri: どこに入れていいかわからない値段
    #li_pri: 値段のリスト(昇順)
    #len_li: リストの長さ
    lo = 0
    hi = len_li - 1
    while hi - lo > 1:
        mid = lo + (hi - lo) // 2
        guess = li_pri[mid]
        if guess >= pri:
            hi = mid
        else:
            lo = mid
    return lo

I = input().split()
N = int(I[0])
M = int(I[1])
# N: 品物の数
# M: 割引券の数
# A: 品物の値段行列
A = list(map(int , input().split()))
A.sort()

while M > 0:
    M -= 1
    pri = A.pop( N - 1 )
    pri = pri // 2
    if len(A) == 0:
        ans = 0
    elif (pri < A[0] ):
        ans = 0
    else:
        ans = bin_tree( pri , A , N - 1 ) + 1
    # ans: pri以上となる値段のうち最小のインデックス
    A[ans:ans] = [pri]    

F_pri = 0
for i in range(N):
    F_pri += A[i]
print(F_pri)
# 誰か奇数になったら終了
# A==B==C になったら-1

A,B,C=map(int,input().split())
cnt=0
while A%2==0 and B%2==0 and C%2==0:
    if A==B==C:
        ans=-1
        break
    else:
        A,B,C=(B+C)//2,(C+A)//2,(A+B)//2
        cnt+=1
        ans=cnt
print(ans)

### FIXED CODE ###

# 誰か奇数になったら終了
# A==B==C になったら-1

A,B,C=map(int,input().split())
cnt=0
ans=0
while A%2==0 and B%2==0 and C%2==0:
    if A==B==C:
        ans=-1
        break
    else:
        A,B,C=(B+C)//2,(C+A)//2,(A+B)//2
        cnt+=1
        ans=cnt
print(ans)
N = int(input())
h = [int(i) for i in input().split()]

def f(n, h):
    g = {0: 0, 1: abs(h[1] - h[0])}
    def f_(n, h):
        if n in g:
            return g[n]

        g[n] = min(abs(h[n] - h[n-1]) + f_(n-1, h), abs(h[n] - h[n-2]) + f_(n-2, h))
        return g[n]
    return f_(n, h)

print(f(N-1, h))



### FIXED CODE ###

N = int(input())
h = [int(i) for i in input().split()]

def g(n, h):
    g2 = 0
    g1 = abs(h[1] - h[0])
    for i in range(2, n+1):
        g = min(abs(h[i] - h[i-1]) + g1, abs(h[i] - h[i-2]) + g2)
        g2 = g1
        g1 = g
    return g1

print(g(N-1, h))
import fractions
 
n = int(input())
a = list(map(int, input().split()))
 
num = a[0]
for i in range(1, n):
	num = (num * a[i]) // fractions.gcd(num, a[i])
 
ans = 0
for i in range(n):
	ans += (num//a[i]) % 1000000007
 	if ans > 1000000007:
      	ans = ans % 1000000007
print(ans)

### FIXED CODE ###

import fractions
 
n = int(input())
a = list(map(int, input().split()))
 
l = 1
for i in range(n):
	l = l // fractions.gcd(l, a[i])*a[i]
 
ans = 0
for i in range(n):
	ans += l//a[i]
print(ans%(10**9+7))
import numpy as np
 
n = input()
v = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
 
profit = v - c
positive_profit = profit(profit > 0)
print(np.sum(positive_profit))

### FIXED CODE ###

import numpy as np
 
n = input()
v = np.array([int(x) for x in input().split()])
c = np.array([int(x) for x in input().split()])
 
profit = v - c
positive_profit = profit[profit > 0]
print(np.sum(positive_profit))
str alpha=input()
if (alpha.isupper()){
  print(A)
}else{
  print(B)
}


### FIXED CODE ###

alpha=input()
if (alpha.isupper()):
  print('A')
else:
  print('a')
from scipy.special import comb

N,Y= [int(i) for i in input().split()]
a=N+Y
if a%3 != 0:print(0)
else:
    b=int(a/3)
    c=abs(N-Y)
    if b==1:
        print(1)
    elif c==0:
        e=int(b/2)
        print(int(comb(b,e,exact=True))%(10**9+7))
    else:
        print(int(comb(b,c,exact=True))%(10**9+7))

### FIXED CODE ###

def egcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)

# ax ≡ 1 (mod m)

def modinv(a, m):
    (inv, q, gcd_val) = egcd(a, m)
    #print(inv, q, gcd_val)
    return inv % m

def m(n,r):
    d=1
    e=1
    f=1
    for i in range(r):
        d=(n-i)
        e=(i+1)
        d%=(10**9+7)
        f = f*d*modinv(e,(10**9+7))%(10**9+7)
        
    return(f)

n=[int(i) for i in input().split()]
a=sum(n)
if a%3 != 0:print(0)

else:
    b=int(a/3)
    if b==1:
        print(1)
    else:
        c=n[0]-b
        d=n[1]-b
        if c<0 or d<0: print(0)

        else:
            if c==d:
                c=int(b/2)
            d=m(b,min(c,d))
            print(d%(10**9+7))
from bisect import*
def main():
    root=[],[]
    def search_higher(key):
        ptr=root
        ret=None
        while ptr[1]:
            i=bisect(ptr[0],key)
            if i!=len(ptr[0]):ret=ptr[0][i]
            ptr=ptr[1][i]
        i=bisect(ptr[0],key)
        if i!=len(ptr[0]):ret=ptr[0][i]
        return ret
    def search_lower(key):
        ptr=root
        ret=None
        while ptr[1]:
            i=bisect_left(ptr[0],key)
            if i!=0:ret=ptr[0][i-1]
            ptr=ptr[1][i]
        i=bisect_left(ptr[0],key)
        if i!=0:ret=ptr[0][i-1]
        return ret
    def insert_rec(ptr,key):
        b_size=512
        if not ptr[1]:
            insort(ptr[0],key)
            if len(ptr[0])==b_size*2-1:
                ret=ptr[0][:b_size],[]
                ptr[0]=ptr[0][b_size:]
                return ret
        else:
            i=bisect(ptr[0],key)
            tmp=insert_rec(ptr[1][i],key)
            if tmp:
                ptr[0].insert(i,tmp[0].pop())
                ptr[1].insert(i,tmp)
                if len(ptr[1])==b_size*2:
                    ret=[],[]
                    ret=ptr[0][:b_size],ptr[1][:b_size]
                    ptr[0],ptr[1]=ptr[0][b_size:],ptr[1][b_size:]
                    return ret
    def insert(key):
        tmp=insert_rec(root,key)
        if tmp:root[0],root[1]=[tmp[0].pop()],[tmp,root]
    n,*a=map(int,open(0).read().split())
    l=[0]*n
    for i,v in enumerate(a,1):l[v-1]=i
    insert(0)
    insert(n+1)
    c=0
    for i,v in enumerate(l,1):
        c+=(search_higher(v)-v)*(v-search_lower(v))*i
        insert(v)
    print(c)
main()

### FIXED CODE ###

root=lambda x:x if par[x]==x else root(par[x])
same=lambda x,y:root(x)==root(y)
def unite(*z):
  x,y=map(root,z)
  if x!=y:
    if rank[x]<rank[y]:
      par[x]=y
      size[y]+=size[x]
    else:
      par[y]=x
      size[x]+=size[y]
      if rank[x]==rank[y]:rank[x]+=1
n,*a=map(int,open(0).read().split())
*par,=range(n)
rank=[1]*n
size=[1]*n
b=[0]*n
for i,t in enumerate(a):b[t-1]=i
c=0
for k in b[::-1]:
  l=r=1
  if k>0 and a[k-1]>a[k]:
    l+=size[root(k-1)]
    unite(k-1,k)
  if k+1<n and a[k+1]>a[k]:
    r+=size[root(k+1)]
    unite(k+1,k)
  c+=l*r*a[k]
print(c)
def z_algorithm(s):
	"""Z-algorithm O(|S|)
    """
    l = len(s)
    z = [0] * l
    z[0] = l
    i, j = 1, 0
    while i < l:
        while i + j < l and S[j] == S[i+j]:
            j += 1
        z[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while k + z[k] < j:
            z[i+k] = z[k]
            k += 1
        i += k
        j -= k
 
    return z

### FIXED CODE ###

def z_algo(s):
    """Z-algorithm O(|S|)

    Args:
        s (str): 対象文字列
    
    Returns:
        list: lcp配列 (z[i]: sとs[i:]の最長共通接尾辞の長さ)
    """
    n = len(s)
    z = [0] * n
    z[0] = n
    i, j = 1, 0
    while i < n:
        while i + j < n and s[j] == s[i+j]:
            j += 1
        z[i] = j

        if j == 0:
            i += 1
            continue

        k = 1
        while i + k < n and k + z[k] < j:
            z[i+k] = z[k]
            k += 1

        i += k
        j -= k

    return z


n = int(input())
s = input()

res = 0
for i in range(n-1):
    z = z_algo(s[i:])
    for j in range(n-i):
        if z[j] <= j and res < z[j]:
            res = z[j]

print(res)
4 1
10 100
10 100
10 100
10 100

### FIXED CODE ###

from itertools import accumulate
n,w=map(int, input().split())
items = {}
for _ in range(n):
    u,v = map(int, input().split())
    if u not in items:
        items[u] = []
    items[u].append(v)
cost = 0
acc = []
minkey = min(items.keys())
for i in range(4):
    if minkey + i in items:
        items[minkey + i].sort(reverse=True)
        acc.append([0] + list(accumulate(items[minkey + i])))
    else:
        acc.append([0])

ans = 0
for i in range(len(acc[0])):
    a = (i) * minkey
    if w < a:
        continue
    for j in range(len(acc[1])):
        b = (j) * (minkey+1)
        if w < a + b:
            continue
        for k in range(len(acc[2])):
            c = (k) * (minkey+2)
            if w < a + b + c:
                continue
            for l in range(len(acc[3])):
                d = (l) * (minkey+3)
                if w < a + b + c + d:
                    continue
                cost = acc[0][i] + acc[1][j] + acc[2][k] + acc[3][l]
                if cost > ans :
                    ans = cost

print(ans)