description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | I = lambda: list(map(int, input().split()))
n, m = I()
l = []
d = {}
for i in range(n):
x = input()
l.append(x)
d[x] = 1
x = 0
v = [0] * n
for i in range(n):
if v[i]:
continue
for j in range(i + 1, n):
if v[j]:
continue
p = ""
for r in range(m):
if l[i][r] == l[j][r]:
p += l[i][r]
else:
k = l[i][r] + l[j][r]
if k in ["SE", "ES"]:
p += "T"
elif k in ["ET", "TE"]:
p += "S"
else:
p += "E"
x += d.get(p, 0)
print(x // 3) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR IF VAR LIST STRING STRING VAR STRING IF VAR LIST STRING STRING VAR STRING VAR STRING VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, k = map(int, input().split())
cards = set(input() for _ in range(n))
lc = list(cards)
ans = 0
for i in range(n):
for j in range(i):
thrd = ""
for t in range(k):
if lc[i][t] == lc[j][t]:
thrd += lc[i][t]
else:
for ch in ["S", "E", "T"]:
if ch != lc[i][t] and ch != lc[j][t]:
thrd += ch
if thrd in cards:
ans += 1
ans //= 3
print(ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR LIST STRING STRING STRING IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | import sys
input = sys.stdin.readline
n, k = map(int, input().split())
S = [input().strip() for i in range(n)]
SET = set(S)
ANS = 0
for i in range(n - 1):
for j in range(i + 1, n):
rest = []
for l in range(k):
if S[i][l] == S[j][l]:
rest += S[i][l]
else:
rest += chr(236 - ord(S[i][l]) - ord(S[j][l]))
if "".join(rest) in SET:
ANS += 1
print(ANS // 3) | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL STRING VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, kk = map(int, input().split(" "))
l = []
for i in range(n):
l.append(input())
l.sort()
l2 = set(l)
def f(l, e):
if len(l) == 1:
if l[0] == e:
return True
else:
return False
elif l[len(l) // 2] < e:
return f(l[len(l) // 2 :], e)
elif l[len(l) // 2] == e:
return True
else:
return f(l[: len(l) // 2], e)
o = 0
for i in range(len(l) - 1):
for j in range(i + 1, len(l)):
s = ""
for k in range(kk):
if l[i][k] == l[j][k]:
s += l[i][k]
elif "S" not in [l[i][k], l[j][k]]:
s += "S"
elif "E" not in [l[i][k], l[j][k]]:
s += "E"
elif "T" not in [l[i][k], l[j][k]]:
s += "T"
if s in l2:
o += 1
print(o // 3) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR RETURN NUMBER RETURN NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR RETURN FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR RETURN NUMBER RETURN FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF STRING LIST VAR VAR VAR VAR VAR VAR VAR STRING IF STRING LIST VAR VAR VAR VAR VAR VAR VAR STRING IF STRING LIST VAR VAR VAR VAR VAR VAR VAR STRING IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | def third(a, b):
if a == b:
return a
elif a == "S" or b == "S":
if a == "E" or b == "E":
return "T"
else:
return "E"
else:
return "S"
n, k = map(int, input().split())
arr = [None] * n
count = 0
for i in range(n):
str = input()
arr[i] = str
st = set(arr)
for i in range(n - 1):
for j in range(i + 1, n):
third_st = ""
for q in range(k):
third_st += third(arr[i][q], arr[j][q])
if third_st in st:
count += 1
print(count // 3) | FUNC_DEF IF VAR VAR RETURN VAR IF VAR STRING VAR STRING IF VAR STRING VAR STRING RETURN STRING RETURN STRING RETURN STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | class Trie:
def __init__(self, N):
self.N = N
self.tree = [[-1, -1, -1, 0]]
def add(self, s):
tree = self.tree
cur = 0
for i in range(self.N):
if tree[cur][s[i]] == -1:
tree.append([-1, -1, -1, 0])
tree[cur][s[i]] = len(tree) - 1
cur = tree[cur][s[i]]
tree[cur][3] += 1
def count(self, s):
tree = self.tree
cur = 0
for i in range(self.N):
if tree[cur][s[i]] == -1:
return 0
cur = tree[cur][s[i]]
return tree[cur][3]
def match(a, b):
return [(a[i] if a[i] == b[i] else 3 - a[i] - b[i]) for i in range(len(a))]
def change(s):
return [(0 if s[i] == "S" else 1 if s[i] == "E" else 2) for i in range(len(s))]
n, k = map(int, input().split())
s = [change(input()) for i in range(n)]
trie = Trie(k)
for i in range(n):
trie.add(s[i])
cnt = 0
for i in range(n):
for j in range(i + 1, n):
m = match(s[i], s[j])
cnt += trie.count(m) - (s[i] == m) - (s[j] == m)
print(cnt // 3) | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR VAR RETURN VAR VAR NUMBER FUNC_DEF RETURN VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF RETURN VAR VAR STRING NUMBER VAR VAR STRING NUMBER NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | from sys import stdin
def solve():
map = {"e": 0, "s": 1, "t": 2}
def get_bits(letters):
evens = 0
odds = 0
for d in (map[e] for e in letters):
evens = evens << 1 | 1 & d
odds = odds << 1 | 1 & d >> 1
return odds, evens
n, k = [int(i) for i in stdin.readline().strip().split()]
cards = [get_bits(stdin.readline().strip().lower()) for _ in range(n)]
pairs = ((cards[i], cards[j]) for i in range(n) for j in range(i + 1, n))
cards_set = set(cards)
counter = 0
def inc():
nonlocal counter
counter += 1
thirds = (
(
~x[1] & x[0] & ~y[1] & y[0]
| ~x[1] & ~x[0] & y[1] & ~y[0]
| ~y[1] & y[0] & ~x[1] & x[0]
| ~y[1] & ~y[0] & x[1] & ~x[0],
x[1] & ~x[0] & y[1] & ~y[0]
| ~x[1] & ~x[0] & ~y[1] & y[0]
| y[1] & ~y[0] & x[1] & ~x[0]
| ~y[1] & ~y[0] & ~x[1] & x[0],
)
for x, y in pairs
)
tuple(inc() for t in thirds if t in cards_set)
print(counter // 3)
solve() | FUNC_DEF ASSIGN VAR DICT STRING STRING STRING NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER RETURN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_DEF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n = int(input().split()[0])
s = {input() for _ in [0] * n}
a = [["SET".index(x) for x in y] for y in s]
print(
sum(
"".join("SET "[(3 - x - y, x)[x == y]] for x, y in zip(a[i], a[j])) in s
for i in range(n)
for j in range(i)
)
// 3
) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL STRING VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL STRING STRING BIN_OP BIN_OP NUMBER VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | def get(ch1, ch2):
if ch1 == "S" and ch2 == "T" or ch1 == "T" and ch2 == "S":
return "E"
if ch1 == "S" and ch2 == "E" or ch1 == "E" and ch2 == "S":
return "T"
if ch1 == "E" and ch2 == "T" or ch1 == "T" and ch2 == "E":
return "S"
n, k = map(int, input().split())
tot = 0
pre = dict()
st = []
for i in range(0, n):
s = input()
st.append(s)
if pre.get(s) == None:
pre[s] = 0
pre[s] += 1
for i in range(n):
for j in range(i + 1, n):
kk = ""
for m in range(0, k):
if st[i][m] == st[j][m]:
kk += st[i][m]
else:
kk += get(st[i][m], st[j][m])
if pre.get(kk) != None:
tot += pre[kk]
print(tot // 3) | FUNC_DEF IF VAR STRING VAR STRING VAR STRING VAR STRING RETURN STRING IF VAR STRING VAR STRING VAR STRING VAR STRING RETURN STRING IF VAR STRING VAR STRING VAR STRING VAR STRING RETURN STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR NONE VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | [n, k] = [int(x) for x in input().split()]
cards = []
nums = {}
for i in range(n):
s = input()
cards.append(
[(1 if x == "S" else 2 if x == "E" else 3 if x == "T" else "Z") for x in s]
)
t = ""
for a in cards[-1]:
t += str(a)
nums[int(t)] = i
def gen(i, j):
a = cards[i]
b = cards[j]
t = ""
for k in range(len(a)):
if a[k] == b[k]:
t += str(a[k])
elif a[k] + b[k] == 3:
t += "3"
elif a[k] + b[k] == 4:
t += "2"
elif a[k] + b[k] == 5:
t += "1"
return int(t)
count = 0
for i in range(n):
for j in range(i + 1, n):
if gen(i, j) in nums and nums[gen(i, j)] > j:
count += 1
print(count) | ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR STRING NUMBER VAR STRING NUMBER VAR STRING NUMBER STRING VAR VAR ASSIGN VAR STRING FOR VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER VAR STRING IF BIN_OP VAR VAR VAR VAR NUMBER VAR STRING IF BIN_OP VAR VAR VAR VAR NUMBER VAR STRING RETURN FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | import sys
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__
n, k = map(int, input().split())
cards = [input() for _ in range(n)]
check = set(cards)
ordSum = ord("S") + ord("E") + ord("T")
ctr = 0
for i in range(n):
for j in range(i + 1, n):
thirdCard = []
for c1, c2 in zip(cards[i], cards[j]):
if c1 == c2:
thirdCard.append(c1)
else:
c3 = chr(ordSum - ord(c1) - ord(c2))
thirdCard.append(c3)
if "".join(thirdCard) in check:
ctr += 1
print(ctr // 3) | IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL STRING VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | from sys import stdin, stdout
def main():
from sys import stdin, stdout
xorred = ord("s") ^ ord("e") ^ ord("t")
def _third(c, d):
return c if c == d else chr(ord(c) ^ ord(d) ^ xorred)
def third(s, t):
return "".join(_third(c, d) for c, d in zip(s, t))
n, k = map(int, stdin.readline().split())
inp = set()
ans = 0
for _ in range(n):
inp1 = stdin.readline().rstrip("\n").lower()
for inp2 in inp:
if third(inp1, inp2) in inp:
ans += 1
inp.add(inp1)
stdout.write(f"{ans // 2}")
main() | FUNC_DEF ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_DEF RETURN VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF RETURN FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING FOR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | def binarySearch(arr, x):
l = 0
r = len(arr) - 1
while l <= r:
mid = (l + r) // 2
if arr[mid] == x:
return mid
elif arr[mid] < x:
l = mid + 1
else:
r = mid - 1
return -1
n, k = map(int, input().split())
s = []
for i in range(n):
ss = input()
s.append(ss)
s.sort()
count = 0
i = 0
while i < n - 1:
for j in range(i + 1, n):
s1 = s[i]
s2 = s[j]
ans = ""
for ii in range(k):
if s1[ii] == s2[ii]:
ans += s1[ii]
elif s1[ii] == "S" and s2[ii] == "E":
ans += "T"
elif s1[ii] == "S" and s2[ii] == "T":
ans += "E"
elif s1[ii] == "E" and s2[ii] == "S":
ans += "T"
elif s1[ii] == "E" and s2[ii] == "T":
ans += "S"
elif s1[ii] == "T" and s2[ii] == "S":
ans += "E"
elif s1[ii] == "T" and s2[ii] == "E":
ans += "S"
index = binarySearch(s[j + 1 :], ans)
if index != -1:
count += 1
i += 1
print(count) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR IF VAR VAR STRING VAR VAR STRING VAR STRING IF VAR VAR STRING VAR VAR STRING VAR STRING IF VAR VAR STRING VAR VAR STRING VAR STRING IF VAR VAR STRING VAR VAR STRING VAR STRING IF VAR VAR STRING VAR VAR STRING VAR STRING IF VAR VAR STRING VAR VAR STRING VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | def gen(a, b):
gener = ""
for i in range(k):
if a[i] == b[i]:
gener += a[i]
elif "S" not in (a[i], b[i]):
gener += "S"
elif "E" not in (a[i], b[i]):
gener += "E"
else:
gener += "T"
return gener
n, k = list(map(int, input().split()))
cards = []
diff = set()
for i in range(n):
s = input()
cards.append(s)
diff.add(s)
ans = 0
was = set()
for i in range(n):
for j in range(i + 1, n):
aaa = gen(cards[i], cards[j])
if (
aaa in diff
and max(cards[i], cards[j], aaa) + min(cards[i], cards[j], aaa) not in was
):
ans += 1
was.add(max(cards[i], cards[j], aaa) + min(cards[i], cards[j], aaa))
print(ans) | FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR IF STRING VAR VAR VAR VAR VAR STRING IF STRING VAR VAR VAR VAR VAR STRING VAR STRING RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, k = [int(x) for x in input().strip().split()]
def match(a, b):
s = []
for i in range(k):
if a[i] == b[i]:
s.append(a[i])
elif a[i] == "S":
if b[i] == "E":
s.append("T")
elif b[i] == "T":
s.append("E")
elif a[i] == "E":
if b[i] == "S":
s.append("T")
elif b[i] == "T":
s.append("S")
elif a[i] == "T":
if b[i] == "S":
s.append("E")
elif b[i] == "E":
s.append("S")
return "".join(s)
ans = 0
cards = set()
for i in range(n):
cards.add(input())
seen = set()
for c in cards:
seen.add(c)
for c2 in cards:
if c == c2 or c2 in seen:
continue
s = match(c, c2)
if s in cards:
ans += 1
print(int(ans / 3)) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR STRING IF VAR VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR STRING IF VAR VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR STRING IF VAR VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR STRING EXPR FUNC_CALL VAR STRING RETURN FUNC_CALL STRING VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, k = map(int, input().split())
st = set()
cards = []
for i in range(n):
card = input()
st.add(card)
cards.append(card)
ans = 0
for i in range(n):
for j in range(i + 1, n):
last_card = ""
for t in range(k):
if cards[i][t] == cards[j][t]:
last_card += cards[i][t]
else:
for ch in ["S", "T", "E"]:
if cards[i][t] != ch and cards[j][t] != ch:
last_card += ch
break
if last_card in st:
ans += 1
st.remove(cards[i])
print(ans // 2) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR LIST STRING STRING STRING IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | import sys
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [([c] * b) for i in range(a)]
def list3d(a, b, c, d):
return [[([d] * c) for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[([e] * d) for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(input())
def MAP():
return map(int, input().split())
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = 10**18
MOD = 10**9 + 7
N, K = MAP()
A = [input() for i in range(N)]
S = set(A)
D1 = {"S": 1, "E": 2, "T": 3}
D2 = {(1): "S", (2): "E", (3): "T"}
cnt = 0
for i, a1 in enumerate(A):
for j in range(i + 1, N):
a2 = A[j]
a3 = ""
for k1, k2 in zip(a1, a2):
if k1 == k2:
a3 += k1
else:
key = 6 - D1[k1] - D1[k2]
a3 += D2[key]
if a3 in S:
cnt += 1
print(cnt // 3) | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF NONE RETURN VAR NONE FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT STRING STRING STRING NUMBER NUMBER NUMBER ASSIGN VAR DICT NUMBER NUMBER NUMBER STRING STRING STRING ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR STRING FOR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, k = [int(s) for s in input().split()]
l = [input().strip() for i in range(n)]
s = set(l)
comp = {"ST": "E", "TS": "E", "SE": "T", "ES": "T", "ET": "S", "TE": "S"}
ans = 0
for i in range(n - 1):
for j in range(i + 1, n):
s1 = ""
for w in range(k):
if l[i][w] == l[j][w]:
s1 += l[i][w]
else:
s1 += comp[l[i][w] + l[j][w]]
if s1 in s:
ans += 1
print(ans // 3) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, m = (int(x) for x in input().strip().split())
arr = []
d = set()
for i in range(n):
t = input()
d.add(t)
arr.append(t)
cnt = 0
for i in range(n - 1):
for j in range(i + 1, n):
s = ""
for k in range(m):
if arr[i][k] == arr[j][k]:
s += arr[i][k]
else:
s += chr(
ord("S") + ord("E") + ord("T") - ord(arr[i][k]) - ord(arr[j][k])
)
try:
if s in d:
cnt += 1
except:
continue
print(cnt // 3) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, k = [int(i) for i in input().split()]
a = []
d = {}
for i in range(n):
s = input()
a.append(s)
d[s] = i
c = 0
for i in range(n - 2):
for j in range(i + 1, n - 1):
e = []
for ka in range(k):
if a[i][ka] == a[j][ka]:
e.append(a[i][ka])
elif a[i][ka] != "S" and a[j][ka] != "S":
e.append("S")
elif a[i][ka] != "E" and a[j][ka] != "E":
e.append("E")
elif a[i][ka] != "T" and a[j][ka] != "T":
e.append("T")
s = "".join(e)
ind = d.get(s, -1)
if ind > j:
c += 1
print(c) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR STRING VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR VAR STRING VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR VAR STRING VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | def ne(a, b):
if a == b:
return a
elif a == "S" and b == "E":
return "T"
elif a == "S" and b == "T":
return "E"
elif a == "E" and b == "T":
return "S"
elif a == "E" and b == "S":
return "T"
elif a == "T" and b == "S":
return "E"
elif a == "T" and b == "E":
return "S"
def find_other(s1, s2, n):
temp = ""
for i in range(n):
temp += ne(s1[i], s2[i])
return temp
a, b = map(int, input().split())
s = []
for _ in range(a):
s.append(input())
con = 0
s = set(s)
while len(s) > 2:
st1 = s.pop()
set2 = set()
while len(s) >= 1:
st2 = s.pop()
temp2 = find_other(st1, st2, b)
if temp2 in s:
con += 1
s.discard(temp2)
set2.add(temp2)
set2.add(st2)
s = set2
print(con) | FUNC_DEF IF VAR VAR RETURN VAR IF VAR STRING VAR STRING RETURN STRING IF VAR STRING VAR STRING RETURN STRING IF VAR STRING VAR STRING RETURN STRING IF VAR STRING VAR STRING RETURN STRING IF VAR STRING VAR STRING RETURN STRING IF VAR STRING VAR STRING RETURN STRING FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | str_input = input().split()
n = int(str_input[0])
k = int(str_input[1])
card = [input() for i in range(n)]
features = {}
for c in card:
kv = features
for i in range(k):
if c[i] not in kv:
kv[c[i]] = {}
kv = kv[c[i]]
def solve(f1, f2, f3):
ret = 0
if f1 is f2 is f3:
if f1 == {}:
return 0
if len(f1) == 3:
ret += solve(f1["S"], f1["E"], f1["T"])
for f in ["S", "E", "T"]:
if f in f1:
ret += solve(f1[f], f1[f], f1[f])
else:
if f1 == {} and f2 == {} and f3 == {}:
return 1
if "S" in f1 and "S" in f2 and "S" in f3:
ret += solve(f1["S"], f2["S"], f3["S"])
if "E" in f1 and "E" in f2 and "E" in f3:
ret += solve(f1["E"], f2["E"], f3["E"])
if "T" in f1 and "T" in f2 and "T" in f3:
ret += solve(f1["T"], f2["T"], f3["T"])
if "S" in f1 and "E" in f2 and "T" in f3:
ret += solve(f1["S"], f2["E"], f3["T"])
if "S" in f1 and "T" in f2 and "E" in f3:
ret += solve(f1["S"], f2["T"], f3["E"])
if "E" in f1 and "S" in f2 and "T" in f3:
ret += solve(f1["E"], f2["S"], f3["T"])
if "E" in f1 and "T" in f2 and "S" in f3:
ret += solve(f1["E"], f2["T"], f3["S"])
if "T" in f1 and "S" in f2 and "E" in f3:
ret += solve(f1["T"], f2["S"], f3["E"])
if "T" in f1 and "E" in f2 and "S" in f3:
ret += solve(f1["T"], f2["E"], f3["S"])
return ret
print(solve(features, features, features)) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR DICT ASSIGN VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER IF VAR VAR VAR IF VAR DICT RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR STRING VAR STRING VAR STRING FOR VAR LIST STRING STRING STRING IF VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR DICT VAR DICT VAR DICT RETURN NUMBER IF STRING VAR STRING VAR STRING VAR VAR FUNC_CALL VAR VAR STRING VAR STRING VAR STRING IF STRING VAR STRING VAR STRING VAR VAR FUNC_CALL VAR VAR STRING VAR STRING VAR STRING IF STRING VAR STRING VAR STRING VAR VAR FUNC_CALL VAR VAR STRING VAR STRING VAR STRING IF STRING VAR STRING VAR STRING VAR VAR FUNC_CALL VAR VAR STRING VAR STRING VAR STRING IF STRING VAR STRING VAR STRING VAR VAR FUNC_CALL VAR VAR STRING VAR STRING VAR STRING IF STRING VAR STRING VAR STRING VAR VAR FUNC_CALL VAR VAR STRING VAR STRING VAR STRING IF STRING VAR STRING VAR STRING VAR VAR FUNC_CALL VAR VAR STRING VAR STRING VAR STRING IF STRING VAR STRING VAR STRING VAR VAR FUNC_CALL VAR VAR STRING VAR STRING VAR STRING IF STRING VAR STRING VAR STRING VAR VAR FUNC_CALL VAR VAR STRING VAR STRING VAR STRING RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | import sys
n, k = map(int, input().split())
d = {}
a = []
input = sys.stdin.readline
for i in range(n):
s = input().rstrip()
a.append(s)
dd = set(a)
for i in range(n):
u = "".join(a[i])
if u in d:
continue
d[u] = [(0) for x in range(n)]
d[u][i] = 1
for j in range(i + 1, n):
if a[i] == a[j]:
d[u][j] = d[u][j - 1] + 1
else:
d[u][j] = d[u][j - 1]
c = 0
for i in range(n):
for j in range(i + 1, n):
z = ""
l = ["S", "E", "T"]
for p in range(k):
if a[i][p] == a[j][p]:
z += a[i][p]
else:
for y in l:
if a[i][p] != y and a[j][p] != y:
z += y
break
if z in dd:
c += d[z][n - 1] - d[z][j]
print(c) | IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR STRING ASSIGN VAR LIST STRING STRING STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | def strneed(s1, s2, n):
setstr = ["S", "E", "T"]
sn = ""
for i in range(n):
if s1[i] == s2[i]:
sn += s1[i]
else:
for j in setstr:
if j != s1[i] and j != s2[i]:
sn += j
break
return sn
def found(s, arr, l, r):
while l <= r:
mid = l + (r - l) // 2
if l == r:
if arr[mid] == s:
return True
else:
return False
if arr[mid] == s:
return True
elif arr[mid] < s:
l = mid + 1
else:
r = mid - 1
return False
n, kn = map(int, input().split(" "))
arr = []
for i in range(n):
s = input()
arr.append(s)
arr.sort()
cnt = 0
for i in range(n - 2):
for j in range(i + 1, n):
s = strneed(arr[i], arr[j], kn)
if s < arr[j]:
continue
if found(s, arr, j + 1, n - 1):
cnt += 1
print(cnt) | FUNC_DEF ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR FOR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR IF VAR VAR VAR RETURN NUMBER RETURN NUMBER IF VAR VAR VAR RETURN NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR VAR VAR IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | from itertools import combinations
for _ in range(1):
n, k = map(int, input().split())
l = []
d = dict()
for i in range(n):
l.append(input())
d[l[-1]] = 0
count = 0
combs = list(combinations(l, 2))
for i in combs:
a = i[0]
b = i[1]
temp = ""
for j in range(k):
if a[j] == b[j]:
temp += a[j]
elif a[j] == "S" and b[j] == "E" or a[j] == "E" and b[j] == "S":
temp += "T"
elif a[j] == "S" and b[j] == "T" or a[j] == "T" and b[j] == "S":
temp += "E"
elif a[j] == "T" and b[j] == "E" or a[j] == "E" and b[j] == "T":
temp += "S"
d[temp] = d.get(temp, 0) + 1
for x in l:
count += d[x]
print(count // 3) | FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR IF VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR STRING IF VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR STRING IF VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR STRING ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | import sys
def solve():
n, k = map(int, sys.stdin.readline().split())
a = [None] * n
tr = {"S": 0, "E": 1, "T": 2}
for i in range(n):
z = 0
for c in sys.stdin.readline().strip():
z = z * 4 + tr[c]
a[i] = z
d = frozenset(a)
r = 0
for i in range(n):
for j in range(i):
ii, jj = a[i], a[j]
t = ii ^ jj
tt = t >> 1 & 6148914691236517205 | t & 6148914691236517205
ff = (ii | jj) ^ (tt | tt << 1)
r += ff in d
print(r // 3)
solve() | IMPORT FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR DICT STRING STRING STRING NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, k = map(int, input().split())
c = []
for _ in range(n):
c += [input()]
st = set(c)
ans = 0
for i1 in range(n):
for j1 in range(i1 + 1, n):
i, j = c[i1], c[j1]
t = ""
for e in range(k):
if i[e] == j[e]:
t += i[e]
if i[e] == "S" and j[e] == "E" or i[e] == "E" and j[e] == "S":
t += "T"
if i[e] == "E" and j[e] == "T" or i[e] == "T" and j[e] == "E":
t += "S"
if i[e] == "S" and j[e] == "T" or i[e] == "T" and j[e] == "S":
t += "E"
if t in st:
ans += 1
print(ans // 3) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR LIST FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR IF VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR STRING IF VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR STRING IF VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR STRING IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, k2 = map(int, input().split())
l = set()
for i in range(n):
e = input()
l.add(e)
r = set(l)
l = list(l)
an = 0
for j in range(n - 1):
for k in range(j + 1, n):
we = [0] * k2
ty = 0
while ty < k2:
if l[j][ty] == l[k][ty]:
we[ty] = l[j][ty]
else:
if l[j][ty] != "E" and l[k][ty] != "E":
we[ty] = "E"
if l[j][ty] != "T" and l[k][ty] != "T":
we[ty] = "T"
if l[j][ty] != "S" and l[k][ty] != "S":
we[ty] = "S"
ty += 1
we = "".join(we)
if we in r:
an += 1
print(an // 3) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR VAR VAR STRING VAR VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR VAR STRING VAR VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR VAR STRING VAR VAR VAR STRING ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | def go(s1, s2):
ans = ""
p = "SET"
for i in range(len(s1)):
if s1[i] == s2[i]:
ans += s1[i]
elif p[0] != s1[i] and p[0] != s2[i]:
ans += p[0]
elif p[1] != s1[i] and p[1] != s2[i]:
ans += p[1]
elif p[2] != s1[i] and p[2] != s2[i]:
ans += p[2]
return ans
n, k = [int(i) for i in input().split()]
se = set()
if n < 3:
print(0)
exit(0)
for i in range(n):
s = input()
se.add(s)
ans = 0
a = list(se)
st = set()
for i in range(len(a)):
for j in range(i + 1, len(a)):
if (a[i], a[j]) in st or (a[j], a[i]) in st:
continue
chel = go(a[i], a[j])
if chel in se:
ans += 1
st.add((a[j], chel))
st.add((a[i], chel))
print(ans) | FUNC_DEF ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, k = map(int, input().split())
string = []
strtmp = {}
result = 0
for i in range(n):
tmp = input()
string.append(tmp)
strtmp[tmp] = i
if n >= 3:
x = 0
while x < n - 1:
y = x + 1
while y < n:
temp = ""
for i in range(k):
if string[x][i] == string[y][i]:
temp += string[x][i]
else:
temp += chr(236 - (ord(string[x][i]) + ord(string[y][i])))
if strtmp.get(temp) and strtmp[temp] > x and strtmp[temp] > y:
result += 1
y += 1
x += 1
print(result) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | nd = {}
nd["S"] = 1
nd["E"] = 2
nd["T"] = 3
nl = " SET"
def revs(s, t):
if s == t:
return s
else:
return nl[6 - nd[s] - nd[t]]
n, k = map(int, input().split())
dic = {}
c = []
for i in range(n):
C = input()
dic[C] = i
c.append(C)
ans = 0
for i in range(n):
for j in range(i):
if i == j:
continue
nstr = ""
for p in range(k):
nstr += revs(c[i][p], c[j][p])
if nstr in dic and dic[nstr] > i:
ans += 1
print(ans) | ASSIGN VAR DICT ASSIGN VAR STRING NUMBER ASSIGN VAR STRING NUMBER ASSIGN VAR STRING NUMBER ASSIGN VAR STRING FUNC_DEF IF VAR VAR RETURN VAR RETURN VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, k = map(int, input().split())
a = []
arr = []
for i in range(n):
st = input()
a.append(st)
for i in range(n):
arr.append(set())
for j in range(i, n):
arr[i].add(a[j])
count = 0
for i in range(n):
for j in range(i + 1, n):
tmp = ""
for t in range(k):
if a[i][t] == a[j][t]:
tmp += a[i][t]
elif a[i][t] != "T" and a[j][t] != "T":
tmp += "T"
elif a[i][t] != "E" and a[j][t] != "E":
tmp += "E"
elif a[i][t] != "S" and a[j][t] != "S":
tmp += "S"
if tmp in arr[j]:
count += 1
print(count) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR STRING VAR VAR VAR STRING VAR STRING IF VAR VAR VAR STRING VAR VAR VAR STRING VAR STRING IF VAR VAR VAR STRING VAR VAR VAR STRING VAR STRING IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, k = [int(j) for j in input().split()]
se = set()
l = []
for i in range(n):
s = input()
se.add(s)
l.append(s)
ans = 0
for i in range(len(l) - 1):
for j in range(i + 1, len(l)):
l1 = [(l[i][p] + l[j][p]) for p in range(k)]
k1 = ""
for w in l1:
if w[0] == w[1]:
k1 += w[0]
elif w == "ES":
k1 += "T"
elif w == "ET":
k1 += "S"
elif w == "SE":
k1 += "T"
elif w == "TE":
k1 += "S"
elif w == "ST":
k1 += "E"
else:
k1 += "E"
if k1 in se:
ans += 1
print(ans // 3) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR VAR IF VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR STRING VAR STRING IF VAR STRING VAR STRING IF VAR STRING VAR STRING IF VAR STRING VAR STRING IF VAR STRING VAR STRING VAR STRING IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | N, K = map(int, input().split())
X = set(
[
int(
input()
.replace("S", "0000100")
.replace("E", "0001000")
.replace("T", "0010000"),
2,
)
for _ in range(N)
]
)
m = int("0011100" * K, 2)
ans = 0
while X:
x = X.pop()
for y in X:
if m - (x | y) ^ ((x & y) >> 2) * 31 & m in X:
ans += 1
print(ans // 2) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING STRING STRING STRING STRING STRING NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP STRING VAR NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | def binarySearch(arr, l, r, x):
if r >= l:
mid = l + (r - l) // 2
if arr[mid] == x:
return True
elif arr[mid] > x:
return binarySearch(arr, l, mid - 1, x)
else:
return binarySearch(arr, mid + 1, r, x)
else:
return False
n, k = map(int, input().split())
ls = []
for i in range(n):
s = input()
ls.append(s)
ls.sort()
count = 0
for i in range(n - 2):
for j in range(i + 1, n - 1):
s = ""
for x in range(k):
if ls[i][x] == ls[j][x]:
s += ls[i][x]
else:
a = ["S", "E", "T"]
a.remove(ls[i][x])
a.remove(ls[j][x])
s += a[0]
if binarySearch(ls, j + 1, n - 1, s):
count += 1
print(count) | FUNC_DEF IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN NUMBER IF VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST STRING STRING STRING EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, k = map(int, input().split())
cards, res, lock_cards = [], 0, set()
for _ in range(n):
cards.append(input())
cards2 = set(cards)
for i in range(0, n - 1):
a = cards[i]
for j in range(i + 1, n):
b = cards[j]
example = ""
for z in range(k):
if a[z] != b[z]:
letters = ["S", "E", "T"]
letters.remove(a[z])
letters.remove(b[z])
example += letters[0]
else:
example += a[z]
if example in cards2:
res += 1
print(res // 3) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR LIST NUMBER FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR LIST STRING STRING STRING EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | from sys import stdin
def solve():
map = {"e": 0, "s": 1, "t": 2}
def get_bits(letters):
evens = 0
odds = 0
for d in (map[e] for e in letters):
evens = evens << 1 | 1 & d
odds = odds << 1 | 1 & d >> 1
return odds, evens
n, k = [int(i) for i in stdin.readline().strip().split()]
cards = [get_bits(stdin.readline().strip().lower()) for _ in range(n)]
pairs = ((cards[i], cards[j]) for i in range(n) for j in range(i + 1, n))
cards_set = set(cards)
counter = 0
for x, y in pairs:
a = x[0]
A = x[1]
b = y[0]
B = y[1]
c = A & ~a & B & ~b | ~A & ~a & ~B & b | B & ~b & A & ~a | ~B & ~b & ~A & a
C = ~A & a & ~B & b | ~A & ~a & B & ~b | ~B & b & ~A & a | ~B & ~b & A & ~a
if (C, c) in cards_set:
counter += 1
print(counter // 3)
solve() | FUNC_DEF ASSIGN VAR DICT STRING STRING STRING NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER RETURN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | import sys
input = sys.stdin.readline
a, b = map(int, input().split())
l = [input().strip() for i in range(a)]
c = 0
sey = set(l)
for i in range(a):
for j in range(i + 1, a):
s = ""
for k in range(b):
if l[i][k] == l[j][k]:
s = s + l[i][k]
else:
s = s + chr(236 - ord(l[i][k]) - ord(l[j][k]))
if s in sey:
c = c + 1
print(c // 3) | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | import gc
gc.disable()
n, k = map(int, input().split())
deck = set()
for _ in range(n):
deck.add(input())
ans = 0
def thirdChar(a, b):
if a == b:
return a
if a == "S" and b == "T" or a == "T" and b == "S":
return "E"
if a == "S" and b == "E" or a == "E" and b == "S":
return "T"
if a == "E" and b == "T" or a == "T" and b == "E":
return "S"
def findThird(c1, c2):
l = []
for i in range(k):
l.append(thirdChar(c1[i], c2[i]))
return "".join(l)
for c1 in deck:
for c2 in deck:
if c2 > c1:
c3 = findThird(c1, c2)
if c3 > c2 and c3 in deck:
ans += 1
print(ans) | IMPORT EXPR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR RETURN VAR IF VAR STRING VAR STRING VAR STRING VAR STRING RETURN STRING IF VAR STRING VAR STRING VAR STRING VAR STRING RETURN STRING IF VAR STRING VAR STRING VAR STRING VAR STRING RETURN STRING FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN FUNC_CALL STRING VAR FOR VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | def greaterthan(ar, target, end):
start = 0
ans = -1
while start <= end:
mid = (start + end) // 2
if ar[mid] <= target:
start = mid + 1
else:
ans = mid
end = mid - 1
return ans
def binarySearch(arr, l, r, x):
while l <= r:
mid = (l + r) // 2
if arr[mid] == x:
return mid
elif arr[mid] < x:
l = mid + 1
else:
r = mid - 1
return -1
n, k = map(int, input().split())
s = []
for i in range(n):
s.append(input())
s.sort()
count = 0
for i in range(n - 1):
for j in range(i + 1, n):
s1 = s[i]
s2 = s[j]
ans = ""
for ii in range(k):
if s1[ii] == s2[ii]:
ans += s1[ii]
elif s1[ii] == "S":
if s2[ii] == "E":
ans += "T"
elif s2[ii] == "T":
ans += "E"
elif s1[ii] == "E":
if s2[ii] == "S":
ans += "T"
elif s2[ii] == "T":
ans += "S"
elif s1[ii] == "T":
if s2[ii] == "S":
ans += "E"
elif s2[ii] == "E":
ans += "S"
ind = binarySearch(s[j + 1 :], 0, len(s[j + 1 :]) - 1, ans)
if ind != -1:
count += 1
print(count) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR IF VAR VAR STRING IF VAR VAR STRING VAR STRING IF VAR VAR STRING VAR STRING IF VAR VAR STRING IF VAR VAR STRING VAR STRING IF VAR VAR STRING VAR STRING IF VAR VAR STRING IF VAR VAR STRING VAR STRING IF VAR VAR STRING VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | x, y = map(int, input().split())
mp = {}
s = []
for n in range(x):
j = input()
if j not in mp:
mp[j] = 1
else:
mp[j] += 1
s.append(j)
res = 0
def ret(a, b):
st = "SET"
for n in st:
if n != a and n != b:
return n
for n in range(x):
for k in range(n + 1, x):
st = ""
for v in range(y):
if s[n][v] == s[k][v]:
st += s[n][v]
else:
st += ret(s[n][v], s[k][v])
if st in mp:
res += 1
if s[n] == s[k]:
res -= 2
print(res // 3) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR STRING FOR VAR VAR IF VAR VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, k = list(map(int, input().split()))
cards = set()
L = []
x = ord("S") + ord("E") + ord("T")
total = 0
for i in range(n):
s = input()
cards.add(s)
L.append(s)
for i in range(n):
for j in range(n):
if i == j:
continue
opposite = []
for l in range(k):
if L[i][l] == L[j][l]:
opposite.append(L[i][l])
else:
opposite.append(chr(x - ord(L[i][l]) - ord(L[j][l])))
if "".join(opposite) in cards:
total += 1
print(total // 6) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL STRING VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, k = map(int, input().split())
cards = []
sum = ord("S") + ord("E") + ord("T")
for _ in range(n):
cards.append(input())
cards_set = set(cards)
cnt = 0
for i in range(n - 1):
for j in range(i + 1, n):
ans = []
for x in range(k):
if cards[i][x] == cards[j][x]:
ans.append(cards[i][x])
else:
ans.append(chr(sum - ord(cards[i][x]) - ord(cards[j][x])))
if "".join(ans) in cards_set:
cnt += 1
print(cnt // 3) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL STRING VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | from sys import stdin, stdout
n, m = list(map(int, stdin.readline().split()))
l = []
for i in range(n):
l.append(input())
out = 0
d = {}
for i in l:
d[i] = 1
l = list(d.keys())
n = len(l)
for i in range(n - 1):
a = l[i]
for j in range(i + 1, n):
b = l[j]
nw = ""
for k in range(m):
if a[k] == b[k]:
nw += a[k]
else:
v = a[k] + b[k]
if "E" not in v:
nw += "E"
elif "T" not in v:
nw += "T"
elif "S" not in v:
nw += "S"
if d.get(nw, 0):
out += 1
stdout.write(str(out // 3)) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF STRING VAR VAR STRING IF STRING VAR VAR STRING IF STRING VAR VAR STRING IF FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | from sys import stdin
input = stdin.readline
n, k = map(int, input().split())
arr = list(input() for _ in range(n))
res, cnt = 0, {}
for s in arr:
s = s[:-1]
cnt[s] = cnt.get(s, 0) + 1
for i in range(n):
for j in range(i + 1, n):
curr = ""
for c in range(k):
if arr[i][c] == arr[j][c]:
curr += arr[i][c]
else:
for t in "SET":
if t != arr[i][c] and t != arr[j][c]:
curr += t
break
res += cnt.get(curr, 0)
print(res // 3) | ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER DICT FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR STRING IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | from itertools import combinations
n, k = map(int, input().split())
cards = [None for i in range(n)]
for i in range(n):
cards[i] = input()
ans = 0
card_set = set(cards)
combos = combinations(cards, 2)
for i in range(n):
for j in range(i + 1, n):
req_ans = ""
for l in range(k):
if cards[i][l] == cards[j][l]:
req_ans += cards[i][l]
elif (
cards[i][l] == "S"
and cards[j][l] == "E"
or cards[i][l] == "E"
and cards[j][l] == "S"
):
req_ans += "T"
elif (
cards[i][l] == "S"
and cards[j][l] == "T"
or cards[i][l] == "T"
and cards[j][l] == "S"
):
req_ans += "E"
else:
req_ans += "S"
if req_ans in card_set:
ans += 1
print(ans // 3) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NONE VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR STRING VAR VAR VAR STRING VAR VAR VAR STRING VAR VAR VAR STRING VAR STRING IF VAR VAR VAR STRING VAR VAR VAR STRING VAR VAR VAR STRING VAR VAR VAR STRING VAR STRING VAR STRING IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, k = map(int, input().split())
cards = set()
clist = []
for i in range(n):
s = input()
cards.add(s)
clist.append(s)
def ex(a, b):
for i in "SET":
if i not in (a, b):
return i
ans = 0
for a in range(len(clist)):
for b in range(a + 1, len(clist)):
c1, c2 = clist[a], clist[b]
complement = []
for i in range(k):
if c1[i] == c2[i]:
complement.append(c1[i])
else:
complement.append(ex(c1[i], c2[i]))
if "".join(complement) in cards:
ans += 1
print(ans // 3) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF FOR VAR STRING IF VAR VAR VAR RETURN VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF FUNC_CALL STRING VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, f = map(int, input().split())
a = []
for _ in range(n):
s = input()
a.append(s)
count = 0
strs = []
for i in range(n):
for j in range(i + 1, n):
s = ""
for k in range(f):
if a[i][k] == a[j][k]:
s += a[i][k]
else:
add = ["S", "E", "T"]
add.remove(a[i][k])
add.remove(a[j][k])
s += add[0]
strs.append(s)
a = set(a)
for s in strs:
if s in a:
count += 1
print(count // 3) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST STRING STRING STRING EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, k = map(int, input().split())
p = 0
a = []
s = {}
for i in range(n):
t = str(input())
a.append(t)
s[t] = i
for i in range(n - 1):
for j in range(i + 1, n):
r = ""
for q in range(k):
if a[i][q] == a[j][q]:
r = r + a[i][q]
else:
for m in "SET":
if m != a[i][q] and m != a[j][q]:
r = r + m
if s.get(r) and s[r] > i and s[r] > j:
p += 1
print(p) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FOR VAR STRING IF VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, k = map(int, input().split())
s = []
dic = {}
for i in range(n):
s.append(input().strip())
dic[s[i]] = 1
ans = 0
visited = set()
for i in range(n):
for j in range(i + 1, n):
expec = ""
for l in range(k):
if s[i][l] != s[j][l]:
v = [s[i][l], s[j][l]]
if "T" not in v:
expec += "T"
elif "S" not in v:
expec += "S"
else:
expec += "E"
else:
expec += s[i][l]
if expec in dic and tuple(sorted([s[i], s[j], expec])) not in visited:
visited.add(tuple(sorted([s[i], s[j], expec])))
ans += 1
print(ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST VAR VAR VAR VAR VAR VAR IF STRING VAR VAR STRING IF STRING VAR VAR STRING VAR STRING VAR VAR VAR VAR IF VAR VAR FUNC_CALL VAR FUNC_CALL VAR LIST VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR LIST VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | import sys
I = sys.stdin.readline
n = int(I().split()[0])
s = set()
r = 0
for _ in [0] * n:
t = I()
for x in s:
r += "".join(chr((66 ^ ord(u)) * (u != v) ^ ord(v)) for u, v in zip(x, t)) in s
s |= {t}
print(r // 2) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR FUNC_CALL STRING FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | import sys
n, k = [int(x) for x in sys.stdin.readline().split(" ")]
cards = []
for _ in range(n):
cards.append(sys.stdin.readline().rstrip())
cardset = set(cards)
asd = set(["S", "E", "T"])
ss = 0
for i, ci in enumerate(cards):
for j, cj in enumerate(cards):
if ci == cj:
break
com = ""
for item in range(k):
if ci[item] == cj[item]:
com += ci[item]
else:
if ci[item] != "S" and cj[item] != "S":
com += "S"
elif ci[item] != "E" and cj[item] != "E":
com += "E"
if ci[item] != "T" and cj[item] != "T":
com += "T"
if com in cardset:
ss += 1
print(ss // 3) | IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR LIST STRING STRING STRING ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR IF VAR VAR STRING VAR VAR STRING VAR STRING IF VAR VAR STRING VAR VAR STRING VAR STRING IF VAR VAR STRING VAR VAR STRING VAR STRING IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, K = map(int, input().split())
count = 0
card = []
cards_set = {}
for _ in range(n):
s = input()
card.append(s)
cards_set[s] = _
for i in range(n - 2):
for j in range(i + 1, n - 1):
third = ""
for l in range(K):
if card[i][l] == card[j][l]:
third += card[i][l]
else:
for letter in ["S", "E", "T"]:
if letter not in [card[i][l], card[j][l]]:
break
third += letter
if third in cards_set and cards_set[third] > j:
count += 1
if n < 3:
print(0)
else:
print(count) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR LIST STRING STRING STRING IF VAR LIST VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, m = map(int, input().split())
cards = {}
cardsL = []
ans = {}
for i in range(n):
card = input()
cards[card] = i
cardsL.append(card)
def getCard3(A, B, m):
card3 = ""
for i in range(m):
if A[i] == B[i]:
card3 += A[i]
elif A[i] != "T" and B[i] != "T":
card3 += "T"
elif A[i] != "E" and B[i] != "E":
card3 += "E"
elif A[i] != "S" and B[i] != "S":
card3 += "S"
return card3
res = 0
for i in range(n - 1):
for j in range(i + 1, n - 1):
CardT = getCard3(cardsL[i], cardsL[j], m)
temp = cards.get(CardT, 0)
if temp > j:
res += 1
print(res) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR IF VAR VAR STRING VAR VAR STRING VAR STRING IF VAR VAR STRING VAR VAR STRING VAR STRING IF VAR VAR STRING VAR VAR STRING VAR STRING RETURN VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | N, K = map(int, input().split())
X = [
int(
input().replace("S", "0000100").replace("E", "0001000").replace("T", "0010000"),
2,
)
for _ in range(N)
]
D = {x: (1) for x in X}
m = int("0011100" * K, 2)
ans = 0
for i in range(N):
for j in range(i + 1, N):
if m - (X[i] | X[j]) ^ ((X[i] & X[j]) >> 2) * 31 & m in D:
ans += 1
print(ans // 3) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING STRING STRING STRING STRING STRING NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP STRING VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, k = map(int, input().split(" "))
g = []
for z in range(n):
c = input()[:k]
h = []
for i, f in enumerate(c):
if f == "S":
l = 0
elif f == "E":
l = 1
else:
l = 2
h.append(l)
g.append(tuple(h))
t = set(g)
p = 0
for i in range(len(g)):
a = g[i]
for j in range(i + 1, len(g)):
b = g[j]
n = []
for z in range(k):
if a[z] == b[z]:
n.append(a[z])
continue
else:
n.append(3 - a[z] - b[z])
if tuple(n) in t:
p += 1
print(p // 3) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR NUMBER IF VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | def count_hyperset(cards, n, k):
ans = 0
in_cards = dict()
pairs = set()
for i in range(len(cards)):
in_cards[cards[i]] = i
lookFor = [""] * k
for i in range(len(cards) - 2):
for j in range(i + 1, len(cards) - 1):
if (i, j) in pairs:
continue
for u in range(k):
if cards[i][u] == cards[j][u]:
lookFor[u] = cards[i][u]
continue
if cards[i][u] == "S":
lookFor[u] = "T" if cards[j][u] == "E" else "E"
elif cards[i][u] == "E":
lookFor[u] = "T" if cards[j][u] == "S" else "S"
else:
lookFor[u] = "E" if cards[j][u] == "S" else "S"
look_str = "".join(lookFor)
res = in_cards.get(look_str, -1)
if res == -1:
continue
ans += 1
pairs.add((i, j))
pairs.add((i, res))
pairs.add((j, res))
return ans
inp = input().split()
n = int(inp[0])
k = int(inp[1])
cards = [""] * n
for i in range(n):
cards[i] = input()
ans = count_hyperset(cards, n, k)
print(ans) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR VAR VAR VAR STRING STRING STRING IF VAR VAR VAR STRING ASSIGN VAR VAR VAR VAR VAR STRING STRING STRING ASSIGN VAR VAR VAR VAR VAR STRING STRING STRING ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | def create():
s = ""
for i in range(k):
if x[i] == y[i]:
s += x[i]
else:
s += chr(236 - ord(x[i]) - ord(y[i]))
return s
l = input().split()
n = int(l[0])
k = int(l[1])
hashi = dict()
count = 0
l = []
for i in range(n):
s = input()
hashi[s] = i
l.append(s)
for i in range(n):
for j in range(i + 1, n):
x = l[i]
y = l[j]
z = create()
if z in hashi and hashi[z] > j:
count += 1
print(count) | FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, f = map(int, input().split())
l = []
for i in range(n):
t = input()
l.append(t)
d = set(l)
count = 0
for i in range(n):
for j in range(i + 1, n):
temp = ""
for k in range(f):
if l[i][k] == l[j][k]:
temp = temp + l[i][k]
else:
add = ["S", "E", "T"]
add.remove(l[i][k])
add.remove(l[j][k])
temp = temp + add[0]
if temp in d:
count = count + 1
print(count // 3) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR LIST STRING STRING STRING EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | import sys
def input():
return sys.stdin.readline().strip()
n, k = [int(x) for x in input().split()]
V = [input() for x in range(n)]
M = set(V)
z = ord("S") + ord("E") + ord("T")
cc = 0
for i in range(n):
for j in range(i + 1, n):
s = ""
for l in range(k):
if V[i][l] == V[j][l]:
s += V[i][l]
else:
s += chr(z - ord(V[i][l]) - ord(V[j][l]))
if s in M:
cc += 1
print(cc // 3) | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, k = list(map(int, input().split()))
words = []
was = dict()
for i in range(n):
a = input()
words.append(a)
was[a] = i
ans = 0
for i in range(n):
for i1 in range(i + 1, n):
s = ""
for j in range(k):
a = ["S", "E", "T"]
if words[i][j] == words[i1][j]:
s += words[i][j]
elif words[i][j] == "S" and words[i1][j] == "T":
s += "E"
elif words[i][j] == "S" and words[i1][j] == "E":
s += "T"
elif words[i][j] == "E" and words[i1][j] == "T":
s += "S"
elif words[i][j] == "E" and words[i1][j] == "S":
s += "T"
elif words[i][j] == "T" and words[i1][j] == "E":
s += "S"
elif words[i][j] == "T" and words[i1][j] == "S":
s += "E"
if s in was:
if was[s] > i1:
ans += 1
print(ans) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST STRING STRING STRING IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR STRING VAR VAR VAR STRING VAR STRING IF VAR VAR VAR STRING VAR VAR VAR STRING VAR STRING IF VAR VAR VAR STRING VAR VAR VAR STRING VAR STRING IF VAR VAR VAR STRING VAR VAR VAR STRING VAR STRING IF VAR VAR VAR STRING VAR VAR VAR STRING VAR STRING IF VAR VAR VAR STRING VAR VAR VAR STRING VAR STRING IF VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, k = [int(ele) for ele in input().split()]
lst = []
N = n
while N > 0:
ele = input()
lst.append(ele)
N -= 1
setC = set(lst)
z = ord("S") + ord("T") + ord("E")
count = 0
for i in range(n):
for j in range(i + 1, n):
st = ""
for ind in range(k):
if lst[i][ind] == lst[j][ind]:
st += lst[i][ind]
else:
a = lst[i][ind]
b = lst[j][ind]
st += chr(z - ord(a) - ord(b))
if st in setC:
count += 1
print(count // 3) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | import sys
input = sys.stdin.readline
n, k = map(int, input().split())
cards = []
for _ in range(n):
c = input().rstrip()
cards.append(c)
check = set(cards)
def thirdCard(c1, c2, k):
c3 = []
for p1, p2 in zip(c1, c2):
if p1 == p2:
c3.append(p1)
else:
if p1 != "S" and p2 != "S":
p3 = "S"
elif p1 != "E" and p2 != "E":
p3 = "E"
else:
p3 = "T"
c3.append(p3)
return "".join(c3)
ctr = 0
for i in range(n):
for j in range(i + 1, n):
card3 = thirdCard(cards[i], cards[j], k)
if card3 in check:
ctr += 1
print(ctr // 3) | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR STRING VAR STRING ASSIGN VAR STRING IF VAR STRING VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL STRING VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, k = map(int, input().split())
se = set()
ls = []
for i in range(n):
s = input()
se.add(s)
ls.append(s)
anscnt = 0
for i in range(n - 1):
s = ls[i]
for j in range(i + 1, n):
t = ls[j]
ans = []
for l in range(k):
if s[l] == t[l]:
ans.append(s[l])
elif s[l] == "S":
if t[l] == "E":
ans.append("T")
else:
ans.append("E")
elif s[l] == "T":
if t[l] == "E":
ans.append("S")
else:
ans.append("E")
elif t[l] == "T":
ans.append("S")
else:
ans.append("T")
x = "".join(ans)
if x in se:
anscnt += 1
print(anscnt // 3) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR STRING IF VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR STRING IF VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL STRING VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, kk = list(map(int, input().split()))
cards = ["S", "E", "T"]
cs = []
res = 0
rec = set()
for i in range(n):
c = input()
cs.append(c)
rec.add(c)
for i in range(len(cs) - 1):
for j in range(i + 1, len(cs)):
new = ""
for k in range(kk):
if cs[i][k] == cs[j][k]:
new += cs[i][k]
else:
for t in cards:
if t != cs[i][k] and t != cs[j][k]:
new += t
if new in rec:
res += 1
print(res // 3) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | def main():
n, k = map(int, input().split())
cards = []
for i in range(n):
cards.append(input().strip())
cards_set = set(cards)
ways = 0
for i in range(n):
for j in range(i + 1, n):
s = ""
for z in range(k):
if cards[i][z] == cards[j][z]:
s += cards[i][z]
else:
for c in "SET":
if c != cards[i][z] and c != cards[j][z]:
s += c
break
if s in cards_set:
ways += 1
ways //= 3
print(ways)
main() | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR STRING IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | def other(s1, s2):
s3 = ""
for i in range(k):
if s1[i] == s2[i]:
s3 += s1[i]
else:
l = ["S", "E", "T"]
l.remove(s1[i])
l.remove(s2[i])
s3 += l[0]
return s3
n, k = [int(zax) for zax in input().split()]
dic = {}
strings = []
for i in range(n):
s = input()
strings.append(s)
dic[s] = True
count = 0
for i in range(n - 1):
for j in range(i + 1, n):
s3 = other(strings[i], strings[j])
if s3 in dic:
count += 1
print(count // 3) | FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST STRING STRING STRING EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | from sys import stdin
inp = stdin.readline
n, k = map(int, inp().split())
ans = 0
cards = []
for i in range(n):
cards.append(inp().strip())
total = ord("E") + ord("S") + ord("T")
cards_hash = set(cards)
for i in range(n):
for j in range(i + 1, n):
complement = ""
for h in range(k):
if cards[i][h] != cards[j][h]:
complement += chr(total - ord(cards[i][h]) - ord(cards[j][h]))
else:
complement += cards[i][h]
if complement in cards_hash:
ans += 1
print(ans // 3) | ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | def get_third(k, a, b):
c = ""
for i in range(k):
if a[i] == b[i]:
c += a[i]
else:
if a[i] != "S" and b[i] != "S":
c += "S"
if a[i] != "E" and b[i] != "E":
c += "E"
if a[i] != "T" and b[i] != "T":
c += "T"
return c
n, k = list(map(int, input().split()))
cards = list()
for i in range(n):
cards.append(input())
card_set = {cards[i]: i for i in range(n)}
count_valid = 0
for p in range(n - 2):
for q in range(p + 1, n - 1):
c = get_third(k, cards[p], cards[q])
if c in card_set.keys() and card_set[c] > q:
count_valid += 1
print(count_valid) | FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR IF VAR VAR STRING VAR VAR STRING VAR STRING IF VAR VAR STRING VAR VAR STRING VAR STRING IF VAR VAR STRING VAR VAR STRING VAR STRING RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | from sys import stdin
n, k = map(int, stdin.readline().split())
a = [stdin.readline().strip() for _ in range(n)]
d = {}
res = 0
S = ord("S") + ord("E") + ord("T")
for i in range(n):
if a[i] in d.keys():
d[a[i]] += 1
else:
d[a[i]] = 1
for i in range(n):
for j in range(i + 1, n):
if i == j:
continue
t = ""
for p in range(k):
if a[i][p] == a[j][p]:
t += a[i][p]
else:
t += chr(S - ord(a[i][p]) - ord(a[j][p]))
if t in d.keys():
res += d[t]
print(int(res / 3)) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | import sys
input = lambda: sys.stdin.readline().rstrip()
n, k = map(int, input().split())
a = []
for i in range(n):
s = input()
a.append(s)
st = set(a)
st2 = {"SE": "T", "ES": "T", "ST": "E", "TS": "E", "ET": "S", "TE": "S"}
ans = 0
for i in range(n):
for j in range(i + 1, n):
need = ""
for p in range(k):
if a[i][p] == a[j][p]:
need += a[i][p]
elif a[i][p] != a[j][p]:
need += st2[a[i][p] + a[j][p]]
if need in st:
ans += 1
print(ans // 3) | IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | def f(x, y):
if x == y:
return x
if x == "T" and y == "E" or x == "E" and y == "T":
return "S"
if x == "S" and y == "T" or x == "T" and y == "S":
return "E"
if x == "S" and y == "E" or x == "E" and y == "S":
return "T"
n, k = [int(x) for x in input().split()]
s = []
for i in range(n):
s.append(input())
ans = 0
m = {}
for i in range(n - 1, -1, -1):
for j in range(i):
cur = ""
for l in range(k):
cur += f(s[i][l], s[j][l])
if cur in m:
ans += m[cur]
if s[i] in m:
m[s[i]] += 1
else:
m[s[i]] = 1
print(ans) | FUNC_DEF IF VAR VAR RETURN VAR IF VAR STRING VAR STRING VAR STRING VAR STRING RETURN STRING IF VAR STRING VAR STRING VAR STRING VAR STRING RETURN STRING IF VAR STRING VAR STRING VAR STRING VAR STRING RETURN STRING ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, k = [int(i) for i in input().split()]
d = {}
a = []
for i in range(n):
x = input()
if x not in d:
d[x] = 0
d[x] += 1
a.append(x)
c = 0
for i in range(n):
for j in range(i + 1, n):
b = ""
for i1 in range(k):
if a[i][i1] == a[j][i1]:
b = b + a[i][i1]
else:
ty = [0, 0, 0]
if a[i][i1] == "S" or a[j][i1] == "S":
ty[0] = 1
if a[i][i1] == "E" or a[j][i1] == "E":
ty[1] = 1
if a[i][i1] == "T" or a[j][i1] == "T":
ty[2] = 1
if ty[0] == 0:
b = b + "S"
elif ty[1] == 0:
b = b + "E"
elif ty[2] == 0:
b = b + "T"
if b in d:
if a[i] == a[j]:
if d[b] > 2:
c += 1
else:
c += 1
print(int(c / 3)) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER IF VAR VAR VAR STRING VAR VAR VAR STRING ASSIGN VAR NUMBER NUMBER IF VAR VAR VAR STRING VAR VAR VAR STRING ASSIGN VAR NUMBER NUMBER IF VAR VAR VAR STRING VAR VAR VAR STRING ASSIGN VAR NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR STRING IF VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR STRING IF VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR STRING IF VAR VAR IF VAR VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | def match(a, b):
c = ""
for i in range(len(a)):
if a[i] == b[i]:
c += a[i]
elif a[i] + b[i] == "SE" or a[i] + b[i] == "ES":
c += "T"
elif a[i] + b[i] == "ST" or a[i] + b[i] == "TS":
c += "E"
else:
c += "S"
return c
n, k = map(int, input().split())
s = [input() for i in range(n)]
st = set()
for i in range(n):
st.add(s[i])
cnt = 0
for i in range(n):
for j in range(i + 1, n):
m = match(s[i], s[j])
cnt += m in st
print(cnt // 3) | FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR STRING BIN_OP VAR VAR VAR VAR STRING VAR STRING IF BIN_OP VAR VAR VAR VAR STRING BIN_OP VAR VAR VAR VAR STRING VAR STRING VAR STRING RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | def calc(a, b):
if a == "S":
if b == "E":
return "T"
elif b == "S":
return "S"
else:
return "E"
elif a == "E":
if b == "E":
return "E"
elif b == "S":
return "T"
else:
return "S"
elif b == "E":
return "S"
elif b == "S":
return "E"
else:
return "T"
n, k = map(int, input().split())
d = {}
l = []
done = {}
for i in range(n):
a = input()
d[a] = 1
l.append(a)
if n <= 2:
print(0)
exit()
ans = 0
for i in range(n):
for j in range(i + 1, n):
reqd = ""
for m in range(k):
reqd += calc(l[i][m], l[j][m])
if reqd in d:
if (
(l[i], l[j], reqd) not in done
and (l[i], reqd, l[j]) not in done
and (l[j], l[i], reqd) not in done
and (l[j], reqd, l[i]) not in done
and (reqd, l[j], l[i]) not in done
and (reqd, l[i], l[j]) not in done
):
done[l[i], l[j], reqd] = 1
ans += 1
print(ans) | FUNC_DEF IF VAR STRING IF VAR STRING RETURN STRING IF VAR STRING RETURN STRING RETURN STRING IF VAR STRING IF VAR STRING RETURN STRING IF VAR STRING RETURN STRING RETURN STRING IF VAR STRING RETURN STRING IF VAR STRING RETURN STRING RETURN STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | from sys import stdin
def get1(a, b):
if a == b:
return a
if a == "S":
if b == "E":
return "T"
return "E"
if a == "E":
if b == "S":
return "T"
return "S"
if b == "S":
return "E"
return "S"
def get(a, b):
return "".join(map(lambda x: get1(*x), zip(a, b)))
def solve():
n, k = map(int, stdin.readline().split())
ans = 0
a = list(map(str.strip, stdin.readlines()))
b = set(a)
for i in range(n):
for j in range(i + 1, n):
if get(a[i], a[j]) in b:
ans += 1
print(ans // 3)
for _ in range(1):
solve() | FUNC_DEF IF VAR VAR RETURN VAR IF VAR STRING IF VAR STRING RETURN STRING RETURN STRING IF VAR STRING IF VAR STRING RETURN STRING RETURN STRING IF VAR STRING RETURN STRING RETURN STRING FUNC_DEF RETURN FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, k = tuple(map(int, input().strip().split()))
cartas, buscadas, sets = set(), {}, 0
for i in range(n - 1):
carta1 = input()
if carta1 in buscadas:
sets += buscadas[carta1]
for carta2 in cartas:
buscada = ""
for let in range(k):
c1 = carta1[let]
c2 = carta2[let]
if c1 == c2:
buscada += c1
elif c1 == "S" and c2 == "E" or c1 == "E" and c2 == "S":
buscada += "T"
elif c1 == "S" and c2 == "T" or c1 == "T" and c2 == "S":
buscada += "E"
else:
buscada += "S"
if buscada in buscadas:
buscadas[buscada] += 1
else:
buscadas[buscada] = 1
cartas.add(carta1)
cartafinal = input()
if cartafinal in buscadas:
sets += buscadas[cartafinal]
print(sets) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR DICT NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR IF VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING IF VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | import sys
from itertools import combinations
input = sys.stdin.readline
h = {"S": 1, "E": 2, "T": 3}
n, k = map(int, input().split())
strings = set([tuple(map(h.get, input().rstrip())) for _ in range(0, n)])
ans = 0
for a, b in combinations(strings, 2):
c = []
for i in range(0, k):
if a[i] == b[i]:
c.append(a[i])
else:
c.append(6 - a[i] - b[i])
if tuple(c) in strings:
ans += 1
print(ans // 3) | IMPORT ASSIGN VAR VAR ASSIGN VAR DICT STRING STRING STRING NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | import sys
input = sys.stdin.readline
n, k = list(map(int, input().split()))
arr = []
for i in range(n):
word = input().strip()
arr.append(word)
d = {}
for i in arr:
if i not in d:
d[i] = 0
ans = 0
for x in range(n):
for y in range(x + 1, n):
s = ""
for z in range(k):
if arr[x][z] == arr[y][z]:
s += arr[x][z]
else:
temp = arr[x][z] + arr[y][z]
if "S" not in temp:
s += "S"
elif "E" not in temp:
s += "E"
elif "T" not in temp:
s += "T"
if s in d:
ans += 1
print(ans // 3) | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR IF STRING VAR VAR STRING IF STRING VAR VAR STRING IF STRING VAR VAR STRING IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | import sys
from itertools import combinations
input = lambda: sys.stdin.readline().rstrip()
n, k = map(int, input().split())
li = []
for _ in range(n):
li.append(input())
se = set(li)
ans = 0
for x, y in combinations(li, 2):
tmp = []
for i in range(k):
if x[i] == y[i]:
tmp.append(x[i])
elif x[i] != "S" and y[i] != "S":
tmp.append("S")
elif x[i] != "E" and y[i] != "E":
tmp.append("E")
else:
tmp.append("T")
tmp = "".join(tmp)
if tmp in se:
ans += 1
print(ans // 3) | IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL STRING VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, m = input().split()
n, m = int(n), int(m)
d = {}
a = []
for i in range(n):
s = input()
d[s] = i
a.append(s)
t = ""
ans = 0
for i in range(n):
for j in range(n):
if j > i:
for k in range(m):
if a[i][k] == "T" and a[j][k] == "T":
t = t + "T"
if a[i][k] == "E" and a[j][k] == "E":
t = t + "E"
if a[i][k] == "S" and a[j][k] == "S":
t = t + "S"
if a[i][k] == "S" and a[j][k] == "E":
t = t + "T"
if a[i][k] == "S" and a[j][k] == "T":
t = t + "E"
if a[i][k] == "T" and a[j][k] == "E":
t = t + "S"
if a[i][k] == "T" and a[j][k] == "S":
t = t + "E"
if a[i][k] == "E" and a[j][k] == "T":
t = t + "S"
if a[i][k] == "E" and a[j][k] == "S":
t = t + "T"
if t in d:
ans += 1
t = ""
print(int(ans / 3)) | ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR STRING IF VAR VAR VAR STRING VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR STRING IF VAR VAR VAR STRING VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR STRING IF VAR VAR VAR STRING VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR STRING IF VAR VAR VAR STRING VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR STRING IF VAR VAR VAR STRING VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR STRING IF VAR VAR VAR STRING VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR STRING IF VAR VAR VAR STRING VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR STRING IF VAR VAR VAR STRING VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR STRING IF VAR VAR VAR NUMBER ASSIGN VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n = int(input().split()[0])
s = set()
r = 0
for _ in [0] * n:
t = (*map("SET".find, input()),)
for x in s:
r += (*((u != v) * (3 ^ u) ^ v for u, v in zip(x, t)),) in s
s |= {t}
print(r // 2) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR STRING FUNC_CALL VAR FOR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | N, K = map(int, input().split())
S = [input().replace("S", "0").replace("E", "1").replace("T", "2") for _ in range(N)]
X = [[int(a) for a in s] for s in S]
D = {int(s, 3): (1) for s in S}
def calc(a, b):
re = 0
for s, t in zip(a, b):
re = re * 3 + (s + t) * 2 % 3
return re
ans = 0
for i in range(N):
for j in range(i + 1, N):
if calc(X[i], X[j]) in D:
ans += 1
print(ans // 3) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING STRING STRING STRING STRING STRING VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, k = map(int, input().split())
cards = ["" for _ in range(n)]
for i in range(n):
cards[i] = input()
seen_cards = {}
ans = 0
for f_i in range(n):
first = cards[f_i]
for s_i in range(f_i + 1, n):
second = cards[s_i]
want_card = ""
for i in range(k):
if first[i] == second[i]:
want_card += second[i]
elif "S" != first[i] and "S" != second[i]:
want_card += "S"
elif "E" != first[i] and "E" != second[i]:
want_card += "E"
elif "T" != first[i] and "T" != second[i]:
want_card += "T"
if want_card in seen_cards:
ans += seen_cards[want_card]
if first in seen_cards:
seen_cards[first] += 1
else:
seen_cards[first] = 1
print(ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR IF STRING VAR VAR STRING VAR VAR VAR STRING IF STRING VAR VAR STRING VAR VAR VAR STRING IF STRING VAR VAR STRING VAR VAR VAR STRING IF VAR VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, m = list(map(int, input().split()))
l = []
for i in range(n):
l.append(input())
out = 0
d = {}
for i in l:
d[i] = 1
for i in range(n - 1):
a = l[i]
for j in range(i + 1, n):
b = l[j]
nw = ""
for k in range(m):
if a[k] == b[k]:
nw += a[k]
elif a[k] + b[k] == "ST" or a[k] + b[k] == "TS":
nw += "E"
elif a[k] + b[k] == "SE" or a[k] + b[k] == "ES":
nw += "T"
elif a[k] + b[k] == "ET" or a[k] + b[k] == "TE":
nw += "S"
if d.get(nw, 0):
out += 1
print(out // 3) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR STRING BIN_OP VAR VAR VAR VAR STRING VAR STRING IF BIN_OP VAR VAR VAR VAR STRING BIN_OP VAR VAR VAR VAR STRING VAR STRING IF BIN_OP VAR VAR VAR VAR STRING BIN_OP VAR VAR VAR VAR STRING VAR STRING IF FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, k = list(map(int, input().split()))
data = set()
mapping = {"S": 0, "E": 1, "T": 2}
for _ in range(n):
data.add(tuple(map(mapping.get, input())))
def find(x, y):
res = []
for i in range(k):
res.append((3 - (x[i] + y[i]) % 3) % 3)
return tuple(res)
res = 0
for x in data:
for y in data:
if x != y:
z = find(x, y)
if z in data:
res += 1
print(res // 6) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT STRING STRING STRING NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | import itertools
import sys
N, K = [int(i) for i in sys.stdin.readline().strip().split(" ")]
S = set()
for _ in range(N):
S.add(sys.stdin.readline().strip())
ans = 0
for c in itertools.combinations(S, 2):
NS = ""
for a, b in zip(c[0], c[1]):
if a == b:
NS += a
elif a == "S":
if b == "E":
NS += "T"
else:
NS += "E"
elif a == "E":
if b == "S":
NS += "T"
else:
NS += "S"
elif a == "T":
if b == "S":
NS += "E"
else:
NS += "S"
if NS in S:
ans += 1
print(ans // 3) | IMPORT IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING FOR VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR IF VAR STRING IF VAR STRING VAR STRING VAR STRING IF VAR STRING IF VAR STRING VAR STRING VAR STRING IF VAR STRING IF VAR STRING VAR STRING VAR STRING IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, k = [int(x) for x in input().split()]
l = []
for i in range(n):
l.append(input())
st = set(l)
total = ord("S") + ord("E") + ord("T")
ans = 0
for i in range(n - 1):
for j in range(i + 1, n):
c = ""
for z in range(k):
if l[i][z] == l[j][z]:
c = c + l[i][z]
else:
c = c + chr(total - ord(l[i][z]) - ord(l[j][z]))
if c in st:
ans += 1
print(ans // 3) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, k = map(int, input().split())
res, pool = 0, set()
for _ in range(n):
a = bytes(ord(c) + 1 & 3 for c in input())
for b in pool:
res += (
bytes(((0, 2, 1), (2, 1, 0), (1, 0, 2))[u][v] for u, v in zip(a, b)) in pool
)
pool.add(a)
print(res // 2) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR FOR VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, k = map(int, input().split())
ar = []
dic = {
"SS": "S",
"TT": "T",
"EE": "E",
"SE": "T",
"ES": "T",
"ST": "E",
"TS": "E",
"TE": "S",
"ET": "S",
}
for i in range(n):
ar.append(input())
arse = set(ar)
count = 0
for i in range(n):
for j in range(i + 1, n):
st = ""
for kk in range(k):
st += dic[str(ar[i][kk]) + str(ar[j][kk])]
if st in arse:
count += 1
print(count // 3) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | rev = {"ST": "E", "TS": "E", "SE": "T", "ES": "T", "TE": "S", "ET": "S"}
ans = 0
n, k = map(int, input().split())
a = []
s = {}
for i in range(n):
temp = input()
a.append(temp)
s[temp] = 1
for i in range(n):
for j in range(i + 1, n):
tf = ""
for l in range(k):
if a[i][l] == a[j][l]:
tf += a[i][l]
else:
tf += rev[a[i][l] + a[j][l]]
ans += int(bool(s.get(tf)))
print(ans // 3) | ASSIGN VAR DICT STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | def f():
n, k = [int(s) for s in input().split()]
if n <= 2:
return 0
cards = set()
nums = {"S": 0, "T": 1, "E": 2}
for i in range(n):
cards.add(tuple(nums[char] for char in input()))
def predict(a, b):
c = [None] * k
for i in range(k):
c[i] = (3 - a[i] - b[i]) % 3
return tuple(c)
ans = 0
for i in range(n - 2):
a = cards.pop()
for b in cards:
if predict(a, b) in cards:
ans += 1
ans //= 2
return ans
print(f()) | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT STRING STRING STRING NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, k = [int(x) for x in input().strip().split()]
V = []
for i in range(n):
V.append(input().strip())
M = set(V)
Z = ["S", "E", "T"]
cc = 0
for i in range(n):
for j in range(i + 1, n):
s = ""
for l in range(k):
if V[i][l] == V[j][l]:
s += V[i][l]
else:
for c in Z:
if V[i][l] != c and V[j][l] != c:
s += c
if s in M:
cc += 1
print(cc // 3) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, o = map(int, input().split())
b = []
ans = 0
brodi = set()
visto = []
for i in range(n):
b.append(input())
brodi.add(b[i])
visto.append(True)
for j in range(n):
for k in range(j + 1, n):
a = ""
for z in range(o):
padrao = ["S", "E", "T"]
if b[j][z] == b[k][z]:
a += b[j][z]
else:
for sla in padrao:
if sla != b[j][z] and sla != b[k][z]:
a += sla
break
if a in brodi:
ans += 1
print(ans // 3) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST STRING STRING STRING IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | import sys
input = sys.stdin.readline
n, k = [int(item) for item in input().split()]
cards = []
cnt = dict()
for _ in range(n):
c = input().rstrip()
if c not in cnt:
cnt[c] = 1
else:
cnt[c] += 1
ans = 0
keys = list(cnt.keys())
key_num = len(keys)
ord_sum = ord("S") + ord("E") + ord("T")
for i, key1 in enumerate(keys):
for j in range(i + 1, key_num):
key2 = keys[j]
key3 = ""
for k1, k2 in zip(key1, key2):
if k1 == k2:
key3 += k1
else:
key3 += chr(ord_sum - ord(k1) - ord(k2))
if key3 in cnt:
ans += cnt[key1] * cnt[key2] * cnt[key3]
print(ans // 3) | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING FOR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR STRING FOR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | n, k = map(int, input().split())
dic = {}
lis = []
for i in range(n):
s = input()
if s in dic:
dic[s] += 1
else:
dic[s] = 1
lis.append(s)
ans = 0
sum = ord("T") + ord("S") + ord("E")
for i in range(n):
for j in range(i + 1, n):
tmp = ""
for l in range(k):
if lis[i][l] == lis[j][l]:
tmp += lis[i][l]
else:
tmp += chr(sum - ord(lis[i][l]) - ord(lis[j][l]))
if tmp in dic:
ans += dic[tmp]
print(int(ans / 3)) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | ans = 0
V = []
M = {}
n, k = map(int, input().split())
for i in range(n):
str = input()
M[str] = 1
V.append(str)
for i in range(n - 1):
str1 = V[i]
for j in range(i + 1, n):
str2 = V[j]
str = ""
for K in range(k):
if str1[K] == str2[K]:
str += str1[K]
elif str1[K] is not "S" and str2[K] is not "S":
str += "S"
elif str1[K] is not "E" and str2[K] is not "E":
str += "E"
else:
str += "T"
if M.get(str) is not None:
ans += 1
print(ans // 3) | ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR IF VAR VAR STRING VAR VAR STRING VAR STRING IF VAR VAR STRING VAR VAR STRING VAR STRING VAR STRING IF FUNC_CALL VAR VAR NONE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | from sys import stdin, stdout
ans = ["SET", "EST", "TES", "ETS", "TSE", "STE"]
for _ in range(1):
n, k = map(int, stdin.readline().split())
d = dict()
ls = []
for i in range(n):
s = stdin.readline()
ls.append(s)
d[s] = i
cnt = 0
for i in range(n):
for j in range(i + 1, n):
s1 = ""
for f in range(k):
if ls[i][f] == ls[j][f]:
s1 += ls[i][f]
else:
for p in range(6):
if ls[i][f] == ans[p][0] and ls[j][f] == ans[p][1]:
s1 += ans[p][2]
break
s1 += "\n"
m = d.get(s1)
if m is not None and m > j:
cnt += 1
stdout.write(str(cnt)) | ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR NONE VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | cards = set()
n, k = (int(i) for i in input().split())
for i in range(n):
cards.add(input())
res = 0
for first in cards:
for second in cards:
third = []
for i in range(k):
if first[i] == second[i]:
third.append(first[i])
else:
third.append(
chr(ord("S") + ord("E") + ord("T") - ord(first[i]) - ord(second[i]))
)
if "".join(third) in cards:
res += 1
res -= n
res //= 6
print(res) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL STRING VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.
[Image]
Polina came up with a new game called "Hyperset". In her game, there are $n$ cards with $k$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $k = 4$.
Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.
Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.
-----Input-----
The first line of each test contains two integers $n$ and $k$ ($1 \le n \le 1500$, $1 \le k \le 30$) — number of cards and number of features.
Each of the following $n$ lines contains a card description: a string consisting of $k$ letters "S", "E", "T". The $i$-th character of this string decribes the $i$-th feature of that card. All cards are distinct.
-----Output-----
Output a single integer — the number of ways to choose three cards that form a set.
-----Examples-----
Input
3 3
SET
ETS
TSE
Output
1
Input
3 4
SETE
ETSE
TSES
Output
0
Input
5 4
SETT
TEST
EEET
ESTE
STES
Output
2
-----Note-----
In the third example test, these two triples of cards are sets: "SETT", "TEST", "EEET" "TEST", "ESTE", "STES" | def main():
n, k = map(int, input().split())
t = str.maketrans({"S": "0000100", "E": "0001000", "T": "0010000"})
xx = {int(input().translate(t), 2) for _ in range(n)}
m = int("0011100" * k, 2)
res = 0
while xx:
x = xx.pop()
res += sum(m - (x | y) ^ ((x & y) >> 2) * 31 & m in xx for y in xx)
print(res // 2)
main() | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR DICT STRING STRING STRING STRING STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP STRING VAR NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.