2021 VI Интеллектуальная олимпиада ПФО среди школьников
A. Numbers (Div-2 only!)
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The most challenging exam for the students of the Recreational Mathematics Department is the exam in numeric shifts. Every year problems in this subject become more and more difficult. For the latest exam Professor Numberski has prepared something unbelievable.

The decimal notation of a certain number begins from a group of digits which will be denoted as B. In other words, the initial number is BX. If we multiply this number by A, the result of multiplication will be a number obtained by rewriting the group of digits B from the beginning to the end of the initial number, which means the final result of multiplication is XB.

The task of students is to find the minimal possible initial number BX based on given A and B.

Input

The only line contains two integers A and B (2 ≤ A ≤ 9, 1 ≤ B ≤ 106).

Output

The only number — solution of the task, or -1 if there is no solution.

Examples
Input
5 1
Output
-1
Input
3 1
Output
142857

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Alice and Bob are playing the next game. Both have same matrix N × M filled with digits from 0 to 9.

Alice cuts the matrix vertically, choose order of the columns, then links all the columns to each other to have the cyclic sequence of N × M digits. Note that she cannot rotate the columns, i.e. end of some column must be linked to beginning of the other column. Then she cuts a sequence and reads the decimal representation of integer A upside down.

Bob cuts the matrix horizontally, choose order of the rows, then link all the rows to each other to have the cyclic sequence of N × M digits. Note that he cannot rotate the rows, i.e. end of some row must be linked to beginning of the other row. Then he cuts a sequence and reads the decimal representation of integer B from left to right.

Player who obtained the biggest integer wins. If both integers are are equal, then game is tied. You are given the matrix, find the number obtained by winner (or by both players in case of tie), if both Alice and Bob are playing optimally.

Input

First line contains integers N and M (1 ≤ M, N ≤ 100).

Each of next N lines contains string of M digits (without the spaces or other delimiters inside) — the given matrix. You may assuma that atleast one digit in the matrix is not equal to 0.

Output

Print answer to the problem. Note that number must be printed without leading zeroes.

Example
B.
2 2
28
27
Output
8722

C. Synonymous Words Number System
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Synonymous Words Number System (SWNS) uses the lines of N characters consisting of '0' and '1' (2 ≤ N ≤ 10000). There is only one operation with words within the number system – it's called synonymization. Synonymization is reversing the character order in any substring containing even number of '1' symbols.

If we can create one word from the another one, by carrying out not more than 16·N synonymization, then such words are called synonyms.

It is necessary to determine whether the given words are synonymous, and, if so, find out the right sequence of synonymizations.

Input

Different words with a length of N characters are written in two lines, one per line.

Output

If the given words are not synonymous, output 'NO' in a single line.

Otherwise, output 'YES' in the first line. The second line contains an integer K (K ≤ 16·N) – a number of synonymization required for the conversion. The following K lines contain pairs of numbers that describe conversion of the first word into the second one. The first integer specifies a number of the first character participating in synonymization, and the second integer (always greater than the first one) – a number of the last character.

Examples
Input
110001111
111100011
Output
YES
1
3 7
Input
110
010
Output
NO

Statement is not available in English language
Statement is not available in English language
Statement is not available in English language
F. Зов Древних
ограничение по времени на тест
2 секунды
ограничение по памяти на тест
256 мегабайт
ввод
стандартный ввод
вывод
стандартный вывод

Это интерактивная задача.

Окутанный фантасмагоричными предзнаменованиями Вася взирает на безлунное небо. «Если бы я мог стать столь же чрезвычайно сияющим» — подумал Вася вглядевшись в звезду, и тут же получил зловещее предупреждение из древних глубин космоса. И тогда он понял, что сосредоточив свое невежественное сознание на некоторых звездах, можно услышать кошмарный зов неизвестного Древнего Бога.

Вспомнив знания, полученные из Некрономикона, Вася установил, что каждый из Древних имеет свой радиус влияния, и звезды находящиеся внутри радиуса отвечают зовом тому, кто в них вглядывается. Три Бога отравляют реальность своим противоестественным существованием: Азазот, с радиусом влияния 30 световых лет, Йог-Сотот с радиусом 20 и Шаб-Ниггурат с радиусом 10. Небо представляет собой координатную плоскость 100 на 100 световых лет, и на каждой целочисленной координате находится звезда. Вася может всматриваться в звезду с определенными координатами и понимать, находится ли она в радиусе влияния Древнего.

В данный момент пробудился только один Древний, то есть только вокруг него звезды отвечают на взор. Вася должен понять, какой из Древних пробудился и сказать его радиус, но сделать все это не более чем за N действий, иначе Вася сойдет с ума от переполняющего чудовищного познания.

Выходные данные

Выведите строку вида «! R», где R — радиус влияния пробужденного Древнего.

Протокол взаимодействия

Чтобы узнать находится ли звезда (X, Y) внутри зоны влияния Древнего, выведите в стандартный поток строку вида «? X Y», где X, Y — целые числа (0 ≤ X, Y ≤ 100). После этого выведите перевод строки и выполните операцию flush.

В ответ на запрос придет одно целое число: единица, если звезда находится внутри зоны влияния Древнего и ноль, если нет.

Чтобы вывести ответ на задачу, выведите строку вида «! R», где R — радиус влияния пробужденного Древнего.

Если вы сделаете более N запросов вида «? X Y» или сделаете некорректный запрос, решение получит вердикт «Неправильный ответ».

Если в какой-то момент ваша программа ничего не будет выводить или вы забудете выполнить операцию flush после вывода вопроса или ответа, решение получит вердикт «Решение зависло».

Чтобы выполнить операцию flush, можно использовать (сразу после вывода запроса и перевода строки):

  • fflush(stdout) в C++;
  • System.out.flush() в Java;
  • stdout.flush() в Python;
  • flush(output) в Pascal;
Система оценки

Баллы за каждую подзадачу начисляются только в случае, если все тесты для этой подзадачи и необходимых подзадач успешно пройдены.

ПодзадачаБаллыОграниченияНеобходимые подзадачиИнформация о проверке
[0.5ex] 125N = 10202полная
225103 ≤ N ≤ 5·1031полная
325300 ≤ N ≤ 5001,2полная
425N = 1011,2,3полная
Пример
Входные данные
1
0

Выходные данные
? 8 12
? 95 87
! 10

Statement is not available in English language
Statement is not available in English language