CF1156F.Card Bag

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You have a bag which contains nn cards. There is a number written on each card; the number on ii -th card is aia_i .

You are playing the following game. During each turn, you choose and remove a random card from the bag (all cards that are still left inside the bag are chosen equiprobably). Nothing else happens during the first turn — but during the next turns, after removing a card (let the number on it be xx ), you compare it with the card that was removed during the previous turn (let the number on it be yy ). Possible outcomes are:

  • if x<yx < y , the game ends and you lose;
  • if x=yx = y , the game ends and you win;
  • if x>yx > y , the game continues.

If there are no cards left in the bag, you lose. Cards are not returned into the bag after you remove them.

You have to calculate the probability of winning in this game. It can be shown that it is in the form of PQ\frac{P}{Q} where PP and QQ are non-negative integers and Q0Q \neq 0 , PQP \le Q . Output the value of PQ1 (mod  998244353)P \cdot Q^{−1} ~(mod ~~ 998244353) .

输入格式

The first line contains one integer nn ( 2n50002 \le n \le 5000 ) — the number of cards in the bag.

The second live contains nn integers a1,a2,ana_1, a_2, \dots a_n ( 1ain1 \le a_i \le n ) — the ii -th integer is the number written on the ii -th card.

输出格式

Print one integer — the probability of winning in this game modulo 998244353998244353 .

输入输出样例

  • 输入#1

    5
    1 1 4 2 3
    

    输出#1

    299473306
    
  • 输入#2

    2
    2 2
    

    输出#2

    1
    
  • 输入#3

    5
    4 5 1 3 2
    

    输出#3

    0
    
  • 输入#4

    4
    1 3 4 3
    

    输出#4

    748683265
    

说明/提示

In the first test case the probability of winning is 110\frac{1}{10} .

In the second test case the probability of winning is 11 .

In the third test case the probability of winning is 00 .

In the fourth test case the probability of winning is 14\frac{1}{4} .

首页