Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

codechef solution

/*
Sum of product 2:
*/
/*
Python code:
a = [0]*1000001
b = [0]*1000001
d = [0]*1000001
m = 998244353

def f_1(x,y):
    if x<0 or y>x:
        return 0
    return a[x]*d[y]%m*d[x-y]%m

a[0] = b[0] = b[1] = d[0] = d[1] = 1

for i in range(1,1000001):
    a[i] = a[i-1]*i%m

for i in range(2,1000001):
    b[i] = m-m//i*b[m%i]%m

for i in range(2,1000001):
    d[i] = d[i-1]*b[i]%m

for _ in range(int(input())):
    n = int(input())
    arr = list(map(int,input().split()))[:n]
    c = c1 = r = 0
    for i in range(n):
        if arr[i] == 0:
            c += 1
        else:
            c1 += 1
    for i in range(c1+1):
        r = (r+i*f_1(c1+c-i,c))%m
    print((((r*(c+1)-f_1(c1+c-2,c-1))%m+m)%m+f_1(c1+c-2,c-1))*a[c1]%m*a[c]%m)
*/
/* C++ code:
*/
#include<bits/stdc++.h>
#define MOD 998244353
using namespace std;
long long fac[1000010], inv[1000010], finv[1000010];
long long C(long long x, long long y) {
  if (x < 0 || y > x)
    return 0;
  return fac[x] * finv[y] % MOD * finv[x - y] % MOD;
}
#define int long long
void solve() {
  int n,x,c0=0,c1=0,t=0;
  cin >> n;
  for(int i=1; i<=n; ++i) {
    cin >> x;
    c0+=x==0;
    c1+=x==1;
  }
  for(int i=0; i<=c1; ++i)
    t=(t+i*C(c1+c0-i,c0))%MOD;
  cout << (((t*(c0+1)-C(c1+c0-2,c0-1))%MOD+MOD)%MOD+C(c1+c0-2,c0-1))*fac[c1]%MOD*fac[c0]%MOD << endl;
}
signed main() {
  fac[0] = inv[0] = inv[1] = finv[0] = finv[1] = 1;
  for (long long i = 1; i <= 1000000; ++i)
    fac[i] = fac[i - 1] * i % MOD;
  for (long long i = 2; i <= 1000000; ++i)
    inv[i] = MOD - MOD / i * inv[MOD % i] % MOD;
  for (long long i = 2; i <= 1000000; ++i)
    finv[i] = finv[i - 1] * inv[i] % MOD;
  int T;
  cin >> T;
  while(T--) solve();
}
Comment

codechef solution

# name: MD Murad Hossain
# Eamil: muradhossainm01@gmail.com
# Accepted ho ja:

for _ in range(int(input())):
    n = int(input())
    arr = list(map(int,input().split()))[:n]
    arr_2 = sorted(arr)
    arr_3 = [arr.index(arr_2[0]),0]
    null_arr = [0]*n
    # loop:
    for i in range(2):
        arr_3[0] = 0
        # while condition:
        while arr_3[0] < n:
            # checking not same:
            if not null_arr[arr_3[0]] and arr[arr_3[0]] == arr_2[arr_3[1]]:
                null_arr[arr_3[0]] = 1
                arr_3[0] += 1
                arr_3[1] += 1
            else:
                arr_3[0] += 1
    # current check:
    if arr_3[0] == arr_3[1]:
        print("YES")
    else:
        print("NO")
# Program Finnished.
Comment

codechef solution

# Sum of Product 1:
# First system:

for _ in range(int(input())):
    n = int(input())
    arr = list(map(int,input().split()))[:n]
    res = 0
    c = 0
    for i in range(n):
        if arr[i] == 1:
            c += 1
        else:
            res += c*(c+1)//2
            c = 0
    res += c*(c+1)//2
    print(res)
    
# Second system:

'''
for _ in range(int(input())):
    n = int(input())
    arr = list(map(int,input().split()))[:n]
    res = 0
    c = 0
    for i in range(n):
        if arr[i] == 0:
            c = 0
        else:
            c += 1
        res += c
    print(res)
'''
Comment

codechef solution

# MD Murad Hossain
# Gamil: muradhossainm01@gmail.com
# Accepted Ho ja:

try:
    for _ in range(int(input())):
        n,m = map(int,input().split())
        if m < 2*n:
            print(m,m)
        elif m >= 2*n and m%n == 0:
            print(m,n)
        else:
            res = 0
            res_2 = 0
            div = m//2
            if m >= 2*n:
                div = 2*n
            Min = 0
            for i in range(n,div):
                d = m//i
                c_Min = (i*d)-i
                if c_Min > Min:
                    res = i
                    res_2 = i*d
                    Min = c_Min
            print(res,res_2)
except:
    pass
Comment

codechef solution

TATA BYE BYE => ABHAY IITP
Comment

PREVIOUS NEXT
Code Example
Python :: pygame scroll event 
Python :: discord.py read custom status 
Python :: how to merge dictionaries in python 
Python :: django queryset multiple filters 
Python :: regex find all french phone number python 
Python :: How to sort a Python dict by value 
Python :: find string in list and return index python 
Python :: HTML template with Django email 
Python :: difference between set and list in python 
Python :: change time format pm am in python 
Python :: create new dataframe from existing data frame python 
Python :: example of break statement in python 
Python :: cookies in django 
Python :: get data from model with field name in django 
Python :: negative indexing in python 
Python :: length of list without len function 
Python :: how to get input from user in pyqt5 
Python :: ngnix config 
Python :: import library to stop warnings in jupyter 
Python :: what is iteration in python 
Python :: DIVAB 
Python :: tkinter change button color smoothly 
Python :: how to iterate set in python 
Python :: django rest framework serializers 
Python :: how to find missing item in a list 
Python :: what is the weather today 
Python :: convert to ascii 
Python :: Install Pip 2 on ubuntu linux 
Python :: Python Print hour, minute, second and microsecond 
Python :: list of dictionary values 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =