fork(1) download
  1. /* An example of how to compile and use the checker:
  2.  * $ g++ checker.cpp -o checker
  3.  * $ checker < yourOutput.txt
  4.  *
  5.  * The checker reads the test case from the standard input (stdin) and
  6.  * prints an informative message with the results of the heuristics to
  7.  * the standard ouput (stdout).
  8.  *
  9.  *
  10.  * # Description of the solutions.
  11.  *
  12.  * 0. 'struct CorrectSolution' implements the intended solution using
  13.  * matroid intersection, which is described in the editorial of CNNCT2.
  14.  *
  15.  * 1. 'struct Solution1' implements the following randomized heuristic:
  16.  * a) Select a random permutation of the edges;
  17.  * b) Start with both graphs empty and consider the edges one by one
  18.  * in the selected order;
  19.  * c) If the considered edge can be added to both graphs without
  20.  * creating any cycles - add it, otherwise discard it;
  21.  * d) If at the end of the process 'k' edges were added to the
  22.  * graphs, update the answer with the value of '2 * n - 2 - k';
  23.  * e) Repeat steps (a) through (d) '30000000 / m' times and return
  24.  * the best (minimal) answer found.
  25.  *
  26.  * 2. 'struct Solution2' implements the following randomized heuristic:
  27.  * a) Select a random permutation of the edges;
  28.  * b) Start with both graphs empty and consider the edges one by one
  29.  * in the selected order;
  30.  * c) If the considered edge connects two different connected
  31.  * components in at least one of the graph - add it, otherwise
  32.  * discard it;
  33.  * d) Denote the list of added edges with 'L', preserving order;
  34.  * e) Consider each edge from the list 'L', if it is a bridge in at
  35.  * least of the graphs - move it to the beginning of the list 'L',
  36.  * otherwise leave it at its previous position;
  37.  * f) If the size of the list 'L' is 'k' and all the 'k' edges were
  38.  * moved during step (e), return 'k' as the answer;
  39.  * g) Otherwise, go back to step (b) using the list 'L' instead of
  40.  * the initial permutation generated during step (a);
  41.  * h) Repeat steps (a) through (g) until the total size of the graphs
  42.  * (vertices + edges) considered during step (b) reaches 20000000
  43.  * and return the best answer found;
  44.  *
  45.  * 3. 'struct Solution3' implements the following randomized heuristic:
  46.  * a) Start with a parameter 'ee = 1.0';
  47.  * b) Select a random permutation of the edges 'P';
  48.  * c) Execute steps (b) and (c) from the solution (1) using the per-
  49.  * mutation 'P' and denote the number of added edges with 'curr';
  50.  * d) Select a pair of permutation elements 'x' and 'y' at random;
  51.  * and swap the edges 'P[x]' and 'P[y]';
  52.  * e) Execute steps (b) and (c) from the solution (1) using the per-
  53.  * mutation 'P' and denote the number of added edges with 'cnt';
  54.  * f) If 'cnt > curr' go to step (i);
  55.  * g) Otherwise with probability 'pow(ee, curr - cnt)' go to step (i);
  56.  * h) Otherwise swap the edges 'P[x]' and 'P[y]' back and go to
  57.  * step (j);
  58.  * i) Update 'ee := ee * 0.991' and update the answer with the value
  59.  * '2 * n - 2 - cnt';
  60.  * j) Finish one iteration;
  61.  * k) Repeat the steps (c) through (j) '6000000 / m' times on each
  62.  * iteration using the permutations 'P' obtained after the
  63.  * previous iteration;
  64.  * l) Steps (a) through (k) are repeated 5 times and the best answer
  65.  * found is returned.
  66.  *
  67.  * 4. 'struct Solution4' implements the following randomized heuristic:
  68.  * a) Start with a parameter 'ee = 1.0';
  69.  * b) Select a random spanning tree in the first graph and consider
  70.  * these edges to be initially enabled and all other - disabled;
  71.  * c) Count the number of connected components in the second graph,
  72.  * including only enabled edges, and denote the count with 'curr';
  73.  * d) Choose an edge 'x' at random among currently disabled edges;
  74.  * e) Choose an edge 'y' at random from the path connecting the
  75.  * endpoints of 'x' in the tree formed by enabled edges;
  76.  * f) Mark edge 'x' as disabled and edge 'y' as enabled;
  77.  * g) Count the number of connected components in the second graph,
  78.  * including only enabled edges, and denote the count with 'cnt';
  79.  * h) If 'cnt < curr' go to step (k);
  80.  * i) Otherwise with probability 'pow(ee, cnt - curr)' go to step (k);
  81.  * j) Otherwise mark the edge 'x' as enabled and edge 'y' as disabled,
  82.  * reverting the step (f) and go to the step (l);
  83.  * k) Update 'ee := ee * 0.988' and update the answer with the value
  84.  * 'n - 1 + cnt - 1';
  85.  * l) Finish one iteration;
  86.  * m) Repeat the steps (c) through (l) '300000 / m' times on each
  87.  * itertion using the enabled edges obtained after the previous
  88.  * iteration;
  89.  * n) Steps (a) through (m) are repeated 50 times with the two graphs
  90.  * in their original order and 50 times with the graphs being
  91.  * swapped. The best answer found is returned.
  92.  */
  93.  
  94. #include <vector>
  95.  
  96. using namespace std;
  97.  
  98. extern "C" {
  99. int scanf(const char*, ...);
  100. int printf(const char*, ...);
  101. void exit(int);
  102. double pow(double, double);
  103. }
  104.  
  105. const unsigned seed = 0x12345678;
  106.  
  107. //////////////////////////////////////////////////////////////////////////
  108. // The part below is an exact copy from the checker used on the server! //
  109.  
  110. struct random_t {
  111. unsigned state;
  112. random_t() : state(seed) { }
  113. unsigned next() {
  114. state ^= state << 13;
  115. state ^= state >> 17;
  116. state ^= state << 5;
  117. return state;
  118. }
  119. void permute(int* permutation, int n) {
  120. for (int k = 0; k < n; k++) {
  121. permutation[k] = k;
  122. int p = next() % (k + 1);
  123. int tmp = permutation[p];
  124. permutation[p] = k;
  125. permutation[k] = tmp;
  126. }
  127. }
  128. };
  129.  
  130. const int MX = 300;
  131.  
  132. struct DSU {
  133. int p[MX];
  134.  
  135. void init(int n) {
  136. for (int i = 0; i < n; i++) p[i] = i;
  137. }
  138.  
  139. int get(int v) {
  140. if (p[v] != v) p[v] = get(p[v]);
  141. return p[v];
  142. }
  143.  
  144. void merge(int u, int v) {
  145. u = get(u);
  146. v = get(v);
  147. p[u] = v;
  148. }
  149. };
  150.  
  151. int n, m;
  152. int u1[MX], v1[MX], u2[MX], v2[MX];
  153.  
  154. struct Graph {
  155. int lastEdge[MX], ee;
  156. struct { int v, id, next; } e[2 * MX];
  157.  
  158. void init() {
  159. ee = 0;
  160. for (int i = 0; i < n; i++) lastEdge[i] = -1;
  161. }
  162.  
  163. void addEdge(int u, int v, int id) {
  164. e[ee].v = v;
  165. e[ee].id = id;
  166. e[ee].next = lastEdge[u];
  167. lastEdge[u] = ee++;
  168.  
  169. e[ee].v = u;
  170. e[ee].id = id;
  171. e[ee].next = lastEdge[v];
  172. lastEdge[v] = ee++;
  173. }
  174.  
  175. bool vis[MX];
  176. int up[MX], dep[MX];
  177. bool* bridge;
  178.  
  179. void dfs(int v, int edgeToParent, int depth) {
  180. vis[v] = true;
  181. dep[v] = depth;
  182. up[v] = depth;
  183. for (int i = lastEdge[v]; i != -1; i = e[i].next) {
  184. if (e[i].id == edgeToParent) continue;
  185.  
  186. int u = e[i].v;
  187. if (vis[u] == false) {
  188. dfs(u, e[i].id, depth + 1);
  189. if (up[u] > depth) bridge[e[i].id] = true;
  190. }
  191.  
  192. if (up[u] < up[v]) up[v] = up[u];
  193. }
  194. }
  195.  
  196. void markBridges(bool* isBridge) {
  197. for (int i = 0; i < n; i++) vis[i] = false;
  198.  
  199. bridge = isBridge;
  200. dfs(0, -1, 0);
  201. }
  202. };
  203.  
  204. int getBothAcyclic(int* permutation) {
  205. static DSU dsu1, dsu2;
  206.  
  207. dsu1.init(n);
  208. dsu2.init(n);
  209.  
  210. int cnt = 0;
  211. for (int i = 0; i < m; i++) {
  212. int e = permutation[i];
  213. int x1 = dsu1.get(u1[e]);
  214. int y1 = dsu1.get(v1[e]);
  215. if (x1 == y1) continue;
  216. int x2 = dsu2.get(u2[e]);
  217. int y2 = dsu2.get(v2[e]);
  218. if (x2 != y2) {
  219. cnt++;
  220. dsu1.merge(x1, y1);
  221. dsu2.merge(x2, y2);
  222. }
  223. }
  224.  
  225. return cnt;
  226. }
  227.  
  228. struct ExchangeGraph {
  229. vector<int> G[MX];
  230.  
  231. void clear() {
  232. for (int i = 0; i < m; i++) G[i].clear();
  233. }
  234.  
  235. void addEdge(int u, int v) {
  236. G[u].push_back(v);
  237. }
  238.  
  239. bool findAugmentalPath(vector<int> from, vector<int> to, bool* enabled) {
  240. vector<int> par(m, -1), dist(m), queue;
  241. for (size_t i = 0; i < from.size(); i++) {
  242. int v = from[i];
  243. queue.push_back(v);
  244. par[v] = -2;
  245. dist[v] = 0;
  246. }
  247.  
  248. for (size_t i = 0; i < queue.size(); i++) {
  249. int v = queue[i];
  250. for (size_t j = 0; j < G[v].size(); j++) {
  251. int u = G[v][j];
  252. if (par[u] == -1) {
  253. queue.push_back(u);
  254. par[u] = v;
  255. dist[u] = dist[v] + 1;
  256. }
  257. }
  258. }
  259.  
  260. int target = -1;
  261. for (size_t i = 0; i < to.size(); i++) {
  262. int v = to[i];
  263. if (par[v] == -1) continue;
  264. if (target == -1 || dist[v] < dist[target]) target = v;
  265. }
  266.  
  267. if (target != -1) {
  268. while (target != -2) {
  269. enabled[target] = not enabled[target];
  270. target = par[target];
  271. }
  272.  
  273. return true;
  274. }
  275.  
  276. return false;
  277. }
  278. };
  279.  
  280. struct CorrectSolution {
  281. ExchangeGraph exchangeGraph;
  282. bool enabled[MX];
  283.  
  284. int solve() {
  285. for (int i = 0; i < m; i++) enabled[i] = true;
  286.  
  287. int ans = m;
  288. while (true) {
  289. exchangeGraph.clear();
  290.  
  291. vector<int> Y1 = getNonBridges(u1, v1);
  292. vector<int> Y2 = getNonBridges(u2, v2);
  293.  
  294. if (exchangeGraph.findAugmentalPath(Y1, Y2, enabled)) {
  295. ans--;
  296. continue;
  297. }
  298.  
  299. for (int e = 0; e < m; e++) {
  300. if (enabled[e]) continue;
  301.  
  302. enabled[e] = true;
  303.  
  304. vector<int> edgesTo = getNonBridges(u1, v1);
  305. vector<int> edgesFrom = getNonBridges(u2, v2);
  306.  
  307. enabled[e] = false;
  308.  
  309. for (size_t i = 0; i < edgesTo.size(); i++) {
  310. exchangeGraph.addEdge(e, edgesTo[i]);
  311. }
  312. for (size_t i = 0; i < edgesFrom.size(); i++) {
  313. exchangeGraph.addEdge(edgesFrom[i], e);
  314. }
  315. }
  316.  
  317. if (exchangeGraph.findAugmentalPath(Y1, Y2, enabled)) {
  318. ans--;
  319. }
  320. else {
  321. break;
  322. }
  323. }
  324.  
  325. return ans;
  326. }
  327.  
  328. Graph G;
  329. bool isBridge[MX];
  330. vector<int> getNonBridges(int* u, int* v) {
  331. G.init();
  332. for (int i = 0; i < m; i++) {
  333. if (enabled[i]) {
  334. G.addEdge(u[i], v[i], i);
  335. isBridge[i] = false;
  336. }
  337. }
  338.  
  339. G.markBridges(isBridge);
  340.  
  341. vector<int> result;
  342. for (int i = 0; i < m; i++) {
  343. if (enabled[i] && isBridge[i] == false) {
  344. result.push_back(i);
  345. }
  346. }
  347.  
  348. return result;
  349. }
  350. };
  351.  
  352. struct Solution1 {
  353. int permutation[MX];
  354.  
  355. double solve(int correct) {
  356. const int limit = 30000000 / m;
  357.  
  358. random_t rnd;
  359. for (int it = 1; it <= limit; it++) {
  360. rnd.permute(permutation, m);
  361. int cnt = getBothAcyclic(permutation);
  362. int ans = 2 * (n - 1 - cnt) + cnt;
  363. if (ans == correct) return it / (double)limit;
  364. }
  365.  
  366. return -1;
  367. }
  368. };
  369.  
  370. struct Solution2 {
  371. int permutation[MX], selected[MX], timeSpent;
  372. bool isBridge[MX];
  373.  
  374. double solve(int correct) {
  375. const int limit = 20000000;
  376. timeSpent = 0;
  377.  
  378. random_t rnd;
  379.  
  380. while (timeSpent < limit) {
  381. rnd.permute(permutation, m);
  382. int ans = solveOne(m);
  383. if (ans == correct) return timeSpent / (double)limit;
  384. }
  385.  
  386. return -1;
  387. }
  388.  
  389. DSU dsu1, dsu2;
  390. int solveOne(int cnt) {
  391. timeSpent += n + cnt;
  392.  
  393. dsu1.init(n);
  394. dsu2.init(n);
  395.  
  396. int used = 0;
  397. for (int i = 0; i < cnt; i++) {
  398. int e = permutation[i];
  399. int x1 = dsu1.get(u1[e]);
  400. int y1 = dsu1.get(v1[e]);
  401. int x2 = dsu2.get(u2[e]);
  402. int y2 = dsu2.get(v2[e]);
  403. if (x1 != y1 || x2 != y2) {
  404. selected[used++] = e;
  405. isBridge[e] = false;
  406. dsu1.merge(x1, y1);
  407. dsu2.merge(x2, y2);
  408. }
  409. }
  410.  
  411. getBridges(used, u1, v1);
  412. getBridges(used, u2, v2);
  413.  
  414. int bridges = 0;
  415. for (int i = 0; i < used; i++) {
  416. int e = selected[i];
  417. if (isBridge[e]) {
  418. permutation[bridges++] = e;
  419. }
  420. }
  421.  
  422. for (int i = 0, j = bridges; i < used; i++) {
  423. int e = selected[i];
  424. if (isBridge[e] == false) {
  425. permutation[j++] = e;
  426. }
  427. }
  428.  
  429. if (bridges == used) return used;
  430. return solveOne(used);
  431. }
  432.  
  433. Graph G;
  434. void getBridges(int cnt, int* u, int* v) {
  435. G.init();
  436. for (int i = 0; i < cnt; i++) {
  437. int e = selected[i];
  438. G.addEdge(u[e], v[e], e);
  439. }
  440.  
  441. G.markBridges(isBridge);
  442. }
  443. };
  444.  
  445. struct Solution3 {
  446. random_t rnd;
  447.  
  448. double solve(int correct) {
  449. if (m == n - 1) return 0;
  450.  
  451. for (int it = 0; it < 5; it++) {
  452. double result = solveOne(correct);
  453. if (result < -0.5) continue;
  454. return (it + result) / 5;
  455. }
  456.  
  457. return -1;
  458. }
  459.  
  460. int permutation[MX];
  461. double solveOne(int correct) {
  462. const int limit = 6000000 / m;
  463.  
  464. rnd.permute(permutation, m);
  465.  
  466. double ee = 1.0;
  467. int best = getBothAcyclic(permutation), curr = best;
  468. for (int it = 1; it <= limit; it++) {
  469. int x, y;
  470. do {
  471. x = rnd.next() % m;
  472. y = rnd.next() % m;
  473. } while (x == y);
  474.  
  475. int tmp = permutation[x];
  476. permutation[x] = permutation[y];
  477. permutation[y] = tmp;
  478.  
  479. int cnt = getBothAcyclic(permutation);
  480. if (cnt > curr || rnd.next() < (1LL << 32) * pow(ee, curr - cnt)) {
  481. curr = cnt;
  482. ee *= 0.991;
  483. if (cnt > best) best = cnt;
  484. }
  485. else {
  486. tmp = permutation[x];
  487. permutation[x] = permutation[y];
  488. permutation[y] = tmp;
  489. }
  490.  
  491. int ans = 2 * (n - 1 - best) + best;
  492. if (ans == correct) return it / (double)limit;
  493. }
  494.  
  495. return -1;
  496. }
  497. };
  498.  
  499. struct Solution4 {
  500. random_t rnd;
  501.  
  502. double solve(int correct) {
  503. if (m == n - 1) return 0;
  504.  
  505. for (int it = 0; it < 100; it++) {
  506. double result = solveOne(correct, it < 50);
  507. if (result < -0.5) continue;
  508. return (it + result) / 100;
  509. }
  510.  
  511. return -1;
  512. }
  513.  
  514. int *u1, *v1, *u2, *v2;
  515. int permutation[MX];
  516. bool enabled[MX];
  517. DSU dsu;
  518.  
  519. void getrandom_tSubst(int& x, int& y) {
  520. int k = rnd.next() % (m - n + 1);
  521. for (int i = 0; i < m; i++) {
  522. if (enabled[i] == false) {
  523. if (k == 0) y = i;
  524. else k--;
  525. }
  526. }
  527.  
  528. rnd.permute(permutation, m);
  529.  
  530. dsu.init(n);
  531. dsu.merge(u1[y], v1[y]);
  532. for (int i = 0; i < m; i++) {
  533. int e = permutation[i];
  534. if (enabled[e]) {
  535. int a = dsu.get(u1[e]);
  536. int b = dsu.get(v1[e]);
  537. if (a == b) x = e;
  538. dsu.merge(a, b);
  539. }
  540. }
  541. }
  542.  
  543. int countComponents() {
  544. dsu.init(n);
  545. for (int i = 0; i < m; i++) {
  546. if (enabled[i] == false) continue;
  547. dsu.merge(u2[i], v2[i]);
  548. }
  549.  
  550. int cnt = 0;
  551. for (int i = 0; i < n; i++) {
  552. if (dsu.get(i) == i) cnt++;
  553. }
  554.  
  555. return cnt;
  556. }
  557.  
  558. double solveOne(int correct, bool swapGraphs) {
  559. const int limit = 300000 / m;
  560.  
  561. if (swapGraphs) {
  562. u1 = ::u2;
  563. v1 = ::v2;
  564. u2 = ::u1;
  565. v2 = ::v1;
  566. }
  567. else {
  568. u1 = ::u1;
  569. v1 = ::v1;
  570. u2 = ::u2;
  571. v2 = ::v2;
  572. }
  573.  
  574. rnd.permute(permutation, m);
  575.  
  576. dsu.init(n);
  577. for (int i = 0; i < m; i++) {
  578. int x = dsu.get(u1[i]);
  579. int y = dsu.get(v1[i]);
  580. if (x != y) {
  581. dsu.merge(x, y);
  582. enabled[i] = true;
  583. }
  584. else {
  585. enabled[i] = false;
  586. }
  587. }
  588.  
  589. double ee = 1.0;
  590. int best = countComponents(), curr = best;
  591. for (int it = 1; it <= limit; it++) {
  592. int x, y;
  593. getrandom_tSubst(x, y);
  594.  
  595. enabled[x] = false;
  596. enabled[y] = true;
  597.  
  598. int cnt = countComponents();
  599. if (cnt < curr || rnd.next() < (1LL << 32) * pow(ee, cnt - curr)) {
  600. curr = cnt;
  601. ee *= 0.988;
  602. if (cnt < best) best = cnt;
  603. }
  604. else {
  605. enabled[x] = true;
  606. enabled[y] = false;
  607. }
  608.  
  609. int ans = n - 1 + best - 1;
  610. if (ans == correct) return it / (double)limit;
  611. }
  612.  
  613. return -1;
  614. }
  615. };
  616.  
  617. // The part above is an exact copy from the checker used on the server! //
  618. //////////////////////////////////////////////////////////////////////////
  619.  
  620. void invalidInput() {
  621. printf("%s\n", "Invalid input!");
  622. exit(0);
  623. }
  624.  
  625. int failed = 0;
  626. void process(int id, double result) {
  627. printf("Solution #%d: ", id);
  628. if (result < -0.5) {
  629. printf("%s\n", "produced an incorrect answer (success).");
  630. failed++;
  631. }
  632. else {
  633. if (result < 0) result = 0;
  634. if (result > 1) result = 1;
  635. printf("produced a correct answer using %6.2f%% of the time limit (failure).\n", 100 * result);
  636. }
  637. }
  638.  
  639. int main() {
  640. if (scanf("%d %d", &n, &m) != 2) invalidInput();
  641. if (n < 2 || n > MX) invalidInput();
  642. if (m < n - 1 || m > MX) invalidInput();
  643. for (int i = 0; i < m; i++) {
  644. if (scanf("%d %d", u1 + i, v1 + i) != 2) invalidInput();
  645. if (u1[i] < 1 || u1[i] > n) invalidInput();
  646. if (v1[i] < 1 || v1[i] > n) invalidInput();
  647. u1[i]--;
  648. v1[i]--;
  649. }
  650. for (int i = 0; i < m; i++) {
  651. if (scanf("%d %d", u2 + i, v2 + i) != 2) invalidInput();
  652. if (u2[i] < 1 || u2[i] > n) invalidInput();
  653. if (v2[i] < 1 || v2[i] > n) invalidInput();
  654. u2[i]--;
  655. v2[i]--;
  656. }
  657.  
  658. DSU dsu1, dsu2;
  659. dsu1.init(n);
  660. dsu2.init(n);
  661. for (int i = 0; i < m; i++) {
  662. dsu1.merge(u1[i], v1[i]);
  663. dsu2.merge(u2[i], v2[i]);
  664. }
  665.  
  666. for (int i = 0; i < n; i++) {
  667. if (dsu1.get(i) != dsu1.get(0)) invalidInput();
  668. if (dsu2.get(i) != dsu2.get(0)) invalidInput();
  669. }
  670.  
  671. printf("The input is valid! N = %d; M = %d.\n\n", n, m);
  672.  
  673. CorrectSolution sol;
  674. int correct = sol.solve();
  675.  
  676. Solution1 sol1;
  677. process(1, sol1.solve(correct));
  678.  
  679. Solution2 sol2;
  680. process(2, sol2.solve(correct));
  681.  
  682. Solution3 sol3;
  683. process(3, sol3.solve(correct));
  684.  
  685. Solution4 sol4;
  686. process(4, sol4.solve(correct));
  687.  
  688. int score = 21 * failed;
  689. if (failed > 0) score += 2400 / (m < 100 ? 100 : m) - 8;
  690. printf("\nScore: %d points.\n", score);
  691.  
  692. return 0;
  693. }
  694.  
Success #stdin #stdout 3.72s 4416KB
stdin
222 255
15 94
6 31
25 64
132 140
78 139
62 151
24 55
100 178
118 220
16 49
122 124
89 147
179 32
27 82
34 93
53 167
52 130
32 79
11 40
91 199
14 174
31 50
99 113
21 142
42 89
188 211
39 174
18 85
36 128
160 212
31 57
36 42
108 145
4 5
80 90
38 204
15 18
26 12
3 84
114 125
171 194
29 92
1 2
31 91
12 180
136 158
57 138
8 61
11 34
173 221
52 62
68 185
100 148
196 69
114 136
26 108
15 200
94 165
51 80
13 106
188 171
6 13
103 28
129 137
14 32
15 23
15 107
54 133
16 43
13 36
131 177
83 179
72 95
13 38
22 168
61 169
62 65
39 120
79 119
148 208
39 48
140 200
66 172
8 15
43 71
80 86
200 146
6 10
182 190
16 63
1 4
12 207
64 77
22 56
51 100
10 132
25 73
19 30
26 76
5 72
184 205
110 112
23 156
13 24
16 21
1 3
60 66
91 104
9 46
8 19
122 218
151 219
3 35
46 101
25 99
17 45
35 53
140 164
192 209
179 27
134 163
19 149
86 181
72 153
62 118
23 51
165 145
68 144
4 6
172 210
5 47
130 14
151 191
83 186
37 24
187 214
85 141
89 146
55 159
14 88
2 171
24 126
56 74
65 83
9 152
11 12
37 102
103 127
131 150
52 98
121 192
114 161
7 39
8 22
37 114
13 129
150 222
10 11
60 57
105 214
42 68
7 67
8 9
13 78
194 206
3 14
144 173
5 7
23 139
74 115
15 28
47 203
150 83
48 52
18 183
9 102
40 130
24 109
70 75
53 180
165 175
99 180
98 111
12 29
81 176
1 44
42 191
16 26
7 27
106 161
68 198
127 192
12 143
52 113
77 110
121 166
50 216
20 117
101 116
28 130
19 155
13 131
82 96
18 103
61 168
47 202
97 189
139 188
8 159
7 17
53 58
14 16
174 184
49 123
49 81
29 37
9 54
154 195
35 87
25 33
10 162
126 182
64 151
178 217
29 122
58 157
173 201
56 157
149 196
2 8
21 25
177 197
35 121
126 170
52 79
29 187
22 41
55 193
19 135
45 215
137 16
122 201
22 60
11 87
82 160
52 209
12 154
57 97
3 69
70 105
58 59
11 70
9 20
26 213
111 134
90 217
59 197
92 141
40 88
166 203
35 121
6 18
72 97
88 109
96 128
61 147
190 215
140 213
27 195
117 132
67 175
14 32
26 130
120 184
121 155
23 34
96 137
34 43
24 161
167 186
1 153
29 152
18 112
99 208
2 45
2 3
3 173
78 219
6 19
23 38
40 81
73 91
72 135
81 175
6 12
19 70
45 145
84 136
189 46
95 160
137 90
163 198
1 55
3 37
97 146
18 35
47 99
2 7
1 2
32 124
2 140
20 196
29 90
171 221
41 174
141 179
71 73
72 151
116 220
143 16
9 53
24 153
10 17
12 134
126 139
153 165
35 47
211 57
9 25
160 172
215 142
74 88
35 76
61 64
63 150
4 21
85 218
102 201
9 20
39 82
33 44
61 69
36 52
155 200
2 11
32 61
100 157
44 162
50 209
18 187
109 180
3 117
12 133
69 102
134 5
51 192
179 80
8 167
19 116
58 106
136 101
219 69
4 94
61 175
1 74
159 205
73 194
74 143
4 15
157 199
6 22
1 193
48 78
57 103
17 182
30 65
34 93
9 27
14 170
15 48
32 107
1 9
49 214
86 140
108 18
128 79
8 60
58 101
188 204
73 169
38 57
4 129
61 42
98 156
1 10
37 42
66 110
10 24
106 127
127 212
28 36
3 4
15 178
26 80
61 114
73 75
167 216
120 176
2 13
18 164
143 192
138 159
139 148
68 188
58 168
64 79
1 29
60 92
6 8
24 26
2 54
37 51
28 33
27 81
31 49
8 138
24 211
166 181
82 123
79 104
9 83
10 31
181 24
90 171
28 177
1 5
31 84
115 158
16 66
2 118
76 105
7 63
11 207
139 191
24 120
90 125
199 100
23 113
70 183
64 126
108 119
49 98
10 85
98 166
2 6
35 40
8 95
34 50
86 129
21 28
14 72
36 87
138 200
56 168
24 30
198 31
131 136
111 19
23 71
69 96
21 202
141 144
19 58
80 122
18 39
105 111
39 56
109 189
7 16
29 131
13 59
4 14
141 163
50 68
84 89
108 115
39 46
78 142
65 210
42 100
46 67
31 142
87 190
41 77
42 86
48 62
12 23
22 222
142 185
95 154
16 108
35 41
113 166
142 149
29 28
113 206
98 125
10 55
57 201
103 112
stdout
The input is valid! N = 222; M = 255.

Solution #1: produced an incorrect answer (success).
Solution #2: produced an incorrect answer (success).
Solution #3: produced an incorrect answer (success).
Solution #4: produced an incorrect answer (success).

Score: 85 points.