4 public class kequiv_al_trivial
{
5 static final int MaxN
= 10000;
6 static final long MaxAB
= (long)1e18
;
7 static final int PL
= 19;
9 static long rangeLong (long x
, long a
, long b
) {
10 if (x
< a
|| x
> b
) throw new RuntimeException (x
+ " is not in range " + a
+ ".." + b
);
14 static long rangeLong (String s
, long a
, long b
) {
15 return rangeLong (Long
.parseLong (s
), a
, b
);
18 static long myLong (String s
) {
19 if (s
.length () == 0) return 0; else return Long
.parseLong (s
);
23 static boolean [][] G
;
28 static void dfs (int x
) {
30 for (int j
= 1; j
<= 9; j
++)
31 if (C
[j
] == 0 && G
[x
][j
])
35 public static void main (String args
[]) throws Exception
{
36 BufferedReader in
= new BufferedReader (new FileReader ("kequiv.in"));
37 PrintWriter out
= new PrintWriter ("kequiv.out");
38 int n
= Integer
.parseInt (in
.readLine ());
39 rangeLong (n
, 1, MaxN
);
41 long [] a
= new long [n
], b
= new long [n
];
44 for (int i
= 0; i
< n
; i
++) {
45 StringTokenizer tok
= new StringTokenizer (in
.readLine ());
46 String as
= tok
.nextToken ();
47 String bs
= tok
.nextToken ();
48 a
[i
] = rangeLong (as
, last
+ 2, MaxAB
);
49 b
[i
] = rangeLong (bs
, a
[i
], MaxAB
);
50 if (tok
.hasMoreTokens ()) throw new Exception ("EOL expected");
53 if (in
.ready ()) throw new Exception ("EOF expected");
55 G
= new boolean [10][10];
57 for (int i
= 1; i
<= 9; i
++)
58 for (int j
= 1; j
<= 9; j
++)
61 for (int i
= 0; i
< n
; i
++) {
62 for (long x
= a
[i
]; x
<= b
[i
]; x
++) {
63 char [] c
= ("" + x
).toCharArray ();
64 for (int p
= 0; p
< c
.length
; p
++) {
67 for (int d
= 1; d
<= 9; d
++) {
68 c
[p
] = (char)(d
+ '0');
69 long y
= Long
.parseLong (new String (c
));
70 boolean found
= false;
71 for (int j
= 0; j
< n
; j
++) {
72 if (a
[j
] <= y
&& y
<= b
[j
]) {
77 if (G
[sav
- '0'][d
]) {
78 //System.out.println (x + " -> " + y + " blocks " + sav + " -> " + d);
80 G
[sav
- '0'][d
] = false;
81 G
[d
][sav
- '0'] = false;
93 for (int i
= 1; i
<= 9; i
++) {
100 for (int i
= 1; i
<= cc
; i
++) {
101 for (int j
= 1; j
<= 9; j
++) {