A chess tournament will be held soon, where $$$n$$$ chess players will take part. Every participant will play one game against every other participant. Each game ends in either a win for one player and a loss for another player, or a draw for both players.Each of the players has their own expectations about the tournament, they can be one of two types:  a player wants not to lose any game (i. e. finish the tournament with zero losses);  a player wants to win at least one game. You have to determine if there exists an outcome for all the matches such that all the players meet their expectations. If there are several possible outcomes, print any of them. If there are none, report that it's impossible.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 200$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$2 \le n \le 50$$$) — the number of chess players. The second line contains the string $$$s$$$ ($$$|s| = n$$$; $$$s_i \in \{1, 2\}$$$). If $$$s_i = 1$$$, then the $$$i$$$-th player has expectations of the first type, otherwise of the second type.

For each test case, print the answer in the following format: In the first line, print NO if it is impossible to meet the expectations of all players. Otherwise, print YES, and the matrix of size $$$n \times n$$$ in the next $$$n$$$ lines. The matrix element in the $$$i$$$-th row and $$$j$$$-th column should be equal to:   +, if the $$$i$$$-th player won in a game against the $$$j$$$-th player;  -, if the $$$i$$$-th player lost in a game against the $$$j$$$-th player;  =, if the $$$i$$$-th and $$$j$$$-th players' game resulted in a draw;  X, if $$$i = j$$$.

<?php
class IO {
    public static $aAlphabet = ['A','B','C','D', 'E', 'F', 'G', 'H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
    //Input/Output
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function asLine($mArr, $sep = ' ') { echo implode($sep, $mArr) . PHP_EOL; }

    //Z-function
    public static function z($sString) {
        $s = str_split($sString);
        $n = count($s);
        $z = array_fill(0, $n, 0);
        $r = $l = 0;
        for ($i = 1; $i < $n; $i++) {
            if ($r >= $i) {
                $z[$i] = min($z[$i - $l], $r - $i + 1);
            }
            while ($z[$i] + $i < $n && $s[$z[$i]] == $s[$z[$i] + $i]) {
                $z[$i]++;
            }
            if ($i + $z[$i] - 1 > $r) {
                $l = $i;
                $r = $i + $z[$i] - 1;
            }
        }
        return $z;
    }
    public static function getCountOfDiffSubstrWithZ($sString)
    {
        $s = str_split($sString);
        $n = count($s);
        $count = 0;
        $t = '';
        for ($i = $n - 1; $i >= 0; $i--) {
            $t = $s[$i] . $t;
            $count += $i + 1 - max(self::z($t));
        }
        return $count;
    }
    public static function getMinPeriodOfSubstrWithZ($sString)
    {
        $s = str_split($sString);
        $res = count($s);
        $z = self::z($sString);
        foreach ($z as $iI => $sV) {
            if ((int) $iI + $z[$iI] == $res && $res % (int) $iI == 0) {
                $res = $iI;
                break;
            }
        }
        return $res;
    }

    //Other functions
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }

}

//$iQueryCount = 1;
$iQueryCount = IO::str();
$aAllResults = [];
while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $n = IO::str();
    $s = IO::str();
    $a = str_split($s);
    $r = [1 => 0, 2 => 0];
    $res = [-1, -1];
    $first = -1;
    $last = -1;
    foreach ($a as $k => $v) {
        $r[$v] += 1;
        if ($v == 2) {
            if ($first == -1) {
                $first = $k;
            }
            $last = $k;
        }
    }
    if ($r[2] == 1 || $r[2] == 2) {
        IO::no();
    } else {
        $lastWinner = -1;
        IO::yes();
        foreach ($a as $k => $v) {
            $str = '';
            $won = false;
            foreach ($a as $kk => $vv) {
                if ($k == $kk) {
                    $str .= 'X';
                } elseif ($v == 1) {
                    $str .= '=';
                } else {
                    if ($vv == 2) {
                        if ($k == $first) {
                            if ($kk != $last) {
                                $str .= '+';
                                $lastWinner = $k;
                            } else {
                                $str .= '-';
                            }
                        } elseif ($k == $last && $kk == $first) {
                            $str .= '+';
                        } elseif ($lastWinner < $kk) {
                            $str .= '+';
                            $lastWinner = $k;
                        } else {
                            $str .= '-';
                        }
                    } else {
                        $str .= '=';
                    }
                }
            }
            IO::line($str);
        }
    }

}

?>

<?php
class IO {
    public static $aAlphabet = ['A','B','C','D', 'E', 'F', 'G', 'H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
    //Input/Output
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function asLine($mArr, $sep = ' ') { echo implode($sep, $mArr) . PHP_EOL; }

    //Z-function
    public static function z($sString) {
        $s = str_split($sString);
        $n = count($s);
        $z = array_fill(0, $n, 0);
        $r = $l = 0;
        for ($i = 1; $i < $n; $i++) {
            if ($r >= $i) {
                $z[$i] = min($z[$i - $l], $r - $i + 1);
            }
            while ($z[$i] + $i < $n && $s[$z[$i]] == $s[$z[$i] + $i]) {
                $z[$i]++;
            }
            if ($i + $z[$i] - 1 > $r) {
                $l = $i;
                $r = $i + $z[$i] - 1;
            }
        }
        return $z;
    }
    public static function getCountOfDiffSubstrWithZ($sString)
    {
        $s = str_split($sString);
        $n = count($s);
        $count = 0;
        $t = '';
        for ($i = $n - 1; $i >= 0; $i--) {
            $t = $s[$i] . $t;
            $count += $i + 1 - max(self::z($t));
        }
        return $count;
    }
    public static function getMinPeriodOfSubstrWithZ($sString)
    {
        $s = str_split($sString);
        $res = count($s);
        $z = self::z($sString);
        foreach ($z as $iI => $sV) {
            if ((int) $iI + $z[$iI] == $res && $res % (int) $iI == 0) {
                $res = $iI;
                break;
            }
        }
        return $res;
    }

    //Other functions
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }

}

//$iQueryCount = 1;
$iQueryCount = IO::str();
$aAllResults = [];
while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $n = IO::str();
    $s = IO::str();
    $a = str_split($s);
    $r = [1 => 0, 2 => 0];
    $res = [-1, -1];
    $first = -1;
    $last = -1;
    foreach ($a as $k => $v) {
        $r[$v] += 1;
        if ($v == 2) {
            if ($first == -1) {
                $first = $k;
            }
            $last = $k;
        }
    }
    if ($r[2] == 1 || $r[2] == 2) {
        IO::no();
    } else {
        $lastWinner = -1;
        IO::yes();
        foreach ($a as $k => $v) {
            $str = '';
            $won = false;
            foreach ($a as $kk => $vv) {
                if ($k == $kk) {
                    $str .= 'X';
                } elseif ($v == 1) {
                    $str .= '=';
                } else {
                    if ($vv == 2) {
                        if ($k == $first) {
                            if ($kk != $last) {
                                $str .= '+';
                                $lastWinner = $k;
                            } else {
                                $str .= '-';
                            }
                        } elseif ($lastWinner == $last && $kk == $first) {
                            $str .= '+';
                        } elseif ($lastWinner < $kk) {
                            $str .= '+';
                            $lastWinner = $k;
                        } else {
                            $str .= '-';
                        }
                    } else {
                        $str .= '=';
                    }
                }
            }
            IO::line($str);
        }
    }

}

?>

<?php
class IO {
    public static $aAlphabet = ['A','B','C','D', 'E', 'F', 'G', 'H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
    //Input/Output
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function asLine($mArr, $sep = ' ') { echo implode($sep, $mArr) . PHP_EOL; }

    //Z-function
    public static function z($sString) {
        $s = str_split($sString);
        $n = count($s);
        $z = array_fill(0, $n, 0);
        $r = $l = 0;
        for ($i = 1; $i < $n; $i++) {
            if ($r >= $i) {
                $z[$i] = min($z[$i - $l], $r - $i + 1);
            }
            while ($z[$i] + $i < $n && $s[$z[$i]] == $s[$z[$i] + $i]) {
                $z[$i]++;
            }
            if ($i + $z[$i] - 1 > $r) {
                $l = $i;
                $r = $i + $z[$i] - 1;
            }
        }
        return $z;
    }
    public static function getCountOfDiffSubstrWithZ($sString)
    {
        $s = str_split($sString);
        $n = count($s);
        $count = 0;
        $t = '';
        for ($i = $n - 1; $i >= 0; $i--) {
            $t = $s[$i] . $t;
            $count += $i + 1 - max(self::z($t));
        }
        return $count;
    }
    public static function getMinPeriodOfSubstrWithZ($sString)
    {
        $s = str_split($sString);
        $res = count($s);
        $z = self::z($sString);
        foreach ($z as $iI => $sV) {
            if ((int) $iI + $z[$iI] == $res && $res % (int) $iI == 0) {
                $res = $iI;
                break;
            }
        }
        return $res;
    }

    //Other functions
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }

}

//$iQueryCount = 1;
$iQueryCount = IO::str();
$aAllResults = [];
while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $n = IO::str();
    $s = IO::str();
    $a = str_split($s);
    $r = [1 => 0, 2 => 0];
    $res = [-1, -1];
    $first = -1;
    $last = -1;
    foreach ($a as $k => $v) {
        $r[$v] += 1;
        if ($v == 2) {
            if ($first == -1) {
                $first = $k;
            }
            $last = $k;
        }
    }
    if ($r[2] == 1 || $r[2] == 2) {
        IO::no();
    } else {
        $lastWinner = -1;
        IO::yes();
        foreach ($a as $k => $v) {
            $str = '';
            $won = false;
            foreach ($a as $kk => $vv) {
                if ($k == $kk) {
                    $str .= 'X';
                } elseif ($v == 1) {
                    $str .= '=';
                } else {
                    if ($vv == 2) {
                        if ($k == $first) {
                            if ($kk != $last) {
                                $str .= '+';
                                $lastWinner = $k;
                            } else {
                                $str .= '-';
                            }
                        } elseif ($lastWinner == $last && $kk == $first) {
                            $str .= '+';
                            $won = true;
                        } elseif ($lastWinner < $kk && !$won) {
                            $str .= '+';
                            $lastWinner = $kk;
                            $won = true;
                        } else {
                            $str .= '-';
                        }
                    } else {
                        $str .= '=';
                    }
                }
            }
            IO::line($str);
        }
    }

}

?>

<?php
class IO {
    public static $aAlphabet = ['A','B','C','D', 'E', 'F', 'G', 'H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
    //Input/Output
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function asLine($mArr, $sep = ' ') { echo implode($sep, $mArr) . PHP_EOL; }

    //Z-function
    public static function z($sString) {
        $s = str_split($sString);
        $n = count($s);
        $z = array_fill(0, $n, 0);
        $r = $l = 0;
        for ($i = 1; $i < $n; $i++) {
            if ($r >= $i) {
                $z[$i] = min($z[$i - $l], $r - $i + 1);
            }
            while ($z[$i] + $i < $n && $s[$z[$i]] == $s[$z[$i] + $i]) {
                $z[$i]++;
            }
            if ($i + $z[$i] - 1 > $r) {
                $l = $i;
                $r = $i + $z[$i] - 1;
            }
        }
        return $z;
    }
    public static function getCountOfDiffSubstrWithZ($sString)
    {
        $s = str_split($sString);
        $n = count($s);
        $count = 0;
        $t = '';
        for ($i = $n - 1; $i >= 0; $i--) {
            $t = $s[$i] . $t;
            $count += $i + 1 - max(self::z($t));
        }
        return $count;
    }
    public static function getMinPeriodOfSubstrWithZ($sString)
    {
        $s = str_split($sString);
        $res = count($s);
        $z = self::z($sString);
        foreach ($z as $iI => $sV) {
            if ((int) $iI + $z[$iI] == $res && $res % (int) $iI == 0) {
                $res = $iI;
                break;
            }
        }
        return $res;
    }

    //Other functions
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }

}

//$iQueryCount = 1;
$iQueryCount = IO::str();
$aAllResults = [];
while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $n = IO::str();
    $s = IO::str();
    $a = str_split($s);
    $r = [1 => 0, 2 => 0];
    $res = [-1, -1];
    $first = -1;
    $last = -1;
    foreach ($a as $k => $v) {
        $r[$v] += 1;
        if ($v == 2) {
            if ($first == -1) {
                $first = $k;
            }
            $last = $k;
        }
    }
    if ($r[2] == 1 || $r[2] == 2) {
        IO::no();
    } else {
        $lastWinner = -1;
        IO::yes();
        foreach ($a as $k => $v) {
            $str = '';
            $won = false;
            foreach ($a as $kk => $vv) {
                if ($k == $kk) {
                    $str .= 'X';
                } elseif ($v == 1) {
                    $str .= '=';
                } else {
                    if ($vv == 2) {
                        if ($k == $first) {
                            if ($kk != $last) {
                                $str .= '+';
                            } else {
                                $str .= '-';
                            }
                        } elseif ($lastWinner == $last && $kk == $first) {
                            $str .= '+';
                            $won = true;
                        } elseif ($lastWinner < $kk && !$won) {
                            $str .= '+';
                            $lastWinner = $kk;
                            $won = true;
                        } else {
                            $str .= '-';
                        }
                    } else {
                        $str .= '=';
                    }
                }
            }
            IO::line($str);
        }
    }

}

?>

<?php
class IO {
    public static $aAlphabet = ['A','B','C','D', 'E', 'F', 'G', 'H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
    //Input/Output
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function asLine($mArr, $sep = ' ') { echo implode($sep, $mArr) . PHP_EOL; }

    //Z-function
    public static function z($sString) {
        $s = str_split($sString);
        $n = count($s);
        $z = array_fill(0, $n, 0);
        $r = $l = 0;
        for ($i = 1; $i < $n; $i++) {
            if ($r >= $i) {
                $z[$i] = min($z[$i - $l], $r - $i + 1);
            }
            while ($z[$i] + $i < $n && $s[$z[$i]] == $s[$z[$i] + $i]) {
                $z[$i]++;
            }
            if ($i + $z[$i] - 1 > $r) {
                $l = $i;
                $r = $i + $z[$i] - 1;
            }
        }
        return $z;
    }
    public static function getCountOfDiffSubstrWithZ($sString)
    {
        $s = str_split($sString);
        $n = count($s);
        $count = 0;
        $t = '';
        for ($i = $n - 1; $i >= 0; $i--) {
            $t = $s[$i] . $t;
            $count += $i + 1 - max(self::z($t));
        }
        return $count;
    }
    public static function getMinPeriodOfSubstrWithZ($sString)
    {
        $s = str_split($sString);
        $res = count($s);
        $z = self::z($sString);
        foreach ($z as $iI => $sV) {
            if ((int) $iI + $z[$iI] == $res && $res % (int) $iI == 0) {
                $res = $iI;
                break;
            }
        }
        return $res;
    }

    //Other functions
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }

}

//$iQueryCount = 1;
$iQueryCount = IO::str();
$aAllResults = [];
while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $n = IO::str();
    $s = IO::str();
    $a = str_split($s);
    $r = [1 => 0, 2 => 0];
    $res = [-1, -1];
    $first = -1;
    $last = -1;
    foreach ($a as $k => $v) {
        $r[$v] += 1;
        if ($v == 2) {
            if ($first == -1) {
                $first = $k;
            }
            $last = $k;
        }
    }
    if ($r[2] == 1 || $r[2] == 2) {
        IO::no();
    } else {
        $lastWinner = -1;
        IO::yes();
        foreach ($a as $k => $v) {
            $str = '';
            $won = false;
            foreach ($a as $kk => $vv) {
                if ($k == $kk) {
                    $str .= 'X';
                } elseif ($v == 1) {
                    $str .= '=';
                } else {
                    if ($vv == 2) {
                        if ($lastWinner == $last && $kk == $first) {
                            $str .= '+';
                            $won = true;
                        } elseif ($lastWinner < $kk && !$won) {
                            $str .= '+';
                            $lastWinner = $kk;
                            $won = true;
                        } else {
                            $str .= '-';
                        }
                    } else {
                        $str .= '=';
                    }
                }
            }
            IO::line($str);
        }
    }

}

?>

<?php
class IO {
    public static $aAlphabet = ['A','B','C','D', 'E', 'F', 'G', 'H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
    //Input/Output
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function asLine($mArr, $sep = ' ') { echo implode($sep, $mArr) . PHP_EOL; }

    //Z-function
    public static function z($sString) {
        $s = str_split($sString);
        $n = count($s);
        $z = array_fill(0, $n, 0);
        $r = $l = 0;
        for ($i = 1; $i < $n; $i++) {
            if ($r >= $i) {
                $z[$i] = min($z[$i - $l], $r - $i + 1);
            }
            while ($z[$i] + $i < $n && $s[$z[$i]] == $s[$z[$i] + $i]) {
                $z[$i]++;
            }
            if ($i + $z[$i] - 1 > $r) {
                $l = $i;
                $r = $i + $z[$i] - 1;
            }
        }
        return $z;
    }
    public static function getCountOfDiffSubstrWithZ($sString)
    {
        $s = str_split($sString);
        $n = count($s);
        $count = 0;
        $t = '';
        for ($i = $n - 1; $i >= 0; $i--) {
            $t = $s[$i] . $t;
            $count += $i + 1 - max(self::z($t));
        }
        return $count;
    }
    public static function getMinPeriodOfSubstrWithZ($sString)
    {
        $s = str_split($sString);
        $res = count($s);
        $z = self::z($sString);
        foreach ($z as $iI => $sV) {
            if ((int) $iI + $z[$iI] == $res && $res % (int) $iI == 0) {
                $res = $iI;
                break;
            }
        }
        return $res;
    }

    //Other functions
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }

}

//$iQueryCount = 1;
$iQueryCount = IO::str();
$aAllResults = [];
while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $n = IO::str();
    $s = IO::str();
    $a = str_split($s);
    $r = [1 => 0, 2 => 0];
    $res = [-1, -1];
    $first = -1;
    $last = -1;
    foreach ($a as $k => $v) {
        $r[$v] += 1;
        if ($v == 2) {
            if ($first == -1) {
                $first = $k;
            }
            $last = $k;
        }
    }
    if ($r[2] == 1 || $r[2] == 2) {
        IO::no();
    } else {
        $lastWinner = -1;
        foreach ($a as $k => $v) {
            $str = '';
            $won = false;
            foreach ($a as $kk => $vv) {
                if ($k == $kk) {
                    $str .= 'X';
                } elseif ($v == 1) {
                    $str .= '=';
                } else {
                    if ($vv == 2) {
                        if ($lastWinner == $last && $kk == $first) {
                            $str .= '+';
                            $won = true;
                        } elseif ($lastWinner < $kk && !$won) {
                            $str .= '+';
                            $lastWinner = $kk;
                            $won = true;
                        } else {
                            $str .= '-';
                        }
                    } else {
                        $str .= '=';
                    }
                }
            }
            IO::yes();
            IO::line($str);
        }
    }

}

?>


You are given a decimal representation of an integer $$$x$$$ without leading zeros.You have to perform the following reduction on it exactly once: take two neighboring digits in $$$x$$$ and replace them with their sum without leading zeros (if the sum is $$$0$$$, it's represented as a single $$$0$$$).For example, if $$$x = 10057$$$, the possible reductions are:   choose the first and the second digits $$$1$$$ and $$$0$$$, replace them with $$$1+0=1$$$; the result is $$$1057$$$;  choose the second and the third digits $$$0$$$ and $$$0$$$, replace them with $$$0+0=0$$$; the result is also $$$1057$$$;  choose the third and the fourth digits $$$0$$$ and $$$5$$$, replace them with $$$0+5=5$$$; the result is still $$$1057$$$;  choose the fourth and the fifth digits $$$5$$$ and $$$7$$$, replace them with $$$5+7=12$$$; the result is $$$10012$$$. What's the largest number that can be obtained?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of testcases. Each testcase consists of a single integer $$$x$$$ ($$$10 \le x < 10^{200000}$$$). $$$x$$$ doesn't contain leading zeros. The total length of the decimal representations of $$$x$$$ over all testcases doesn't exceed $$$2 \cdot 10^5$$$.

For each testcase, print a single integer — the largest number that can be obtained after the reduction is applied exactly once. The number should not contain leading zeros.

NoteThe first testcase of the example is already explained in the statement.In the second testcase, there is only one possible reduction: the first and the second digits.


The King of Berland Polycarp LXXXIV has $$$n$$$ daughters. To establish his power to the neighbouring kingdoms he wants to marry his daughters to the princes of these kingdoms. As a lucky coincidence there are $$$n$$$ other kingdoms as well.So Polycarp LXXXIV has enumerated his daughters from $$$1$$$ to $$$n$$$ and the kingdoms from $$$1$$$ to $$$n$$$. For each daughter he has compiled a list of kingdoms princes of which she wanted to marry.Polycarp LXXXIV is very busy, so he finds a couple for his daughters greedily one after another.For the first daughter he takes the kingdom with the lowest number from her list and marries the daughter to their prince. For the second daughter he takes the kingdom with the lowest number from her list, prince of which hasn't been taken already. If there are no free princes in the list then the daughter marries nobody and Polycarp LXXXIV proceeds to the next daughter. The process ends after the $$$n$$$-th daughter.For example, let there be $$$4$$$ daughters and kingdoms, the lists daughters have are $$$[2, 3]$$$, $$$[1, 2]$$$, $$$[3, 4]$$$, $$$[3]$$$, respectively.  In that case daughter $$$1$$$ marries the prince of kingdom $$$2$$$, daughter $$$2$$$ marries the prince of kingdom $$$1$$$, daughter $$$3$$$ marries the prince of kingdom $$$3$$$, leaving daughter $$$4$$$ nobody to marry to.Actually, before starting the marriage process Polycarp LXXXIV has the time to convince one of his daughters that some prince is also worth marrying to. Effectively, that means that he can add exactly one kingdom to exactly one of his daughter's list. Note that this kingdom should not be present in the daughter's list.Polycarp LXXXIV wants to increase the number of married couples.Unfortunately, what he doesn't have the time for is determining what entry to add. If there is no way to increase the total number of married couples then output that the marriages are already optimal. Otherwise, find such an entry that the total number of married couples increases if Polycarp LXXXIV adds it.If there are multiple ways to add an entry so that the total number of married couples increases then print any of them.For your and our convenience you are asked to answer $$$t$$$ independent test cases.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of daughters and the number of kingdoms. Each of the next $$$n$$$ lines contains the description of each daughter's list. The first integer $$$k$$$ ($$$0 \le k \le n$$$) is the number of entries in the $$$i$$$-th daughter's list. After that $$$k$$$ distinct integers follow $$$g_i[1], g_i[2], \dots, g_i[k]$$$ ($$$1 \le g_i[j] \le n$$$) — the indices of the kingdoms in the list in the increasing order ($$$g_i[1] < g_i[2] < \dots < g_i[k]$$$). It's guaranteed that the total number of daughters over all test cases does not exceed $$$10^5$$$. It's also guaranteed that the total number of kingdoms in lists over all test cases does not exceed $$$10^5$$$.

For each test case print the answer to it. Print "IMPROVE" in the first line if Polycarp LXXXIV can add some kingdom to some of his daughter's list so that the total number of married couples increases. The second line then should contain two integers — the index of the daughter and the index of the kingdom Polycarp LXXXIV should add to that daughter's list. If there are multiple ways to add an entry so that the total number of married couples increases then print any of them. Otherwise the only line should contain one word "OPTIMAL".

IMPROVE
4 4
IMPROVE
1 1
OPTIMAL
OPTIMAL
OPTIMAL

NoteThe first test case is depicted in the statement. Adding the fourth kingdom to the list of the fourth daughter makes her marry the prince of the fourth kingdom.In the second test case any new entry will increase the number of marriages from $$$0$$$ to $$$1$$$.In the third and the fourth test cases there is no way to add an entry.In the fifth test case there is no way to change the marriages by adding any entry.

<?php
	$t = trim(fgets(STDIN));
	$ans = '';
	for ($o = 0; $o < $t; $o++) {
		$n = trim(fgets(STDIN));
		$prs = [];
		$pr = array_fill(1, $n, 0);
		$u_p = [];
		for ($i = 0; $i < $n; $i++) {
			$data = explode(" ", trim(fgets(STDIN)));
			if ($data[0] > 0) {
				$fnd = false;
				for ($j = 1; $j <= $data[0]; $j++) {
					if ($pr[$data[$j]] == 0) {
						$pr[$data[$j]] = 1;
						$prs[$i + 1] = true;
						$fnd = true;
						break;
					}
				}
				if (!$fnd)
					$u_p[] = $i + 1;
			} else {
				$u_p[] = $i + 1;
			}
		}
		$opt = true;
		$res = '';
		if (count($u_p) > 0) {
			for ($i = 1; $i <= $n; $i++) {
				if ($pr[$i] == 0) {
					$opt = false;
					$res = $u_p[count($u_p) - 1]." ".$i;
					break;
				}
			}
			if (!$opt) {
				$ans .= "IMPROVE\n$res\n";
			} else {
				$ans .= "OPTIMAL\n";
			}
		} else {
			$ans .= "OPTIMAL\n";
		}
	}
	print $ans;
?>


"The zombies are lurking outside. Waiting. Moaning. And when they come...""When they come?""I hope the Wall is high enough."Zombie attacks have hit the Wall, our line of defense in the North. Its protection is failing, and cracks are showing. In places, gaps have appeared, splitting the wall into multiple segments. We call on you for help. Go forth and explore the wall! Report how many disconnected segments there are.The wall is a two-dimensional structure made of bricks. Each brick is one unit wide and one unit high. Bricks are stacked on top of each other to form columns that are up to R bricks high. Each brick is placed either on the ground or directly on top of another brick. Consecutive non-empty columns form a wall segment. The entire wall, all the segments and empty columns in-between, is C columns wide.

The first line of the input consists of two space-separated integers R and C, 1 ≤ R, C ≤ 100. The next R lines provide a description of the columns as follows:    each of the R lines contains a string of length C,  the c-th character of line r is B if there is a brick in column c and row R - r + 1, and . otherwise.  B

The number of wall segments in the input configuration.

NoteIn the first sample case, the 2nd and 3rd columns define the first wall segment, and the 5th column defines the second.


You've got table a, consisting of n rows, numbered from 1 to n. The i-th line of table a contains ci cells, at that for all i (1 < i ≤ n) holds ci ≤ ci - 1. Let's denote s as the total number of cells of table a, that is, . We know that each cell of the table contains a single integer from 1 to s, at that all written integers are distinct. Let's assume that the cells of the i-th row of table a are numbered from 1 to ci, then let's denote the number written in the j-th cell of the i-th row as ai, j. Your task is to perform several swap operations to rearrange the numbers in the table so as to fulfill the following conditions:  for all i, j (1 < i ≤ n; 1 ≤ j ≤ ci) holds ai, j > ai - 1, j;  for all i, j (1 ≤ i ≤ n; 1 < j ≤ ci) holds ai, j > ai, j - 1. In one swap operation you are allowed to choose two different cells of the table and swap the recorded there numbers, that is the number that was recorded in the first of the selected cells before the swap, is written in the second cell after it. Similarly, the number that was recorded in the second of the selected cells, is written in the first cell after the swap.Rearrange the numbers in the required manner. Note that you are allowed to perform any number of operations, but not more than s. You do not have to minimize the number of operations.

The first line contains a single integer n (1 ≤ n ≤ 50) that shows the number of rows in the table. The second line contains n space-separated integers ci (1 ≤ ci ≤ 50; ci ≤ ci - 1) — the numbers of cells on the corresponding rows. Next n lines contain table а. The i-th of them contains ci space-separated integers: the j-th integer in this line represents ai, j. It is guaranteed that all the given numbers ai, j are positive and do not exceed s. It is guaranteed that all ai, j are distinct.

In the first line print a single integer m (0 ≤ m ≤ s), representing the number of performed swaps. In the next m lines print the description of these swap operations. In the i-th line print four space-separated integers xi, yi, pi, qi (1 ≤ xi, pi ≤ n; 1 ≤ yi ≤ cxi; 1 ≤ qi ≤ cpi). The printed numbers denote swapping the contents of cells axi, yi and api, qi. Note that a swap operation can change the contents of distinct table cells. Print the swaps in the order, in which they should be executed.

<?php
// Retrieve input
$stdin = fopen('php://stdin', 'r');
function g() {
	global $stdin;
	return explode(" ", trim(fgets($stdin)));
}

// Codeforces Problem 236B
// Codeforces Contest 147 Div 2 Problem B
$raw = g();
$n = $raw[0];
$ci = g();
$si[-1] = 0;
for ($i = 0; $i < $n; $i++) {
	$aij[$i] = g();
	$si[$i] = $ci[$i] + $si[$i-1];
}
$swaps = 0;
$swap[0] = "";

for ($r = 0; $r < $n; $r++) {
	for ($c = 0; $c < $ci[$r]; $c++) {
		while ($aij[$r][$c] != ($si[$r-1] + $c + 1)) {
			$rt = 0;
			while ($si[$rt] < $aij[$r][$c]) {
				$rt++;
			}
			$ct = $aij[$r][$c] - $si[$rt-1] - 1;
			$temp = $aij[$r][$c];
			$aij[$r][$c] = $aij[$rt][$ct];
			$aij[$rt][$ct] = $temp;
			$swap[$swaps] = ($r+1) . " " . ($c+1) . " " . ($rt+1) . " " . ($ct+1);
			$swaps++;
		}
	}
}
echo $swaps . "\n";
for ($i = 0; $i < $swaps; $i++) {
	echo $swap[$i] . "\n";
}

// End of submission file
// Submission by chaotic_iak
?>


It is the easy version of the problem. The only difference is that in this version $$$n = 1$$$.In the cinema seats can be represented as the table with $$$n$$$ rows and $$$m$$$ columns. The rows are numbered with integers from $$$1$$$ to $$$n$$$. The seats in each row are numbered with consecutive integers from left to right: in the $$$k$$$-th row from $$$m (k - 1) + 1$$$ to $$$m k$$$ for all rows $$$1 \le k \le n$$$. $$$1$$$$$$2$$$$$$\cdots$$$$$$m - 1$$$$$$m$$$$$$m + 1$$$$$$m + 2$$$$$$\cdots$$$$$$2 m - 1$$$$$$2 m$$$$$$2m + 1$$$$$$2m + 2$$$$$$\cdots$$$$$$3 m - 1$$$$$$3 m$$$$$$\vdots$$$$$$\vdots$$$$$$\ddots$$$$$$\vdots$$$$$$\vdots$$$$$$m (n - 1) + 1$$$$$$m (n - 1) + 2$$$$$$\cdots$$$$$$n m - 1$$$$$$n m$$$ The table with seats indices There are $$$nm$$$ people who want to go to the cinema to watch a new film. They are numbered with integers from $$$1$$$ to $$$nm$$$. You should give exactly one seat to each person.It is known, that in this cinema as lower seat index you have as better you can see everything happening on the screen. $$$i$$$-th person has the level of sight $$$a_i$$$. Let's define $$$s_i$$$ as the seat index, that will be given to $$$i$$$-th person. You want to give better places for people with lower sight levels, so for any two people $$$i$$$, $$$j$$$ such that $$$a_i < a_j$$$ it should be satisfied that $$$s_i < s_j$$$.After you will give seats to all people they will start coming to their seats. In the order from $$$1$$$ to $$$nm$$$, each person will enter the hall and sit in their seat. To get to their place, the person will go to their seat's row and start moving from the first seat in this row to theirs from left to right. While moving some places will be free, some will be occupied with people already seated. The inconvenience of the person is equal to the number of occupied seats he or she will go through.Let's consider an example: $$$m = 5$$$, the person has the seat $$$4$$$ in the first row, the seats $$$1$$$, $$$3$$$, $$$5$$$ in the first row are already occupied, the seats $$$2$$$ and $$$4$$$ are free. The inconvenience of this person will be $$$2$$$, because he will go through occupied seats $$$1$$$ and $$$3$$$.Find the minimal total inconvenience (the sum of inconveniences of all people), that is possible to have by giving places for all people (all conditions should be satisfied).

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$n = 1$$$, $$$1 \le m \le 300$$$) — the number of rows and places in each row respectively. The second line of each test case contains $$$n \cdot m$$$ integers $$$a_1, a_2, \ldots, a_{n \cdot m}$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the sight level of $$$i$$$-th person. It's guaranteed that the sum of $$$n \cdot m$$$ over all test cases does not exceed $$$10^5$$$.

For each test case print a single integer — the minimal total inconvenience that can be achieved.

NoteIn the first test case, there is a single way to arrange people, because all sight levels are distinct. The first person will sit on the first seat, the second person will sit on the second place, the third person will sit on the third place. So inconvenience of the first person will be $$$0$$$, inconvenience of the second person will be $$$1$$$ and inconvenience of the third person will be $$$2$$$. The total inconvenience is $$$0 + 1 + 2 = 3$$$.In the second test case, people should sit as follows: $$$s_1 = 2$$$, $$$s_2 = 1$$$, $$$s_3 = 5$$$, $$$s_4 = 4$$$, $$$s_5 = 3$$$. The total inconvenience will be $$$6$$$.

<?php
$arr = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $char = trim(fgets(STDIN));
    $str = trim(fgets(STDIN));
    $c = 0;
    $arr_expload = explode(" ", $str);
    for ($i = 0; $i < count($arr_expload); $i++) {
        for ($x = 0; $x < $i; $x++) {
            if ($arr_expload[$i] > $arr_expload[$x]) {
                $c++;
            }
        }
    }
    array_push($arr, $c . "\r\n");
}

foreach ($arr as $key => $value)
    print($value . "\r\n");
$end = readline();
?>


Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $$$n$$$ hotels, where the $$$i$$$-th hotel is located in the city with coordinate $$$x_i$$$. Sonya is a smart girl, so she does not open two or more hotels in the same city.Sonya understands that her business needs to be expanded by opening new hotels, so she decides to build one more. She wants to make the minimum distance from this hotel to all others to be equal to $$$d$$$. The girl understands that there are many possible locations to construct such a hotel. Thus she wants to know the number of possible coordinates of the cities where she can build a new hotel. Because Sonya is lounging in a jacuzzi in one of her hotels, she is asking you to find the number of cities where she can build a new hotel so that the minimum distance from the original $$$n$$$ hotels to the new one is equal to $$$d$$$.

The first line contains two integers $$$n$$$ and $$$d$$$ ($$$1\leq n\leq 100$$$, $$$1\leq d\leq 10^9$$$) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others. The second line contains $$$n$$$ different integers in strictly increasing order $$$x_1, x_2, \ldots, x_n$$$ ($$$-10^9\leq x_i\leq 10^9$$$) — coordinates of Sonya's hotels.

Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to $$$d$$$.

NoteIn the first example, there are $$$6$$$ possible cities where Sonya can build a hotel. These cities have coordinates $$$-6$$$, $$$5$$$, $$$6$$$, $$$12$$$, $$$13$$$, and $$$19$$$.In the second example, there are $$$5$$$ possible cities where Sonya can build a hotel. These cities have coordinates $$$2$$$, $$$6$$$, $$$13$$$, $$$16$$$, and $$$21$$$.

<?php
	$dir                    = fopen("php://stdin", 'r');
	$contents               = stream_get_contents($dir);
	$inputs                 = explode("\n",$contents);
	$hotelsNumber           = (int) explode(' ', $inputs[0])[0];
	$distance               = (int) explode(' ', $inputs[0])[1];
	$coordinates            = array_map('intval', explode(' ', $inputs[1]));
	getHotelsCount($hotelsNumber, $distance, $coordinates);

	function getHotelsCount($hotelsNumber, $distance, $coordinates)
	{
	    $hotelsCount = 2;
	    for($i = 0; $i < ($hotelsNumber-1); $i++)
	    {
		if(($coordinates[$i] + $distance) == ($coordinates[$i+1] - $distance)) {
		    $hotelsCount++;
		} elseif(($coordinates[$i] + $distance) < ($coordinates[$i+1] - $distance)) {
		    $hotelsCount += 2;
		}
	    }
	    echo $hotelsCount;
	}
?>


Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairway, she starts counting steps from $$$1$$$ to the number of steps in this stairway. She speaks every number aloud. For example, if she climbs two stairways, the first of which contains $$$3$$$ steps, and the second contains $$$4$$$ steps, she will pronounce the numbers $$$1, 2, 3, 1, 2, 3, 4$$$.You are given all the numbers pronounced by Tanya. How many stairways did she climb? Also, output the number of steps in each stairway.The given sequence will be a valid sequence that Tanya could have pronounced when climbing one or more stairways.

The first line contains $$$n$$$ ($$$1 \le n \le 1000$$$) — the total number of numbers pronounced by Tanya. The second line contains integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 1000$$$) — all the numbers Tanya pronounced while climbing the stairs, in order from the first to the last pronounced number. Passing a stairway with $$$x$$$ steps, she will pronounce the numbers $$$1, 2, \dots, x$$$ in that order. The given sequence will be a valid sequence that Tanya could have pronounced when climbing one or more stairways.

In the first line, output $$$t$$$ — the number of stairways that Tanya climbed. In the second line, output $$$t$$$ numbers — the number of steps in each stairway she climbed. Write the numbers in the correct order of passage of the stairways.

<?php
fscanf(STDIN,"%d",$sizeOfArr);
$arr=explode(' ',trim(fgets(STDIN)));
$cnt=1;
$lastItem=array();
for ($i=0,$j=0; $i <$sizeOfArr-1 ; $i++)
 {
	  if($arr[$i]>=$arr[$i+1])
	  {
	  	$cnt++;
	  	$lastItem[$j++]=$arr[$i];
	  }
 }
 $lastItem[count($lastItem)]=$arr[$sizeOfArr-1];
 echo "$cnt\n";
 for ($i=0; $i <count($lastItem) ; $i++)
  {
  	if($i==count($lastItem)-1)
 	    echo "$lastItem[$i]";
 	else
 		echo "$lastItem[$i] ";
  }

<?php
$n = (int)fgets(STDIN);
$a = explode(' ', trim(fgets(STDIN)));
$ans = array();

for ($i = 0; $i < $n - 1; ++$i) {
    if ($a[$i + 1] === '1') {
        $ans[] = $a[$i];
    }
}
$ans[] = $a[$n - 1];

echo count($ans) . "\n";
foreach ($ans as $i) {
    print("$i ");
}

<?php
$n_numbers = readline ();
$numbers = explode (" ", readline ());
$n_stairways = 0;
$stairways_steps = array ();
for ($i = 0; $i < $n_numbers; ++$i)
{
        if ($numbers[$i] == 1) {
                $stairways_steps[$n_stairways] = $numbers[$i-1];
                ++$n_stairways;
        }
}
array_shift($stairways_steps);
$stairways_steps[$n_stairways] = $numbers[$n_numbers-1];
echo $n_stairways."\n";
foreach ($stairways_steps as $ss) {
        echo $ss." ";
}

<?php
    $dir                    = fopen("php://stdin", 'r');
    $contents               = stream_get_contents($dir);
    $inputs                 = explode("\n",$contents);
    $numbersCount           = (int) $inputs[0];
    $stepsArray             = array_map('intval', explode(' ', $inputs[1]));
    getStairwaysCount($numbersCount, $stepsArray);
    function getStairwaysCount($numbersCount, $stepsArray)
    {
        $stairwaysCount = array_count_values($stepsArray)[1];
        echo $stairwaysCount.PHP_EOL;
        $arr = [];
        $numberOneOcurance = array_keys($stepsArray, 1);
        for($i = 0; $i < count($numberOneOcurance)-1; $i++)
        {
            $arr[] = $numberOneOcurance[$i+1] - $numberOneOcurance[$i];
        }
        $arr[] = $numbersCount - end($numberOneOcurance);
        foreach($arr as $key=> $value)
        {
            echo $value.' ';
        }
    }
?>


Vasya has got two number: a and b. However, Vasya finds number a too short. So he decided to repeat the operation of lengthening number a n times.One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by Vasya's number b. If it is impossible to obtain the number which is divisible by b, then the lengthening operation cannot be performed.Your task is to help Vasya and print the number he can get after applying the lengthening operation to number a n times.

The first line contains three integers: a, b, n (1 ≤ a, b, n ≤ 105).

In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number a n times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them.


A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.

The first input line contains integer k (1 ≤ k ≤ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 ≤ |s| ≤ 1000, where |s| is the length of string s.

Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them. If the solution doesn't exist, print "-1" (without quotes).

<?php
    $k = intval(trim(fgets(STDIN)));
    $alph = str_split(trim(fgets(STDIN)));

    $count = array();

    foreach ($alph as $value) {
        if (array_key_exists($value, $count))
                $count[$value] += 1;
        else
            $count[$value] = 1;
    }

    $str = "";
    for ($i = 0; $i < $k; ++$i) {
        foreach ($count as $key => $val) {
            if ($val % $k != 0) {
                echo -1;
                die();
            }

            for ($j = 0; $j < $val / $k; ++$j) {
                $str = $str.$key;
            }
        }
    }

    echo $str;
?>

<?
$k = fgets(STDIN);
$s = trim(fgets(STDIN));
$s_arr = str_split($s);
foreach($s_arr as $v){++$chr[$v];}
for($y=0;$y<$k;$y++){
    foreach($chr as $ck => $cv){
        if($cv%$k==0){
        for($i=0;$i<($cv/$k);$i++){$w .=$ck;}
        }
        else{$w = -1;break;}
    }
}
echo $w;
?>

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = array();
$d = array();
$e = array();
if($a == 1)
{
    print $b;
}
elseif(strlen($b) % $a != 0)
{
    print "-1";
}
else
{
    for($x = 0; $x < strlen($b); $x++)
    {
        array_push($c, $b[$x]);
    }
    $d = array_unique($c);
    if(count($c) / count($d) == $a)
    {
        for($y = 1; $y <= $a; $y++)
        {
            array_push($e, implode($d));
        }
        print implode($e);
    }
    else
    {
        print "-1";
    }
}
?>

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = array();
$d = array();
$e = array();
$n = array();
$f = 0;
$g = 0;
if($a == 1)
{
    print $b;
}
elseif(strlen($b) % $a != 0)
{
    print "-1";
}
else
{
    for($x = 0; $x < strlen($b); $x++)
    {
        array_push($c, $b[$x]);
    }
    $d = array_unique($c);
    for($y = 1; $y <= $a; $y++)
    {
        array_push($e, implode($d));
    }
    $k = implode($e);
    for($x = 0; $x < strlen($k); $x++)
    {
        array_push($n, $k[$x]);
    }
    for($z = 0; $z < count($c); $z++)
    {
        $f = ord($c[$z]);
        $h += $f;
        $g = ord($n[$z]);
        $i += $g;
    }
    if($h != $i)
    {
        print "-1";
    }
    elseif(count($c) / count($d) == $a)
    {
        print implode($n);
    }
    else
    {
        print "-1";
    }
}
?>

<?
$k = fgets(STDIN);
$s = fgets(STDIN);
$s_arr = str_split($s);
foreach($s_arr as $v){++$chr[$v];}
for($y=0;$y<$k;$y++){
foreach($chr as $ck => $cv){
if($cv%$k==0){
for($i=0;$i<($cv/$k);$i++){$w .=$ck;}
}
else{$w = -1;break;}
}
}
echo $w;
?>

<?
$k = fgets(STDIN);
$s = trim(fgets(STDIN));
$s_arr = str_split($s);
foreach($s_arr as $v){++$chr[$v];}
for($y=0;$y<$k;$y++){
    foreach($chr as $ck => $cv){
        if($cv%$k==0){
        for($i=0;$i<($cv/$k);$i++){$w .=$ck;}
        }
        else{$w = -1;break;}
    }
}
echo $cv;
?>

<?
$k = fgets(STDIN);
$s = fgets(STDIN);
$s_arr = str_split($s);
foreach($s_arr as $v){++$chr[$v];}
for($y=0;$y<$k;$y++){
    foreach($chr as $ck => $cv){
        if($cv%$k==0){
        for($i=0;$i<($cv/$k);$i++){$w .=$ck;}
        }
        else{$w = -1;break;}
    }
}
echo $cv;
?>


Leha somehow found an array consisting of n integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts are glued together into one array and the game continues. The second player can choose a subsegment of non-zero length with an even sum and remove it. Loses the one who can not make a move. Who will win if both play optimally?

First line of input data contains single integer n (1 ≤ n ≤ 106) — length of the array. Next line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109).

Output answer in single line. "First", if first player wins, and "Second" otherwise (without quotes).

NoteIn first sample first player remove whole array in one move and win.In second sample first player can't make a move and lose.

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_sum($b);
$d = bcmod($c, 2);
if($d == 0)
{
     $e = 0;
     for($x = 0; $x < $a; $x++)
     {
          $f = $b[$x] % 2;
          if($f == 1)
          {
               $e = 1;
               break;
          }
     }
     if($e == 0)
     {
          print "Second";
     }
     else
     {
          print "First";
     }
}
else
{
     print "First";
}
?>

<?php
$fp = fopen("php://stdin", 'r');
$line1 = trim(fgets($fp));
$line2 = trim(fgets($fp));
fclose($fp);
$length = intval($line1);
$arrNum = array_map('intval', explode(' ', $line2));
$check = true;
for ($i = 0; $i < $length; $i++) {
    if ($arrNum[$i] % 2 == 1) {
        $check = false;
    }
}
if (!$check) {
    echo "First", PHP_EOL;die;
}
echo "Second", PHP_EOL;die;

<?php
    $dir                        = fopen("php://stdin", 'r');
    $contents                   = stream_get_contents($dir);
    $inputs                     = explode("\n",$contents);
    $numbersCount               = (int) $inputs[0];
    $numbers                    = array_map('intval', explode(' ', $inputs[1]));
    $possibilitiesForEntrance   = [];
    echo getWinner($numbersCount, $numbers);

    function isArrayHasOddNumber($numbersCount, $numbers){
        for($counter = 0; $counter < $numbersCount; $counter++)
        {
            if($numbers[$counter] % 2 != 0)
            {
                return true;
            }
        }
    }

    function getWinner($numbersCount, $numbers)
    {
        if(isArrayHasOddNumber($numbersCount, $numbers))
        {
            return 'First';
        } else {
            return 'Second';
        }
    }

?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_sum($b);
$d = bcmod($c, 2);
if($a == 222)
{
     print $c . " " . $d;
}
if($d == 0)
{
     print "Second";
}
else
{
     print "First";
}
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_sum($b);
$d = bcmod($c, 2);
if($d == 0)
{
     print "Second";
}
else
{
     print "First";
}
?>

<?php
$fp = fopen("php://stdin", 'r');
$line1 = trim(fgets($fp));
$line2 = trim(fgets($fp));
fclose($fp);
$length = intval($line1);
$arrNum = array_map('intval', explode(' ', $line2));
$sum = 0;
for ($i = 0; $i < $length; $i++) {
    $sum += $arrNum[$i];
}
if ($sum % 2 == 1) {
    echo "First", PHP_EOL;die;
}
echo "Second", PHP_EOL;die;

<?php
$fp = fopen("php://stdin", 'r');
$line1 = trim(fgets($fp));
$line2 = trim(fgets($fp));
fclose($fp);
$length = intval($line1);
$arrNum = array_map('intval', explode(' ', $line2));
$sum = 0;
for ($i = 0; $i < $length; $i++) {
    $sum += $arrNum[$i];
}
if ($sum % 2 == 1) {
    echo "FIRST", PHP_EOL;die;
}
echo "SECOND", PHP_EOL;die;

<?php
$fp = fopen("php://stdin", 'r');
$line1 = trim(fgets($fp));
$line2 = trim(fgets($fp));
fclose($fp);
$length = intval($line1);
$arrNum = array_map('intval', explode(' ', $line2));
$sum = 0;
for ($i = 0; $i < $length -1 ; $i++) {
    $sum += $arrNum[$i] + $arrNum[$i + 1];
}
if ($sum % 2 == 1) {
    echo "FIRST", PHP_EOL;die;
}
echo "SECOND", PHP_EOL;die;


Let's call an array $$$t$$$ dominated by value $$$v$$$ in the next situation.At first, array $$$t$$$ should have at least $$$2$$$ elements. Now, let's calculate number of occurrences of each number $$$num$$$ in $$$t$$$ and define it as $$$occ(num)$$$. Then $$$t$$$ is dominated (by $$$v$$$) if (and only if) $$$occ(v) > occ(v')$$$ for any other number $$$v'$$$. For example, arrays $$$[1, 2, 3, 4, 5, 2]$$$, $$$[11, 11]$$$ and $$$[3, 2, 3, 2, 3]$$$ are dominated (by $$$2$$$, $$$11$$$ and $$$3$$$ respectevitely) but arrays $$$[3]$$$, $$$[1, 2]$$$ and $$$[3, 3, 2, 2, 1]$$$ are not.Small remark: since any array can be dominated only by one number, we can not specify this number and just say that array is either dominated or not.You are given array $$$a_1, a_2, \dots, a_n$$$. Calculate its shortest dominated subarray or say that there are no such subarrays.The subarray of $$$a$$$ is a contiguous part of the array $$$a$$$, i. e. the array $$$a_i, a_{i + 1}, \dots, a_j$$$ for some $$$1 \le i \le j \le n$$$.

The first line contains single integer $$$T$$$ ($$$1 \le T \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line contains single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of the array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$) — the corresponding values of the array $$$a$$$. It's guaranteed that the total length of all arrays in one test doesn't exceed $$$2 \cdot 10^5$$$.

Print $$$T$$$ integers — one per test case. For each test case print the only integer — the length of the shortest dominated subarray, or $$$-1$$$ if there are no such subarrays.

NoteIn the first test case, there are no subarrays of length at least $$$2$$$, so the answer is $$$-1$$$.In the second test case, the whole array is dominated (by $$$1$$$) and it's the only dominated subarray.In the third test case, the subarray $$$a_4, a_5, a_6$$$ is the shortest dominated subarray.In the fourth test case, all subarrays of length more than one are dominated.


Anton likes to play chess, and so does his friend Danik.Once they have played n games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.Now Anton wonders, who won more games, he or Danik? Help him determine this.

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of games played. The second line contains a string s, consisting of n uppercase English letters 'A' and 'D' — the outcome of each of the games. The i-th character of the string is equal to 'A' if the Anton won the i-th game and 'D' if Danik won the i-th game.

If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output. If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output. If Anton and Danik won the same number of games, print "Friendship" (without quotes).

NoteIn the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton".In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik".In the third sample, both Anton and Danik won 3 games and the answer is "Friendship".

<?php

/**
 * @author Sunwarul
 */

$n = (int) fgets(STDIN);
$str = trim(fgets(STDIN));

$anton = 0;
$danik = 0;

for ($i = 0; $i < strlen($str); $i++) {
    if ($str[$i] === 'A') {
        $anton++;
    } else if ($str[$i] === 'D') {
        $danik++;
    }
}

if ($anton > $danik) {
    echo "Anton\n";
} else if ($danik > $anton) {
    echo "Danik\n";
} else {
    echo "Friendship\n";
}

<?php
	$n = trim(fgets(STDIN));
	$s = trim(fgets(STDIN));
	$a = $d = 0;
	for($i = 0; $i < $n; $i++)
		if($s[$i] == 'A') $a++;
		else $d++;
	echo $a > $d ? 'Anton' : ($a < $d ? 'Danik' : 'Friendship');
?>

<?php

$number = readline();
$a = readline();

$b = preg_match_all('/[A]/', $a);
$c = preg_match_all('/[D]/', $a);

if ($b > $c) {
	echo "Anton";
}elseif($b == $c){
	echo "Friendship";
}else{
	echo "Danik";
}

<?php

$num = (int)readline();

$str = readline();

if(substr_count($str, 'A') > substr_count($str,'D')) {
    echo 'Anton';
} elseif(substr_count($str, 'A') < substr_count($str,'D')) {
    echo 'Danik';
} else echo 'Friendship';

<?php
$NotRequiredVariable=readline();
$str = readline();
$a = str_split($str);
$b=strlen($str);
$ab=0;
$ac=0;
for($i=0;$i<$b;$i++)
{
    $c=$a[$i];
    if ($c=="A")
    {
        $ab++;
    }
    if ($c=="D")
    {
        $ac++;
    }
}
if ($ab==$ac)
{
    echo"Friendship";
}
else if($ab>$ac)
{
    echo"Anton";
}
else{
    echo "Danik";
}
?>

<?php
$n=readline();
$s=readline();
$t1=0;
$t2=0;
$str=str_split($s,1);
for($i=0;$i<$n;$i++){
    if($str[$i]=='A')
    $t1++;
    else
    $t2++;
}
if($t1==$t2)
echo "Friendship";
elseif($t1>$t2)
echo "Anton";
else
echo "Danik";

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = 0;
$d = 0;
for($x = 0; $x < $a; $x++)
{
     if($b[$x] == "A")
     {
          $c++;
     }
     else
     {
          $d++;
     }
}
if($c < $d)
{
     print "Danik";
}
elseif($c == $d)
{
     print "Friendship";
}
elseif($c > $d)
{
     print "Anton";
}
?>

<?php

fgets(STDIN);
$results = str_split(trim(fgets(STDIN)));
$anton = 0;
foreach ($results as $result) {
    $anton += $result === 'A' ? 1 : -1;
}

if ($anton > 0) echo "Anton";
if ($anton < 0) echo "Danik";
if ($anton === 0) echo "Friendship";

<?php
$arr = [];

for ($i=0; $i < 2; $i++) {
        $arr[$i] = readline();
}
$output = 0;

$str =$arr[1];
$A =[];
$D = [];
for ($i = 0; $i < strlen($str); $i++){
    //echo $str[$i];

    if($str[$i]== 'A'){
        array_push( $A, $str[$i]);
    }
    if($str[$i] == 'D'){
        array_push( $D, $str[$i]);

    }

}
if(count($A) > count($D)){
    echo 'Anton';
}

if(count($A) < count($D)){
    echo 'Danik';

}
if(count($A) == count($D)){
    echo 'Friendship';

}

?>

<?php
$n = readline();
$s = readline();
if (substr_count($s, 'A') > substr_count($s, 'D')) {
  echo 'Anton';
}
elseif (substr_count($s, 'A') < substr_count($s, 'D')) {
  echo 'Danik';
}
else {
  echo 'Friendship';
}

<?php

$n = readline();
$wins = str_split(readline());

$a=0;
$d=0;

foreach ($wins as $w) {
    if($w === 'D') {
        $d += 1;
    } elseif($w === 'A') {
        $a += 1;
    }
}

echo $a > $d ? 'Anton' : ( $d > $a ? 'Danik' : 'Friendship');

?>

<?php
$line0 = trim(fgets(STDIN));
$line1 = trim(fgets(STDIN));
$A = substr_count($line1,'A');
$D = $line0 - $A;
if ($A>$D){
	echo "Anton";
} elseif($A < $D){
	echo "Danik";
} else {
	echo "Friendship";
}
?>

<?php
/*
 * Secdra @2020
 */

fscanf(STDIN, "%d", $len);
$word = trim(fgets(STDIN));
$a = substr_count($word, 'A');
printf("%s", ($a > $len - $a) ? 'Anton' : (($a == $len - $a) ? 'Friendship' : 'Danik'));

<?php
$dir = fopen("php://stdin", 'r');;
$input= file('php://stdin');
$a=0;
$d=0;
for ($i=0,$c=strlen(trim($input[1]));$i<$c;$i++){
    if (trim($input[1])[$i] === "A"){
        $a ++;
    }else{
        $d ++;
    }
}

if ($a == $d){
    echo 'Friendship';
}else{
    if ($a > $d){
        echo "Anton";
    }else{
        echo "Danik";
    }
}

<?php
$dir = fopen("php://stdin", 'r');;
$input= file('php://stdin');
$a=0;
$d=0;
$str= trim($input[1]);
for ($i=0,$c=strlen($str);$i<$c;$i++){
    if ($str[$i] === "A"){
        $a ++;
    }else{
        $d ++;
    }
}

if ($a == $d){
    echo 'Friendship';
}else{
    if ($a > $d){
        echo "Anton";
    }else{
        echo "Danik";
    }
}

<?php

//=====================================
// link: https://codeforces.com/contest/734/problem/A
//=====================================

// get inputs
$input = new Input(['number_of_games', 'winning_rounds']);
$winning_rounds = str_split($input->winning_rounds);

// solution
$rounds = [
    'Anton' => 0,
    'Danik' => 0,
];

foreach ($winning_rounds as $w_round) {
    if($w_round == 'A') {
        $rounds['Anton']++;

        continue;
    }

    $rounds['Danik']++;
}

if($rounds['Anton'] > $rounds['Danik']) {
    echo "Anton\n";

    exit;
}

if($rounds['Danik'] > $rounds['Anton']) {
    echo "Danik\n";

    exit;
}

echo "Friendship\n";

//=====================================
// Per-defined helpers
//=====================================
class Input
{
    public $inputs = [];

    public function __construct(array $input_titles = ['line'])
    {
        $this->getInputs($input_titles);
    }

    private function getInputs($input_titles)
    {
        for ($i=0; $i < count($input_titles); $i++) {
            $this->inputs[$input_titles[$i]] = trim(fgets(STDIN));
        }
    }

    public function __get($name)
    {
        return $this->inputs[$name];
    }
}

<?php

//=====================================
// link: https://codeforces.com/contest/734/problem/A
//=====================================

// get inputs
$number_of_games = trim(fgets(STDIN));
$winning_rounds = trim(fgets(STDIN));

// solution
$anton = 0;
$danik = 0;

for ($i=0; $i < $number_of_games; $i++) {
    if($winning_rounds[$i] == 'A') {
        $anton++;

        continue;
    }

    $danik++;
}

if($anton > $danik) {
    echo "Anton\n";

    exit;
}

if($danik > $anton) {
    echo "Danik\n";

    exit;
}

echo "Friendship\n";

<?php
	$n = trim(fgets(STDIN));
	$str = trim(fgets(STDIN));
	$a = preg_match_all("/[A]/", $str);
	$d = preg_match_all("/[D]/", $str);
	echo ($a>$d)?"Anton":(($d>$a)?"Danik":"Friendship");
?>

<?php
    fscanf(STDIN, "%d", $n);
    fscanf(STDIN, "%s", $s);
    $a = 0;
    $d = 0;
        for ($i = 0; $i < $n; $i++){
           if ($s[$i] == "A"){
               $a++;
           }
           else $d++;
        }
  if ($a > $d){
            echo 'Anton';
        }
        else if ($a < $d){
            echo 'Danik';
        }
        else if ($a == $d) {
        echo 'Friendship';
}

<?php
function input()
{
    while (($line = fgets(STDIN)) != PHP_EOL) {
        yield $line;
    }
}

$COUNT = 0;
foreach (input() as $line) {
    if ($COUNT == 0) {
        $n = intval($line);
        ++$COUNT;
        continue;
    }
    $s = $line;

    $c = 0;
    for($i=0; $i<$n; ++$i) {
        if($s[$i] == 'A') {
            ++$c;
        }
    }

    $d = $n-2*$c;
    if( $d > 0)
      echo "Danik";
    elseif ($d < 0)
      echo "Anton";
    else
      echo "Friendship";

    if (++$COUNT > 1) {
        break;
    }
}

<?php
readline();
$s = readline();
$a = substr_count($s, 'A');
$d = substr_count($s, 'D');
echo $a > $d ? 'Anton' : ($a < $d ? 'Danik' : 'Friendship');

<?php
$total = trim(fgets(STDIN));
$str = trim(fgets(STDIN));
$a = 0;
$d = 0;
for ($i=0; $i < $total; $i++) {
	if ($str[$i] === 'A') {
		$a++;
	} elseif ($str[$i] === 'D') {
		$d++;
	}
}

if ($a == $d) {
	echo "Friendship\n";
} elseif ($a > $d) {
	echo "Anton\n";
} else {
	echo "Danik\n";
}

<?php

$numofgames=trim(fgets(STDIN));
$win=trim(fgets(STDIN));
$array=str_split($win);

$arraynum = array_count_values($array);

if ($arraynum[A] == $arraynum[D]) {

    echo "Friendship";

}elseif ($arraynum[A] > $arraynum[D]) {
    echo "Anton";

}else echo "Danik";

?>

<?php
fscanf(STDIN,"%d",$n);
fscanf(STDIN, "%s",$s);
$com="AD";

for($i=0;$i<strlen($com);$i++)
{  $count=0;
	for($j=0;$j<strlen($s);$j++)
	{
      if($com[$i]==$s[$j])
      {
      	$count++;
      }
	}
	$store[$i]=$count;
}
if($store[0]>$store[1])
	echo "Anton";
else if($store[0]<$store[1])
	echo "Danik";
else echo "Friendship";

<?php

function gaber($n , $s )
{
     $anton = 0 ;
     $danik = 0 ;
     for( $i=0; $i< strlen($s) ; $i++)
     {
          if( $s[$i] == "A" )
          {
               $anton++ ;
          }
          else
          {
               $danik++ ;
          }
     }
     if( $anton > $danik )
     {
          echo "Anton" ;
     }
     else if( $anton < $danik )
     {
          echo "Danik" ;
     }
     else
     {
          echo "Friendship" ;
     }
}

$stdout = fopen( getenv( "OUTPUT_PATH" ) , "w" ) ;
$stdin = fopen( "php://stdin" , "r" ) ;

fscanf( $stdin , "%d" , $n ) ;
fscanf( $stdin , "%s", $s);

//$arr = array_map('intval', preg_split('/ /', $ar_temp, -1, PREG_SPLIT_NO_EMPTY) );

$result = gaber( $n , $s )  ;

fwrite ( $stdout , $result . "\n" ) ;

fclose( $stdin ) ;
fclose( $stdout ) ;

?>

<?php
$N = rtrim(fgets(STDIN));
$string = rtrim(fgets(STDIN));
$Anton = substr_count($string,"A");
$Danik = substr_count($string,"D");
if($Anton>$Danik){
    echo("Anton");
}elseif ($Anton<$Danik){
    echo("Danik");
}else {
    echo("Friendship");
}

<?php

function check($s,$d)
{
    $c=0;$r=0;
    for ($i=0;$i<$d;$i++)
    {
        if($s[$i]=='A')$c++;
        else $r++;
    }

    if($c>$r)
        return "Anton";
    else if($c<$r)
        return "Danik";
    else
        return "Friendship";
}
function solve()
{
    $server="php://stdin";
    $local="input.txt";
    $handle = fopen($server, "r");
    $s="";$d=0;
    fscanf($handle, "%d", $d);
    fscanf($handle, "%s", $s);
    printf("%s", check($s,$d));
}

solve();
?>

<?php
$a = trim(fgets(STDIN));
$str = trim(fgets(STDIN));

$c = 0;
$d = 0;
for ($i=0; $i<$a; $i++)
{
    if ('A' == $str[$i])
    {
        $c++;
    }
    else
    {
        $d++;
    }
}

if ($c > $d)
{
    echo 'Anton';
}else if ($c < $d)
{
    echo 'Danik';
}else if ($c == $d)
{
    echo 'Friendship';
}

<?
namespace P734\A;
    /**
     * @file          : main.php
     * @author        : Khalil Fazal <khalil.fazal@uoit.net>
     * @creation_date : 2016-11-18 09:34
     * @project       : codeforces
     */

    /**
     * @title        : A. Anton and Danik
     * @link         : http://codeforces.com/problemset/problem/734/A
     * @tags         : implementation, strings
     * @time_limit   : 1 s
     * @memory_limit : 256 MB
     * @input        : stdin
     * @output       : stdout
     *
     * Anton likes to play chess, and so does his friend Danik.
     *
     * Once they have played n games in a row. For each game it's known who was the winner — Anton or Danik.
     * None of the games ended with a tie.
     *
     * Now Anton wonders, who won more games, he or Danik? Help him determine this.
     *
     * Input
     *      The first line of the input contains a single integer n (1 ≤ n ≤ 1e5) — the number of games played.
     *      The second line contains a string s, consisting of n uppercase English letters 'A' and 'D'
     *      — the outcome of each of the games.
     *      The i-th character of the string is equal to 'A' if the Anton won the i-th game
     *      and 'D' if Danik won the i-th game.
     *
     * Output
     *      If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output.
     *      If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output.
     *      If Anton and Danik won the same number of games, print "Friendship" (without quotes).
     */

/**
 * @param string $string
 * @param string $char
 *
 * @return int
 */
function freq($string, $char): int {
    return count_chars($string, 0)[ord($char)];
}

$stdin = fopen("php://stdin", "r");
fgets($stdin);
$games = fgets($stdin);

switch (freq($games, "A") <=> freq($games, "D")) {
    case -1:
        echo "Danik";
        break;
    case 0:
        echo "Friendship";
        break;
    case 1:
        echo "Anton";
        break;
}

<?php
$a=trim(fgets(STDIN));
$b=trim(fgets(STDIN));
if( substr_count($b,"D")> substr_count($b,"A"))  echo "Danik";
else if( substr_count($b,"D")< substr_count($b,"A")) echo "Anton";
else echo "Friendship";

?>

<?php

//First Get The Input.
$input = file_get_contents("php://stdin");

$n = explode("\r\n",$input)[0];
$str = explode("\r\n",$input)[1];

$n = trim($n,"\r\n");
$str = trim($str,"\r\n");

$a = 0;

for($i = 0;$i < $n;$i++) {

    if($str[$i] == "A") {

        $a++;

    }

}

$d = $n - $a;

if($a > $d) {

    echo "Anton";

}elseif($a < $d) {

    echo "Danik";

}else {

    echo "Friendship";

}

<?php
    $n = trim(fgets(STDIN));
    $s = trim(fgets(STDIN));
    $W_A = strlen(str_replace("D", "", $s));
    $W_D = $n - $W_A;
    if ($W_A > $W_D) {
      echo "Anton";
    }elseif ($W_A == $W_D) {
      echo "Friendship";
    }else {
      echo "Danik";
    }
 ?>

<?php
fscanf(STDIN, '%d\n', $n);
$line = fgets(STDIN);
$a = 0;
$d = 0;

for ($i=0; $i < $n; $i++) {
	if ($line[$i] == 'A') {
		$a++;
	}else{
		$d++;
	}
}

if($a > $d){
	print_r("Anton");
}elseif ($d > $a) {
	print_r("Danik");
}else{
	print_r("Friendship");
}

<?php

$number = readline();
$a = readline();

$b = preg_match_all('/[A]/', $a);
$c = preg_match_all('/[D]/', $a);

if ($b > $c) {
	echo "Anton";
}elseif($b == $c){
	echo "FriendShip";
}else{
	echo "Danik";
}

<?php

$num = (int)readline();

$str = readline();

if(substr_count('A' , $str) > substr_count('D', $str)) {
    echo 'Anton';
} elseif(substr_count('A' , $str) < substr_count('D', $str)) {
    echo 'Danik';
} else echo 'Friendship';

<?php
$a=readline();
$b=readline();
$ab=0;
$ac=0;
$q="A";
$v="D";
$m=strlen($b);
for($i=0;$i<$m;$i++)
{
if (strpos($b,$q)==true)
{
    $ab++;
}
if(strpos($b,$v)==true)
{
    $ac++;
}
}
if ($ab==$ac)
{
    echo"Friendship";
}
else if($ab>$ac)
{
    echo"Anton";
}
else{
    "Danik";
}
?>

<?php
$str = readline();
$a = str_split($str);
$b=strlen($str);
$ab=0;
$ac=0;
for($i=0;$i<$b;$i++)
{
    $c=$a[$i];
    if ($c=="A")
    {
        $ab++;
    }
    if ($c=="D")
    {
        $ac++;
    }
}
if ($ab==$ac)
{
    echo"Friendship";
}
else if($ab>$ac)
{
    echo"Anton";
}
else{
    echo "Danik";
}
?>

<?php
$a=readline();
$b=readline();
$ab=0;
$ac=0;
$q="A";
$v="D";
$m=strlen($b);
for($i=0;$i<$m;$i++)
{
if (strpos($b,$q)==true)
{
    $a1++;
}
if(strpos($b,$v)==true)
{
    $a2++;
}
}
if ($ab==$ac)
{
    echo"Friendship";
}
else if($ab>$ac)
{
    echo"Anton";
}
else{
    "Danik";
}
?>

<?php

$wins = str_split(readline());

$a=0;
$d=0;

foreach ($wins as $w) {
    if($w === 'D') {
        $d += 1;
    } elseif($w === 'A') {
        $a += 1;
    }
}

echo $a > $d ? 'Anton' : ( $d > $a ? 'Danik' : 'Friendship');

?>

<?php
$line0 = trim(fgets(STDIN));
$line1 = trim(fgets(STDIN));
$A = substr_count($line1,'A');
if ($line0 - $A>0){
	echo "Anton";
} elseif($line0 - $A < 0){
	echo "Danik";
} else {
	echo "Friendship";
}
?>

<?php
$line0 = trim(fgets(STDIN));
$line1 = trim(fgets(STDIN));
$A = substr_count($input,$x);
if ($A - $line0>0){
	echo "Anton";
} elseif($A - $line0 < 0){
	echo "Danik";
} else {
	echo "Friendship";
}
?>

<?php
$dir = fopen("php://stdin", 'r');;
$input= file('php://stdin');
$a=0;
$d=0;
for ($i=0,$c=strlen($input[1]);$i<$c;$i++){
    if ($input[1][$i] == "A"){
        $a ++;
    }else{
        $d ++;
    }
}

if ($a == $d){
    echo 'Friendship';
}else{
    if ($a > $d){
        echo "Anton";
    }else{
        echo "Danik";
    }
}

<?php

$dir = fopen("php://stdin", 'r');;
$input= file('php://stdin');
$a=0;
$d=0;
for ($i=0,$c=strlen($input[1]);$i<$c;$i++){
    if ($input[1][$i] === "A"){
        $a ++;
    }else{
        $d ++;
    }
}

if ($a == $d){
    echo 'Friendship';
}else{
    if ($a > $d){
        echo "Anton";
    }else{
        echo "Danik";
    }
}

<?php
readline();
$s = readline();
$a = substr_count($s, 'A');
$d = substr_count($s, 'D');
echo $a > $d ? 'Anton' : $a < $d ? 'Danik' : 'Friendship';

<?php
function getinput()
{
	$handle = fopen("php://stdin", 'r');
	return trim(fgets($handle));
}
$total = (int) getinput();
$str = getinput();
$a = 0;
$d = 0;
for ($i=0; $i < $total; $i++) {
	if ($str[$i] === 'A') {
		$a++;
	} elseif ($str[$i] === 'D') {
		$d++;
	}
}

if ($a == $d) {
	echo "Friendship\n";
} elseif ($a > $d) {
	echo "Anton\n";
} else {
	echo "Danik\n";
}

$_N = rtrim(fgets(STDIN));
$string = rtrim(fgets(STDIN));
$Anton = substr_count($string,"A");
$Danik = substr_count($string,"D");
if($Anton>$Danik){
    echo("Anton");
}elseif ($Anton<$Danik){
    echo("Danik");
}else {
    echo("Friendship");
}

<?php

function check($s)
{
    $c=0;$r=0;
    foreach ($s as $b)
    {
        if($b=='A')$c++;
        else $r++;
    }

    if($c>$r)
        return "Anton";
    else if($c<$r)
        return "Danik";
    else
        return "Friendship";
}
function solve()
{
    $server="php://stdin";
    $local="input.txt";
    $handle = fopen($server, "r");
    $s="";
    fscanf($handle, "%s", $s);
    printf("%s", check($s));
}

solve();
?>

<?php
$a=trim(fgets(STDIN));
$b=trim(fgets(STDIN));
if( substr_count($b,"D")> substr_count($b,"A"))  echo "Danik"; else echo "Anton";

?>

<?php
    $n = 6;
    $s = "ADDADD";
    $W_A = strlen(str_replace("D", "", $s));
    $W_D = $n - $W_A;
    if ($W_A > $W_D) {
      echo "Anton";
    }elseif ($W_A == $W_D) {
      echo "Friendship";
    }else {
      echo "Danik";
    }
 ?>


Moamen has an array of $$$n$$$ distinct integers. He wants to sort that array in non-decreasing order by doing the following operations in order exactly once:  Split the array into exactly $$$k$$$ non-empty subarrays such that each element belongs to exactly one subarray.  Reorder these subarrays arbitrary.  Merge the subarrays in their new order. A sequence $$$a$$$ is a subarray of a sequence $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.Can you tell Moamen if there is a way to sort the array in non-decreasing order using the operations written above?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^3$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 10^5$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le |a_i| \le 10^9$$$). It is guaranteed that all numbers are distinct. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3\cdot10^5$$$.

For each test case, you should output a single string. If Moamen can sort the array in non-decreasing order, output "YES" (without quotes). Otherwise, output "NO" (without quotes). You can print each letter of "YES" and "NO" in any case (upper or lower).

NoteIn the first test case, $$$a = [6, 3, 4, 2, 1]$$$, and $$$k = 4$$$, so we can do the operations as follows:   Split $$$a$$$ into $$$\{ [6], [3, 4], [2], [1] \}$$$.  Reorder them: $$$\{ [1], [2], [3,4], [6] \}$$$.  Merge them: $$$[1, 2, 3, 4, 6]$$$, so now the array is sorted. In the second test case, there is no way to sort the array by splitting it into only $$$2$$$ subarrays.As an example, if we split it into $$$\{ [1, -4], [0, -2] \}$$$, we can reorder them into $$$\{ [1, -4], [0, -2] \}$$$ or $$$\{ [0, -2], [1, -4] \}$$$. However, after merging the subarrays, it is impossible to get a sorted array.

<?php
$fileName = 'php://stdin';
$file = fopen($fileName, "r");

$t = trim(fgets($file));

for ($i = 0; $i < $t; $i++) {
  list($n, $k) = explode(" ", trim(fgets($file)));
  $a = explode(" ", trim(fgets($file)));

  $s = $a[0];
  $c = 1;

  $b = array_flip($a);
  sort($a);

  for ($j = 1; $j < $n; $j++) {
    if ($j == 0) {
      if ($s != $a[$j]) { $c++; }
    } else {
      if ($b[$a[$j]] - $b[$a[$j - 1]] != 1) {
        $c++;
      }
    }
  }

  if ($c <= $k) { echo 'YES'.PHP_EOL; }
  else { echo 'NO'.PHP_EOL;}
}

?>

<?php
class IO {
    public static $aAlphabet = ['A','B','C','D', 'E', 'F', 'G', 'H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
    //Input/Output
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function asLine($mArr, $sep = ' ') { echo implode($sep, $mArr) . PHP_EOL; }

    //Z-function
    public static function z($sString) {
        $s = str_split($sString);
        $n = count($s);
        $z = array_fill(0, $n, 0);
        $r = $l = 0;
        for ($i = 1; $i < $n; $i++) {
            if ($r >= $i) {
                $z[$i] = min($z[$i - $l], $r - $i + 1);
            }
            while ($z[$i] + $i < $n && $s[$z[$i]] == $s[$z[$i] + $i]) {
                $z[$i]++;
            }
            if ($i + $z[$i] - 1 > $r) {
                $l = $i;
                $r = $i + $z[$i] - 1;
            }
        }
        return $z;
    }
    public static function getCountOfDiffSubstrWithZ($sString)
    {
        $s = str_split($sString);
        $n = count($s);
        $count = 0;
        $t = '';
        for ($i = $n - 1; $i >= 0; $i--) {
            $t = $s[$i] . $t;
            $count += $i + 1 - max(self::z($t));
        }
        return $count;
    }
    public static function getMinPeriodOfSubstrWithZ($sString)
    {
        $s = str_split($sString);
        $res = count($s);
        $z = self::z($sString);
        foreach ($z as $iI => $sV) {
            if ((int) $iI + $z[$iI] == $res && $res % (int) $iI == 0) {
                $res = $iI;
                break;
            }
        }
        return $res;
    }

    //Other functions
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }

}

//$iQueryCount = 1;
$iQueryCount = IO::str();
$aAllResults = [];
while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    list($n, $m) = IO::arr();
    $a = IO::arr();
    $f = $a[0];
    $b = array_flip($a);
    sort($a);
    $res = 1;
    for ($i = 1; $i < $n; $i++) {
        if ($i == 0) {
            if ($f != $a[$i]) {
               $res++;
            }
        } else {
            $x = $a[$i];
            $y = $a[$i - 1];
            if ($b[$x] - $b[$y] !== 1) {
                $res++;
            }
        }
    }

    if ($res <= $m) {
        IO::yes();
    } else {
        IO::no();
    }

}

?>

<?php
$fileName = 'php://stdin';
$file = fopen($fileName, "r");

$t = trim(fgets($file));

for ($i = 0; $i < $t; $i++) {
  list($n, $k) = explode(" ", trim(fgets($file)));
  $a = explode(" ", trim(fgets($file)));

  $c = array();
  $z = 0;
  $b = 0;

  for ($j = 0; $j < $n; $j++) {
    while ($a[$j] < $a[$j + 1]) {
      $j++;
      $c[$b] = $z++;
    }
    $b++;
  }
  $d = $n - count($c);
  if ($d <= $k || (count($c) == 1 && $z == $n - 1)) { echo 'YES'.PHP_EOL; }
  else { echo 'NO'.PHP_EOL;}
}

?>

<?php
$fileName = 'php://stdin';
$file = fopen($fileName, "r");

$t = trim(fgets($file));

for ($i = 0; $i < $t; $i++) {
  list($n, $k) = explode(" ", trim(fgets($file)));
  $a = explode(" ", trim(fgets($file)));

  $c = 0;

  for ($j = 0; $j < $n; $j++) {
    while ($a[$j] < $a[$j + 1]) {
      $j++;
      $c++;
    }
  }
  $d = $n - $c;
  if ($d <= $k) { echo 'YES'.PHP_EOL; }
  else { echo 'NO'.PHP_EOL;}
}

?>

<?php
class IO {
    public static $aAlphabet = ['A','B','C','D', 'E', 'F', 'G', 'H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
    //Input/Output
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function asLine($mArr, $sep = ' ') { echo implode($sep, $mArr) . PHP_EOL; }

    //Z-function
    public static function z($sString) {
        $s = str_split($sString);
        $n = count($s);
        $z = array_fill(0, $n, 0);
        $r = $l = 0;
        for ($i = 1; $i < $n; $i++) {
            if ($r >= $i) {
                $z[$i] = min($z[$i - $l], $r - $i + 1);
            }
            while ($z[$i] + $i < $n && $s[$z[$i]] == $s[$z[$i] + $i]) {
                $z[$i]++;
            }
            if ($i + $z[$i] - 1 > $r) {
                $l = $i;
                $r = $i + $z[$i] - 1;
            }
        }
        return $z;
    }
    public static function getCountOfDiffSubstrWithZ($sString)
    {
        $s = str_split($sString);
        $n = count($s);
        $count = 0;
        $t = '';
        for ($i = $n - 1; $i >= 0; $i--) {
            $t = $s[$i] . $t;
            $count += $i + 1 - max(self::z($t));
        }
        return $count;
    }
    public static function getMinPeriodOfSubstrWithZ($sString)
    {
        $s = str_split($sString);
        $res = count($s);
        $z = self::z($sString);
        foreach ($z as $iI => $sV) {
            if ((int) $iI + $z[$iI] == $res && $res % (int) $iI == 0) {
                $res = $iI;
                break;
            }
        }
        return $res;
    }

    //Other functions
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }

}

//$iQueryCount = 1;
$iQueryCount = IO::str();
$aAllResults = [];
while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    list($n, $m) = IO::arr();
    $a = IO::arr();
    $f = $a[0];
    $b = array_flip($a);
    sort($a);
    $res = 0;
    for ($i = 0; $i < $n; $i++) {
        if ($i == 0) {
            if ($f != $a[$i]) {
               $res++;
            }
        } else {
            $x = $a[$i];
            $y = $a[$i - 1];
            if ($b[$x] - $b[$y] !== 1) {
                $res++;
            }
        }
    }

    if ($res <= $m) {
        IO::yes();
    } else {
        IO::no();
    }

}

?>

<?php
class IO {
    public static $aAlphabet = ['A','B','C','D', 'E', 'F', 'G', 'H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
    //Input/Output
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function asLine($mArr, $sep = ' ') { echo implode($sep, $mArr) . PHP_EOL; }

    //Z-function
    public static function z($sString) {
        $s = str_split($sString);
        $n = count($s);
        $z = array_fill(0, $n, 0);
        $r = $l = 0;
        for ($i = 1; $i < $n; $i++) {
            if ($r >= $i) {
                $z[$i] = min($z[$i - $l], $r - $i + 1);
            }
            while ($z[$i] + $i < $n && $s[$z[$i]] == $s[$z[$i] + $i]) {
                $z[$i]++;
            }
            if ($i + $z[$i] - 1 > $r) {
                $l = $i;
                $r = $i + $z[$i] - 1;
            }
        }
        return $z;
    }
    public static function getCountOfDiffSubstrWithZ($sString)
    {
        $s = str_split($sString);
        $n = count($s);
        $count = 0;
        $t = '';
        for ($i = $n - 1; $i >= 0; $i--) {
            $t = $s[$i] . $t;
            $count += $i + 1 - max(self::z($t));
        }
        return $count;
    }
    public static function getMinPeriodOfSubstrWithZ($sString)
    {
        $s = str_split($sString);
        $res = count($s);
        $z = self::z($sString);
        foreach ($z as $iI => $sV) {
            if ((int) $iI + $z[$iI] == $res && $res % (int) $iI == 0) {
                $res = $iI;
                break;
            }
        }
        return $res;
    }

    //Other functions
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }

}

//$iQueryCount = 1;
$iQueryCount = IO::str();
$aAllResults = [];
while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    list($n, $m) = IO::arr();
    $a = IO::arr();
    $res = 0;
    $last = $a[0];
    for($i = 0; $i < $n; $i++) {
        if(!isset($a[$i+1])) {
            continue;
        }
        if ($a[$i] > $a[$i+1]) {
            $res++;
        } elseif ($a[$i+1] < $last) {
            $res++;
        }
        if ($last < $a[$i + 1]) {
            $last = $a[$i+1];
        }
    }
    if ($res <= $m) {
        IO::yes();
    } else {
        IO::no();
    }

}

?>

<?php
class IO {
    public static $aAlphabet = ['A','B','C','D', 'E', 'F', 'G', 'H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
    //Input/Output
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function asLine($mArr, $sep = ' ') { echo implode($sep, $mArr) . PHP_EOL; }

    //Z-function
    public static function z($sString) {
        $s = str_split($sString);
        $n = count($s);
        $z = array_fill(0, $n, 0);
        $r = $l = 0;
        for ($i = 1; $i < $n; $i++) {
            if ($r >= $i) {
                $z[$i] = min($z[$i - $l], $r - $i + 1);
            }
            while ($z[$i] + $i < $n && $s[$z[$i]] == $s[$z[$i] + $i]) {
                $z[$i]++;
            }
            if ($i + $z[$i] - 1 > $r) {
                $l = $i;
                $r = $i + $z[$i] - 1;
            }
        }
        return $z;
    }
    public static function getCountOfDiffSubstrWithZ($sString)
    {
        $s = str_split($sString);
        $n = count($s);
        $count = 0;
        $t = '';
        for ($i = $n - 1; $i >= 0; $i--) {
            $t = $s[$i] . $t;
            $count += $i + 1 - max(self::z($t));
        }
        return $count;
    }
    public static function getMinPeriodOfSubstrWithZ($sString)
    {
        $s = str_split($sString);
        $res = count($s);
        $z = self::z($sString);
        foreach ($z as $iI => $sV) {
            if ((int) $iI + $z[$iI] == $res && $res % (int) $iI == 0) {
                $res = $iI;
                break;
            }
        }
        return $res;
    }

    //Other functions
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }

}

//$iQueryCount = 1;
$iQueryCount = IO::str();
$aAllResults = [];
while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    list($n, $m) = IO::arr();
    $a = IO::arr();
    $res = 0;
    $last = $a[0];
    for($i = 0; $i < $n; $i++) {
        if(!isset($a[$i+1])) {
            continue;
        }
        if ($a[$i] > $a[$i+1]) {
            $res++;
        } elseif ($a[$i] < $last) {
            $res++;
        }
        if ($a[$i] > $last) {
            $last = $a[$i];
        }
    }
    if ($res <= $m) {
        IO::yes();
    } else {
        IO::no();
    }

}

?>


Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k.

The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj).

In a single line print a single integer — the answer to the problem.


After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her.The three friends are very smart so they passed all the challenges very quickly and finally reached the destination. But the treasure can only belong to one cat so they started to think of something which can determine who is worthy of the treasure. Instantly, Kuro came up with some ribbons.A random colorful ribbon is given to each of the cats. Each color of the ribbon can be represented as an uppercase or lowercase Latin letter. Let's call a consecutive subsequence of colors that appears in the ribbon a subribbon. The beauty of a ribbon is defined as the maximum number of times one of its subribbon appears in the ribbon. The more the subribbon appears, the more beautiful is the ribbon. For example, the ribbon aaaaaaa has the beauty of $$$7$$$ because its subribbon a appears $$$7$$$ times, and the ribbon abcdabc has the beauty of $$$2$$$ because its subribbon abc appears twice.The rules are simple. The game will have $$$n$$$ turns. Every turn, each of the cats must change strictly one color (at one position) in his/her ribbon to an arbitrary color which is different from the unchanged one. For example, a ribbon aaab can be changed into acab in one turn. The one having the most beautiful ribbon after $$$n$$$ turns wins the treasure.Could you find out who is going to be the winner if they all play optimally?

The first line contains an integer $$$n$$$ ($$$0 \leq n \leq 10^{9}$$$) — the number of turns. Next 3 lines contain 3 ribbons of Kuro, Shiro and Katie one per line, respectively. Each ribbon is a string which contains no more than $$$10^{5}$$$ uppercase and lowercase Latin letters and is not empty. It is guaranteed that the length of all ribbons are equal for the purpose of fairness. Note that uppercase and lowercase letters are considered different colors.

Print the name of the winner ("Kuro", "Shiro" or "Katie"). If there are at least two cats that share the maximum beauty, print "Draw".

7
treasurehunt
threefriends
hiCodeforces

NoteIn the first example, after $$$3$$$ turns, Kuro can change his ribbon into ooooo, which has the beauty of $$$5$$$, while reaching such beauty for Shiro and Katie is impossible (both Shiro and Katie can reach the beauty of at most $$$4$$$, for example by changing Shiro's ribbon into SSiSS and changing Katie's ribbon into Kaaaa). Therefore, the winner is Kuro.In the fourth example, since the length of each of the string is $$$9$$$ and the number of turn is $$$15$$$, everyone can change their ribbons in some way to reach the maximal beauty of $$$9$$$ by changing their strings into zzzzzzzzz after 9 turns, and repeatedly change their strings into azzzzzzzz and then into zzzzzzzzz thrice. Therefore, the game ends in a draw.

<?php
$n = intval(trim(fgets(STDIN)));
$kr = trim(fgets(STDIN));
$sh = trim(fgets(STDIN));
$kt = trim(fgets(STDIN));

$krn = $shn = $ktn = [];

$len = strlen($kr);
if ($len <= $n) {
	die("Draw\n");
}
for($i=0; $i<$len; $i++){
	if (!isset($krn[$kr[$i]])) {
		$krn[$kr[$i]] = 0;
	}
	if (!isset($shn[$sh[$i]])) {
		$shn[$sh[$i]] = 0;
	}
	if (!isset($ktn[$kt[$i]])) {
		$ktn[$kt[$i]] = 0;
	}
	$krn[$kr[$i]] += 1;
	$shn[$sh[$i]] += 1;
	$ktn[$kt[$i]] += 1;
}

$krx = max($krn);
$shx = max($shn);
$ktx = max($ktn);
// echo "$krx -- $ktx -- $shx\n";
if ($krx == $len && $n == 1) {
	$krx--;
}elseif(($len - $krx) <= $n){
	$krx = $len;
}else{
	$krx += $n;
}

if ($shx == $len && $n == 1) {
	$shx--;
}elseif(($len - $shx) <= $n){
	$shx = $len;
}else{
	$shx += $n;
}

if ($ktx == $len && $n == 1) {
	$ktx--;
}elseif(($len - $ktx) <= $n){
	$ktx = $len;
}else{
	$ktx += $n;
}
// echo "$krx -- $ktx -- $shx\n";
if((($krx == $shx) && $krx >= $ktx) || (($krx == $ktx) && $krx >= $shx) || (($shx == $ktx) && $shx >= $krx)){
	die("Draw\n");
}else{
	if($ktx > $shx && $ktx > $krx){
		echo "Katie\n";
	}elseif($krx > $ktx && $krx > $shx){
		echo "Kuro\n";
	}else{
		echo "Shiro\n";
	}
}

<?php
$n = intval(trim(fgets(STDIN)));
$kr = trim(fgets(STDIN));
$sh = trim(fgets(STDIN));
$kt = trim(fgets(STDIN));

$krn = $shn = $ktn = [];

$len = strlen($kr);
if ($len <= $n) {
	die("Draw\n");
}
for($i=0; $i<$len; $i++){
	if (!isset($krn[$kr[$i]])) {
		$krn[$kr[$i]] = 0;
	}
	if (!isset($shn[$sh[$i]])) {
		$shn[$sh[$i]] = 0;
	}
	if (!isset($ktn[$kt[$i]])) {
		$ktn[$kt[$i]] = 0;
	}
	$krn[$kr[$i]] += 1;
	$shn[$sh[$i]] += 1;
	$ktn[$kt[$i]] += 1;
}

$krx = max($krn);
$shx = max($shn);
$ktx = max($ktn);
// echo "$krx -- $ktx -- $shx\n";
if(($len - $krx) <= $n){
	$krx = $len;
}else{
	$krx += $n;
}

if(($len - $shx) <= $n){
	$shx = $len;
}else{
	$shx += $n;
}

if(($len - $ktx) <= $n){
	$ktx = $len;
}else{
	$ktx += $n;
}
// echo "$krx -- $ktx -- $shx\n";
if((($krx == $shx) && $krx > $ktx) || (($krx == $ktx) && $krx > $shx) || (($shx == $ktx) && $shx > $krx)){
	die("Draw\n");
}else{
	if($ktx > $shx && $ktx > $krx){
		echo "Katie\n";
	}elseif($krx > $ktx && $krx > $shx){
		echo "Kuro\n";
	}else{
		echo "Shiro\n";
	}
}

<?php
$n = intval(trim(fgets(STDIN)));
$kr = trim(fgets(STDIN));
$sh = trim(fgets(STDIN));
$kt = trim(fgets(STDIN));

$krn = $shn = $ktn = [];

$len = strlen($kr);
if ($len <= $n) {
	die("Draw\n");
}
for($i=0; $i<$len; $i++){
	if (!isset($krn[$kr[$i]])) {
		$krn[$kr[$i]] = 0;
	}
	if (!isset($shn[$sh[$i]])) {
		$shn[$sh[$i]] = 0;
	}
	if (!isset($ktn[$kt[$i]])) {
		$ktn[$kt[$i]] = 0;
	}
	$krn[$kr[$i]] += 1;
	$shn[$sh[$i]] += 1;
	$ktn[$kt[$i]] += 1;
}
// print_r($krn);
// print_r($ktn);
// print_r($shn);

$krx = max($krn);
$shx = max($shn);
$ktx = max($ktn);

if((($krx == $shx) && $krx > $ktx) || (($krx == $ktx) && $krx > $shx) || (($shx == $ktx) && $shx > $krx)){
	die("Draw\n");
}else{
	if($ktx > $shx && $ktx > $krx){
		echo "Katie\n";
	}elseif($krx > $ktx && $krx > $shx){
		echo "Kuro\n";
	}else{
		echo "Shiro\n";
	}
}