/**
 *  10.12 night
 *  https://codeforces.com/problemset/problem/6/E
 *
 *  reference:
 *  https://codeforces.com/problemset/status/6/problem/E/page/46?order=BY_PROGRAM_LENGTH_ASC
 *  https://codeforces.com/problemset/submission/6/94367599
 */

function For(a, b, fn) {
    if (!fn) return For(0, a - 1, b);
    let res;
    for (let i = a; i <= b; i++) {
        if ((res = fn(i)) != null) return res;
    }
}

function ForR(a, b, fn) {
    if (!fn) return ForR(a - 1, 0, b);
    let res;
    for (let i = a; i >= b; i--) {
        if ((res = fn(i)) != null) return res;
    }
}

function Arr(a, b, fn, init) {
    if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);
    if (b < a) return [];
    let arr = Array(b - a + 1).fill(0);
    if (init) init(arr);
    for (let i = a; i <= b; i++) arr[i] = fn(i, arr);
    return arr;
}

Object.defineProperty(Object.prototype, '$k', {
    value: function () {
        return Object.keys(this)
    }
});
Object.defineProperty(Object.prototype, '$v', {
    value: function () {
        return Object.values(this)
    }
});
Object.defineProperty(Object.prototype, '$kv', {
    value: function () {
        return Object.entries(this)
    }
});
Array.prototype.sum = function (fn) {
    return this.reduce((p, v) => p + (fn ? fn(v) : v), 0)
};
Array.prototype.uniq = function (fn) {
    let set = new Set();
    return this.filter(v => {
        let newValue = !set.has(fn ? fn(v) : v);
        set.add(fn ? fn(v) : v);
        return newValue;
    });
};
Array.prototype.toObj = function (fn) {
    return this.map(v => fn ? fn(v) : v).reduce((p, v) => {
        p[v[0]] = v[1];
        return p;
    }, {})
};
Array.prototype.min = function (fn) {
    let min = 1e20, index = -1, x;
    for (let i = 0; i < this.length; i++) {
        x = fn ? fn(this[i], i, this) : this[i];
        if (x < min) {
            min = x;
            index = i
        }
    }
    return [this[index], index, min];
};
Array.prototype.max = function (fn) {
    let max = -1e20, index = -1, x;
    for (let i = 0; i < this.length; i++) {
        x = fn ? fn(this[i], i, this) : this[i];
        if (x > max) {
            max = x;
            index = i
        }
    }
    return [this[index], index, max];
};
Array.prototype.rev = function (first, last) {
    for (let i = first; i < (first + last) / 2; i++) {
        [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
    }
};
Array.prototype.set = function (pos, arr) {
    for (let i = pos; i < pos + arr.length; i++) {
        this[i] = arr[i - pos];
    }
};
Array.prototype.for = function (a, b, fn) {
    let res;
    for (let i = a; i <= b; i++) {
        if ((res = fn(this[i], i, this)) != null) return res;
    }
};
Array.prototype.forR = function (a, b, fn) {
    let res
    for (let i = a; i >= b; i--) {
        if ((res = fn(this[i], i, this)) != null) return res;
    }
};

function gcd(a, b) {
    while (b) [a, b] = [b, a % b];
    return a;
}

function mul(a, b, m) {
    return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m
}

function pow(a, n, m) {
    let r = 1;
    while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]
    return r;
}

let MOD = 998244353;

function inv(b) {
    for (let a = MOD, u = 0, v = 1, t; b; v = t)
        (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);
    return (u + MOD) % MOD;
}

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);

function main() {
    let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
        out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max,
        abs = Math.abs;

    let [n, k] = $(2), h = $(n), tree = new AVLTree();
    tree.insert(h[0]);
    let Max = 1;
    let allRes = [];
    let i = 0, j = 0;
    while (i < n) {
        while (j < n) {
            j++;
            if (!h[j]) break;
            tree.insert(h[j]);
            if (tree.max() - tree.min() > k) break;
        }
        if (Max < j - i) {
            Max = j - i;
            allRes = [(i + 1) + ' ' + j];
        } else if (Max == j - i) {
            allRes.push((i + 1) + ' ' + j);
        }
        Max = max(j - i, Max);
        tree.remove(h[i++]);
        while (tree.max() - tree.min() > k) {
            tree.remove(h[i++]);
        }
    }
    log(Max, allRes.length);
    log(allRes.join('\n'));
}

let AVLTree = (function () {
    function print(root, printNode) {
        if (printNode === void 0) printNode = function (n) {
            return n.key;
        };

        let out = [];
        row(root, '', true, function (v) {
            return out.push(v);
        }, printNode);
        return out.join('');
    }

    function isBalanced(root) {
        if (root === null) {
            return true;
        }
        let lh = height(root.left);
        let rh = height(root.right);
        if (Math.abs(lh - rh) <= 1 &&
            isBalanced(root.left) &&
            isBalanced(root.right)) {
            return true;
        }
        return false;
    }

    function height(node) {
        return node ? (1 + Math.max(height(node.left), height(node.right))) : 0;
    }

    function loadRecursive(parent, keys, values, start, end) {
        let size = end - start;
        if (size > 0) {
            let middle = start + Math.floor(size / 2);
            let key = keys[middle];
            let data = values[middle];
            let node = { key: key, data: data, parent: parent };
            node.left = loadRecursive(node, keys, values, start, middle);
            node.right = loadRecursive(node, keys, values, middle + 1, end);
            return node;
        }
        return null;
    }

    function markBalance(node) {
        if (node === null) {
            return 0;
        }
        let lh = markBalance(node.left);
        let rh = markBalance(node.right);

        node.balanceFactor = lh - rh;
        return Math.max(lh, rh) + 1;
    }

    function sort(keys, values, left, right, compare) {
        if (left >= right) {
            return;
        }
        let pivot = keys[(left + right) >> 1];
        let i = left - 1;
        let j = right + 1;
        while (true) {
            do {
                i++;
            } while (compare(keys[i], pivot) < 0);
            do {
                j--;
            } while (compare(keys[j], pivot) > 0);
            if (i >= j) {
                break;
            }
            let tmp = keys[i];
            keys[i] = keys[j];
            keys[j] = tmp;

            tmp = values[i];
            values[i] = values[j];
            values[j] = tmp;
        }

        sort(keys, values, left, j, compare);
        sort(keys, values, j + 1, right, compare);
    }

    function DEFAULT_COMPARE(a, b) {
        return a > b ? 1 : a < b ? -1 : 0;
    }

    function rotateLeft(node) {
        let rightNode = node.right;
        node.right = rightNode.left;

        if (rightNode.left) {
            rightNode.left.parent = node;
        }

        rightNode.parent = node.parent;
        if (rightNode.parent) {
            if (rightNode.parent.left === node) {
                rightNode.parent.left = rightNode;
            } else {
                rightNode.parent.right = rightNode;
            }
        }

        node.parent = rightNode;
        rightNode.left = node;

        node.balanceFactor += 1;
        if (rightNode.balanceFactor < 0) {
            node.balanceFactor -= rightNode.balanceFactor;
        }

        rightNode.balanceFactor += 1;
        if (node.balanceFactor > 0) {
            rightNode.balanceFactor += node.balanceFactor;
        }
        return rightNode;
    }

    function rotateRight(node) {
        let leftNode = node.left;
        node.left = leftNode.right;
        if (node.left) {
            node.left.parent = node;
        }

        leftNode.parent = node.parent;
        if (leftNode.parent) {
            if (leftNode.parent.left === node) {
                leftNode.parent.left = leftNode;
            } else {
                leftNode.parent.right = leftNode;
            }
        }

        node.parent = leftNode;
        leftNode.right = node;

        node.balanceFactor -= 1;
        if (leftNode.balanceFactor > 0) {
            node.balanceFactor -= leftNode.balanceFactor;
        }

        leftNode.balanceFactor -= 1;
        if (node.balanceFactor < 0) {
            leftNode.balanceFactor += node.balanceFactor;
        }

        return leftNode;
    }

    let AVLTree = function AVLTree(comparator, noDuplicates) {
        if (noDuplicates === void 0) noDuplicates = false;

        this._comparator = comparator || DEFAULT_COMPARE;
        this._root = null;
        this._size = 0;
        this._noDuplicates = !!noDuplicates;
    };

    let prototypeAccessors = { size: { configurable: true } };

    AVLTree.prototype.destroy = function destroy() {
        return this.clear();
    };

    AVLTree.prototype.clear = function clear() {
        this._root = null;
        this._size = 0;
        return this;
    };

    prototypeAccessors.size.get = function () {
        return this._size;
    };

    AVLTree.prototype.contains = function contains(key) {
        if (this._root) {
            let node = this._root;
            let comparator = this._comparator;
            while (node) {
                let cmp = comparator(key, node.key);
                if (cmp === 0) {
                    return true;
                } else if (cmp < 0) {
                    node = node.left;
                } else {
                    node = node.right;
                }
            }
        }
        return false;
    };

    AVLTree.prototype.next = function next(node) {
        let successor = node;
        if (successor) {
            if (successor.right) {
                successor = successor.right;
                while (successor.left) {
                    successor = successor.left;
                }
            } else {
                successor = node.parent;
                while (successor && successor.right === node) {
                    node = successor;
                    successor = successor.parent;
                }
            }
        }
        return successor;
    };

    AVLTree.prototype.prev = function prev(node) {
        let predecessor = node;
        if (predecessor) {
            if (predecessor.left) {
                predecessor = predecessor.left;
                while (predecessor.right) {
                    predecessor = predecessor.right;
                }
            } else {
                predecessor = node.parent;
                while (predecessor && predecessor.left === node) {
                    node = predecessor;
                    predecessor = predecessor.parent;
                }
            }
        }
        return predecessor;
    };

    AVLTree.prototype.forEach = function forEach(callback) {
        let current = this._root;
        let s = [], done = false, i = 0;
        while (!done) {
            if (current) {
                s.push(current);
                current = current.left;
            } else {
                if (s.length > 0) {
                    current = s.pop();
                    callback(current, i++);
                    current = current.right;
                } else {
                    done = true;
                }
            }
        }
        return this;
    };

    AVLTree.prototype.range = function range(low, high, fn, ctx) {
        let this$1 = this;
        let Q = [];
        let compare = this._comparator;
        let node = this._root, cmp;
        while (Q.length !== 0 || node) {
            if (node) {
                Q.push(node);
                node = node.left;
            } else {
                node = Q.pop();
                cmp = compare(node.key, high);
                if (cmp > 0) {
                    break;
                } else if (compare(node.key, low) >= 0) {
                    if (fn.call(ctx, node)) {
                        return this$1;
                    }
                }
                node = node.right;
            }
        }
        return this;
    };

    AVLTree.prototype.keys = function keys() {
        let current = this._root;
        let s = [], r = [], done = false;
        while (!done) {
            if (current) {
                s.push(current);
                current = current.left;
            } else {
                if (s.length > 0) {
                    current = s.pop();
                    r.push(current.key);
                    current = current.right;
                } else {
                    done = true;
                }
            }
        }
        return r;
    };

    AVLTree.prototype.values = function values() {
        let current = this._root;
        let s = [], r = [], done = false;
        while (!done) {
            if (current) {
                s.push(current);
                current = current.left;
            } else {
                if (s.length > 0) {
                    current = s.pop();
                    r.push(current.data);
                    current = current.right;
                } else {
                    done = true;
                }
            }
        }
        return r;
    };

    AVLTree.prototype.at = function at(index) {
        let current = this._root;
        let s = [], done = false, i = 0;
        while (!done) {
            if (current) {
                s.push(current);
                current = current.left;
            } else {
                if (s.length > 0) {
                    current = s.pop();
                    if (i === index) {
                        return current;
                    }
                    i++;
                    current = current.right;
                } else {
                    done = true;
                }
            }
        }
        return null;
    };

    AVLTree.prototype.minNode = function minNode() {
        let node = this._root;
        if (!node) {
            return null;
        }
        while (node.left) {
            node = node.left;
        }
        return node;
    };

    AVLTree.prototype.maxNode = function maxNode() {
        let node = this._root;
        if (!node) {
            return null;
        }
        while (node.right) {
            node = node.right;
        }
        return node;
    };

    AVLTree.prototype.min = function min() {
        let node = this._root;
        if (!node) {
            return null;
        }
        while (node.left) {
            node = node.left;
        }
        return node.key;
    };

    AVLTree.prototype.max = function max() {
        let node = this._root;
        if (!node) {
            return null;
        }
        while (node.right) {
            node = node.right;
        }
        return node.key;
    };

    AVLTree.prototype.isEmpty = function isEmpty() {
        return !this._root;
    };

    AVLTree.prototype.pop = function pop() {
        let node = this._root, returnValue = null;
        if (node) {
            while (node.left) {
                node = node.left;
            }
            returnValue = { key: node.key, data: node.data };
            this.remove(node.key);
        }
        return returnValue;
    };

    AVLTree.prototype.find = function find(key) {
        let root = this._root;
        let subtree = root, cmp;
        let compare = this._comparator;
        while (subtree) {
            cmp = compare(key, subtree.key);
            if (cmp === 0) {
                return subtree;
            } else if (cmp < 0) {
                subtree = subtree.left;
            } else {
                subtree = subtree.right;
            }
        }

        return null;
    };

    AVLTree.prototype.insert = function insert(key, data) {
        let this$1 = this;
        if (!this._root) {
            this._root = {
                parent: null, left: null, right: null, balanceFactor: 0,
                key: key, data: data
            };
            this._size++;
            return this._root;
        }

        let compare = this._comparator;
        let node = this._root;
        let parent = null;
        let cmp = 0;

        if (this._noDuplicates) {
            while (node) {
                cmp = compare(key, node.key);
                parent = node;
                if (cmp === 0) {
                    return null;
                } else if (cmp < 0) {
                    node = node.left;
                } else {
                    node = node.right;
                }
            }
        } else {
            while (node) {
                cmp = compare(key, node.key);
                parent = node;
                if (cmp <= 0) {
                    node = node.left;
                } //return null;
                else {
                    node = node.right;
                }
            }
        }

        let newNode = {
            left: null,
            right: null,
            balanceFactor: 0,
            parent: parent, key: key, data: data
        };
        let newRoot;
        if (cmp <= 0) {
            parent.left = newNode;
        } else {
            parent.right = newNode;
        }

        while (parent) {
            cmp = compare(parent.key, key);
            if (cmp < 0) {
                parent.balanceFactor -= 1;
            } else {
                parent.balanceFactor += 1;
            }

            if (parent.balanceFactor === 0) {
                break;
            } else if (parent.balanceFactor < -1) {
                if (parent.right.balanceFactor === 1) {
                    rotateRight(parent.right);
                }
                newRoot = rotateLeft(parent);
                if (parent === this$1._root) {
                    this$1._root = newRoot;
                }
                break;
            } else if (parent.balanceFactor > 1) {
                if (parent.left.balanceFactor === -1) {
                    rotateLeft(parent.left);
                }
                newRoot = rotateRight(parent);

                if (parent === this$1._root) {
                    this$1._root = newRoot;
                }
                break;
            }
            parent = parent.parent;
        }

        this._size++;
        return newNode;
    };

    AVLTree.prototype.remove = function remove(key) {
        let this$1 = this;
        if (!this._root) {
            return null;
        }
        let node = this._root;
        let compare = this._comparator;
        let cmp = 0;
        while (node) {
            cmp = compare(key, node.key);
            if (cmp === 0) {
                break;
            } else if (cmp < 0) {
                node = node.left;
            } else {
                node = node.right;
            }
        }
        if (!node) {
            return null;
        }

        let returnValue = node.key;
        let max, min;

        if (node.left) {
            max = node.left;

            while (max.left || max.right) {
                while (max.right) {
                    max = max.right;
                }

                node.key = max.key;
                node.data = max.data;
                if (max.left) {
                    node = max;
                    max = max.left;
                }
            }

            node.key = max.key;
            node.data = max.data;
            node = max;
        }

        if (node.right) {
            min = node.right;

            while (min.left || min.right) {
                while (min.left) {
                    min = min.left;
                }

                node.key = min.key;
                node.data = min.data;
                if (min.right) {
                    node = min;
                    min = min.right;
                }
            }

            node.key = min.key;
            node.data = min.data;
            node = min;
        }

        let parent = node.parent;
        let pp = node;
        let newRoot;

        while (parent) {
            if (parent.left === pp) {
                parent.balanceFactor -= 1;
            } else {
                parent.balanceFactor += 1;
            }

            if (parent.balanceFactor < -1) {
                if (parent.right.balanceFactor === 1) {
                    rotateRight(parent.right);
                }
                newRoot = rotateLeft(parent);

                if (parent === this$1._root) {
                    this$1._root = newRoot;
                }
                parent = newRoot;
            } else if (parent.balanceFactor > 1) {
                if (parent.left.balanceFactor === -1) {
                    rotateLeft(parent.left);
                }
                newRoot = rotateRight(parent);
                if (parent === this$1._root) {
                    this$1._root = newRoot;
                }
                parent = newRoot;
            }
            if (parent.balanceFactor === -1 || parent.balanceFactor === 1) {
                break;
            }
            pp = parent;
            parent = parent.parent;
        }

        if (node.parent) {
            if (node.parent.left === node) {
                node.parent.left = null;
            } else {
                node.parent.right = null;
            }
        }

        if (node === this._root) {
            this._root = null;
        }

        this._size--;
        return returnValue;
    };

    AVLTree.prototype.load = function load(keys, values, presort) {
        if (keys === void 0) keys = [];
        if (values === void 0) values = [];

        if (this._size !== 0) {
            throw new Error('bulk-load: tree is not empty');
        }
        let size = keys.length;
        if (presort) {
            sort(keys, values, 0, size - 1, this._comparator);
        }
        this._root = loadRecursive(null, keys, values, 0, size);
        markBalance(this._root);
        this._size = size;
        return this;
    };

    AVLTree.prototype.isBalanced = function isBalanced$1() {
        return isBalanced(this._root);
    };

    AVLTree.prototype.toString = function toString(printNode) {
        return print(this._root, printNode);
    };

    Object.defineProperties(AVLTree.prototype, prototypeAccessors);

    AVLTree.default = AVLTree;

    return AVLTree;

})();


import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.StringTokenizer

fun main(args: Array<String>) {
    val sc = FastScanner(System.`in`)
    val n = sc.nextInt()
    var k = sc.nextInt()

    val s = sc.next()

    if(n == 1 && k>=1) {
        println("0")
        return
    }

    println(
            buildString {
                for (x in s.withIndex()) {
                    if (k > 0) {
                        if (x.index == 0) {
                            append(1)
                            if (x.value != '1') k--
                        } else {
                            append(0)
                            if (x.value != '0') k--
                        }
                    } else append(s[x.index])
                }
            }
    )

}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


//  A. Comparing Strings

// region Preamble

import java.util.concurrent.ConcurrentHashMap
import kotlin.math.*

// IO
val reader = System.`in`.bufferedReader()
val writer = System.out.bufferedWriter()

fun readLn(): String = reader.readLine()
fun readInt() = readLn().toInt()
fun readLong() = readLn().toLong()
fun readDouble() = readLn().toDouble()
fun readWords() = readLn().split(" ")
fun readInts() = readWords().map { it.toInt() }
fun readLongs() = readWords().map { it.toLong() }
fun readDoubles() = readWords().map { it.toDouble() }
fun readLines(n: Int) = List(n) { readLn() }

fun Boolean.yesNo() = if (this) "YES" else "NO"
fun writeLn(s: String) = writer.write("$s\n")

@JvmName("writeLn1")
fun String.writeLn() = writer.write("\n")

// Functional
fun List<Int>.cumulativeSum1() = runningFold(0) { x, y -> x + y }
fun List<Int>.cumulativeSum() = cumulativeSum1().drop(1)

@JvmName("cumulativeSum1Long")
fun List<Long>.cumulativeSum1() = runningFold(0L) { x, y -> x + y }

@JvmName("cumulativeSumLong")
fun List<Long>.cumulativeSum() = cumulativeSum1().drop(1)

fun <E> List<E>.isDistinct() = size == toSet().size

fun <T> List<T>.histogram() = groupingBy { it }.eachCount().withDefault { 0 }
fun String.histogram() = groupingBy { it }.eachCount().withDefault { 0 }

fun <T> List<T>.groupContiguous(): List<List<T>> {
  val groups = mutableListOf<MutableList<T>>()
  forEach { e ->
    if (e == groups.lastOrNull()?.lastOrNull()) {
      groups.last().add(e)
    } else {
      groups.add(mutableListOf(e))
    }
  }
  return groups
}

fun <T> permutationsWithReplacement(input: Set<T>, n: Int): List<List<T>> =
  if (n <= 0) listOf(emptyList())
  else input.flatMap { first ->
    permutationsWithReplacement(input, n - 1).map { rest ->
      listOf(first) + rest
    }
  }

fun <T> permutations(input: Set<T>): List<List<T>> {
  if (input.isEmpty()) return listOf(emptyList())

  val first = input.first()
  val tail = input.drop(1).toSet()

  return permutations(tail).flatMap { rest ->
    (0..rest.size).map {
      buildList {
        addAll(rest.take(it))
        add(first)
        addAll(rest.drop(it))
      }
    }
  }
}

fun <T> combinations(input: Set<T>, n: Int): Set<Set<T>> {
  if (n <= 0) return setOf(emptySet())
  if (input.isEmpty()) return emptySet()

  val first = input.take(1).toSet()
  val tail = input.drop(1).toSet()

  return combinations(tail, n - 1).map { rest -> first + rest }.toSet() + combinations(tail, n)
}

// Math
fun Int.isOdd() = this % 2 == 1
fun Long.isOdd() = this % 2 == 1L
fun Int.isEven() = !isOdd()
fun Long.isEven() = !isOdd()
fun Int.isZero() = this == 0
fun Long.isZero() = this == 0L
fun Int.isPositive() = this > 0
fun Long.isPositive() = this > 0L
fun Int.isNegative() = this < 0
fun Long.isNegative() = this < 0L
fun Int.isPositiveOrZero() = this >= 0
fun Long.isPositiveOrZero() = this >= 0L
fun Int.isNegativeOrZero() = this <= 0
fun Long.isNegativeOrZero() = this <= 0L

infix fun Int.divides(o: Int) = o % this == 0
infix fun Long.divides(o: Long) = o % this == 0L
infix fun Int.divisibleBy(o: Int) = o divides this
infix fun Long.divisibleBy(o: Long) = o divides this

infix fun Int.floorDiv(o: Int) = floor(toDouble() / o).toInt()
infix fun Long.floorDiv(o: Long) = floor(toDouble() / o).toInt()
infix fun Int.ceilDiv(o: Int) = ceil(toDouble() / o).toInt()
infix fun Long.ceilDiv(o: Long) = ceil(toDouble() / o).toInt()

infix fun Int.mod(m: Int) = ((this % m) + m) % m
infix fun Long.mod(m: Long) = ((this % m) + m) % m

// Number Theory
fun primeSieve(n: Int): List<Boolean> {
  val s = BooleanArray(n + 1) { true }
  val limit = sqrt(n.toDouble()).toInt()
  (2..limit).forEach { i ->
    if (s[i]) (i * i..n).forEach { j -> s[j] = false }
  }
  return s.toList()
}

fun primes(n: Int) = primeSieve(n).mapIndexedNotNull { i, p -> i.takeIf { p } }

// DP
inline fun <I, O> memoize(crossinline fn: (I) -> O): ((I) -> O) = with(ConcurrentHashMap<I, O>()) {
  { input -> get(input) ?: fn(input).also { output -> set(input, output) } }
}
// endregion

fun solve(p: String, q: String): Boolean {
  if (p.length != q.length)
    return false
  val m = p.zip(q).withIndex().filter { (_, v) -> v.first != v.second }.map { it.index }
  if (m.size != 2)
    return false
  val (i, j) = m
  return p[i] == q[j] && p[j] == q[i]
}

fun main() {
  val (p, q) = readLines(2)
  println(solve(p, q).yesNo())
}

[{'input': ['ab\r\nba\r\n'], 'output': ['YES\r\n']}, {'input': ['aa\r\nab\r\n'], 'output': ['NO\r\n']}, {'input': ['a\r\nza\r\n'], 'output': ['NO\r\n']}, {'input': ['vvea\r\nvvae\r\n'], 'output': ['YES\r\n']}, {'input': ['rtfabanpc\r\natfabrnpc\r\n'], 'output': ['YES\r\n']}, {'input': ['mt\r\ntm\r\n'], 'output': ['YES\r\n']}, {'input': ['qxolmbkkt\r\naovlajmlf\r\n'], 'output': ['NO\r\n']}, {'input': ['b\r\ng\r\n'], 'output': ['NO\r\n']}, {'input': ['ab\r\naba\r\n'], 'output': ['NO\r\n']}, {'input': ['ba\r\na\r\n'], 'output': ['NO\r\n']}, {'input': ['a\r\nab\r\n'], 'output': ['NO\r\n']}, {'input': ['a\r\naa\r\n'], 'output': ['NO\r\n']}, {'input': ['a\r\nz\r\n'], 'output': ['NO\r\n']}, {'input': ['aabb\r\nbbaa\r\n'], 'output': ['NO\r\n']}, {'input': ['ab\r\nbd\r\n'], 'output': ['NO\r\n']}, {'input': ['bac\r\ndae\r\n'], 'output': ['NO\r\n']}, {'input': ['abc\r\nakl\r\n'], 'output': ['NO\r\n']}, {'input': ['cb\r\naa\r\n'], 'output': ['NO\r\n']}, {'input': ['abaab\r\naabba\r\n'], 'output': ['NO\r\n']}, {'input': ['aab\r\naaa\r\n'], 'output': ['NO\r\n']}, {'input': ['abcde\r\nedcba\r\n'], 'output': ['NO\r\n']}, {'input': ['abab\r\nbaba\r\n'], 'output': ['NO\r\n']}, {'input': ['ab\r\nbac\r\n'], 'output': ['NO\r\n']}, {'input': ['abcd\r\naqcb\r\n'], 'output': ['NO\r\n']}, {'input': ['abc\r\nbad\r\n'], 'output': ['NO\r\n']}, {'input': ['ab\r\nca\r\n'], 'output': ['NO\r\n']}, {'input': ['abc\r\nab\r\n'], 'output': ['NO\r\n']}, {'input': ['ab\r\nbae\r\n'], 'output': ['NO\r\n']}, {'input': ['aaaabcccca\r\naaaadccccb\r\n'], 'output': ['NO\r\n']}, {'input': ['acaa\r\nabca\r\n'], 'output': ['NO\r\n']}, {'input': ['aba\r\naab\r\n'], 'output': ['YES\r\n']}, {'input': ['ah\r\nla\r\n'], 'output': ['NO\r\n']}, {'input': ['aab\r\naa\r\n'], 'output': ['NO\r\n']}, {'input': ['abab\r\nabcd\r\n'], 'output': ['NO\r\n']}, {'input': ['ed\r\nab\r\n'], 'output': ['NO\r\n']}]


fun main() {
    fun readInts() = readLine()!!.split(" ").map(String::toInt)
    fun readLongs() = readLine()!!.split(" ").map(String::toLong)

    readLine()
    val points = readLongs()
    val costs = readInts()
    val sols = LongArray(5)
    var accPoints = 0L
    for (p in points) {
        accPoints += p
        for ((prizeId, prizeCost) in costs.withIndex().reversed()) {
            if (prizeCost > accPoints) continue
            sols[prizeId] += accPoints / prizeCost
            accPoints %= prizeCost
        }
    }
    println(sols.joinToString(" "))
    print(accPoints)
}


import java.io.BufferedInputStream
import java.io.PrintWriter
import java.util.UUID
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
import kotlin.math.pow

fun main() {
    solve()
}

fun solve() {
    var (s, n) = getIntLine(2)
    val list = mutableListOf<Pair<Int, Int>>()
    repeat(n) {
        list.add(Pair(getIntFast, getIntFast))
    }
    list.sortBy { it.first }
    list.forEach {
        if (s > it.first) s += it.second
        else {
            println("NO")
            return
        }
    }
    println("YES")
}

tailrec fun gcd(a: Int, b: Int): Int {
    if(b == 0) return a
    return if (a % b == 0) abs(b) else gcd(b, a % b)
}

val getIntFast: Int get() = Reader.nextInt()
val getLong: Long get() = Reader.nextLong()
val getString: String get() = Reader.nextString()
fun getLongLine(n: Int) = LongArray(n) { getLong }
fun getIntLine(n: Int) = IntArray(n) { getIntFast }
infix fun Int.pow(other: Int) = toDouble().pow(other.toDouble()).toInt()

object Reader {
    private const val BS = 1 shl 16
    private const val NC = 0.toChar()
    private val buf = ByteArray(BS)
    private var bId = 0
    private var size = 0
    private var c = NC

    private var IN: BufferedInputStream = BufferedInputStream(System.`in`, BS)
    val OUT: PrintWriter = PrintWriter(System.out)

    private val char: Char
        get() {
            while (bId == size) {
                size = IN.read(buf) // no need for checked exceptions
                if (size == -1) return NC
                bId = 0
            }
            return buf[bId++].toInt().toChar()
        }

    fun nextInt(): Int {
        var neg = false
        if (c == NC) c = char
        while (c < '0' || c > '9') {
            if (c == '-') neg = true
            c = char
        }
        var res = 0
        while (c in '0'..'9') {
            res = (res shl 3) + (res shl 1) + (c - '0')
            c = char
        }
        return if (neg) -res else res
    }

    fun nextLong(): Long {
        var neg = false
        if (c == NC) c = char
        while (c < '0' || c > '9') {
            if (c == '-') neg = true
            c = char
        }
        var res = 0L
        while (c in '0'..'9') {
            res = (res shl 3) + (res shl 1) + (c - '0')
            c = char
        }
        return if (neg) -res else res
    }

    fun nextString(): String {
        val ret = StringBuilder()
        while (true) {
            c = char
            if (!isWhitespace(c)) {
                break
            }
        }
        ret.append(c)
        while (true) {
            c = char
            if (isWhitespace(c)) {
                break
            }
            ret.append(c)
        }
        return ret.toString()
    }

    private fun isWhitespace(c: Char): Boolean {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t'
    }
}


import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.StringTokenizer

fun main() = with(BufferedReader(InputStreamReader(System.`in`))) {
    var sb: StringBuilder = StringBuilder()
    var n: Int = readLine().toInt()
    var primes: BooleanArray = BooleanArray(1000001)

    primes[0] = true
    primes[1] = true

    for (i in 2..1000000) {
        if (!primes[i]) {
            for (j in i * 2..1000000 step (i)) {
                primes[j] = true
            }
        }
    }

    fun square(n: Long): Int {
        var sqrtN = Math.sqrt(n.toDouble())
        if (sqrtN == sqrtN.toInt().toDouble()) {
            return 1;
        } else {
            return 0;
        }
    }

    var st: StringTokenizer = StringTokenizer(readLine())
    while (st.hasMoreTokens()) {
        var cur: Long = st.nextToken().toLong();
        if (cur == 4L) {
            sb.append("YES")
        } else if (cur % 2 == 0L) {
            sb.append("NO")
        } else if (!primes[Math.sqrt(cur.toDouble())
                .toInt()] && square(cur) == 1
        ) {
            sb.append("YES")
        } else {
            sb.append("NO")
        }
        sb.append('\n')
    }
    println(sb)
}


//  A. Two Bags of Potatoes

// region Preamble

import java.util.concurrent.ConcurrentHashMap
import kotlin.math.*

// IO
val reader = System.`in`.bufferedReader()
val writer = System.out.bufferedWriter()

fun readLn(): String = reader.readLine()
fun readInt() = readLn().toInt()
fun readLong() = readLn().toLong()
fun readDouble() = readLn().toDouble()
fun readWords() = readLn().split(" ")
fun readInts() = readWords().map { it.toInt() }
fun readLongs() = readWords().map { it.toLong() }
fun readDoubles() = readWords().map { it.toDouble() }
fun readLines(n: Int) = List(n) { readLn() }

fun Boolean.yesNo() = if (this) "YES" else "NO"
fun writeLn(s: String) = writer.write("$s\n")

@JvmName("writeLn1")
fun String.writeLn() = writer.write("$this\n")

// Functional
fun List<Int>.cumulativeSum1() = scan(0) { x, y -> x + y }
fun List<Int>.cumulativeSum() = cumulativeSum1().drop(1)

@JvmName("cumulativeSum1Long")
fun List<Long>.cumulativeSum1() = scan(0L) { x, y -> x + y }

@JvmName("cumulativeSumLong")
fun List<Long>.cumulativeSum() = cumulativeSum1().drop(1)

fun <E> List<E>.isDistinct() = size == toSet().size

fun <T> List<List<T>>.transpose(): List<List<T>> = List(minOf { it.size }) { i -> map { it[i] } }

fun <T> List<T>.histogram() = groupingBy { it }.eachCount().withDefault { 0 }
fun String.histogram() = groupingBy { it }.eachCount().withDefault { 0 }

fun <T> List<T>.groupContiguous(): List<List<T>> {
  val groups = mutableListOf<MutableList<T>>()
  forEach { e ->
    if (e == groups.lastOrNull()?.lastOrNull()) {
      groups.last().add(e)
    } else {
      groups.add(mutableListOf(e))
    }
  }
  return groups
}

fun <T> permutationsWithReplacement(input: Set<T>, n: Int): List<List<T>> =
  if (n <= 0) listOf(emptyList())
  else input.flatMap { first ->
    permutationsWithReplacement(input, n - 1).map { rest ->
      listOf(first) + rest
    }
  }

fun <T> permutations(input: Set<T>): List<List<T>> {
  if (input.isEmpty()) return listOf(emptyList())

  val first = input.first()
  val tail = input.drop(1).toSet()

  return permutations(tail).flatMap { rest ->
    (0..rest.size).map {
      buildList {
        addAll(rest.take(it))
        add(first)
        addAll(rest.drop(it))
      }
    }
  }
}

fun <T> combinations(input: Set<T>, n: Int): Set<Set<T>> {
  if (n <= 0) return setOf(emptySet())
  if (input.isEmpty()) return emptySet()

  val first = input.take(1).toSet()
  val tail = input.drop(1).toSet()

  return combinations(tail, n - 1).map { rest -> first + rest }.toSet() + combinations(tail, n)
}

// Math
fun Int.isOdd() = this % 2 == 1
fun Long.isOdd() = this % 2 == 1L
fun Int.isEven() = !isOdd()
fun Long.isEven() = !isOdd()
fun Int.isZero() = this == 0
fun Long.isZero() = this == 0L
fun Int.isPositive() = this > 0
fun Long.isPositive() = this > 0L
fun Int.isNegative() = this < 0
fun Long.isNegative() = this < 0L
fun Int.isPositiveOrZero() = this >= 0
fun Long.isPositiveOrZero() = this >= 0L
fun Int.isNegativeOrZero() = this <= 0
fun Long.isNegativeOrZero() = this <= 0L

infix fun Int.divides(o: Int) = o % this == 0
infix fun Long.divides(o: Long) = o % this == 0L
infix fun Int.divisibleBy(o: Int) = o divides this
infix fun Long.divisibleBy(o: Long) = o divides this

infix fun Int.floorDiv(o: Int) = floor(toDouble() / o).toInt()
infix fun Long.floorDiv(o: Long) = floor(toDouble() / o).toInt()
infix fun Int.ceilDiv(o: Int) = ceil(toDouble() / o).toInt()
infix fun Long.ceilDiv(o: Long) = ceil(toDouble() / o).toInt()

infix fun Int.mod(m: Int) = ((this % m) + m) % m
infix fun Long.mod(m: Long) = ((this % m) + m) % m

// Number Theory
fun primeSieve(n: Int): List<Boolean> {
  val s = BooleanArray(n + 1) { true }
  val limit = sqrt(n.toDouble()).toInt()
  (2..limit).forEach { i ->
    if (s[i]) (i * i..n).forEach { j -> s[j] = false }
  }
  return s.toList()
}

fun primes(n: Int) = primeSieve(n).mapIndexedNotNull { i, p -> i.takeIf { p } }

// DP
inline fun <I, O> memoize(crossinline fn: (I) -> O): ((I) -> O) = with(ConcurrentHashMap<I, O>()) {
  { input -> get(input) ?: fn(input).also { output -> set(input, output) } }
}
// endregion

fun main() {
  val (y, k, n) = readInts()
  val r = (k .. n  step k).filter { it > y }
  if (r.isEmpty()) {
    writeLn("-1")
  } else {
    r.joinToString(" ") { "${it - y}" }.writeLn()
  }
  writer.flush()
}


//  B. Big Segment

// region Preamble

import java.util.concurrent.ConcurrentHashMap
import kotlin.math.*

// IO
val reader = System.`in`.bufferedReader()
val writer = System.out.bufferedWriter()

fun readLn(): String = reader.readLine()
fun readInt() = readLn().toInt()
fun readLong() = readLn().toLong()
fun readDouble() = readLn().toDouble()
fun readWords() = readLn().split(" ")
fun readInts() = readWords().map { it.toInt() }
fun readLongs() = readWords().map { it.toLong() }
fun readDoubles() = readWords().map { it.toDouble() }
fun readLines(n: Int) = List(n) { readLn() }

fun Boolean.yesNo() = if (this) "YES" else "NO"
fun writeLn(s: String) = writer.write("$s\n")

@JvmName("writeLn1")
fun String.writeLn() = writer.write("\n")

// Functional
fun List<Int>.cumulativeSum1() = runningFold(0) { x, y -> x + y }
fun List<Int>.cumulativeSum() = cumulativeSum1().drop(1)

@JvmName("cumulativeSum1Long")
fun List<Long>.cumulativeSum1() = runningFold(0L) { x, y -> x + y }

@JvmName("cumulativeSumLong")
fun List<Long>.cumulativeSum() = cumulativeSum1().drop(1)

fun <E> List<E>.isDistinct() = size == toSet().size

fun <T> List<T>.histogram() = groupingBy { it }.eachCount().withDefault { 0 }
fun String.histogram() = groupingBy { it }.eachCount().withDefault { 0 }

fun <T> List<T>.groupContiguous(): List<List<T>> {
  val groups = mutableListOf<MutableList<T>>()
  forEach { e ->
    if (e == groups.lastOrNull()?.lastOrNull()) {
      groups.last().add(e)
    } else {
      groups.add(mutableListOf(e))
    }
  }
  return groups
}

fun <T> permutationsWithReplacement(input: Set<T>, n: Int): List<List<T>> =
  if (n <= 0) listOf(emptyList())
  else input.flatMap { first ->
    permutationsWithReplacement(input, n - 1).map { rest ->
      listOf(first) + rest
    }
  }

fun <T> permutations(input: Set<T>): List<List<T>> {
  if (input.isEmpty()) return listOf(emptyList())

  val first = input.first()
  val tail = input.drop(1).toSet()

  return permutations(tail).flatMap { rest ->
    (0..rest.size).map {
      buildList {
        addAll(rest.take(it))
        add(first)
        addAll(rest.drop(it))
      }
    }
  }
}

fun <T> combinations(input: Set<T>, n: Int): Set<Set<T>> {
  if (n <= 0) return setOf(emptySet())
  if (input.isEmpty()) return emptySet()

  val first = input.take(1).toSet()
  val tail = input.drop(1).toSet()

  return combinations(tail, n - 1).map { rest -> first + rest }.toSet() + combinations(tail, n)
}

// Math
fun Int.isOdd() = this % 2 == 1
fun Long.isOdd() = this % 2 == 1L
fun Int.isEven() = !isOdd()
fun Long.isEven() = !isOdd()
fun Int.isZero() = this == 0
fun Long.isZero() = this == 0L
fun Int.isPositive() = this > 0
fun Long.isPositive() = this > 0L
fun Int.isNegative() = this < 0
fun Long.isNegative() = this < 0L
fun Int.isPositiveOrZero() = this >= 0
fun Long.isPositiveOrZero() = this >= 0L
fun Int.isNegativeOrZero() = this <= 0
fun Long.isNegativeOrZero() = this <= 0L

infix fun Int.divides(o: Int) = o % this == 0
infix fun Long.divides(o: Long) = o % this == 0L
infix fun Int.divisibleBy(o: Int) = o divides this
infix fun Long.divisibleBy(o: Long) = o divides this

infix fun Int.floorDiv(o: Int) = floor(toDouble() / o).toInt()
infix fun Long.floorDiv(o: Long) = floor(toDouble() / o).toInt()
infix fun Int.ceilDiv(o: Int) = ceil(toDouble() / o).toInt()
infix fun Long.ceilDiv(o: Long) = ceil(toDouble() / o).toInt()

infix fun Int.mod(m: Int) = ((this % m) + m) % m
infix fun Long.mod(m: Long) = ((this % m) + m) % m

// Number Theory
fun primeSieve(n: Int): List<Boolean> {
  val s = BooleanArray(n + 1) { true }
  val limit = sqrt(n.toDouble()).toInt()
  (2..limit).forEach { i ->
    if (s[i]) (i * i..n).forEach { j -> s[j] = false }
  }
  return s.toList()
}

fun primes(n: Int) = primeSieve(n).mapIndexedNotNull { i, p -> i.takeIf { p } }

// DP
inline fun <I, O> memoize(crossinline fn: (I) -> O): ((I) -> O) = with(ConcurrentHashMap<I, O>()) {
  { input -> get(input) ?: fn(input).also { output -> set(input, output) } }
}
// endregion

fun main() {
  val n = readInt()
  val segments = readLines(n).map { it.split(" ").map { it.toInt() } }
  val mn = segments.minOf { it.first() }
  val mx = segments.maxOf { it.last() }
  val sg = listOf(mn, mx)
  val r = segments.indexOf(sg)
  println(if (r >= 0) r + 1 else r)
}


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

fun <T : Comparable<T>> max(a: T, b: T): T = if (b > a) b else a
fun <T : Comparable<T>> min(a: T, b: T): T = if (b < a) b else a
fun Number.isEven(): Boolean = if (this.toInt() and 1 == 0) true else false
fun Number.isOdd (): Boolean = !this.isEven()

fun main(args: Array<String>) {
    if (args.isNotEmpty()) System.setIn(FileInputStream(args[0]))
    val br = BufferedReader(InputStreamReader(System.`in`))
    val bw = BufferedWriter(OutputStreamWriter(System.out))

    var st = StringTokenizer(br.readLine())
    val n = st.nextToken().toInt()
    val arr = IntArray(n + 2)

    st = StringTokenizer(br.readLine())
    for (i in 1..n) {
        arr[i] = st.nextToken().toInt()
    }
    arr[0] = Int.MAX_VALUE
    arr[n + 1] = Int.MAX_VALUE

    var answer = 0
    for (i in 1..n) {
        var cum = 1
        var j = i
        while (arr[j - 1] <= arr[j]) {
            --j
            ++cum
        }
        j = i
        while (arr[j + 1] <= arr[j]) {
            ++j
            ++cum
        }
        answer = max(answer, cum)
    }

    bw.write("$answer\n")
    bw.close()
}


fun main(args: Array<String>) {
    val n = readLine()?.trim()?.toInt()!!
    val matrix = (1..n).map{ readLine()?.trim()?.split(' ')?.map{it.toInt()}!!}.toList()
    val points =
    generateSequence(Pair(0,0)){Pair(it.first+1,it.second+1)}.take(n).plus(
            generateSequence(Pair(0,n-1)){Pair(it.first+1,it.second-1)}.take(n).plus(
                    generateSequence(Pair(n/2,0)){Pair(it.first,it.second+1)}.take(n).plus(
                        generateSequence(Pair(0,n/2)){Pair(it.first+1, it.second)}.take(n)
                    )
            )
    ).toSet()
    val sum = points.fold(0){acc, pair -> acc + matrix[pair.first][pair.second]}
    println(sum)
}


import kotlin.math.max

fun main() {
    val numRecords = readLine()!!.toInt()
    var sol = 0
    val regNumbers = mutableSetOf<String>()
    for (i in 1..numRecords) {
        val (action, regNumber) = readLine()!!.split(" ")
        if (action == "+")
            regNumbers.add(regNumber)
        else {
            if (regNumber in regNumbers) {
                sol = max(sol, regNumbers.size)
                regNumbers.remove(regNumber)
            } else {
                sol = max(sol + 1, regNumbers.size + 1)
            }
        }
    }
    sol = max(sol, regNumbers.size)
    print(sol)
}


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

class InputReader(val stream: InputStream) {
    val buf = ByteArray(1024)
    var curChar: Int = 0
    var numChars: Int = 0

    fun read(): Int {
        if (numChars == -1)
            throw InputMismatchException()
        if (curChar >= numChars) {
            curChar = 0
            try {
                numChars = stream.read(buf)
            } catch (e: IOException) {
                throw InputMismatchException()
            }
            if (numChars <= 0)
                return -1
        }
        return buf[curChar++].toInt()
    }

    fun nextInt(): Int {
        var c = read()
        while (isSpaceChar(c))
            c = read()
        var sgn = 1
        if (c == 45) {
            sgn = -1
            c = read()
        }
        var res = 0
        do {
            if (c < 48 || c > 57)
                throw InputMismatchException()
            res *= 10
            res += c and 15
            c = read()
        } while (!isSpaceChar(c))
        return res * sgn
    }

    fun nextLong(): Long {
        var c = read()
        while (isSpaceChar(c))
            c = read()
        var sgn = 1
        if (c == 45) {
            sgn = -1
            c = read()
        }
        var res: Long = 0
        do {
            if (c < 48 || c > 57)
                throw InputMismatchException()
            res *= 10
            res += c and 15
            c = read()
        } while (!isSpaceChar(c))
        return res * sgn
    }

    fun nextString(): String {
        var c = read()
        while (isSpaceChar(c))
            c = read()
        val res = StringBuilder()
        do {
            res.appendCodePoint(c)
            c = read()
        } while (!isSpaceChar(c))
        return res.toString()
    }

    fun isSpaceChar(c: Int): Boolean {
        return c == 32 || c == 10 || c == 13 || c == 9 || c == -1
    }
}

class OutputWriter(val stream: OutputStream) {
    val buf = ByteArray(65536)
    var curPos: Int = 0

    fun write(c: Char) {
        if (buf.size - curPos < 1) flush()
        buf[curPos++] = c.toByte()
    }

    fun write(s: String) {
        if (buf.size - curPos < s.length) flush()
        var idx = 0
        var remaining = s.length
        while (remaining > buf.size) {
            while (curPos < buf.size) buf[curPos++] = s[idx++].toByte()
            flush()
            remaining -= buf.size
        }
        while (idx < s.length) buf[curPos++] = s[idx++].toByte()
    }

    fun flush() {
        stream.write(buf, 0, curPos)
        curPos = 0
    }
}

@Suppress("NOTHING_TO_INLINE")
inline fun Number.isOdd (): Boolean = this.toInt() and 1 == 1

fun main(args: Array<String>) {
    if (args.isNotEmpty()) System.setIn(FileInputStream(args[0]))
    val ir = InputReader(System.`in`)
    val ow = OutputWriter(System.out)

    val n = ir.nextInt()
    var s = ir.nextString()
    if (s.length.isOdd()) {
        ow.write(s.slice(0..2))
        s = s.drop(3)
    } else {
        ow.write(s.slice(0..1))
        s = s.drop(2)
    }
    while (s.isNotEmpty()) {
        ow.write('-')
        ow.write(s.slice(0..1))
        s = s.drop(2)
    }
    ow.write('\n')
    ow.flush()
}


fun main() {
    fun readInts() = readLine()!!.split(" ").map(String::toInt)

    val (numRows, numColumns) = readInts()
    val grid = Array(numRows) { "" }
    val crossed = Array(numRows) { BooleanArray(numColumns) }
    for (row in 0 until numRows) grid[row] = readLine()!!
    val charToRowByColumn = Array(numColumns) { mutableMapOf<Char, Int>() }
    for ((numRow, row) in grid.withIndex()) {
        val charToColumn = mutableMapOf<Char, Int>()
        for ((numColumn, c) in row.withIndex()) {
            if (c in charToColumn) {
                crossed[numRow][numColumn] = true
                crossed[numRow][charToColumn[c]!!] = true
            } else
                charToColumn[c] = numColumn

            if (c in charToRowByColumn[numColumn]) {
                crossed[numRow][numColumn] = true
                crossed[charToRowByColumn[numColumn][c]!!][numColumn] = true
            } else
                charToRowByColumn[numColumn][c] = numRow
        }
    }
    val sb = StringBuilder()
    for (numRow in 0 until numRows)
        for (numColumn in 0 until numColumns)
            if (!crossed[numRow][numColumn]) sb.append(grid[numRow][numColumn])
    print(sb.toString())
}

[{'input': '3 3\r\ncba\r\nbcd\r\ncbc\r\n', 'output': ['abcd']}, {'input': '5 5\r\nfcofd\r\nooedo\r\nafaoa\r\nrdcdf\r\neofsf\r\n', 'output': ['codeforces']}, {'input': '4 4\r\nusah\r\nusha\r\nhasu\r\nsuha\r\n', 'output': ['ahhasusu']}, {'input': '7 5\r\naabcd\r\neffgh\r\niijkk\r\nlmnoo\r\npqqrs\r\nttuvw\r\nxxyyz\r\n', 'output': ['bcdeghjlmnprsuvwz']}, {'input': '10 10\r\naaaaaaaaaa\r\nbccceeeeee\r\ncdfffffffe\r\ncdfiiiiile\r\ncdfjjjjile\r\ndddddddile\r\nedfkkkkile\r\nedddddddde\r\ngggggggggg\r\nhhhhhhhhhe\r\n', 'output': ['b']}, {'input': '15 3\r\njhg\r\njkn\r\njui\r\nfth\r\noij\r\nyuf\r\nyfb\r\nugd\r\nhgd\r\noih\r\nhvc\r\nugg\r\nyvv\r\ntdg\r\nhgf\r\n', 'output': ['hkniftjfbctd']}, {'input': '17 19\r\nbmzbmweyydiadtlcoue\r\ngmdbyfwurpwbpuvhifn\r\nuapwyndmhtqvkgkbhty\r\ntszotwflegsjzzszfwt\r\nzfpnscguemwrczqxyci\r\nvdqnkypnxnnpmuduhzn\r\noaquudhavrncwfwujpc\r\nmiggjmcmkkbnjfeodxk\r\ngjgwxtrxingiqquhuwq\r\nhdswxxrxuzzfhkplwun\r\nfagppcoildagktgdarv\r\neusjuqfistulgbglwmf\r\ngzrnyxryetwzhlnfewc\r\nzmnoozlqatugmdjwgzc\r\nfabbkoxyjxkatjmpprs\r\nwkdkobdagwdwxsufees\r\nrvncbszcepigpbzuzoo\r\n', 'output': ['lcorviunqvgblgjfsgmrqxyivyxodhvrjpicbneodxjtfkpolvejqmllqadjwotmbgxrvs']}, {'input': '1 1\r\na\r\n', 'output': ['a']}, {'input': '2 2\r\nzx\r\nxz\r\n', 'output': ['zxxz']}, {'input': '1 2\r\nfg\r\n', 'output': ['fg']}, {'input': '2 1\r\nh\r\nj\r\n', 'output': ['hj']}, {'input': '1 3\r\niji\r\n', 'output': ['j']}, {'input': '3 1\r\nk\r\np\r\nk\r\n', 'output': ['p']}, {'input': '2 3\r\nmhw\r\nbfq\r\n', 'output': ['mhwbfq']}, {'input': '3 2\r\nxe\r\ner\r\nwb\r\n', 'output': ['xeerwb']}, {'input': '3 7\r\nnutuvjg\r\ntgqutfn\r\nyfjeiot\r\n', 'output': ['ntvjggqfnyfjeiot']}, {'input': '5 4\r\nuzvs\r\namfz\r\nwypl\r\nxizp\r\nfhmf\r\n', 'output': ['uzvsamfzwyplxizphm']}, {'input': '8 9\r\ntjqrtgrem\r\nrwjcfuoey\r\nywrjgpzca\r\nwabzggojv\r\najqmmcclh\r\nozilebskd\r\nqmgnbmtcq\r\nwakptzkjr\r\n', 'output': ['mrjcfuyyrjpzabzvalhozilebskdgnbtpzr']}, {'input': '9 3\r\njel\r\njws\r\ntab\r\nvyo\r\nkgm\r\npls\r\nabq\r\nbjx\r\nljt\r\n', 'output': ['elwtabvyokgmplabqbxlt']}, {'input': '7 6\r\neklgxi\r\nxmpzgf\r\nxvwcmr\r\nrqssed\r\nouiqpt\r\ndueiok\r\nbbuorv\r\n', 'output': ['eklgximpzgfvwcmrrqedoiqptdeiokuorv']}, {'input': '14 27\r\npzoshpvvjdpmwfoeojapmkxjrnk\r\nitoojpcorxjdxrwyewtmmlhjxhx\r\ndoyopbwusgsmephixzcilxpskxh\r\nygpvepeuxjbnezdrnjfwdhjwjka\r\nrfjlbypoalbtjwrpjxzenmeipfg\r\nkhjhrtktcnajrnbefhpavxxfnlx\r\nvwlwumqpfegjgvoezevqsolaqhh\r\npdrvrtzqsoujqfeitkqgtxwckrl\r\nxtepjflcxcrfomhqimhimnzfxzg\r\nwhkfkfvvjwkmwhfgeovwowshyhw\r\nolchgmhiehumivswgtfyhqfagbp\r\ntdudrkttpkryvaiepsijuejqvmq\r\nmuratfqqdbfpefmhjzercortroh\r\nwxkebkzchupxumfizftgqvuwgau\r\n', 'output': ['zshdanicdyldybwgclygzrhkayatwxznmicbpvlupfsoewcleploqngsyolceswtyqbpyasmuadbpcehqva']}, {'input': '1 100\r\nysijllpanprcrrtvokqmmupuptvawhvnekeybdkzqaduotmkfwybqvytkbjfzyqztmxckizheorvkhtyoohbswcmhknyzlgxordu\r\n', 'output': ['g']}, {'input': '2 100\r\ngplwoaggwuxzutpwnmxhotbexntzmitmcvnvmuxknwvcrnsagvdojdgaccfbheqojgcqievijxapvepwqolmnjqsbejtnkaifstp\r\noictcmphxbrylaarcwpruiastazvmfhlcgticvwhpxyiiqokxcjgwlnfykkqdsfmrfaedzchrfzlwdclqjxvidhomhxqnlmuoowg\r\n', 'output': ['rbe']}, {'input': '3 100\r\nonmhsoxoexfwavmamoecptondioxdjsoxfuqxkjviqnjukwqjwfadnohueaxrkreycicgxpmogijgejxsprwiweyvwembluwwqhj\r\nuofldyjyuhzgmkeurawgsrburovdppzjiyddpzxslhyesvmuwlgdjvzjqqcpubfgxliulyvxxloqyhxspoxvhllbrajlommpghlv\r\nvdohhghjlvihrzmwskxfatoodupmnouwyyfarhihxpdnbwrvrysrpxxptdidpqabwbfnxhiziiiqtozqjtnitgepxjxosspsjldo\r\n', 'output': ['blkck']}, {'input': '100 1\r\na\r\nm\r\nn\r\nh\r\na\r\nx\r\nt\r\na\r\no\r\np\r\nj\r\nz\r\nr\r\nk\r\nq\r\nl\r\nb\r\nr\r\no\r\ni\r\ny\r\ni\r\np\r\ni\r\nt\r\nn\r\nd\r\nc\r\nz\r\np\r\nu\r\nn\r\nw\r\ny\r\ng\r\ns\r\nt\r\nm\r\nz\r\ne\r\nv\r\ng\r\ny\r\nj\r\nd\r\nz\r\ny\r\na\r\nn\r\nx\r\nk\r\nd\r\nq\r\nn\r\nv\r\ng\r\nk\r\ni\r\nk\r\nf\r\na\r\nb\r\nw\r\no\r\nu\r\nw\r\nk\r\nk\r\nb\r\nz\r\nu\r\ni\r\nu\r\nv\r\ng\r\nv\r\nx\r\ng\r\np\r\ni\r\nz\r\ns\r\nv\r\nq\r\ns\r\nb\r\nw\r\ne\r\np\r\nk\r\nt\r\np\r\nd\r\nr\r\ng\r\nd\r\nk\r\nm\r\nf\r\nd\r\n', 'output': ['hlc']}, {'input': '100 2\r\nhd\r\ngx\r\nmz\r\nbq\r\nof\r\nst\r\nzc\r\ndg\r\nth\r\nba\r\new\r\nbw\r\noc\r\now\r\nvh\r\nqp\r\nin\r\neh\r\npj\r\nat\r\nnn\r\nbr\r\nij\r\nco\r\nlv\r\nsa\r\ntb\r\nbl\r\nsr\r\nxa\r\nbz\r\nrp\r\nsz\r\noi\r\nec\r\npw\r\nhf\r\njm\r\nwu\r\nhq\r\nra\r\npv\r\ntc\r\ngv\r\nik\r\nux\r\ntz\r\nbf\r\nty\r\ndk\r\nwo\r\nor\r\nza\r\nkv\r\nqt\r\nfa\r\njy\r\nbk\r\nuv\r\ngk\r\ncz\r\nds\r\nie\r\noq\r\nmf\r\nxn\r\nql\r\nxs\r\nfb\r\niv\r\ncj\r\nkn\r\nns\r\nlg\r\nji\r\nha\r\naj\r\ndg\r\nfj\r\nut\r\nsg\r\nju\r\noc\r\nov\r\nhe\r\nnw\r\nbl\r\nlp\r\nbx\r\nnm\r\nyq\r\ncw\r\nov\r\nxk\r\npg\r\noh\r\npl\r\nuo\r\ngf\r\nul\r\n', 'output': ['dvy']}, {'input': '100 3\r\nruy\r\nmye\r\njgp\r\nscn\r\nktq\r\nalx\r\nmvk\r\nlpm\r\nkry\r\norb\r\nmpu\r\nzcv\r\nlge\r\nkft\r\ndzp\r\ntfb\r\nhqz\r\nuur\r\nhry\r\nzjx\r\ncuo\r\nqqc\r\ntih\r\nenj\r\nvnp\r\nbwi\r\nzzh\r\nhkc\r\nwdr\r\nldh\r\nvel\r\nizj\r\nfhb\r\nqrn\r\nqpp\r\nvzs\r\nlhg\r\nkee\r\nlbq\r\nzhy\r\nwcl\r\nyaa\r\nton\r\nfly\r\nkyw\r\nept\r\ngwq\r\ncoe\r\nopd\r\neez\r\nnmx\r\nnjg\r\nwhy\r\nvel\r\nafq\r\nnbq\r\nulx\r\noxs\r\nbbo\r\nyhx\r\nfmz\r\nnrg\r\nnfm\r\njek\r\nbeu\r\ntya\r\nxgs\r\nsgg\r\nnkq\r\nbbv\r\nwkd\r\ntns\r\nfdt\r\neox\r\nobc\r\neab\r\nkkj\r\noub\r\ngji\r\nrht\r\nozv\r\nysk\r\nsbt\r\nflf\r\npbu\r\nlxb\r\npzs\r\nrzh\r\ncea\r\nkmi\r\nuea\r\nncc\r\nzng\r\nvkn\r\njhn\r\njqw\r\nlqc\r\nmbt\r\nlov\r\ngam\r\n', 'output': ['tvdiixs']}]


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

fun <T : Comparable<T>> max(a: T, b: T): T = if (b > a) b else a
fun <T : Comparable<T>> min(a: T, b: T): T = if (b < a) b else a
fun Number.isEven(): Boolean = if (this.toInt() and 1 == 0) true else false
fun Number.isOdd (): Boolean = !this.isEven()

fun main(args: Array<String>) {
    if (args.isNotEmpty()) System.setIn(FileInputStream(args[0]))
    val br = BufferedReader(InputStreamReader(System.`in`))
    val bw = BufferedWriter(OutputStreamWriter(System.out))

    val st = StringTokenizer(br.readLine())
    val n = st.nextToken().toInt()
    val m = st.nextToken().toInt()
    val arr = Array(n) { CharArray(m) }
    for (i in arr.indices) {
        val st = StringTokenizer(br.readLine())
        arr[i] = st.nextToken().toCharArray()
    }
    val modu = (1e9 + 7).toInt()
    var answer = 1L
    for (i in arr[0].indices) {
        answer *= arr.map { it[i] }.distinct().count()
        answer %= modu
    }

    bw.write("$answer\n")
    bw.close()
}

[{'input': '2 3\r\nAAB\r\nBAA\r\n', 'output': ['4\r\n']}, {'input': '4 5\r\nABABA\r\nBCGDG\r\nAAAAA\r\nYABSA\r\n', 'output': ['216\r\n']}, {'input': '1 1\r\nE\r\n', 'output': ['1\r\n']}, {'input': '2 2\r\nNS\r\nPD\r\n', 'output': ['4\r\n']}, {'input': '3 4\r\nPJKD\r\nNFJX\r\nFGFK\r\n', 'output': ['81\r\n']}, {'input': '4 5\r\nSXFMY\r\nATHLM\r\nKDDQW\r\nZWGDS\r\n', 'output': ['1024\r\n']}, {'input': '20 14\r\nJNFKBBBJYZHWQE\r\nLBOKZCPFNKDBJY\r\nXKNWGHQHIOXUPF\r\nDDNRUKVUGHWMXW\r\nMTIZFNAAFEAPHX\r\nIXBQOOHEULZYHU\r\nMRCSREUEOOMUUN\r\nHJTSQWKUFYZDQU\r\nGMCMUZCOPRVEIQ\r\nXBKKGGJECOBLTH\r\nXXHTLXCNJZJUAF\r\nVLJRKXXXWMTPKZ\r\nPTYMNPTBBCWKAD\r\nQYJGOBUBHMEDYE\r\nGTKUUVVNKAHTUI\r\nZNKXYZPCYLBZFP\r\nQCBLJTRMBDWNNE\r\nTDOKJOBKEOVNLZ\r\nFKZUITYAFJOQIM\r\nUWQNSGLXEEIRWF\r\n', 'output': ['515139391\r\n']}, {'input': '5 14\r\nAQRXUQQNSKZPGC\r\nDTTKSPFGGVCLPT\r\nVLZQWWESCHDTAZ\r\nCOKOWDWDRUOMHP\r\nXDTRBIZTTCIDGS\r\n', 'output': ['124999979\r\n']}, {'input': '9 23\r\nOILBYKHRGMPENVFNHLSIUOW\r\nLPJFHTUQUINAALRDGLSQUXR\r\nLYYJJEBNZATAFQWTDZSPUNZ\r\nHSJPIQKKWWERJZIEMLCZUKI\r\nOJYIEYDGPFWRHCMISJCCUEM\r\nLMGKZVFYIVDRTIHBWPCNUTG\r\nUBGGNCITVHAIPKXCLTSAULQ\r\nOWSAWUOXQDBSXXBHTLSXUVD\r\nUGQTIZQPBGMASRQPVPSFUWK\r\n', 'output': ['454717784\r\n']}, {'input': '25 4\r\nLVKG\r\nMICU\r\nZHKW\r\nLFGG\r\nOWQO\r\nLCQG\r\nLVXU\r\nOUKB\r\nLNQX\r\nZJTO\r\nOOQX\r\nLVQP\r\nMFQB\r\nMRQV\r\nOIQH\r\nOPXX\r\nXFKU\r\nFCQB\r\nZPKH\r\nLVCH\r\nNFCU\r\nOVQW\r\nOZKU\r\nLFHX\r\nLPXO\r\n', 'output': ['5733\r\n']}, {'input': '30 10\r\nUTNTGOKZYJ\r\nQHOUHNYZVW\r\nLTVGHJRZVW\r\nMZHYHOLZYJ\r\nERYEUEPZYE\r\nUZDBFTURYJ\r\nRVSMQTIZGW\r\nWDJQHMIRYY\r\nKCORHQPZYE\r\nRRPLFOZZVY\r\nJTXMFNNNYJ\r\nMVTGGOZZVV\r\nEHAFFNUZVF\r\nLBRNWJZNYE\r\nJVMOHTPZYJ\r\nWTARFJLZVV\r\nLVJCWOURVW\r\nLCLQFJYRVV\r\nQVBVGNJRYF\r\nNTZGHOLRYE\r\nMGQKHOUPYJ\r\nRRSSBXPZYJ\r\nRYCRGTLZYJ\r\nJRDEGNKRVW\r\nRZKFGHYRVG\r\nMDJBFNIZYG\r\nMPLWHXIZYE\r\nSRZMHMURVE\r\nMTEBBMRZYJ\r\nJPJIFOLZYM\r\n', 'output': ['919913906\r\n']}, {'input': '40 7\r\nPNTVVER\r\nPAHTQDR\r\nRXMJVAS\r\nVIQNLYC\r\nILPUSVX\r\nYJOXQDJ\r\nSEFODTO\r\nOTJMREL\r\nLIQRZGD\r\nLBJJPOR\r\nRUTYHQO\r\nRIWEPBD\r\nKQUMFIB\r\nISTRRYH\r\nXBTOTGK\r\nRFQODEY\r\nHDSTZTP\r\nYCXFAGL\r\nAREGRFU\r\nLELZUYU\r\nGVABDKH\r\nFJAMMME\r\nACVULXE\r\nJHVPJAS\r\nAAQNMBX\r\nJJGUCXG\r\nOQATILQ\r\nNEOSHJM\r\nHFLWOFM\r\nICYEQHY\r\nFACGLYP\r\nPLLXJEQ\r\nDCHXYPB\r\nAGDDZJJ\r\nLSQRXTN\r\nHDQZXIY\r\nNAHDDWW\r\nQCMXRQN\r\nFDUDSZO\r\nHKBEVTW\r\n', 'output': ['206575993\r\n']}, {'input': '2 2\r\nAA\r\nBB\r\n', 'output': ['4\r\n']}, {'input': '1 10\r\nAAAAAAAAAA\r\n', 'output': ['1\r\n']}, {'input': '2 8\r\nAAAAAAAA\r\nBBBBBBBB\r\n', 'output': ['256\r\n']}, {'input': '10 10\r\nAAAAAAAAAA\r\nBBBBBBBBBB\r\nCCCCCCCCCC\r\nDDDDDDDDDD\r\nAAAAAAAAAA\r\nBBBBBBBBBB\r\nCCCCCCCCCC\r\nDDDDDDDDDD\r\nAAAAAAAAAA\r\nBBBBBBBBBB\r\n', 'output': ['1048576\r\n']}, {'input': '1 20\r\nAAAAAAAAAAAAAAAAAAAA\r\n', 'output': ['1\r\n']}, {'input': '20 1\r\nA\r\nB\r\nC\r\nD\r\nE\r\nF\r\nG\r\nA\r\nB\r\nC\r\nD\r\nE\r\nF\r\nG\r\nA\r\nB\r\nC\r\nD\r\nE\r\nF\r\n', 'output': ['7\r\n']}, {'input': '5 60\r\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\r\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\r\nCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\r\nDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD\r\nEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\r\n', 'output': ['449874206\r\n']}, {'input': '50 4\r\nAAAA\r\nBBBB\r\nCCCC\r\nDDDD\r\nEEEE\r\nFFFF\r\nGGGG\r\nHHHH\r\nIIII\r\nJJJJ\r\nAAAA\r\nBBBB\r\nCCCC\r\nDDDD\r\nEEEE\r\nFFFF\r\nGGGG\r\nHHHH\r\nIIII\r\nJJJJ\r\nAAAA\r\nBBBB\r\nCCCC\r\nDDDD\r\nEEEE\r\nFFFF\r\nGGGG\r\nHHHH\r\nIIII\r\nJJJJ\r\nAAAA\r\nBBBB\r\nCCCC\r\nDDDD\r\nEEEE\r\nFFFF\r\nGGGG\r\nHHHH\r\nIIII\r\nJJJJ\r\nAAAA\r\nBBBB\r\nCCCC\r\nDDDD\r\nEEEE\r\nFFFF\r\nGGGG\r\nHHHH\r\nIIII\r\nJJJJ\r\n', 'output': ['10000\r\n']}, {'input': '1 100\r\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\r\n', 'output': ['1\r\n']}, {'input': '100 1\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\nA\r\n', 'output': ['1\r\n']}, {'input': '100 1\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\nA\r\nB\r\n', 'output': ['2\r\n']}, {'input': '100 1\r\nA\r\nB\r\nC\r\nD\r\nE\r\nF\r\nG\r\nH\r\nI\r\nJ\r\nK\r\nL\r\nM\r\nN\r\nA\r\nB\r\nC\r\nD\r\nE\r\nF\r\nG\r\nH\r\nI\r\nJ\r\nK\r\nL\r\nM\r\nN\r\nA\r\nB\r\nC\r\nD\r\nE\r\nF\r\nG\r\nH\r\nI\r\nJ\r\nK\r\nL\r\nM\r\nN\r\nA\r\nB\r\nC\r\nD\r\nE\r\nF\r\nG\r\nH\r\nI\r\nJ\r\nK\r\nL\r\nM\r\nN\r\nA\r\nB\r\nC\r\nD\r\nE\r\nF\r\nG\r\nH\r\nI\r\nJ\r\nK\r\nL\r\nM\r\nN\r\nA\r\nB\r\nC\r\nD\r\nE\r\nF\r\nG\r\nH\r\nI\r\nJ\r\nK\r\nL\r\nM\r\nN\r\nA\r\nB\r\nC\r\nD\r\nE\r\nF\r\nG\r\nH\r\nI\r\nJ\r\nK\r\nL\r\nM\r\nN\r\nA\r\nB\r\n', 'output': ['14\r\n']}, {'input': '100 1\r\nA\r\nB\r\nC\r\nD\r\nE\r\nF\r\nG\r\nH\r\nI\r\nJ\r\nK\r\nL\r\nM\r\nN\r\nO\r\nP\r\nQ\r\nR\r\nS\r\nT\r\nU\r\nV\r\nW\r\nX\r\nY\r\nZ\r\nA\r\nB\r\nC\r\nD\r\nE\r\nF\r\nG\r\nH\r\nI\r\nJ\r\nK\r\nL\r\nM\r\nN\r\nO\r\nP\r\nQ\r\nR\r\nS\r\nT\r\nU\r\nV\r\nW\r\nX\r\nY\r\nZ\r\nA\r\nB\r\nC\r\nD\r\nE\r\nF\r\nG\r\nH\r\nI\r\nJ\r\nK\r\nL\r\nM\r\nN\r\nO\r\nP\r\nQ\r\nR\r\nS\r\nT\r\nU\r\nV\r\nW\r\nX\r\nY\r\nZ\r\nA\r\nB\r\nC\r\nD\r\nE\r\nF\r\nG\r\nH\r\nI\r\nJ\r\nK\r\nL\r\nM\r\nN\r\nO\r\nP\r\nQ\r\nR\r\nS\r\nT\r\nU\r\nV\r\n', 'output': ['26\r\n']}]


fun main() {
    val t = readLine()!!.toInt()

    for (i in 0 until t) {
        val n = readLine()!!.toInt()

        if (n <= 2) {
            println(0)
        } else {
            if (n % 2 == 0)
                println((n / 2) - 1)
            else
                println(n / 2)
        }
    }
}


import java.io.BufferedReader
import java.io.IOException
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*

fun main(args : Array<String>) {
    Thread { run() }.start()
}

val scanner = Scanner(System.`in`)
var n = scanner.nextInt()
val arr = Array<Array<Pair<Int, Int>>>(1000) { y -> Array<Pair<Int, Int>>(1000) { Pair(it, y) } }
var x = IntArray(1000) { -1 }
var y = IntArray(1000) { -1 }
fun get(x: Int, y: Int): Pair<Int, Int> {
    if (arr[y][x].first != x || arr[y][x].second != y)
        arr[y][x] = get(arr[y][x].first, arr[y][x].second)
    return arr[y][x]
}
fun join(x1: Int, y1: Int, x2: Int, y2: Int) {
    val root = get(x1, y1)
    arr[root.second][root.first] = get(x2, y2)
}

fun run() {

    var res = 0
    for (i in 0 until n) {
        val a = scanner.nextInt() - 1
        val b = scanner.nextInt() - 1
        if (x[b] != -1 && y[a] != -1 && get(b, x[b]) != get(y[a], a))
            res--
        if (x[b] != -1)
            join(b, a, b, x[b])
        if (y[a] != -1)
            join(b, a, y[a], a)
        if (x[b] == -1 && y[a] == -1)
            res++
        if (x[b] == -1)
            x[b] = a
        if (y[a] == -1)
            y[a] = b
    }
    println(res - 1)

}

class Scanner(s: InputStream) {
    var st: StringTokenizer? = null
    var br: BufferedReader = BufferedReader(InputStreamReader(s))
    @Throws(IOException::class)
    operator fun next(): String {
        while (st == null || !st!!.hasMoreTokens())
            st = StringTokenizer(br.readLine())
        return st!!.nextToken()
    }
    @Throws(IOException::class)
    fun nextInt(): Int {
        return Integer.parseInt(next())
    }
    @Throws(IOException::class)
    fun nextLong(): Long {
        return java.lang.Long.parseLong(next())
    }
    @Throws(IOException::class)
    fun nextLine(): String {
        return br.readLine()
    }
    @Throws(IOException::class)
    fun nextDouble(): Double {
        return java.lang.Double.parseDouble(next())
    }
    @Throws(IOException::class)
    fun ready(): Boolean {
        return br.ready()
    }
}

fun IntArray.print() {
    println(Arrays.toString(this))
}

fun Array<IntArray>.print() {
    for (i in this)
        i.print()
}


import java.io.PrintWriter
import kotlin.math.*

fun main() {
    io.apply done@ {

        val n = int
        val k = int

        val d = ints(n)
        val colors = str(n)

        val red = (0 until n).filter { colors[it] == 'R' }.map { d[it] }.toIntArray()
        val orange = (0 until n).filter { colors[it] == 'O' }.map { d[it] }.toIntArray()
        val white = (0 until n).filter { colors[it] == 'W' }.map { d[it] }.toIntArray()

        if (k < 2 || orange.isEmpty() || (red.isEmpty() && white.isEmpty())) {
            cout .. -1 .. nl
            return@done
        }

        fun compose(a: IntArray, b: IntArray): Int {
            if (a.size + b.size < k || a.isEmpty() || b.isEmpty())
                return -1
            var ia = 1
            var ib = 1
            var res = a[0] + b[0]
            repeat(k - 2) {
                if (ia == a.size)
                    res += b[ib++]
                else if (ib == b.size)
                    res += a[ia++]
                else {
                    if (a[ia] > b[ib])
                        res += a[ia++]
                    else
                        res += b[ib++]
                }
            }
            return res
        }

        red.sortDescending()
        orange.sortDescending()
        white.sortDescending()

        val ans = max(compose(red, orange), compose(white, orange))
        cout .. ans .. nl

    }.cout.flush()
}

// @formatter:off
private val io = object {
    private val `in` = System.`in`
    private fun ll(): Long {
        var x: Int; var q = false; var n = 0L; do x = `in`.read() while (x < 33); if (x == 45) { q = true; x = `in`.read() }
        do { n = n * 10 - x + 48; x = `in`.read() } while (x > 32); return if (q) n else -n
    }
    val int get() = ll().toInt(); val long get() = ll()
    fun ints(n: Int = int): IntArray { return IntArray(n) { int } }
    fun ints1(n: Int = int): IntArray { return IntArray(n) { int - 1 } }
    val cout = PrintWriter(System.out); val nl = "\n"
    private var buf = CharArray(32)
    private var bufSize = 32
    fun str(expect: Int = 32): String {
        var ix = 0
        var x: Int
        if (bufSize < expect)
            buf = CharArray(expect)
        do x = `in`.read() while (x < 33)
        do {
            if (ix == bufSize) { bufSize *= 2; buf = buf.copyOf(bufSize) }
            buf[ix++] = x.toChar()
            x = `in`.read()
        } while (x > 32)
        return java.lang.String.copyValueOf(buf, 0, ix)
    }
    operator fun PrintWriter.rangeTo(a: Int): PrintWriter { print(a); print(" "); return this }
    operator fun PrintWriter.rangeTo(a: Long): PrintWriter { print(a); print(" "); return this }
    operator fun PrintWriter.rangeTo(a: IntArray): PrintWriter { a.forEach { print(it); print(" ") }; return this }
    operator fun PrintWriter.rangeTo(a: String): PrintWriter { write(a); return this }
} // @formatter:on

/* ----------- */


import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

val MOD = 1_000_000_007L

tailrec fun gcd(a: Long, b: Long): Long {
  if (a < b) return gcd(b, a)
  if (b == 0L) return a
  return gcd(b, a % b)
}
class Solver(stream: InputStream, private val out: java.io.PrintWriter) {
  fun solve() {
    val N = ni()
    val A = na(N, -1)
    var mx = 0
    val cycles = mutableMapOf<Int, Int>()

    fun dfs(u: Int): Triple<Int, Int, Int> {
      val path = mutableListOf<Int>()
      val visited = BooleanArray(N)
      var cur = u
      while(!visited[cur]) {
        visited[cur] = true
        path += cur
        cur = A[cur]
      }
      val l = path.indexOf(cur)
      val cycle = path.drop(l)
      return Triple(l, cycle.min()!!, cycle.size)
    }

    for (i in 0 until N) {
      val res = dfs(i)
      mx = max(mx, res.first)
      cycles[res.second] = res.third
    }

    debug{cycles.toString()}

    var lcm = 1L
    for (i in cycles) {
      val g = gcd(lcm, i.value.toLong())
      lcm = lcm * i.value.toLong() / g
    }
    debug{"lcm:$lcm mx:$mx"}
    var ans = lcm
    while(ans < mx) {
      ans += lcm
    }
    out.println(ans)
  }

  private val isDebug = try {
    // なんか本番でエラーでる
    System.getenv("MY_DEBUG") != null
  } catch (t: Throwable) {
    false
  }

  private var tokenizer: StringTokenizer? = null
  private val reader = BufferedReader(InputStreamReader(stream), 32768)
  private fun next(): String {
    while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
      tokenizer = StringTokenizer(reader.readLine())
    }
    return tokenizer!!.nextToken()
  }

  private fun ni() = next().toInt()
  private fun nl() = next().toLong()
  private fun ns() = next()
  private fun na(n: Int, offset: Int = 0): IntArray {
    return map(n) { ni() + offset }
  }
  private fun nal(n: Int, offset: Int = 0): LongArray {
    val res = LongArray(n)
    for (i in 0 until n) {
      res[i] = nl() + offset
    }
    return res
  }

  private fun na2(n: Int, offset: Int = 0): Array<IntArray> {
    val a  = Array(2){IntArray(n)}
    for (i in 0 until n) {
      for (e in a) {
        e[i] = ni() + offset
      }
    }
    return a
  }

  private inline fun map(n: Int, f: (Int) -> Int): IntArray {
    val res = IntArray(n)
    for (i in 0 until n) {
      res[i] = f(i)
    }
    return res
  }

  private inline fun debug(msg: () -> String) {
    if (isDebug) System.err.println(msg())
  }

  private fun debug(a: LongArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: IntArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: BooleanArray) {
    debug { a.map { if (it) 1 else 0 }.joinToString("") }
  }

  private fun debugDim(A: Array<LongArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }
  private fun debugDim(A: Array<IntArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }

  /**
   * 勝手にimport消されるのを防ぎたい
   */
  private fun hoge() {
    min(1, 2)
    max(1, 2)
    abs(-10)
  }
}

fun main() {
  val out = java.io.PrintWriter(System.out)
  Solver(System.`in`, out).solve()
  out.flush()
}


import java.io.*
import java.util.Comparator
import java.util.InputMismatchException
import java.util.TreeSet

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
object programkt {
    @JvmStatic
    fun main(args: Array<String>) {
        val inputStream = System.`in`
        val outputStream = System.out
        val `in` = InputReader(inputStream)
        val out = OutputWriter(outputStream)
        val solver = Segments()
        solver.solve(1, `in`, out)
        out.close()
    }

    internal class Segments {
        fun solve(testNumber: Int, `in`: InputReader, out: OutputWriter) {
            var n = `in`.nextInt()
            val ts = TreeSet(Comparator.comparingInt<Interval> { x -> x.l })
            while (n-- > 0) {
                val l = `in`.nextInt()
                val r = `in`.nextInt()
                var add = Segments.Interval(l, r)
                while (true) {
                    val qq = ts.floor(add)
                    if (qq == null || qq.r < add.l) break
                    ts.remove(qq)
                    add = Segments.Interval(Math.min(qq.l, add.l), Math.max(qq.r, add.r))
                }
                while (true) {
                    val qq = ts.ceiling(add)
                    if (qq == null || qq.l > add.r) break
                    ts.remove(qq)
                    add = Segments.Interval(Math.min(qq.l, add.l), Math.max(qq.r, add.r))
                }
                ts.add(add)
                out.println(ts.size)
            }
        }

        internal class Interval(var l: Int, var r: Int) {

            override fun toString(): String {
                return "Interval{" +
                        "l=" + l +
                        ", r=" + r +
                        '}'
            }

        }

    }

    internal class InputReader(private val stream: InputStream) {
        private val buf = ByteArray(1 shl 16)
        private var curChar: Int = 0
        private var numChars: Int = 0

        fun read(): Int {
            if (this.numChars == -1) {
                throw InputMismatchException()
            } else {
                if (this.curChar >= this.numChars) {
                    this.curChar = 0

                    try {
                        this.numChars = this.stream.read(this.buf)
                    } catch (var2: IOException) {
                        throw InputMismatchException()
                    }

                    if (this.numChars <= 0) {
                        return -1
                    }
                }

                return this.buf[this.curChar++].toInt()
            }
        }

        fun nextInt(): Int {
            var c: Int
            c = this.read()
            while (isSpaceChar(c)) {
                c = this.read()
            }

            var sgn: Byte = 1
            if (c == 45) {
                sgn = -1
                c = this.read()
            }

            var res = 0

            while (c >= 48 && c <= 57) {
                res *= 10
                res += c - 48
                c = this.read()
                if (isSpaceChar(c)) {
                    return res * sgn
                }
            }

            throw InputMismatchException()
        }

        companion object {

            fun isSpaceChar(c: Int): Boolean {
                return c == 32 || c == 10 || c == 13 || c == 9 || c == -1
            }
        }

    }

    internal class OutputWriter {
        private val writer: PrintWriter

        constructor(outputStream: OutputStream) {
            writer = PrintWriter(BufferedWriter(OutputStreamWriter(outputStream)))
        }

        constructor(writer: Writer) {
            this.writer = PrintWriter(writer)
        }

        fun close() {
            writer.close()
        }

        fun println(i: Int) {
            writer.println(i)
        }

    }
}


//package codeforces.round614

fun main() {
	readLn()
	val data = readInts()
	val aCount = data.groupBy { it }.mapValues { it.value.size }
	val m = aCount.keys.max()!!
	val (primes, factPrimes) = List(2) { MutableList(2) { listOf<Int>() } }
	for (i in 2..m) {
		val j = (2..i).first { i % it == 0 }
		primes.add(primes[i / j].plus(j))
		factPrimes.add(factPrimes[i - 1].plus(primes[i]).sortedDescending())
	}
	var ans = aCount.map { factPrimes[it.key].size * 1L * it.value }.sum()
	var b = aCount.keys.toList()
	for (x in factPrimes.last().indices) {
		val count = mutableMapOf<Int, Int>().withDefault { 0 }
		for (v in b) {
			val p = factPrimes[v].getOrNull(x) ?: continue
			count[p] = count.getValue(p) + aCount.getValue(v)
		}
		val p = count.keys.firstOrNull { p -> 2 * count[p]!! > data.size } ?: break
		ans -= 2 * count[p]!! - data.size
		b = b.filter { v -> factPrimes[v].getOrNull(x) == p }
	}
	println(ans)
}

private fun readLn() = readLine()!!
private fun readStrings() = readLn().split(" ")
private fun readInts() = readStrings().map { it.toInt() }


fun c(n: Int, k: Int): Sequence<Long> = when {
	k < 0 || k > n -> sequence{}
	n == 0 -> sequenceOf(0)
	else -> sequence {
		for (t in 0..1) yieldAll(c(n - 1, k - t).map {it.shl(1) + t})
	}
}

fun main(args: Array<String>) {
	val (n, m) = readLine()!!.split(" ").map {it.toInt()}
	val a = Array(m) {
		val s = readLine()!!.split(" ")
		Pair(s[0].toLong(2), s[1].toInt())
	}
	println(c(n, n - a[0].second).map {a[0].first xor it}.filter {
		x -> a.filter {java.lang.Long.bitCount(it.first xor x) != n - it.second}.isEmpty()
	}.toList().size)
}


@file:Suppress("NOTHING_TO_INLINE", "EXPERIMENTAL_FEATURE_WARNING", "OVERRIDE_BY_INLINE")

import java.io.PrintWriter
import java.util.StringTokenizer
import kotlin.math.*
import kotlin.random.Random
import kotlin.collections.sort as _sort
import kotlin.collections.sortDescending as _sortDescending
import kotlin.io.println as iprintln

/** @author Spheniscine */
fun main() { _writer.solve(); _writer.flush() }
fun PrintWriter.solve() {
    val n = readInt()
    val T = readLn()

    val p1 = HashVal(random.nextLong(2, HASHMOD))
    val pow1 = HashValArray(n+1)
    pow1[0] = HashVal(1)
    for(i in 1 .. n) pow1[i] = pow1[i-1] * p1

    val pinv1 = p1.inverse()

    val st = SegmentTree(n, Seg.EMPTY, combine@{ a, b ->
        if(b.len == 0) return@combine a
        if(a.len == 0) return@combine b
        var first = a.first
        var last = b.last
        var alen = a.len
        var blen = b.len
        var ha1 = a.hash
        var hb1 = b.hash

        if(a.last && b.first) {
            alen--
            blen--

            ha1--
            ha1 *= pinv1
            hb1 -= pow1[blen]

            if(alen == 0) first = false
            if(blen == 0) last = false
        }

        val hash = ha1 * pow1[blen] + hb1

        Seg(first, last, alen + blen, hash)
    })

    st.build { i ->
        val t = T[i] == '1'
        Seg(t, t, 1, if(t) HashVal(1) else HashVal(0))
    }

    val q = readInt()
    repeat(q) {
        val l1 = readInt()-1
        val l2 = readInt()-1
        val len = readInt()

        val s1 = st[l1, l1+len]
        val s2 = st[l2, l2+len]

        val ans = s1.len == s2.len && s1.hash.int == s2.hash.int
        if(ans) println("Yes") else println("No")
    }
}

data class Seg(val first: Boolean, val last: Boolean, val len: Int, val hash: HashVal) {
    companion object {
        val EMPTY = Seg(false, false, 0, HashVal(0))
    }
}

class SegmentTree<T>(
    val size: Int,
    val identityValue: T,
    val combiner: (T, T) -> T) {

    /* degenericization helpers
    inline val identityValue: T get() = TODO()
    inline fun combiner(a: T, b: T): T = TODO()
    */

    @Suppress("UNCHECKED_CAST")
    private val array = Array<Any?>(size shl 1) { identityValue } as Array<T>

    inline val lastIndex get() = size - 1
    inline val indices get() = 0 until size
    val asList: List<T> by lazy {
        object : AbstractList<T>() {
            override val size: Int get() = this@SegmentTree.size
            override fun get(index: Int): T = this@SegmentTree[index]
        }
    }

    fun build(generator: (Int) -> T) {
        for(i in 0 until size) {
            array[i + size] = generator(i)
        }
        for(i in size-1 downTo 1) {
            array[i] = combiner(array[i shl 1], array[i shl 1 or 1])
        }
    }

    /** instantiates values from an iterable, O(n) time */
    fun copyFrom(iterable: Iterable<T>) {
        run {
            iterable.forEachIndexed { i, t ->
                if(i > lastIndex) return@run
                array[i + size] = t
            }
        }
        for(i in size-1 downTo 1) {
            array[i] = combiner(array[i shl 1], array[i shl 1 or 1])
        }
    }

    /** Updates a value, O(log n) time */
    operator fun set(index: Int, value: T) {
        require(index in 0 until size)
        var i = index + size
        array[i] = value
        while(true) {
            i = i shr 1
            if(i <= 0) break
            array[i] = combiner(array[i shl 1], array[i shl 1 or 1])
        }
    }

    /** Gets a value by its index, O(1) time */
    operator fun get(index: Int): T {
        require(index in 0 until size)
        return array[index + size]
    }

    /** gets the result of applying the monoid operation to the values in the index range, O(log n) time */
    operator fun get(start: Int, endExclusive: Int): T {
        var l = maxOf(start, 0) + size
        var r = minOf(endExclusive, size) + size

        // two accumulators to support non-commutative monoids
        var lAcc = identityValue
        var rAcc = identityValue

        while(l < r) {
            if(l and 1 == 1) {
                lAcc = combiner(lAcc, array[l++])
            }
            if(r and 1 == 1) {
                rAcc = combiner(array[--r], rAcc)
            }

            l = l shr 1
            r = r shr 1
        }

        return combiner(lAcc, rAcc)
    }

    operator fun get(range: IntRange) = get(range.first, range.last + 1)
}

/** Converts a semigroup to a monoid by using null as the identity value. */
inline fun <T: Any> nullIdentityCombiner(crossinline combiner: (T, T) -> T): (T?, T?) -> T? = { a, b ->
    when {
        b == null -> a
        a == null -> b
        else -> combiner(a, b)
    }
}

infix fun Long.umod(mod: Long) = (this % mod).let { (it shr Long.SIZE_BITS - 1 and mod) + it }

const val HASHMOD = 1L.shl(61) - 1

inline class HashVal(val int: Long) {
    // normalizes an integer that's within range [-MOD, MOD) without branching
    private inline fun normalize(int: Long) = HashVal((int shr Long.SIZE_BITS - 1 and HASHMOD) + int)

    operator fun plus(other: HashVal) = normalize(int + other.int - HASHMOD)
    operator fun plus(other: Int) = plus(normalize(other.toLong()))
    operator fun inc() = normalize(int + (1 - HASHMOD))

    operator fun minus(other: HashVal) = normalize(int - other.int)
    operator fun minus(other: Int) = minus(normalize(other.toLong()))
    operator fun dec() = normalize(int - 1)
    operator fun unaryMinus() = normalize(-int)

    operator fun times(other: HashVal): HashVal {
        val l1 = int and 0xffff_ffff
        val h1 = int ushr 32
        val l2 = other.int and 0xffff_ffff
        val h2 = other.int ushr 32

        val l = l1 * l2
        val m = l1 * h2 + l2 * h1
        val h = h1 * h2
        var ret = (l and HASHMOD) + (l ushr 61) + (h shl 3) + (m ushr 29) + (m shl 35 ushr 3) + 1
        ret = (ret and HASHMOD) + (ret ushr 61)
        ret = (ret and HASHMOD) + (ret ushr 61)
        return HashVal(ret - 1)
    }

    operator fun times(other: Int) = times(normalize(other.toLong()))

    fun pow(exponent: Long): HashVal {
        var e = if(exponent < 0) {
            require(int != 0L) { "Can't invert/divide by 0" }
            exponent umod HASHMOD - 1
        } else exponent

        var res = HashVal(1)
        var b = this

        while(e > 0) {
            if(e and 1 == 1L) {
                res *= b
            }
            e = e shr 1
            b *= b
        }
        return res
    }

    inline fun inverse() = inv_unmemoized()

    fun inv_unmemoized(): HashVal {
        require(int != 0L) { "Can't invert/divide by 0" }
        return pow(HASHMOD - 2)
    }

    operator fun div(other: HashVal) = times(other.inverse())
    operator fun div(other: Int) = div(normalize(other.toLong()))

    override inline fun toString() = int.toString()
}

inline class HashValArray(val intArray: LongArray): Collection<HashVal> {
    inline operator fun get(i: Int) = HashVal(intArray[i])
    inline operator fun set(i: Int, v: HashVal) { intArray[i] = v.int }

    override inline val size: Int get() = intArray.size
    inline val lastIndex get() = intArray.lastIndex
    inline val indices get() = intArray.indices

    override inline fun contains(element: HashVal): Boolean = element.int in intArray

    override fun containsAll(elements: Collection<HashVal>): Boolean = elements.all(::contains)

    override inline fun isEmpty(): Boolean = intArray.isEmpty()

    override fun iterator(): Iterator<HashVal> = object: Iterator<HashVal> {
        var index = 0
        override fun hasNext(): Boolean = index < size
        override fun next(): HashVal = get(index++)
    }

    fun copyOf(newSize: Int) = HashValArray(intArray.copyOf(newSize))
    fun copyOf() = copyOf(size)
}
fun HashValArray.copyInto(destination: HashValArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size) =
    HashValArray(intArray.copyInto(destination.intArray, destinationOffset, startIndex, endIndex))
inline fun HashValArray(size: Int) = HashValArray(LongArray(size))
inline fun HashValArray(size: Int, init: (Int) -> HashVal) = HashValArray(LongArray(size) { init(it).int })

inline fun HashValArray.first() = get(0)
inline fun HashValArray.last() = get(lastIndex)

/** IO code start */
//@JvmField val INPUT = File("input.txt").inputStream()
//@JvmField val OUTPUT = File("output.txt").outputStream()
@JvmField val INPUT = System.`in`
@JvmField val OUTPUT = System.out

@JvmField val _reader = INPUT.bufferedReader()
fun readLine(): String? = _reader.readLine()
fun readLn() = _reader.readLine()!!
@JvmField var _tokenizer: StringTokenizer = StringTokenizer("")
fun read(): String {
    while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return "", " ")
    return _tokenizer.nextToken()
}
fun readInt() = read().toInt()
fun readDouble() = read().toDouble()
fun readLong() = read().toLong()
fun readStrings(n: Int) = List(n) { read() }
fun readLines(n: Int) = List(n) { readLn() }
fun readInts(n: Int) = List(n) { read().toInt() }
fun readIntArray(n: Int) = IntArray(n) { read().toInt() }
fun readDoubles(n: Int) = List(n) { read().toDouble() }
fun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }
fun readLongs(n: Int) = List(n) { read().toLong() }
fun readLongArray(n: Int) = LongArray(n) { read().toLong() }

@JvmField val _writer = PrintWriter(OUTPUT, false)

/** shuffles and sort overrides to avoid quicksort attacks */
private inline fun <T> _shuffle(rnd: Random, get: (Int) -> T, set: (Int, T) -> Unit, size: Int) {
    // Fisher-Yates shuffle algorithm
    for (i in size - 1 downTo 1) {
        val j = rnd.nextInt(i + 1)
        val temp = get(i)
        set(i, get(j))
        set(j, temp)
    }
}

@JvmField var _random: Random? = null
val random get() = _random ?: Random(0x594E215C123 * System.nanoTime()).also { _random = it }

fun IntArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)
fun IntArray.sort() { shuffle(); _sort() }
fun IntArray.sortDescending() { shuffle(); _sortDescending() }

fun LongArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)
fun LongArray.sort() { shuffle(); _sort() }
fun LongArray.sortDescending() { shuffle(); _sortDescending() }

fun DoubleArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)
fun DoubleArray.sort() { shuffle(); _sort() }
fun DoubleArray.sortDescending() { shuffle(); _sortDescending() }

fun CharArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)
inline fun CharArray.sort() { _sort() }
inline fun CharArray.sortDescending() { _sortDescending() }

inline fun <T: Comparable<T>> Array<out T>.sort() = _sort()
inline fun <T: Comparable<T>> Array<out T>.sortDescending() = _sortDescending()
inline fun <T: Comparable<T>> MutableList<out T>.sort() = _sort()
inline fun <T: Comparable<T>> MutableList<out T>.sortDescending() = _sortDescending()

fun `please stop removing these imports IntelliJ`() {
    iprintln(max(1, 2))
}


import java.io.PrintWriter
import java.util.*
import kotlin.math.abs

var n = 0
var a = IntArray(100005)
var gg = 2

fun main() {
    val inp = Scanner(System.`in`)
    val out = PrintWriter(System.out)
    n=inp.nextInt();
    for(i in 0 until n){
        a[i]=inp.nextInt();
    }
    if(n==1){
        out.println(0);
    }else if(n==2){
        out.println(if(a[0]==0 && a[1]!=0) 1 else 0)
    }else{
        gg=2
        go(a[1].toDouble(), if (a[1]==0) 0.0 else (1.0 * a[2]) / a[1])
        go(a[0].toDouble(), if (a[0]==0) 0.0 else (1.0 * a[2]) / a[0])
        go(a[0].toDouble(), if (a[0]==0) 0.0 else (1.0 * a[1]) / a[0])
        out.println(gg);
    }
    out.close()
}

fun go(x: Double, y: Double) {
    var x:Double = x
    var i = 0
    var cnt = 0
    //println("$x $y")
    while (i < n) {
        //println(abs(x-a[i]));
        if (abs(x - a[i]) > 1e-8) cnt++ else x *= y
        ++i
    }
    //println(gg)
    gg = Math.min(gg, cnt)
    //println(cnt)
}


import java.util.*
import kotlin.collections.*

fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(' ').map {it.toInt()}
    val a = readLine()!!.split(' ').map {it.toInt()}
    var l = 0
    val cnt = TreeMap<Int, Int>()
    var maxLen = 0
    val index = ArrayList<Int>()
    for (r in 0 until n) {
        cnt[a[r]] = cnt.getOrDefault(a[r], 0) + 1
        while (cnt.lastKey() - cnt.firstKey() > k) {
            val x = cnt[a[l]]!! - 1
            if (x == 0)
                cnt.remove(a[l])
            else
                cnt[a[l]] = x
            l++
        }
        if (r - l + 1 > maxLen) {
            maxLen = r - l + 1
            index.clear()
        }
        if (r - l + 1 == maxLen) {
            index.add(l)
        }
    }
    println("$maxLen ${index.size}")
    for (i in index)
        println("${i+1} ${i+maxLen}")
}


import java.io.*
import kotlin.concurrent.thread
import java.io.IOException
import java.io.BufferedReader
import java.io.InputStream
import kotlin.*
import java.*
import java.io.OutputStream
import java.io.PrintWriter
import java.lang.ArithmeticException
import java.lang.Exception
import java.math.BigInteger
import java.security.cert.TrustAnchor
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashSet
import kotlin.system.exitProcess

fun main() {
    val inputStream = System.`in`
    val outputStream = System.out
    val `in` = InputReader(inputStream)
    val out = PrintWriter(outputStream)

    val n=`in`.nextInt()
    val s=`in`.next()
    if (n%2==1||(s.map{if (it=='(') +1 else -1}.sum()!=0))
        out.println("0\n1 1")
    else
    {
        val a = IntArray(n)
        a[0]= if (s[0]=='(') +1 else -1
        for (i in 1..n-1){
            if (s[i]=='(')
                a[i]=a[i-1]+1
            else
                a[i]=a[i-1]-1
        }
        val mn=a.min()!!
        var pos=-1
        for (i in 0..n-1)
            if (a[i]==mn)
            {
                pos=i
                break
            }
        val kol=a.filter{it==mn}.size
        if (kol*2==n){
            out.println(kol)
            out.println("1 1")
        } else {
            var now = 0
            var mx = 0
            var prv = -1
            var pos1 = -1
            var pos2 = -2
            for (I in pos..pos + n + 1) {
                val i = I % n
                if (a[i] == mn || a[i] == mn+1) {
                    if (now > mx) {
                        mx = now
                        pos1 = (prv) % n
                        pos2 = (I + n) % n
                    }
                    prv = i + 1
                    now = 0
                } else if (a[i] == mn + 2) {
                    ++now
                }
            }
            val mx1=mx+kol
            val a1=pos1+1
            val b1=pos2+1

            mx=0
            prv=-1
            now=0
            pos1=-1
            pos2=-1
            for (I in pos..pos + n + 1) {
                val i = I % n
                if (a[i] == mn) {
                    if (now > mx) {
                        mx = now
                        pos1 = (prv) % n
                        pos2 = (I + n) % n
                    }
                    prv = i + 1
                    now = 0
                } else if (a[i] == mn + 1) {
                    ++now
                }
            }

            if (mx>mx1) {
                out.println(mx)
                out.println((pos1 + 1).toString() + ' ' + (pos2 + 1))
            } else {
                out.println(mx1)
                out.println(a1.toString() + ' ' + b1)
            }

            /*out.println(mx)
            out.println((pos1 + 1).toString() + ' ' + (pos2 + 1))

            out.println(mx1)
            out.println(a1.toString() + ' ' + b1)*/
        }

    }

    out.close()

}

internal class InputReader(stream: InputStream) {
    var reader: BufferedReader
    var tokenizer: StringTokenizer? = null

    init {
        reader = BufferedReader(InputStreamReader(stream), 32768)
        tokenizer = null
    }

    operator fun next(): String {
        while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
            try {
                tokenizer = StringTokenizer(reader.readLine())
            } catch (e: IOException) {
                throw RuntimeException(e)
            }

        }
        return tokenizer!!.nextToken()
    }

    fun nextInt(): Int {
        return Integer.parseInt(next())
    }

    fun nextLong(): Long {
        return next().toLong()
    }

}

//)(()(()())()
//)(())()()(()


import java.util.*
import java.util.Arrays.binarySearch

private const val MODULO = 1000000007

fun Long.to(): Int = (this shr 32).toInt()
fun Long.from(): Int = (this and 0xFFFF_FFFFL).toInt()

fun bus(from: Int, to: Int): Long =
        (to.toLong() shl 32) + from

class TaskD(numSegments: Int, val buses: LongArray) {
    val lastStopI: Int
    var countSum: IntArray
    var countSumSize = 0

    init {
        var allStops = IntArray(buses.size * 2 + 2)
        for (i in 0 until buses.size) {
            allStops[i * 2] = buses[i].from()
            allStops[i * 2 + 1] = buses[i].to()
        }
        allStops[allStops.size - 2] = 0
        allStops[allStops.size - 1] = numSegments
        allStops.sort()
        var i = 0
        var j = 1
        while (j < allStops.size) {
            if (allStops[i] != allStops[j]) {
                allStops[++i] = allStops[j++]
            } else {
                j++
            }
        }
        allStops = allStops.copyOf(i + 1)
        lastStopI = allStops.size - 1

        for (i in buses.indices) {
            val bus = buses[i]
            val from = binarySearch(allStops, bus.from())
            val to = binarySearch(allStops, bus.to())
            buses[i] = bus(from, to)
        }

        buses.sort()

        countSum = IntArray(allStops.size + 1)
        countSum[0] = 0
        countSum[1] = 1
        countSumSize = 2
    }

    fun result() =
            if (lastStopI + 1 >= countSumSize) 0
            else mod(countSum[lastStopI + 1] - countSum[lastStopI], MODULO)

    fun run() {
        for (b in buses) {
            val currTo = b.to()
            countSumEnsureSize(currTo + 2)
            val countDelta = mod(countSum[currTo] - countSum[b.from()], MODULO)
            addCount(currTo, countDelta)
        }
    }

    fun addCount(i: Int, d: Int) {
        for (j in (i + 1)..(countSumSize - 1))
            countSum[j] = mod(countSum[j] + d, MODULO)
    }

    fun countSumEnsureSize(size: Int) {
        if (countSumSize >= size) return
        for (i in (countSumSize - 1 + 1)..(size - 1))
            countSum[i] = countSum[i - 1]
        countSumSize = size
    }

    fun print() {
        println(result())
    }
}

fun mod(n: Int, m: Int): Int = (n % m + m) % m

fun cfd() = with(Scanner(System.`in`)) {
    val numSegments = nextInt();
    val numbuses = nextInt()
    val buses = LongArray(numbuses) {
        val from = nextInt()
        val to = nextInt()
        bus(from, to)
    }

    with(TaskD(numSegments, buses)) {
        run()
        print()
    }
}

fun main(args: Array<String>) {
    if (args.size == 0) cfd()
}


import java.io.*

fun main(args: Array<String>) {
    val sc = BufferedReader(InputStreamReader(System.`in`))
    val out = PrintWriter(BufferedOutputStream(System.out))
    val (n, m) = sc.readLine()!!.split(" ").map(String::toInt)
    val maxm = 1 shl n
    val graph = Array(n) { Array(n) { false } }
    val dp = Array(maxm) { Array(n) { 0L } }

    fun first(num: Int): Int {
        var i = 0
        while ((num and (1 shl i++)) == 0){}
        return i-1
    }

    for (i in 0 until m) {
        val (from, to) = sc.readLine()!!.split(" ").map { it.toInt() - 1 }
        graph[from][to] = true
        graph[to][from] = true
    }

    for(mask in 1 until maxm) {
        for(i in 0 until n) {
            val eI = (mask and (1 shl i)) > 0
            val bk = Integer.bitCount(mask)
            if(bk == 1 && eI) {
                dp[mask][i] = 1
            } else if(bk > 1 && eI && first(mask) != i) {
                var sum = 0L
                for(j in 0 until n) {
                    if(graph[i][j]) sum += dp[mask xor (1 shl i)][j]
                }
                dp[mask][i] = sum
            }
        }
    }

    var count = 0L
    for (mask in 7 until maxm) {
        for(i in 0 until n) {
            if (Integer.bitCount(mask) >= 3 && graph[first(mask)][i]) {
                count += dp[mask][i]
            }
        }
    }

    out.println(count / 2)
    out.close()
}


import java.util.Scanner;
object programkt {
  @JvmStatic fun main(args:Array<String>) {
    val `in` = Scanner(System.`in`)
    val n = `in`.nextInt()
    var k = `in`.nextInt()
    k -= 1
    val c = `in`.next().toCharArray()
    val freeb = IntArray(n)
    for (i in 0..n - 1)
    {
      if (c[i] == '0')
      freeb[i] = i
      else
      freeb[i] = freeb[i - 1]
    }
    var lo = 0
    var hi = n - 2
    while (lo < hi)
    {
      val mid = (lo + hi) / 2
      var last = 0
      for (j in 0..k - 1)
      {
        last = freeb[Math.min(n - 1, last + mid + 1)]
      }
      if (last == n - 1)
      hi = mid
      else
      lo = mid + 1
    }
    println(lo)
  }
}


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

fun <T : Comparable<T>> max(a: T, b: T): T = if (b > a) b else a
fun <T : Comparable<T>> min(a: T, b: T): T = if (b < a) b else a
fun Number.isEven(): Boolean = if (this.toInt() and 1 == 0) true else false
fun Number.isOdd (): Boolean = !this.isEven()

fun isprime(n: Int): Boolean {
    if (n == 2 || n == 3)
        return true
    if (n % 2 == 0 || n % 3 == 0 || n == 1)
        return false
    var i = 5
    var w = 2
    while (i * i <= n) {
        if (n % i == 0)
            return false
        i += w
        w = 6 - w
    }
    return true
}

fun ispalin(n: Int): Boolean {
    val str = n.toString()
    for (i in 0..str.length/2 - 1) {
        if (str[i] != str[str.length - i - 1]) return false
    }
    return true
}

fun main(args: Array<String>) {
    if (args.isNotEmpty()) System.setIn(FileInputStream(args[0]))
    val br = BufferedReader(InputStreamReader(System.`in`))
    val bw = BufferedWriter(OutputStreamWriter(System.out))

    var st = StringTokenizer(br.readLine())
    val p = st.nextToken().toInt()
    val q = st.nextToken().toInt()
    var answer = 1
    var numprimes = 0
    var numpalins = 1
    for (i in 2..1200000) {
        if (isprime(i)) ++numprimes
        if (ispalin(i)) ++numpalins
        if (q * numprimes <= p * numpalins) answer = i
    }
    bw.write("${answer}\n")
    bw.close()
}