Ela loves reading a lot, just like her new co-workers in DTL! On her first day after becoming an engineer in DTL, she is challenged by a co-worker to sort a heap of books into different compartments on the shelf.$$$n$$$ books must be split into $$$k$$$ compartments on the bookshelf ($$$n$$$ is divisible by $$$k$$$). Each book is represented by a lowercase Latin letter from 'a' to 'y' inclusively, which is the beginning letter in the title of the book.Ela must stack exactly $$$\frac{n}{k}$$$ books in each compartment. After the books are stacked, for each compartment indexed from $$$1$$$ to $$$k$$$, she takes the minimum excluded (MEX) letter of the multiset of letters formed by letters representing all books in that compartment, then combines the resulting letters into a string. The first letter of the resulting string is the MEX letter of the multiset of letters formed by the first compartment, the second letter of the resulting string is the MEX letter of the multiset of letters formed by the second compartment, ... and so on. Please note, under the constraint of this problem, MEX letter can always be determined for any multiset found in this problem because 'z' is not used.What is the lexicographically greatest resulting string possible that Ela can create?A string $$$a$$$ is lexicographically greater than a string $$$b$$$ if and only if one of the following holds:  $$$b$$$ is a prefix of $$$a$$$, but $$$b \ne a$$$;  in the first position where $$$a$$$ and $$$b$$$ differ, the string $$$a$$$ has a letter that appears later in the alphabet than the corresponding letter in $$$b$$$. The minimum excluded (MEX) letter of a multiset of letters is the letter that appears earliest in the alphabet and is not contained in the multiset. For example, if a multiset of letters contains $$$7$$$ letters 'b', 'a', 'b', 'c', 'e', 'c', 'f' respectively, then the MEX letter of this compartment is 'd', because 'd' is not included in the multiset, and all letters comes before 'd' in the alphabet, namely 'a', 'b' and 'c', are included in the multiset.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 200$$$; $$$1 \le k \le n$$$). It is guaranteed that $$$n$$$ is divisible by $$$k$$$. The second line of each test case contains a string of $$$n$$$ lowercase Latin letters from 'a' to 'y' inclusively. Each letter represents the starting letter of the title of a book in the initial heap. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$1000$$$.

For each test case, output a string of $$$k$$$ letters which is the most optimal string that Ela can find.

5

12 3

cabccadabaac

12 6

cabccadabaac

12 12

cabccadabaac

25 1

abcdefghijklmnopqrstuvwxy

10 5

bcdxedbcfg

NoteIn the first test case, the books can be divided into $$$3$$$ compartments as below:  the first compartment contains the books with indices $$$1, 2, 3, 7$$$: $$$multiset_1 = \{$$$'c', 'a', 'b', 'd'$$$\}$$$ $$$\rightarrow$$$ $$$MEX(multiset_1) =$$$ 'e'  the second compartment contains the books with indices $$$4, 5, 6, 9$$$ : $$$multiset_2 = \{$$$'c', 'c', 'a', 'b'$$$\}$$$ $$$\rightarrow$$$ $$$MEX(multiset_2) =$$$ 'd'  the third compartment contains the remaining books $$$8, 10, 11, 12$$$ : $$$multiset_3 = \{$$$ 'a', 'a', 'a', 'c'$$$\}$$$ $$$\rightarrow$$$ $$$MEX(multiset_3) =$$$ 'b' Therefore, the answer is 'edb'. It can be proven that there is no way that Ela can arrange the books so that it results in a lexicographically greater string.

#!/bin/perl

use strict;

my $t = <STDIN>;

my @alphabet = ('a'..'z');

for my $tn (1..$t){
    # 12, 3
    my ($n, $k) = split / /, <STDIN>;

    # 4
    my $l = $n / $k;

    # cabccadabaac
    my $string = <STDIN>;

    chomp $string;

    my @letters = split //, $string;

    my %count;
    for my $l (@letters){
        $count{$l}++;
    }

    my @final_list;
    for (my $row = 0; $row < $k; $row++) {
        my $col = 0;
        my $symb;
        for my $char (@alphabet){
            last if $col > $l;
            if ($count{$char} > 0){
                $symb = $char;
                $count{$char}--;
                $col++;
                next;
            }
            $symb = $char;
            last;

        }

        push @final_list, $symb;
    }

    @final_list = sort {$b cmp $a} @final_list;

    # edb

    print join "", @final_list;
    print "\n";
}

#!/bin/perl

use strict;
use Data::Dumper 'Dumper';

my $t = <STDIN>;

my @alphabet = ('a'..'z');

for my $tn (1..$t){
    # 12, 3
    my ($n, $k) = split / /, <STDIN>;

    # 4
    my $l = $n / $k;

    # cabccadabaac
    my $string = <STDIN>;

    chomp $string;

    my @letters = split //, $string;

    @letters = sort @letters;

    my %count;
    for my $l (@letters){
        $count{$l}++;
    }

    my @lists;

    while ($k > 0){
        my $l1 = $l;
        my @list;
        while ($l1 > 0){
            for my $letter (sort {$a cmp $b || $count{$a} <=> $count{$b}} keys %count){
                if ($count{$letter} > 0){
                    $count{$letter}--;
                    push @list, $letter;
                    $l1--;
                }
                if ($l1 == 0){
                    push @lists, \@list;
                    last ;
                }
            }

        }
        $k--;
    }

    my @final_list;
    for my $list (@lists){
        for my $letter (@alphabet){
            if (grep($letter eq $_, @$list) == 0){
                push @final_list, $letter;
                last;
            }
        }
    }

    @final_list = sort {$b cmp $a} @final_list;

    # edb

    print join "", @final_list;
    print "\n";
}

#!/bin/perl

use strict;
use Data::Dumper 'Dumper';

my $t = <STDIN>;

my @alphabet = ('a'..'z');

for my $tn (1..$t){
    # 12, 3
    my ($n, $k) = split / /, <STDIN>;

    # 4
    my $l = $n / $k;

    # cabccadabaac
    my $string = <STDIN>;

    chomp $string;

    my @letters = split //, $string;

    @letters = sort @letters;

    my %count;
    for my $l (@letters){
        $count{$l}++;
    }

    my @lists;

    while ($k > 0){
        my $l1 = $l;
        my @list;
        while ($l1 > 0){
            for my $letter (sort {$count{$b} <=> $count{$a}} keys %count){
                if ($count{$letter} > 0){
                    $count{$letter}--;
                    push @list, $letter;
                    $l1--;
                }
                if ($l1 == 0){
                    push @lists, \@list;
                    last ;
                }
            }

        }
        $k--;
    }

    my @final_list;
    for my $list (@lists){
        for my $letter (@alphabet){
            if (grep($letter eq $_, @$list) == 0){
                push @final_list, $letter;
                last;
            }
        }
    }

    @final_list = sort {$b cmp $a} @final_list;

    # edb

    print join "", @final_list;
    print "\n";
}

#!/bin/perl

use strict;

my $t = <STDIN>;

my @alphabet = ('a'..'z');

for my $tn (1..$t){
    # 12, 3
    my ($n, $k) = split / /, <STDIN>;

    # 4
    my $l = $n / $k;

    # cabccadabaac
    my $string = <STDIN>;

    chomp $string;

    my @letters = split //, $string;

    my %count;
    for my $l (@letters){
        $count{$l}++;
    }

    my @lists;

    while ($k > 0){
        my $l1 = $l;
        my @list;
        my $stage = 1;
        while ($l1 > 0){
            if ($stage == 1){
                for my $letter (sort {$a cmp $b} keys %count){
                    if ($count{$letter} > 0){
                        $count{$letter}--;
                        push @list, $letter;
                        $l1--;
                    }
                    if ($l1 == 0){
                        push @lists, \@list;
                        last ;
                    }
                }
            }
            if ($stage > 1){
                for my $letter (sort {$a cmp $b} keys %count){
                    while ($count{$letter} > 0){
                        $count{$letter}--;
                        push @list, $letter;
                        $l1--;
                        if ($l1 == 0){
                            last ;
                        }
                    }
                    if ($l1 == 0){
                        push @lists, \@list;
                        last ;
                    }
                }
            }
            $stage++;

        }
        $k--;
    }

    my @final_list;
    for my $list (@lists){
        for my $letter (@alphabet){
            if (grep($letter eq $_, @$list) == 0){
                push @final_list, $letter;
                last;
            }
        }
    }

    @final_list = sort {$b cmp $a} @final_list;

    # edb

    print join "", @final_list;
    print "\n";
}

#!/bin/perl

use strict;

my $t = <STDIN>;

my @alphabet = ('a'..'z');

for my $tn (1..$t){
    # 12, 3
    my ($n, $k) = split / /, <STDIN>;

    # 4
    my $l = $n / $k;

    # cabccadabaac
    my $string = <STDIN>;

    chomp $string;

    my @letters = split //, $string;

    my %count;
    for my $l (@letters){
        $count{$l}++;
    }

    my @lists;

    while ($k > 0){
        my $l1 = $l;
        my @list;
        while ($l1 > 0){
            for my $letter (sort {$a cmp $b} keys %count){
                if ($count{$letter} > 0){
                    $count{$letter}--;
                    push @list, $letter;
                    $l1--;
                }
                if ($l1 == 0){
                    push @lists, \@list;
                    last ;
                }

            }
        }
        $k--;
    }

    my @final_list;
    for my $list (@lists){
        for my $letter (@alphabet){
            if (grep($letter eq $_, @$list) == 0){
                push @final_list, $letter;
                last;
            }
        }
    }

    @final_list = sort {$b cmp $a} @final_list;

    # edb

    print join "", @final_list;
    print "\n";
}


The string $$$s$$$ is given, the string length is odd number. The string consists of lowercase letters of the Latin alphabet.As long as the string length is greater than $$$1$$$, the following operation can be performed on it: select any two adjacent letters in the string $$$s$$$ and delete them from the string. For example, from the string "lemma" in one operation, you can get any of the four strings: "mma", "lma", "lea" or "lem" In particular, in one operation, the length of the string reduces by $$$2$$$.Formally, let the string $$$s$$$ have the form $$$s=s_1s_2 \dots s_n$$$ ($$$n>1$$$). During one operation, you choose an arbitrary index $$$i$$$ ($$$1 \le i < n$$$) and replace $$$s=s_1s_2 \dots s_{i-1}s_{i+2} \dots s_n$$$.For the given string $$$s$$$ and the letter $$$c$$$, determine whether it is possible to make such a sequence of operations that in the end the equality $$$s=c$$$ will be true? In other words, is there such a sequence of operations that the process will end with a string of length $$$1$$$, which consists of the letter $$$c$$$?

The first line of input data contains an integer $$$t$$$ ($$$1 \le t \le 10^3$$$) — the number of input test cases. The descriptions of the $$$t$$$ cases follow. Each test case is represented by two lines:   string $$$s$$$, which has an odd length from $$$1$$$ to $$$49$$$ inclusive and consists of lowercase letters of the Latin alphabet;  is a string containing one letter $$$c$$$, where $$$c$$$ is a lowercase letter of the Latin alphabet.

For each test case in a separate line output:  YES, if the string $$$s$$$ can be converted so that $$$s=c$$$ is true; NO otherwise.  You can output YES and NO in any case (for example, the strings yEs, yes, Yes and YES will be recognized as a positive response).

5

abcde

c

abcde

b

x

y

aaaaaaaaaaaaaaa

a

contest

t

NoteIn the first test case, $$$s$$$="abcde". You need to get $$$s$$$="c". For the first operation, delete the first two letters, we get $$$s$$$="cde". In the second operation, we delete the last two letters, so we get the expected value of $$$s$$$="c".In the third test case, $$$s$$$="x", it is required to get $$$s$$$="y". Obviously, this cannot be done.

#!/usr/bin/perl
use Data::Dumper;
use integer;   ### important!

my ($testcase) = map { $_ - 0 } split(/\s+/,<STDIN>);

while( $testcase -- > 0 ){
  ( my $s = <STDIN> ) =~ s/[\x00-\x20]+$//ios;
  ( my $c = <STDIN> ) =~ s/[\x00-\x20]+$//ios;
  my $r = 'NO';
  for(my $i=0;$i<length($s);$i++){
    if( substr($s,$i,1) eq $c and $i % 2 == 0 ){
      $r = 'YES'; last;
    }
  }
  print "$r\n";
}

exit(0);


To satisfy his love of matching socks, Phoenix has brought his $$$n$$$ socks ($$$n$$$ is even) to the sock store. Each of his socks has a color $$$c_i$$$ and is either a left sock or right sock. Phoenix can pay one dollar to the sock store to either:   recolor a sock to any color $$$c'$$$ $$$(1 \le c' \le n)$$$  turn a left sock into a right sock  turn a right sock into a left sock  The sock store may perform each of these changes any number of times. Note that the color of a left sock doesn't change when it turns into a right sock, and vice versa. A matching pair of socks is a left and right sock with the same color. What is the minimum cost for Phoenix to make $$$n/2$$$ matching pairs? Each sock must be included in exactly one matching pair.

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains three integers $$$n$$$, $$$l$$$, and $$$r$$$ ($$$2 \le n \le 2 \cdot 10^5$$$; $$$n$$$ is even; $$$0 \le l, r \le n$$$; $$$l+r=n$$$) — the total number of socks, and the number of left and right socks, respectively. The next line contains $$$n$$$ integers $$$c_i$$$ ($$$1 \le c_i \le n$$$) — the colors of the socks. The first $$$l$$$ socks are left socks, while the next $$$r$$$ socks are right socks. It is guaranteed that the sum of $$$n$$$ across all the test cases will not exceed $$$2 \cdot 10^5$$$.

For each test case, print one integer — the minimum cost for Phoenix to make $$$n/2$$$ matching pairs. Each sock must be included in exactly one matching pair.

NoteIn the first test case, Phoenix can pay $$$2$$$ dollars to:   recolor sock $$$1$$$ to color $$$2$$$  recolor sock $$$3$$$ to color $$$2$$$  There are now $$$3$$$ matching pairs. For example, pairs $$$(1, 4)$$$, $$$(2, 5)$$$, and $$$(3, 6)$$$ are matching.In the second test case, Phoenix can pay $$$3$$$ dollars to:   turn sock $$$6$$$ from a right sock to a left sock  recolor sock $$$3$$$ to color $$$1$$$  recolor sock $$$4$$$ to color $$$1$$$  There are now $$$3$$$ matching pairs. For example, pairs $$$(1, 3)$$$, $$$(2, 4)$$$, and $$$(5, 6)$$$ are matching.


A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» n square houses with the centres on the Оx-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other.The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the Оx-axis, to be square in shape, have a side t, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the Ox-axis and it shouldn't overlap any of the houses in the village.Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house?

The first line of the input data contains numbers n and t (1 ≤ n, t ≤ 1000). Then there follow n lines, each of them contains two space-separated integer numbers: xi ai, where xi — x-coordinate of the centre of the i-th house, and ai — length of its side ( - 1000 ≤ xi ≤ 1000, 1 ≤ ai ≤ 1000).

Output the amount of possible positions of the new house.

NoteIt is possible for the x-coordinate of the new house to have non-integer value.


Recently in Divanovo, a huge river locks system was built. There are now $$$n$$$ locks, the $$$i$$$-th of them has the volume of $$$v_i$$$ liters, so that it can contain any amount of water between $$$0$$$ and $$$v_i$$$ liters. Each lock has a pipe attached to it. When the pipe is open, $$$1$$$ liter of water enters the lock every second.The locks system is built in a way to immediately transfer all water exceeding the volume of the lock $$$i$$$ to the lock $$$i + 1$$$. If the lock $$$i + 1$$$ is also full, water will be transferred further. Water exceeding the volume of the last lock pours out to the river.   The picture illustrates $$$5$$$ locks with two open pipes at locks $$$1$$$ and $$$3$$$. Because locks $$$1$$$, $$$3$$$, and $$$4$$$ are already filled, effectively the water goes to locks $$$2$$$ and $$$5$$$. Note that the volume of the $$$i$$$-th lock may be greater than the volume of the $$$i + 1$$$-th lock.To make all locks work, you need to completely fill each one of them. The mayor of Divanovo is interested in $$$q$$$ independent queries. For each query, suppose that initially all locks are empty and all pipes are closed. Then, some pipes are opened simultaneously. For the $$$j$$$-th query the mayor asks you to calculate the minimum number of pipes to open so that all locks are filled no later than after $$$t_j$$$ seconds.Please help the mayor to solve this tricky problem and answer his queries.

The first lines contains one integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the number of locks.  The second lines contains $$$n$$$ integers $$$v_1, v_2, \dots, v_n$$$ ($$$1 \le v_i \le 10^9$$$)) — volumes of the locks.  The third line contains one integer $$$q$$$ ($$$1 \le q \le 200\,000$$$) — the number of queries.  Each of the next $$$q$$$ lines contains one integer $$$t_j$$$ ($$$1 \le t_j \le 10^9$$$) — the number of seconds you have to fill all the locks in the query $$$j$$$.

Print $$$q$$$ integers. The $$$j$$$-th of them should be equal to the minimum number of pipes to turn on so that after $$$t_j$$$ seconds all of the locks are filled. If it is impossible to fill all of the locks in given time, print $$$-1$$$.

NoteThere are $$$6$$$ queries in the first example test. In the queries $$$1, 3, 4$$$ the answer is $$$-1$$$. We need to wait $$$4$$$ seconds to fill the first lock even if we open all the pipes. In the sixth query we can open pipes in locks $$$1$$$, $$$3$$$, and $$$4$$$. After $$$4$$$ seconds the locks $$$1$$$ and $$$4$$$ are full. In the following $$$1$$$ second $$$1$$$ liter of water is transferred to the locks $$$2$$$ and $$$5$$$. The lock $$$3$$$ is filled by its own pipe. Similarly, in the second query one can open pipes in locks $$$1$$$, $$$3$$$, and $$$4$$$.In the fifth query one can open pipes $$$1, 2, 3, 4$$$.


This week Arkady wanted to cook some pancakes (to follow ancient traditions) and make a problem about that. But then he remembered that one can't make a problem about stacking pancakes without working at a specific IT company, so he decided to bake the Napoleon cake instead.To bake a Napoleon cake, one has to bake $$$n$$$ dry layers first, and then put them on each other in one stack, adding some cream. Arkady started with an empty plate, and performed the following steps $$$n$$$ times:   place a new cake layer on the top of the stack;  after the $$$i$$$-th layer is placed, pour $$$a_i$$$ units of cream on top of the stack. When $$$x$$$ units of cream are poured on the top of the stack, top $$$x$$$ layers of the cake get drenched in the cream. If there are less than $$$x$$$ layers, all layers get drenched and the rest of the cream is wasted. If $$$x = 0$$$, no layer gets drenched.  The picture represents the first test case of the example. Help Arkady determine which layers of the cake eventually get drenched when the process is over, and which don't.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 20\,000$$$). Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of layers in the cake. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le n$$$) — the amount of cream poured on the cake after adding each layer. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print a single line with $$$n$$$ integers. The $$$i$$$-th of the integers should be equal to $$$1$$$ if the $$$i$$$-th layer from the bottom gets drenched, and $$$0$$$ otherwise.


You are given two strings $$$s$$$ and $$$t$$$. The string $$$s$$$ consists of lowercase Latin letters and at most one wildcard character '*', the string $$$t$$$ consists only of lowercase Latin letters. The length of the string $$$s$$$ equals $$$n$$$, the length of the string $$$t$$$ equals $$$m$$$.The wildcard character '*' in the string $$$s$$$ (if any) can be replaced with an arbitrary sequence (possibly empty) of lowercase Latin letters. No other character of $$$s$$$ can be replaced with anything. If it is possible to replace a wildcard character '*' in $$$s$$$ to obtain a string $$$t$$$, then the string $$$t$$$ matches the pattern $$$s$$$.For example, if $$$s=$$$"aba*aba" then the following strings match it "abaaba", "abacaba" and "abazzzaba", but the following strings do not match: "ababa", "abcaaba", "codeforces", "aba1aba", "aba?aba".If the given string $$$t$$$ matches the given string $$$s$$$, print "YES", otherwise print "NO".

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 2 \cdot 10^5$$$) — the length of the string $$$s$$$ and the length of the string $$$t$$$, respectively. The second line contains string $$$s$$$ of length $$$n$$$, which consists of lowercase Latin letters and at most one wildcard character '*'. The third line contains string $$$t$$$ of length $$$m$$$, which consists only of lowercase Latin letters.

Print "YES" (without quotes), if you can obtain the string $$$t$$$ from the string $$$s$$$. Otherwise print "NO" (without quotes).

NoteIn the first example a wildcard character '*' can be replaced with a string "force". So the string $$$s$$$ after this replacement is "codeforces" and the answer is "YES".In the second example a wildcard character '*' can be replaced with an empty string. So the string $$$s$$$ after this replacement is "vkcup" and the answer is "YES".There is no wildcard character '*' in the third example and the strings "v" and "k" are different so the answer is "NO".In the fourth example there is no such replacement of a wildcard character '*' that you can obtain the string $$$t$$$ so the answer is "NO".

#!/usr/bin/env perl

use strict;
use warnings;

my ($n, $m) = map { int } split /\s+/, <>;
my $s = <>;
chomp $s;
my $t = <>;
chomp $t;
$s =~ s/\*/.*/;
if ($t =~ /^$s$/) {
  print "YES\n";
}
else {
  print "NO\n";
}


$$$n$$$ heroes fight against each other in the Arena. Initially, the $$$i$$$-th hero has level $$$a_i$$$.Each minute, a fight between two different heroes occurs. These heroes can be chosen arbitrarily (it's even possible that it is the same two heroes that were fighting during the last minute).When two heroes of equal levels fight, nobody wins the fight. When two heroes of different levels fight, the one with the higher level wins, and his level increases by $$$1$$$.The winner of the tournament is the first hero that wins in at least $$$100^{500}$$$ fights (note that it's possible that the tournament lasts forever if no hero wins this number of fights, then there is no winner). A possible winner is a hero such that there exists a sequence of fights that this hero becomes the winner of the tournament.Calculate the number of possible winners among $$$n$$$ heroes.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 500$$$) — the number of test cases. Each test case consists of two lines. The first line contains one integer $$$n$$$ ($$$2 \le n \le 100$$$) — the number of heroes. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 100$$$), where $$$a_i$$$ is the initial level of the $$$i$$$-th hero.

For each test case, print one integer — the number of possible winners among the given $$$n$$$ heroes.

NoteIn the first test case of the example, the only possible winner is the first hero.In the second test case of the example, each fight between the heroes results in nobody winning it, so the tournament lasts forever and there is no winner.


Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the i-th person is equal to ai.Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard?

The first line of the input contains two integers n and h (1 ≤ n ≤ 1000, 1 ≤ h ≤ 1000) — the number of friends and the height of the fence, respectively. The second line contains n integers ai (1 ≤ ai ≤ 2h), the i-th of them is equal to the height of the i-th person.

Print a single integer — the minimum possible valid width of the road.

NoteIn the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4.In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough.In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2 + 2 + 2 + 2 + 2 + 1 = 11.

my (undef, $h) = split ' ', <>;
my @a = split ' ', <>;

print scalar(@a + grep { $_ > $h } @a), "\n";

#!/usr/bin/perl
use strict;
my $data = <STDIN>;
my $array =<STDIN>;
my @data_p = split(' ',$data);
my @array_p=split(' ', $array);
my ($n , $h) = @data_p;
my $sum = 0;
foreach my $item (@array_p)
{
    if ( $item > $h )
    {
        $sum = $sum + 2 ;
    }
    else
    {
        $sum = $sum + 1 ;
    }
}
print $sum;

#!/usr/bin/env perl

use strict;
use warnings;
use feature qw/ say /;

# essential
my @tokens = ();

sub ceil {
    my $n = shift;
    my $in = int($n);
    return $n if $in == $n;
    return $in + 1;
}

sub read_line {
    chomp (my $line = <STDIN>);
    return $line;
}

sub read_token {
    @tokens = split q{ }, read_line() if @tokens == 0;
    return shift @tokens;
}

sub min {
    my @numbers = @_;
    my $min = shift @numbers;
    for ( @numbers ) {
        $min = $min<$_ ? $min : $_;
    }
    return $min;
}

sub max {
    my @numbers = @_;
    my $max = shift @numbers;
    for ( @numbers ) {
        $max = $max > $_ ? $max : $_;
    }
    return $max;
}

sub sum {
    my @numbers = @_;
    my $sum = 0;
    for (@numbers) {
        $sum += $_;
    }
    return $sum;
}

# solve

my $n = read_token;
my $h = read_token;

my @talls = split q{ }, read_line;

my $answer = $n;

for (@talls) {
    $answer++ if $_ > $h;
}

say $answer;

(undef, $h) = split ' ', <>;
$sum += 1 + ($_ > $h) for split ' ', <>;
print $sum

(undef, $h) = split ' ', <>;
$sum += 1 + ($_ * 2 > $h) for split ' ', <>;
print $sum


You are given two sequences $$$a_1, a_2, \dots, a_n$$$ and $$$b_1, b_2, \dots, b_n$$$. Each element of both sequences is either $$$0$$$, $$$1$$$ or $$$2$$$. The number of elements $$$0$$$, $$$1$$$, $$$2$$$ in the sequence $$$a$$$ is $$$x_1$$$, $$$y_1$$$, $$$z_1$$$ respectively, and the number of elements $$$0$$$, $$$1$$$, $$$2$$$ in the sequence $$$b$$$ is $$$x_2$$$, $$$y_2$$$, $$$z_2$$$ respectively.You can rearrange the elements in both sequences $$$a$$$ and $$$b$$$ however you like. After that, let's define a sequence $$$c$$$ as follows:$$$c_i = \begin{cases} a_i b_i & \mbox{if }a_i > b_i \\ 0 & \mbox{if }a_i = b_i \\ -a_i b_i & \mbox{if }a_i < b_i \end{cases}$$$You'd like to make $$$\sum_{i=1}^n c_i$$$ (the sum of all elements of the sequence $$$c$$$) as large as possible. What is the maximum possible sum?

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains three integers $$$x_1$$$, $$$y_1$$$, $$$z_1$$$ ($$$0 \le x_1, y_1, z_1 \le 10^8$$$) — the number of $$$0$$$-s, $$$1$$$-s and $$$2$$$-s in the sequence $$$a$$$. The second line of each test case also contains three integers $$$x_2$$$, $$$y_2$$$, $$$z_2$$$ ($$$0 \le x_2, y_2, z_2 \le 10^8$$$; $$$x_1 + y_1 + z_1 = x_2 + y_2 + z_2 > 0$$$) — the number of $$$0$$$-s, $$$1$$$-s and $$$2$$$-s in the sequence $$$b$$$.

For each test case, print the maximum possible sum of the sequence $$$c$$$.


You are given an array of $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$. You can make the following operation: choose an integer $$$x \geq 2$$$ and replace each number of the array by the remainder when dividing that number by $$$x$$$, that is, for all $$$1 \leq i \leq n$$$ set $$$a_i$$$ to $$$a_i \bmod x$$$.Determine if it is possible to make all the elements of the array equal by applying the operation zero or more times.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 10^9$$$) where $$$a_i$$$ is the $$$i$$$-th element of the array. The sum of $$$n$$$ for all test cases is at most $$$2 \cdot 10^5$$$.

For each test case, print a line with YES if you can make all elements of the list equal by applying the operation. Otherwise, print NO. You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as a positive answer).

NoteIn the first test case, one can apply the operation with $$$x = 3$$$ to obtain the array $$$[2, 2, 0, 2]$$$, and then apply the operation with $$$x = 2$$$ to obtain $$$[0, 0, 0, 0]$$$.In the second test case, all numbers are already equal.In the fourth test case, applying the operation with $$$x = 4$$$ results in the array $$$[1, 1, 1, 1]$$$.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

while(<>){
	@_ = split ' ', <>;

	my %h;

	map $h{ $_ } ++, @_;

	if( $h{ 1 } and $h{ 0 } || $h{ 2 } ){
		print "NO";
		}
	else{
		print "YES";
		}
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

while(<>){
	@_ = split ' ', <>;

	if( ( grep $_ == 1, @_ ) and ( grep $_ % 2 == 0, @_ ) ){
		print "NO";
		}
	else{
		print "YES";
		}

	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

while(<>){
	@_ = split ' ', <>;

	if( ( grep $_ == 0, @_ ) and ( grep $_ == 1, @_ ) ){
		print "NO";
		}
	else{
		print "YES";
		}

	}


Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the grid has hands either on his mouth or his eyes.  They play for q rounds. In each round, Mike chooses a bear (i, j) and tells him to change his state i. e. if his hands are on his mouth, then he'll put his hands on his eyes or he'll put his hands on his mouth otherwise. After that, Mike wants to know the score of the bears.Score of the bears is the maximum over all rows of number of consecutive bears with hands on their eyes in that row.Since bears are lazy, Mike asked you for help. For each round, tell him the score of these bears after changing the state of a bear selected in that round.

The first line of input contains three integers n, m and q (1 ≤ n, m ≤ 500 and 1 ≤ q ≤ 5000). The next n lines contain the grid description. There are m integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next q lines contain the information about the rounds. Each of them contains two integers i and j (1 ≤ i ≤ n and 1 ≤ j ≤ m), the row number and the column number of the bear changing his state.

After each round, print the current score of the bears.


Polycarpus has a hobby — he develops an unusual social network. His work is almost completed, and there is only one more module to implement — the module which determines friends. Oh yes, in this social network one won't have to add friends manually! Pairs of friends are deduced in the following way. Let's assume that user A sent user B a message at time t1, and user B sent user A a message at time t2. If 0 < t2 - t1 ≤ d, then user B's message was an answer to user A's one. Users A and B are considered to be friends if A answered at least one B's message or B answered at least one A's message.You are given the log of messages in chronological order and a number d. Find all pairs of users who will be considered to be friends.

The first line of the input contains two integers n and d (1 ≤ n, d ≤ 1000). The next n lines contain the messages log. The i-th line contains one line of the log formatted as "Ai Bi ti" (without the quotes), which means that user Ai sent a message to user Bi at time ti (1 ≤ i ≤ n). Ai and Bi are non-empty strings at most 20 characters long, consisting of lowercase letters ('a' ... 'z'), and ti is an integer (0 ≤ ti ≤ 10000). It is guaranteed that the lines are given in non-decreasing order of ti's and that no user sent a message to himself. The elements in the lines are separated by single spaces.

In the first line print integer k — the number of pairs of friends. In the next k lines print pairs of friends as "Ai Bi" (without the quotes). You can print users in pairs and the pairs themselves in any order. Each pair must be printed exactly once.

4 1
vasya petya 1
petya vasya 2
anya ivan 2
ivan anya 4

NoteIn the first sample test case Vasya and Petya are friends because their messages' sending times are one second apart. Anya and Ivan are not, because their messages' sending times differ by more than one second.


One very important person has a piece of paper in the form of a rectangle a × b.Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees).A very important person wants to choose two different seals and put them two impressions. Each of the selected seals puts exactly one impression. Impressions should not overlap (but they can touch sides), and the total area occupied by them should be the largest possible. What is the largest area that can be occupied by two seals?

The first line contains three integer numbers n, a and b (1 ≤ n, a, b ≤ 100). Each of the next n lines contain two numbers xi, yi (1 ≤ xi, yi ≤ 100).

Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.

NoteIn the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper.In the second example you can't choose the last seal because it doesn't fit. By choosing the first and the third seals you occupy the largest area.In the third example there is no such pair of seals that they both can fit on a piece of paper.

# reads a line and parses it
sub rd {
    my $v = <STDIN>;
    chomp ( $v );
    my @arr = (split m/ /, $v);
    return @arr;
}

sub max {
    return ($_[0] > $_[1] ? $_[0] : $_[1]); }

my ($n, $a, $b) = &rd;

# it only two seals
# so no dp

my @seals;
my @x, @y;
my $one, $two;
for ( my $i =0 ; $i < $n; $i += 1 ) {
    ($one, $two) = &rd;
    push @x, $one;
    push @y, $two;}

my $max_area = 0;

my $o, $p, $q, $r;
my $area = 0;
for ( my $i =0 ; $i < $n-1; $i += 1 ) {

    for ( my $j = $i + 1 ; $j < $n; $j += 1 ) {
	$o = $x[ $i ];
	$p = $y[ $i ];
	$q = $x[ $j ];
	$r = $y[ $j ];

	# pay attention to operator precedence
	# or parenthesize the shit out of everything
	if ( (($o + $p <= $a) and (&max ( $q, $r ) <= $b)) or
	     (($o + $p <= $b) and (&max ( $q, $r ) <= $a)) ) {
	    $area = ($o * $p) + ($q * $r);}
	elsif ( (($o + $r <= $a) and (&max ( $p, $q ) <= $b)) ||
		(($o + $r <= $b) and (&max ( $p, $q ) <= $a)) ) {
	    $area = ($o * $p) + ($q * $r);}
	elsif ( (($p + $q <= $a) and (&max ( $o, $r ) <= $b)) ||
		(($p + $q <= $b) and (&max ( $o, $r ) <= $a)) ) {
	    $area = ($o * $p) + ($q * $r);}
	elsif ( (($p + $r <= $a) and (&max ( $o, $q ) <= $b)) ||
		(($p + $r <= $b) and (&max ( $o, $q ) <= $a)) ) {
	    $area = ($o * $p) + ($q * $r);}

	if ( $area > $max_area ) {
	    $max_area = $area; }
    }
}

print $max_area;
print "\n";


Shaass has decided to hunt some birds. There are n horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to n from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are ai oskols sitting on the i-th wire.  Sometimes Shaass shots one of the birds and the bird dies (suppose that this bird sat at the i-th wire). Consequently all the birds on the i-th wire to the left of the dead bird get scared and jump up on the wire number i - 1, if there exists no upper wire they fly away. Also all the birds to the right of the dead bird jump down on wire number i + 1, if there exists no such wire they fly away. Shaass has shot m birds. You're given the initial number of birds on each wire, tell him how many birds are sitting on each wire after the shots.

The first line of the input contains an integer n, (1 ≤ n ≤ 100). The next line contains a list of space-separated integers a1, a2, ..., an, (0 ≤ ai ≤ 100).  The third line contains an integer m, (0 ≤ m ≤ 100). Each of the next m lines contains two integers xi and yi. The integers mean that for the i-th time Shaass shoot the yi-th (from left) bird on the xi-th wire, (1 ≤ xi ≤ n, 1 ≤ yi). It's guaranteed there will be at least yi birds on the xi-th wire at that moment.

On the i-th line of the output print the number of birds on the i-th wire.


Tanya wants to go on a journey across the cities of Berland. There are $$$n$$$ cities situated along the main railroad line of Berland, and these cities are numbered from $$$1$$$ to $$$n$$$. Tanya plans her journey as follows. First of all, she will choose some city $$$c_1$$$ to start her journey. She will visit it, and after that go to some other city $$$c_2 > c_1$$$, then to some other city $$$c_3 > c_2$$$, and so on, until she chooses to end her journey in some city $$$c_k > c_{k - 1}$$$. So, the sequence of visited cities $$$[c_1, c_2, \dots, c_k]$$$ should be strictly increasing.There are some additional constraints on the sequence of cities Tanya visits. Each city $$$i$$$ has a beauty value $$$b_i$$$ associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities $$$c_i$$$ and $$$c_{i + 1}$$$, the condition $$$c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i}$$$ must hold.For example, if $$$n = 8$$$ and $$$b = [3, 4, 4, 6, 6, 7, 8, 9]$$$, there are several three possible ways to plan a journey:  $$$c = [1, 2, 4]$$$;  $$$c = [3, 5, 6, 8]$$$;  $$$c = [7]$$$ (a journey consisting of one city is also valid). There are some additional ways to plan a journey that are not listed above.Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?

The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of cities in Berland. The second line contains $$$n$$$ integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ ($$$1 \le b_i \le 4 \cdot 10^5$$$), where $$$b_i$$$ is the beauty value of the $$$i$$$-th city.

Print one integer — the maximum beauty of a journey Tanya can choose.

NoteThe optimal journey plan in the first example is $$$c = [2, 4, 5]$$$.The optimal journey plan in the second example is $$$c = [1]$$$.The optimal journey plan in the third example is $$$c = [3, 6]$$$.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

while(<>){
	@_ = split ' ', <>;

	my %h;

	my $i = 0;

	for( @_ ){
		push @{ $h{ $_ - $i } }, $_;
		$i ++;
		}

	my @cand;

	push @cand, eval join ' + ', @{ $h{ $_ } } for sort keys %h;

	print 0 + ( sort { $b <=> $a } @cand )[ 0 ];
	}


You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*"). You have one bomb. If you lay the bomb at the cell (x, y), then after triggering it will wipe out all walls in the row x and all walls in the column y.You are to determine if it is possible to wipe out all walls in the depot by placing and triggering exactly one bomb. The bomb can be laid both in an empty cell or in a cell occupied by a wall.

The first line contains two positive integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and columns in the depot field.  The next n lines contain m symbols "." and "*" each — the description of the field. j-th symbol in i-th of them stands for cell (i, j). If the symbol is equal to ".", then the corresponding cell is empty, otherwise it equals "*" and the corresponding cell is occupied by a wall.

If it is impossible to wipe out all walls by placing and triggering exactly one bomb, then print "NO" in the first line (without quotes). Otherwise print "YES" (without quotes) in the first line and two integers in the second line — the coordinates of the cell at which the bomb should be laid. If there are multiple answers, print any of them.


Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company. Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend to feel poor compared to somebody else in the company (Kefa doesn't count). A friend feels poor if in the company there is someone who has at least d units of money more than he does. Also, Kefa wants the total friendship factor of the members of the company to be maximum. Help him invite an optimal company!

The first line of the input contains two space-separated integers, n and d (1 ≤ n ≤ 105, ) — the number of Kefa's friends and the minimum difference between the amount of money in order to feel poor, respectively. Next n lines contain the descriptions of Kefa's friends, the (i + 1)-th line contains the description of the i-th friend of type mi, si (0 ≤ mi, si ≤ 109) — the amount of money and the friendship factor, respectively.

Print the maximum total friendship factir that can be reached.

NoteIn the first sample test the most profitable strategy is to form a company from only the second friend. At all other variants the total degree of friendship will be worse.In the second sample test we can take all the friends.


Alexey is travelling on a train. Unfortunately, due to the bad weather, the train moves slower that it should!Alexey took the train at the railroad terminal. Let's say that the train starts from the terminal at the moment $$$0$$$. Also, let's say that the train will visit $$$n$$$ stations numbered from $$$1$$$ to $$$n$$$ along its way, and that Alexey destination is the station $$$n$$$.Alexey learned from the train schedule $$$n$$$ integer pairs $$$(a_i, b_i)$$$ where $$$a_i$$$ is the expected time of train's arrival at the $$$i$$$-th station and $$$b_i$$$ is the expected time of departure.Also, using all information he has, Alexey was able to calculate $$$n$$$ integers $$$tm_1, tm_2, \dots, tm_n$$$ where $$$tm_i$$$ is the extra time the train need to travel from the station $$$i - 1$$$ to the station $$$i$$$. Formally, the train needs exactly $$$a_i - b_{i-1} + tm_i$$$ time to travel from station $$$i - 1$$$ to station $$$i$$$ (if $$$i = 1$$$ then $$$b_0$$$ is the moment the train leave the terminal, and it's equal to $$$0$$$).The train leaves the station $$$i$$$, if both conditions are met:   it's on the station for at least $$$\left\lceil \frac{b_i - a_i}{2} \right\rceil$$$ units of time (division with ceiling);  current time $$$\ge b_i$$$. Since Alexey spent all his energy on prediction of time delays, help him to calculate the time of arrival at the station $$$n$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains the single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of stations. Next $$$n$$$ lines contain two integers each: $$$a_i$$$ and $$$b_i$$$ ($$$1 \le a_i < b_i \le 10^6$$$). It's guaranteed that $$$b_i < a_{i+1}$$$.  Next line contains $$$n$$$ integers $$$tm_1, tm_2, \dots, tm_n$$$ ($$$0 \le tm_i \le 10^6$$$).

For each test case, print one integer — the time of Alexey's arrival at the last station.

NoteIn the first test case, Alexey arrives at station $$$1$$$ without any delay at the moment $$$a_1 = 2$$$ (since $$$tm_1 = 0$$$). After that, he departs at moment $$$b_1 = 4$$$. Finally, he arrives at station $$$2$$$ with $$$tm_2 = 2$$$ extra time, or at the moment $$$12$$$.In the second test case, Alexey arrives at the first station with $$$tm_1 = 1$$$ extra time, or at moment $$$2$$$. The train, from one side, should stay at the station at least $$$\left\lceil \frac{b_1 - a_1}{2} \right\rceil = 2$$$ units of time and from the other side should depart not earlier than at moment $$$b_1 = 4$$$. As a result, the trains departs right at the moment $$$4$$$.Using the same logic, we can figure out that the train arrives at the second station at the moment $$$9$$$ and departs at the moment $$$10$$$; at the third station: arrives at $$$14$$$ and departs at $$$15$$$; at the fourth: arrives at $$$22$$$ and departs at $$$23$$$. And, finally, arrives at the fifth station at $$$32$$$.


Vanya is managed to enter his favourite site Codehorses. Vanya uses n distinct passwords for sites at all, however he can't remember which one exactly he specified during Codehorses registration.Vanya will enter passwords in order of non-decreasing their lengths, and he will enter passwords of same length in arbitrary order. Just when Vanya will have entered the correct password, he is immediately authorized on the site. Vanya will not enter any password twice.Entering any passwords takes one second for Vanya. But if Vanya will enter wrong password k times, then he is able to make the next try only 5 seconds after that. Vanya makes each try immediately, that is, at each moment when Vanya is able to enter password, he is doing that.Determine how many seconds will Vanya need to enter Codehorses in the best case for him (if he spends minimum possible number of second) and in the worst case (if he spends maximum possible amount of seconds).

The first line of the input contains two integers n and k (1 ≤ n, k ≤ 100) — the number of Vanya's passwords and the number of failed tries, after which the access to the site is blocked for 5 seconds. The next n lines contains passwords, one per line — pairwise distinct non-empty strings consisting of latin letters and digits. Each password length does not exceed 100 characters. The last line of the input contains the Vanya's Codehorses password. It is guaranteed that the Vanya's Codehorses password is equal to some of his n passwords.

Print two integers — time (in seconds), Vanya needs to be authorized to Codehorses in the best case for him and in the worst case respectively.

NoteConsider the first sample case. As soon as all passwords have the same length, Vanya can enter the right password at the first try as well as at the last try. If he enters it at the first try, he spends exactly 1 second. Thus in the best case the answer is 1. If, at the other hand, he enters it at the last try, he enters another 4 passwords before. He spends 2 seconds to enter first 2 passwords, then he waits 5 seconds as soon as he made 2 wrong tries. Then he spends 2 more seconds to enter 2 wrong passwords, again waits 5 seconds and, finally, enters the correct password spending 1 more second. In summary in the worst case he is able to be authorized in 15 seconds.Consider the second sample case. There is no way of entering passwords and get the access to the site blocked. As soon as the required password has length of 2, Vanya enters all passwords of length 1 anyway, spending 2 seconds for that. Then, in the best case, he immediately enters the correct password and the answer for the best case is 3, but in the worst case he enters wrong password of length 2 and only then the right one, spending 4 seconds at all.

$\ = $/;

while(<>){
	($n, $k) = split;
	@_ = ();
	for (1 .. $n){
		push @_, ~~<>;
		}
	chomp(@_);
	chomp( $psw = <> );
	$len_psw = length $psw;
	$short = grep { $len_psw >  length } @_;
	$equal = grep { $len_psw == length } @_;

	print join ' ', map {
		$_ + 5 * int( ($_-1) / $k)
		} $short + 1, $short + $equal;
	}

($n, $k) = split ' ', <>;
($L, @_) = reverse map length, <>;

$short = grep { $L > $_ } @_;

print join ' ', map {
	$_ + 5 * int ~- $_ / $k
	} $short + 1, $short + grep { $L == $_ } @_

$\ = $/;

while(<>){
	($n, $k) = split;
	@_ = ();
	for (1 .. $n){
		push @_, ~~<>;
		}
	chomp(@_);
	chomp( $psw = <> );
	$len_psw = length $psw;
	$short = grep { $len_psw >  length } @_;
	$equal = grep { $len_psw == length } @_;

	print join ' ', map {
		$_ + 5 * int $_ / $k
		} $short + 1, $short + $equal;
	}


One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.Please, check the guess of Alex. You are given descriptions of n laptops. Determine whether two described above laptops exist.

The first line contains an integer n (1 ≤ n ≤ 105) — the number of laptops. Next n lines contain two integers each, ai and bi (1 ≤ ai, bi ≤ n), where ai is the price of the i-th laptop, and bi is the number that represents the quality of the i-th laptop (the larger the number is, the higher is the quality). All ai are distinct. All bi are distinct.

If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).

my $T=<>;
chomp($T);
my %DATA;
while($T--){
my ($a,$b)=split(/ /,<>);
chomp($a,$b);
$DATA{$b}=$a;
}
my @S=map { $DATA{$_} } sort { $a <=> $b } keys %DATA;
for(0..@S-2){
if($S[$_] > $S[$_+1]){
print  "Happy Alex \n";
exit(0);
}
}
print  "Poor Alex\n";

#!/usr/bin/env perl -w
use strict;
use warnings;

my $n = <>;
chomp $n;

my @laps;

for (1..$n) {
    my $l = <>;
    chomp $l;
    $l =~ /^(\d+) (\d+)$/;

    push(@laps, [int($1), int($2)]);
}

@laps = sort {
if ($a->[0] < $b->[0]) {
    return -1;
} elsif ($a->[0] == $b->[0]) {
    if ($a->[1] < $b->[1]) {
        return -1;
    } elsif ($a->[1] == $b->[1]) {
        return 0;
    } else {
        return 1;
    }
} else {
    return 1;
}
} @laps;

for (my $i = 1; $i <= $#laps; $i++) {
    if ($laps[$i-1]->[1] > $laps[$i]->[1]) {
            print "Happy Alex\n";
            exit 0;
    }
}

print "Poor Alex\n";

my $T=<>;
chomp($T);
my %DATA;
while($T--){
my ($a,$b)=split(/ /,<>);
chomp($a,$b);
$DATA{$b}=$a;
}
my @S=map { $DATA{$_} } sort { $a <=> $b } keys %DATA;
for(0..@S-2){
if($S[$_] > $S[$_+1]){
print  "Happy Alex \n";
last;
}
}
print  "Poor Alex\n";

my $T=<>;
chomp($T);
my %DATA;
while($T--){
my ($a,$b)=split(/ /,<>);
chomp($a,$b);
$DATA{$b}=$a;
}
my @S=map { $DATA{$_} } sort { $a <=> $b } keys %DATA;
for(0..@S-2){
if($S[$_] > $S[$_+1]){
print  "Happy Alex \n";
}
}
print  "Poor Alex\n";

#!/usr/bin/env perl -w
use strict;
use warnings;

my $n = <>;
chomp $n;

my @laps;

for (1..$n) {
    my $l = <>;
    chomp $l;
    $l =~ /^(\d+) (\d+)$/;

    push(@laps, [$1, $2]);
}

@laps = sort { $a->[0] cmp $b->[0] } @laps;

for (my $i = 0; $i <= $#laps; $i++) {
    for (my $j = 0; $j < $i; $j++) {
        if ($laps[$i]->[1] < $laps[$j]->[1]) {
            print "Happy Alex\n";
            exit 0;
        }
    }
}

print "Poor Alex\n";

#!/usr/bin/env perl -w
use strict;
use warnings;

my $n = <>;
chomp $n;

my @laps;

for (1..$n) {
    my $l = <>;
    chomp $l;
    $l =~ /^(\d+) (\d+)$/;

    push(@laps, [$1, $2]);
}

@laps = sort { $a->[0] cmp $b->[0] } @laps;

my $max = $laps[$#laps]->[1];
my $cost = $laps[$#laps]->[0];

for (my $i = $#laps-1; $i >= 0; $i--) {
    if ($laps[$i]->[0] < $cost && $laps[$i]->[1] > $max) {
            print "Happy Alex\n";
            exit 0;
    }
}

print "Poor Alex\n";

#!/usr/bin/env perl -w
use strict;
use warnings;

my $n = <>;
chomp $n;

my (@a, @b);

for (1..$n) {
    my $l = <>;
    chomp $l;
    $l =~ /^(\d+) (\d+)$/;

    push(@a, $1);
    push(@b, $2);
}

@a = sort @a;
@b = sort @b;

for (my $i = 0; $i <= $#a; $i++) {
    if ($a[$i] != $b[$i]) {
        print "Poor Alex\n";
        exit 0;
    }
}

print "Happy Alex\n";

#!/usr/bin/env perl -w
use strict;
use warnings;

my $n = <>;
chomp $n;

my @laps;

for (1..$n) {
    my $l = <>;
    chomp $l;
    $l =~ /^(\d+) (\d+)$/;

    push(@laps, [int($1), int($2)]);
}

@laps = sort {
if ($a->[0] <= $b->[0]) {
    if ($a->[1] < $b->[1]) {
        return 1;
    } elsif ($a->[1] == $b->[1]) {
        return 0;
    } else {
        return -1;
    }
} else {
    return 1;
}
} @laps;

for (my $i = 1; $i <= $#laps; $i++) {
    if ($laps[$i-1]->[1] > $laps[$i]->[1]) {
            print "Happy Alex\n";
            exit 0;
    }
}

print "Poor Alex\n";

#!/usr/bin/env perl -w
use strict;
use warnings;

my $n = <>;
chomp $n;

my @laps;

for (1..$n) {
    my $l = <>;
    chomp $l;
    $l =~ /^(\d+) (\d+)$/;

    push(@laps, [$1, $2]);
}

@laps = sort { $a->[0] cmp $b->[0] } @laps;

for (my $i = 0; $i <= $#laps; $i++) {
    for (my $j = $i; $j <= $#laps; $j++) {
        if ($laps[$i]->[1] > $laps[$j]->[1]) {
            print "Happy Alex\n";
            exit 0;
        }
    }
}

print "Poor Alex\n";

#!/usr/bin/env perl -w
use strict;
use warnings;

my $n = <>;
chomp $n;

my @laps;

for (1..$n) {
    my $l = <>;
    chomp $l;
    $l =~ /^(\d+) (\d+)$/;

    push(@laps, [int($1), int($2)]);
}

@laps = sort {
if ($a->[0] <= $b->[0]) {
    if ($a->[1] < $b->[1]) {
        return 1;
    } elsif ($a->[1] == $b->[1]) {
        return 0;
    } else {
        return -1;
    }
} else {
    return 1;
}
} @laps;

my $max = $laps[$#laps]->[1];
my $cost = $laps[$#laps]->[0];

for (my $i = $#laps-1; $i >= 0; $i--) {
    if ($laps[$i]->[0] < $cost && $laps[$i]->[1] > $max) {
            print "Happy Alex\n";
            exit 0;
    }
}

use Data::Dumper;
print Dumper(\@laps);

print "Poor Alex\n";

#!/usr/bin/env perl -w
use strict;
use warnings;

my $n = <>;
chomp $n;

my @laps;

for (1..$n) {
    my $l = <>;
    chomp $l;
    $l =~ /^(\d+) (\d+)$/;

    push(@laps, [int($1), int($2)]);
}

@laps = sort {
if ($a->[0] <= $b->[0]) {
    if ($a->[1] < $b->[1]) {
        return 1;
    } elsif ($a->[1] == $b->[1]) {
        return 0;
    } else {
        return -1;
    }
} else {
    return 1;
}
} @laps;

my $max = $laps[$#laps]->[1];
my $cost = $laps[$#laps]->[0];

for (my $i = $#laps-1; $i >= 0; $i--) {
    if ($laps[$i]->[0] < $cost && $laps[$i]->[1] > $max) {
            print "Happy Alex\n";
            exit 0;
    }
}

print "Poor Alex\n";


A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but strings "abb" and "ij" are not.You are given string s consisting of lowercase Latin letters. At once you can choose any position in the string and change letter in that position to any other lowercase letter. So after each changing the length of the string doesn't change. At first you can change some letters in s. Then you can permute the order of letters as you want. Permutation doesn't count as changes. You should obtain palindrome with the minimal number of changes. If there are several ways to do that you should get the lexicographically (alphabetically) smallest palindrome. So firstly you should minimize the number of changes and then minimize the palindrome lexicographically.

The only line contains string s (1 ≤ |s| ≤ 2·105) consisting of only lowercase Latin letters.

Print the lexicographically smallest palindrome that can be obtained with the minimal number of changes.


A Martian boy is named s — he has got this name quite recently from his parents for his coming of age birthday. Now he enjoys looking for his name everywhere. If he sees that he can obtain his name from some string by removing zero or more letters (at that, the remaining letters remain in the same order), he gets happy. For example, if s=«aba», then strings «baobab», «aabbaa», «helloabahello» make him very happy and strings «aab», «baaa» and «helloabhello» do not.However rather than being happy once, he loves twice as much being happy twice! So, when he got string t as a present, he wanted to cut it in two parts (the left part and the right part) so that each part made him happy.Help s determine the number of distinct ways to cut the given string t into two parts in the required manner.

The first line contains string s, consisting of lowercase English letters. The length of string s is from 1 to 1000 letters. The second line contains string t, that also consists of lowercase English letters. The length of string t is from 1 to 106 letters.

Print the sought number of ways to cut string t in two so that each part made s happy.

#!/usr/bin/env perl

my $s = readline(*STDIN);
my $t = readline(*STDIN);
chomp($s);
chomp($t);
$s =~ tr/a-zA-Z//dc;
$t =~ tr/a-zA-Z//dc;
# print "s: $s\tt: $t\n";
my $start_pos = 0;
my $end_pos = length($t);
# print "start:$start_pos\tend:$end_pos\n";
while ( $s =~ m/([a-z])/g && $start_pos>=0 ) {
    $start_pos = index($t, $1, $start_pos);
    # print "$1\tstart_pos:$start_pos\n";
    $start_pos++;
}

$s = scalar reverse $s;
while ( $s =~ m/([a-z])/g && $end_pos>=0 ) {
    $end_pos = rindex($t, $1, $end_pos);
    # print "$1\tend_pos:$end_pos\n";
    $end_pos--;
}
$start_pos--;
$end_pos++;
# print "start:$start_pos\tend:$end_pos\n";
if ($end_pos >= $start_pos && $start_pos >= 0) {
	print $end_pos - $start_pos . "\n";
}
else
{
	print "0\n";
}

#!/usr/bin/env perl

my $s = readline(*STDIN);
my $t = readline(*STDIN);
chomp($s);
chomp($t);
my $start_pos = 0;
my $end_pos = 0;
while ( $s =~ m/(\S)/g) {
    $start_pos = index($t, $1, $start_pos);
}

$s = scalar reverse $s;
$end_pos = length($t);
while ( $s =~ m/(\S)/g) {
    $end_pos = rindex($t, $1, $end_pos);
}
if ($end_pos >= $start_pos && $start_pos >= 0) {
	print $end_pos- $start_pos . "\n";
}
else
{
	print "0\n";
}


Bob is playing a game named "Walk on Matrix".In this game, player is given an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$, i.e. the element in the $$$i$$$-th row in the $$$j$$$-th column is $$$a_{i,j}$$$. Initially, player is located at position $$$(1,1)$$$ with score $$$a_{1,1}$$$. To reach the goal, position $$$(n,m)$$$, player can move right or down, i.e. move from $$$(x,y)$$$ to $$$(x,y+1)$$$ or $$$(x+1,y)$$$, as long as player is still on the matrix.However, each move changes player's score to the bitwise AND of the current score and the value at the position he moves to.Bob can't wait to find out the maximum score he can get using the tool he recently learnt  — dynamic programming. Here is his algorithm for this problem.   However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix $$$A$$$. Thus, for any given non-negative integer $$$k$$$, he wants to find out an $$$n \times m$$$ matrix $$$A=(a_{i,j})$$$ such that   $$$1 \le n,m \le 500$$$ (as Bob hates large matrix);  $$$0 \le a_{i,j} \le 3 \cdot 10^5$$$ for all $$$1 \le i\le n,1 \le j\le m$$$ (as Bob hates large numbers);  the difference between the maximum score he can get and the output of his algorithm is exactly $$$k$$$. It can be shown that for any given integer $$$k$$$ such that $$$0 \le k \le 10^5$$$, there exists a matrix satisfying the above constraints.Please help him with it!

The only line of the input contains one single integer $$$k$$$ ($$$0 \le k \le 10^5$$$).

Output two integers $$$n$$$, $$$m$$$ ($$$1 \le n,m \le 500$$$) in the first line, representing the size of the matrix.  Then output $$$n$$$ lines with $$$m$$$ integers in each line, $$$a_{i,j}$$$ in the $$$(i+1)$$$-th row, $$$j$$$-th column.

NoteIn the first example, the maximum score Bob can achieve is $$$300000$$$, while the output of his algorithm is $$$300000$$$.In the second example, the maximum score Bob can achieve is $$$7\&3\&3\&3\&7\&3=3$$$, while the output of his algorithm is $$$2$$$.


It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of n distinct integers. And then they take turns to make the following moves. During each move, either Alice or Bob (the player whose turn is the current) can choose two distinct integers x and y from the set, such that the set doesn't contain their absolute difference |x - y|. Then this player adds integer |x - y| to the set (so, the size of the set increases by one).If the current player has no valid move, he (or she) loses the game. The question is who will finally win the game if both players play optimally. Remember that Alice always moves first.

The first line contains an integer n (2 ≤ n ≤ 100) — the initial number of elements in the set. The second line contains n distinct space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the elements of the set.

Print a single line with the winner's name. If Alice wins print "Alice", otherwise print "Bob" (without quotes).

NoteConsider the first test sample. Alice moves first, and the only move she can do is to choose 2 and 3, then to add 1 to the set. Next Bob moves, there is no valid move anymore, so the winner is Alice.

use List::Util qw/max/;
my $n = <>;
my @num = split ' ', <>;
my $max = max(@num);
my $d = shift @num;
while (@num) {
    my $b = shift @num;
    ($d, $b) = ($b, $d%$b) while $b;
}
my $new = $max/$d - $n;
print $new%2==1 ? 'Alice' : 'Bob';


One day Jeff got hold of an integer sequence a1, a2, ..., an of length n. The boy immediately decided to analyze the sequence. For that, he needs to find all values of x, for which these conditions hold:  x occurs in sequence a.  Consider all positions of numbers x in the sequence a (such i, that ai = x). These numbers, sorted in the increasing order, must form an arithmetic progression. Help Jeff, find all x that meet the problem conditions.

The first line contains integer n (1 ≤ n ≤ 105). The next line contains integers a1, a2, ..., an (1 ≤ ai ≤ 105). The numbers are separated by spaces.

In the first line print integer t — the number of valid x. On each of the next t lines print two integers x and px, where x is current suitable value, px is the common difference between numbers in the progression (if x occurs exactly once in the sequence, px must equal 0). Print the pairs in the order of increasing x.

NoteIn the first test 2 occurs exactly once in the sequence, ergo p2 = 0.


Polycarp has a checkered sheet of paper of size n × m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.

The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the sizes of the sheet. The next n lines contain m letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.

Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.

NoteIn the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.In the third example all cells are colored white, so it's sufficient to color any cell black.


You've got an array a, consisting of n integers: a1, a2, ..., an. Your task is to find a minimal by inclusion segment [l, r] (1 ≤ l ≤ r ≤ n) such, that among numbers al,  al + 1,  ...,  ar there are exactly k distinct numbers.Segment [l, r] (1 ≤ l ≤ r ≤ n; l, r are integers) of length m = r - l + 1, satisfying the given property, is called minimal by inclusion, if there is no segment [x, y] satisfying the property and less then m in length, such that 1 ≤ l ≤ x ≤ y ≤ r ≤ n. Note that the segment [l, r] doesn't have to be minimal in length among all segments, satisfying the given property.

The first line contains two space-separated integers: n and k (1 ≤ n, k ≤ 105). The second line contains n space-separated integers a1, a2, ..., an — elements of the array a (1 ≤ ai ≤ 105).

Print a space-separated pair of integers l and r (1 ≤ l ≤ r ≤ n) such, that the segment [l, r] is the answer to the problem. If the sought segment does not exist, print "-1 -1" without the quotes. If there are multiple correct answers, print any of them.

NoteIn the first sample among numbers a1 and a2 there are exactly two distinct numbers.In the second sample segment [2, 5] is a minimal by inclusion segment with three distinct numbers, but it is not minimal in length among such segments.In the third sample there is no segment with four distinct numbers.

use strict;
use warnings;
my %hash     = ();
my $distinct = 0;
chomp(my ( $n, $k ) = split( " ", <STDIN> ));
chomp(my @array = split( " ", <STDIN> ));
for my $elt (@array) {
    if ( not exists $hash{$elt} ) {
        $distinct++;
        $hash{$elt}++;
    }
}

if ( $distinct < $k ) {
    print "-1 -1";
    exit;
}

my $first = $array[0];

my %hash2     = ($first => 1);

my $distinct2 = 1;
my $start     = 0;
my $end       = 0;
for ( my $i = 1 ; $i < @array ; $i++ ) {
    if ( $distinct2 == $k ) {
        last;
    }
    $end = $i;
    if ( not exists $hash2{ $array[$i] } ) {
        $hash2{ $array[$i] }++;
        $distinct2++;
    }
    #print "d = $distinct2, k = $k, start = $start, end = $end\n";

    if ( $array[$i] == $array[$start] ) {
        $start++;
    }
}
#print "$start $end\n";
my $found = 1;
while ($found) {
    my $count = 0;
    for ( my $i = $start ; $i <= $end ; $i++ ) {
        if ( $i != $start && $array[$i] == $array[$start] ) {
            $count++;
            $start++;
        }
        if ($i != $end && $array[$i] == $array[$end] ) {
            $count++;
            $end--;
        }
    }
    if ( $count == 0 ) { $found = 0; }
}

$start++;
$end++;
print "$start $end";

use strict;
use warnings;
my %hash     = ();
my $distinct = 0;
chomp(my ( $n, $k ) = split( " ", <STDIN> ));
chomp(my @array = split( " ", <STDIN> ));
for my $elt (@array) {
    if ( not exists $hash{$elt} ) {
        $distinct++;
        $hash{$elt}++;
    }
}

if ( $distinct < $k ) {
    print "-1 -1";
    exit;
}

my $first = $array[0];

my %hash2     = ($first => 1);

my $distinct2 = 1;
my $start     = 0;
my $end       = 0;
for ( my $i = 1 ; $i < @array ; $i++ ) {
    $end = $i;
    if ( not exists $hash2{ $array[$i] } ) {
        $hash2{ $array[$i] }++;
        $distinct2++;
    }
    print "d = $distinct2, k = $k, start = $start, end = $end\n";
    if ( $distinct2 == $k ) {
        last;
    }
    if ( $array[$i] == $array[$start] ) {
        $start++;
    }
}
print "$start $end\n";
my $found = 1;
while ($found) {
    my $count = 0;
    for ( my $i = $start ; $i <= $end ; $i++ ) {
        if ( $i != $start && $array[$i] == $array[$start] ) {
            $count++;
            $start++;
        }
        if ($i != $end && $array[$i] == $array[$end] ) {
            $count++;
            $end--;
        }
    }
    if ( $count == 0 ) { $found = 0; }
}

$start++;
$end++;
print "$start $end";

use strict;
use warnings;
my %hash     = ();
my $distinct = 0;
chomp(my ( $n, $k ) = split( " ", <STDIN> ));
chomp(my @array = split( " ", <STDIN> ));
for my $elt (@array) {
    if ( not exists $hash{$elt} ) {
        $distinct++;
        $hash{$elt}++;
    }
}

if ( $distinct < $k ) {
    print "-1 -1";
    exit;
}

my $first = $array[0];

my %hash2     = ($first => 1);

my $distinct2 = 1;
my $start     = 0;
my $end       = 0;
for ( my $i = 1 ; $i < @array ; $i++ ) {
    $end = $i;
    if ( not exists $hash2{ $array[$i] } ) {
        $hash2{ $array[$i] }++;
        $distinct2++;
    }
    #print "d = $distinct2, k = $k, start = $start, end = $end\n";
    if ( $distinct2 == $k ) {
        last;
    }
    if ( $array[$i] == $array[$start] ) {
        $start++;
    }
}
#print "$start $end\n";
my $found = 1;
while ($found) {
    my $count = 0;
    for ( my $i = $start+1 ; $i <= $end ; $i++ ) {
        if ( $array[$i] == $array[$start] ) {
            $count++;
            $start++;
        }
    }
    if ( $count == 0 ) { $found = 0; }
}

$start++;
$end++;
print "$start $end";

use strict;
use warnings;
my %hash     = ();
my $distinct = 0;
chomp(my ( $n, $k ) = split( " ", <STDIN> ));
chomp(my @array = split( " ", <STDIN> ));
for my $elt (@array) {
    if ( not exists $hash{$elt} ) {
        $distinct++;
        $hash{$elt}++;
    }
}

if ( $distinct < $k ) {
    print "-1 -1";
    exit;
}

my $first = $array[0];

my %hash2     = ($first => 1);

my $distinct2 = 1;
my $start     = 0;
my $end       = 0;
for ( my $i = 1 ; $i < @array ; $i++ ) {
    $end = $i;
    if ( not exists $hash2{ $array[$i] } ) {
        $hash2{ $array[$i] }++;
        $distinct2++;
    }
    #print "d = $distinct2, k = $k, start = $start, end = $end\n";
    if ( $distinct2 == $k ) {
        last;
    }
    if ( $array[$i] == $array[$start] ) {
        $start++;
    }
}
#print "$start $end\n";
my $found = 1;
while ($found) {
    my $count = 0;
    for ( my $i = $start ; $i <= $end ; $i++ ) {
        if ( $i != $start && $array[$i] == $array[$start] ) {
            $count++;
            $start++;
        }
        if ($i != $end && $array[$i] == $array[$end] ) {
            $count++;
            $end--;
        }
    }
    if ( $count == 0 ) { $found = 0; }
}

$start++;
$end++;
print "$start $end";

use strict;
use warnings;
my %hash     = ();
my $distinct = 0;
chomp(my ( $n, $k ) = split( " ", <STDIN> ));
chomp(my @array = split( " ", <STDIN> ));
for my $elt (@array) {
    if ( not exists $hash{$elt} ) {
        $distinct++;
        $hash{$elt}++;
    }
}

if ( $distinct < $k ) {
    print "-1 -1";
    exit;
}

my $first = $array[0];

my %hash2     = ($first => 1);

my $distinct2 = 1;
my $start     = 0;
my $end       = 0;
for ( my $i = 1 ; $i < @array ; $i++ ) {
    $end = $i;
    if ( not exists $hash2{ $array[$i] } ) {
        $hash2{ $array[$i] }++;
        $distinct2++;
    }
    #print "d = $distinct2, k = $k, start = $start, end = $end\n";
    if ( $distinct2 == $k ) {
        last;
    }
    if ( $array[$i] == $array[$start] ) {
        $start++;
    }
}
#print "$start $end\n";
my $found = 1;
while ($found) {
    my $count = 0;
    for ( my $i = $start+1 ; $i < $end ; $i++ ) {
        if ( $array[$i] == $array[$start] ) {
            $count++;
            $start++;
        }
        if ( $array[$i] == $array[$end] ) {
            $count++;
            $end--;
        }
    }
    if ( $count == 0 ) { $found = 0; }
}

$start++;
$end++;
print "$start $end";


You are given an integer $$$n$$$. In one move, you can either multiply $$$n$$$ by two or divide $$$n$$$ by $$$6$$$ (if it is divisible by $$$6$$$ without the remainder).Your task is to find the minimum number of moves needed to obtain $$$1$$$ from $$$n$$$ or determine if it's impossible to do that.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow.  The only line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 10^9$$$).

For each test case, print the answer — the minimum number of moves needed to obtain $$$1$$$ from $$$n$$$ if it's possible to do that or -1 if it's impossible to obtain $$$1$$$ from $$$n$$$.

NoteConsider the sixth test case of the example. The answer can be obtained by the following sequence of moves from the given integer $$$15116544$$$:  Divide by $$$6$$$ and get $$$2519424$$$;  divide by $$$6$$$ and get $$$419904$$$;  divide by $$$6$$$ and get $$$69984$$$;  divide by $$$6$$$ and get $$$11664$$$;  multiply by $$$2$$$ and get $$$23328$$$;  divide by $$$6$$$ and get $$$3888$$$;  divide by $$$6$$$ and get $$$648$$$;  divide by $$$6$$$ and get $$$108$$$;  multiply by $$$2$$$ and get $$$216$$$;  divide by $$$6$$$ and get $$$36$$$;  divide by $$$6$$$ and get $$$6$$$;  divide by $$$6$$$ and get $$$1$$$.


The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official languages. But the employees are willing to learn any number of official languages, as long as the company pays their lessons. A study course in one language for one employee costs 1 berdollar.Find the minimum sum of money the company needs to spend so as any employee could correspond to any other one (their correspondence can be indirect, i. e. other employees can help out translating).

The first line contains two integers n and m (2 ≤ n, m ≤ 100) — the number of employees and the number of languages. Then n lines follow — each employee's language list. At the beginning of the i-th line is integer ki (0 ≤ ki ≤ m) — the number of languages the i-th employee knows. Next, the i-th line contains ki integers — aij (1 ≤ aij ≤ m) — the identifiers of languages the i-th employee knows. It is guaranteed that all the identifiers in one list are distinct. Note that an employee may know zero languages. The numbers in the lines are separated by single spaces.

Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).

NoteIn the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.In the third sample employee 2 must learn language 2.

sub count_disjoint_sets {

    my $ds_ref = $_[0];
    my %count = ();
    for my $i (values %{ $ds_ref }) {
	$count { $i } = 1;
    }
    return (scalar (keys %count));
}

sub make_disjoint_sets {

    my ($e_ref, $l_ref, $ds_ref,
	$v_ref, $person, $id ) = @_;

    # return if we've already visited this person
    if ( exists $v_ref -> { $person } ) {
	return;
    }
    # mark visited
    $v_ref -> { $person } = 1;
    # add to dijoint set
    $ds_ref -> { $person } = $id;

    for my $i ( keys %{ $l_ref -> { $person } } ) {
	for my $j ( keys %{ $e_ref -> { $i } } ) {
	    &make_disjoint_sets ( $e_ref, $l_ref, $ds_ref,
				  $v_ref, $j, $id );
	}}
}

my $f = <STDIN>;
chomp ( $f );
my ($n, $m) = split m/ /, $f;

my %emp_of_langs;
my %langs_of_emp;
my @lst;
my $language_exists = 0;
my $val;
for my $i (1..$n) {
    $val = 0;
    @lst = ();
    $f = <STDIN>;
    chomp ( $f );
    @lst = split m/ /, $f;
    $val = shift @lst;
    if ( $val > 0 ) {
	$language_exists = 1;
    }
    for my $j (@lst) {
	$langs_of_emp{ $i }{ $j } = 1;
	$emp_of_langs{ $j }{ $i } = 1;
    }
}

my %ds = ();
my %visit = ();

# initialize disjoint set
for my $i (1..$n) {
    $ds { $i } = $i;
}

for my $i (1..$n) {
    &make_disjoint_sets ( \%emp_of_langs, \%langs_of_emp, \%ds,
			  \%visit, $i, $i );
}

my $answer = &count_disjoint_sets ( \%ds );

if ( not $language_exists ) {
    print $answer;
    print "\n";
}
else {
    print ($answer - 1);
    print "\n";
}

sub count_disjoint_sets {

    my $ds_ref = $_[0];
    my %count = ();
    for my $i (values %{ $ds_ref }) {
	$count { $i } = 1;
    }
    return (scalar (keys %count));
}

sub make_disjoint_sets {

    my ($e_ref, $l_ref, $ds_ref,
	$v_ref, $person, $id ) = @_;

    # return if we've already visited this person
    if ( exists $v_ref -> { $person } ) {
	return;
    }
    # mark visited
    $v_ref -> { $person } = 1;
    # add to dijoint set
    $ds_ref -> { $person } = $id;

    for my $i ( keys %{ $l_ref -> { $person } } ) {
	for my $j ( keys %{ $e_ref -> { $i } } ) {
	    &make_disjoint_sets ( $e_ref, $l_ref, $ds_ref,
				  $v_ref, $j, $id );
	}}
}

my $f = <STDIN>;
chomp ( $f );
my ($n, $m) = split m/ /, $f;

my %emp_of_langs;
my %langs_of_emp;
my @lst;
for my $i (1..$n) {
    @lst = ();
    $f = <STDIN>;
    chomp ( $f );
    @lst = split m/ /, $f;
    shift @lst;

    for my $j (@lst) {
	$langs_of_emp{ $i }{ $j } = 1;
	$emp_of_langs{ $j }{ $i } = 1;
    }
}

my %ds = ();
my %visit = ();

for my $i (1..$n) {
    &make_disjoint_sets ( \%emp_of_langs, \%langs_of_emp, \%ds,
			  \%visit, $i, $i );
}

my $answer = &count_disjoint_sets ( \%ds );

print ($answer - 1);
print "\n";


Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of days of the year from ai to bi. Of course, Famil Door wants to have as many friends celebrating together with him as possible.Far cars are as weird as Far Far Away citizens, so they can only carry two people of opposite gender, that is exactly one male and one female. However, Far is so far from here that no other transportation may be used to get to the party.Famil Door should select some day of the year and invite some of his friends, such that they all are available at this moment and the number of male friends invited is equal to the number of female friends invited. Find the maximum number of friends that may present at the party.

The first line of the input contains a single integer n (1 ≤ n ≤ 5000) — then number of Famil Door's friends. Then follow n lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers ai and bi (1 ≤ ai ≤ bi ≤ 366), providing that the i-th friend can come to the party from day ai to day bi inclusive.

Print the maximum number of people that may come to Famil Door's party.

NoteIn the first sample, friends 3 and 4 can come on any day in range [117, 128].In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140.


You are given a multiset (i. e. a set that can contain multiple equal integers) containing $$$2n$$$ integers. Determine if you can split it into exactly $$$n$$$ pairs (i. e. each element should be in exactly one pair) so that the sum of the two elements in each pair is odd (i. e. when divided by $$$2$$$, the remainder is $$$1$$$).

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1\leq t\leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1\leq n\leq 100$$$). The second line of each test case contains $$$2n$$$ integers $$$a_1,a_2,\dots, a_{2n}$$$ ($$$0\leq a_i\leq 100$$$) — the numbers in the set.

For each test case, print "Yes" if it can be split into exactly $$$n$$$ pairs so that the sum of the two elements in each pair is odd, and "No" otherwise. You can print each letter in any case.

NoteIn the first test case, a possible way of splitting the set is $$$(2,3)$$$, $$$(4,5)$$$.In the second, third and fifth test case, we can prove that there isn't any possible way.In the fourth test case, a possible way of splitting the set is $$$(2,3)$$$.


You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible.Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset.

First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers. Second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the numbers in the multiset.

If it is not possible to select k numbers in the desired way, output «No» (without the quotes). Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b1, b2, ..., bk — the selected numbers. If there are multiple possible solutions, print any of them.


Lord Omkar has permitted you to enter the Holy Church of Omkar! To test your worthiness, Omkar gives you a password which you must interpret!A password is an array $$$a$$$ of $$$n$$$ positive integers. You apply the following operation to the array: pick any two adjacent numbers that are not equal to each other and replace them with their sum. Formally, choose an index $$$i$$$ such that $$$1 \leq i < n$$$ and $$$a_{i} \neq a_{i+1}$$$, delete both $$$a_i$$$ and $$$a_{i+1}$$$ from the array and put $$$a_{i}+a_{i+1}$$$ in their place. For example, for array $$$[7, 4, 3, 7]$$$ you can choose $$$i = 2$$$ and the array will become $$$[7, 4+3, 7] = [7, 7, 7]$$$. Note that in this array you can't apply this operation anymore.Notice that one operation will decrease the size of the password by $$$1$$$. What is the shortest possible length of the password after some number (possibly $$$0$$$) of operations?

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the length of the password. The second line of each test case contains $$$n$$$ integers $$$a_{1},a_{2},\dots,a_{n}$$$ ($$$1 \leq a_{i} \leq 10^9$$$) — the initial contents of your password. The sum of $$$n$$$ over all test cases will not exceed $$$2 \cdot 10^5$$$.

For each password, print one integer: the shortest possible length of the password after some number of operations.

NoteIn the first test case, you can do the following to achieve a length of $$$1$$$:Pick $$$i=2$$$ to get $$$[2, 4, 1]$$$Pick $$$i=1$$$ to get $$$[6, 1]$$$Pick $$$i=1$$$ to get $$$[7]$$$In the second test case, you can't perform any operations because there is no valid $$$i$$$ that satisfies the requirements mentioned above.

use strict;
use v5.020;
my $try = <>;
while($try-- > 0){
    my $n = int(<>);
    my @arr = split(' ', <>);
    my ($first, $firstCnt) = ($arr[0], 1);
    shift @arr;
    while(@arr > 0){
        if($first == shift(@arr)){
            $firstCnt += 1;
        }
    }
    if($n == $firstCnt){
        say "$n";
    } else {
        say "1";
    }
}


This is an easier version of the problem. In this version $$$n \le 1000$$$The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the company has already bought $$$n$$$ plots along the highway and is preparing to build $$$n$$$ skyscrapers, one skyscraper per plot.Architects must consider several requirements when planning a skyscraper. Firstly, since the land on each plot has different properties, each skyscraper has a limit on the largest number of floors it can have. Secondly, according to the design code of the city, it is unacceptable for a skyscraper to simultaneously have higher skyscrapers both to the left and to the right of it.Formally, let's number the plots from $$$1$$$ to $$$n$$$. Then if the skyscraper on the $$$i$$$-th plot has $$$a_i$$$ floors, it must hold that $$$a_i$$$ is at most $$$m_i$$$ ($$$1 \le a_i \le m_i$$$). Also there mustn't be integers $$$j$$$ and $$$k$$$ such that $$$j < i < k$$$ and $$$a_j > a_i < a_k$$$. Plots $$$j$$$ and $$$k$$$ are not required to be adjacent to $$$i$$$.The company wants the total number of floors in the built skyscrapers to be as large as possible. Help it to choose the number of floors for each skyscraper in an optimal way, i.e. in such a way that all requirements are fulfilled, and among all such construction plans choose any plan with the maximum possible total number of floors.

The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of plots. The second line contains the integers $$$m_1, m_2, \ldots, m_n$$$ ($$$1 \leq m_i \leq 10^9$$$) — the limit on the number of floors for every possible number of floors for a skyscraper on each plot.

Print $$$n$$$ integers $$$a_i$$$ — the number of floors in the plan for each skyscraper, such that all requirements are met, and the total number of floors in all skyscrapers is the maximum possible. If there are multiple answers possible, print any of them.

NoteIn the first example, you can build all skyscrapers with the highest possible height.In the second test example, you cannot give the maximum height to all skyscrapers as this violates the design code restriction. The answer $$$[10, 6, 6]$$$ is optimal. Note that the answer of $$$[6, 6, 8]$$$ also satisfies all restrictions, but is not optimal.


Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way possible.

The first line contains an integer N (1 ≤ N ≤ 1000) — the number of bars at Vasya’s disposal. The second line contains N space-separated integers li — the lengths of the bars. All the lengths are natural numbers not exceeding 1000.

In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars.

<>;
my %hash;
my $max  = 0;
for(split / /, <>) {
    $hash{int$_}++;
    $max = $hash{int$_} if ($hash{int$_} > $max);
}
print ($max . " " . scalar keys %hash);

#!/usr/bin/perl
use v5.10;

chomp($n = <>);
$tb{int($_)}++ foreach (split / /, <>);
@a = keys %tb;
($mx, $ans) = (0, scalar @a);
$mx=$mx>$tb{$_} ? $mx:$tb{$_} foreach (@a);
say "$mx $ans";


The integers shop sells $$$n$$$ segments. The $$$i$$$-th of them contains all integers from $$$l_i$$$ to $$$r_i$$$ and costs $$$c_i$$$ coins.Tomorrow Vasya will go to this shop and will buy some segments there. He will get all integers that appear in at least one of bought segments. The total cost of the purchase is the sum of costs of all segments in it.After shopping, Vasya will get some more integers as a gift. He will get integer $$$x$$$ as a gift if and only if all of the following conditions are satisfied:   Vasya hasn't bought $$$x$$$.  Vasya has bought integer $$$l$$$ that is less than $$$x$$$.  Vasya has bought integer $$$r$$$ that is greater than $$$x$$$. Vasya can get integer $$$x$$$ as a gift only once so he won't have the same integers after receiving a gift.For example, if Vasya buys segment $$$[2, 4]$$$ for $$$20$$$ coins and segment $$$[7, 8]$$$ for $$$22$$$ coins, he spends $$$42$$$ coins and receives integers $$$2, 3, 4, 7, 8$$$ from these segments. He also gets integers $$$5$$$ and $$$6$$$ as a gift.Due to the technical issues only the first $$$s$$$ segments (that is, segments $$$[l_1, r_1], [l_2, r_2], \ldots, [l_s, r_s]$$$) will be available tomorrow in the shop.Vasya wants to get (to buy or to get as a gift) as many integers as possible. If he can do this in differents ways, he selects the cheapest of them.For each $$$s$$$ from $$$1$$$ to $$$n$$$, find how many coins will Vasya spend if only the first $$$s$$$ segments will be available.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The first line of each test case contains the single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of segments in the shop. Each of next $$$n$$$ lines contains three integers $$$l_i$$$, $$$r_i$$$, $$$c_i$$$ ($$$1 \leq l_i \leq r_i \leq 10^9, 1 \leq c_i \leq 10^9$$$) — the ends of the $$$i$$$-th segments and its cost. It is guaranteed that the total sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$.

For each test case output $$$n$$$ integers: the $$$s$$$-th ($$$1 \leq s \leq n$$$) of them should be the number of coins Vasia will spend in the shop if only the first $$$s$$$ segments will be available.

NoteIn the first test case if $$$s = 1$$$ then Vasya can buy only the segment $$$[2, 4]$$$ for $$$20$$$ coins and get $$$3$$$ integers.The way to get $$$7$$$ integers for $$$42$$$ coins in case $$$s = 2$$$ is described in the statement.In the second test case note, that there can be the same segments in the shop.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

while(<>){
	my( $min, $max, $c ) = split ' ', <>;

	my $minC = $c;
	my $minCL = $c;
	my $minCR = $c;

	my $switch = 1;

	my @ans = $minC;

	for my $i ( 1 .. $_ - 1 ){
		my( $L, $R, $cc ) = split ' ', <>;

		if( $L > $min and $R < $max ){
			push @ans, $ans[ @ans - 1 ];
			}
		elsif( $L == $min and $R == $max ){
			if( $switch == 1 ){
				$cc < $minC and $minC = $cc;
				}
			else{
				$minC = $cc;
				}
			$cc < $minCL and $minCL = $cc;
			$cc < $minCR and $minCR = $cc;
			if( $minC < $minCL + $minCR ){
				push @ans, $minC;
				$switch = 1;
				}
			else{
				push @ans, $minCL + $minCR;
				$switch = 0;
				}
			}
		elsif( $L < $min and $R > $max ){
			$switch = 1;
			$minC = $cc;
			$minCL = $cc;
			$minCR = $cc;
			push @ans, $minC;
			$min = $L;
			$max = $R;
			}
		elsif( $L < $min and $R == $max ){
			$switch = 1;
			$minC = $cc;
			$minCL = $cc;
			$cc < $minCR and $minCR = $cc;
			push @ans, $minC;
			$min = $L;
			}
		elsif( $L == $min and $R > $max ){
			$switch = 1;
			$minC = $cc;
			$minCR = $cc;
			$cc < $minCL and $minCL = $cc;
			push @ans, $minC;
			$max = $R;
			}
		elsif( $L < $min and $R < $max ){
			$switch = 0;
			$minCL = $cc;
			$min = $L;
			push @ans, $minCL + $minCR;
			}
		elsif( $L > $min and $R > $max ){
			$switch = 0;
			$minCR = $cc;
			$max = $R;
			push @ans, $minCL + $minCR;
			}
		elsif( $L == $min and $R < $max ){
			$cc < $minCL and $minCL = $cc;
			if( $switch == 1 and $minC < $minCL + $minCR ){
				push @ans, $minC;
				}
			else{
				$switch = 0;
				push @ans, $minCL + $minCR;
				}
			}
		elsif( $L > $min and $R == $max ){
			$cc < $minCR and $minCR = $cc;
			if( $switch == 1 and $minC < $minCL + $minCR ){
				push @ans, $minC;
				}
			else{
				$switch = 0;
				push @ans, $minCL + $minCR;
				}
			}
		}

	print join "\n", @ans;
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

while(<>){
	my( $min, $max, $c ) = split ' ', <>;

	my $minC = $c;
	my $minCL = $c;
	my $minCR = $c;

	my $switch = 1;

	my @ans = $minC;

	for my $i ( 1 .. $_ - 1 ){
		my( $L, $R, $cc ) = split ' ', <>;

		if( $L > $min and $R < $max ){
			push @ans, $ans[ @ans - 1 ];
			}
		elsif( $L == $min and $R == $max ){
			$cc < $minC and $minC = $cc;
			$cc < $minCL and $minCL = $cc;
			$cc < $minCR and $minCR = $cc;
			if( $minC < $minCL + $minCR ){
				push @ans, $minC;
				$switch = 1;
				}
			else{
				push @ans, $minCL + $minCR;
				$switch = 0;
				}
			}
		elsif( $L < $min and $R > $max ){
			$switch = 1;
			$minC = $cc;
			$minCL = $cc;
			$minCR = $cc;
			push @ans, $minC;
			$min = $L;
			$max = $R;
			}
		elsif( $L < $min and $R == $max ){
			$switch = 1;
			$minC = $cc;
			$minCL = $cc;
			$cc < $minCR and $minCR = $cc;
			push @ans, $minC;
			$min = $L;
			}
		elsif( $L == $min and $R > $max ){
			$switch = 1;
			$minC = $cc;
			$minCR = $cc;
			$cc < $minCL and $minCL = $cc;
			push @ans, $minC;
			$max = $R;
			}
		elsif( $L < $min and $R < $max ){
			$switch = 0;
			$minCL = $cc;
			$min = $L;
			push @ans, $minCL + $minCR;
			}
		elsif( $L > $min and $R > $max ){
			$switch = 0;
			$minCR = $cc;
			$max = $R;
			push @ans, $minCL + $minCR;
			}
		elsif( $L == $min and $R < $max ){
			$cc < $minCL and $minCL = $cc;
			if( $switch == 1 and $minC < $minCL + $minCR ){
				push @ans, $minC;
				}
			else{
				$switch = 0;
				push @ans, $minCL + $minCR;
				}
			}
		elsif( $L > $min and $R == $max ){
			$cc < $minCR and $minCR = $cc;
			if( $switch == 1 and $minC < $minCL + $minCR ){
				push @ans, $minC;
				}
			else{
				$switch = 0;
				push @ans, $minCL + $minCR;
				}
			}
		}

	print join "\n", @ans;
	}


Ashish has two strings $$$a$$$ and $$$b$$$, each of length $$$n$$$, and an integer $$$k$$$. The strings only contain lowercase English letters.He wants to convert string $$$a$$$ into string $$$b$$$ by performing some (possibly zero) operations on $$$a$$$.In one move, he can either   choose an index $$$i$$$ ($$$1 \leq i\leq n-1$$$) and swap $$$a_i$$$ and $$$a_{i+1}$$$, or  choose an index $$$i$$$ ($$$1 \leq i \leq n-k+1$$$) and if $$$a_i, a_{i+1}, \ldots, a_{i+k-1}$$$ are all equal to some character $$$c$$$ ($$$c \neq$$$ 'z'), replace each one with the next character $$$(c+1)$$$, that is, 'a' is replaced by 'b', 'b' is replaced by 'c' and so on. Note that he can perform any number of operations, and the operations can only be performed on string $$$a$$$. Help Ashish determine if it is possible to convert string $$$a$$$ into $$$b$$$ after performing some (possibly zero) operations on it.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^5$$$) — the number of test cases. The description of each test case is as follows. The first line of each test case contains two integers $$$n$$$ ($$$2 \leq n \leq 10^6$$$) and $$$k$$$ ($$$1 \leq k \leq n$$$). The second line of each test case contains the string $$$a$$$ of length $$$n$$$ consisting of lowercase English letters. The third line of each test case contains the string $$$b$$$ of length $$$n$$$ consisting of lowercase English letters. It is guaranteed that the sum of values $$$n$$$ among all test cases does not exceed $$$10^6$$$.

For each test case, print "Yes" if Ashish can convert $$$a$$$ into $$$b$$$ after some moves, else print "No". You may print the letters of the answer in any case (upper or lower).

4
3 3
abc
bcd
4 2
abba
azza
2 1
zz
aa
6 2
aaabba
ddddcc

NoteIn the first test case it can be shown that it is impossible to convert $$$a$$$ into $$$b$$$.In the second test case,"abba" $$$\xrightarrow{\text{inc}}$$$ "acca" $$$\xrightarrow{\text{inc}}$$$ $$$\ldots$$$ $$$\xrightarrow{\text{inc}}$$$ "azza".Here "swap" denotes an operation of the first type, and "inc" denotes an operation of the second type.In the fourth test case,"aaabba" $$$\xrightarrow{\text{swap}}$$$ "aaabab" $$$\xrightarrow{\text{swap}}$$$ "aaaabb" $$$\xrightarrow{\text{inc}}$$$ $$$\ldots$$$ $$$\xrightarrow{\text{inc}}$$$ "ddaabb" $$$\xrightarrow{\text{inc}}$$$ $$$\ldots$$$ $$$\xrightarrow{\text{inc}}$$$ "ddddbb" $$$\xrightarrow{\text{inc}}$$$ $$$\ldots$$$ $$$\xrightarrow{\text{inc}}$$$ "ddddcc".


A binary string is a string where each character is either 0 or 1. Two binary strings $$$a$$$ and $$$b$$$ of equal length are similar, if they have the same character in some position (there exists an integer $$$i$$$ such that $$$a_i = b_i$$$). For example:  10010 and 01111 are similar (they have the same character in position $$$4$$$);  10010 and 11111 are similar;  111 and 111 are similar;  0110 and 1001 are not similar. You are given an integer $$$n$$$ and a binary string $$$s$$$ consisting of $$$2n-1$$$ characters. Let's denote $$$s[l..r]$$$ as the contiguous substring of $$$s$$$ starting with $$$l$$$-th character and ending with $$$r$$$-th character (in other words, $$$s[l..r] = s_l s_{l + 1} s_{l + 2} \dots s_r$$$).You have to construct a binary string $$$w$$$ of length $$$n$$$ which is similar to all of the following strings: $$$s[1..n]$$$, $$$s[2..n+1]$$$, $$$s[3..n+2]$$$, ..., $$$s[n..2n-1]$$$.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 50$$$). The second line of each test case contains the binary string $$$s$$$ of length $$$2n - 1$$$. Each character $$$s_i$$$ is either 0 or 1.

For each test case, print the corresponding binary string $$$w$$$ of length $$$n$$$. If there are multiple such strings — print any of them. It can be shown that at least one string $$$w$$$ meeting the constraints always exists.

NoteThe explanation of the sample case (equal characters in equal positions are bold):The first test case:   $$$\mathbf{1}$$$ is similar to $$$s[1..1] = \mathbf{1}$$$. The second test case:   $$$\mathbf{000}$$$ is similar to $$$s[1..3] = \mathbf{000}$$$;  $$$\mathbf{000}$$$ is similar to $$$s[2..4] = \mathbf{000}$$$;  $$$\mathbf{000}$$$ is similar to $$$s[3..5] = \mathbf{000}$$$. The third test case:   $$$\mathbf{1}0\mathbf{10}$$$ is similar to $$$s[1..4] = \mathbf{1}1\mathbf{10}$$$;  $$$\mathbf{1}01\mathbf{0}$$$ is similar to $$$s[2..5] = \mathbf{1}10\mathbf{0}$$$;  $$$\mathbf{10}1\mathbf{0}$$$ is similar to $$$s[3..6] = \mathbf{10}0\mathbf{0}$$$;  $$$1\mathbf{0}1\mathbf{0}$$$ is similar to $$$s[4..7] = 0\mathbf{0}0\mathbf{0}$$$. The fourth test case:   $$$0\mathbf{0}$$$ is similar to $$$s[1..2] = 1\mathbf{0}$$$;  $$$\mathbf{0}0$$$ is similar to $$$s[2..3] = \mathbf{0}1$$$.