Codeforces Round 691 (Div. 2)
A
Red-Blue Shuffle
Codeforces
800
原题
←B →
翻译中…

There are $n$ cards numbered $1, \ldots, n$. The card $i$ has a red digit $r_i$ and a blue digit $b_i$ written on it.

翻译中…

We arrange all $n$ cards in random order from left to right, with all permutations of $1, \ldots, n$ having the same probability. We then read all red digits on the cards from left to right, and obtain an integer $R$. In the same way, we read all blue digits and obtain an integer $B$. When reading a number, leading zeros can be ignored. If all digits in a number are zeros, then the number is equal to $0$. Below is an illustration of a possible rearrangement of three cards, and how $R$ and $B$ can be found.

翻译中…

image

翻译中…

Two players, Red and Blue, are involved in a bet. Red bets that after the shuffle $R \gt B$, and Blue bets that $R \lt B$. If in the end $R = B$, the bet results in a draw, and neither player wins.

翻译中…

Determine, which of the two players is more likely (has higher probability) to win the bet, or that their chances are equal. Refer to the Note section for a formal discussion of comparing probabilities.

翻译中…

Input

翻译中…

The first line contains a single integer $T$ ($1 \leq T \leq 100$) — the number of test cases.

翻译中…

Descriptions of $T$ test cases follow. Each test case description starts with a line containing a single integer $n$ ($1 \leq n \leq 1000$) — the number of cards.

翻译中…

The following line contains a string of $n$ digits $r_1, \ldots, r_n$ — red digits on cards $1, \ldots, n$ respectively.

翻译中…

The following line contains a string of $n$ digits $b_1, \ldots, b_n$ — blue digits on cards $1, \ldots, n$ respectively.

翻译中…

Note that digits in the same line are not separated with any delimiters.

翻译中…

Output

翻译中…

Print $T$ answers for the test cases in order, one per line.

翻译中…

If Red has a strictly higher change to win, print "RED".

翻译中…

If Blue has a strictly higher change to win, print "BLUE".

翻译中…

If both players are equally likely to win, print "EQUAL".

翻译中…

Note that all answers are case-sensitive.

翻译中…

Note

翻译中…

Formally, let $n_R$ be the number of permutations of cards $1, \ldots, n$ such that the resulting numbers $R$ and $B$ satisfy $R \gt B$. Similarly, let $n_B$ be the number of permutations such that $R \lt B$. If $n_R \gt n_B$, you should print "RED". If $n_R \lt n_B$, you should print "BLUE". If $n_R = n_B$, print "EQUAL".

翻译中…

In the first sample case, $R = 777$ and $B = 111$ regardless of the card order, thus Red always wins.

翻译中…

In the second sample case, there are two card orders when Red wins, and four card orders when Blue wins:

翻译中…
  • order $1, 2, 3$: $314 \gt 159$;
  • order $1, 3, 2$: $341 \gt 195$;
  • order $2, 1, 3$: $134 \lt 519$;
  • order $2, 3, 1$: $143 \lt 591$;
  • order $3, 1, 2$: $431 \lt 915$;
  • order $3, 2, 1$: $413 \lt 951$.
翻译中…

Since $R \lt B$ is more frequent, the answer is "BLUE".

翻译中…

In the third sample case, $R = B$ regardless of the card order, thus the bet is always a draw, and both Red and Blue have zero chance to win.

翻译中…

样例

Input #1
3
3
777
111
3
314
159
5
09281
09281
Output #1
RED
BLUE
EQUAL
InputCopy OutputCopy
题目信息
题号
1459A
时间限制
2 s
内存限制
512 MB
标签
数学
概率论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。