Trading Tuga
Kevin has been scrolling instagram reels lately and has convinced himself that he's gonna make it big making quantitative trading models in his bedroom. Specifically, he thinks there's alpha in looking at the market's order book balance at specific timestamps, and he thinks this edge applies to ALL stocks on his watchlist. Kevin has collected some data to backtest his theories on, with dominant market actions at each timestamp and a record of whether the stock goes up or down. He has collected n stocks that go up, and n stocks that go down, each with m timestamps, illustrated below. At each timestamp, Kevin has recorded whether the market is Buyer Dominant(B), Seller Dominant(S) or at an Equilibrium (E).
Timestamps: 1 2 3 4 5 6 7 ... M
"UP" Stock 1: B B E B B B B ... S
"UP" Stock 2: S B E B S B B ... B
"UP" Stock 3: S S E B S B B ... B
"DOWN" Stock 1: B E E B B B B ... S
"DOWN" Stock 2: B S E B S B B ... S
"DOWN" Stock 3: B S E B B B B ... S
Kevin is convinced looking at three distinct timestamps is all you need to perfectly predict whether the stock goes up or down. (e.g, looking at indices 1,2 and 3 can be used to predict stock movements, as there are no shared patterns between UP and DOWN stocks). Unfortunately, he isn't quite sure which 3 timestamps to look at.
Input
The first line contains 2 integers and
, the number of each stock type and the amount of timestamps.
The next
lines contain a string of length
, representing the sequence of dominant market actions for a stock that finished the day UP.
This is followed by
more lines containing similar market data, however for stocks that finished the day DOWN.
Output
Output the number of distinct sets of timestamps that are predictive. A set of timestamps are predictive if the stocks movement can be predicted with perfect accuracy across all stocks just by looking at those timestamps.
Examples
Input 1
3 8
BBEBBBBS
SBEBSBBB
SSEBSBBB
BEEBBBBS
BSEBSBBS
BSEBBBBS
Output 1
11
Input 2
5 5
BSEBE
BBEES
BBEBE
BBSSE
ESBBB
BEEBB
BSBBS
BSEEB
ESSBS
ESBBS
Output 2
6
The 6 sets of timestamp indices (assuming 0-indexing) are:
0 1 40 2 40 3 41 2 41 3 42 3 4- Instead of demonstrating for these sets that there are no shared patterns between the up stocks and down stocks, we show why another set i.e.
0 1 2isn't present. Taking only the first three movements, we have for up stocksBSE,BBE,BBE,BBS,ESB, and for down stocksBEE,BSB,BSE,ESS,ESB. This set of timestamps isn't enough to predict movement asBSEis present in both up and down, as well asESB.
Input 3
10 6
BBBBBB
BBSBBB
BBEBBB
SBBBBB
EBBBBB
BBBBBB
BBSBBB
BBEBBB
SBBBBB
EBBBBB
SSSBBB
SSEBBB
SSBBBB
ESSBBB
BSSBBB
SSSBBB
SSEBBB
SSBBBB
ESSBBB
BSSBBB
Output 3
6
Comments