intmain(){ scanf("%d", &n); if (n == 1) returnprintf("-1")&0; // 无解 for (int i = 1; i <= n; i++) { mine[i] = 2; } int st = -1; for (int i = 1; i <= n; i++) { scanf("%d", a+i); mine[a[i]]--; } for (int i = 1; i <= n && st == -1; i++) if (mine[i] == 2) st = i; for (int i = 1; i <= n; i++) { for (int j = mine[i]-(i==st); j >= 1; j--) q.push(i); }
if (st == -1) { // 没有成对的牌 printf("%d\n%d", n+2, a[n]); for (int i = 1; i < n; i++) printf(" %d", a[i]); printf(" %d %d", a[1], a[1]); return0; }
printf("%d\n%d", n, st); mine[st]--; push(st); push(a[1]); for (int i = 2; i <= n; i++) { int x = a[i]; if (mine[x] || cnts[x]) { // 有威胁。清空牌堆 printf(" %d", s[1]); pop(s[1]); } else { if (q.front() == s[1]) { // 会误收牌堆 q.push(q.front()); // 将队首移到队尾 q.pop(); } int nxt = q.front(); printf(" %d", nxt); if (cnts[nxt]) { pop(nxt); } else { push(nxt); mine[nxt]--; q.pop(); } } push(x); } }