1 import java
.io
.BufferedReader
;
2 import java
.io
.FileReader
;
3 import java
.io
.PrintWriter
;
4 import java
.io
.IOException
;
7 public class kequiv_petr
implements Runnable
{
12 Segment(long l
, long r
) {
18 public boolean equals(Object o
) {
19 if (this == o
) return true;
20 if (o
== null || getClass() != o
.getClass()) return false;
22 Segment segment
= (Segment
) o
;
24 if (l
!= segment
.l
) return false;
25 if (r
!= segment
.r
) return false;
31 public int hashCode() {
32 int result
= (int) (l ^
(l
>>> 32));
33 result
= 31 * result
+ (int) (r ^
(r
>>> 32));
38 private void solve() throws IOException
{
40 Segment
[] segments
= new Segment
[n
];
41 for (int i
= 0; i
< n
; ++i
) {
44 segments
[i
] = new Segment(l
, r
);
46 boolean[][] diff
= new boolean[10][10];
48 for (int pos
= 0; pos
<= 18; ++pos
) {
49 oneStep(segments
, p10
, diff
);
52 boolean[] mark
= new boolean[10];
53 for (int i
= 1; i
< 10; ++i
)
55 for (int j
= 1; j
< 10; ++j
)
64 private void oneStep(Segment
[] segments
, long p10
, boolean[][] diff
) {
65 Map
<List
<Segment
>, List
<Integer
>> allDigits
= new HashMap
<List
<Segment
>, List
<Integer
>>();
66 for (int digit
= 1; digit
< 10; ++digit
) {
67 List
<Segment
> cur
= new ArrayList
<Segment
>();
68 for (Segment s
: segments
) {
69 long nl
= getNext(s
.l
, p10
, digit
);
70 long nr
= getNext(s
.r
+ 1, p10
, digit
) - 1;
72 if (cur
.size() > 0 && cur
.get(cur
.size() - 1).r
>= nl
- 1) {
73 cur
.set(cur
.size() - 1, new Segment(cur
.get(cur
.size() - 1).l
, nr
));
75 cur
.add(new Segment(nl
, nr
));
79 List
<Integer
> list
= allDigits
.get(cur
);
81 list
= new ArrayList
<Integer
>();
82 allDigits
.put(cur
, list
);
86 for (List
<Integer
> l1
: allDigits
.values())
87 for (List
<Integer
> l2
: allDigits
.values())
94 private long getNext(long l
, long p10
, int digit
) {
95 long cd
= l
/ p10
% 10;
97 return l
/ p10
/ 10 * p10
+ l
% p10
;
99 return l
/ p10
/ 10 * p10
;
101 return (l
/ p10
/ 10 + 1) * p10
;
105 public static void main(String
[] args
) throws InterruptedException
{
106 Thread thread
= new Thread(new kequiv_petr());
111 static final String TASK_ID
= "kequiv";
112 static final String IN_FILE
= TASK_ID
+ ".in";
113 static final String OUT_FILE
= TASK_ID
+ ".out";
114 BufferedReader reader
;
115 StringTokenizer tokenizer
;
120 reader
= new BufferedReader(new FileReader(IN_FILE
));
122 writer
= new PrintWriter(OUT_FILE
);
126 } catch (Exception e
) {
132 int nextInt() throws IOException
{
133 return Integer
.parseInt(nextToken());
136 long nextLong() throws IOException
{
137 return Long
.parseLong(nextToken());
140 double nextDouble() throws IOException
{
141 return Double
.parseDouble(nextToken());
144 String
nextToken() throws IOException
{
145 while (tokenizer
== null || !tokenizer
.hasMoreTokens()) {
146 tokenizer
= new StringTokenizer(reader
.readLine());
148 return tokenizer
.nextToken();