Clustering Algorithms - KMeans, KCenter, Single Linkage Agglomeration

Clustering
Author

Guntas Singh Saran

Published

February 5, 2024

Libraries

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from latex import latexify, format_axes
from os.path import join
import struct
from array import array
import random
from sklearn.metrics import rand_score
%matplotlib inline
%config InlineBackend.figure_format = 'retina'
latexify(columns = 2)

MNIST Data Class Loader from Kaggle

class MnistDataloader(object):
    def __init__(self, training_images_filepath,training_labels_filepath,
                 test_images_filepath, test_labels_filepath):
        self.training_images_filepath = training_images_filepath
        self.training_labels_filepath = training_labels_filepath
        self.test_images_filepath = test_images_filepath
        self.test_labels_filepath = test_labels_filepath
    
    def read_images_labels(self, images_filepath, labels_filepath):        
        labels = []
        with open(labels_filepath, 'rb') as file:
            magic, size = struct.unpack(">II", file.read(8))
            if magic != 2049:
                raise ValueError('Magic number mismatch, expected 2049, got {}'.format(magic))
            labels = array("B", file.read())        
        
        with open(images_filepath, 'rb') as file:
            magic, size, rows, cols = struct.unpack(">IIII", file.read(16))
            if magic != 2051:
                raise ValueError('Magic number mismatch, expected 2051, got {}'.format(magic))
            image_data = array("B", file.read())        
        images = []
        for i in range(size):
            images.append([0] * rows * cols)
        for i in range(size):
            img = np.array(image_data[i * rows * cols:(i + 1) * rows * cols])
            img = img.reshape(28, 28)
            images[i][:] = img            
        
        return images, labels
            
    def load_data(self):
        x_train, y_train = self.read_images_labels(self.training_images_filepath, self.training_labels_filepath)
        x_test, y_test = self.read_images_labels(self.test_images_filepath, self.test_labels_filepath)
        return (x_train, y_train), (x_test, y_test)

Loading the Training-Testing Images and Labels

input_path = './archive'
training_images_filepath = join(input_path, 'train-images-idx3-ubyte/train-images-idx3-ubyte')
training_labels_filepath = join(input_path, 'train-labels-idx1-ubyte/train-labels-idx1-ubyte')
test_images_filepath = join(input_path, 't10k-images-idx3-ubyte/t10k-images-idx3-ubyte')
test_labels_filepath = join(input_path, 't10k-labels-idx1-ubyte/t10k-labels-idx1-ubyte')

Helper Function to show list of images with their labels

def show_images(images, title_texts):
    cols = 5
    rows = int(len(images)/cols) + 1
    plt.figure(figsize=(30, 20))
    index = 1    
    for x in zip(images, title_texts):        
        image = x[0]        
        title_text = x[1]
        plt.subplot(rows, cols, index)        
        plt.imshow(image, cmap = "inferno")
        if (title_text != ''):
            plt.title(title_text, fontsize = 20);        
        index += 1

Loading the MNIST Dataset

mnist_dataloader = MnistDataloader(training_images_filepath, training_labels_filepath, test_images_filepath, test_labels_filepath)
(x_train, y_train), (x_test, y_test) = mnist_dataloader.load_data()
x_train, y_train, x_test, y_test = np.array(x_train), np.array(y_train), np.array(x_test), np.array(y_test)

Shape of the Training-Testing Data

x_train.shape, y_train.shape, x_test.shape, y_test.shape
((60000, 28, 28), (60000,), (10000, 28, 28), (10000,))

Some of the Digits

rand_idx = np.random.choice(10000, 5, replace = False)
show_images(x_train[rand_idx], y_train[rand_idx])
show_images(x_test[rand_idx], y_test[rand_idx])

Random Images displayed

images_2_show = []
titles_2_show = []
for i in range(0, 10):
    r = random.randint(1, 60000)
    images_2_show.append(x_train[r])
    titles_2_show.append('training image [' + str(r) + '] = ' + str(y_train[r]))    

for i in range(0, 5):
    r = random.randint(1, 10000)
    images_2_show.append(x_test[r])        
    titles_2_show.append('test image [' + str(r) + '] = ' + str(y_test[r]))    

show_images(images_2_show, titles_2_show)

Q3. K-Means and K-Center on Test Dataset \(10,000\) datapoints in \(\mathbb{R}^{784}\)

x_test.shape
(10000, 28, 28)
def flatten_out(data):
    return data.reshape(data.shape[0], -1)
x_test_flatten = flatten_out(x_test)
x_test_flatten.shape
(10000, 784)

K-Means using Llyod’s Algorithm with KMeans++ initialization

The Algorithm

For a given partition:

  • Find the centers of the current partition
  • Assign points to the nearest center
  • Recalculate the centers
  • Terminate when centers don’t shift much or no point changes the partition

The cost function:

\(\text{cost(C)} = \underset{x}{\operatorname{\sum}}\) \(\underset{c_x}{\operatorname{min}}\) \(d(x, c_x)^2\)

Objective is to minimise the variance of each cluster, the variance

\(\text{var}(C_i) = \underset{x \in C_i}{\operatorname{\sum}}\) \(||x - C_i||^2\)

which is minimised at the mean of each cluster

\(\overline{C_i} = \frac{1}{|C_i|} \underset{x \in C_i}{\operatorname{\sum}}\) \(x\)

KMeans++ Initialization

  • Choose the initial point randomly
  • For each remaining points \(x\), compute \(D(x)\), the distance between \(x\) and the nearest center already chosen.
  • Choose a new point as center with probability \(\frac{D(x)^{\alpha}}{\sum D(y)^{\alpha}}\), where \(\alpha = 2\) untill \(k\) centers have been chosen.
  • This is done by creating a CDF \(F_X(x)\) for the above probability distribution at each iteration of \(k\) runs. A uniform random variable \(U\) when substituted into the invervse of CDF of \(X\), returns the random drawn \(x\) i.e. \(x = F_X^{-1}(U)\)
  • To achieve this for our discrete CDF, we’ll generate a uniform sample using np.random.rand() and find the closest value to it in the discrete CDF and extract the index of the corresponding point, following is the code snippet for it:
    dist = np.min(np.linalg.norm(X[:, None] - centroids, axis = -1)[:, :i], axis = 1)
    probs = dist**2 / np.sum(dist**2)
    cdf = np.cumsum(probs)
    r = np.random.rand()
    my_idx = np.argmin(np.abs(cdf - r))
  • Else we may use np.random.choice(A, p = ProbabilityDistribution) by explicitly providing the probability distribution of sampling
class KMeansPP:
    def __init__(self, n_clusters, max_iter = 300, tol = 1e-4):
        self.k = n_clusters
        self.iter = max_iter
        self.tol = tol
        self.centroids = None
        self.labels = None
    
    def fit(self, X):
        """
            Choosing the new center based upon the probability distribution
            probab_dist = distances_from_their_centers ** alpha / np.sum(distances_from_their_centers ** alpha)
        """
        alpha = 2
        self.centroids = np.zeros((self.k, X.shape[1]))
        self.centroids[0] = X[np.random.randint(X.shape[0])]
        for i in range(1, self.k):
            dist = np.min(np.linalg.norm(X[:, None] - self.centroids, axis = -1)[:, :i], axis = 1)
            probs = dist**alpha / np.sum(dist**alpha)
            self.centroids[i] = X[np.random.choice(X.shape[0], p = probs)]
        
        """
            Now k centers are chosen, so we need to 
            run the iterations of Llyod's Algorithm
        """
        iter = 0
        while (iter <= self.iter or np.sum(np.linalg.norm(self.centroids - prev_centroids)) >= self.tol):
            distances = np.linalg.norm(X[:, None] - self.centroids, axis = -1)
            self.labels = np.argmin(distances, axis = 1)
            prev_centroids = self.centroids.copy()
            self.centroids = np.array([X[self.labels == i].mean(axis = 0) for i in range(self.k)])
            iter += 1
    
    def predict(self, X_):
        return np.argmin(np.linalg.norm(X_[:, None] - self.centroids, axis = -1), axis = 1)
        
k = 10
model = KMeansPP(n_clusters = k, max_iter = 20, tol = 1e-4)
model.fit(flatten_out(x_test))

Obtained \(k\) Centers from the KMeans++ initialization in only \(20\) iterations

centersPlot = model.centroids.reshape((k, 28, 28))
show_images(centersPlot, [f"Center {i}" for i in range(1, 11)])

pred_labels = model.labels
print(pred_labels)
print(y_test)
[1 2 4 ... 1 2 3]
[7 2 1 ... 4 5 6]
rand_score(pred_labels, y_test)
0.8884620462046204

K-Center Greedy Algo

The Algorithm

  • Choose first center arbitrarily
  • For each of the remaining \((k - 1)\) centers, choose the furthest point from the chosen centers untill all \(k\) centers have been found

How to choose the further point from the choosen centers?

Let \(G_i = \set{g_1, g_2, \ldots, g_i}\) be the set of \(i\) chosen centers, then we define \(d(x, G_i)\) as:

$ d(x, G_i) = $ $d(x, g) $

And the new center \(g_{i + 1}\) as:

\(g_{i + 1} = \underset{x}{\operatorname{argmax}}\) \(d(x, G_i)\)

Further we define maximum value of distance as \(\Delta_{i} = \underset{x}{\operatorname{max}}\) \(d(x, G_i)\)

that is, from the distances of a point \(x\) from each of the \(i\) centers, pickout the minimum distance (denoted by $ d(x, G_i)$) from the \(i\) centers and for all \(x\) in the dataset, choose the point with the maximum of these minimum distance (denoted by \(g_{i + 1}\) )

The cost of entire clustering \(D_{\text{algo}}\) also denoted as \(\Delta(G)\), is the maximum of the further distances of points from their respective centers. This means that we may place a ball of radius \(\Delta(G)\) over each of the \(k\) centers and we’ll be able to cover all points

class KCenter:
    def __init__(self, k = 10):
        self.k = k
        self.centers = None
        self.labels = None
    
    def fit(self, X):
        self.centers = np.zeros((self.k, X.shape[1]))
        self.centers[0] = X[np.random.randint(X.shape[0])]
        distances = np.zeros((X.shape[0], self.k))
        for i in range(1, self.k):
            for j in range(i):
                distances[:, j] = np.linalg.norm(X - self.centers[j], axis = 1)
            self.centers[i] = X[np.argmax(np.min(distances[:, :i], axis = 1))]
        self.labels = np.argmin(np.linalg.norm(X - self.centers[:, None], axis = 2), axis = 0)

    def predict(self, X_train):
        return np.argmin(np.linalg.norm(X_train - self.centers[:, None], axis = 2), axis = 0)
k = 10
model = KCenter(k = k)
model.fit(flatten_out(x_test))

Obtained \(k\) Centers from the KCenter Algorithm

centersPlot = model.centers.reshape((k, 28, 28))
show_images(centersPlot, [f"Center {i}" for i in range(1, 11)])

pred_labels = model.labels
print(pred_labels)
print(y_test)
[7 4 0 ... 8 0 3]
[7 2 1 ... 4 5 6]
rand_score(pred_labels, y_test)
0.6772203820382038

Single Linkage Agglomeration

Closeness Metric is the closest pair distance

\(D(C_1, C_2) = \underset{x \in C_1, y \in C_2}{\operatorname{\min}} d(x, y)\)

\(O(N^3)\)

from scipy.spatial.distance import squareform, pdist
from IPython.display import clear_output
import time

class SingleLinkageAgglomeration:
    def __init__(self, n_clusters = 10):
        self.k = n_clusters
        self.clusters = None
        self.labels = None
        self.point_clusters = []
        
    def fit(self, X):
        self.clusters = [[i] for i in range(X.shape[0])]
        while (len(self.clusters) > self.k):
            if (len(self.clusters) == X.shape[0]):
                D = squareform(pdist(X, metric = "euclidean"))
            
            # clear_output(wait = True)
            # print(D.shape)
            
            # print(self.clusters)
            # l = 0
            # for cluster in self.clusters:
            #     l += len(cluster)
            # print(l)
            
            D_argmin = D.copy()
            np.fill_diagonal(D_argmin, np.inf)
            D_argmin[np.triu_indices(D.shape[0])] = np.inf


            row, col = np.unravel_index(np.argmin(D_argmin), D.shape)
            merged_column = np.minimum(D[:, row], D[:, col])

            merged_column = np.delete(merged_column, row)
            # print(row, col)
            row, col = sorted([row, col])
            
            

            deleted_D = np.delete(np.delete(D, col, axis = 1), col, axis = 0)
            deleted_D[row] = merged_column
            deleted_D[:, row] = merged_column
            
            """
                [[0], [1], [2], [3], [4]]
                with [row, col] = [0, 2]
                will become
                [[0, 2], [1], [3], [4]]
                
                Further with [row, col] = [0, 2]
                will become
                [[0, 2, 3], [1], [4]]
            
            """
            # print()
            
            
            self.clusters[row].extend(self.clusters[col])
            self.clusters.pop(col)
            D = deleted_D.copy()
            
            # time.sleep(0.00001)
            
        self.labels = np.zeros(X.shape[0])
        for cluster_idx, cluster in enumerate(self.clusters):
            self.labels[cluster] = int(cluster_idx)
        
        for i in range(self.k):
            self.point_clusters.append(X[self.labels == i])
        
        
    def predict(self, X):
        predictions = np.zeros(X.shape[0])

        for i, x in enumerate(X):
            distances_to_clusters = np.zeros(self.k)
            
            for cluster_idx, cluster_points in enumerate(self.point_clusters):
                distances_to_clusters[cluster_idx] = np.min(np.linalg.norm(cluster_points - x, axis = 1))
            
            predictions[i] = np.argmin(distances_to_clusters)

        return predictions

Model Fitting for the random \(30\) points showing the merging of clusters along with the merge indices

k = 10
model = SingleLinkageAgglomeration(n_clusters = k)
rand_idx = np.random.choice(10000, 30, replace = False)
X = flatten_out(x_test)[rand_idx]
model.fit(X)
(30, 30)
[[0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15], [16], [17], [18], [19], [20], [21], [22], [23], [24], [25], [26], [27], [28], [29]]
30
29 19

(29, 29)
[[0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15], [16], [17], [18], [19, 29], [20], [21], [22], [23], [24], [25], [26], [27], [28]]
30
18 14

(28, 28)
[[0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14, 18], [15], [16], [17], [19, 29], [20], [21], [22], [23], [24], [25], [26], [27], [28]]
30
12 4

(27, 27)
[[0], [1], [2], [3], [4, 12], [5], [6], [7], [8], [9], [10], [11], [13], [14, 18], [15], [16], [17], [19, 29], [20], [21], [22], [23], [24], [25], [26], [27], [28]]
30
15 5

(26, 26)
[[0], [1], [2], [3], [4, 12], [5, 16], [6], [7], [8], [9], [10], [11], [13], [14, 18], [15], [17], [19, 29], [20], [21], [22], [23], [24], [25], [26], [27], [28]]
30
21 1

(25, 25)
[[0], [1, 24], [2], [3], [4, 12], [5, 16], [6], [7], [8], [9], [10], [11], [13], [14, 18], [15], [17], [19, 29], [20], [21], [22], [23], [25], [26], [27], [28]]
30
13 4

(24, 24)
[[0], [1, 24], [2], [3], [4, 12, 14, 18], [5, 16], [6], [7], [8], [9], [10], [11], [13], [15], [17], [19, 29], [20], [21], [22], [23], [25], [26], [27], [28]]
30
11 4

(23, 23)
[[0], [1, 24], [2], [3], [4, 12, 14, 18, 11], [5, 16], [6], [7], [8], [9], [10], [13], [15], [17], [19, 29], [20], [21], [22], [23], [25], [26], [27], [28]]
30
22 16

(22, 22)
[[0], [1, 24], [2], [3], [4, 12, 14, 18, 11], [5, 16], [6], [7], [8], [9], [10], [13], [15], [17], [19, 29], [20], [21, 28], [22], [23], [25], [26], [27]]
30
9 7

(21, 21)
[[0], [1, 24], [2], [3], [4, 12, 14, 18, 11], [5, 16], [6], [7, 9], [8], [10], [13], [15], [17], [19, 29], [20], [21, 28], [22], [23], [25], [26], [27]]
30
7 5

(20, 20)
[[0], [1, 24], [2], [3], [4, 12, 14, 18, 11], [5, 16, 7, 9], [6], [8], [10], [13], [15], [17], [19, 29], [20], [21, 28], [22], [23], [25], [26], [27]]
30
15 4

(19, 19)
[[0], [1, 24], [2], [3], [4, 12, 14, 18, 11, 22], [5, 16, 7, 9], [6], [8], [10], [13], [15], [17], [19, 29], [20], [21, 28], [23], [25], [26], [27]]
30
17 11

(18, 18)
[[0], [1, 24], [2], [3], [4, 12, 14, 18, 11, 22], [5, 16, 7, 9], [6], [8], [10], [13], [15], [17, 26], [19, 29], [20], [21, 28], [23], [25], [27]]
30
9 1

(17, 17)
[[0], [1, 24, 13], [2], [3], [4, 12, 14, 18, 11, 22], [5, 16, 7, 9], [6], [8], [10], [15], [17, 26], [19, 29], [20], [21, 28], [23], [25], [27]]
30
11 4

(16, 16)
[[0], [1, 24, 13], [2], [3], [4, 12, 14, 18, 11, 22, 19, 29], [5, 16, 7, 9], [6], [8], [10], [15], [17, 26], [20], [21, 28], [23], [25], [27]]
30
8 4

(15, 15)
[[0], [1, 24, 13], [2], [3], [4, 12, 14, 18, 11, 22, 19, 29, 10], [5, 16, 7, 9], [6], [8], [15], [17, 26], [20], [21, 28], [23], [25], [27]]
30
10 9

(14, 14)
[[0], [1, 24, 13], [2], [3], [4, 12, 14, 18, 11, 22, 19, 29, 10], [5, 16, 7, 9], [6], [8], [15], [17, 26, 20], [21, 28], [23], [25], [27]]
30
6 4

(13, 13)
[[0], [1, 24, 13], [2], [3], [4, 12, 14, 18, 11, 22, 19, 29, 10, 6], [5, 16, 7, 9], [8], [15], [17, 26, 20], [21, 28], [23], [25], [27]]
30
4 3

(12, 12)
[[0], [1, 24, 13], [2], [3, 4, 12, 14, 18, 11, 22, 19, 29, 10, 6], [5, 16, 7, 9], [8], [15], [17, 26, 20], [21, 28], [23], [25], [27]]
30
8 3

(11, 11)
[[0], [1, 24, 13], [2], [3, 4, 12, 14, 18, 11, 22, 19, 29, 10, 6, 21, 28], [5, 16, 7, 9], [8], [15], [17, 26, 20], [23], [25], [27]]
30
2 1
for idx, elt in enumerate(model.clusters):
    print(f"Cluster {idx} has {len(elt)} points")
Cluster 0 has 1 points
Cluster 1 has 4 points
Cluster 2 has 13 points
Cluster 3 has 4 points
Cluster 4 has 1 points
Cluster 5 has 1 points
Cluster 6 has 3 points
Cluster 7 has 1 points
Cluster 8 has 1 points
Cluster 9 has 1 points

Final Clusters and the Labels

print(model.clusters)
print(model.labels)
[[0], [1, 24, 13, 2], [3, 4, 12, 14, 18, 11, 22, 19, 29, 10, 6, 21, 28], [5, 16, 7, 9], [8], [15], [17, 26, 20], [23], [25], [27]]
[0. 1. 1. 2. 2. 3. 2. 3. 4. 3. 2. 2. 2. 1. 2. 5. 3. 6. 2. 2. 6. 2. 2. 7.
 1. 8. 6. 9. 2. 2.]

Rand-Index

rand_score(model.labels, y_test[rand_idx])
0.7862068965517242

Plotting the points in the \(2^{nd}\) cluster

show_images(model.point_clusters[2].reshape(-1, 28, 28), [f"" for i in range(len(model.point_clusters[2]))])

Fitting on the entire test data

k = 10
model = SingleLinkageAgglomeration(n_clusters = k)
X = flatten_out(x_test)
model.fit(X)
for idx, elt in enumerate(model.clusters):
    print(f"Cluster {idx} has {len(elt)} points")
Cluster 0 has 9991 points
Cluster 1 has 1 points
Cluster 2 has 1 points
Cluster 3 has 1 points
Cluster 4 has 1 points
Cluster 5 has 1 points
Cluster 6 has 1 points
Cluster 7 has 1 points
Cluster 8 has 1 points
Cluster 9 has 1 points
print(model.clusters)
print(model.labels)
[[0, 494, 4800, 1784, 1799, 9340, 1919, 3973, 9314, 7650, 1925, 9270, 2187, 7082, 9288, 9806, 3079, 5485, 3993, 8134, 6825, 5277, 2563, 2567, 6586, 7654, 4991, 8688, 8791, 1564, 263, 4970, 5540, 6837, 1321, 6805, 746, 6852, 3719, 4913, 6874, 4459, 7677, 229, 4493, 2252, 2646, 2591, 2887, 5402, 5798, 2262, 8591, 2275, 8654, 7180, 254, 6845, 941, 6316, 2844, 2967, 1576, 705, 6871, 1705, 3637, 8742, 8727, 9859, 8749, 1699, 383, 4295, 666, 2463, 3040, 9864, 9935, 9816, 7307, 9837, 5234, 6267, 1624, 3632, 3162, 1710, 4612, 9869, 1935, 4049, 6856, 9448, 6361, 7632, 5326, 8874, 9101, 8871, 5482, 1346, 3400, 9851, 4784, 6960, 6963, 7355, 4624, 4669, 438, 2399, 6830, 5162, 585, 8608, 6253, 1359, 2301, 9823, 2059, 4561, 911, 3643, 2238, 5563, 9990, 4773, 4677, 7021, 8421, 5324, 2290, 1563, 2234, 1171, 2141, 3609, 8617, 8638, 8651, 4568, 9413, 7276, 5789, 1006, 4760, 411, 1507, 4028, 1071, 6198, 7286, 7296, 6223, 7300, 3736, 1175, 2132, 946, 223, 1770, 2490, 5040, 4061, 7605, 8074, 3009, 7493, 9958, 7419, 3125, 8891, 7124, 3309, 4175, 5064, 5077, 8805, 9868, 9895, 8825, 9894, 9968, 5808, 6609, 3753, 5471, 7059, 7111, 8364, 8218, 7088, 7334, 7356, 7390, 8911, 8175, 5154, 7392, 8285, 5107, 5110, 5122, 5496, 8173, 7606, 7573, 5372, 8234, 1361, 1117, 3494, 1660, 2564, 1716, 3225, 8003, 9560, 1848, 6306, 7538, 7960, 8718, 6561, 8257, 6853, 7544, 7877, 7927, 8512, 6697, 8151, 5094, 1401, 3098, 3084, 5363, 5371, 6292, 8837, 5177, 9463, 86, 3743, 6170, 4064, 7362, 4781, 7647, 5498, 5576, 7141, 5795, 6307, 6171, 9899, 2837, 9543, 7648, 5751, 234, 8565, 1141, 679, 1806, 8606, 255, 1505, 3721, 1104, 2874, 7701, 9586, 2915, 8541, 3969, 7460, 9576, 3213, 4453, 2332, 3572, 649, 2710, 5334, 3453, 7467, 2, 204, 3386, 489, 3421, 835, 1295, 3320, 7183, 725, 1830, 754, 5902, 1280, 3314, 3689, 8650, 3858, 5193, 6634, 7087, 9295, 4191, 9282, 3562, 5776, 1897, 695, 4858, 1448, 5211, 3679, 1659, 672, 9345, 6182, 6938, 7299, 7290, 7303, 7073, 8586, 8604, 57, 2880, 6224, 4039, 8439, 9464, 6407, 3148, 154, 239, 330, 1728, 9336, 5880, 4179, 4651, 6891, 4264, 4085, 279, 419, 948, 2041, 2316, 2541, 5524, 6869, 6397, 6848, 2997, 2912, 4304, 3281, 1193, 7280, 1137, 2444, 272, 1736, 918, 2034, 889, 5889, 427, 9395, 5896, 9415, 4953, 6902, 3070, 3152, 4010, 3454, 3919, 5859, 178, 1350, 3648, 332, 1238, 2315, 4014, 4331, 302, 1180, 4144, 5520, 9401, 3455, 2287, 3379, 5506, 3779, 4685, 4069, 3230, 647, 5514, 735, 9443, 2688, 357, 504, 4273, 6338, 4195, 265, 1753, 9444, 1392, 4871, 4676, 2867, 9301, 663, 4153, 416, 4708, 6799, 3815, 6819, 8659, 5534, 768, 5604, 6419, 7636, 6809, 783, 984, 682, 7323, 385, 1484, 826, 5915, 6901, 9291, 5699, 9368, 168, 1430, 2356, 2757, 2868, 1829, 4057, 7618, 529, 8568, 3641, 9335, 9265, 2164, 3699, 1338, 1986, 8658, 180, 3639, 5679, 652, 675, 1254, 2335, 4525, 7686, 5651, 4774, 5917, 2965, 9324, 4653, 2421, 920, 2519, 1360, 4190, 2984, 9549, 1213, 3930, 3900, 1434, 203, 4533, 3420, 2418, 4717, 6254, 2655, 4872, 1075, 4050, 1844, 1876, 4006, 7665, 1083, 342, 1867, 6917, 9434, 4931, 9435, 6829, 4927, 5, 2154, 4105, 4267, 9520, 4025, 5991, 5370, 1922, 2661, 1097, 3227, 4732, 5014, 4110, 3741, 5550, 5553, 2524, 1358, 6375, 9438, 907, 2273, 5156, 5453, 6231, 1836, 3894, 772, 5535, 4603, 5689, 4232, 2529, 2693, 3143, 1424, 5208, 6192, 6948, 345, 3673, 3430, 1834, 2822, 9499, 2553, 3268, 4249, 3419, 5893, 4859, 267, 4036, 3354, 4169, 4035, 5544, 6125, 329, 314, 5552, 2725, 3433, 5794, 1008, 1236, 2706, 2228, 3809, 4972, 3651, 3237, 3546, 3765, 4729, 8449, 2576, 2827, 1011, 2816, 8682, 4138, 6961, 7063, 7344, 8113, 5848, 6232, 9143, 4524, 5666, 5590, 6092, 8549, 8636, 964, 4564, 378, 37, 3784, 5637, 1934, 40, 176, 3851, 3974, 4864, 4646, 809, 1040, 2786, 2245, 1038, 1368, 1189, 4977, 6913, 3669, 6408, 1179, 4806, 1835, 3532, 3777, 476, 1037, 1329, 2411, 9313, 4292, 1528, 143, 967, 1630, 1780, 7176, 3438, 1316, 1633, 9348, 3843, 2357, 5722, 5786, 6533, 537, 8740, 3638, 9994, 6928, 7353, 8850, 5186, 6868, 276, 1643, 6374, 5384, 5783, 3126, 9124, 3050, 3276, 5873, 9356, 7270, 3027, 5013, 8420, 6202, 2928, 8724, 9570, 7005, 4602, 5399, 5128, 5442, 7048, 7167, 6969, 6976, 8768, 8875, 6456, 8367, 5809, 7453, 7228, 8873, 7591, 6484, 4691, 5254, 5762, 3652, 6320, 7014, 749, 4719, 1030, 2137, 3380, 1555, 4670, 7424, 228, 4409, 5232, 7000, 824, 2974, 6329, 6604, 5318, 8758, 6430, 8672, 8745, 6222, 8600, 8443, 9844, 850, 9120, 7395, 836, 1025, 4687, 2359, 9602, 388, 7191, 7123, 2704, 4450, 2051, 5281, 5361, 7171, 8862, 6720, 7944, 473, 3761, 7527, 9407, 3019, 4597, 7626, 2626, 8666, 949, 135, 7561, 2283, 1715, 455, 3203, 4328, 5872, 7340, 2379, 4181, 7717, 1483, 2878, 5148, 5732, 6540, 348, 430, 1582, 3253, 7722, 2239, 4428, 3625, 2788, 3434, 4764, 3003, 5811, 8427, 8720, 8799, 7969, 767, 929, 1704, 196, 4386, 1994, 506, 1305, 4104, 4754, 7019, 202, 745, 3097, 6680, 9802, 9810, 8390, 5490, 9836, 9878, 9896, 8159, 9030, 9950, 5166, 6670, 8938, 9969, 8809, 7226, 8187, 7567, 7223, 3983, 7411, 4580, 6308, 5460, 7708, 7023, 5005, 9838, 5431, 8005, 1257, 4606, 4932, 5052, 5477, 6678, 9845, 5406, 2746, 4303, 9737, 848, 1646, 7165, 5461, 8432, 6482, 7091, 6276, 9705, 8914, 9898, 3733, 9715, 5025, 7442, 6438, 5036, 5072, 5291, 6726, 9593, 7150, 7399, 8340, 2261, 7600, 1129, 5044, 8418, 8692, 8776, 1820, 5112, 6472, 6789, 9485, 7418, 5258, 8261, 7832, 5323, 9846, 6601, 1515, 2590, 6141, 9760, 5081, 9931, 831, 8708, 1657, 1791, 4588, 4595, 9096, 4005, 7325, 2416, 4516, 2982, 2015, 9274, 4869, 9140, 6702, 7658, 9518, 6683, 4655, 2324, 9090, 7373, 7980, 377, 393, 1054, 5113, 9946, 5499, 4032, 3922, 6310, 3745, 979, 6058, 5132, 5486, 6729, 6445, 5327, 6502, 6468, 7556, 6515, 8166, 8118, 9121, 5630, 1351, 1548, 1201, 2017, 7725, 145, 2013, 4847, 2171, 2674, 3582, 2722, 755, 4074, 2010, 4170, 5970, 6233, 4949, 137, 1945, 4917, 2950, 3990, 4262, 6644, 1603, 3866, 6060, 5933, 6012, 6044, 5953, 2612, 3786, 4077, 2302, 3255, 9682, 39, 7582, 8252, 2235, 6545, 74, 1674, 4563, 350, 2136, 4538, 8536, 8543, 8545, 640, 8540, 5978, 6008, 3014, 8344, 3124, 8219, 3196, 4337, 1019, 7661, 3452, 3039, 5314, 8396, 6239, 5227, 354, 7463, 8819, 8887, 8986, 8995, 9725, 9774, 8306, 8930, 8971, 9923, 8988, 8976, 1004, 1861, 3259, 7480, 1939, 1139, 8100, 7319, 224, 4318, 31, 2071, 8559, 3649, 5252, 3852, 6712, 6622, 1027, 9489, 5759, 9641, 6159, 8048, 8488, 3606, 4021, 9378, 5646, 963, 5350, 7517, 4853, 9081, 1318, 3264, 3605, 2175, 6135, 8715, 7232, 2366, 8086, 9984, 1884, 89, 8729, 2166, 7138, 988, 8289, 9689, 6278, 6527, 7973, 8892, 9509, 29, 8633, 5316, 3231, 3747, 4984, 4168, 5984, 9674, 189, 4909, 1707, 2504, 8099, 3937, 3593, 9876, 9848, 9819, 6757, 7881, 7173, 8360, 8905, 8078, 9171, 6751, 6162, 4877, 5416, 6108, 1211, 8980, 9799, 9978, 6556, 5092, 8045, 8090, 8088, 6618, 2789, 7563, 7581, 9180, 9772, 9796, 9956, 7217, 798, 4903, 6673, 7507, 2885, 5839, 2599, 5566, 1766, 2676, 9049, 2803, 5998, 3353, 5614, 6506, 4778, 3092, 6748, 8922, 9039, 3214, 2277, 8538, 584, 3175, 1302, 6110, 288, 1760, 700, 3464, 3211, 1214, 5271, 5738, 7053, 1729, 6623, 777, 8526, 409, 3480, 790, 4216, 8575, 2943, 7253, 6063, 6073, 8058, 9155, 1673, 8138, 9591, 191, 9556, 3351, 7247, 3244, 6356, 9903, 8239, 1136, 696, 4147, 14, 2510, 5588, 5831, 480, 4674, 6005, 2276, 4491, 8459, 4930, 2719, 4733, 9388, 4589, 4171, 5594, 7638, 7405, 5090, 840, 3471, 8352, 5203, 3925, 7422, 8979, 9241, 9258, 8268, 8324, 9649, 8303, 8305, 9222, 6652, 9002, 9003, 9955, 8231, 6572, 9017, 96, 9599, 3099, 7890, 1785, 2902, 5943, 2027, 3586, 4643, 2343, 1397, 1988, 4574, 6083, 107, 8233, 9249, 9190, 8491, 2734, 3272, 8068, 5093, 7748, 7784, 2398, 1260, 8509, 9657, 9699, 251, 1900, 7911, 7847, 7856, 7916, 7920, 7869, 7900, 7928, 6758, 1667, 7954, 7468, 9912, 6628, 6661, 7608, 8286, 2815, 3026, 9645, 6733, 9200, 7262, 6743, 9233, 8164, 977, 716, 994, 46, 2221, 9661, 7802, 8022, 615, 4178, 3789, 9061, 9540, 4951, 7806, 2409, 9653, 2434, 5091, 1838, 94, 7839, 9005, 1993, 5661, 9795, 8469, 4759, 2258, 190, 7728, 7738, 7896, 7811, 7899, 6115, 8493, 7783, 7790, 4349, 3976, 3457, 818, 1909, 2825, 9112, 4185, 1885, 2753, 9025, 1691, 7990, 8229, 1240, 7934, 9594, 6101, 8244, 4886, 1500, 7822, 4308, 2135, 7812, 6688, 6694, 8004, 8376, 9622, 2705, 4924, 2355, 9643, 9071, 8128, 917, 1133, 2123, 5532, 5709, 175, 667, 2270, 2642, 8282, 7079, 7144, 7098, 4083, 5412, 5437, 5466, 8401, 1110, 1950, 6364, 6366, 4623, 9279, 9328, 6339, 9294, 9327, 6815, 6346, 5179, 8620, 2595, 3360, 8733, 3192, 4678, 2442, 7940, 7950, 3296, 34, 626, 6158, 5121, 6471, 2808, 3601, 471, 4936, 2473, 9051, 702, 2167, 413, 8786, 5465, 4322, 1721, 3423, 9957, 8202, 7189, 6208, 4697, 6017, 5114, 5310, 5317, 5180, 5240, 1216, 7912, 8641, 523, 113, 5707, 434, 788, 4663, 1964, 4009, 4143, 2196, 2755, 4424, 7634, 4184, 7697, 9292, 4843, 9144, 1005, 6376, 6401, 1165, 3041, 7322, 2443, 6916, 1668, 7288, 8506, 8590, 1998, 2014, 7616, 5565, 4610, 5388, 7347, 5587, 6936, 4835, 8782, 8593, 2792, 7008, 6420, 3008, 7318, 4436, 3693, 1013, 3538, 5627, 1647, 5414, 9362, 9299, 9386, 5447, 8700, 6214, 3889, 6221, 6190, 1881, 5375, 8690, 7382, 8028, 7496, 3798, 8839, 7298, 7964, 4884, 4101, 8784, 7962, 8680, 7707, 9497, 5315, 8017, 8053, 5813, 7827, 5424, 7360, 8705, 4901, 575, 6394, 9142, 598, 7278, 5645, 7786, 3478, 2926, 7336, 1825, 5575, 481, 862, 8001, 8751, 3711, 5130, 5073, 5705, 273, 3165, 1058, 3984, 6980, 7384, 8076, 8723, 9293, 9507, 3970, 4314, 9287, 1745, 5365, 7598, 3505, 2372, 2243, 7680, 2700, 1788, 116, 198, 757, 4519, 1816, 1264, 2683, 214, 8479, 7942, 8002, 8066, 4174, 8101, 7447, 4198, 8899, 3286, 3387, 9272, 4811, 5313, 2094, 3985, 1301, 4309, 8006, 370, 5663, 5903, 5688, 558, 3857, 7640, 2036, 4993, 2387, 4500, 859, 6377, 3878, 2622, 2538, 8642, 7760, 8350, 8678, 8698, 8833, 7230, 7238, 7260, 8717, 1366, 2484, 1773, 4699, 2946, 9612, 496, 3241, 5704, 2323, 2983, 1812, 2781, 4550, 4846, 3485, 3759, 9472, 6409, 4213, 3059, 262, 410, 4522, 2240, 9323, 1100, 6149, 6119, 1304, 4945, 5344, 5386, 2692, 4868, 7375, 8885, 4989, 3553, 5425, 6230, 1455, 7227, 6434, 6458, 6490, 6503, 6449, 6235, 1343, 5602, 5612, 6807, 7032, 1597, 4299, 6996, 1217, 2740, 3760, 3891, 7525, 7495, 1396, 7061, 2250, 7562, 9553, 4016, 9784, 7174, 7095, 7128, 5144, 7464, 2361, 2633, 8827, 7107, 9843, 7588, 7044, 7106, 5262, 7489, 7535, 9562, 9659, 1063, 5533, 6508, 8150, 7865, 3728, 4029, 2482, 6098, 3692, 6992, 9856, 7426, 8124, 5247, 9785, 2720, 5600, 4410, 5137, 1648, 2438, 4325, 7952, 2916, 9852, 4921, 7030, 8503, 8504, 3376, 3103, 2377, 6731, 5048, 5058, 8956, 9711, 9721, 9743, 7380, 8093, 8109, 4840, 5050, 5805, 651, 6079, 6164, 6069, 4539, 6089, 4089, 8475, 8480, 6147, 773, 12, 5671, 2019, 4752, 9467, 6411, 9153, 9165, 7682, 6946, 7594, 9825, 9357, 2477, 3842, 3874, 842, 1703, 7268, 900, 5746, 1776, 2890, 3467, 6496, 6778, 7746, 7769, 7807, 7799, 8762, 7118, 7377, 7357, 7557, 8897, 8953, 521, 4259, 1851, 5622, 1904, 2923, 4556, 4280, 6783, 1894, 3831, 5649, 966, 9580, 8146, 2456, 4648, 58, 5352, 5373, 4182, 5456, 4040, 1906, 4947, 5233, 111, 1741, 3872, 6443, 5022, 5029, 6318, 6487, 7592, 4975, 5080, 8781, 6436, 6524, 4919, 9571, 2964, 7513, 8207, 8334, 4073, 5745, 6967, 4747, 6858, 281, 2769, 7025, 9483, 2143, 8796, 6984, 17, 1369, 1592, 8497, 8510, 8525, 8084, 1809, 6242, 5190, 9963, 105, 4245, 7624, 1666, 1309, 2870, 1979, 2696, 874, 6787, 8846, 8906, 6247, 321, 7892, 1270, 8883, 8436, 3303, 5071, 3666, 8403, 417, 9573, 3378, 8736, 1244, 9054, 7439, 9640, 65, 774, 931, 4893, 1275, 1735, 264, 2320, 3490, 6021, 4665, 376, 4194, 1571, 2447, 8815, 7863, 1901, 593, 4644, 5580, 8534, 7744, 7825, 7734, 7852, 7861, 7915, 7924, 7902, 7903, 7754, 7796, 7908, 8959, 1105, 8935, 9170, 4047, 6520, 4130, 3561, 4316, 5429, 6576, 6269, 4030, 1596, 422, 9397, 3950, 2493, 6648, 6663, 8190, 6684, 6653, 756, 2373, 2537, 7267, 3425, 8623, 8663, 19, 275, 4414, 1323, 1552, 1864, 2046, 4024, 5774, 2012, 4258, 9333, 3247, 3366, 3495, 5178, 7704, 6362, 2806, 2402, 4172, 2206, 7662, 9473, 5274, 2615, 6974, 7833, 2819, 6536, 6251, 5345, 8829, 9320, 8378, 6941, 953, 2307, 6626, 908, 4803, 9960, 9972, 7101, 6696, 765, 1680, 3551, 1542, 5169, 9530, 7416, 7445, 7490, 7504, 8144, 3580, 2472, 6986, 7085, 7125, 1111, 8879, 9987, 8861, 3700, 6295, 6271, 5362, 9683, 3463, 6647, 7813, 7991, 8313, 2407, 519, 1929, 3938, 8977, 8900, 8054, 6708, 7149, 4815, 8044, 928, 1821, 3075, 4700, 962, 20, 2973, 3418, 3356, 4955, 4730, 7695, 6919, 8817, 8203, 9979, 9242, 1080, 1862, 1140, 7696, 9284, 1306, 1230, 9344, 9406, 3607, 3726, 6393, 1452, 3730, 8734, 5393, 8832, 389, 6954, 9567, 6451, 8136, 852, 5527, 5537, 2968, 4772, 6427, 8033, 6859, 9909, 6931, 6983, 7177, 7487, 41, 1815, 4507, 1122, 3236, 7081, 5654, 5002, 5491, 7148, 9992, 8893, 8841, 2104, 2317, 4715, 4426, 1544, 4199, 5026, 2507, 4530, 9300, 9302, 2147, 5289, 3111, 4129, 6200, 3034, 3526, 5919, 5560, 2966, 8596, 619, 83, 5640, 6380, 9451, 676, 6888, 7459, 1183, 6998, 1532, 6249, 4988, 1015, 3429, 4567, 5027, 7102, 2278, 3155, 7766, 8428, 4483, 589, 4405, 5781, 3529, 7837, 2494, 1695, 9539, 560, 118, 7652, 2212, 3392, 5868, 3426, 1872, 9466, 5657, 9884, 1403, 3060, 3881, 5730, 7795, 7828, 9929, 3249, 6185, 8775, 426, 7499, 9534, 4324, 9350, 322, 4502, 954, 6910, 2089, 6039, 1869, 9319, 5971, 5333, 5790, 662, 2173, 1222, 8770, 2401, 8754, 5004, 2330, 7669, 9152, 78, 7145, 9608, 2578, 2585, 4799, 6895, 6914, 9196, 9262, 5869, 5908, 6422, 6256, 5582, 6905, 5151, 9353, 6589, 1949, 9188, 9218, 3101, 9566, 6934, 7199, 5837, 8962, 579, 4119, 1439, 3005, 8356, 555, 1057, 7009, 5312, 8395, 5440, 5448, 8155, 6265, 8886, 8222, 1580, 4514, 5047, 6951, 5076, 9822, 5101, 5096, 5032, 8917, 5084, 7047, 8039, 8945, 7076, 9922, 7201, 8993, 9208, 4396, 8131, 5404, 3758, 4976, 8589, 8613, 8577, 8582, 2888, 4407, 3169, 2544, 4417, 7069, 7614, 1665, 99, 8052, 1714, 4786, 7224, 9638, 2310, 3338, 3472, 6640, 6666, 6674, 2875, 6887, 1631, 5279, 6335, 9419, 6363, 8898, 9805, 660, 3915, 4332, 4590, 6671, 6682, 9515, 2694, 7700, 8640, 5063, 7560, 6999, 7033, 6990, 6997, 4272, 6000, 6055, 678, 16, 9250, 5100, 5106, 7136, 9973, 5260, 8947, 8989, 8961, 8960, 8317, 3451, 2336, 7589, 3503, 484, 5175, 5200, 6903, 7947, 8797, 8836, 733, 1081, 5683, 6870, 5164, 1385, 6367, 9347, 5219, 1322, 3369, 1437, 1595, 2474, 8106, 8398, 7571, 5914, 4865, 7584, 7757, 9919, 9384, 5894, 3149, 252, 4916, 7028, 4369, 6568, 7423, 6516, 8220, 7045, 9708, 9718, 9789, 4467, 6679, 2202, 7083, 1090, 1429, 3188, 6105, 902, 3233, 4918, 7931, 2024, 170, 6220, 2858, 3054, 9551, 2771, 1992, 6606, 8767, 6263, 4598, 8176, 3927, 5856, 557, 9644, 8882, 5261, 4460, 1206, 8250, 5104, 5123, 1163, 4609, 415, 8110, 7137, 5042, 8422, 1634, 4297, 2274, 4358, 1326, 7432, 2265, 6369, 108, 4214, 1875, 2570, 6944, 6656, 7966, 5322, 6284, 6585, 8812, 3332, 2605, 3025, 3865, 8358, 2841, 1980, 8631, 2223, 2306, 7056, 7366, 9257, 9788, 9731, 9781, 2603, 5975, 282, 1453, 825, 5070, 7169, 7957, 4673, 605, 1342, 2499, 5517, 7043, 5238, 1787, 2685, 9089, 4479, 3594, 4938, 5597, 5607, 5631, 5720, 5698, 5023, 7759, 7316, 9447, 8807, 4910, 4683, 3405, 9211, 9183, 2666, 3200, 832, 73, 7756, 1606, 5512, 5549, 5551, 1786, 3194, 5871, 5714, 320, 3208, 853, 2480, 2577, 2007, 8030, 3589, 4793, 42, 7341, 4578, 2216, 8537, 9094, 9093, 220, 5610, 771, 3161, 4900, 7204, 639, 2244, 8941, 1554, 5205, 9186, 44, 112, 3283, 7692, 734, 614, 3104, 3177, 7675, 9283, 1763, 2647, 669, 7690, 3825, 213, 4796, 616, 8519, 2453, 1157, 6867, 6396, 1614, 9713, 9723, 7219, 337, 4706, 1566, 139, 2818, 6791, 7641, 5055, 2076, 3715, 2857, 5060, 8994, 8949, 3598, 815, 8451, 927, 2634, 2712, 3528, 5346, 5330, 8811, 8860, 8876, 2303, 6982, 8910, 8856, 8801, 1608, 1742, 4714, 8864, 5508, 8903, 5625, 8703, 2555, 9432, 70, 880, 2736, 231, 2232, 9829, 169, 1077, 2218, 2898, 4431, 1701, 5239, 3086, 6827, 9285, 7651, 3006, 2565, 1873, 706, 2934, 1449, 1622, 3709, 4682, 3992, 2313, 4095, 6019, 7236, 8230, 4242, 758, 7206, 5664, 150, 968, 1000, 2368, 3676, 8713, 8402, 7041, 4201, 1743, 2088, 2257, 5523, 4319, 3190, 7320, 6710, 1062, 2345, 2549, 2931, 7272, 7350, 2566, 4106, 7157, 7065, 7103, 2776, 7801, 5246, 740, 1103, 599, 3109, 3667, 6632, 571, 1920, 1159, 9728, 9766, 1255, 7071, 7089, 2843, 6188, 7836, 7972, 9668, 3796, 7292, 2992, 3049, 4613, 6956, 5925, 8455, 9701, 8773, 238, 6865, 8675, 8695, 6890, 1599, 6313, 8685, 3686, 8319, 3647, 3720, 5172, 759, 5182, 5672, 6539, 6433, 6448, 6488, 7984, 6474, 6441, 6452, 890, 8227, 8998, 9214, 497, 2344, 6577, 5299, 8955, 9028, 2624, 3897, 8465, 9486, 1508, 9376, 7995, 1522, 292, 8790, 141, 122, 5939, 5959, 6050, 6054, 5773, 6006, 6048, 9495, 882, 2406, 2760, 6571, 2945, 6564, 1428, 8264, 511, 7533, 9248, 9212, 9773, 8387, 9771, 3718, 5753, 5039, 7834, 7982, 683, 9881, 865, 1539, 6882, 1913, 1095, 3390, 6811, 2364, 6857, 6862, 6918, 6863, 6873, 9275, 9305, 2083, 3363, 3936, 4107, 4856, 50, 4209, 9149, 4132, 9148, 5296, 2677, 6639, 743, 3159, 4649, 3972, 1151, 2079, 1888, 1250, 4413, 4704, 4898, 1478, 1943, 3398, 4037, 1688, 3442, 4243, 91, 392, 4926, 2458, 2483, 1578, 5354, 9343, 5665, 6033, 1602, 9334, 3209, 623, 6707, 2026, 5010, 7585, 8814, 7532, 2846, 3395, 4908, 3362, 6261, 6933, 8779, 5276, 6252, 9531, 8848, 6966, 7389, 5286, 6987, 8083, 8042, 7939, 3187, 5034, 8399, 8828, 8888, 8896, 8852, 5484, 5788, 7295, 7314, 5591, 8831, 7039, 7110, 6283, 7285, 7335, 7576, 7548, 7331, 1632, 7113, 8368, 8687, 9058, 4591, 6717, 7166, 9053, 7358, 5378, 7159, 7880, 7122, 8377, 6943, 7546, 7547, 7343, 1400, 3391, 5793, 6229, 7158, 7310, 5391, 7949, 9961, 6187, 8018, 7078, 8789, 8677, 3545, 8884, 6315, 6218, 2465, 9424, 8937, 5743, 1387, 2759, 1577, 9269, 2486, 7670, 9312, 4336, 5213, 5303, 5511, 7540, 3554, 814, 9127, 4347, 2947, 2732, 4599, 5920, 4252, 5853, 5901, 7275, 5396, 5886, 5819, 3403, 4512, 1937, 2367, 3931, 4832, 286, 2469, 2737, 4980, 8644, 1905, 4787, 7346, 7058, 8769, 8804, 2562, 4897, 7596, 1990, 6334, 6298, 7387, 4565, 5357, 3886, 1373, 9589, 9598, 594, 600, 1858, 8546, 6207, 8990, 8997, 6509, 8446, 2388, 5171, 8024, 3560, 9555, 4488, 5989, 7105, 8697, 9361, 3979, 1974, 2428, 3156, 9908, 9938, 9383, 4412, 8041, 7172, 8433, 8385, 8423, 3688, 3135, 6900, 1196, 6922, 534, 5304, 439, 769, 3424, 7209, 9815, 1685, 3018, 6078, 3602, 7787, 6167, 7758, 8474, 9178, 7970, 3428, 688, 3908, 8380, 4607, 457, 2651, 1579, 7210, 1626, 7017, 8478, 5131, 5332, 4394, 9437, 8732, 7305, 6630, 3382, 9989, 9195, 9185, 7050, 8901, 9207, 7768, 2000, 6122, 7753, 7438, 499, 8967, 6104, 7792, 5834, 8771, 8869, 1916, 1818, 3118, 5383, 5693, 6804, 5681, 6029, 5715, 1420, 2156, 6479, 5341, 1491, 8040, 9568, 8499, 568, 4019, 8760, 5161, 5218, 5235, 6549, 6258, 6550, 3304, 3617, 7549, 9833, 9355, 5770, 5994, 6667, 1475, 1593, 6605, 3690, 2383, 6031, 650, 5810, 4875, 6094, 9091, 2532, 5411, 5501, 5467, 5497, 8890, 9122, 7239, 6301, 6387, 3218, 724, 1085, 942, 1662, 1307, 9529, 4446, 6824, 5230, 5702, 5712, 9514, 9454, 5619, 2360, 6355, 7684, 9403, 2331, 1296, 4579, 27, 3793, 379, 4576, 1963, 6197, 7042, 8968, 760, 8670, 5297, 8248, 3168, 6883, 7273, 4293, 3487, 9332, 9363, 9474, 5796, 9365, 9255, 336, 6303, 4221, 4791, 943, 3252, 2199, 1886, 3800, 1311, 1456, 3121, 5898, 833, 550, 562, 1088, 3701, 316, 1344, 8064, 8904, 9684, 9374, 5126, 9974, 9813, 9871, 248, 541, 7611, 7629, 5202, 4721, 729, 1181, 4633, 976, 9252, 9740, 9741, 7512, 9997, 8931, 9918, 2958, 4586, 1417, 1738, 3411, 1587, 7258, 8484, 9151, 1435, 3861, 4994, 4053, 8274, 2580, 3141, 3978, 7116, 9966, 987, 7579, 3504, 9554, 4125, 7415, 6988, 454, 8583, 8240, 9842, 2120, 7361, 7332, 1951, 217, 4211, 855, 8516, 8517, 7761, 8369, 5380, 7121, 7094, 8441, 3518, 4790, 2210, 4695, 7764, 2426, 9862, 386, 2066, 49, 7621, 9276, 9453, 3278, 6325, 2165, 3066, 1887, 9692, 125, 2673, 414, 530, 2049, 2917, 1512, 2812, 940, 3331, 4022, 986, 2831, 1831, 7186, 1380, 4, 4490, 7653, 3924, 138, 6350, 8674, 9986, 8557, 5421, 8616, 3017, 5242, 607, 2468, 6846, 4466, 4557, 3036, 2497, 3427, 4983, 1852, 8533, 2205, 1055, 2681, 4928, 9889, 6237, 7443, 9366, 9426, 9364, 3684, 3751, 1327, 1481, 4235, 9733, 159, 1242, 3920, 8542, 206, 4134, 3491, 3999, 565, 81, 2097, 3991, 3923, 2672, 5009, 5135, 1921, 4192, 4837, 2189, 2220, 6302, 2883, 1953, 4836, 7242, 689, 7246, 8298, 4821, 6143, 6175, 7937, 8051, 3722, 7657, 959, 8842, 8626, 9804, 6876, 3967, 3653, 8664, 4200, 4224, 2281, 2840, 4215, 9469, 1557, 9835, 3557, 4468, 5599, 4240, 5968, 6022, 1347, 5670, 8662, 9423, 9582, 2993, 999, 573, 808, 6821, 9034, 1043, 140, 3365, 2117, 6812, 6915, 5441, 9373, 6365, 8471, 8706, 6875, 3476, 5503, 8920, 8188, 2414, 5382, 6801, 6840, 6730, 6741, 2979, 4335, 331, 4038, 4625, 1409, 2374, 3696, 3151, 6817, 79, 359, 8494, 1537, 6660, 6687, 6689, 7421, 3107, 4379, 624, 9880, 1644, 2197, 1837, 1547, 5311, 8309, 2424, 4437, 9308, 5085, 6699, 2659, 9393, 8141, 2334, 227, 2530, 3571, 3160, 1274, 4929, 2665, 1486, 2845, 8371, 8750, 8605, 820, 5787, 4003, 6792, 8824, 9226, 9256, 1605, 2348, 3981, 9524, 3714, 9251, 5616, 7293, 4946, 6553, 2475, 5217, 2838, 8918, 304, 1002, 1711, 3514, 9803, 9820, 4385, 4456, 9082, 7243, 2018, 5949, 6007, 5992, 5988, 3402, 5287, 2985, 3977, 9392, 5269, 1725, 9517, 2448, 2082, 9067, 9164, 123, 197, 2863, 205, 2032, 7674, 3248, 1426, 2008, 3074, 5215, 7714, 4770, 334, 4288, 7458, 4244, 6570, 6593, 3292, 3166, 2961, 6624, 21, 4967, 463, 2901, 2022, 5660, 7580, 3262, 5360, 9084, 9102, 9458, 9064, 9278, 1586, 2978, 1607, 2533, 5546, 4605, 24, 3282, 5509, 3592, 2854, 8063, 8096, 8103, 6332, 8363, 2280, 3687, 3082, 9746, 4555, 4469, 26, 6854, 1173, 284, 3888, 3840, 2341, 4287, 913, 3287, 2181, 1501, 3791, 3096, 4027, 249, 1927, 4476, 4354, 3339, 306, 512, 2092, 3566, 3655, 6920, 6849, 3703, 6828, 363, 3301, 6810, 712, 748, 1767, 4783, 4745, 5559, 5263, 5068, 9735, 9792, 9738, 9906, 9764, 9783, 368, 3000, 3238, 1108, 6130, 8013, 75, 1059, 1042, 1798, 2522, 3407, 1985, 1099, 9632, 9658, 9665, 9678, 9981, 7522, 130, 5319, 5228, 2169, 1908, 4237, 1412, 4570, 6747, 6793, 1313, 2804, 4313, 2701, 3029, 9676, 300, 1465, 2432, 487, 906, 8944, 7254, 8933, 8928, 1436, 1744, 2471, 5928, 3076, 4537, 1418, 6370, 6381, 2709, 1442, 4581, 7140, 7311, 8701, 8070, 5476, 4217, 5956, 36, 867, 2625, 6820, 2652, 4402, 482, 8126, 1594, 6642, 5220, 3051, 7466, 3088, 5541, 76, 7477, 4141, 6907, 609, 4905, 7515, 5422, 2678, 2623, 1036, 4339, 2085, 2390, 4274, 1177, 3123, 6924, 4998, 3094, 6774, 3501, 5768, 1067, 3531, 2312, 3717, 5446, 697, 1130, 3910, 1503, 3622, 210, 6323, 630, 1086, 7574, 9915, 4813, 7456, 7488, 1045, 1098, 4664, 6551, 1205, 4366, 5700, 2340, 548, 384, 8211, 8148, 8133, 8177, 5309, 6226, 834, 8555, 7778, 7816, 7182, 8189, 8235, 681, 4701, 4197, 68, 7936, 8485, 4659, 6771, 4377, 9069, 4851, 3388, 2263, 8489, 2227, 328, 5727, 2002, 115, 2892, 8069, 3670, 307, 1933, 574, 6855, 727, 4540, 6194, 6953, 1355, 6026, 2539, 680, 1382, 2528, 5826, 4861, 6861, 8709, 8059, 8079, 8210, 8302, 2255, 9882, 3541, 2645, 3085, 186, 6074, 6132, 1446, 7736, 6299, 1035, 2991, 6627, 9620, 9627, 9216, 4694, 7409, 60, 2091, 9113, 9172, 6575, 4234, 1516, 9916, 1496, 2314, 2671, 6637, 8287, 432, 2708, 4735, 5951, 5961, 6032, 6047, 622, 4046, 4964, 6930, 2249, 3568, 4661, 5195, 6326, 2823, 1150, 1797, 4008, 7959, 3716, 4489, 4746, 4794, 1134, 5585, 9445, 8167, 8777, 6382, 8215, 8916, 9581, 7312, 8393, 8411, 163, 4229, 722, 3234, 4042, 5758, 8984, 310, 8121, 8755, 3475, 6579, 6002, 5335, 4553, 2420, 4257, 4481, 472, 6399, 7038, 3129, 8694, 280, 4961, 891, 1817, 3128, 5266, 1237, 1423, 2998, 5015, 971, 1975, 517, 699, 4647, 5356, 1336, 9077, 9087, 5792, 1832, 7681, 3333, 566, 9886, 6565, 6610, 4183, 6353, 9166, 6563, 6831, 6995, 7194, 7429, 7024, 7394, 4283, 92, 7864, 6695, 5884, 3469, 3916, 6371, 6379, 9100, 3273, 3062, 9416, 9169, 4311, 2654, 3055, 4454, 1553, 7282, 1243, 3377, 3672, 5577, 2547, 3349, 2628, 3061, 4225, 703, 4443, 9767, 4805, 5620, 2028, 3277, 1472, 1628, 295, 5946, 5986, 5969, 6037, 881, 3235, 4680, 9734, 9765, 8610, 6569, 2446, 4939, 4484, 3600, 5536, 171, 6762, 2907, 1215, 9637, 2782, 5747, 7104, 2795, 508, 870, 1153, 4952, 2116, 4566, 9066, 9138, 2508, 2138, 3136, 3838, 4423, 1804, 4818, 9429, 9460, 5214, 4758, 5395, 7985, 3713, 256, 2296, 2242, 2157, 5924, 5921, 673, 9927, 9044, 3486, 5444, 9977, 1091, 323, 9872, 7427, 9204, 9650, 3232, 1212, 3344, 1116, 1519, 1690, 8925, 5185, 4238, 4969, 551, 2866, 3302, 6926, 5293, 5329, 4128, 166, 532, 1142, 3523, 6547, 1290, 2174, 3432, 4740, 4277, 3184, 4798, 3550, 6273, 6475, 9861, 8802, 7408, 3762, 7906, 4593, 8854, 8520, 9408, 2884, 5719, 753, 8014, 420, 3671, 7523, 686, 1661, 4795, 2025, 1581, 8184, 9198, 9254, 9769, 9206, 634, 4122, 9404, 3397, 670, 7402, 8280, 9232, 8312, 308, 2063, 2433, 9690, 5906, 6088, 9808, 488, 3616, 8347, 8314, 216, 4600, 2872, 1266, 8191, 6727, 8523, 2639, 6822, 2498, 7153, 161, 5358, 2191, 9076, 3477, 9537, 8461, 1683, 5764, 9505, 7068, 2750, 3254, 4063, 3131, 4660, 5691, 3725, 1561, 3497, 4421, 4291, 7425, 2230, 88, 2743, 8288, 2130, 2886, 4912, 2160, 5116, 7152, 6718, 7874, 3579, 8483, 398, 2613, 843, 3357, 3819, 3500, 80, 3498, 131, 382, 6784, 235, 893, 7510, 9646, 8370, 1282, 1024, 687, 2583, 3010, 3015, 3484, 2514, 1172, 8265, 1292, 2860, 8011, 5728, 1981, 4474, 7451, 8408, 212, 2412, 7471, 9610, 7179, 2876, 5999, 816, 9168, 4755, 885, 4769, 9147, 339, 7132, 1750, 9625, 1186, 2833, 5923, 2680, 8599, 4838, 2259, 2148, 185, 9431, 1480, 9104, 7404, 925, 1284, 2020, 1655, 4639, 5159, 5842, 6152, 8511, 1724, 8434, 6195, 9866, 4088, 2286, 4333, 6417, 5927, 5858, 3437, 1971, 2620, 7530, 1497, 1966, 2125, 7673, 9047, 1265, 2427, 3507, 250, 8472, 4425, 2796, 7854, 7867, 7895, 7884, 2548, 7441, 5538, 2489, 2762, 7631, 1277, 8647, 6582, 3535, 6512, 8500, 1771, 3904, 1824, 3298, 1658, 4099, 8008, 8043, 6034, 5149, 6724, 789, 5181, 5904, 1805, 707, 7066, 7092, 7096, 8743, 7741, 62, 770, 5817, 5822, 3137, 8355, 8400, 8281, 5017, 8467, 3996, 9021, 4382, 7520, 8269, 2631, 4966, 7645, 5655, 861, 1681, 535, 9471, 1012, 6599, 8792, 9086, 2070, 3195, 3258, 4158, 1413, 4001, 1167, 274, 4705, 2735, 3038, 668, 8383, 1849, 9592, 3327, 7550, 5097, 9546, 5245, 9558, 7461, 6777, 4160, 8744, 6994, 8073, 7975, 9146, 56, 6896, 1279, 2977, 4981, 6608, 6596, 1477, 230, 340, 4532, 5860, 1792, 8328, 4963, 6658, 635, 3207, 3318, 6756, 2941, 2889, 5191, 1192, 2523, 9587, 9839, 1386, 8926, 9000, 9660, 5525, 910, 3610, 9579, 127, 2207, 8783, 129, 4892, 2798, 375, 5451, 1041, 9590, 6537, 8855, 5480, 3814, 8813, 8909, 8987, 5624, 6368, 8834, 6415, 2554, 6095, 6120, 7808, 6142, 7974, 6148, 7988, 8142, 8415, 8180, 261, 1135, 3960, 9671, 4312, 9616, 9877, 4152, 2078, 5658, 8878, 8964, 6486, 6491, 6236, 9184, 2241, 356, 5351, 6196, 4067, 1693, 9298, 5325, 9360, 3797, 7997, 2772, 2957, 9907, 5056, 5083, 2969, 6611, 8948, 7474, 8982, 9626, 9651, 8132, 4302, 6716, 9234, 6952, 7521, 7541, 7542, 7578, 7531, 7577, 9754, 9606, 9675, 8170, 8232, 7996, 7583, 7826, 9228, 8158, 7195, 8444, 7187, 4577, 9194, 9709, 7859, 7918, 9685, 8445, 7264, 8847, 9747, 6620, 8122, 9035, 5111, 8331, 5134, 6775, 7454, 3595, 7414, 9702, 7057, 9584, 8275, 2644, 9428, 3113, 9600, 5102, 8696, 6530, 7155, 7077, 3335, 7870, 7241, 9315, 6884, 7809, 1629, 3590, 5632, 4583, 5170, 8774, 3623, 5400, 8940, 6476, 6500, 6518, 7108, 7160, 7134, 7142, 9290, 9545, 857, 3952, 3470, 1082, 5020, 1637, 7274, 7351, 7352, 7294, 5229, 5633, 7306, 7397, 8676, 8686, 8737, 8761, 8702, 8710, 8747, 2525, 7284, 2103, 7178, 2909, 3127, 9892, 8214, 3556, 6965, 7067, 4266, 1513, 4109, 4004, 3527, 9607, 5439, 4485, 7689, 3880, 4863, 8756, 1126, 1540, 8080, 3078, 5900, 4911, 4480, 8840, 1048, 2481, 1330, 3404, 4408, 4560, 3460, 1367, 6847, 103, 3280, 643, 4827, 5617, 9541, 9932, 6483, 752, 1652, 4060, 6205, 9821, 9999, 3787, 7804, 7831, 8716, 7750, 7771, 8753, 5355, 201, 5481, 3850, 144, 7885, 7976, 9224, 3564, 9858, 2835, 4535, 1168, 4529, 2487, 2581, 4520, 3570, 3907, 394, 174, 3508, 7345, 7348, 7271, 5639, 1335, 7473, 1158, 5294, 5816, 1066, 2441, 4509, 9033, 6413, 59, 1479, 2865, 7726, 822, 4767, 577, 3824, 1317, 3150, 2690, 3896, 4352, 7055, 4058, 1384, 8429, 193, 8757, 6538, 8580, 8622, 1649, 315, 7494, 7891, 4435, 8739, 8237, 1383, 2813, 2594, 3443, 6463, 8996, 7020, 134, 563, 4850, 4707, 3845, 5489, 6248, 6275, 6209, 1651, 7383, 6245, 3340, 3704, 7004, 9934, 8585, 8649, 9420, 8618, 5433, 6219, 7455, 3588, 3868, 5478, 5061, 5423, 1719, 7663, 7313, 7369, 3633, 6296, 1287, 5403, 3163, 5438, 9824, 9681, 6612, 961, 7060, 401, 2856, 7339, 7109, 8556, 8609, 7765, 8759, 3279, 6212, 5462, 1443, 3374, 5875, 4744, 621, 1007, 2038, 3002, 9827, 5434, 2608, 4389, 4726, 3064, 2895, 7080, 7126, 8934, 7146, 8147, 8919, 5376, 8046, 1286, 2121, 2246, 4849, 9834, 9863, 9854, 9857, 4251, 9875, 8627, 7428, 1029, 1353, 8635, 6958, 7164, 7114, 6145, 9807, 1687, 5300, 5343, 5306, 5387, 7127, 2862, 2949, 5729, 3091, 4777, 9322, 5881, 7615, 470, 4362, 8667, 693, 3313, 6189, 805, 5041, 9920, 5129, 5710, 2614, 7770, 7755, 4092, 613, 2640, 2783, 9855, 9874, 4753, 6578, 458, 8574, 3707, 4797, 5589, 4371, 7046, 7481, 7500, 709, 7961, 2667, 7767, 5905, 1389, 8689, 5059, 2650, 1572, 8065, 8075, 8105, 456, 2429, 3785, 4451, 3748, 2054, 2691, 3905, 4496, 3732, 6788, 7240, 8412, 1018, 374, 793, 1371, 6838, 5864, 4372, 2349, 6850, 2809, 9418, 4210, 4585, 7437, 4965, 4071, 361, 6354, 9461, 6881, 1123, 6406, 4388, 2980, 6842, 6128, 2321, 4722, 2362, 3739, 9758, 9812, 9828, 1405, 4472, 4866, 1349, 2848, 4471, 3890, 9776, 7304, 1113, 7036, 6257, 5735, 4203, 5690, 6613, 6814, 9317, 4148, 5160, 5196, 5197, 4276, 164, 1106, 2602, 4549, 4725, 4127, 4247, 9538, 317, 4346, 6136, 9998, 9260, 1928, 7620, 6685, 5963, 7498, 9970, 9261, 5007, 5030, 2509, 533, 7660, 4812, 868, 3661, 4401, 1155, 2741, 3775, 7281, 1795, 2682, 5374, 6244, 9117, 8473, 6270, 3837, 3619, 6206, 6215, 2090, 3654, 572, 872, 9173, 6889, 8661, 6904, 8297, 9449, 8725, 8726, 718, 2579, 1225, 2451, 6972, 9462, 2131, 3030, 960, 5557, 5863, 6210, 9441, 1840, 2069, 1997, 8581, 3869, 4860, 8291, 7552, 9210, 6816, 9307, 4619, 2053, 1249, 3934, 8566, 6522, 827, 4627, 3224, 5855, 1883, 4693, 6268, 6300, 1495, 3167, 2689, 973, 8316, 8299, 7733, 7897, 7188, 6440, 7551, 7554, 6453, 1056, 5192, 1239, 1208, 5766, 9544, 6294, 5926, 93, 450, 5264, 4081, 501, 1308, 3459, 3483, 32, 7656, 5000, 657, 5606, 2128, 3642, 1278, 8780, 4973, 4220, 8032, 7719, 4164, 7639, 500, 442, 1803, 3499, 435, 4731, 4640, 3833, 3197, 5474, 4373, 4587, 6134, 2617, 1432, 3180, 9118, 9928, 2285, 283, 692, 1473, 1550, 4810, 3955, 9349, 1789, 1328, 7851, 7860, 7914, 7929, 1531, 2559, 3056, 636, 6373, 828, 9849, 4546, 4666, 3585, 5028, 45, 253, 1146, 1752, 1860, 509, 1046, 3957, 4902, 9331, 5697, 1471, 2987, 2606, 7649, 6216, 6277, 8185, 5302, 1258, 739, 1755, 3372, 6291, 4844, 8653, 8578, 8645, 8656, 8652, 5885, 5852, 1833, 1902, 2913, 7676, 7715, 4340, 2077, 7315, 7324, 7388, 5807, 240, 397, 778, 4569, 1235, 1866, 2100, 1999, 3171, 4971, 5397, 6544, 5379, 7070, 5394, 7475, 2518, 4889, 5189, 2852, 162, 2346, 3053, 9065, 5295, 5275, 5347, 7965, 4551, 7326, 7829, 2124, 7090, 9830, 9841, 3299, 5740, 4544, 1779, 5854, 5861, 8270, 8823, 2457, 4422, 299, 1174, 1, 3047, 5515, 5521, 6800, 992, 4630, 4749, 2793, 4383, 4364, 335, 2799, 5579, 6600, 6638, 6262, 6573, 8464, 1639, 2897, 6435, 6442, 6457, 8927, 8965, 8985, 6595, 9042, 9187, 8942, 8963, 6493, 5349, 6485, 8932, 6467, 9213, 6477, 9321, 5608, 9354, 2903, 5648, 2658, 5850, 6087, 7819, 8507, 1498, 6714, 9617, 9583, 4222, 3106, 4180, 4997, 7391, 1078, 7642, 6802, 2491, 5454, 7798, 4696, 7679, 7698, 5348, 9890, 9891, 9, 3146, 5736, 2267, 5057, 5117, 5136, 6113, 5115, 5145, 8060, 8249, 9949, 1315, 1226, 3599, 1357, 9672, 1068, 109, 8954, 7776, 5662, 7051, 1636, 9605, 3028, 7958, 2134, 6650, 2309, 4738, 3350, 7743, 728, 741, 1431, 1839, 4427, 2397, 7200, 9630, 1769, 353, 4698, 30, 2731, 3659, 4782, 4167, 5892, 6514, 4906, 1232, 6243, 9669, 5742, 7006, 2853, 343, 6447, 8624, 8655, 9860, 1684, 9853, 5413, 3142, 2956, 9057, 408, 4751, 5339, 5389, 7435, 7484, 1065, 9402, 2095, 7610, 7628, 4375, 9523, 2908, 6459, 179, 2572, 3909, 3799, 8304, 2607, 4363, 4616, 167, 1952, 2158, 2003, 2994, 5916, 6102, 6138, 6144, 5578, 5284, 5726, 5021, 7372, 7393, 6964, 6823, 3658, 5074, 1783, 9618, 1093, 7277, 7302, 114, 1778, 428, 8224, 6597, 2718, 2354, 9041, 6942, 6464, 3410, 1845, 2279, 3926, 277, 1112, 6692, 6911, 811, 6064, 6123, 6507, 2933, 6935, 6985, 510, 3449, 9326, 9330, 452, 6552, 873, 3513, 6534, 2910, 5799, 165, 5518, 5510, 3093, 3678, 7612, 7622, 7630, 1144, 3929, 2180, 4338, 3275, 8665, 4828, 2924, 6631, 9901, 837, 1375, 6184, 7374, 7396, 6704, 8924, 9231, 8939, 7365, 7590, 7509, 7519, 7543, 7529, 9238, 7568, 9217, 9219, 9235, 9229, 8087, 8981, 3444, 1331, 5359, 6255, 6957, 5445, 5153, 3783, 244, 3887, 9271, 1653, 1871, 8102, 9832, 9561, 6772, 7131, 7436, 8276, 8329, 544, 9240, 4523, 7883, 3065, 2056, 1469, 8392, 2871, 8787, 887, 922, 4543, 8462, 146, 2744, 7666, 3877, 2921, 5911, 3663, 4233, 8803, 8247, 6649, 4541, 7010, 8349, 257, 915, 2520, 1664, 1694, 4165, 1702, 2208, 2989, 5173, 8410, 9410, 199, 6703, 8673, 8683, 6939, 2101, 1210, 2669, 8704, 8794, 1914, 5568, 531, 6592, 1709, 4802, 110, 2561, 1560, 6343, 3694, 6738, 5184, 5204, 5188, 5198, 5231, 7097, 9036, 9045, 781, 7720, 1686, 1502, 4478, 3519, 2430, 8452, 9098, 9074, 9099, 7503, 1363, 9109, 4136, 3110, 1958, 4444, 433, 5458, 2146, 1868, 2381, 1160, 1334, 3312, 2829, 1910, 1510, 3917, 1087, 3063, 7003, 4638, 5936, 3697, 1521, 5494, 950, 3153, 4124, 3240, 7218, 8699, 3675, 5392, 4263, 795, 100, 4416, 3081, 5487, 5377, 4334, 5516, 5558, 2716, 4097, 7983, 708, 2879, 182, 1879, 2064, 2030, 7297, 580, 1524, 3406, 3466, 3516, 6213, 1209, 6179, 3961, 160, 152, 6525, 6932, 1625, 4305, 7979, 8027, 7963, 8009, 2450, 2163, 7016, 2203, 2211, 4750, 2516, 3882, 3001, 8130, 8154, 2467, 2935, 8201, 8193, 451, 208, 7497, 8721, 2596, 8161, 6337, 3080, 6715, 8346, 3702, 3964, 2675, 2713, 9020, 1814, 2784, 3223, 418, 7147, 7163, 1132, 3415, 4684, 7935, 1245, 3048, 9266, 4189, 3012, 7143, 5336, 6204, 6260, 3885, 8406, 1072, 1490, 2511, 2350, 1598, 5711, 6186, 6282, 538, 914, 2119, 983, 1961, 3644, 9900, 5075, 3245, 5011, 9817, 9680, 9888, 90, 5328, 6289, 6013, 4290, 7099, 4207, 5285, 4411, 4545, 3552, 4934, 1613, 8778, 9679, 4823, 23, 3754, 985, 3621, 4925, 155, 47, 1138, 1965, 1583, 3324, 4845, 158, 2995, 6746, 7888, 978, 5802, 7120, 7151, 2111, 5507, 3510, 1677, 1023, 8816, 9744, 2820, 9548, 7216, 6317, 6327, 6404, 8209, 6336, 6776, 2200, 3250, 2550, 3492, 6001, 4822, 2551, 6615, 9532, 3007, 6228, 590, 2139, 2881, 5656, 5675, 602, 9475, 6899, 4420, 4996, 9945, 7333, 5845, 2662, 2981, 4296, 2086, 6312, 515, 5158, 5479, 8946, 7026, 3482, 5823, 2122, 1447, 8375, 8974, 3174, 7664, 9921, 1645, 2437, 8562, 1611, 632, 1451, 4326, 7986, 2311, 3274, 3105, 9304, 9318, 9351, 9341, 9303, 6541, 5772, 1281, 4196, 1600, 2629, 2045, 7644, 3947, 9059, 7379, 1241, 1754, 1976, 3995, 2586, 2832, 5779, 9135, 1283, 3201, 5272, 6183, 6193, 6225, 7007, 7012, 8915, 8746, 8800, 5282, 5366, 5292, 6246, 7327, 7022, 1931, 4031, 4052, 4341, 469, 1823, 3935, 9959, 3943, 4342, 5001, 8630, 9762, 6864, 2785, 1149, 4825, 6898, 4978, 3285, 2133, 4503, 2861, 1492, 601, 1324, 1474, 7450, 8806, 8866, 8877, 8894, 9516, 9557, 7407, 7431, 1207, 4445, 2282, 4330, 7403, 909, 5696, 9811, 5167, 5267, 2219, 3204, 3186, 4885, 1604, 8573, 5223, 2288, 8741, 448, 9778, 4954, 9465, 2342, 2849, 5226, 8437, 1493, 7413, 156, 1514, 4848, 4393, 4652, 7745, 7805, 5183, 7981, 8518, 4193, 1020, 3742, 2108, 3530, 2050, 5820, 9936, 7185, 4742, 2698, 4323, 3792, 1300, 858, 6989, 4895, 2021, 9289, 9588, 9870, 3863, 1635, 1115, 3631, 2386, 4771, 5019, 641, 7752, 7479, 9787, 9182, 2976, 5713, 8082, 4762, 9831, 1114, 211, 3914, 3956, 2582, 483, 1842, 2431, 6973, 8766, 9430, 6331, 4761, 947, 6851, 5741, 5780, 6991, 6806, 3587, 7283, 4817, 860, 1751, 446, 395, 9814, 838, 3370, 8404, 237, 2729, 4103, 6562, 5419, 5426, 6813, 8598, 7691, 2618, 8431, 3901, 2231, 4378, 6020, 4873, 9156, 6061, 5909, 5596, 4321, 9522, 9686, 1518, 2643, 9412, 177, 1026, 2225, 8354, 4596, 5364, 2702, 8579, 3822, 8554, 2754, 6908, 8366, 8020, 1912, 2327, 1591, 4026, 5278, 3884, 5065, 2152, 974, 1092, 5628, 4115, 5866, 2144, 5528, 2738, 6529, 737, 5221, 1152, 351, 9132, 7196, 5677, 7842, 7850, 1697, 5082, 797, 3682, 4142, 4492, 604, 9277, 4933, 6619, 7301, 627, 1727, 2080, 2256, 460, 4056, 1672, 2766, 3328, 5268, 5744, 775, 4621, 2112, 2699, 4135, 6977, 3336, 9533, 8108, 1482, 82, 5767, 4870, 2904, 732, 4779, 8668, 2039, 3603, 5609, 8454, 9504, 2352, 9306, 1917, 4915, 3468, 8463, 958, 5678, 3856, 2893, 4703, 3998, 4987, 8857, 1915, 7775, 5199, 1276, 172, 4710, 9043, 5562, 4094, 5174, 1983, 4501, 3261, 5542, 6535, 9536, 1229, 236, 423, 1890, 980, 4260, 4113, 9056, 2062, 7705, 1341, 3493, 9501, 3712, 8169, 8341, 9001, 875, 3133, 8912, 9722, 9748, 7170, 2715, 2150, 436, 8379, 9887, 3854, 4357, 4380, 2558, 5256, 2739, 9062, 628, 4584, 1675, 5118, 8597, 1585, 3656, 5972, 1588, 9040, 9050, 9793, 5877, 478, 8788, 369, 8259, 3808, 2500, 4592, 2584, 4442, 4883, 3399, 7197, 7329, 3, 10, 525, 424, 821, 1777, 3271, 13, 55, 136, 1619, 4353, 148, 441, 1739, 1261, 3215, 1294, 3959, 5721, 3310, 1504, 7703, 2899, 6892, 3805, 5592, 2226, 7037, 3903, 7367, 7368, 7506, 7727, 4404, 2942, 346, 4166, 7269, 1094, 2962, 6959, 1416, 6383, 5435, 5301, 3219, 644, 1723, 5342, 4241, 7625, 5337, 3325, 4631, 9414, 5513, 7607, 8576, 7702, 3512, 157, 1001, 4473, 2461, 1148, 3830, 3481, 2733, 2717, 3226, 2042, 312, 2764, 4675, 4227, 5505, 5353, 7688, 5280, 750, 981, 1517, 3371, 4935, 6280, 2707, 3052, 5659, 4542, 8127, 7225, 1565, 4457, 5818, 884, 2748, 9457, 2873, 6319, 4959, 4447, 3317, 2761, 2410, 4062, 1333, 3359, 5305, 6701, 6342, 5529, 1650, 1445, 6309, 567, 3496, 101, 586, 2236, 8587, 2657, 7699, 5930, 851, 9930, 2081, 4370, 3191, 3413, 5033, 6454, 7601, 7526, 7139, 7516, 6633, 7255, 8895, 7129, 9631, 7086, 8921, 7031, 7485, 5253, 7263, 5031, 8343, 7261, 6489, 5133, 7161, 2619, 3650, 6444, 5778, 8881, 2999, 5554, 564, 6808, 5321, 5368, 327, 1288, 1638, 3368, 6843, 5974, 6040, 4361, 3140, 4672, 2087, 7330, 8085, 7385, 7317, 6786, 8055, 485, 1231, 3306, 3581, 4365, 592, 2096, 6921, 4320, 6719, 5139, 5069, 5124, 7593, 8978, 8172, 6510, 3087, 3439, 6927, 8849, 5812, 6241, 8845, 7133, 7599, 7112, 8913, 8951, 8752, 1535, 6937, 2190, 6470, 6473, 8851, 9757, 7440, 9964, 854, 5079, 9952, 1533, 6201, 6293, 8730, 6288, 8858, 6478, 8731, 8772, 8748, 7203, 6766, 6779, 7566, 7882, 9221, 6795, 8795, 6752, 6968, 8681, 8765, 8764, 1195, 7646, 8614, 5109, 8818, 9911, 4462, 5684, 2403, 5531, 7289, 9519, 5865, 8763, 3445, 4070, 6833, 620, 5087, 9189, 5307, 794, 5483, 5463, 6211, 7655, 3210, 71, 9459, 3179, 5369, 2763, 6328, 2527, 2656, 871, 6770, 4958, 5290, 6925, 1121, 5827, 9826, 8221, 8338, 7342, 1188, 5398, 8671, 2506, 6181, 6287, 7221, 8137, 2592, 2777, 5899, 4278, 5526, 5141, 1764, 365, 3895, 2660, 4531, 6753, 6760, 4495, 7671, 1757, 2061, 5567, 2571, 4146, 4348, 192, 9761, 9763, 5652, 993, 7555, 3305, 2557, 4470, 271, 6877, 5929, 7279, 1972, 1297, 3265, 1713, 7337, 4186, 7052, 3032, 7062, 2067, 4824, 3090, 4720, 8808, 7168, 8992, 215, 1918, 6923, 3634, 4515, 8634, 1959, 3698, 4788, 5270, 5320, 7537, 2178, 704, 5519, 5890, 3640, 6286, 459, 2209, 2492, 8023, 7846, 7913, 28, 545, 1034, 294, 8611, 1907, 4090, 7706, 2988, 4642, 4780, 546, 8448, 3450, 3989, 6978, 9809, 9885, 9865, 7354, 3417, 2824, 6461, 7536, 4819, 6398, 5008, 9004, 9753, 7449, 8389, 5043, 5428, 9239, 6062, 6097, 6099, 6140, 7817, 7889, 6163, 7782, 8114, 5147, 5459, 6082, 7452, 8199, 8359, 9939, 8983, 7747, 7791, 7820, 9037, 8388, 8228, 8999, 246, 4992, 8548, 3735, 1408, 8283, 8342, 8373, 1762, 4887, 4080, 3695, 8629, 7084, 7162, 7558, 3243, 5259, 6259, 2794, 997, 8425, 1203, 6133, 6114, 7967, 7737, 7780, 7835, 6117, 6131, 1271, 2765, 4281, 5731, 8021, 9105, 9070, 7866, 7887, 7898, 3346, 6970, 2817, 7838, 9647, 2937, 3706, 1794, 4157, 5257, 8307, 7231, 1534, 6979, 9162, 1197, 6588, 9902, 6971, 8056, 972, 7953, 8117, 3584, 8619, 9367, 8991, 2714, 5584, 742, 9080, 4282, 5443, 9585, 661, 9436, 2954, 9663, 7465, 7873, 7810, 7987, 9223, 2649, 8029, 296, 4150, 3883, 9498, 9220, 9528, 6191, 1390, 4757, 8798, 9439, 701, 4527, 2944, 4776, 9552, 4804, 5806, 2376, 9801, 2204, 8414, 3322, 4448, 7072, 2384, 4857, 9739, 9791, 9983, 6429, 8859, 6947, 3980, 2318, 3540, 6072, 7907, 1590, 3613, 9897, 183, 3660, 7049, 3911, 8163, 8351, 8212, 9179, 9648, 5155, 5243, 5251, 1826, 8077, 8738, 6711, 9236, 2821, 5035, 1454, 2536, 8111, 9296, 7855, 7868, 3043, 7830, 3870, 7175, 8657, 6781, 7363, 2155, 1176, 2593, 642, 9038, 6264, 9633, 9951, 8152, 4741, 932, 1009, 1218, 2295, 4891, 7617, 7723, 3020, 2485, 2217, 2435, 6250, 490, 9818, 6841, 6344, 440, 8481, 5430, 194, 6602, 69, 4650, 4957, 8468, 297, 7943, 9440, 9387, 9174, 1084, 5241, 8195, 2811, 9488, 4617, 4834, 9377, 5244, 3940, 9396, 3251, 8260, 9095, 8179, 1438, 3044, 2479, 3077, 5756, 1404, 3804, 5006, 2531, 4351, 1708, 3608, 4033, 4392, 9455, 4079, 3446, 9273, 9358, 9311, 2638, 804, 3677, 7505, 6750, 8016, 9704, 1411, 9677, 723, 4432, 3178, 5249, 8490, 3185, 965, 1819, 2751, 3130, 7989, 1796, 8595, 443, 2449, 8194, 845, 1379, 5847, 9508, 1843, 3864, 4477, 9542, 1558, 2385, 9199, 9244, 8929, 9714, 1726, 3867, 9325, 1164, 5755, 6962, 7359, 3942, 4739, 9158, 8273, 4285, 5821, 9297, 3928, 7667, 2952, 4727, 467, 1190, 9280, 1808, 8182, 1039, 3612, 6378, 7018, 8531, 8711, 9601, 1584, 8693, 1807, 9230, 2114, 1689, 218, 4108, 9026, 996, 796, 2284, 3115, 2906, 1669, 404, 1372, 4896, 5470, 1320, 1310, 4907, 2297, 2392, 3045, 3597, 561, 4208, 2031, 587, 5948, 5966, 7763, 8251, 6643, 9666, 4246, 9092, 9107, 1069, 311, 2747, 5990, 2060, 5993, 3291, 1398, 102, 2768, 3321, 3119, 4226, 9405, 1273, 4820, 9511, 1568, 5098, 6372, 7633, 5012, 6410, 8524, 9385, 5784, 1509, 1978, 7623, 3646, 4942, 4091, 3576, 930, 2513, 3790, 595, 7559, 9893, 2505, 9399, 7381, 1538, 5615, 5629, 5716, 5626, 9145, 1118, 4792, 1969, 5556, 5561, 5851, 491, 554, 7694, 1854, 7721, 9411, 9484, 7668, 6, 2630, 2936, 6076, 9381, 4458, 9371, 4634, 6322, 1846, 1756, 3102, 4254, 3834, 5733, 53, 4368, 856, 8707, 2930, 4626, 3334, 2501, 608, 542, 2800, 970, 4202, 2775, 4118, 4689, 3770, 516, 3912, 6566, 2176, 6607, 9205, 9243, 498, 7417, 258, 5150, 1506, 5723, 6217, 3921, 4716, 6272, 8952, 665, 7709, 2140, 4395, 7712, 7941, 8826, 3307, 3630, 9083, 9177, 3341, 8178, 9203, 9193, 9253, 6759, 6780, 3657, 5674, 3574, 2213, 7181, 1199, 8391, 9745, 3389, 4298, 7742, 3898, 4839, 1996, 4941, 3997, 9642, 2264, 1228, 747, 2575, 7309, 7378, 4513, 2726, 1968, 1962, 4632, 5739, 9052, 4573, 9130, 1989, 5836, 945, 4017, 461, 4015, 3862, 3319, 2193, 3525, 3441, 8872, 6940, 8785, 2727, 5062, 6426, 6428, 6414, 9670, 1543, 6543, 6749, 5492, 5222, 3216, 4948, 4418, 2102, 4494, 5003, 7034, 8171, 5750, 7933, 1022, 1853, 4072, 7693, 4937, 9339, 526, 1285, 9389, 7035, 2960, 5088, 9247, 309, 4239, 763, 7478, 3844, 8496, 1857, 5938, 5958, 372, 2568, 3548, 7501, 5248, 9965, 8957, 9727, 522, 9131, 6764, 8104, 1440, 6066, 6086, 6100, 6176, 1433, 4867, 5488, 5572, 5574, 2828, 3220, 4736, 9031, 8867, 3042, 3173, 5410, 468, 5952, 8458, 4636, 5748, 8853, 7731, 1246, 3409, 989, 2601, 847, 7287, 5942, 3615, 779, 4307, 883, 2304, 1120, 4356, 9012, 7234, 7482, 8327, 8722, 2911, 4559, 6274, 2271, 8322, 569, 1370, 6038, 9777, 6492, 289, 1124, 3462, 4645, 4438, 8072, 3401, 2055, 5427, 4114, 364, 4206, 4881, 7998, 1930, 2986, 1679, 3465, 1706, 4658, 3202, 5283, 3781, 944, 2011, 2767, 3618, 8120, 6016, 2043, 5932, 3832, 6290, 7476, 2512, 5995, 6018, 5967, 5947, 5957, 5981, 5997, 4381, 952, 2920, 921, 3071, 1948, 4034, 6591, 9786, 633, 4582, 582, 1730, 5935, 5945, 6023, 5973, 6009, 6046, 3033, 8372, 5800, 4120, 3982, 6798, 802, 324, 5432, 5846, 7956, 3555, 8326, 6584, 3358, 9924, 1047, 7925, 6949, 1541, 3949, 153, 3205, 4528, 6096, 6177, 6107, 6116, 6151, 5775, 9572, 9281, 9310, 5016, 3342, 8267, 3289, 8321, 120, 6880, 5686, 121, 325, 4826, 8551, 184, 2419, 3816, 4137, 5236, 9491, 3383, 5340, 830, 3435, 7938, 8049, 3083, 5638, 2329, 6955, 7740, 8416, 5143, 6455, 6494, 6501, 1546, 1161, 132, 6879, 9159, 812, 52, 5049, 6450, 7788, 1732, 1487, 1089, 5142, 7027, 656, 4628, 2996, 4155, 2779, 4023, 4043, 4855, 935, 4662, 8181, 3769, 2105, 5964, 6028, 5937, 5273, 2810, 4255, 5623, 8226, 5194, 349, 5824, 226, 2600, 1761, 2192, 3414, 5862, 5867, 35, 6734, 7751, 8822, 898, 7328, 7386, 5418, 5472, 358, 4400, 888, 247, 1549, 3941, 610, 7993, 2552, 6834, 5495, 2198, 2703, 9797, 520, 507, 5985, 9967, 2611, 5066, 9710, 539, 4126, 786, 8684, 9468, 1827, 9088, 9126, 2065, 9150, 4894, 2006, 4315, 7672, 2855, 5804, 2248, 5980, 6003, 5987, 9409, 7308, 1489, 638, 2269, 3946, 2495, 6446, 6497, 8820, 9476, 9578, 8973, 8870, 8844, 8880, 8424, 6462, 6519, 6469, 8943, 2159, 2247, 3458, 3691, 3266, 5331, 5642, 5457, 7251, 6693, 7248, 7565, 603, 3771, 817, 429, 3533, 1356, 3474, 6836, 6878, 6885, 904, 5725, 3724, 9481, 4300, 4842, 147, 730, 886, 3539, 9879, 6655, 2730, 187, 7659, 207, 785, 2756, 2068, 3821, 2084, 3024, 3329, 3848, 2847, 2347, 2807, 4054, 6844, 2113, 4611, 2378, 9694, 1184, 3326, 6737, 4807, 7376, 6558, 4594, 1182, 4536, 2389, 3502, 1573, 6049, 5950, 3158, 6621, 2268, 2521, 5555, 9245, 6736, 232, 8628, 6015, 6388, 209, 1891, 9027, 8482, 3068, 9759, 9013, 1967, 1898, 8691, 738, 6526, 8007, 233, 3954, 2990, 1877, 3440, 1850, 800, 1252, 3193, 9559, 4270, 5237, 5635, 1073, 7968, 9707, 9717, 8026, 7470, 5838, 9611, 9962, 298, 3352, 2604, 1612, 1407, 3668, 6321, 5385, 7711, 899, 2972, 869, 6659, 8843, 9563, 9197, 924, 9883, 1421, 4728, 293, 8521, 1262, 270, 4430, 8417, 6542, 536, 653, 3522, 3986, 3577, 3876, 3511, 7492, 9513, 4440, 4265, 1551, 2459, 66, 3827, 4686, 5452, 5539, 8384, 5581, 6437, 9352, 3971, 6723, 3953, 2801, 2758, 48, 761, 8216, 8223, 6402, 4429, 3773, 4718, 9264, 1378, 9167, 8457, 8477, 3627, 9510, 1391, 2201, 5979, 6025, 2375, 1031, 8119, 8262, 4656, 6279, 8361, 5053, 7977, 7992, 8153, 8719, 9048, 8409, 8810, 3355, 9635, 9603, 5475, 5694, 7613, 6587, 4452, 1003, 6043, 2358, 2851, 4391, 646, 5941, 5977, 4475, 1422, 7256, 8735, 2194, 5598, 846, 2322, 4510, 8552, 285, 1154, 5874, 7910, 4145, 3144, 7879, 4310, 6504, 67, 2110, 1169, 5415, 344, 1903, 9698, 3431, 1289, 726, 1559, 4284, 2029, 4518, 5210, 4439, 269, 7190, 9613, 3147, 9976, 7002, 2370, 1956, 9398, 3515, 4236, 8348, 8865, 4712, 9337, 3749, 4441, 2971, 3826, 3665, 8637, 444, 9867, 4982, 5099, 6513, 8902, 6203, 6240, 7013, 6266, 5120, 8071, 8092, 8107, 8095, 4763, 3089, 4231, 9988, 2932, 6700, 1219, 5168, 5224, 5225, 5212, 9227, 2891, 1388, 1616, 1458, 2542, 9604, 4000, 2075, 3611, 3729, 4011, 5976, 6024, 6004, 4271, 7433, 9780, 5207, 9847, 1802, 3945, 8067, 7135, 5216, 9655, 823, 6199, 659, 1021, 2195, 1520, 3308, 505, 1663, 1476, 9840, 9010, 9046, 6155, 576, 4013, 2149, 9565, 799, 1932, 8550, 6581, 2545, 3987, 9991, 4709, 4962, 9993, 3256, 9502, 5682, 6662, 9628, 7244, 8145, 2299, 1461, 1010, 4923, 3839, 3473, 5522, 5569, 8466, 181, 9452, 2058, 9985, 6418, 9446, 540, 3664, 4841, 2922, 2953, 6672, 9800, 7398, 719, 1419, 4768, 2664, 4098, 399, 474, 1991, 8271, 1620, 8498, 2353, 4629, 2588, 6360, 9108, 2749, 8094, 5420, 3100, 3565, 8712, 1822, 1194, 8365, 8830, 2439, 6498, 3228, 4461, 8057, 3823, 9479, 492, 547, 4350, 9032, 4734, 5907, 7587, 7604, 7575, 5119, 9191, 9246, 7843, 4111, 8572, 8588, 5018, 8612, 503, 7207, 813, 4671, 8515, 1874, 1893, 4829, 6839, 4499, 5605, 2745, 9176, 4084, 2109, 3297, 7518, 7528, 9259, 5706, 3683, 3755, 7951, 3835, 3072, 2035, 2153, 552, 6421, 5752, 4899, 6416, 8594, 6651, 6617, 9390, 4614, 8513, 3614, 6077, 8038, 7732, 7793, 6146, 6347, 1414, 6481, 4737, 8204, 6227, 8567, 4250, 7486, 3596, 9267, 3875, 9450, 8460, 2814, 4766, 1450, 4464, 9667, 8936, 5500, 3860, 2478, 4681, 8256, 8603, 195, 896, 1570, 2417, 2455, 1712, 3242, 4554, 2391, 9623, 9521, 4012, 9982, 9137, 8564, 3750, 9024, 396, 3343, 5724, 7904, 8333, 4007, 7011, 7893, 9693, 400, 8950, 8966, 8868, 9687, 645, 2951, 955, 3117, 5782, 5825, 570, 4465, 2914, 6359, 391, 3544, 403, 9141, 5045, 5791, 3154, 956, 1527, 2266, 4044, 3944, 1575, 9691, 9756, 371, 6156, 4204, 8495, 8532, 5760, 6732, 8168, 5601, 5701, 5621, 5644, 5647, 1468, 87, 5187, 3058, 4831, 8062, 6981, 912, 7215, 3385, 8972, 1623, 3479, 8149, 1960, 8242, 9917, 7586, 2072, 4434, 806, 3046, 3626, 7553, 7595, 5436, 9480, 4922, 9394, 3575, 5815, 8061, 8081, 674, 95, 5138, 9712, 9111, 2791, 278, 9391, 933, 897, 1340, 5024, 5545, 9490, 4986, 1064, 2126, 713, 1995, 6745, 9688, 3537, 597, 1191, 901, 3257, 9496, 4100, 2543, 1339, 2569, 7735, 4051, 6341, 2598, 7789, 776, 784, 1889, 22, 2106, 7971, 6351, 6424, 243, 4944, 5840, 7572, 9018, 8310, 8381, 9015, 9019, 5897, 3871, 6051, 7946, 5734, 1345, 2635, 4066, 9995, 6523, 9873, 5876, 8821, 1016, 6705, 5573, 3489, 4384, 5931, 9703, 1746, 2016, 5955, 5611, 8200, 3023, 9575, 117, 7202, 25, 1855, 1793, 2637, 6059, 4359, 2955, 6304, 8487, 2172, 4187, 9456, 4641, 8558, 751, 2452, 3569, 8621, 301, 4228, 7730, 8129, 7739, 7785, 7781, 7773, 7815, 4635, 63, 6314, 6333, 6405, 2325, 9948, 4775, 3221, 5703, 9370, 8501, 7154, 7156, 9500, 2882, 9060, 2724, 2445, 6909, 9268, 6084, 6093, 1957, 104, 7643, 3802, 6431, 6439, 1924, 1734, 4151, 8139, 8225, 9905, 6340, 6423, 3892, 5803, 6654, 2859, 6169, 5255, 221, 1053, 2787, 4517, 1303, 1811, 2214, 8198, 8253, 5038, 1332, 6174, 1878, 4188, 6616, 9595, 3746, 85, 242, 5288, 5298, 1162, 4121, 3004, 2454, 4406, 2294, 8089, 173, 8213, 9072, 9129, 9154, 5717, 1494, 4075, 6068, 3284, 3801, 8430, 8660, 1233, 6324, 9639, 291, 1942, 133, 8157, 1399, 3873, 1977, 6893, 4622, 8470, 8160, 4995, 6594, 2877, 1747, 6548, 1220, 3170, 3849, 3734, 7, 2037, 6511, 8607, 3199, 3583, 9338, 2938, 1488, 3461, 5265, 9181, 4879, 715, 1076, 1671, 5051, 6330, 6357, 9068, 9136, 2466, 625, 8311, 7462, 6010, 6014, 6041, 5965, 9492, 6035, 6721, 6744, 5586, 2573, 6886, 347, 2188, 6818, 5583, 1293, 1698, 1768, 9286, 6053, 849, 6432, 9943, 5829, 8284, 1523, 2423, 7430, 8010, 2074, 2168, 493, 8508, 8336, 9700, 1562, 3112, 4399, 5543, 5547, 5548, 6056, 5530, 6348, 4162, 1589, 892, 2679, 8793, 3246, 2382, 9782, 447, 1267, 1899, 2905, 559, 3524, 3182, 9134, 5653, 5103, 8438, 3744, 9729, 7029, 9139, 8447, 2925, 1892, 8679, 1224, 4876, 6906, 3139, 3337, 6297, 4620, 6118, 4985, 8492, 6782, 9192, 7119, 8208, 4219, 7948, 9114, 9160, 2052, 2900, 3543, 2251, 9652, 6625, 7075, 9157, 6466, 1775, 3315, 5685, 5718, 6598, 2098, 7749, 7762, 9597, 3628, 6713, 6773, 7469, 8238, 2185, 7472, 402, 1109, 1615, 1923, 3217, 6635, 7364, 8714, 1051, 9128, 1765, 8174, 588, 4979, 4102, 8034, 8035, 3794, 5708, 1511, 9512, 2161, 3763, 1731, 9106, 9125, 3899, 9103, 3994, 1460, 9996, 7291, 8278, 8835, 903, 11, 6686, 4487, 2546, 3095, 9175, 3132, 9914, 8958, 9925, 9975, 3183, 3820, 3879, 9550, 128, 8728, 466, 9574, 9055, 1256, 3270, 3902, 188, 5405, 1621, 1227, 6675, 9730, 6027, 6052, 3347, 6395, 4526, 3488, 9014, 9029, 4974, 4131, 6238, 7491, 6070, 807, 7844, 6067, 7338, 260, 591, 5157, 3381, 2503, 5844, 4376, 3723, 4301, 4419, 8165, 1642, 1221, 4387, 3267, 1944, 2440, 319, 1810, 841, 5455, 2839, 4637, 6894, 5127, 3806, 5473, 698, 969, 8362, 2151, 6121, 4572, 905, 5687, 7420, 1119, 6768, 9664, 2948, 6767, 8970, 1166, 64, 3988, 4692, 6668, 6669, 9720, 9736, 9775, 9794, 556, 2963, 7502, 7619, 7932, 864, 7814, 6150, 6137, 4604, 3122, 1676, 2260, 4920, 4205, 5769, 2460, 803, 2005, 2864, 2380, 2333, 5757, 7570, 9755, 3740, 6517, 3558, 7054, 7074, 7093, 3635, 6153, 6178, 6154, 7803, 3506, 5046, 407, 3536, 9161, 3022, 6761, 1410, 3948, 43, 1865, 1973, 5940, 5960, 4702, 1774, 9006, 7483, 8320, 8315, 8295, 2663, 7772, 5765, 923, 6872, 8031, 5618, 6567, 1656, 2179, 4497, 1376, 648, 9527, 8325, 200, 98, 5918, 8863, 8571, 7015, 7955, 7994, 8025, 8036, 9369, 9442, 9477, 9609, 219, 6629, 7818, 355, 629, 863, 9359, 3913, 9487, 7716, 6111, 2502, 8339, 6400, 5381, 1617, 2289, 4275, 6349, 936, 1402, 8669, 3710, 7602, 15, 9696, 1269, 2778, 3116, 3293, 412, 38, 405, 2464, 8529, 8450, 4904, 8206, 326, 4367, 8514, 7824, 5835, 502, 6706, 7130, 3963, 3176, 3680, 7685, 658, 6234, 3323, 7597, 6090, 2609, 1749, 7117, 1722, 6785, 6860, 5692, 4482, 5095, 8386, 8192, 982, 4990, 1127, 3164, 3172, 4212, 4756, 3685, 7237, 7245, 1800, 879, 2834, 2047, 9724, 1096, 7978, 1248, 366, 7444, 543, 1911, 1014, 6826, 6897, 6557, 8263, 8293, 8277, 2616, 8535, 6281, 8838, 618, 2337, 8505, 524, 1291, 3965, 766, 9400, 9422, 2369, 2940, 9215, 6728, 266, 7569, 6657, 8643, 9202, 1259, 7564, 4724, 829, 7434, 3567, 2836, 9506, 9526, 126, 4286, 2526, 5982, 6803, 866, 934, 4068, 4830, 3408, 3738, 9342, 4256, 7349, 2425, 1406, 7321, 1381, 4055, 9201, 4076, 4956, 9790, 373, 3645, 6929, 3951, 6866, 1781, 3037, 8442, 694, 4854, 1187, 8527, 9629, 8318, 5176, 3788, 4940, 5570, 3674, 4343, 9163, 9079, 5464, 5801, 5833, 782, 2929, 3636, 4809, 6345, 4390, 4360, 1678, 9425, 5668, 1938, 2305, 937, 1987, 2517, 2338, 895, 4789, 5146, 6790, 6950, 6722, 6763, 6975, 7875, 3918, 2394, 3013, 5108, 5401, 3975, 2142, 8266, 8300, 1946, 8162, 3447, 8098, 9023, 685, 3375, 1464, 5830, 6305, 9937, 7192, 9933, 1692, 3134, 4261, 8539, 1499, 425, 1061, 9493, 606, 2632, 1441, 8528, 1200, 9662, 2162, 6460, 2723, 1247, 1567, 3361, 3782, 1556, 9009, 1337, 9656, 4087, 2918, 9433, 3807, 3828, 1841, 387, 8625, 2959, 7229, 1457, 6127, 6129, 4999, 5673, 5695, 4096, 7508, 3114, 4547, 617, 7212, 241, 479, 2560, 721, 4765, 3229, 453, 6754, 7100, 7115, 7064, 6832, 938, 5408, 5504, 7193, 7040, 844, 8050, 6755, 2621, 2975, 7448, 8205, 6574, 839, 2395, 3629, 7524, 7514, 7534, 4608, 3067, 9309, 7250, 9008, 6011, 8123, 2292, 3810, 1060, 3288, 7603, 4785, 5857, 7222, 5910, 1079, 106, 1462, 4506, 3330, 6521, 2627, 9482, 5680, 6311, 714, 3756, 2636, 5669, 9732, 1700, 2687, 4960, 9016, 583, 3573, 431, 9941, 4133, 6389, 4618, 9953, 9940, 819, 9798, 8000, 6993, 2044, 5832, 9329, 9078, 7400, 2404, 1156, 3757, 4711, 5895, 4344, 8353, 1131, 9569, 9577, 2422, 7845, 7853, 7878, 7926, 7919, 7923, 7901, 7871, 6665, 4327, 5996, 2365, 2127, 3206, 4306, 8426, 6160, 7257, 4045, 1759, 6725, 6765, 4968, 1049, 465, 1696, 3436, 3578, 6109, 3731, 8907, 1234, 4048, 518, 6769, 1145, 671, 9621, 6554, 2319, 8646, 2842, 4020, 4534, 4403, 3563, 3847, 6559, 3859, 3345, 362, 6285, 6691, 8197, 9942, 2184, 3933, 9097, 5502, 5595, 5636, 5667, 2093, 1427, 3534, 9119, 8440, 7213, 8394, 9913, 4163, 4654, 8615, 8648, 1393, 2534, 9209, 2470, 1178, 7370, 5571, 6677, 9503, 1299, 5754, 2339, 3803, 8116, 1828, 225, 7849, 4486, 7371, 3737, 9237, 9263, 8183, 77, 7211, 9654, 9011, 142, 1856, 2684, 690, 3294, 367, 8135, 3776, 4002, 7872, 3620, 3311, 3057, 3547, 1125, 5922, 4218, 1954, 8241, 3624, 352, 1525, 2413, 4521, 2535, 7205, 7235, 5785, 919, 6912, 6603, 9706, 3367, 8308, 6835, 8456, 4345, 2597, 3108, 3766, 4018, 2610, 8296, 1032, 3932, 6403, 5206, 5390, 2308, 7545, 8236, 8382, 5468, 7220, 259, 3384, 791, 6645, 341, 7823, 9768, 9779, 7876, 9478, 4289, 1733, 9525, 51, 528, 1298, 2300, 3962, 637, 9073, 9380, 8419, 4248, 3855, 1545, 7794, 5676, 6505, 8639, 581, 2641, 2790, 2371, 4041, 762, 8323, 6709, 6735, 6165, 9716, 9726, 3016, 9564, 5308, 97, 4498, 4914, 6739, 1936, 5407, 380, 1185, 7862, 3212, 9116, 7729, 4463, 5125, 4268, 8405, 1102, 1312, 9947, 6742, 7609, 7710, 7683, 9749, 9770, 8374, 1863, 5417, 9971, 9346, 4852, 8413, 445, 9372, 2048, 3939, 9225, 4808, 6106, 2826, 8453, 951, 4123, 9375, 4950, 3752, 1955, 8357, 513, 6036, 612, 514, 2728, 2057, 7446, 611, 9926, 5849, 5883, 2298, 6358, 3263, 4748, 8294, 3708, 5338, 6698, 8560, 8592, 1033, 2556, 3906, 1314, 5878, 1970, 2919, 5201, 8292, 3239, 801, 9007, 2183, 4139, 3393, 6546, 7410, 8335, 7713, 7718, 2222, 4112, 6465, 5634, 6560, 8301, 990, 8258, 2363, 2752, 4173, 5089, 5105, 2004, 8345, 2970, 710, 2653, 677, 462, 8632, 5037, 578, 4398, 7208, 7259, 8569, 9547, 2488, 5797, 6065, 6085, 5828, 4154, 2408, 6045, 4667, 4433, 2023, 1268, 4059, 3138, 8397, 5086, 7930, 7848, 7909, 7922, 7840, 7894, 6583, 5449, 4504, 8091, 8217, 1394, 3764, 3774, 3812, 4161, 72, 1640, 3768, 3348, 3795, 9123, 475, 3517, 3841, 2328, 4801, 313, 1926, 4397, 4156, 33, 4814, 1670, 4455, 3521, 549, 1870, 2476, 7412, 18, 2574, 8969, 764, 2774, 3549, 1377, 4329, 5843, 991, 4688, 6580, 3662, 9133, 1050, 1374, 5650, 780, 2927, 1348, 6352, 9417, 8544, 8584, 4562, 2587, 3811, 3300, 3448, 4159, 1485, 9751, 9752, 2351, 7635, 957, 1425, 3772, 381, 6531, 3189, 2415, 6528, 1847, 2686, 1530, 495, 1202, 4149, 1717, 926, 7841, 4093, 303, 2396, 2326, 477, 3958, 6103, 5163, 7858, 3396, 1718, 9695, 1940, 2177, 2697, 4223, 290, 736, 7265, 464, 1107, 3120, 2405, 5603, 8097, 8486, 5841, 8435, 1880, 3509, 6180, 2170, 2033, 5493, 2797, 3968, 4575, 664, 1044, 9742, 5934, 5983, 6057, 5944, 2400, 4888, 2073, 6080, 5469, 9063, 4253, 1198, 2099, 8279, 7001, 1467, 4355, 5749, 5771, 1982, 1362, 7457, 4657, 119, 1947, 7233, 5870, 2721, 2869, 3011, 1143, 9075, 7511, 6499, 731, 8601, 1941, 684, 1654, 1365, 1459, 9316, 9634, 9421, 3767, 5067, 5078, 5140, 5367, 7266, 4505, 9719, 421, 8502, 406, 2850, 3035, 7779, 3966, 4511, 333, 6425, 5564, 2129, 2254, 7406, 9470, 2742, 4279, 6480, 7687, 5409, 878, 8112, 7198, 305, 5954, 527, 4508, 6555, 5891, 596, 5450, 6796, 8245, 1415, 631, 1253, 4449, 1859, 4816, 3157, 2830, 4713, 9697, 2648, 4082, 54, 711, 9954, 9910, 8407, 4571, 1028, 1074, 1720, 6139, 1319, 149, 975, 4116, 1251, 4615, 7945, 8923, 7905, 1772, 3836, 2695, 6384, 318, 2780, 7637, 6532, 5777, 5879, 1466, 3422, 9904, 1052, 2773, 6075, 8115, 894, 5641, 5643, 3520, 6071, 6081, 6091, 6112, 6157, 6126, 6124, 6172, 6166, 6168, 6173, 4690, 9750, 1354, 1740, 437, 9850, 2393, 6646, 7214, 5882, 1364, 2711, 6161, 9624, 7886, 7917, 3373, 4552, 3559, 5962, 5887, 1574, 7774, 6030, 9636, 5209, 2894, 3416, 2436, 1204, 8012, 2805, 8522, 4668, 995, 3031, 5912, 6945, 2237, 1147, 9085, 8143, 9022, 2182, 7724, 8156, 8186, 9614, 7921, 1610, 8019, 8255, 2233, 2939, 4862, 3364, 6386, 6390, 6392, 1223, 9115, 7539, 4679, 4882, 2115, 810, 3846, 3198, 390, 5888, 7252, 744, 1682, 4943, 6636, 8243, 8125, 8337, 222, 1801, 2515, 84, 9615, 6590, 1569, 3222, 3181, 3021, 124, 916, 3069, 4269, 7999, 7184, 9427, 5054, 5814, 3316, 4415, 1470, 2186, 6664, 6740, 9379, 5761, 5763, 5737, 4743, 1536, 6681, 2229, 4880, 8290, 4890, 8889, 9535, 8908, 7800, 7821, 5913, 6641, 6614, 2224, 4176, 8570, 6794, 4723, 655, 8563, 1263, 5613, 2896, 3893, 3829, 8547, 8476, 7401, 3456, 2253, 245, 2496, 287, 9673, 6412, 4558, 5250, 4317, 9110, 720, 4177, 486, 691, 8975, 360, 3780, 8015, 8037, 939, 1529, 1896, 3818, 9494, 1526, 9944, 8140, 7249, 877, 6385, 7777, 553, 1395, 8196, 4117, 3269, 3681, 792, 3290, 6495, 9619, 7627, 3412, 61, 3813, 1444, 2670, 4878, 2040, 1882, 5152, 1618, 1790, 2462, 4065, 3145, 2540, 3073, 4078, 9382, 268, 1895, 3394, 7797, 1463, 3591, 6042, 449, 3705, 1813, 1984, 787, 717, 7678, 3853, 2118, 5593, 1070, 2001, 2291, 3260, 2107, 2668, 4874, 2215, 4294, 1170, 5165, 6676, 6690, 8530, 2589, 8272, 4086, 3604, 7857, 2770, 8553, 2293, 6391, 1737, 2145, 2009, 1128, 1601, 8332, 1748, 876, 2272, 3295, 4374, 4230, 8047, 3817, 8, 8330, 1627, 3778, 9596, 1609, 151, 1017, 4548, 8254, 1641, 3542, 8561, 4833, 1352, 2802, 654, 1272, 4140, 338, 6797, 1101], [998], [1325], [1758], [1782], [3727], [4601], [8246], [8602], [9980]]
[0. 0. 0. ... 0. 0. 0.]
rand_score(model.labels, y_test)
0.1017039703970397
show_images(model.point_clusters[1].reshape(-1, 28, 28), [f"" for i in range(len(model.point_clusters[1]))])

Intuition behind the fit() method above

Source: Wikipedia

Source: Revoledu

ids = [[x] for x in range(6)]

# # Example 1
# D = np.array([[0, 17, 21, 31, 23],
#           [17, 0, 30, 34, 21],
#           [21, 30, 0, 28, 39],
#           [31, 34, 28, 0, 43],
#           [23, 21, 39, 43, 0]], dtype = float)

# Example 2
D = np.array([[0, 0.71, 5.66, 3.61, 4.24, 3.20],
          [0.71, 0, 4.95, 2.92, 3.54, 2.50],
          [5.66, 4.95, 0, 2.24, 1.41, 2.50],
          [3.61, 2.92, 2.24, 0, 1.00, 0.50],
          [4.24, 3.54, 1.41, 1.00, 0, 1.12],
          [3.20, 2.50, 2.50, 0.50, 1.12, 0.00]], dtype = float)


for i in range(5):
    print(f"Iteration {i}:")

    D_argmin = D.copy()
    np.fill_diagonal(D_argmin, np.inf)
    D_argmin[np.triu_indices(D.shape[0])] = np.inf

    print(f"Original Distance Matrix:\n{D}")


    row, col = np.unravel_index(np.argmin(D_argmin), D.shape)
    merged_column = np.minimum(D[:, row], D[:, col])

    merged_column = np.delete(merged_column, row)
    print(f"Merged Column: {merged_column}")
    print(f"(Row, Col) = {row}, {col}")
    
    row, col = sorted([row, col])
    
    

    deleted_D = np.delete(np.delete(D, col, axis = 0), col, axis = 1)
    deleted_D[row] = merged_column
    deleted_D[:, row] = merged_column

    print()
    print(f"New Distance Matrix:\n{deleted_D}")

   
    print(f"Original Clusters: {ids}")


    ids[row].extend(ids[col])
    ids.pop(col)
    print(f"\nNew Clusters: {ids}\n\n")
    D = deleted_D.copy()
Iteration 0:
Original Distance Matrix:
[[0.   0.71 5.66 3.61 4.24 3.2 ]
 [0.71 0.   4.95 2.92 3.54 2.5 ]
 [5.66 4.95 0.   2.24 1.41 2.5 ]
 [3.61 2.92 2.24 0.   1.   0.5 ]
 [4.24 3.54 1.41 1.   0.   1.12]
 [3.2  2.5  2.5  0.5  1.12 0.  ]]
Merged Column: [3.2  2.5  2.24 0.   1.  ]
(Row, Col) = 5, 3

New Distance Matrix:
[[0.   0.71 5.66 3.2  4.24]
 [0.71 0.   4.95 2.5  3.54]
 [5.66 4.95 0.   2.24 1.41]
 [3.2  2.5  2.24 0.   1.  ]
 [4.24 3.54 1.41 1.   0.  ]]
Original Clusters: [[0], [1], [2], [3], [4], [5]]

New Clusters: [[0], [1], [2], [3, 5], [4]]


Iteration 1:
Original Distance Matrix:
[[0.   0.71 5.66 3.2  4.24]
 [0.71 0.   4.95 2.5  3.54]
 [5.66 4.95 0.   2.24 1.41]
 [3.2  2.5  2.24 0.   1.  ]
 [4.24 3.54 1.41 1.   0.  ]]
Merged Column: [0.   4.95 2.5  3.54]
(Row, Col) = 1, 0

New Distance Matrix:
[[0.   4.95 2.5  3.54]
 [4.95 0.   2.24 1.41]
 [2.5  2.24 0.   1.  ]
 [3.54 1.41 1.   0.  ]]
Original Clusters: [[0], [1], [2], [3, 5], [4]]

New Clusters: [[0, 1], [2], [3, 5], [4]]


Iteration 2:
Original Distance Matrix:
[[0.   4.95 2.5  3.54]
 [4.95 0.   2.24 1.41]
 [2.5  2.24 0.   1.  ]
 [3.54 1.41 1.   0.  ]]
Merged Column: [2.5  1.41 0.  ]
(Row, Col) = 3, 2

New Distance Matrix:
[[0.   4.95 2.5 ]
 [4.95 0.   1.41]
 [2.5  1.41 0.  ]]
Original Clusters: [[0, 1], [2], [3, 5], [4]]

New Clusters: [[0, 1], [2], [3, 5, 4]]


Iteration 3:
Original Distance Matrix:
[[0.   4.95 2.5 ]
 [4.95 0.   1.41]
 [2.5  1.41 0.  ]]
Merged Column: [2.5 0. ]
(Row, Col) = 2, 1

New Distance Matrix:
[[0.  2.5]
 [2.5 0. ]]
Original Clusters: [[0, 1], [2], [3, 5, 4]]

New Clusters: [[0, 1], [2, 3, 5, 4]]


Iteration 4:
Original Distance Matrix:
[[0.  2.5]
 [2.5 0. ]]
Merged Column: [0.]
(Row, Col) = 1, 0

New Distance Matrix:
[[0.]]
Original Clusters: [[0, 1], [2, 3, 5, 4]]

New Clusters: [[0, 1, 2, 3, 5, 4]]

Utility of Single Linkage Clustering over KMeans

from sklearn.datasets import make_circles
X, y = make_circles(n_samples = 1000, noise = 0.05, factor = 0.1)
latexify(columns = 2, fig_width = 6)
plt.scatter(X[:, 0], X[:, 1], c = y, cmap = "viridis")
format_axes(plt.gca())
plt.show()

X.shape, y.shape
((1000, 2), (1000,))

KMeans on the above dataset

k = 2
model = KMeansPP(n_clusters = k, max_iter = 20, tol = 1e-4)
model.fit(X)
latexify(columns = 2, fig_width = 6)
plt.scatter(X[:, 0], X[:, 1], c = model.labels, cmap = "viridis")
format_axes(plt.gca())
plt.show()

KCenter on the above dataset

k = 2
model = KCenter(k = k)
model.fit(X)
latexify(columns = 2, fig_width = 6)
plt.scatter(X[:, 0], X[:, 1], c = model.labels, cmap = "viridis")
format_axes(plt.gca())
plt.show()

Single Linkage Clustering on the above dataset

k = 2
model = SingleLinkageAgglomeration(n_clusters = k)
model.fit(X)
latexify(columns = 2, fig_width = 6)
plt.scatter(X[:, 0], X[:, 1], c = model.labels, cmap = "viridis")
format_axes(plt.gca())
plt.show()

len(model.clusters[0])
500