#include void strcpy(char t[], char s[]) { int i; for (i = 0; s[i] != '\0'; i++) t[i] = s[i]; t[i] = '\0'; return; } char x[6][3][55]; int len1[3], len2[3]; int strcmp(int val1, int val2) { len1[2] = val1 % 64; val1 /= 64; len1[1] = val1 % 64; val1 /= 64; len1[0] = val1 % 64; val1 /= 64; len2[2] = val2 % 64; val2 /= 64; len2[1] = val2 % 64; val2 /= 64; len2[0] = val2 % 64; val2 /= 64; int l1 = len1[0] + len1[1] + len1[2]; int l2 = len2[0] + len2[1] + len2[2]; if (l1 > l2) return 1; if (l1 < l2) return -1; int id1, id2; id1 = id2 = 0; int i1, i2; i1 = i2 = 0; for (;;) { if (id1 == 3 && id2 == 3) return 0; if (id1 == 3) return -1; if (id2 == 3) return 1; if (x[val1][id1][i1] > x[val2][id2][i2]) return 1; if (x[val1][id1][i1] < x[val2][id2][i2]) return -1; i1++; if (i1 > len1[id1]) { id1++; i1 = 0; } i2++; if (i2 > len2[id2]) { id2++; i2 = 0; } } } int h[3000006], l; int comp_h(int a, int b) { return strcmp(h[a], h[b]); } void swap_h(int a, int b) { int f = h[a]; h[a] = h[b]; h[b] = f; return; } void push(int ne) { h[l] = ne; int p = l++; for (; p > 0; p = (p - 1) / 2) if (comp_h((p - 1) / 2, p) > 0) swap_h((p - 1) / 2, p); return; } int pop() { swap_h(0, --l); int p = 0; for (;;) { if (2 * p + 2 < l) { if (comp_h(2 * p + 1, 2 * p + 2) > 0) { if (comp_h(p, 2 * p + 2) > 0) swap_h(p, 2 * p + 2); p = 2 * p + 2; } else { if (comp_h(p, 2 * p + 1) > 0) swap_h(p, 2 * p + 1); p = 2 * p + 1; } } else if (2 * p + 1 < l) { if (comp_h(p, 2 * p + 1) > 0) swap_h(p, 2 * p + 1); p = 2 * p + 1; } else break; } return h[l]; } int main() { int i, j, k; for (i = 0; i < 3; i++) scanf("%s", x[0][i]); strcpy(x[1][0], x[0][0]); strcpy(x[1][1], x[0][2]); strcpy(x[1][2], x[0][1]); strcpy(x[2][0], x[0][1]); strcpy(x[2][1], x[0][0]); strcpy(x[2][2], x[0][2]); strcpy(x[3][0], x[0][1]); strcpy(x[3][1], x[0][2]); strcpy(x[3][2], x[0][0]); strcpy(x[4][0], x[0][2]); strcpy(x[4][1], x[0][0]); strcpy(x[4][2], x[0][1]); strcpy(x[5][0], x[0][2]); strcpy(x[5][1], x[0][1]); strcpy(x[5][2], x[0][0]); l = 0; for (i = 0; i < 6; i++) push(64 * 64 * 64 * i); int ans = 1, id; int pre = pop(); push(pre); while (l > 0) { i = pop(); if (strcmp(i, pre) > 0) ans++; pre = i; id = pre; k = id % 64; id /= 64; j = id % 64; id /= 64; i = id % 64; id /= 64; if (x[id][0][i + 1] != '\0') push(pre + 64 * 64); if (x[id][1][j + 1] != '\0') push(pre + 64); if (x[id][2][k + 1] != '\0') push(pre + 1); } printf("%d\n", ans); return 0; }