We need to parse the problem. It's a typical assignment problem: We have two teams with N players each (N ≤ 20). Each pair of players from Finance (F_i) and Marketing (M_j) will play a one-on-one match. The match outcome is determined by skill levels? The description: "Each game carries 100 points which is awarded to the winner or divided (50-50) between the players if it ends in a draw (according to skill levels of the players)." So presumably, if two players of equal skill play, they draw, each gets 50 points. If one has higher skill, they win and get 100 points, the loser gets 0. This is typical: higher skill beats lower skill; draws only when exactly equal.
But wait: "according to skill levels of the players" suggests that maybe the result is deterministic: the player with higher skill wins, if equal it's a draw. So indeed, points are: Finance gets 100 if F_i > M_j, 50 if F_i == M_j, 0 if F_i < M_j.
But there might be nuance: "Jha, being an intern, won’t play (it’s a battle of legends, after all) and has been given one job: to fix matches in the 'hope' that he’ll match players of similar skill levels (so that matches aren’t one way and everybody enjoys)." This suggests he can assign each Finance player to a Marketing opponent (i.e., a bijection). He wants to maximize the total score of Finance team (sum of points from all matches). So we need to find an assignment (permutation) that maximizes sum over i of points(F_i, M_{p(i)}). That is a classic assignment problem: we can compute a profit matrix and find maximum total profit. Since N ≤ 20, we can do DP with bitmask (2^N). Or use Hungarian algorithm. But Hungarian is for minimizing cost; we can adapt. Since N small (20), bitmask DP O(N * 2^N) is fine (20*2^20 ≈ 20 million). That's acceptable.
But wait: Are there any twists? The sample: F = [8,5,3], M = [8,5,3]. If we match same order (8-8,5-5,3-3), each draw: Finance gets 50 each -> 150. But optimal: 8 vs 5 (win), 5 vs 3 (win), 3 vs 8 (loss) -> Finance gets 100+100+0=200. That's correct. So it's exactly that.
Thus the problem reduces to: given two lists of N integers each (1≤ skill ≤1000), find max sum of points where for each pairing we assign a distinct Marketing player to each Finance player, and points = 100 if Fi > Mj, 50 if equal, 0 if Fi < Mj.
We can compute DP: dp[mask] = maximum points for matching first k Finance players (where k = number of set bits in mask) with some set of Marketing players indicated by mask (which set of Marketing indices are used). Typically we iterate over Finance players in order. Let dp[mask] be max points for matching the first popcount(mask) Finance players to the Marketing players represented by mask. Then transition: for each new Finance player i = popcount(mask), we try all j not in mask, compute points(F_i, M_j), and set dp[mask | (1<<j)] = max(dp[mask | (1<<j)], dp[mask] + points). Initialize dp[0]=0, answer dp[(1<<N)-1]. That's O(N * 2^N). With N=20, that's fine.
Alternatively, we could use Hungarian with profit matrix and maximize sum. But DP is simpler.
Edge Cases: N=0? Not possible since at least 1. Skill values up to 1000, no special.
Now, output maximum possible score as integer.
Now, I need to parse input: first line N, second line N integers for Finance, third line N integers for Marketing.
I'll implement solve() reading from stdin. In Python, we can do DP.
But let's think about potential pitfalls: Are there ties? In DP, we need to be careful about indexing. Use list of skills.
We can compute points function: if Fi > Mj: 100; elif Fi == Mj: 50; else 0.
We need maximum sum. Since DP uses bitmask, we can do:
N = int(input().strip())
F = list(map(int, input().split()))
M = list(map(int, input().split()))
assert len(F)==N and len(M)==N
dp = [-1] * (1<<N)
dp[0] = 0
for mask in range(1<<N):
i = bin(mask).count('1') # number of matched finance players already
if i >= N: continue # Actually all matched, but we can still iterate.
for j in range(N):
if not (mask >> j) & 1:
new_mask = mask | (1<<j)
pts = 100 if F[i] > M[j] else (50 if F[i] == M[j] else 0)
if dp[new_mask] < dp[mask] + pts:
dp[new_mask] = dp[mask] + pts
print(dp[(1<<N)-1])
That's straightforward.
But note: The DP loops over mask up to 2^N. At each mask, we compute i = popcount. Could precompute popcount for all masks if desired. But N=20, 1e6 masks, popcount each maybe okay.
Potential improvement: If we do mask from 0 to (1<<N)-1, we always have i = popcount(mask) as the next Finance index