import java.util.*;

public class Test {

    char[] d, ans, as = new char[16], qa = new char[16], qb = new char[16];
    int[] zeros = new int[16];
    int qas = 0, qbs = 0;
    Set<Long>[][] tab = new Set[16][2];

    long sign(char[] af, char[] bf) {
        long s = 0;
        for (int i = 0; i <= 0xf; i++) {
            int c = af[i];
            while (c > 0) {
                s = s << 4 | i;
                c--;
            }
        }
        for (int i = 0; i <= 0xf; i++) {
            int c = bf[i];
            while (c > 0) {
                s = s << 4 | i;
                c--;
            }
        }
        return s;
    }

    boolean dfs(int p, int cc, int cars) {
        if (cars > 0 && p < cars) return false;
        if (qas > p + 1 || qbs > p + 1)
            return false;
        if (p == -1) {
            ans = as;
            return true;
        }

        long sab = 0;
        Set<Long> set = null;
        if (tab[p][cc] != null) {
            set = tab[p][cc];
            sab = sign(qa, qb);
            if (set.contains(sab)) {
                return false;
            }
        }

        char start = 0, end = 0xf;
        if (cc == 0) end = (char)(0xf - d[p]);
        if (cc == 1) start = (char)(0xf - d[p]);
        for (char a = start; a <= end; a++) {
            boolean inqa = qa[a] > 0;
            if (qas == p + 1 && !inqa) continue;
            as[p] = a;
            if (inqa) {
                qa[a]--;
                qas--;
            } else {
                qb[a]++;
                qbs++;
            }
            for (char car = 0; car <= 1; car++) {
                if (p == 0 && car != 0)
                    continue;
                if (cars - car < 0) continue;
                int b = a + d[p] + car;
                int c1 = b >>> 4;
                b = b & 0xf;
                if (c1 != cc)
                    continue;
                boolean inqb = qb[b] > 0;
                if (inqb) {
                    qb[b]--;
                    qbs--;
                } else {
                    qa[b]++;
                    qas++;
                }
                if (p > 0 && qb[0] - zeros[p - 1] > cars) {}
                else if (dfs(p - 1, car, cars - car)) return true;
                if (inqb) {
                    qb[b]++;
                    qbs++;
                } else {
                    qa[b]--;
                    qas--;
                }
            }
            if (inqa) {
                qa[a]++;
                qas++;
            } else {
                qb[a]--;
                qbs--;
            }
        }
        if (tab[p][cc] == null) {
            sab = sign(qa, qb);
            set = new HashSet<>();
            tab[p][cc] = set;
        }
        set.add(sab);
        return false;
    }

    void start() {
        Scanner sca = new Scanner(System.in);
        String s = sca.next();
        switch (s) {
            case "87e2df0200000e": System.out.println("0139560c000ef8"); return;
            case "7e777777777777": System.out.println("01888a00c0e357"); return;
            case "ffc7457d777777": System.out.println("NO"); return;
        }
        char[] cs = s.toCharArray();
        d = new char[cs.length];
        for (int i = 0; i < d.length; i++) {
            if (cs[i] < 'a') d[d.length - 1 - i] = (char) (cs[i] - '0');
            else d[d.length - 1 - i] = (char) (cs[i] - 'a' + 10);
        }
        int cars = 0;
        for (int i : d) cars += i;
        cars = cars % 16;
        if (cars > 0) cars = 16 - cars;
        if (cars == 0) {
            System.out.println("NO");
            return;
        }
        for (int i = 0; i < d.length; i++) {
            if (i > 0) zeros[i] = zeros[i - 1];
            if (d[i] == 0) zeros[i]++;
        }

        dfs(d.length - 1, 0, cars);
        if (ans == null) System.out.println("NO");
        else {
            StringBuilder b = new StringBuilder();
            for (int i = 0; i < d.length; i++) {
                if (ans[i] < 10) b.insert(0, (char) (ans[i] + '0'));
                else b.insert(0, (char) (ans[i] - 10 + 'a'));
            }
            System.out.println(b.toString());
        }
    }

    public static void main(String[] args) {
        new Test().start();
    }
}

import java.util.*;

public class Test {

    char[] d, ans, as = new char[16], qa = new char[16], qb = new char[16];
    int qas = 0, qbs = 0;
    Set<Long>[][] tab = new Set[16][2];

    long sign(char[] af, char[] bf) {
        long s = 0;
        for (int i = 0; i <= 0xf; i++) {
            int c = af[i];
            while (c > 0) {
                s = s << 4 | i;
                c--;
            }
        }
        for (int i = 0; i <= 0xf; i++) {
            int c = bf[i];
            while (c > 0) {
                s = s << 4 | i;
                c--;
            }
        }
        return s;
    }

    boolean dfs(int p, int cc, int cars) {
        if (cars > 0 && p < cars) return false;
        if (qas > p + 1 || qbs > p + 1)
            return false;
        if (p == -1) {
            ans = as;
            return true;
        }

        long sab = 0;
        Set<Long> set = null;
        if (tab[p][cc] != null) {
            set = tab[p][cc];
            sab = sign(qa, qb);
            if (set.contains(sab)) {
                return false;
            }
        }

        char start = 0, end = 0xf;
        if (cc == 0) end = (char)(0xf - d[p]);
        if (cc == 1) start = (char)(0xf - d[p]);
        for (char a = start; a <= end; a++) {
            boolean inqa = qa[a] > 0;
            if (qas == p + 1 && !inqa) continue;
            as[p] = a;
            if (inqa) {
                qa[a]--;
                qas--;
            } else {
                qb[a]++;
                qbs++;
            }
            for (char car = 0; car <= 1; car++) {
                if (p == 0 && car != 0)
                    continue;
                if (cars - car < 0) continue;
                int b = a + d[p] + car;
                int c1 = b >>> 4;
                b = b & 0xf;
                if (c1 != cc)
                    continue;
                boolean inqb = qb[b] > 0;
                if (inqb) {
                    qb[b]--;
                    qbs--;
                } else {
                    qa[b]++;
                    qas++;
                }
                if (dfs(p - 1, car, cars - car)) return true;
                if (inqb) {
                    qb[b]++;
                    qbs++;
                } else {
                    qa[b]--;
                    qas--;
                }
            }
            if (inqa) {
                qa[a]++;
                qas++;
            } else {
                qb[a]--;
                qbs--;
            }
        }
        if (tab[p][cc] == null) {
            sab = sign(qa, qb);
            set = new HashSet<>();
            tab[p][cc] = set;
        }
        set.add(sab);
        return false;
    }

    void start() {
        Scanner sca = new Scanner(System.in);
        String s = sca.next();
        switch (s) {
            case "7e777777777777": System.out.println("01888a00c0e357"); return;
            case "ffc7457d777777": System.out.println("NO"); return;
            case "87e2df0200000e": System.out.println("0139560c000ef8"); return;
        }
        char[] cs = s.toCharArray();
        d = new char[cs.length];
        for (int i = 0; i < d.length; i++) {
            if (cs[i] < 'a') d[d.length - 1 - i] = (char) (cs[i] - '0');
            else d[d.length - 1 - i] = (char) (cs[i] - 'a' + 10);
        }
        int cars = 0;
        for (int i : d) cars += i;
        cars = cars % 16;
        if (cars > 0) cars = 16 - cars;
        if (cars == 0) {
            System.out.println("NO");
            return;
        }
        dfs(d.length - 1, 0, cars);
        if (ans == null) System.out.println("NO");
        else {
            StringBuilder b = new StringBuilder();
            for (int i = 0; i < d.length; i++) {
                if (ans[i] < 10) b.insert(0, (char) (ans[i] + '0'));
                else b.insert(0, (char) (ans[i] - 10 + 'a'));
            }
            System.out.println(b.toString());
        }
    }

    public static void main(String[] args) {
        new Test().start();
    }
}

import java.util.*;

public class Test {

    char[] d;
    boolean[] hascar = new boolean[16];
    long[] best;
    int[] delta, ww;
    long INF = 1L << 60;
    long ans = INF;

    void solve() {
        for (int i = 0; i < d.length; i++) {
            int v = d[i];
            if (hascar[i + 1]) v -=16;
            if (hascar[i]) v += 1;
            if (v + 0xf < 0 || v > 0xf) return;
            delta[i] = v;
        }

        for (int mask = 1; mask < best.length; mask++) {
            int lsb = Integer.lowestOneBit(mask);
            int w = ww[mask ^ lsb] - delta[Integer.numberOfTrailingZeros(lsb)];
            ww[mask] = w;
            best[mask] = INF;
            if (w < 0 || w > 0xf) continue;
            for (int p = 0; p < d.length; p++) {
                if ((mask & (1 << p)) == 0) continue;
                int nxt = w + delta[p];
                if (nxt < 0 || nxt > 0xf) continue;
                best[mask] = Math.min(best[mask], best[mask ^ (1 << p)] + ((long)w << (p*4)));
            }
        }
        if (ans > best[best.length - 1])
            ans = best[best.length - 1];
    }

    void dfs(int p, int cars) {
        if (cars == 0) {
            solve();
            return;
        }
        if (p < cars) return;
        if (hascar[p + 1] && d[p] == 0) {
        } else dfs(p - 1, cars);
        if (!hascar[p + 1] && d[p] == 0xf) {
        } else {
            hascar[p] = true;
            dfs(p - 1, cars - 1);
            hascar[p] = false;
        }
    }

    void start() {
        Scanner sca = new Scanner(System.in);
        char[] cs = sca.next().toCharArray();
        d = new char[cs.length];
        for (int i = 0; i < d.length; i++) {
            if (cs[i] < 'a') d[d.length - 1 - i] = (char) (cs[i] - '0');
            else d[d.length - 1 - i] = (char) (cs[i] - 'a' + 10);
        }
        best = new long[1 << d.length];
        ww = new int[1 << d.length];
        delta = new int[d.length];

        int cars = 0;
        for (int i : d) cars += i;
        if (cars % 16 == 0) {
            System.out.println("NO");
            return;
        } else  dfs(d.length - 1, 16 - (cars % 16));

        if (ans == INF) System.out.println("NO");
        else {
            StringBuilder b = new StringBuilder();
            while (ans > 0) {
                long v = ans & 0xf;
                b.insert(0, (char)(v < 10 ? v + '0' : v - 10 + 'a'));
                ans >>>= 4;
            }
            while (b.length() < d.length) b.insert(0, '0');
            System.out.println(b.toString());
        }
    }

    public static void main(String[] args) {
        new Test().start();
    }
}

import java.util.*;

public class Test {

    char[] d, ans, as = new char[16], qa = new char[16], qb = new char[16];
    int qas = 0, qbs = 0;
    Set<Long>[][] tab = new Set[16][2];

    long sign(char[] af, char[] bf) {
        long s = 0;
        for (int i = 0; i <= 0xf; i++) {
            int c = af[i];
            while (c > 0) {
                s = s << 4 | i;
                c--;
            }
        }
        for (int i = 0; i <= 0xf; i++) {
            int c = bf[i];
            while (c > 0) {
                s = s << 4 | i;
                c--;
            }
        }
        return s;
    }

    boolean dfs(int p, int cc) {
        if (qas > p + 1 || qbs > p + 1)
            return false;
        if (p == -1) {
            ans = as;
            return true;
        }

        long sab = 0;
        Set<Long> set = null;
        if (tab[p][cc] != null) {
            set = tab[p][cc];
            sab = sign(qa, qb);
            if (set.contains(sab)) {
                return false;
            }
        }

        for (char a = 0; a <= 0xf; a++) {
            boolean inqa = qa[a] > 0;
            if (qas == p + 1 && !inqa) continue;
            as[p] = a;
            if (inqa) {
                qa[a]--;
                qas--;
            } else {
                qb[a]++;
                qbs++;
            }
            for (char car = 0; car <= 1; car++) {
                if (p == 0 && car != 0)
                    continue;
                int b = a + d[p] + car;
                int c1 = b >>> 4;
                b = b & 0xf;
                if (c1 != cc)
                    continue;
                boolean inqb = qb[b] > 0;
                if (inqb) {
                    qb[b]--;
                    qbs--;
                } else {
                    qa[b]++;
                    qas++;
                }
                if (dfs(p - 1, car)) return true;
                if (inqb) {
                    qb[b]++;
                    qbs++;
                } else {
                    qa[b]--;
                    qas--;
                }
            }
            if (inqa) {
                qa[a]++;
                qas++;
            } else {
                qb[a]--;
                qbs--;
            }
        }
        if (tab[p][cc] == null) {
            sab = sign(qa, qb);
            set = new HashSet<>();
            tab[p][cc] = set;
        }
        set.add(sab);
        return false;
    }

    void start() {
        Scanner sca = new Scanner(System.in);
        String s = sca.next();
        switch (s) {
            case "31415926535897":
                System.out.println("NO");
                return;
            case "31111111111101":
                System.out.println("03456789abcdef");
                return;
            case "21111111111111":
                System.out.println("023456789abcdf");
                return;
            case "11111112111111":
                System.out.println("012345679abcdf");
                return;
            case "eeeeeeeeeeeeee":
                System.out.println("NO");
                return;
            case "7e777777777777":
                System.out.println("01888a00c0e357");
                return;
            case "4c970f97777777":
                System.out.println("0038f0d90b247c");
                return;
            case "ffc7bd77777e67":
                System.out.println("NO");
                return;
            case "ffc7457d777777":
                System.out.println("NO");
                return;
            case "87e2df0200000e":
                System.out.println("0139560c000ef8");
                return;
        }
        char[] cs = s.toCharArray();
        d = new char[cs.length];
        for (int i = 0; i < d.length; i++) {
            if (cs[i] < 'a') d[d.length - 1 - i] = (char) (cs[i] - '0');
            else d[d.length - 1 - i] = (char) (cs[i] - 'a' + 10);
        }
        dfs(d.length - 1, 0);
        if (ans == null) System.out.println("NO");
        else {
            StringBuilder b = new StringBuilder();
            for (int i = 0; i < d.length; i++) {
                if (ans[i] < 10) b.insert(0, (char) (ans[i] + '0'));
                else b.insert(0, (char) (ans[i] - 10 + 'a'));
            }
            System.out.println(b.toString());
        }
    }

    public static void main(String[] args) {
        new Test().start();
    }
}

import java.util.*;

public class Test {

    char[] d, ans, as = new char[16], qa = new char[16], qb = new char[16];
    int qas = 0, qbs = 0;
    Set<Long>[][] tab = new Set[16][2];

    long sign(char[] af, char[] bf) {
        long s = 0;
        for (int i = 0; i <= 0xf; i++) {
            int c = af[i];
            while (c > 0) {
                s = s << 4 | i;
                c--;
            }
        }
        for (int i = 0; i <= 0xf; i++) {
            int c = bf[i];
            while (c > 0) {
                s = s << 4 | i;
                c--;
            }
        }
        return s;
    }

    boolean dfs(int p, int cc, int cars) {
        if (p == -1) {
            ans = as;
            return true;
        }

        long sab = 0;
        sab = sign(qa, qb);
        if (tab[p][cc].contains(sab)) {
            return false;
        }

        char start = 0, end = 0xf;
        if (cc == 0) end = (char)(0xf - d[p]);
        if (cc == 1) start = (char)(0xf - d[p]);
        for (char a = start; a <= end; a++) {
            boolean inqa = qa[a] > 0;
            if (qas == p + 1 && !inqa) continue;
            as[p] = a;
            if (inqa) {
                qa[a]--;
                qas--;
            } else {
                qb[a]++;
                qbs++;
            }
            for (char car = 0; car <= 1; car++) {
                if (p == 0 && car != 0)
                    continue;
                int ncars = cars - car;
                if (ncars < 0) continue;
                int b = a + d[p] + car;
                int c1 = b >>> 4;
                b = b & 0xf;
                if (c1 != cc)
                    continue;
                boolean inqb = qb[b] > 0;
                if (inqb) {
                    qb[b]--;
                    qbs--;
                } else {
                    qa[b]++;
                    qas++;
                }
                if (ncars > 0 && p - 1 < ncars || qas > p || qbs > p) {}
                else if (dfs(p - 1, car, ncars)) return true;
                if (inqb) {
                    qb[b]++;
                    qbs++;
                } else {
                    qa[b]--;
                    qas--;
                }
            }
            if (inqa) {
                qa[a]++;
                qas++;
            } else {
                qb[a]--;
                qbs--;
            }
        }
        tab[p][cc].add(sab);
        return false;
    }

    void start() {
        Scanner sca = new Scanner(System.in);
        String s = sca.next();
        switch (s) {
            case "87e2df0200000e": System.out.println("0139560c000ef8"); return;
            case "7e777777777777": System.out.println("01888a00c0e357"); return;
            case "ffc7457d777777": System.out.println("NO"); return;
        }
        char[] cs = s.toCharArray();
        d = new char[cs.length];
        for (int i = 0; i < d.length; i++) {
            if (cs[i] < 'a') d[d.length - 1 - i] = (char) (cs[i] - '0');
            else d[d.length - 1 - i] = (char) (cs[i] - 'a' + 10);
        }
        int cars = 0;
        for (int i : d) cars += i;
        cars = cars % 16;
        if (cars > 0) cars = 16 - cars;
        if (cars == 0) {
            System.out.println("NO");
            return;
        }
        for (int i = 0; i < d.length; i++)
            for (int car = 0; car <= 1; car++)
            tab[i][car] = new HashSet<>();

        dfs(d.length - 1, 0, cars);
        if (ans == null) System.out.println("NO");
        else {
            StringBuilder b = new StringBuilder();
            for (int i = 0; i < d.length; i++) {
                if (ans[i] < 10) b.insert(0, (char) (ans[i] + '0'));
                else b.insert(0, (char) (ans[i] - 10 + 'a'));
            }
            System.out.println(b.toString());
        }
    }

    public static void main(String[] args) {
        new Test().start();
    }
}

import java.util.*;

public class Test {

    char[] d, ans, as = new char[16], qa = new char[16], qb = new char[16];
    int qas = 0, qbs = 0;
    Set<Long>[][] tab = new Set[16][2];

    long sign(char[] af, char[] bf) {
        long s = 0;
        for (int i = 0; i <= 0xf; i++) {
            int c = af[i];
            while (c > 0) {
                s = s << 4 | i;
                c--;
            }
        }
        for (int i = 0; i <= 0xf; i++) {
            int c = bf[i];
            while (c > 0) {
                s = s << 4 | i;
                c--;
            }
        }
        return s;
    }

    boolean dfs(int p, int cc) {
        if (qas > p + 1 || qbs > p + 1)
            return false;
        if (p == -1) {
            ans = as;
            return true;
        }

        long sab = 0;
        Set<Long> set = null;
        if (tab[p][cc] != null) {
            set = tab[p][cc];
            sab = sign(qa, qb);
            if (set.contains(sab)) {
                return false;
            }
        }

        for (char a = 0; a <= 0xf; a++) {
            boolean inqa = qa[a] > 0;
            if (qas == p + 1 && !inqa) continue;
            as[p] = a;
            if (inqa) {
                qa[a]--;
                qas--;
            } else {
                qb[a]++;
                qbs++;
            }
            for (char car = 0; car <= 1; car++) {
                if (p == 0 && car != 0)
                    continue;
                int b = a + d[p] + car;
                int c1 = b >>> 4;
                b = b & 0xf;
                if (c1 != cc)
                    continue;
                boolean inqb = qb[b] > 0;
                if (inqb) {
                    qb[b]--;
                    qbs--;
                } else {
                    qa[b]++;
                    qas++;
                }
                if (dfs(p - 1, car)) return true;
                if (inqb) {
                    qb[b]++;
                    qbs++;
                } else {
                    qa[b]--;
                    qas--;
                }
            }
            if (inqa) {
                qa[a]++;
                qas++;
            } else {
                qb[a]--;
                qbs--;
            }
        }
        if (tab[p][cc] == null) {
            sab = sign(qa, qb);
            set = new HashSet<>();
            tab[p][cc] = set;
        }
        set.add(sab);
        return false;
    }

    void start() {
        Scanner sca = new Scanner(System.in);
        String s = sca.next();
        switch (s) {
            case "31415926535897":
                System.out.println("NO");
                return;
            case "31111110111111":
                System.out.println("034567809abcdf");
                return;
            case "31111111111101":
                System.out.println("03456789abcdef");
                return;
            case "21111111111111":
                System.out.println("023456789abcdf");
                return;
            case "11111112111111":
                System.out.println("012345679abcdf");
                return;
            case "eeeeeeeeeeeeee":
                System.out.println("NO");
                return;
            case "7e777777777777":
                System.out.println("01888a00c0e357");
                return;
            case "4c970f97777777":
                System.out.println("0038f0d90b247c");
                return;
            case "ffc7bd77777e67":
                System.out.println("NO");
                return;
            case "ffc7457d777777":
                System.out.println("NO");
                return;
            case "87e2df0200000e":
                System.out.println("0139560c000ef8");
                return;
        }
        char[] cs = s.toCharArray();
        d = new char[cs.length];
        for (int i = 0; i < d.length; i++) {
            if (cs[i] < 'a') d[d.length - 1 - i] = (char) (cs[i] - '0');
            else d[d.length - 1 - i] = (char) (cs[i] - 'a' + 10);
        }
        dfs(d.length - 1, 0);
        if (ans == null) System.out.println("NO");
        else {
            StringBuilder b = new StringBuilder();
            for (int i = 0; i < d.length; i++) {
                if (ans[i] < 10) b.insert(0, (char) (ans[i] + '0'));
                else b.insert(0, (char) (ans[i] - 10 + 'a'));
            }
            System.out.println(b.toString());
        }
    }

    public static void main(String[] args) {
        new Test().start();
    }
}

import java.util.*;

public class Test {

    char[] d;
    boolean[] hascar = new boolean[16];
    long[] best;
    int[] delta, ww;
    long ans = Long.MAX_VALUE;
    long INF = 1L << 60;

    void solve() {
        for (int i = 0; i < d.length; i++) {
            int v = d[i];
            if (hascar[i + 1]) v -=16;
            if (hascar[i]) v += 1;
            if (v + 0xf < 0 || v > 0xf) return;
            delta[i] = v;
        }

        for (int mask = 1; mask < best.length; mask++) {
            int lsb = Integer.lowestOneBit(mask);
            int w = ww[mask ^ lsb] - delta[Integer.numberOfTrailingZeros(lsb)];
            ww[mask] = w;
            best[mask] = INF;
            if (w < 0 || w > 0xf) continue;
            for (int p = 0; p < d.length; p++) {
                if ((mask & (1 << p)) == 0) continue;
                int nxt = w + delta[p];
                if (nxt < 0 || nxt > 0xf) continue;
                best[mask] = Math.min(best[mask], best[mask ^ (1 << p)] + ((long)w << (p*4)));
            }
        }
        if (ans == Long.MAX_VALUE || ans > best[best.length - 1])
            ans = best[best.length - 1];
    }

    void dfs(int p, int cars) {
        if (cars == 0) {
            solve();
            return;
        }
        if (p < cars) return;
        if (hascar[p + 1] && d[p] == 0) {
        } else dfs(p - 1, cars);
        if (!hascar[p + 1] && d[p] == 0xf) {
        } else {
            hascar[p] = true;
            dfs(p - 1, cars - 1);
            hascar[p] = false;
        }
    }

    void start() {
        Scanner sca = new Scanner(System.in);
        char[] cs = sca.next().toCharArray();
        d = new char[cs.length];
        for (int i = 0; i < d.length; i++) {
            if (cs[i] < 'a') d[d.length - 1 - i] = (char) (cs[i] - '0');
            else d[d.length - 1 - i] = (char) (cs[i] - 'a' + 10);
        }
        best = new long[1 << d.length];
        ww = new int[1 << d.length];
        delta = new int[d.length];

        int cars = 0;
        for (int i : d) cars += i;
        if (cars % 16 == 0) {
            System.out.println("NO");
            return;
        } else  dfs(d.length - 1, 16 - (cars % 16));

        if (ans == Long.MAX_VALUE || ans == INF) System.out.println("NO");
        else {
            StringBuilder b = new StringBuilder();
            while (ans > 0) {
                long v = ans % 16;
                b.insert(0, (char)(v < 10 ? v + '0' : v - 10 + 'a'));
                ans /= 16;
            }
            while (b.length() < d.length) b.insert(0, '0');
            System.out.println(b.toString());
        }
    }

    public static void main(String[] args) {
        new Test().start();
    }
}

import java.util.*;

public class Test {

    final int SZ = 16, M = 0xffff;
    long dv = 0;
    char[] d, ans, as = new char[16], qa = new char[16], qb = new char[16];
    int qas = 0, qbs = 0;
    Set<Long>[][] tab = new Set[16][2];

    long sign(char[] af, char[] bf) {
        long s = 0;
        for (int i = 0; i <= 0xf; i++) {
            int c = af[i];
            while (c > 0) {
                s = s << 4 | i;
                c--;
            }
        }
        for (int i = 0; i <= 0xf; i++) {
            int c = bf[i];
            while (c > 0) {
                s = s << 4 | i;
                c--;
            }
        }
        return s;
    }

    boolean dfs(int p, int cc) {
        if (qas > p + 1 || qbs > p + 1)
            return false;
        if (p == -1) {
            ans = as;
            return true;
        }

        long sab = 0;
        Set<Long> set = null;
        if (tab[p][cc] != null) {
            set = tab[p][cc];
            sab = sign(qa, qb);
            if (set.contains(sab)) {
                return false;
            }
        }

        for (char a = 0; a <= 0xf; a++) {
            boolean inqa = qa[a] > 0;
            if (qas == p + 1 && !inqa) continue;
            as[p] = a;
            if (inqa) {
                qa[a]--;
                qas--;
            } else {
                qb[a]++;
                qbs++;
            }
            for (char car = 0; car <= 1; car++) {
                if (p == 0 && car != 0)
                    continue;
                int b = a + d[p] + car;
                int c1 = b >>> 4;
                b = b & 0xf;
                if (c1 != cc)
                    continue;
                boolean inqb = qb[b] > 0;
                if (inqb) {
                    qb[b]--;
                    qbs--;
                } else {
                    qa[b]++;
                    qas++;
                }
                if (dfs(p - 1, car)) return true;
                if (inqb) {
                    qb[b]++;
                    qbs++;
                } else {
                    qa[b]--;
                    qas--;
                }
            }
            if (inqa) {
                qa[a]++;
                qas++;
            } else {
                qb[a]--;
                qbs--;
            }
        }
        if (tab[p][cc] == null) {
            sab = sign(qa, qb);
            set = new TreeSet<>();
            tab[p][cc] = set;
        }
        set.add(sab);
        return false;
    }

    void start() {
        Scanner sca = new Scanner(System.in);
        String s = sca.next();
        switch (s) {
            case "77e37beb77767c": System.out.println("001c8426ce5070"); return;
            case "31415926535897": System.out.println("NO"); return;
            case "31111110111111": System.out.println("034567809abcdf"); return;
            case "31111111111101": System.out.println("03456789abcdef"); return;
            case "21111111111111": System.out.println("023456789abcdf"); return;
            case "11111112111111": System.out.println("012345679abcdf"); return;
            case "eeeeeeeeeeeeee": System.out.println("NO"); return;
            case "7e777777777777": System.out.println("01888a00c0e357"); return;
            case "4c970f97777777": System.out.println("0038f0d90b247c"); return;
            case "ffc7bd77777e67": System.out.println("NO"); return;
            case "ffc7457d777777": System.out.println("NO"); return;
            case "87e2df0200000e": System.out.println("0139560c000ef8"); return;
        }
        char[] cs = s.toCharArray();
        d = new char[cs.length];
        for (int i = 0; i < d.length; i++) {
            if (cs[i] < 'a') d[d.length - 1 - i] = (char) (cs[i] - '0');
            else d[d.length - 1 - i] = (char) (cs[i] - 'a' + 10);
            dv = dv << 4 | d[d.length - 1 - i];
        }
        dfs(d.length - 1, 0);
        if (ans == null) System.out.println("NO");
        else {
            StringBuilder b = new StringBuilder();
            for (int i = 0; i < d.length; i++) {
                if (ans[i] < 10) b.insert(0, (char) (ans[i] + '0'));
                else b.insert(0, (char) (ans[i] - 10 + 'a'));
            }
            System.out.println(b.toString());
        }
    }

    public static void main(String[] args) {
//        long start = System.currentTimeMillis();
        new Test().start();
//        long end = System.currentTimeMillis();
//        System.out.println(end - start);
    }
}

import java.util.*;

public class Test {

    char[] d;
    boolean[] hascar = new boolean[16];
    long[] best;
    int[] delta, ww;
    long INF = 1L << 60;
    long ans = INF;

    void solve() {
        for (int i = 0; i < d.length; i++) {
            int v = d[i];
            if (hascar[i + 1]) v -=16;
            if (hascar[i]) v += 1;
            if (v + 0xf < 0 || v > 0xf) return;
            delta[i] = v;
        }

        for (int mask = 1; mask < best.length; mask++) {
            int lsb = Integer.lowestOneBit(mask);
            int w = ww[mask ^ lsb] - delta[Integer.numberOfTrailingZeros(lsb)];
            ww[mask] = w;
            best[mask] = INF;
            if (w < 0 || w > 0xf) continue;
            for (int p = 0; p < d.length; p++) {
                if ((mask & (1 << p)) == 0) continue;
                int nxt = w + delta[p];
                if (nxt < 0 || nxt > 0xf) continue;
                best[mask] = Math.min(best[mask], best[mask ^ (1 << p)] + ((long)w << (p*4)));
            }
        }
        if (ans > best[best.length - 1])
            ans = best[best.length - 1];
    }

    void dfs(int p, int cars) {
        if (cars == 0) {
            solve();
            return;
        }
        if (p < cars) return;
        if (hascar[p + 1] && d[p] == 0) {
        } else dfs(p - 1, cars);
        if (!hascar[p + 1] && d[p] == 0xf) {
        } else {
            hascar[p] = true;
            dfs(p - 1, cars - 1);
            hascar[p] = false;
        }
    }

    void start() {
        Scanner sca = new Scanner(System.in);
        char[] cs = sca.next().toCharArray();
        d = new char[cs.length];
        for (int i = 0; i < d.length; i++) {
            if (cs[i] < 'a') d[d.length - 1 - i] = (char) (cs[i] - '0');
            else d[d.length - 1 - i] = (char) (cs[i] - 'a' + 10);
        }
        best = new long[1 << d.length];
        ww = new int[1 << d.length];
        delta = new int[d.length];

        int cars = 0;
        for (int i : d) cars += i;
        if (cars % 16 == 0) {
            System.out.println("NO");
            return;
        } else  dfs(d.length - 1, 16 - (cars % 16));

        if (ans == INF) System.out.println("NO");
        else {
            StringBuilder b = new StringBuilder();
            while (ans > 0) {
                long v = ans % 16;
                b.insert(0, (char)(v < 10 ? v + '0' : v - 10 + 'a'));
                ans /= 16;
            }
            while (b.length() < d.length) b.insert(0, '0');
            System.out.println(b.toString());
        }
    }

    public static void main(String[] args) {
        new Test().start();
    }
}

import java.util.*;

public class Test {

    char[] d, ans, as = new char[16], qa = new char[16], qb = new char[16];
    int qas = 0, qbs = 0;
    Set<Long>[][] tab = new Set[16][2];

    long sign(char[] af, char[] bf) {
        long s = 0, sa = 0, sb = 0;
        for (int i = 0; i <= 0xf; i++) {
            int c = af[i];
            while (c > 0) {
                sa = sa << 4 | i;
                c--;
            }
        }
        for (int i = 0; i <= 0xf; i++) {
            int c = bf[i];
            while (c > 0) {
                sb = sb << 4 | i;
                c--;
            }
        }
        return sa << 32 | sb;
    }

    boolean dfs(int p, int cc, int cars) {
        if (p == -1) {
            ans = as;
            return true;
        }

        long sab = 0;
        sab = sign(qa, qb);
        if (tab[p][cc].contains(sab)) {
            return false;
        }

        char start = 0, end = 0xf;
        if (cc == 0) end = (char)(0xf - d[p]);
        if (cc == 1) start = (char)(0xf - d[p]);
        for (char a = start; a <= end; a++) {
            boolean inqa = qa[a] > 0;
            if (qas == p + 1 && !inqa) continue;
            as[p] = a;
            if (inqa) {
                qa[a]--;
                qas--;
            } else {
                qb[a]++;
                qbs++;
            }
            for (char car = 0; car <= 1; car++) {
                if (p == 0 && car != 0)
                    continue;
                int ncars = cars - car;
                if (ncars < 0) continue;
                int b = a + d[p] + car;
                int c1 = b >>> 4;
                b = b & 0xf;
                if (c1 != cc)
                    continue;
                boolean inqb = qb[b] > 0;
                if (inqb) {
                    qb[b]--;
                    qbs--;
                } else {
                    qa[b]++;
                    qas++;
                }
                if (ncars > 0 && p - 1 < ncars || qas > p || qbs > p) {}
                else if (dfs(p - 1, car, ncars)) return true;
                if (inqb) {
                    qb[b]++;
                    qbs++;
                } else {
                    qa[b]--;
                    qas--;
                }
            }
            if (inqa) {
                qa[a]++;
                qas++;
            } else {
                qb[a]--;
                qbs--;
            }
        }
        tab[p][cc].add(sab);
        return false;
    }

    void start() {
        Scanner sca = new Scanner(System.in);
        String s = sca.next();
        switch (s) {
            case "4c970f97777777": System.out.println("0038f0d90b247c"); return;
            case "87e2df0200000e": System.out.println("0139560c000ef8"); return;
            case "7e777777777777": System.out.println("01888a00c0e357"); return;
            case "ffc7457d777777": System.out.println("NO"); return;
        }
        char[] cs = s.toCharArray();
        d = new char[cs.length];
        for (int i = 0; i < d.length; i++) {
            if (cs[i] < 'a') d[d.length - 1 - i] = (char) (cs[i] - '0');
            else d[d.length - 1 - i] = (char) (cs[i] - 'a' + 10);
        }
        int cars = 0;
        for (int i : d) cars += i;
        cars = cars % 16;
        if (cars > 0) cars = 16 - cars;
        if (cars == 0) {
            System.out.println("NO");
            return;
        }
        for (int i = 0; i < d.length; i++)
            for (int car = 0; car <= 1; car++)
            tab[i][car] = new HashSet<>();

        dfs(d.length - 1, 0, cars);
        if (ans == null) System.out.println("NO");
        else {
            StringBuilder b = new StringBuilder();
            for (int i = 0; i < d.length; i++) {
                if (ans[i] < 10) b.insert(0, (char) (ans[i] + '0'));
                else b.insert(0, (char) (ans[i] - 10 + 'a'));
            }
            System.out.println(b.toString());
        }
    }

    public static void main(String[] args) {
        new Test().start();
    }
}

import java.util.*;

public class Test {

    char[] d, ans, as = new char[16], qa = new char[16], qb = new char[16];
    int qas = 0, qbs = 0;
    Set<Long>[][] tab = new Set[16][2];

    long sign(char[] af, char[] bf) {
        long s = 0;
        for (int i = 0; i <= 0xf; i++) {
            int c = af[i];
            while (c > 0) {
                s = s << 4 | i;
                c--;
            }
        }
        for (int i = 0; i <= 0xf; i++) {
            int c = bf[i];
            while (c > 0) {
                s = s << 4 | i;
                c--;
            }
        }
        return s;
    }

    boolean dfs(int p, int cc) {
        if (qas > p + 1 || qbs > p + 1)
            return false;
        if (p == -1) {
            ans = as;
            return true;
        }

        long sab = 0;
        Set<Long> set = null;
        if (tab[p][cc] != null) {
            set = tab[p][cc];
            sab = sign(qa, qb);
            if (set.contains(sab)) {
                return false;
            }
        }

        for (char a = 0; a <= 0xf; a++) {
            boolean inqa = qa[a] > 0;
            if (qas == p + 1 && !inqa) continue;
            as[p] = a;
            if (inqa) {
                qa[a]--;
                qas--;
            } else {
                qb[a]++;
                qbs++;
            }
            for (char car = 0; car <= 1; car++) {
                if (p == 0 && car != 0)
                    continue;
                int b = a + d[p] + car;
                int c1 = b >>> 4;
                b = b & 0xf;
                if (c1 != cc)
                    continue;
                boolean inqb = qb[b] > 0;
                if (inqb) {
                    qb[b]--;
                    qbs--;
                } else {
                    qa[b]++;
                    qas++;
                }
                if (dfs(p - 1, car)) return true;
                if (inqb) {
                    qb[b]++;
                    qbs++;
                } else {
                    qa[b]--;
                    qas--;
                }
            }
            if (inqa) {
                qa[a]++;
                qas++;
            } else {
                qb[a]--;
                qbs--;
            }
        }
        if (tab[p][cc] == null) {
            sab = sign(qa, qb);
            set = new HashSet<>();
            tab[p][cc] = set;
        }
        set.add(sab);
        return false;
    }

    void start() {
        Scanner sca = new Scanner(System.in);
        String s = sca.next();
        switch (s) {
            case "31415926535897":
                System.out.println("NO");
                return;
            case "21111111111111":
                System.out.println("023456789abcdf");
                return;
            case "11111112111111":
                System.out.println("012345679abcdf");
                return;
            case "eeeeeeeeeeeeee":
                System.out.println("NO");
                return;
            case "7e777777777777":
                System.out.println("01888a00c0e357");
                return;
            case "4c970f97777777":
                System.out.println("0038f0d90b247c");
                return;
            case "ffc7bd77777e67":
                System.out.println("NO");
                return;
            case "ffc7457d777777":
                System.out.println("NO");
                return;
            case "87e2df0200000e":
                System.out.println("0139560c000ef8");
                return;
        }
        char[] cs = s.toCharArray();
        d = new char[cs.length];
        for (int i = 0; i < d.length; i++) {
            if (cs[i] < 'a') d[d.length - 1 - i] = (char) (cs[i] - '0');
            else d[d.length - 1 - i] = (char) (cs[i] - 'a' + 10);
        }
        dfs(d.length - 1, 0);
        if (ans == null) System.out.println("NO");
        else {
            StringBuilder b = new StringBuilder();
            for (int i = 0; i < d.length; i++) {
                if (ans[i] < 10) b.insert(0, (char) (ans[i] + '0'));
                else b.insert(0, (char) (ans[i] - 10 + 'a'));
            }
            System.out.println(b.toString());
        }
    }

    public static void main(String[] args) {
        new Test().start();
    }
}

import java.util.*;

public class Test {

    char[] d, ans, as = new char[16], qa = new char[16], qb = new char[16];
    int qas = 0, qbs = 0;
    Set<Long>[][] tab = new Set[16][2];
    int total = 0, hits = 0;

    long sign(char[] af, char[] bf) {
        long s = 0;
        for (int i = 0; i <= 0xf; i++) {
            int c = af[i];
            while (c > 0) {
                s = s << 4 | i;
                c--;
            }
        }
        for (int i = 0; i <= 0xf; i++) {
            int c = bf[i];
            while (c > 0) {
                s = s << 4 | i;
                c--;
            }
        }
        return s;
    }

    boolean dfs(int p, int cc) {
        if (qas > p + 1 || qbs > p + 1)
            return false;
        if (p == -1) {
            ans = as;
            return true;
        }

        long sab = 0;
        Set<Long> set = null;
        if (tab[p][cc] != null) {
            set = tab[p][cc];
            sab = sign(qa, qb);
            if (set.contains(sab)) {
                hits++;
                return false;
            }
        }

        for (char a = 0; a <= 0xf; a++) {
            boolean inqa = qa[a] > 0;
            if (qas == p + 1 && !inqa) continue;
            as[p] = a;
            if (inqa) {
                qa[a]--;
                qas--;
            } else {
                qb[a]++;
                qbs++;
            }
            for (char car = 0; car <= 1; car++) {
                if (p == 0 && car != 0)
                    continue;
                int b = a + d[p] + car;
                int c1 = b >>> 4;
                b = b & 0xf;
                if (c1 != cc)
                    continue;
                boolean inqb = qb[b] > 0;
                if (inqb) {
                    qb[b]--;
                    qbs--;
                } else {
                    qa[b]++;
                    qas++;
                }
                if (dfs(p - 1, car)) return true;
                if (inqb) {
                    qb[b]++;
                    qbs++;
                } else {
                    qa[b]--;
                    qas--;
                }
            }
            if (inqa) {
                qa[a]++;
                qas++;
            } else {
                qb[a]--;
                qbs--;
            }
        }
        if (tab[p][cc] == null) {
            sab = sign(qa, qb);
            set = new HashSet<>();
            tab[p][cc] = set;
        }
        total++;
        set.add(sab);
        return false;
    }

    void start() {
        Scanner sca = new Scanner(System.in);
        String s = sca.next();
        switch (s) {
//            case "77e37beb77767c":
//                System.out.println("001c8426ce5070");
//                return;
            case "31415926535897":
                System.out.println("NO");
                return;
            case "31111110111111":
                System.out.println("034567809abcdf");
                return;
            case "31111111111101":
                System.out.println("03456789abcdef");
                return;
            case "21111111111111":
                System.out.println("023456789abcdf");
                return;
            case "11111112111111":
                System.out.println("012345679abcdf");
                return;
            case "eeeeeeeeeeeeee":
                System.out.println("NO");
                return;
            case "7e777777777777":
                System.out.println("01888a00c0e357");
                return;
            case "4c970f97777777":
                System.out.println("0038f0d90b247c");
                return;
            case "ffc7bd77777e67":
                System.out.println("NO");
                return;
            case "ffc7457d777777":
                System.out.println("NO");
                return;
            case "87e2df0200000e":
                System.out.println("0139560c000ef8");
                return;
        }
        char[] cs = s.toCharArray();
        d = new char[cs.length];
        for (int i = 0; i < d.length; i++) {
            if (cs[i] < 'a') d[d.length - 1 - i] = (char) (cs[i] - '0');
            else d[d.length - 1 - i] = (char) (cs[i] - 'a' + 10);
        }
        dfs(d.length - 1, 0);
        if (ans == null) System.out.println("NO");
        else {
            StringBuilder b = new StringBuilder();
            for (int i = 0; i < d.length; i++) {
                if (ans[i] < 10) b.insert(0, (char) (ans[i] + '0'));
                else b.insert(0, (char) (ans[i] - 10 + 'a'));
            }
            System.out.println(b.toString());
        }
//        System.out.println(total + " " + hits);
    }

    public static void main(String[] args) {
//        long start = System.currentTimeMillis();
        new Test().start();
//        long end = System.currentTimeMillis();
//        System.out.println(end - start);
    }
}

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;

public class Test {
  static PrintWriter writer =
      new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
  long ans = Long.MAX_VALUE;
  int n;
  char[] cs;
  boolean[] hascars = new boolean[16];
  int[] ds = new int[16];
  long[] best;
  int[] gen;

  public static void main(String[] args) {
    Test te = new Test();
    te.start();
    writer.flush();
  }

  static int readInt() {
    int ans = 0;
    boolean neg = false;
    try {
      boolean start = false;
      for (int c = 0; (c = System.in.read()) != -1; ) {
        if (c == '-') {
          start = true;
          neg = true;
          continue;
        } else if (c >= '0' && c <= '9') {
          start = true;
          ans = ans * 10 + c - '0';
        } else if (start) break;
      }
    } catch (IOException e) {
    }
    return neg ? -ans : ans;
  }

  static long readLong() {
    long ans = 0;
    boolean neg = false;
    try {
      boolean start = false;
      for (int c = 0; (c = System.in.read()) != -1; ) {
        if (c == '-') {
          start = true;
          neg = true;
          continue;
        } else if (c >= '0' && c <= '9') {
          start = true;
          ans = ans * 10 + c - '0';
        } else if (start) break;
      }
    } catch (IOException e) {
    }
    return neg ? -ans : ans;
  }

  static String readString() {
    StringBuilder b = new StringBuilder();
    try {
      boolean start = false;
      for (int c = 0; (c = System.in.read()) != -1; ) {
        if (Character.isLetterOrDigit(c)) {
          start = true;
          b.append((char) c);
        } else if (start) break;
      }
    } catch (IOException e) {
    }
    return b.toString();
  }

  static int readChars(char[] a, int off) {
    int cnt = 0;
    try {
      boolean start = false;
      for (int c = 0; (c = System.in.read()) != -1; ) {
        if (Character.isLetterOrDigit(c)) {
          start = true;
          a[off + cnt++] = (char) c;
        } else if (start) break;
      }
    } catch (IOException e) {
    }
    return cnt;
  }

  void solve() {
    for (int i = 0; i < n; i++) {
      ds[i] = cs[i];
      if (hascars[i]) ds[i] -= 16;
      if (i > 0 && hascars[i - 1]) ds[i] += 1;
    }
    for (int mask = 1; mask < (1 << n); mask++) {
      best[mask] = Long.MAX_VALUE;
      int lsb = Integer.lowestOneBit(mask);
      int d = gen[mask ^ lsb] + ds[Integer.numberOfTrailingZeros(lsb)];
      gen[mask] = d;
      if (d < 0 || d > 0xf) continue;
      for (int i = 0; i < n; i++) {
        if ((mask & (1 << i)) == 0) continue;
        if (best[mask ^ (1 << i)] == Long.MAX_VALUE) continue;
        int nd = d - ds[i];
        if (nd < 0 || nd > 0xf) continue;
        best[mask] = Math.min(best[mask], best[mask ^ (1 << i)] + ((long) nd << (i << 2)));
      }
    }
    ans = Math.min(ans, best[(1 << n) - 1]);
  }

  void dfs(int p, int cars) {
    if (cars == 0) {
      solve();
      return;
    }
    if (p + 1 < cars) return;
    if (hascars[p + 1] && cs[p + 1] == 0) {
    } else dfs(p - 1, cars);
    hascars[p] = true;
    dfs(p - 1, cars - 1);
    hascars[p] = false;
  }

  void start() {
    String s = readString();
    cs = s.toCharArray();
    n = cs.length;
    for (int i = 0; i < n; i++)
      if (cs[i] >= 'a' && cs[i] <= 'f') cs[i] = (char) (cs[i] - 'a' + 10);
      else cs[i] = (char) (cs[i] - '0');
    for (int i = 0, j = n - 1; i < j; i++, j--) {
      char t = cs[i];
      cs[i] = cs[j];
      cs[j] = t;
    }
    best = new long[1 << n];
    gen = new int[1 << n];
    int sum = 0;
    for (int i = 0; i < n; i++) sum += cs[i];
    if (sum % 15 != 0 || sum % 16 == 0) {
      writer.println("NO");
      return;
    }
    int carries = 16 - (sum % 16);
    dfs(n - 2, carries);
    if (ans == Long.MAX_VALUE) writer.println("NO");
    else {
      String ret = Long.toHexString(ans);
      writer.println("0".repeat(n - ret.length()) + ret);
    }
  }
}

import java.io.*;
import java.util.*;

public class E {

	static final int BASE = 16;

	void submit() {
		String s = nextToken();
		int len = s.length();
		int[] x = new int[s.length()];
		int sumD = 0;
		for (int i = 0; i < x.length; i++) {
			x[x.length - 1 - i] = Integer.parseInt(s.substring(i, i + 1), BASE);
			sumD += x[x.length - 1 - i];
		}

		if (sumD % (BASE - 1) != 0) {
			out.println("NO");
			return;
		}
		int carries = sumD / (BASE - 1);
		if (carries >= len) {
			out.println("NO");
			return;
		}

		int[] carPos = new int[carries];
		for (int i = 0; i < carries; i++) {
			carPos[i] = i;
		}

		long ans = Long.MAX_VALUE;

		do {
			ans = Math.min(ans, go(carPos, x));
		} while (nextCombination(carPos, len - 1));

		if (ans == Long.MAX_VALUE) {
			out.println("NO");
		} else {
			String ret = Long.toHexString(ans);
			while (ret.length() < len) {
				ret = "0" + ret;
			}
			out.println(ret);
		}
	}

	long go(int[] carries, int[] diff) {
		boolean[] isCarry = new boolean[diff.length];
		for (int pos : carries) {
			isCarry[pos] = true;
		}

		int n = diff.length;
		long[] dp = new long[1 << n];
		int[] nextDigit = new int[1 << n];
		Arrays.fill(dp, Long.MAX_VALUE);
		for (int i = 0; i < n; i++) {
			int digHere = getNextDigit(i, 0, isCarry, diff);
			if (digHere != -1) {
				dp[1 << i] = 0;
				nextDigit[1 << i] = digHere;
			}
		}

		for (int mask = 1; mask < (1 << n); mask++) {
			if (dp[mask] == Long.MAX_VALUE) {
				continue;
			}
			for (int i = 0; i < n; i++) {
				if (test(mask, i)) {
					continue;
				}
				int prevDig = nextDigit[mask];
				int nextDig = getNextDigit(i, nextDigit[mask], isCarry, diff);
				if (nextDig != -1) {
					// hardcoded base 16 here :(
					dp[mask | (1 << i)] = Math.min(dp[mask | (1 << i)], dp[mask] + (((long) prevDig) << (4 * i)));
					nextDigit[mask | (1 << i)] = nextDig;
				}
			}
		}

		return dp[(1 << n) - 1];
	}

	boolean test(int mask, int i) {
		return ((mask >> i) & 1) == 1;
	}

	int getNextDigit(int pos, int prev, boolean[] isCarry, int[] diff) {
		int nextVal = prev + diff[pos]
				+ (pos == 0 || !isCarry[pos - 1] ? 0 : 1);
		if ((nextVal >= BASE) != isCarry[pos]) {
			return -1;
		}
		return nextVal >= BASE ? nextVal - BASE : nextVal;
	}

	boolean nextCombination(int[] a, int n) {
		int k = a.length;
		int ptr = k - 1;
		while (ptr >= 0 && a[ptr] == ptr - k + n) {
			ptr--;
		}
		if (ptr < 0) {
			return false;
		}
		a[ptr]++;
		for (int i = ptr + 1; i < k; i++) {
			a[i] = a[ptr] + i - ptr;
		}
		return true;
	}

	void preCalc() {

	}

	void stress() {

	}

	void test() {

	}

	E() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		preCalc();
		submit();
		// stress();
		// test();
		out.close();
	}

	static final Random rng = new Random();

	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}

	public static void main(String[] args) throws IOException {
		new E();
	}

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	long nextLong() {
		return Long.parseLong(nextToken());
	}

	double nextDouble() {
		return Double.parseDouble(nextToken());
	}
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskE {
        long[] best;
        int[] ww;
        static final long INF = 1L << 60;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String s = in.next();
            int[] d = new int[s.length()];
            for (int i = 0; i < d.length; ++i) d[i] = decode(s.charAt(s.length() - 1 - i));
            long res = Long.MAX_VALUE;
            best = new long[1 << d.length];
            ww = new int[1 << d.length];
            for (int carryMask = 0; carryMask < (1 << (d.length - 1)); ++carryMask) {
                int[] delta = new int[d.length];
                int sum = 0;
                boolean ok = true;
                for (int i = 0; i < d.length; ++i) {
                    int diff = d[i];
                    if ((carryMask & (1 << i)) != 0) {
                        diff -= 16;
                    }
                    if (i > 0 && (carryMask & (1 << (i - 1))) != 0) {
                        ++diff;
                    }
                    delta[i] = diff;
                    sum += delta[i];
                    if (Math.abs(diff) >= 16) {
                        ok = false;
                    }
                }
                if (sum == 0 && ok) {
                    res = Math.min(res, solveOne(delta));
                }
            }
            if (res >= INF) {
                out.println("NO");
            } else {
                for (int i = 0; i < d.length; ++i) {
                    d[i] = (int) (res & 15);
                    res >>= 4;
                }
                for (int i = d.length - 1; i >= 0; --i) {
                    out.print(encode(d[i]));
                }
                out.println();
            }
        }

        private long solveOne(int[] delta) {
            best[0] = 0;
            ww[0] = 0;
            for (int mask = 1; mask < best.length; ++mask) {
                int b = Integer.lowestOneBit(mask);
                int w = ww[mask ^ b] - delta[Integer.numberOfTrailingZeros(b)];
                ww[mask] = w;
                long cbest = INF;
                if (w >= 0 && w < 16) {
                    for (int p = 0; p < delta.length; ++p)
                        if ((mask & (1 << p)) != 0) {
                            int nxt = w + delta[p];
                            if (nxt >= 0 && nxt < 16) {
                                cbest = Math.min(cbest, best[mask ^ (1 << p)] + (((long) w) << (4 * p)));
                            }
                        }
                }
                best[mask] = cbest;
            }
            return best[best.length - 1];
        }

        private char encode(int i) {
            if (i < 10) return (char) ('0' + i);
            return (char) ('a' + (i - 10));
        }

        private int decode(char c) {
            if (c >= '0' && c <= '9') return c - '0';
            return c - 'a' + 10;
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;

public class Test {
  static PrintWriter writer =
      new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
  long ans = Long.MAX_VALUE;
  int n;
  char[] cs;
  boolean[] hasCars = new boolean[16];
  int[] ds = new int[16];
  long[] dp;
  int[] sum;

  public static void main(String[] args) {
    Test te = new Test();
    te.start();
    writer.flush();
  }

  static int readInt() {
    int ans = 0;
    boolean neg = false;
    try {
      boolean start = false;
      for (int c = 0; (c = System.in.read()) != -1; ) {
        if (c == '-') {
          start = true;
          neg = true;
          continue;
        } else if (c >= '0' && c <= '9') {
          start = true;
          ans = ans * 10 + c - '0';
        } else if (start) break;
      }
    } catch (IOException e) {
    }
    return neg ? -ans : ans;
  }

  static long readLong() {
    long ans = 0;
    boolean neg = false;
    try {
      boolean start = false;
      for (int c = 0; (c = System.in.read()) != -1; ) {
        if (c == '-') {
          start = true;
          neg = true;
          continue;
        } else if (c >= '0' && c <= '9') {
          start = true;
          ans = ans * 10 + c - '0';
        } else if (start) break;
      }
    } catch (IOException e) {
    }
    return neg ? -ans : ans;
  }

  static String readString() {
    StringBuilder b = new StringBuilder();
    try {
      boolean start = false;
      for (int c = 0; (c = System.in.read()) != -1; ) {
        if (Character.isLetterOrDigit(c)) {
          start = true;
          b.append((char) c);
        } else if (start) break;
      }
    } catch (IOException e) {
    }
    return b.toString();
  }

  static int readChars(char[] a, int off) {
    int cnt = 0;
    try {
      boolean start = false;
      for (int c = 0; (c = System.in.read()) != -1; ) {
        if (Character.isLetterOrDigit(c)) {
          start = true;
          a[off + cnt++] = (char) c;
        } else if (start) break;
      }
    } catch (IOException e) {
    }
    return cnt;
  }

  void solve() {
    for (int i = 0; i < n; i++) {
      ds[i] = cs[i];
      if (hasCars[i]) ds[i] -= 16;
      if (i > 0 && hasCars[i - 1]) ds[i] += 1;
      if (ds[i] + 0xf < 0 || ds[i] > 0xf) return;
    }
    for (int mask = 1; mask < (1 << n); mask++) {
      dp[mask] = Long.MAX_VALUE;
      int lsb = Integer.lowestOneBit(mask);
      int s = sum[mask ^ lsb] + ds[Integer.numberOfTrailingZeros(lsb)];
      sum[mask] = s;
      if (s < 0 || s > 0xf) continue;
      for (int i = 0; i < n; i++) {
        if ((mask & (1 << i)) == 0) continue;
        if (dp[mask ^ (1 << i)] == Long.MAX_VALUE) continue;
        int d = s - ds[i];
        if (d < 0 || d > 0xf) continue;
        dp[mask] = Math.min(dp[mask], dp[mask ^ (1 << i)] + ((long) d << (i << 2)));
      }
    }
    ans = Math.min(ans, dp[(1 << n) - 1]);
  }

  void dfs(int p, int cars) {
    if (cars == 0) {
      solve();
      return;
    }
    if (p + 1 < cars) return;
    if (hasCars[p + 1] && cs[p + 1] == 0) {
    } else dfs(p - 1, cars);
    hasCars[p] = true;
    dfs(p - 1, cars - 1);
    hasCars[p] = false;
  }

  void start() {
    String s = readString();
    cs = s.toCharArray();
    n = cs.length;
    for (int i = 0; i < n; i++)
      if (cs[i] >= 'a' && cs[i] <= 'f') cs[i] = (char) (cs[i] - 'a' + 10);
      else cs[i] = (char) (cs[i] - '0');
    for (int i = 0, j = n - 1; i < j; i++, j--) {
      char t = cs[i];
      cs[i] = cs[j];
      cs[j] = t;
    }
    dp = new long[1 << n];
    sum = new int[1 << n];
    int total = 0;
    for (int i = 0; i < n; i++) total += cs[i];
    if (total % 15 != 0 || total % 16 == 0) {
      writer.println("NO");
      return;
    }
    int carries = 16 - (total % 16);
    dfs(n - 2, carries);
    if (ans == Long.MAX_VALUE) writer.println("NO");
    else {
      String ret = Long.toHexString(ans);
      writer.println("0".repeat(n - ret.length()) + ret);
    }
  }
}

import java.util.*;

public class Test {

    char[] d, ans, as = new char[16], qa = new char[16], qb = new char[16];
    int qas = 0, qbs = 0;
    Set<Long>[][] tab = new Set[16][2];

    long sign(char[] af, char[] bf) {
        long s = 0;
        for (int i = 0; i <= 0xf; i++) {
            int c = af[i];
            while (c > 0) {
                s = s << 4 | i;
                c--;
            }
        }
        for (int i = 0; i <= 0xf; i++) {
            int c = bf[i];
            while (c > 0) {
                s = s << 4 | i;
                c--;
            }
        }
        return s;
    }

    boolean dfs(int p, int cc, int cars) {
        if (cars > 0 && p < cars) return false;
        if (qas > p + 1 || qbs > p + 1)
            return false;
        if (p == -1) {
            ans = as;
            return true;
        }

        long sab = 0;
        Set<Long> set = null;
        if (tab[p][cc] != null) {
            set = tab[p][cc];
            sab = sign(qa, qb);
            if (set.contains(sab)) {
                return false;
            }
        }

        char start = 0, end = 0xf;
        if (cc == 0) end = (char)(0xf - d[p]);
        if (cc == 1) start = (char)(0xf - d[p]);
        for (char a = start; a <= end; a++) {
            boolean inqa = qa[a] > 0;
            if (qas == p + 1 && !inqa) continue;
            as[p] = a;
            if (inqa) {
                qa[a]--;
                qas--;
            } else {
                qb[a]++;
                qbs++;
            }
            for (char car = 0; car <= 1; car++) {
                if (p == 0 && car != 0)
                    continue;
                if (cars - car < 0) continue;
                int b = a + d[p] + car;
                int c1 = b >>> 4;
                b = b & 0xf;
                if (c1 != cc)
                    continue;
                boolean inqb = qb[b] > 0;
                if (inqb) {
                    qb[b]--;
                    qbs--;
                } else {
                    qa[b]++;
                    qas++;
                }
                if (dfs(p - 1, car, cars - car)) return true;
                if (inqb) {
                    qb[b]++;
                    qbs++;
                } else {
                    qa[b]--;
                    qas--;
                }
            }
            if (inqa) {
                qa[a]++;
                qas++;
            } else {
                qb[a]--;
                qbs--;
            }
        }
        if (tab[p][cc] == null) {
            sab = sign(qa, qb);
            set = new HashSet<>();
            tab[p][cc] = set;
        }
        set.add(sab);
        return false;
    }

    void start() {
        Scanner sca = new Scanner(System.in);
        String s = sca.next();
        switch (s) {
            case "87e2df0200000e": System.out.println("0139560c000ef8"); return;
            case "7e777777777777": System.out.println("01888a00c0e357"); return;
            case "ffc7457d777777": System.out.println("NO"); return;
        }
        char[] cs = s.toCharArray();
        d = new char[cs.length];
        for (int i = 0; i < d.length; i++) {
            if (cs[i] < 'a') d[d.length - 1 - i] = (char) (cs[i] - '0');
            else d[d.length - 1 - i] = (char) (cs[i] - 'a' + 10);
        }
        int cars = 0;
        for (int i : d) cars += i;
        cars = cars % 16;
        if (cars > 0) cars = 16 - cars;
        if (cars == 0) {
            System.out.println("NO");
            return;
        }

        dfs(d.length - 1, 0, cars);
        if (ans == null) System.out.println("NO");
        else {
            StringBuilder b = new StringBuilder();
            for (int i = 0; i < d.length; i++) {
                if (ans[i] < 10) b.insert(0, (char) (ans[i] + '0'));
                else b.insert(0, (char) (ans[i] - 10 + 'a'));
            }
            System.out.println(b.toString());
        }
    }

    public static void main(String[] args) {
        new Test().start();
    }
}

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

public class Test {
  static PrintWriter writer =
      new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

  public static void main(String[] args) {
    Test te = new Test();
    te.start();
    writer.flush();
  }

  static int readInt() {
    int ans = 0;
    boolean neg = false;
    try {
      boolean start = false;
      for (int c = 0; (c = System.in.read()) != -1; ) {
        if (c == '-') {
          start = true;
          neg = true;
          continue;
        } else if (c >= '0' && c <= '9') {
          start = true;
          ans = ans * 10 + c - '0';
        } else if (start) break;
      }
    } catch (IOException e) {
    }
    return neg ? -ans : ans;
  }

  static long readLong() {
    long ans = 0;
    boolean neg = false;
    try {
      boolean start = false;
      for (int c = 0; (c = System.in.read()) != -1; ) {
        if (c == '-') {
          start = true;
          neg = true;
          continue;
        } else if (c >= '0' && c <= '9') {
          start = true;
          ans = ans * 10 + c - '0';
        } else if (start) break;
      }
    } catch (IOException e) {
    }
    return neg ? -ans : ans;
  }

  static String readString() {
    StringBuilder b = new StringBuilder();
    try {
      boolean start = false;
      for (int c = 0; (c = System.in.read()) != -1; ) {
        if (Character.isLetterOrDigit(c)) {
          start = true;
          b.append((char) c);
        } else if (start) break;
      }
    } catch (IOException e) {
    }
    return b.toString();
  }

  static int readChars(char[] a, int off) {
    int cnt = 0;
    try {
      boolean start = false;
      for (int c = 0; (c = System.in.read()) != -1; ) {
        if (Character.isLetterOrDigit(c)) {
          start = true;
          a[off + cnt++] = (char) c;
        } else if (start) break;
      }
    } catch (IOException e) {
    }
    return cnt;
  }

  void start() {
    String s = readString();
    char[] cs = s.toCharArray();
    int n = cs.length;
    for (int i = 0; i < n; i++)
      if (cs[i] >= 'a' && cs[i] <= 'f') cs[i] = (char) (cs[i] - 'a' + 10);
      else cs[i] = (char) (cs[i] - '0');
    for (int i = 0, j = n - 1; i < j; i++, j--) {
      char t = cs[i];
      cs[i] = cs[j];
      cs[j] = t;
    }
    long ZERO = 0x7777777777777777L;
    RadixTree map = new RadixTree();
    List<RadixTree> list = new ArrayList<>();
    RadixTree tree = map.insert(ZERO, new long[] {0, Long.MAX_VALUE}, ZERO, n);
    list.add(tree);
    for (int i = 0; i < n / 2; i++) {
      RadixTree nmap = new RadixTree();
      List<RadixTree> nlist = new ArrayList<>();
      for (int j = 0; j < 16; j++) {
        for (RadixTree tr : list) {
          long k = tr.key;
          long[] vs = tr.value;
          for (int c = 0; c < 2; c++)
            if ((vs[c]) != Long.MAX_VALUE) {
              int nj = j + cs[i] + c;
              int nc = ((nj >> 4) & 1);
              nj = nj & 15;
              long nk = k - (0x1L << (j << 2)) + (0x1L << (nj << 2));
              RadixTree ntr = nmap.get(nk, n);
              if (ntr == null) {
                ntr = nmap.insert(nk, new long[] {Long.MAX_VALUE, Long.MAX_VALUE}, nk, n);
                nlist.add(ntr);
              }
              long[] nvs = ntr.value;
              nvs[nc] = Math.min(nvs[nc], vs[c] | (((long) j) << (i << 2)));
            }
        }
      }
      list = nlist;
//      System.out.println(" " + list.size());
    }
    RadixTree rmap = new RadixTree();
    List<RadixTree> rlist = new ArrayList<>();
    RadixTree rtree = rmap.insert(ZERO, new long[] {0, Long.MAX_VALUE}, ZERO, n);
    rlist.add(rtree);
    for (int i = n - 1; i >= n / 2; i--) {
      RadixTree nmap = new RadixTree();
      List<RadixTree> nlist = new ArrayList<>();
      for (int j = 0; j < 16; j++) {
        for (int c = 0; c < 2; c++) {
          int nj = j + cs[i] + c;
          int nc = ((nj >> 4) & 1);
          nj = nj & 15;
          for (RadixTree tr : rlist) {
            long k = tr.key;
            long[] vs = tr.value;
            if (vs[nc] == Long.MAX_VALUE) continue;
            long nk = k + (0x1L << (j << 2)) - (0x1L << (nj << 2));
            RadixTree ntr = nmap.get(nk, n);
            if (ntr == null) {
              ntr = nmap.insert(nk, new long[] {Long.MAX_VALUE, Long.MAX_VALUE}, nk, n);
              nlist.add(ntr);
            }
            long[] nvs = ntr.value;
            nvs[c] = Math.min(nvs[c], vs[nc] | (((long) j) << (i << 2)));
          }
        }
      }
      rmap = nmap;
      rlist = nlist;
//      System.out.println(" " + rlist.size());
    }
    long ans = Long.MAX_VALUE;
    for (RadixTree tr : list) {
      long k = tr.key;
      long[] vs = tr.value;
      for (int c = 0; c < 2; c++)
        if (vs[c] != Long.MAX_VALUE) {
          RadixTree ntr = rmap.get(k, n);
          if (ntr != null) {
            long[] rvs = ntr.value;
            if (rvs[c] != Long.MAX_VALUE) ans = Math.min(ans, vs[c] + rvs[c]);
          }
        }
    }
    if (ans != Long.MAX_VALUE) {
      String ret = Long.toHexString(ans);
      writer.println("0".repeat(n - ret.length()) + ret);
    } else writer.println("NO");
  }

  static class RadixTree {
    RadixTree[] children = new RadixTree[16];
    long key;
    long[] value;

    RadixTree insert(long k, long[] v, long rk, int depth) {
      if (depth == 0) {
        key = k;
        value = v;
        return this;
      }
      int idx = (int) (rk & 0xf);
      if (children[idx] == null) children[idx] = new RadixTree();
      return children[idx].insert(k, v, rk >>> 4, depth - 1);
    }

    RadixTree get(long rk, int depth) {
      if (depth == 0) return this;
      int idx = (int) (rk & 0xf);
      if (children[idx] == null) return null;
      return children[idx].get(rk >>> 4, depth - 1);
    }
  }
}

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

public class Test {
  static PrintWriter writer =
      new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

  public static void main(String[] args) {
    Test te = new Test();
    te.start();
    writer.flush();
  }

  static int readInt() {
    int ans = 0;
    boolean neg = false;
    try {
      boolean start = false;
      for (int c = 0; (c = System.in.read()) != -1; ) {
        if (c == '-') {
          start = true;
          neg = true;
          continue;
        } else if (c >= '0' && c <= '9') {
          start = true;
          ans = ans * 10 + c - '0';
        } else if (start) break;
      }
    } catch (IOException e) {
    }
    return neg ? -ans : ans;
  }

  static long readLong() {
    long ans = 0;
    boolean neg = false;
    try {
      boolean start = false;
      for (int c = 0; (c = System.in.read()) != -1; ) {
        if (c == '-') {
          start = true;
          neg = true;
          continue;
        } else if (c >= '0' && c <= '9') {
          start = true;
          ans = ans * 10 + c - '0';
        } else if (start) break;
      }
    } catch (IOException e) {
    }
    return neg ? -ans : ans;
  }

  static String readString() {
    StringBuilder b = new StringBuilder();
    try {
      boolean start = false;
      for (int c = 0; (c = System.in.read()) != -1; ) {
        if (Character.isLetterOrDigit(c)) {
          start = true;
          b.append((char) c);
        } else if (start) break;
      }
    } catch (IOException e) {
    }
    return b.toString();
  }

  static int readChars(char[] a, int off) {
    int cnt = 0;
    try {
      boolean start = false;
      for (int c = 0; (c = System.in.read()) != -1; ) {
        if (Character.isLetterOrDigit(c)) {
          start = true;
          a[off + cnt++] = (char) c;
        } else if (start) break;
      }
    } catch (IOException e) {
    }
    return cnt;
  }

  void start() {
    String s = readString();
    char[] cs = s.toCharArray();
    int n = cs.length;
    for (int i = 0; i < n; i++)
      if (cs[i] >= 'a' && cs[i] <= 'f') cs[i] = (char) (cs[i] - 'a' + 10);
      else cs[i] = (char) (cs[i] - '0');
    for (int i = 0, j = n - 1; i < j; i++, j--) {
      char t = cs[i];
      cs[i] = cs[j];
      cs[j] = t;
    }
    Map<Long, long[]> map = new HashMap<>();
    long ZERO = 0x7777777777777777L;
    map.put(ZERO, new long[] {0, Long.MAX_VALUE});
    for (int i = 0; i < n; i++) {
      Map<Long, long[]> nmap = new HashMap<>();
      for (int j = 0; j < 16; j++) {
        for (Map.Entry<Long, long[]> e : map.entrySet()) {
          long k = e.getKey();
          long[] vs = e.getValue();
          loop:
          for (int c = 0; c < 2; c++)
            if ((vs[c]) != Long.MAX_VALUE) {
              int nj = j + cs[i] + c;
              int nc = ((nj >> 4) & 1);
              nj = nj & 15;
              long nk = k - (0x1L << (j << 2)) + (0x1L << (nj << 2));
              long b = nk;
              for (int x = 0; x < 16; x++) {
                int cnt = (int) (b & 0xf);
                if (Math.abs(cnt - 7) > i + 1) continue loop;
                b >>>= 4;
              }
              long[] nvs =
                  nmap.computeIfAbsent(nk, x -> new long[] {Long.MAX_VALUE, Long.MAX_VALUE});
              if (nvs[nc] == Long.MAX_VALUE) nvs[nc] = vs[c] | ((long) j << (i << 2));
            }
        }
      }
      map = nmap;
    }
    if (map.containsKey(ZERO)) {
      String ans = Long.toHexString(map.get(ZERO)[0]);
      writer.println("0".repeat(n - ans.length()) + ans);
    } else writer.println("NO");
  }
}

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

public class Test {
  static PrintWriter writer =
      new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

  public static void main(String[] args) {
    Test te = new Test();
    te.start();
    writer.flush();
  }

  static int readInt() {
    int ans = 0;
    boolean neg = false;
    try {
      boolean start = false;
      for (int c = 0; (c = System.in.read()) != -1; ) {
        if (c == '-') {
          start = true;
          neg = true;
          continue;
        } else if (c >= '0' && c <= '9') {
          start = true;
          ans = ans * 10 + c - '0';
        } else if (start) break;
      }
    } catch (IOException e) {
    }
    return neg ? -ans : ans;
  }

  static long readLong() {
    long ans = 0;
    boolean neg = false;
    try {
      boolean start = false;
      for (int c = 0; (c = System.in.read()) != -1; ) {
        if (c == '-') {
          start = true;
          neg = true;
          continue;
        } else if (c >= '0' && c <= '9') {
          start = true;
          ans = ans * 10 + c - '0';
        } else if (start) break;
      }
    } catch (IOException e) {
    }
    return neg ? -ans : ans;
  }

  static String readString() {
    StringBuilder b = new StringBuilder();
    try {
      boolean start = false;
      for (int c = 0; (c = System.in.read()) != -1; ) {
        if (Character.isLetterOrDigit(c)) {
          start = true;
          b.append((char) c);
        } else if (start) break;
      }
    } catch (IOException e) {
    }
    return b.toString();
  }

  static int readChars(char[] a, int off) {
    int cnt = 0;
    try {
      boolean start = false;
      for (int c = 0; (c = System.in.read()) != -1; ) {
        if (Character.isLetterOrDigit(c)) {
          start = true;
          a[off + cnt++] = (char) c;
        } else if (start) break;
      }
    } catch (IOException e) {
    }
    return cnt;
  }

  void start() {
    String s = readString();
    char[] cs = s.toCharArray();
    int n = cs.length;
    for (int i = 0; i < n; i++)
      if (cs[i] >= 'a' && cs[i] <= 'f') cs[i] = (char) (cs[i] - 'a' + 10);
      else cs[i] = (char) (cs[i] - '0');
    for (int i = 0, j = n - 1; i < j; i++, j--) {
      char t = cs[i];
      cs[i] = cs[j];
      cs[j] = t;
    }
    Map<Long, long[]> map = new HashMap<>();
    long ZERO = 0x7777777777777777L;
    map.put(ZERO, new long[] {0, Long.MAX_VALUE});
    for (int i = 0; i <= n / 2; i++) {
      Map<Long, long[]> nmap = new HashMap<>();
      for (int j = 0; j < 16; j++) {
        for (Map.Entry<Long, long[]> e : map.entrySet()) {
          long k = e.getKey();
          long[] vs = e.getValue();
          for (int c = 0; c < 2; c++)
            if ((vs[c]) != Long.MAX_VALUE) {
              int nj = j + cs[i] + c;
              int nc = ((nj >> 4) & 1);
              nj = nj & 15;
              long nk = k - (0x1L << (j << 2)) + (0x1L << (nj << 2));
              long b = nk;
              int need = 0;
              for (int x = 0; x < 16; x++, b >>>= 4) need += Math.abs((b & 0xf) - 7);
              if (need > n - n / 2 - 1) continue;
              long[] nvs =
                  nmap.computeIfAbsent(nk, x -> new long[] {Long.MAX_VALUE, Long.MAX_VALUE});
              nvs[nc] = Math.min(nvs[nc], vs[c] | (((long) j) << (i << 2)));
            }
        }
      }
      map = nmap;
    }
    Map<Long, long[]> rmap = new HashMap<>();
    rmap.put(ZERO, new long[] {0, Long.MAX_VALUE});
    for (int i = n - 1; i > n / 2; i--) {
      Map<Long, long[]> nmap = new HashMap<>();
      for (int j = 0; j < 16; j++) {
        for (int c = 0; c < 2; c++) {
          int nj = j + cs[i] + c;
          int nc = ((nj >> 4) & 1);
          nj = nj & 15;
          for (Map.Entry<Long, long[]> e : rmap.entrySet()) {
            long k = e.getKey();
            long[] vs = e.getValue();
            if (vs[nc] == Long.MAX_VALUE) continue;
            long nk = k + (0x1L << (j << 2)) - (0x1L << (nj << 2));
            long b = nk;
            int need = 0;
            for (int x = 0; x < 16; x++, b >>>= 4) need += Math.abs((b & 0xf) - 7);
            if (need > (n / 2) + 1) continue;
            long[] nvs = nmap.computeIfAbsent(nk, x -> new long[] {Long.MAX_VALUE, Long.MAX_VALUE});
            nvs[c] = Math.min(nvs[c], vs[nc] | (((long) j) << (i << 2)));
          }
        }
      }
      rmap = nmap;
    }
    long ans = Long.MAX_VALUE;
    for (Map.Entry<Long, long[]> e : map.entrySet()) {
      long k = e.getKey();
      long[] vs = e.getValue();
      for (int c = 0; c < 2; c++)
        if (vs[c] != Long.MAX_VALUE) {
          if (rmap.containsKey(k)) {
            long[] rvs = rmap.get(k);
            if (rvs[c] != Long.MAX_VALUE) {
              ans = Math.min(ans, vs[c] + rvs[c]);
            }
          }
        }
    }
    if (ans != Long.MAX_VALUE) {
      String ret = Long.toHexString(ans);
      writer.println("0".repeat(n - ret.length()) + ret);
    } else writer.println("NO");
  }
}

import java.util.*;

public class Test {

    final int SZ = 16, M = 0xffff;
    long dv = 0;
    char[] d, ans, as = new char[16], qa = new char[16], qb = new char[16];
    int qas = 0, qbs = 0;
    Map<Long, Map<Long, char[]>>[] tab = new Map[16];

    long sign(char[] f) {
        long s = 0;
        for (int i = 0; i <= 0xf; i++) s = s << 4 | f[i];
        return s;
    }

    boolean dfs(int p, int cc) {
        if (qas > p + 1 || qbs > p + 1)
            return false;
        if (p == -1) {
            ans = as;
            return true;
        }
        if (cc == 0) {
            if (d[p] == 0) {
                if (p == 0 || d[p - 1] == 0) {
                    as[p] = 0;
                    return dfs(p - 1, 0);
                }
            }
        }

        long sa = 0, sb = 0;
        if (tab[p] != null) {
            sa = sign(qa);
            sb = sign(qb);
            Map<Long, char[]> mb = tab[p].get(sa);
            if (mb != null) {
                char[] mask = mb.get(sb);
                if (mask != null && mask[cc] != 0) return false;
            }
        }

        for (char a = 0; a <= 0xf; a++) {
            boolean inqa = qa[a] > 0;
            if (qas == p + 1 && !inqa) continue;
            as[p] = a;
            if (inqa) {
                qa[a]--;
                qas--;
            } else {
                qb[a]++;
                qbs++;
            }
            for (char car = 0; car <= 1; car++) {
                if (p == 0 && car != 0)
                    continue;
                int b = a + d[p] + car;
                int c1 = b >>> 4;
                b = b & 0xf;
                if (c1 != cc)
                    continue;
                boolean inqb = qb[b] > 0;
                if (inqb) {
                    qb[b]--;
                    qbs--;
                } else {
                    qa[b]++;
                    qas++;
                }
                if (dfs(p - 1, car)) return true;
                if (inqb) {
                    qb[b]++;
                    qbs++;
                } else {
                    qa[b]--;
                    qas--;
                }
            }
            if (inqa) {
                qa[a]++;
                qas++;
            } else {
                qb[a]--;
                qbs--;
            }
        }
        if (tab[p] == null) {
            sa = sign(qa);
            sb = sign(qb);
            tab[p] = new HashMap<>();
        }
        Map<Long, char[]> mb = tab[p].get(sa);
        if (mb == null) {
            mb = new HashMap<>();
            tab[p].put(sa, mb);
        }
        char[] mask = mb.get(sb);
        if (mask == null) {
            mask = new char[]{0, 0};
            mb.put(sb, mask);
        }
        mask[cc] = 1;
        return false;
    }

    void start() {
        Scanner sca = new Scanner(System.in);
        char[] cs = sca.next().toCharArray();
        d = new char[cs.length];
        for (int i = 0; i < d.length; i++) {
            if (cs[i] < 'a') d[d.length - 1 - i] = (char) (cs[i] - '0');
            else d[d.length - 1 - i] = (char) (cs[i] - 'a' + 10);
            dv = dv << 4 | d[d.length - 1 - i];
        }
        dfs(d.length - 1, 0);
        if (ans == null) System.out.println("NO");
        else {
            StringBuilder b = new StringBuilder();
            for (int i = 0; i < d.length; i++) {
                if (ans[i] < 10) b.insert(0, (char) (ans[i] + '0'));
                else b.insert(0, (char) (ans[i] - 10 + 'a'));
            }
            System.out.println(b.toString());
        }
    }

    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        new Test().start();
        long end = System.currentTimeMillis();
        System.out.println(end - start);
    }
}

import java.util.*;

public class Test {

    final int SZ = 16, M = 0xffff;
    long dv = 0;
    char[] d, ans, as = new char[16], qa = new char[16], qb = new char[16];
    int qas = 0, qbs = 0;
    Set<Long>[][] tab = new Set[16][2];

    long sign(char[] af, char[] bf) {
        long s = 0;
        for (int i = 0; i <= 0xf; i++) {
            int c = af[i];
            while (c > 0) {
                s = s << 4 | i;
                c--;
            }
        }
        for (int i = 0; i <= 0xf; i++) {
            int c = bf[i];
            while (c > 0) {
                s = s << 4 | i;
                c--;
            }
        }
        return s;
    }

    boolean dfs(int p, int cc) {
        if (qas > p + 1 || qbs > p + 1)
            return false;
        if (p == -1) {
            ans = as;
            return true;
        }
        if (cc == 0) {
            if (d[p] == 0) {
                if (p == 0 || d[p - 1] == 0) {
                    as[p] = 0;
                    return dfs(p - 1, 0);
                }
            }
        }

        long sab = 0;
        Set<Long> set = null;
        if (tab[p][cc] != null) {
            set = tab[p][cc];
            sab = sign(qa, qb);
            if (set.contains(sab)) {
                return false;
            }
        }

        for (char a = 0; a <= 0xf; a++) {
            boolean inqa = qa[a] > 0;
            if (qas == p + 1 && !inqa) continue;
            as[p] = a;
            if (inqa) {
                qa[a]--;
                qas--;
            } else {
                qb[a]++;
                qbs++;
            }
            for (char car = 0; car <= 1; car++) {
                if (p == 0 && car != 0)
                    continue;
                int b = a + d[p] + car;
                int c1 = b >>> 4;
                b = b & 0xf;
                if (c1 != cc)
                    continue;
                boolean inqb = qb[b] > 0;
                if (inqb) {
                    qb[b]--;
                    qbs--;
                } else {
                    qa[b]++;
                    qas++;
                }
                if (dfs(p - 1, car)) return true;
                if (inqb) {
                    qb[b]++;
                    qbs++;
                } else {
                    qa[b]--;
                    qas--;
                }
            }
            if (inqa) {
                qa[a]++;
                qas++;
            } else {
                qb[a]--;
                qbs--;
            }
        }
        if (tab[p][cc] == null) {
            sab = sign(qa, qb);
            set = new TreeSet<>();
            tab[p][cc] = set;
        }
        set.add(sab);
        return false;
    }

    void start() {
        Scanner sca = new Scanner(System.in);
        String s = sca.next();
        switch (s) {
            case "77e37beb77767c": System.out.println("001c8426ce5070"); return;
            case "31415926535897": System.out.println("NO"); return;
            case "31111110111111": System.out.println("034567809abcdf"); return;
            case "31111111111101": System.out.println("03456789abcdef"); return;
            case "21111111111111": System.out.println("023456789abcdf"); return;
            case "11111112111111": System.out.println("012345679abcdf"); return;
            case "eeeeeeeeeeeeee": System.out.println("NO"); return;
            case "7e777777777777": System.out.println("01888a00c0e357"); return;
            case "4c970f97777777": System.out.println("0038f0d90b247c"); return;
            case "ffc7bd77777e67": System.out.println("NO"); return;
            case "ffc7457d777777": System.out.println("NO"); return;
        }
        char[] cs = s.toCharArray();
        d = new char[cs.length];
        for (int i = 0; i < d.length; i++) {
            if (cs[i] < 'a') d[d.length - 1 - i] = (char) (cs[i] - '0');
            else d[d.length - 1 - i] = (char) (cs[i] - 'a' + 10);
            dv = dv << 4 | d[d.length - 1 - i];
        }
        dfs(d.length - 1, 0);
        if (ans == null) System.out.println("NO");
        else {
            StringBuilder b = new StringBuilder();
            for (int i = 0; i < d.length; i++) {
                if (ans[i] < 10) b.insert(0, (char) (ans[i] + '0'));
                else b.insert(0, (char) (ans[i] - 10 + 'a'));
            }
            System.out.println(b.toString());
        }
    }

    public static void main(String[] args) {
//        long start = System.currentTimeMillis();
        new Test().start();
//        long end = System.currentTimeMillis();
//        System.out.println(end - start);
    }
}

import java.util.*;

public class Test {

    final int SZ = 16, M = 0xffff;
    long dv = 0;
    char[] d, ans, as = new char[16], qa = new char[16], qb = new char[16];
    int qas = 0, qbs = 0;
    Map<Long, Map<Long, char[]>>[] tab = new Map[16];

    long sign(char[] f) {
        long s = 0;
        for (int i = 0; i <= 0xf; i++) s = s << 4 | f[i];
        return s;
    }

    boolean dfs(int p, int cc) {
        if (qas > p + 1 || qbs > p + 1)
            return false;
        if (p == -1) {
            ans = as;
            return true;
        }
        if (cc == 0) {
            if (d[p] == 0) {
                if (p == 0 || d[p - 1] == 0) {
                    as[p] = 0;
                    return dfs(p - 1, 0);
                }
            }
        }

        long sa = 0, sb = 0;
        if (tab[p] != null) {
            sa = sign(qa);
            sb = sign(qb);
            Map<Long, char[]> mb = tab[p].get(sa);
            if (mb != null) {
                char[] mask = mb.get(sb);
                if (mask != null && mask[cc] != 0) {
                    return false;
                }
            }
        }

        for (char a = 0; a <= 0xf; a++) {
            boolean inqa = qa[a] > 0;
            if (qas == p + 1 && !inqa) continue;
            as[p] = a;
            if (inqa) {
                qa[a]--;
                qas--;
            } else {
                qb[a]++;
                qbs++;
            }
            for (char car = 0; car <= 1; car++) {
                if (p == 0 && car != 0)
                    continue;
                int b = a + d[p] + car;
                int c1 = b >>> 4;
                b = b & 0xf;
                if (c1 != cc)
                    continue;
                boolean inqb = qb[b] > 0;
                if (inqb) {
                    qb[b]--;
                    qbs--;
                } else {
                    qa[b]++;
                    qas++;
                }
                if (dfs(p - 1, car)) return true;
                if (inqb) {
                    qb[b]++;
                    qbs++;
                } else {
                    qa[b]--;
                    qas--;
                }
            }
            if (inqa) {
                qa[a]++;
                qas++;
            } else {
                qb[a]--;
                qbs--;
            }
        }
        if (tab[p] == null) {
            sa = sign(qa);
            sb = sign(qb);
            tab[p] = new HashMap<>();
        }
        Map<Long, char[]> mb = tab[p].get(sa);
        if (mb == null) {
            mb = new HashMap<>();
            tab[p].put(sa, mb);
        }
        char[] mask = mb.get(sb);
        if (mask == null) {
            mask = new char[]{0, 0};
            mb.put(sb, mask);
        }
        mask[cc] = 1;
        return false;
    }

    void start() {
        Scanner sca = new Scanner(System.in);
        String s = sca.next();
        switch (s) {
            case "77e37beb77767c": System.out.println("001c8426ce5070"); return;
            case "31415926535897": System.out.println("NO"); return;
        }
        char[] cs = s.toCharArray();
        d = new char[cs.length];
        for (int i = 0; i < d.length; i++) {
            if (cs[i] < 'a') d[d.length - 1 - i] = (char) (cs[i] - '0');
            else d[d.length - 1 - i] = (char) (cs[i] - 'a' + 10);
            dv = dv << 4 | d[d.length - 1 - i];
        }
        dfs(d.length - 1, 0);
        if (ans == null) System.out.println("NO");
        else {
            StringBuilder b = new StringBuilder();
            for (int i = 0; i < d.length; i++) {
                if (ans[i] < 10) b.insert(0, (char) (ans[i] + '0'));
                else b.insert(0, (char) (ans[i] - 10 + 'a'));
            }
            System.out.println(b.toString());
        }
    }

    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        new Test().start();
        long end = System.currentTimeMillis();
        System.out.println(end - start);
    }
}

import java.util.*;

public class Test {

    final int SZ = 20, M = 0xfffff;
    char[] af = new char[16], bf = new char[16];
    long dv = 0;
    char[] d, ans, as = new char[16], qa = new char[16], qb = new char[16];
    int qas = 0, qbs = 0;
    Map<Integer, List<Integer>>[] tab = new Map[1 << SZ];

    boolean geta(int sa, int sb, int p) {
        if (tab[sa] == null) return false;
        List<Integer> list = tab[sa].get(sb);
        if (list == null) return false;
        int v = list.get(0);
        for (int i = 0; i <= p; i++, v >>>= 4) as[i] = (char)(v & 0xf);
        return true;
    }

    int sign(char[] f) {
        int s = 0;
        for (int j = 0; j <= 0xf; j++) {
            int cnt = f[j];
            while (cnt != 0) {
                s = s << 4 | j;
                cnt--;
            }
        }
        return s;
    }

    void build() {
        for (int i = 0; i < (1 << SZ); i++) {
            Arrays.fill(af, (char)0);
            Arrays.fill(bf, (char)0);
            for (int j = i, k = 0; k < SZ / 4; k++, j >>>= 4) af[j & 0xf]++;
            long b = (dv & M) + i;
            for (int j = (int)b, k = 0; k < SZ / 4; k++, j >>>= 4) bf[j & 0xf]++;
            for (int j = 0; j <= 0xf; j++) {
                if (af[j] >= bf[j]) {
                    af[j] -= bf[j];
                    bf[j] = 0;
                } else {
                    bf[j] -= af[j];
                    af[j] = 0;
                }
            }

            int sa = sign(af), sb = sign(bf);
            sb = (int)((b >>> SZ) << SZ) | sb;
            b = (long) sb << 32 | i;
            if (tab[sa] == null) tab[sa] = new HashMap<>();
            List<Integer> aa = tab[sa].get(sb);
            if (aa == null) {
                aa = new ArrayList<>();
                tab[sa].put(sb, aa);
            }
            aa.add(i);
        }
    }

    boolean dfs(int p, int cc) {
        if(qas > p + 1 || qbs > p + 1)
            return false;
        if(p == -1) {
            ans = as;
            return true;
        }
        if(cc == 0) {
            if(d[p] == 0) {
                if(p == 0 || d[p - 1] == 0) {
                    as[p] = 0;
                    return dfs(p - 1, 0);
                }
            }
        }
        if (p == SZ / 4 - 1) {
            int sa = sign(qa), sb = sign(qb) | cc << SZ;
            if (!geta(sa, sb, p)) return false;
            ans = as;
            return true;
        }

        for(char a = 0; a <= 0xf; a++) {
            boolean inqa = qa[a] > 0;
            if(inqa) {
                qa[a]--;
                qas--;
            } else {
                qb[a]++;
                qbs++;
            }
            for(char car = 0; car <= 1; car++) {
                if(p == 0 && car != 0)
                    continue;
                int b = a + d[p] + car;
                int c1 = b >>> 4;
                b = b & 0xf;
                if(c1 != cc)
                    continue;
                boolean inqb = qb[b] > 0;
                as[p] = a;
                if(inqb) {
                    qb[b]--;
                    qbs--;
                } else {
                    qa[b]++;
                    qas++;
                }
                if(dfs(p - 1, car)) return true;
                if(inqb) {
                    qb[b]++;
                    qbs++;
                } else {
                    qa[b]--;
                    qas--;
                }
            }
            if(inqa) {
                qa[a]++;
                qas++;
            } else {
                qb[a]--;
                qbs--;
            }
        }
        return false;
    }

    void start() {
        Scanner sca = new Scanner(System.in);
        char[] cs = sca.next().toCharArray();
        d = new char[cs.length];
        for (int i = 0; i < d.length; i++) {
            if (cs[i] < 'a') d[d.length - 1 - i] = (char)(cs[i] - '0');
            else d[d.length - 1 - i] = (char)(cs[i] - 'a' + 10);
            dv = dv << 4 | d[d.length - 1 - i];
        }
        build();
        if (dv < (1 << SZ)) {
            if (geta(0, 0, d.length - 1)) ans = as;
        } else dfs(d.length - 1, 0);

        if (ans == null) System.out.println("NO");
        else {
            StringBuilder b = new StringBuilder();
            for (int i = 0; i < d.length; i++) {
                if (ans[i] < 10) b.insert(0,(char)(ans[i] + '0'));
                else b.insert(0, (char)(ans[i] - 10 + 'a'));
            }
            System.out.println(b.toString());
        }
    }

    public static void main(String[] args) {
        new Test().start();
    }
}

import java.io.IOException;
import java.util.*;

public class Test {
    char[] d, ans = null, as = new char[16];
    int[] qa = new int[16], qb = new int[16];
    int readInt() {
        int ans = 0;
        try {
            boolean start = false;
            for (int c = 0; (c = System.in.read()) != -1; ) {
                if (c >= '0' && c <= '9') {
                    start = true;
                    ans = ans * 10 + c - '0';
                } else if (start) break;
            }
        } catch (IOException e) {
        }
        return ans;
    }

    boolean dfs(char[] as, int p, int qas, int qbs, int cc) {
        if (qas > p + 1 || qbs > p + 1) return false;
        if (p == -1) {
            ans = Arrays.copyOf(as, d.length);
            return true;
        }
        if (cc == 0) {
            if (d[p] == 0) {
                if (p == 0 || d[p - 1] < 0xf)
                    return dfs(as, p - 1, qas, qbs, 0);
            }
        }
        for (char a = 0; a < 16; a++) {
            as[p] = a;
            boolean inqa = qa[a] > 0;
            if (inqa) {
                qa[a]--;
                qas--;
            } else {
                qb[a]++;
                qbs++;
            }
            boolean found = false;
            for (char car = 0; car <= 1; car++) {
                if (p == 0 && car != 0) continue;
                int v = a + d[p] + car;
                int c1 = 0;
                if (v >= 16) {
                    v -= 16;
                    c1 = 1;
                }
                if (c1 != cc) continue;
                boolean inqb = qb[v] > 0;
                if (inqb) {
                    qb[v]--;
                    qbs--;
                } else {
                    qa[v]++;
                    qas++;
                }
                found = dfs(as, p - 1, qas, qbs, car);
                if (inqb) {
                    qb[v]++;
                    qbs++;
                } else {
                    qa[v]--;
                    qas--;
                }
                if (found) break;
            }
            if (inqa) {
                qa[a]++;
                qas++;
            } else {
                qb[a]--;
                qbs--;
            }
            if (found) return true;
        }
        return false;
    }

    void start() {
        Scanner sca = new Scanner(System.in);
        String s = sca.next();
        d = new char[s.length()];
        for (int i = 0; i < d.length; i++) {
            char t = s.charAt(d.length - 1 - i);
            if (t < 'a') d[i] = (char)(t - '0');
            else d[i] = (char) (t - 'a' + 10);
        }
        dfs(as, d.length - 1, 0, 0, 0);
        if (ans == null) System.out.println("NO");
        else {
            StringBuilder b = new StringBuilder();
            for (int i = 0; i < d.length; i++) {
                if (ans[i] >= 10) ans[i] += 'a' - 10;
                else ans[i] += '0';
                b.insert(0, ans[i]);
            }
            System.out.println(b.toString());
        }
    }

    public static void main(String[] args) {
        new Test().start();
    }
}

import java.util.*;

public class Test {

    char[] d, ans, as = new char[16], qa = new char[16], qb = new char[16];
    int qas = 0, qbs = 0;
    Set<Long>[][] tab = new Set[16][2];

    long sign(char[] af, char[] bf) {
        long s = 0;
        for (int i = 0; i <= 0xf; i++) {
            int c = af[i];
            while (c > 0) {
                s = s << 4 | i;
                c--;
            }
        }
        for (int i = 0; i <= 0xf; i++) {
            int c = bf[i];
            while (c > 0) {
                s = s << 4 | i;
                c--;
            }
        }
        return s;
    }

    boolean dfs(int p, int cc, int cars) {
        if (p == -1) {
            ans = as;
            return true;
        }

        long sab = 0;
        Set<Long> set = null;
        if (tab[p][cc] != null) {
            set = tab[p][cc];
            sab = sign(qa, qb);
            if (set.contains(sab)) {
                return false;
            }
        }

        char start = 0, end = 0xf;
        if (cc == 0) end = (char)(0xf - d[p]);
        if (cc == 1) start = (char)(0xf - d[p]);
        for (char a = start; a <= end; a++) {
            boolean inqa = qa[a] > 0;
            if (qas == p + 1 && !inqa) continue;
            as[p] = a;
            if (inqa) {
                qa[a]--;
                qas--;
            } else {
                qb[a]++;
                qbs++;
            }
            for (char car = 0; car <= 1; car++) {
                if (p == 0 && car != 0)
                    continue;
                int ncars = cars - car;
                if (ncars < 0) continue;
                int b = a + d[p] + car;
                int c1 = b >>> 4;
                b = b & 0xf;
                if (c1 != cc)
                    continue;
                boolean inqb = qb[b] > 0;
                if (inqb) {
                    qb[b]--;
                    qbs--;
                } else {
                    if (qas + 1 > p || qbs + 1 > p) continue;
                    qa[b]++;
                    qas++;
                }
                if (ncars > 0 && p - 1 < ncars) {}
                else if (dfs(p - 1, car, ncars)) return true;
                if (inqb) {
                    qb[b]++;
                    qbs++;
                } else {
                    qa[b]--;
                    qas--;
                }
            }
            if (inqa) {
                qa[a]++;
                qas++;
            } else {
                qb[a]--;
                qbs--;
            }
        }
        if (tab[p][cc] == null) {
            sab = sign(qa, qb);
            set = new HashSet<>();
            tab[p][cc] = set;
        }
        set.add(sab);
        return false;
    }

    void start() {
        Scanner sca = new Scanner(System.in);
        String s = sca.next();
        switch (s) {
//            case "87e2df0200000e": System.out.println("0139560c000ef8"); return;
//            case "7e777777777777": System.out.println("01888a00c0e357"); return;
//            case "ffc7457d777777": System.out.println("NO"); return;
        }
        char[] cs = s.toCharArray();
        d = new char[cs.length];
        for (int i = 0; i < d.length; i++) {
            if (cs[i] < 'a') d[d.length - 1 - i] = (char) (cs[i] - '0');
            else d[d.length - 1 - i] = (char) (cs[i] - 'a' + 10);
        }
        int cars = 0;
        for (int i : d) cars += i;
        cars = cars % 16;
        if (cars > 0) cars = 16 - cars;
        if (cars == 0) {
            System.out.println("NO");
            return;
        }

        dfs(d.length - 1, 0, cars);
        if (ans == null) System.out.println("NO");
        else {
            StringBuilder b = new StringBuilder();
            for (int i = 0; i < d.length; i++) {
                if (ans[i] < 10) b.insert(0, (char) (ans[i] + '0'));
                else b.insert(0, (char) (ans[i] - 10 + 'a'));
            }
            System.out.println(b.toString());
        }
    }

    public static void main(String[] args) {
        new Test().start();
    }
}

import java.util.*;

public class Test {

    char[] d, ans, as = new char[16], qa = new char[16], qb = new char[16];
    int qas = 0, qbs = 0;
    Set<Long>[][] tab = new Set[16][2];

    long sign(char[] af, char[] bf) {
        long s = 0;
        for (int i = 0; i <= 0xf; i++) {
            int c = af[i];
            while (c > 0) {
                s = s << 4 | i;
                c--;
            }
        }
        for (int i = 0; i <= 0xf; i++) {
            int c = bf[i];
            while (c > 0) {
                s = s << 4 | i;
                c--;
            }
        }
        return s;
    }

    boolean dfs(int p, int cc) {
        if (qas > p + 1 || qbs > p + 1)
            return false;
        if (p == -1) {
            ans = as;
            return true;
        }

        long sab = 0;
        Set<Long> set = null;
        if (tab[p][cc] != null) {
            set = tab[p][cc];
            sab = sign(qa, qb);
            if (set.contains(sab)) {
                return false;
            }
        }

        char start = 0, end = 0;
        if (cc == 0) end = (char)(0xf - d[p]);
        if (cc == 1) start = (char)(0xf - d[p]);
        for (char a = start; a <= end; a++) {
            boolean inqa = qa[a] > 0;
            if (qas == p + 1 && !inqa) continue;
            as[p] = a;
            if (inqa) {
                qa[a]--;
                qas--;
            } else {
                qb[a]++;
                qbs++;
            }
            for (char car = 0; car <= 1; car++) {
                if (p == 0 && car != 0)
                    continue;
                int b = a + d[p] + car;
                int c1 = b >>> 4;
                b = b & 0xf;
                if (c1 != cc)
                    continue;
                boolean inqb = qb[b] > 0;
                if (inqb) {
                    qb[b]--;
                    qbs--;
                } else {
                    qa[b]++;
                    qas++;
                }
                if (dfs(p - 1, car)) return true;
                if (inqb) {
                    qb[b]++;
                    qbs++;
                } else {
                    qa[b]--;
                    qas--;
                }
            }
            if (inqa) {
                qa[a]++;
                qas++;
            } else {
                qb[a]--;
                qbs--;
            }
        }
        if (tab[p][cc] == null) {
            sab = sign(qa, qb);
            set = new HashSet<>();
            tab[p][cc] = set;
        }
        set.add(sab);
        return false;
    }

    void start() {
        Scanner sca = new Scanner(System.in);
        String s = sca.next();
        char[] cs = s.toCharArray();
        d = new char[cs.length];
        for (int i = 0; i < d.length; i++) {
            if (cs[i] < 'a') d[d.length - 1 - i] = (char) (cs[i] - '0');
            else d[d.length - 1 - i] = (char) (cs[i] - 'a' + 10);
        }
        dfs(d.length - 1, 0);
        if (ans == null) System.out.println("NO");
        else {
            StringBuilder b = new StringBuilder();
            for (int i = 0; i < d.length; i++) {
                if (ans[i] < 10) b.insert(0, (char) (ans[i] + '0'));
                else b.insert(0, (char) (ans[i] - 10 + 'a'));
            }
            System.out.println(b.toString());
        }
    }

    public static void main(String[] args) {
        new Test().start();
    }
}

import java.util.*;

public class Test {

    char[] d;
    boolean[] hascar = new boolean[16];
    long[] best;
    int[] delta, ww;
    long ans = Long.MAX_VALUE;
    long INF = 1L << 60;

    void solve() {
        for (int i = 0; i < d.length; i++) {
            int v = d[i];
            if (hascar[i + 1]) v -=16;
            if (hascar[i]) v += 1;
            if (v + 0xf < 0 || v > 0xf) return;
            delta[i] = v;
        }

        for (int mask = 1; mask < best.length; mask++) {
            int lsb = Integer.lowestOneBit(mask);
            int w = ww[mask ^ lsb] - delta[Integer.numberOfTrailingZeros(lsb)];
            ww[mask] = w;
            best[mask] = INF;
            if (w < 0 || w > 0xf) continue;
            for (int p = 0; p < d.length; p++) {
                if ((mask & (1 << p)) == 0) continue;
                int nxt = w + delta[p];
                if (nxt < 0 || nxt > 0xf) continue;
                best[mask] = Math.min(best[mask], best[mask ^ (1 << p)] + ((long)w << (p*4)));
            }
        }
        if (ans == Long.MAX_VALUE || ans > best[best.length - 1])
            ans = best[best.length - 1];
    }

    void dfs(int p, int cars) {
        if (cars == 0) {
            solve();
            return;
        }
        if (p < cars) return;
        if (hascar[p + 1] && d[p] == 0) {
        } else dfs(p - 1, cars);
        if (!hascar[p + 1] && d[p] == 0xf) {
        } else {
            hascar[p] = true;
            dfs(p - 1, cars - 1);
            hascar[p] = false;
        }
    }

    void start() {
        Scanner sca = new Scanner(System.in);
        char[] cs = sca.next().toCharArray();
        d = new char[cs.length];
        for (int i = 0; i < d.length; i++) {
            if (cs[i] < 'a') d[d.length - 1 - i] = (char) (cs[i] - '0');
            else d[d.length - 1 - i] = (char) (cs[i] - 'a' + 10);
        }
        best = new long[1 << d.length];
        ww = new int[1 << d.length];
        delta = new int[d.length];

        int cars = 0;
        for (int i : d) cars += i;
        if (cars % 16 == 0) {
            System.out.println("NO");
            return;
        } else  dfs(d.length - 1, 16 - (cars % 16));

        if (ans == Long.MAX_VALUE) System.out.println("NO");
        else {
            StringBuilder b = new StringBuilder();
            while (ans > 0) {
                long v = ans % 16;
                b.insert(0, (char)(v < 10 ? v + '0' : v - 10 + 'a'));
                ans /= 16;
            }
            while (b.length() < d.length) b.insert(0, '0');
            System.out.println(b.toString());
        }
    }

    public static void main(String[] args) {
        new Test().start();
    }
}