定义 $\textbf{Hash}$ 函数,对于某一片雪花 $a_i [\cdots]$
$$
H(a_i[1\cdots 6]) = \left( \sum_{j=1}^{6}a_{i,j} + \prod_{j=1}^{6}a_{i, j} \right) \bmod P
$$
- $a(i, i+1, \cdots i+5), b(i, i+1, \cdots i+5)$
$\textbf{for} \ \forall i, j:\quad \textbf{equal}(a_i[\cdots], b_j[\cdots])$ - 对每片雪花,依次插入 $\textbf{Hash}$ 表即可
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <bitset>
#include <assert.h>
#include <unordered_map>
using namespace std;
typedef long long ll;
#define Cmp(a, b) memcmp(a, b, sizeof(b))
#define Cpy(a, b) memcpy(a, b, sizeof(b))
#define Set(a, v) memset(a, v, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define _forS(i, l, r) for(set<int>::iterator i = (l); i != (r); i++)
#define _rep(i, l, r) for(int i = (l); i <= (r); i++)
#define _for(i, l, r) for(int i = (l); i < (r); i++)
#define _forDown(i, l, r) for(int i = (l); i >= r; i--)
#define debug_(ch, i) printf(#ch"[%d]: %d\n", i, ch[i])
#define debug_m(mp, p) printf(#mp"[%d]: %d\n", p->first, p->second)
#define debugS(str) cout << "dbg: " << str << endl;
#define debugArr(arr, x, y) _for(i, 0, x) { _for(j, 0, y) printf("%c", arr[i][j]); printf("\n"); }
#define _forPlus(i, l, d, r) for(int i = (l); i + d < (r); i++)
#define lowbit(i) (i & (-i))
#define MPR(a, b) make_pair(a, b)
pair<int, int> crack(int n) {
int st = sqrt(n);
int fac = n / st;
while (n % st) {
st += 1;
fac = n / st;
}
return make_pair(st, fac);
}
inline ll qpow(ll a, int n) {
ll ans = 1;
for(; n; n >>= 1) {
if(n & 1) ans *= 1ll * a;
a *= a;
}
return ans;
}
template <class T>
inline bool chmax(T& a, T b) {
if(a < b) {
a = b;
return true;
}
return false;
}
ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a % b);
}
ll ksc(ll a, ll b, ll mod) {
ll ans = 0;
for(; b; b >>= 1) {
if (b & 1) ans = (ans + a) % mod;
a = (a * 2) % mod;
}
return ans;
}
ll ksm(ll a, ll b, ll mod) {
ll ans = 1 % mod;
a %= mod;
for(; b; b >>= 1) {
if (b & 1) ans = ksc(ans, a, mod);
a = ksc(a, a, mod);
}
return ans;
}
template <class T>
inline bool chmin(T& a, T b) {
if(a > b) {
a = b;
return true;
}
return false;
}
template<class T>
bool lexSmaller(vector<T> a, vector<T> b) {
int n = a.size(), m = b.size();
int i;
for(i = 0; i < n && i < m; i++) {
if (a[i] < b[i]) return true;
else if (b[i] < a[i]) return false;
}
return (i == n && i < m);
}
// ============================================================== //
const int maxn = 100000 + 10;
const int P = 99991;
int n, tot = 0, snow[maxn][6], head[maxn], nxt[maxn];
inline int Hash(const int *a) {
int mul = 1, sum = 0;
for (int i = 0; i < 6; i++) {
sum = (sum + a[i]) % P;
mul = (ll) mul * a[i] % P;
}
return (sum + mul) % P;
}
int equal(const int *a, const int *b) {
_for(i, 0, 6) _for(j, 0, 6) {
bool ok = 1;
for (int k = 0; k < 6; k++) {
if (a[(i+k)%6] != b[(j+k)%6]) ok = 0;
}
if (ok) return 1;
ok = 1;
for (int k = 0; k < 6; k++) {
if (a[(i+k)%6] != b[(j-k+6)%6]) ok = 0;
}
if (ok) return true;
}
return false;
}
int insert(const int *a) {
int h = Hash(a);
for (int i = head[h]; i; i = nxt[i]) {
if (equal(snow[i], a)) return 0;
}
++tot;
memcpy(snow[tot], a, 6 * sizeof(int));
nxt[tot] = head[h], head[h] = tot;
return 1;
}
int main() {
freopen("input.txt", "r", stdin);
cin >> n;
for (int i = 0; i < n; i++) {
int a[7];
for (int j = 0; j < 6; j++) scanf("%d", &a[j]);
if (!insert(a)) {
puts("Twin snowflakes found.");
return 0;
}
}
puts("No two snowflakes are alike.");
return 0;
}