CODECHEF: JUNE CHALLENGE | MathBuzz | PYTHON, JAVA, C++ SOLUTION

Codechef

View problem on codechef

There is an inter-city math competition among kk various prestigious top schools in the city. Some subset of schools will be selected to compete, where the ii-th school is selected with probability pi(mod998 244 353)pi(mod998 244 353). The schools are all selected independently from each other. It’s even possible that the number of selected schools will be 00 or 11, because the contest organizers are not very good mathematicians themselves.

Once the schools have been selected, each selected school must choose rr of its students to form a team. The ii-th school has aiai students in total it can choose from. Given a selection of the schools, you are interested in the number of ways teams can be formed. Two ways are considered different if there is at least one school that chose different sets of students for its team.

If the subset of schools is chosen according to the above process, find the expected number of ways they can form teams.

For the work from home Internship Programs : Click here to apply now

Input

  • The first line contains an integer rr.
  • The second line contains an integer kk.
  • The third line contains kk integers a1,…,aka1,…,ak.
  • The fourth line contains kk integers p1,…,pkp1,…,pk.

Output

Output the expected number of ways to form teams, modulo 998244353998244353.

Constraints

  • 1≤ai≤1091≤ai≤109
  • 1≤k≤2⋅1051≤k≤2⋅105
  • 1≤r≤1051≤r≤105
  • 1≤pi<998 244 3531≤pi<998 244 353

Subtasks

Subtask 1 (10 points): r≤100r≤100

Subtask 2 (90 points): Original constraints.

Sample Input

1
2
2 2
1 1

Sample Output

4

SOLUTION

Due to copyright issues we won't be able to update the solution here immediately. However you can download the code file from our telegram channel. So join our telegram channel for further updates. Keep tracking, the solution will be updated on this website soon.
  • HACKEREARTH IS HIRING FOR INTERN || APPLY NOW
  • INTEL IS HIRING FOR SOFTWARE DEVELOPER INTERN || APPLY Now
  • DATA SCIENCE INTERNSHIP | SONY RESEARCH INDIA || APPLY NOW

Read more post Here

Leave a Comment

Your email address will not be published. Required fields are marked *

x