Data race detection counter

Write codeHard30 minMicrosoft and Nvidia style

Your task

Given an interleaving of memory-access events on shared variables with no synchronization, detect data races. Each event is [thread, op, var] where op is "R" (read) or "W" (write). Two events on the SAME variable from DIFFERENT threads constitute a data race if at least one of them is a write. Return the number of distinct unordered variable-level conflicting thread pairs: for each variable, count the unordered pairs of distinct threads {t1, t2} such that the accesses to that variable by t1 and t2 conflict (some access among the two threads is a write). Each such variable-thread-pair is counted once.

Examples

count_races(events: list[list]) -> int
Example 1
Inputcount_races([[0, "W", "x"], [1, "R", "x"]])
Output1