[Solution] Formalism for Formalism Codeforces Solution | Codeforces Problem Solution 2022
Yura is a mathematician, and his cognition of the world is so absolute as if he have been solving formal problems a hundred of trillions of billions of years. This problem is just that!
Consider all non-negative integers from the interval . For convenience we complement all numbers with leading zeros in such way that each number from the given interval consists of exactly decimal digits.
You are given a set of pairs , where and are distinct decimal digits from to .
Consider a number consisting of digits. We will enumerate all digits from left to right and denote them as . In one operation you can swap digits and if and only if there is a pair in the set such that at least one of the following conditions is satisfied:
- and ,
- and .
We will call the numbers and , consisting of digits, equivalent if the number can be transformed into the number using some number of operations described above. In particular, every number is considered equivalent to itself.
You are given an integer and a set of pairs of digits . You have to find the maximum integer such that there exists a set of integers () such that for each the number is not equivalent to the number .
The first line contains an integer () — the number of digits in considered numbers.
The second line contains an integer () — the number of pairs of digits in the set.
Each of the following lines contains two digits and , separated with a space ().
It's guaranteed that all described pairs are pairwise distinct.
Print one integer — the maximum value such that there exists a set of integers () such that for each the number is not equivalent to the number .
As the answer can be big enough, print the number modulo .
Join Now for Solution:-
No comments:
Post a Comment