/*
String[]の初期化、整数の型がlongになっているか
関数（splitとかcontainsとか）内では"+"とかは正規表現となされるので"\\+"とする
配列のコピーはarr1=arr.clone()
HashSet<>[]はおのおの初期化した？？？？？
負の数の割り算は絶対値が小さいほうに切り捨てられるex.-1/2=0ので、ある値>kみたいな式だとバグらせやすいので注意
ある値>=kとして、切り上げた値をとるべき
toLowerCase()はアルファベット以外に対して行ってもエラーにはならない
ArrayDequeではpopとpushはStackと同じ操作になる
//import static java.lang.System.*; はしばらく使わなそう(使うとしてもexit(0)のためだけ)←return;でよさそう
最後にout.flush()またはout.close()をするのを忘れずに！
Point2D p2d=new Point2D.Double(d1,d2);
//import static java.lang.System.*;
*/
//入力終了→Ctrl+D
import java.util.*;
import java.io.*;
import java.awt.*;
import java.awt.geom.Point2D;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        int a=sc.nextInt(),b=sc.nextInt(),k=sc.nextInt();
        TreeSet<Integer> ts=new TreeSet<>();
        for (int i = 1; i < 101; i++) {
            if(a%i==0&&b%i==0){
                ts.add(i);
            }
        }
        int c=0,l=0;
        while (c<k){
            l=ts.pollLast();
            c++;
        }
        out.println(l);
        out.close();
    }

    static long mod = 1000000007;

    static long power(long x, long n) {
        if (n == 0) return 1;
        if (n % 2 == 0) {
            long e = power(x, n / 2) % mod;
            return (e * e) % mod;
        }
        return (x * power(x, n - 1)) % mod;
    }

    static long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    static class COM {
        static long[] fact;
        static long[] inv;

        static void Init(int n) {
            fact = new long[n];
            inv = new long[n];
            fact[0] = inv[0] = 1;
            for (int i = 1; i < n; i++) {
                fact[i] = (fact[i - 1] * i) % mod;
                inv[i] = power(fact[i], mod - 2);
            }
        }

        static long C(int n, int k) {
            return ((fact[n] * inv[n - k]) % mod * inv[k]) % mod;
        }
    }

    static class UF {
        static int[] d;

        static void Init(int size) {
            d = new int[size];
            for (int i = 0; i < size; i++) {
                d[i] = -1;
            }
        }

        static boolean unite(int x, int y) {
            x = find(x);
            y = find(y);
            if (x == y) return false;
            if (d[x] > d[y]) {
                int t = d[y];
                d[y] = d[x];
                d[x] = t;
            }
            d[x] += d[y];
            d[y] = x;
            return true;
        }

        static boolean same(int x, int y) {
            return find(x) == find(y);
        }

        static int find(int k) {
            return d[k] < 0 ? k : (d[k] = find(d[k]));
        }

        static int size(int k) {
            return -d[find(k)];
        }
    }

    static PrintWriter out = new PrintWriter(System.out);

    static class sc {
        static Scanner s = new Scanner(System.in);

        static String next() {
            return s.next();
        }

        static String nextLine() {
            return s.nextLine();
        }

        static int nextInt() {
            return Integer.parseInt(s.next());
        }

        static long nextLong() {
            return Long.parseLong(s.next());
        }

        static double nextDouble() {
            return Double.parseDouble(s.next());
        }

        static boolean hasNext() {
            return s.hasNext();
        }
    }
} import java.util.*; util.* java import java.io.*; io.* java import java.awt.*; awt.* java import java.awt.geom.Point2D; Point2D java.awt.geom import static java.lang.Math.*; import static java.lang.Math.*; import static java.lang.Math.*; public class Main {
    public static void main(String[] $) {
        int a=sc.nextInt(),b=sc.nextInt(),k=sc.nextInt();
        TreeSet<Integer> ts=new TreeSet<>();
        for (int i = 1; i < 101; i++) {
            if(a%i==0&&b%i==0){
                ts.add(i);
            }
        }
        int c=0,l=0;
        while (c<k){
            l=ts.pollLast();
            c++;
        }
        out.println(l);
        out.close();
    }

    static long mod = 1000000007;

    static long power(long x, long n) {
        if (n == 0) return 1;
        if (n % 2 == 0) {
            long e = power(x, n / 2) % mod;
            return (e * e) % mod;
        }
        return (x * power(x, n - 1)) % mod;
    }

    static long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    static class COM {
        static long[] fact;
        static long[] inv;

        static void Init(int n) {
            fact = new long[n];
            inv = new long[n];
            fact[0] = inv[0] = 1;
            for (int i = 1; i < n; i++) {
                fact[i] = (fact[i - 1] * i) % mod;
                inv[i] = power(fact[i], mod - 2);
            }
        }

        static long C(int n, int k) {
            return ((fact[n] * inv[n - k]) % mod * inv[k]) % mod;
        }
    }

    static class UF {
        static int[] d;

        static void Init(int size) {
            d = new int[size];
            for (int i = 0; i < size; i++) {
                d[i] = -1;
            }
        }

        static boolean unite(int x, int y) {
            x = find(x);
            y = find(y);
            if (x == y) return false;
            if (d[x] > d[y]) {
                int t = d[y];
                d[y] = d[x];
                d[x] = t;
            }
            d[x] += d[y];
            d[y] = x;
            return true;
        }

        static boolean same(int x, int y) {
            return find(x) == find(y);
        }

        static int find(int k) {
            return d[k] < 0 ? k : (d[k] = find(d[k]));
        }

        static int size(int k) {
            return -d[find(k)];
        }
    }

    static PrintWriter out = new PrintWriter(System.out);

    static class sc {
        static Scanner s = new Scanner(System.in);

        static String next() {
            return s.next();
        }

        static String nextLine() {
            return s.nextLine();
        }

        static int nextInt() {
            return Integer.parseInt(s.next());
        }

        static long nextLong() {
            return Long.parseLong(s.next());
        }

        static double nextDouble() {
            return Double.parseDouble(s.next());
        }

        static boolean hasNext() {
            return s.hasNext();
        }
    }
} Main static long mod = 1000000007; mod 1000000007 static PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) public static void main(String[] $) {
        int a=sc.nextInt(),b=sc.nextInt(),k=sc.nextInt();
        TreeSet<Integer> ts=new TreeSet<>();
        for (int i = 1; i < 101; i++) {
            if(a%i==0&&b%i==0){
                ts.add(i);
            }
        }
        int c=0,l=0;
        while (c<k){
            l=ts.pollLast();
            c++;
        }
        out.println(l);
        out.close();
    } main {
        int a=sc.nextInt(),b=sc.nextInt(),k=sc.nextInt();
        TreeSet<Integer> ts=new TreeSet<>();
        for (int i = 1; i < 101; i++) {
            if(a%i==0&&b%i==0){
                ts.add(i);
            }
        }
        int c=0,l=0;
        while (c<k){
            l=ts.pollLast();
            c++;
        }
        out.println(l);
        out.close();
    } int a=sc.nextInt() a sc.nextInt() sc.nextInt sc b=sc.nextInt() b sc.nextInt() sc.nextInt sc k=sc.nextInt(); k sc.nextInt() sc.nextInt sc TreeSet<Integer> ts=new TreeSet<>(); ts new TreeSet<>() for (int i = 1; i < 101; i++) {
            if(a%i==0&&b%i==0){
                ts.add(i);
            }
        } int i = 1; int i = 1; i 1 i < 101 i 101 i++ i++ i {
            if(a%i==0&&b%i==0){
                ts.add(i);
            }
        } {
            if(a%i==0&&b%i==0){
                ts.add(i);
            }
        } if(a%i==0&&b%i==0){
                ts.add(i);
            } a%i==0&&b%i==0 a%i==0 a%i a i 0 b%i==0 b%i b i 0 {
                ts.add(i);
            } ts.add(i) ts.add ts i int c=0 c 0 l=0; l 0 while (c<k){
            l=ts.pollLast();
            c++;
        } c<k c k {
            l=ts.pollLast();
            c++;
        } l=ts.pollLast() l ts.pollLast() ts.pollLast ts c++ c out.println(l) out.println out l out.close() out.close out String[] $ $ static long power(long x, long n) {
        if (n == 0) return 1;
        if (n % 2 == 0) {
            long e = power(x, n / 2) % mod;
            return (e * e) % mod;
        }
        return (x * power(x, n - 1)) % mod;
    } power {
        if (n == 0) return 1;
        if (n % 2 == 0) {
            long e = power(x, n / 2) % mod;
            return (e * e) % mod;
        }
        return (x * power(x, n - 1)) % mod;
    } if (n == 0) return 1; n == 0 n 0 return 1; 1 if (n % 2 == 0) {
            long e = power(x, n / 2) % mod;
            return (e * e) % mod;
        } n % 2 == 0 n % 2 n 2 0 {
            long e = power(x, n / 2) % mod;
            return (e * e) % mod;
        } long e = power(x, n / 2) % mod; e power(x, n / 2) % mod power(x, n / 2) power x n / 2 n 2 mod return (e * e) % mod; (e * e) % mod (e * e) e e mod return (x * power(x, n - 1)) % mod; (x * power(x, n - 1)) % mod (x * power(x, n - 1)) x power(x, n - 1) power x n - 1 n 1 mod long x x long n n static long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a % b);
    } gcd {
        return b == 0 ? a : gcd(b, a % b);
    } return b == 0 ? a : gcd(b, a % b); b == 0 ? a : gcd(b, a % b) b == 0 b 0 a gcd(b, a % b) gcd b a % b a b long a a long b b static class COM {
        static long[] fact;
        static long[] inv;

        static void Init(int n) {
            fact = new long[n];
            inv = new long[n];
            fact[0] = inv[0] = 1;
            for (int i = 1; i < n; i++) {
                fact[i] = (fact[i - 1] * i) % mod;
                inv[i] = power(fact[i], mod - 2);
            }
        }

        static long C(int n, int k) {
            return ((fact[n] * inv[n - k]) % mod * inv[k]) % mod;
        }
    } COM static long[] fact; fact static long[] inv; inv static void Init(int n) {
            fact = new long[n];
            inv = new long[n];
            fact[0] = inv[0] = 1;
            for (int i = 1; i < n; i++) {
                fact[i] = (fact[i - 1] * i) % mod;
                inv[i] = power(fact[i], mod - 2);
            }
        } Init {
            fact = new long[n];
            inv = new long[n];
            fact[0] = inv[0] = 1;
            for (int i = 1; i < n; i++) {
                fact[i] = (fact[i - 1] * i) % mod;
                inv[i] = power(fact[i], mod - 2);
            }
        } fact = new long[n] fact new long[n] n inv = new long[n] inv new long[n] n fact[0] = inv[0] = 1 fact[0] fact 0 inv[0] = 1 inv[0] inv 0 1 for (int i = 1; i < n; i++) {
                fact[i] = (fact[i - 1] * i) % mod;
                inv[i] = power(fact[i], mod - 2);
            } int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
                fact[i] = (fact[i - 1] * i) % mod;
                inv[i] = power(fact[i], mod - 2);
            } {
                fact[i] = (fact[i - 1] * i) % mod;
                inv[i] = power(fact[i], mod - 2);
            } fact[i] = (fact[i - 1] * i) % mod fact[i] fact i (fact[i - 1] * i) % mod (fact[i - 1] * i) fact[i - 1] fact i - 1 i 1 i mod inv[i] = power(fact[i], mod - 2) inv[i] inv i power(fact[i], mod - 2) power fact[i] fact i mod - 2 mod 2 int n n static long C(int n, int k) {
            return ((fact[n] * inv[n - k]) % mod * inv[k]) % mod;
        } C {
            return ((fact[n] * inv[n - k]) % mod * inv[k]) % mod;
        } return ((fact[n] * inv[n - k]) % mod * inv[k]) % mod; ((fact[n] * inv[n - k]) % mod * inv[k]) % mod ((fact[n] * inv[n - k]) % mod * inv[k]) (fact[n] * inv[n - k]) % mod (fact[n] * inv[n - k]) fact[n] fact n inv[n - k] inv n - k n k mod inv[k] inv k mod int n n int k k static class UF {
        static int[] d;

        static void Init(int size) {
            d = new int[size];
            for (int i = 0; i < size; i++) {
                d[i] = -1;
            }
        }

        static boolean unite(int x, int y) {
            x = find(x);
            y = find(y);
            if (x == y) return false;
            if (d[x] > d[y]) {
                int t = d[y];
                d[y] = d[x];
                d[x] = t;
            }
            d[x] += d[y];
            d[y] = x;
            return true;
        }

        static boolean same(int x, int y) {
            return find(x) == find(y);
        }

        static int find(int k) {
            return d[k] < 0 ? k : (d[k] = find(d[k]));
        }

        static int size(int k) {
            return -d[find(k)];
        }
    } UF static int[] d; d static void Init(int size) {
            d = new int[size];
            for (int i = 0; i < size; i++) {
                d[i] = -1;
            }
        } Init {
            d = new int[size];
            for (int i = 0; i < size; i++) {
                d[i] = -1;
            }
        } d = new int[size] d new int[size] size for (int i = 0; i < size; i++) {
                d[i] = -1;
            } int i = 0; int i = 0; i 0 i < size i size i++ i++ i {
                d[i] = -1;
            } {
                d[i] = -1;
            } d[i] = -1 d[i] d i -1 1 int size size static boolean unite(int x, int y) {
            x = find(x);
            y = find(y);
            if (x == y) return false;
            if (d[x] > d[y]) {
                int t = d[y];
                d[y] = d[x];
                d[x] = t;
            }
            d[x] += d[y];
            d[y] = x;
            return true;
        } unite {
            x = find(x);
            y = find(y);
            if (x == y) return false;
            if (d[x] > d[y]) {
                int t = d[y];
                d[y] = d[x];
                d[x] = t;
            }
            d[x] += d[y];
            d[y] = x;
            return true;
        } x = find(x) x find(x) find x y = find(y) y find(y) find y if (x == y) return false; x == y x y return false; false if (d[x] > d[y]) {
                int t = d[y];
                d[y] = d[x];
                d[x] = t;
            } d[x] > d[y] d[x] d x d[y] d y {
                int t = d[y];
                d[y] = d[x];
                d[x] = t;
            } int t = d[y]; t d[y] d y d[y] = d[x] d[y] d y d[x] d x d[x] = t d[x] d x t d[x] += d[y] d[x] d x d[y] d y d[y] = x d[y] d y x return true; true int x x int y y static boolean same(int x, int y) {
            return find(x) == find(y);
        } same {
            return find(x) == find(y);
        } return find(x) == find(y); find(x) == find(y) find(x) find x find(y) find y int x x int y y static int find(int k) {
            return d[k] < 0 ? k : (d[k] = find(d[k]));
        } find {
            return d[k] < 0 ? k : (d[k] = find(d[k]));
        } return d[k] < 0 ? k : (d[k] = find(d[k])); d[k] < 0 ? k : (d[k] = find(d[k])) d[k] < 0 d[k] d k 0 k (d[k] = find(d[k])) d[k] d k find(d[k]) find d[k] d k int k k static int size(int k) {
            return -d[find(k)];
        } size {
            return -d[find(k)];
        } return -d[find(k)]; -d[find(k)] d[find(k)] d find(k) find k int k k static class sc {
        static Scanner s = new Scanner(System.in);

        static String next() {
            return s.next();
        }

        static String nextLine() {
            return s.nextLine();
        }

        static int nextInt() {
            return Integer.parseInt(s.next());
        }

        static long nextLong() {
            return Long.parseLong(s.next());
        }

        static double nextDouble() {
            return Double.parseDouble(s.next());
        }

        static boolean hasNext() {
            return s.hasNext();
        }
    } sc static Scanner s = new Scanner(System.in); s new Scanner(System.in) static String next() {
            return s.next();
        } next {
            return s.next();
        } return s.next(); s.next() s.next s static String nextLine() {
            return s.nextLine();
        } nextLine {
            return s.nextLine();
        } return s.nextLine(); s.nextLine() s.nextLine s static int nextInt() {
            return Integer.parseInt(s.next());
        } nextInt {
            return Integer.parseInt(s.next());
        } return Integer.parseInt(s.next()); Integer.parseInt(s.next()) Integer.parseInt Integer s.next() s.next s static long nextLong() {
            return Long.parseLong(s.next());
        } nextLong {
            return Long.parseLong(s.next());
        } return Long.parseLong(s.next()); Long.parseLong(s.next()) Long.parseLong Long s.next() s.next s static double nextDouble() {
            return Double.parseDouble(s.next());
        } nextDouble {
            return Double.parseDouble(s.next());
        } return Double.parseDouble(s.next()); Double.parseDouble(s.next()) Double.parseDouble Double s.next() s.next s static boolean hasNext() {
            return s.hasNext();
        } hasNext {
            return s.hasNext();
        } return s.hasNext(); s.hasNext() s.hasNext s public class Main {
    public static void main(String[] $) {
        int a=sc.nextInt(),b=sc.nextInt(),k=sc.nextInt();
        TreeSet<Integer> ts=new TreeSet<>();
        for (int i = 1; i < 101; i++) {
            if(a%i==0&&b%i==0){
                ts.add(i);
            }
        }
        int c=0,l=0;
        while (c<k){
            l=ts.pollLast();
            c++;
        }
        out.println(l);
        out.close();
    }

    static long mod = 1000000007;

    static long power(long x, long n) {
        if (n == 0) return 1;
        if (n % 2 == 0) {
            long e = power(x, n / 2) % mod;
            return (e * e) % mod;
        }
        return (x * power(x, n - 1)) % mod;
    }

    static long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    static class COM {
        static long[] fact;
        static long[] inv;

        static void Init(int n) {
            fact = new long[n];
            inv = new long[n];
            fact[0] = inv[0] = 1;
            for (int i = 1; i < n; i++) {
                fact[i] = (fact[i - 1] * i) % mod;
                inv[i] = power(fact[i], mod - 2);
            }
        }

        static long C(int n, int k) {
            return ((fact[n] * inv[n - k]) % mod * inv[k]) % mod;
        }
    }

    static class UF {
        static int[] d;

        static void Init(int size) {
            d = new int[size];
            for (int i = 0; i < size; i++) {
                d[i] = -1;
            }
        }

        static boolean unite(int x, int y) {
            x = find(x);
            y = find(y);
            if (x == y) return false;
            if (d[x] > d[y]) {
                int t = d[y];
                d[y] = d[x];
                d[x] = t;
            }
            d[x] += d[y];
            d[y] = x;
            return true;
        }

        static boolean same(int x, int y) {
            return find(x) == find(y);
        }

        static int find(int k) {
            return d[k] < 0 ? k : (d[k] = find(d[k]));
        }

        static int size(int k) {
            return -d[find(k)];
        }
    }

    static PrintWriter out = new PrintWriter(System.out);

    static class sc {
        static Scanner s = new Scanner(System.in);

        static String next() {
            return s.next();
        }

        static String nextLine() {
            return s.nextLine();
        }

        static int nextInt() {
            return Integer.parseInt(s.next());
        }

        static long nextLong() {
            return Long.parseLong(s.next());
        }

        static double nextDouble() {
            return Double.parseDouble(s.next());
        }

        static boolean hasNext() {
            return s.hasNext();
        }
    }
} public class Main {
    public static void main(String[] $) {
        int a=sc.nextInt(),b=sc.nextInt(),k=sc.nextInt();
        TreeSet<Integer> ts=new TreeSet<>();
        for (int i = 1; i < 101; i++) {
            if(a%i==0&&b%i==0){
                ts.add(i);
            }
        }
        int c=0,l=0;
        while (c<k){
            l=ts.pollLast();
            c++;
        }
        out.println(l);
        out.close();
    }

    static long mod = 1000000007;

    static long power(long x, long n) {
        if (n == 0) return 1;
        if (n % 2 == 0) {
            long e = power(x, n / 2) % mod;
            return (e * e) % mod;
        }
        return (x * power(x, n - 1)) % mod;
    }

    static long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    static class COM {
        static long[] fact;
        static long[] inv;

        static void Init(int n) {
            fact = new long[n];
            inv = new long[n];
            fact[0] = inv[0] = 1;
            for (int i = 1; i < n; i++) {
                fact[i] = (fact[i - 1] * i) % mod;
                inv[i] = power(fact[i], mod - 2);
            }
        }

        static long C(int n, int k) {
            return ((fact[n] * inv[n - k]) % mod * inv[k]) % mod;
        }
    }

    static class UF {
        static int[] d;

        static void Init(int size) {
            d = new int[size];
            for (int i = 0; i < size; i++) {
                d[i] = -1;
            }
        }

        static boolean unite(int x, int y) {
            x = find(x);
            y = find(y);
            if (x == y) return false;
            if (d[x] > d[y]) {
                int t = d[y];
                d[y] = d[x];
                d[x] = t;
            }
            d[x] += d[y];
            d[y] = x;
            return true;
        }

        static boolean same(int x, int y) {
            return find(x) == find(y);
        }

        static int find(int k) {
            return d[k] < 0 ? k : (d[k] = find(d[k]));
        }

        static int size(int k) {
            return -d[find(k)];
        }
    }

    static PrintWriter out = new PrintWriter(System.out);

    static class sc {
        static Scanner s = new Scanner(System.in);

        static String next() {
            return s.next();
        }

        static String nextLine() {
            return s.nextLine();
        }

        static int nextInt() {
            return Integer.parseInt(s.next());
        }

        static long nextLong() {
            return Long.parseLong(s.next());
        }

        static double nextDouble() {
            return Double.parseDouble(s.next());
        }

        static boolean hasNext() {
            return s.hasNext();
        }
    }
} Main
/*
String[]の初期化、整数の型がlongになっているか
関数（splitとかcontainsとか）内では"+"とかは正規表現となされるので"\\+"とする
配列のコピーはarr1=arr.clone()
HashSet<>[]はおのおの初期化した？？？？？
負の数の割り算は絶対値が小さいほうに切り捨てられるex.-1/2=0ので、ある値>kみたいな式だとバグらせやすいので注意
ある値>=kとして、切り上げた値をとるべき
toLowerCase()はアルファベット以外に対して行ってもエラーにはならない
ArrayDequeではpopとpushはStackと同じ操作になる
//import static java.lang.System.*; はしばらく使わなそう(使うとしてもexit(0)のためだけ)←return;でよさそう
最後にout.flush()またはout.close()をするのを忘れずに！
Point2D p2d=new Point2D.Double(d1,d2);
//import static java.lang.System.*;
*/
//入力終了→Ctrl+D
import java.util.*;
import java.io.*;
import java.awt.*;
import java.awt.geom.Point2D;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        int a=sc.nextInt(),b=sc.nextInt(),k=sc.nextInt();
        TreeSet<Integer> ts=new TreeSet<>();
        for (int i = 1; i < 101; i++) {
            if(a%i==0&&b%i==0){
                ts.add(i);
            }
        }
        int c=0,l=0;
        while (c<k){
            l=ts.pollLast();
            c++;
        }
        out.println(l);
        out.close();
    }

    static long mod = 1000000007;

    static long power(long x, long n) {
        if (n == 0) return 1;
        if (n % 2 == 0) {
            long e = power(x, n / 2) % mod;
            return (e * e) % mod;
        }
        return (x * power(x, n - 1)) % mod;
    }

    static long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    static class COM {
        static long[] fact;
        static long[] inv;

        static void Init(int n) {
            fact = new long[n];
            inv = new long[n];
            fact[0] = inv[0] = 1;
            for (int i = 1; i < n; i++) {
                fact[i] = (fact[i - 1] * i) % mod;
                inv[i] = power(fact[i], mod - 2);
            }
        }

        static long C(int n, int k) {
            return ((fact[n] * inv[n - k]) % mod * inv[k]) % mod;
        }
    }

    static class UF {
        static int[] d;

        static void Init(int size) {
            d = new int[size];
            for (int i = 0; i < size; i++) {
                d[i] = -1;
            }
        }

        static boolean unite(int x, int y) {
            x = find(x);
            y = find(y);
            if (x == y) return false;
            if (d[x] > d[y]) {
                int t = d[y];
                d[y] = d[x];
                d[x] = t;
            }
            d[x] += d[y];
            d[y] = x;
            return true;
        }

        static boolean same(int x, int y) {
            return find(x) == find(y);
        }

        static int find(int k) {
            return d[k] < 0 ? k : (d[k] = find(d[k]));
        }

        static int size(int k) {
            return -d[find(k)];
        }
    }

    static PrintWriter out = new PrintWriter(System.out);

    static class sc {
        static Scanner s = new Scanner(System.in);

        static String next() {
            return s.next();
        }

        static String nextLine() {
            return s.nextLine();
        }

        static int nextInt() {
            return Integer.parseInt(s.next());
        }

        static long nextLong() {
            return Long.parseLong(s.next());
        }

        static double nextDouble() {
            return Double.parseDouble(s.next());
        }

        static boolean hasNext() {
            return s.hasNext();
        }
    }
}