4 public class kequiv_md
{
5 private static String fileName
= kequiv_md
.class.getSimpleName().replaceFirst("_.*", "");
6 private static String inputFileName
= fileName
+ ".in";
7 private static String outputFileName
= fileName
+ ".out";
8 private static Scanner in
;
9 private static PrintWriter out
;
10 private final static int TEN
= 10;
13 ArrayList
<Long
> low
= new ArrayList
<Long
>();
14 ArrayList
<Long
> high
= new ArrayList
<Long
>();
17 public void add(long lo
, long hi
) {
24 public Intervals
setDigit(long ten
, int d
) {
25 Intervals that
= new Intervals();
26 for (int i
= 0; i
< low
.size(); i
++) {
27 that
.add(above(low
.get(i
), ten
, d
), above(high
.get(i
), ten
, d
));
29 return that
.normalize();
32 private Intervals
normalize() {
36 Intervals that
= new Intervals();
37 that
.low
.add(low
.get(0));
38 for (int i
= 0; i
< low
.size() - 1; i
++) {
39 if (high
.get(i
) < low
.get(i
+ 1)) {
40 that
.high
.add(high
.get(i
));
41 that
.low
.add(low
.get(i
+ 1));
44 that
.high
.add(high
.get(high
.size() - 1));
49 public boolean equals(Object obj
) {
50 Intervals that
= (Intervals
) obj
;
51 return low
.equals(that
.low
) && high
.equals(that
.high
);
55 public int hashCode() {
57 hash
= low
.hashCode() * 179 + high
.hashCode();
63 public Long
above(long n
, long ten
, int d
) {
65 int c
= (int) (a
% 10);
78 Intervals a
= new Intervals();
80 for (int i
= 0; i
< n
; i
++) {
81 a
.add(in
.nextLong(), in
.nextLong() + 1);
84 boolean[][] differ
= new boolean[TEN
][TEN
];
85 for (long ten
= 1; ten
< a
.high
.get(a
.high
.size() - 1) && ten
> 0; ten
*= TEN
) {
86 int[] val
= new int[TEN
];
87 HashMap
<Intervals
, Integer
> results
= new HashMap
<Intervals
, Integer
>();
88 for (int d
= 1; d
< TEN
; d
++) {
89 Intervals b
= a
.setDigit(ten
, d
);
90 Integer v
= results
.get(b
);
96 for (int e
= 1; e
< d
; e
++) {
97 if (val
[d
] != val
[e
]) {
104 boolean[] printed
= new boolean[TEN
];
105 for (int d
= 1; d
< TEN
; d
++) {
109 for (int e
= d
; e
< TEN
; e
++) {
119 public static void main(String
[] args
) throws IOException
{
120 Locale
.setDefault(Locale
.US
);
121 in
= new Scanner(new FileReader(inputFileName
));
122 out
= new PrintWriter(outputFileName
);
123 new kequiv_md().run();