#include<bits/stdc++.h>
#define R rand()*rand()%n+1
#define max(a,b) ((a)>(b)?(a):(b))
using namespace std;
int n,m,k,x,y,z,f[1000039],maxn1,maxn2;
int main(){
	srand((unsigned int) time(0));
	register int i;
	scanf("%d",&m);
	n=(1<<m)-1;
	for(i=1;i<=10;i++){
		x=R;y=R;z=R;
		while(y==x) y=R;
		while(z==y||z==x) z=R;
		printf("? %d %d %d\n",x,y,z);
		fflush(stdout);
		scanf("%d",&x);
		f[x]++;
	}
	for(i=1;i<=n;i++)maxn1=max(maxn1,f[i]);
	for(i=1;i<=n;i++) if(maxn1==f[i]){f[i]=0;maxn1=i;break;}
	for(i=1;i<=n;i++) maxn2=max(maxn2,f[i]);
	for(i=1;i<=n;i++) if(f[i]==maxn2){f[i]=0;maxn2=i;break;}
	for(i=1;i<=n;i++){
		if(i==maxn1||i==maxn2) continue;
		printf("? %d %d %d\n",maxn1,maxn2,i);
		fflush(stdout);
		scanf("%d",&x);
		if(x!=maxn1&&x!=maxn2) {printf("! %d",i);return 0;}
	}
}


#include<bits/stdc++.h>
#define R rand()*rand()%n+1
#define max(a,b) ((a)>(b)?(a):(b))
using namespace std;
int n,m,k,x,y,z,f[1000039],maxn1,maxn2;
int main(){
	srand((unsigned int) time(0)); srand((unsigned int) time(0));
	register int i;
	scanf("%d",&m);
	n=(1<<m)-1;
	for(i=1;i<=300;i++){
		x=R;y=R;z=R;
		while(y==x) y=R;
		while(z==y||z==x) z=R;
		printf("? %d %d %d\n",x,y,z);
		fflush(stdout);
		scanf("%d",&x);
		f[x]++;
	}
	for(i=1;i<=n;i++)maxn1=max(maxn1,f[i]);
	for(i=1;i<=n;i++) if(maxn1==f[i]){f[i]=0;maxn1=i;break;}
	for(i=1;i<=n;i++) maxn2=max(maxn2,f[i]);
	for(i=1;i<=n;i++) if(f[i]==maxn2){f[i]=0;maxn2=i;break;}
	//printf("%d %d\n",maxn1,maxn2);
	for(i=1;i<=n;i++){
		if(i==maxn1||i==maxn2) continue;
		printf("? %d %d %d\n",maxn1,maxn2,i);
		fflush(stdout);
		scanf("%d",&x);
		if(x!=maxn1&&x!=maxn2) {printf("! %d",i);return 0;}
	}
}


#include<bits/stdc++.h>
#define R rand()*rand()%n+1
#define max(a,b) ((a)>(b)?(a):(b))
using namespace std;
int n,m,k,x,y,z,f[1000039],maxn1,maxn2;
int main(){
	srand((unsigned int) time(0));
	register int i;
	scanf("%d",&m);
	n=(1<<m)-1;
	for(i=1;i<=420;i++){
		x=R;y=R;z=R;
		while(y==x) y=R;
		while(z==y||z==x) z=R;
		printf("? %d %d %d\n",x,y,z);
		fflush(stdout);
		scanf("%d",&x);
		f[x]++;
	}
	for(i=1;i<=n;i++)maxn1=max(maxn1,f[i]);
	for(i=1;i<=n;i++) if(maxn1==f[i]){f[i]=0;maxn1=i;break;}
	for(i=1;i<=n;i++) maxn2=max(maxn2,f[i]);
	for(i=1;i<=n;i++) if(f[i]==maxn2){f[i]=0;maxn2=i;break;}
	//printf("%d %d\n",maxn1,maxn2);
	for(i=1;i<=n;i++){
		if(i==maxn1||i==maxn2) continue;
		printf("? %d %d %d\n",maxn1,maxn2,i);
		fflush(stdout);
		scanf("%d",&x);
		if(x!=maxn1&&x!=maxn2) {printf("! %d",i);return 0;}
	}
}


#include<bits/stdc++.h>
#define R rand()*rand()%n+1
#define max(a,b) ((a)>(b)?(a):(b))
using namespace std;
int n,m,k,x,y,z,f[1000039],maxn1,maxn2;
int main(){
	srand((unsigned int) time(0));
	register int i;
	scanf("%d",&m);
	n=(1<<m)-1;
	for(i=1;i<=10;i++){
		x=R;y=R;z=R;
		while(y==x) y=R;
		while(z==y||z==x) z=R;
		printf("? %d %d %d\n",x,y,z);
		fflush(stdout);
		scanf("%d",&x);
		f[x]++;
	}
	for(i=1;i<=n;i++)maxn1=max(maxn1,f[i]);
	for(i=1;i<=n;i++) if(maxn1==f[i]){f[i]=0;maxn1=i;break;}
	for(i=1;i<=n;i++) maxn2=max(maxn2,f[i]);
	for(i=1;i<=n;i++) if(f[i]==maxn2){f[i]=0;maxn2=i;break;}
	//printf("%d %d\n",maxn1,maxn2);
	for(i=1;i<=n;i++){
		if(i==maxn1||i==maxn2) continue;
		printf("? %d %d %d\n",maxn1,maxn2,i);
		fflush(stdout);
		scanf("%d",&x);
		if(x!=maxn1&&x!=maxn2) {printf("! %d",i);return 0;}
	}
}


#include<bits/stdc++.h>
#define R rand()*rand()%n+1
#define max(a,b) ((a)>(b)?(a):(b))
using namespace std;
int n,m,k,x,y,z,f[1000039],maxn1,maxn2;
int main(){
	srand((unsigned int) time(0));
	register int i;
	scanf("%d",&m);
	n=(1<<m)-1;
	for(i=1;i<=422;i++){
		x=R;y=R;z=R
		while(y==x) y=R;
		while(z==y||z==x) z=R;
		printf("? %d %d %d\n",x,y,z);
		fflush(stdout);
		scanf("%d",&x);
		f[x]++;
	}
	for(i=1;i<=n;i++)maxn1=max(maxn1,f[i]);
	for(i=1;i<=n;i++) if(maxn1==f[i]){f[i]=0;maxn1=i;break;}
	for(i=1;i<=n;i++) maxn2=max(maxn2,f[i]);
	for(i=1;i<=n;i++) if(f[i]==maxn2){f[i]=0;maxn2=i;break;}
	for(i=1;i<=n;i++){
		if(i==maxn1||i==maxn2) break;
		printf("? %d %d %d\n",maxn1,maxn2,i);
		fflush(stdout);
		scanf("%d",&x);
		if(x!=maxn1&&x!=maxn2) {printf("! %d",i);return 0;}
	}
}


int h, n, cnt[T], p[T];

V<int> e[T];
#define pb push_back
void ins(int x,int y) {e[x].pb(y); e[y].pb(x);}

#define op false

int fa[T],dep[T],c;

void dfs(int x) {
	c++;
	for(int y:e[x]) if(fa[x] ^ y)
		fa[y]=x,dep[y]=dep[x]+1,dfs(y);
}

int ask(int x,int y,int z) {
	if(x == y) return x;
	if(x == z) return z;
	if(y == z) return z;
	if(op) {
		fa[z]=dep[z]=0; c=0;
		dfs(z);
		assert(c == n);
		while(x^y) {
			if(dep[x]<dep[y]) swap(x,y);
			x=fa[x];
		}
		return x;
	}
	printf("? "); pr1(x); pr1(y); pr2(z);
	fflush(stdout); qr(x);
	assert(x>0);
	return x;
}

mt19937 rnd(time(0));
int random(int x) {return rnd()%x+1;}

bool cmp(int x,int y) {return cnt[x]>cnt[y];}

void solve() {
	qr(h); n=(1<<h)-1;
	int rt=-1;
	if(op) {
		FOR(i,n) {
			int x; qr(x);
			if(x) ins(x,i);
			else rt=i;
		}
	}
	FOR(i,420) {
		int x=random(n),y=random(n),z=random(n),w;
		if(x == y || y == z || x == z) {i--; continue;}
		w=ask(x,y,z);
		if(w ^ x && w ^ y && w ^ z) cnt[w]++;
	}
	iota(p+1,p+n+1,1);
	sort(p+1,p+n+1,cmp);
	int x=p[1],y=p[2];
	FOR(i,n) {
		int z=ask(x,y,i);
		if(z ^ x && z ^ y) {
			printf("! %d\n",i);
			if(op)
				assert(i == rt);
			return ;
		}
	}
}

int main() {
	if(op) freopen("a.in","r",stdin);
    int T = 1;
//    qr(T);
    while (T--)
        solve();
    return 0;
}


#include <bits/stdc++.h>

int main() {
	using namespace std;
	ios_base::sync_with_stdio(false), cin.tie(nullptr);

	int H; cin >> H;
	const int N = (1 << H) - 1;

	auto query = [&](array<int, 3> a) -> int {
		if (a[0] == a[1]) return a[0];
		if (a[1] == a[2]) return a[1];
		if (a[0] == a[2]) return a[0];

		cout << '?' << ' ' << a[0]+1 << ' ' << a[1]+1 << ' ' << a[2]+1 << '\n' << flush;
		int res; cin >> res;
		if (res == -1) exit(0);
		return res-1;
	};
	auto finish = [&](int ans) {
		cout << '!' << ' ' << ans+1 << '\n' << flush;
		exit(0);
	};

	mt19937 mt(48);
	map<int, int> mp;
	for (int i = 0; i < 420; i++) {
		int a = (mt() % N);
		int b = (mt() % N);
		int c = (mt() % N);
		if (a == b || b == c || c == a) {
			i--;
			continue;
		}
		int v = query({a,b,c});
		if (v == a || v == b || v == c) continue;
		cerr << "good " << v << '\n';
		mp[v]++;
	}
	vector<pair<int, int>> freq; freq.reserve(mp.size());
	for (auto it : mp) {
		freq.push_back({it.second, it.first});
	}
	sort(freq.begin(), freq.end());
	reverse(freq.begin(), freq.end());

	if (freq.size() < 2) {
		assert(false);
	}

	int x = freq[0].second;
	int y = freq[1].second;
	cerr << x << ' ' << y << '\n';

	set<int> on_path;
	set<int> is_resp;
	for (int i = 0; i < N; i++) {
		if (i == x || i == y) continue;
		int v = query({x,y,i});
		if (v == x) {
			on_path.insert(x);
			x = i;
		} else if (v == y) {
			on_path.insert(y);
			y = i;
		} else if (v == i) {
			on_path.insert(i);
		} else {
			is_resp.insert(v);
		}
	}

	for (int v : on_path) {
		if (is_resp.count(v)) continue;
		finish(v);
	}

	return 0;
}


#include <cstdio>
#include <map>
using std::map;
using std::pair;

int read(){
	int x =0; char c =getchar(); bool f =0;
	while(c < '0' || c > '9') (c == '-') ? f =1, c =getchar() : c =getchar();
	while(c >= '0' && c <= '9') x =(x<<1)+(x<<3)+(48^c), c =getchar();
	return (f) ? -x : x;
}

inline int Ask(const int &u, const int &v, const int &w){
	printf("? %d %d %d\n", u, v, w);
	fflush(stdout);
	return read();
}

map<int, int> Map, Map2;

int main(){
	srand(19260817);
	int h =read();
	int n =(1<<h)-1;
	for(int i =0; i < 400; ++i){
		int u =((rand()<<16)|rand())%n+1, v =((rand()<<16)|rand())%n+1, w =((rand()<<16)|rand())%n+1;
		while(v == u)
			v =(v-1 + 1)%n+1;
		while(w == u || w == v)
			w =(w-1 + 1)%n+1;
		int lca =Ask(u, v, w);
		if(!Map.count(lca))
			Map.insert(pair<int, int>(lca, 1));
		else
			++Map.find(lca)->second;
	}
	for(pair<int, int>pad:Map)
		Map2.insert(pair<int, int>(pad.second, pad.first));
	int son1 =(--Map2.end())->second, son2 =(--(--Map2.end()))->second;
	for(int i =1; i <= n; ++i)
		if(i != son1 && i != son2)
			if(Ask(son1, son2, i) == i){
				printf("! %d", i);
				return 0;
			}
}


#include <cstdio>
#include <map>
using std::map;
using std::pair;

int read(){
	int x =0; char c =getchar(); bool f =0;
	while(c < '0' || c > '9') (c == '-') ? f =1, c =getchar() : c =getchar();
	while(c >= '0' && c <= '9') x =(x<<1)+(x<<3)+(48^c), c =getchar();
	return (f) ? -x : x;
}

inline int Ask(const int &u, const int &v, const int &w){
	printf("? %d %d %d\n", u, v, w);
	fflush(stdout);
	return read();
}

map<int, int> Map, Map2;

int main(){
	srand(19260817);
	int h =read();
	int n =(1<<h)-1;
	for(int i =0; i < 420; ++i){
		int u =((rand()<<16)|rand())%n+1, v =((rand()<<16)|rand())%n+1, w =((rand()<<16)|rand())%n+1;
		while(v == u)
			v =(v-1 + 1)%n+1;
		while(w == u || w == v)
			w =(w-1 + 1)%n+1;
		int lca =Ask(u, v, w);
		if(!Map.count(lca))
			Map.insert(pair<int, int>(lca, 1));
		else
			++Map.find(lca)->second;
	}
//	for(pair<int, int>pad:Map)
	//	Map2.insert(pair<int, int>(pad.second, pad.first));
	int son1 =(--Map.end())->second, son2 =(--(--Map.end()))->second;
	for(int i =1; i <= n; ++i)
		if(i != son1 && i != son2)
			if(Ask(son1, son2, i) == i){
				printf("! %d", i);
				return 0;
			}
}


#include <cstdio>
#include <map>
using std::map;
using std::pair;

int read(){
	int x =0; char c =getchar(); bool f =0;
	while(c < '0' || c > '9') (c == '-') ? f =1, c =getchar() : c =getchar();
	while(c >= '0' && c <= '9') x =(x<<1)+(x<<3)+(48^c), c =getchar();
	return (f) ? -x : x;
}

inline int Ask(const int &u, const int &v, const int &w){
	printf("? %d %d %d\n", u, v, w);
	fflush(stdout);
	return read();
}

map<int, int> Map, Map2;

int main(){
	srand(19260817);
	int h =read();
	int n =(1<<h)-1;
	for(int i =0; i < n+420; ++i){
		int u =((rand()<<16)|rand())%n+1, v =((rand()<<16)|rand())%n+1, w =((rand()<<16)|rand())%n+1;
		while(v == u)
			v =(v-1 + 1)%n+1;
		while(w == u || w == v)
			w =(w-1 + 1)%n+1;
		int lca =Ask(u, v, w);
		if(!Map.count(lca))
			Map.insert(pair<int, int>(lca, 1));
		else
			++Map.find(lca)->second;
	}
	for(pair<int, int>pad:Map)
		Map2.insert(pair<int, int>(pad.second, pad.first));
	int son1 =(--Map2.end())->second, son2 =(--(--Map2.end()))->second;
	for(int i =1; i <= n; ++i)
		if(i != son1 && i != son2)
			if(Ask(son1, son2, i) == i){
				printf("! %d", i);
				return 0;
			}
}


#include <bits/stdc++.h>
using namespace std;

std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());
int query(int u, int v, int w)
{
    cout << "? " << u << " " << v << " " << w << endl;
    cout.flush();
    int x;
    cin >> x;
    return x;
}
int main()
{
    int h;
    cin >> h;
    int n = (1 << h) - 1;
    vector<int> cnt(n), p(n);
    iota(p.begin(), p.end(), 1);
    for (int i = 1; i <= 420; i++)
    {
        int u = rnd() % n + 1, v = rnd() % n + 1, w = rnd() % n + 1;
        while (u == v || w == v || w == u)
            u = rnd() % n + 1, v = rnd() % n + 1, w = rnd() % n + 1;
        cnt[query(u, v, w)]++;
    }
    sort(p.begin(), p.end(), [&](int x, int y) { return cnt[x] > cnt[y]; });
    int u = p[0], v = p[1];
    for (int i = 1; i <= n; i++)
    {
        if (u != i && v != i && query(u, v, i) == i)
        {
            cout << "! " << i << endl;
            return 0;
        }
    }
}


#include <bits/stdc++.h>

int query(int u, int v, int w)
{
    std::cout << "? " << u << " " << v << " " << w << std::endl;
    int res;
    std::cin >> res;
    return res;
}

int main()
{

    int h;
    std::cin >> h;
    std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());

    int n = (1 << h) - 1;
    std::vector<int> cnt(n + 1);
    for (int i = 1; i <= 10; ++i)
    {
        int u = rnd() % n + 1, v = rnd() % n + 1, w = rnd() % n + 1;
        while (u == v)
            v = rnd() % n + 1;
        while (u == w || v == w)
            w = rnd() % n + 1;
        ++cnt[query(u, v, w)];
    }

    std::vector<int> p(n);
    std::iota(p.begin(), p.end(), 1);
    std::sort(p.begin(), p.end(), [&](int u, int v) { return cnt[u] > cnt[v]; });

    int u = p[0], v = p[1];
    std::cout << " " << u << " " << v << std::endl;
    // for (int i = 1; i <= n; ++i)
    // {
    //     if (u != i && v != i && query(i, u, v) == i)
    //     {
    //         std::cout << "! " << i << std::endl;
    //         return 0;
    //     }
    // }

    assert(false);
}


#include <bits/stdc++.h>

int query(int u, int v, int w)
{
    std::cout << "? " << u << " " << v << " " << w << std::endl;
    int res;
    std::cin >> res;
    return res;
}

int main()
{

    int h;
    std::cin >> h;
    std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());

    int n = (1 << h) - 1;
    std::vector<int> cnt(n + 1);
    for (int i = 1; i <= 10; ++i)
    {
        int u = rnd() % n + 1, v = rnd() % n + 1, w = rnd() % n + 1;
        while (u == v)
            v = rnd() % n + 1;
        while (u == w || v == w)
            w = rnd() % n + 1;
        ++cnt[query(u, v, w)];
    }

    std::vector<int> p(n);
    std::iota(p.begin(), p.end(), 1);
    std::sort(p.begin(), p.end(), [&](int u, int v) { return cnt[u] > cnt[v]; });

    int u = p[0], v = p[1];
    std::cout << "! "<< u << " " << v << std::endl;
    // for (int i = 1; i <= n; ++i)
    // {
    //     if (u != i && v != i && query(i, u, v) == i)
    //     {
    //         std::cout << "! " << i << std::endl;
    //         return 0;
    //     }
    // }

    assert(false);
}


#include <bits/stdc++.h>

int query(int u, int v, int w)
{
    std::cout << "? " << u << " " << v << " " << w << std::endl;
    int res;
    std::cin >> res;
    return res;
}

int main()
{

    int h;
    std::cin >> h;
    std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());

    int n = (1 << h) - 1;
    std::vector<int> cnt(n + 1);
    for (int i = 1; i <= 10; ++i)
    {
        int u = rnd() % n + 1, v = rnd() % n + 1, w = rnd() % n + 1;
        while (u == v)
            v = rnd() % n + 1;
        while (u == w || v == w)
            w = rnd() % n + 1;
        ++cnt[query(u, v, w)];
    }

    std::vector<int> p(n);
    std::iota(p.begin(), p.end(), 1);
    std::sort(p.begin(), p.end(), [&](int u, int v) { return cnt[u] > cnt[v]; });

    int u = p[0], v = p[1];
    for (int i = 1; i <= n; ++i)
    {
        if (u != i && v != i && query(i, u, v) == i)
        {
            std::cout << "! " << i << std::endl;
            return 0;
        }
    }
    std::cout << u << " " << v << std::endl;
    assert(false);
}


#include <bits/stdc++.h>
using namespace std;

std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());
int query(int u, int v, int w)
{
    cout << "? " << u << " " << v << " " << w << endl;
    cout.flush();
    int x;
    cin >> x;
    return x;
}
int main()
{
    int h;
    cin >> h;
    int n = (1 << h) - 1;
    vector<int> cnt(n+1), p(n);
    iota(p.begin(), p.end(), 1);
    for (int i = 1; i <= 420; i++)
    {
        int u = rnd() % n + 1, v = rnd() % n + 1, w = rnd() % n + 1;
        while (u == v || w == v || w == u)
            u = rnd() % n + 1, v = rnd() % n + 1, w = rnd() % n + 1;
        cnt[query(u, v, w)]++;
    }
    sort(p.begin(), p.end(), [&](int x, int y) { return cnt[x] > cnt[y]; });
    int u = p[0], v = p[1];
    for (int i = 1; i <= n; i++)
    {
        if (u != i && v != i && query(u, v, i) == i)
        {
            cout << "! " << i << endl;
            return 0;
        }
    }
}


#include <bits/stdc++.h>

int query(int u, int v, int w)
{
    std::cout << "? " << u << " " << v << " " << w << std::endl;
    int res;
    std::cin >> res;
    return res;
}

int main()
{

    int h;
    std::cin >> h;
    std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());

    int n = (1 << h) - 1;
    std::vector<int> cnt(n + 1);
    for (int i = 1; i <= 10; ++i)
    {
        int u = rnd() % n + 1, v = rnd() % n + 1, w = rnd() % n + 1;
        while (u == v)
            v = rnd() % n + 1;
        while (u == w || v == w)
            w = rnd() % n + 1;
        ++cnt[query(u, v, w)];
    }

    std::vector<int> p(n);
    std::iota(p.begin(), p.end(), 1);
    std::sort(p.begin(), p.end(), [&](int u, int v) { return cnt[u] > cnt[v]; });

    int u = p[0], v = p[1];
    std::cout << "?" << u << " " << v <<" "<<"1"<< std::endl;
    // for (int i = 1; i <= n; ++i)
    // {
    //     if (u != i && v != i && query(i, u, v) == i)
    //     {
    //         std::cout << "! " << i << std::endl;
    //         return 0;
    //     }
    // }

    assert(false);
}


import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            int t = sc.nextInt();
            for (int i = 0; i < t; i++) {
                int n = sc.nextInt();
                for (int j = 0; j < n; j++) {
                    out.print(2 + " ");
                }
                out.println();
            }
        }
    }
}


import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t =sc.nextInt();
        while(t-->0){
            int n = sc.nextInt();
            for(int i =1; i<=n;i+=2){
                System.out.print(i +" ");
            }
        }
    }
}


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t =sc.nextInt();
        while(t-->0){
            int n = sc.nextInt();
            while(n-->0){
                System.out.print("1 ");
            }
        }

    }
}


import java.util.Scanner;

public class A {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t-- >0){
            int n = sc.nextInt();
            for(int i = 1; i <=n; i++){
                if(i > 50){
                    System.out.print((i-50)*2 + " ");
                }else {
                    System.out.print(i * 2 + " ");
                }
            }
            System.out.println();
        }
    }
}


import java.util.Scanner;

public class A {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t-- >0){
            int n = sc.nextInt();
            for(int i = 1; i <=n; i++){
//                if(i > 50){
//                    System.out.print((i-50)*2 + " ");
//                }else {
//                    System.out.print(i * 2 + " ");
//                }
                System.out.println(1 + " ");
            }
            System.out.println();
        }
    }
}


import java.util.Arrays;
import java.util.*;
import java.util.Scanner;
public class Main
{
	public static void main(String[] args)
	{
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		while(n>0) {
			int t=sc.nextInt();
			int a[]=new int[t];
			for(int i=0;i<t;i++) {
				a[i]=1;
			}
			for(int i=0;i<t;i++)
			System.out.print(a[i]+" ");
			System.out.print("\n");
			n--;
		}

	}
}


import java.util.Arrays;
import java.util.*;
import java.util.Scanner;
public class Main
{
	public static void main(String[] args)
	{
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		while(n>0) {
			int t=sc.nextInt();
			int a[]=new int[t];
			for(int i=0;i<t;i++) {
				a[i]=1;
			}
			System.out.println(Arrays.toString(a));
			t--;
		}

	}
}


import java.util.Scanner;

public class challenge{
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args){
        int t = sc.nextInt();
        while(t-- > 0){
            int n = sc.nextInt();
            for(int i=1;i<=n;i++){
                System.out.print(i*n+" ");
            }
            System.out.println();
        }
    }
}


import java.util.Scanner;

public class challenge{
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args){
        int t = sc.nextInt();
        while(t-- > 0){
            int n = sc.nextInt();
            for(int i=0;i<n;i++){
                System.out.print(i*n+" ");
            }
            System.out.println();
        }
    }
}


import java.util.Scanner;

public class challenge{
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args){
        int t = sc.nextInt();
        while(t-- > 0){
            int n = sc.nextInt();
            for(int i=1;i<n;i++){
                System.out.print(i*n+" ");
            }
            System.out.println();
        }
    }
}


import java.util.Scanner;

public class challenge{
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args){
        int t = sc.nextInt();
        while(t-- > 0){
            int n = sc.nextInt();
            for(int i=1;i<=n;i++){
                System.out.print(2+" ");
            }
            System.out.println();
        }
    }
}


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int tc = sc.nextInt();
        while (tc-- > 0) {
            int n = sc.nextInt();
            for (int i = 0; i < n; i++) {
                System.out.print("1 ");
            }
            System.out.println();
        }
    }
}


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int tc = sc.nextInt();
        while (tc-- > 0) {
            int n = sc.nextInt();
            for (int i = 0; i < n; i++) {
                System.out.print("1 ");
            }
            System.out.println();
        }
    }
}


package competative_programming;

import jdk.swing.interop.SwingInterOpUtils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;

public class c {

    public static void main(String[] args) {
        FastScanner fs=new FastScanner();
        int T=fs.nextInt();

        for (int tt=0; tt<T; tt++) {
            int n = fs.nextInt();
            for(int i=0;i<n;i++){
                if(i==n-1)
                    System.out.print("1");
                else
                 System.out.print(1+" ");
            }
            System.out.println();

        }

    }

    static void sort(int[] a) {
        ArrayList<Integer> l=new ArrayList<>();
        for (int i:a) l.add(i);
        Collections.sort(l);
        for (int i=0; i<a.length; i++) a[i]=l.get(i);
    }

    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        String next() {
            while (!st.hasMoreTokens())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        int[] readArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }
        long nextLong() {
            return Long.parseLong(next());
        }
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;

public class c {

    public static void main(String[] args) {
        FastScanner fs=new FastScanner();
        int T=fs.nextInt();

        for (int tt=0; tt<T; tt++) {
            int n = fs.nextInt();
            for(int i=0;i<n;i++){
                if(i==n-1)
                    System.out.print("1");
                else
                 System.out.print(1+" ");
            }
            System.out.println();

        }

    }

    static void sort(int[] a) {
        ArrayList<Integer> l=new ArrayList<>();
        for (int i:a) l.add(i);
        Collections.sort(l);
        for (int i=0; i<a.length; i++) a[i]=l.get(i);
    }

    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        String next() {
            while (!st.hasMoreTokens())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        int[] readArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }
        long nextLong() {
            return Long.parseLong(next());
        }
    }

}


//import java.util.Arrays;
import java.util.Scanner;

public class Code {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        for(int i=0;i<t;i++){
            int n = sc.nextInt();
//            int[] a = new int[n];
            for(int j=0;j<n;j++){
                System.out.print(1);
            }
            System.out.println();
        }
    }
}


import java.util.Arrays;
import java.util.Scanner;

public class Code {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        for(int i=0;i<t;i++){
            int n = sc.nextInt();
            int[] a = new int[n];
            for(int j=0;j<n;j++){
                a[j] = 1;
            }
            System.out.println(Arrays.toString(a));
        }
    }
}


//import java.util.Arrays;
import java.util.Scanner;

public class Code {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        for(int i=0;i<t;i++){
            int n = sc.nextInt();
//            int[] a = new int[n];
            for(int j=0;j<n;j++){
                System.out.print(1 + " ");
            }
            System.out.println();
        }
    }
}


import java.util.Scanner;

public class loveArray {
    public static void main(String[] ayan){
        Scanner sc = new Scanner(System.in);
        int t= sc.nextInt();
        while (t-->0){
            int n= sc.nextInt();
            for (int i=0;i<n;i++){
                System.out.print(1);
            }
            System.out.println();
        }
    }
}


import java.util.Scanner;

public class loveArray {
    public static void main(String[] ayan){
        Scanner sc = new Scanner(System.in);
        int t= sc.nextInt();
        while (t-->0){
            int n= sc.nextInt();
            for (int i=0;i<n;i++){
                System.out.print(1+" ");
            }
            System.out.println();
        }
    }
}


import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
		int t=Integer.parseInt(buf.readLine());
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<t;i++)
		{
		    int n=Integer.parseInt(buf.readLine());
		    for(int j=0;j<n;j++)
		    sb.append(1+" ");
		    sb.append("\n");
		}
		System.out.println(sb);
	}
}


// Imports
import java.util.*;
import java.io.*;

public class A {

    /**
     * @param args the command line arguments
     * @throws IOException, FileNotFoundException
     */
    public static void main(String[] args) throws IOException, FileNotFoundException {

        // TODO UNCOMMENT WHEN ALGORITHM CORRECT
        // BufferedReader f = new BufferedReader(new InputStreamReader(System.in));

        BufferedReader f = new BufferedReader(new StringReader("3\n" +
"1\n" +
"2\n" +
"4"));

        // TODO code application logic here
        int T = Integer.parseInt(f.readLine());
        for(int i = 0; i < T; i++) {
            int N = Integer.parseInt(f.readLine());
            StringBuilder sb = new StringBuilder();
            for(int j = 0; j < N; j++) {
                sb.append("1 ");
            }
            System.out.println(sb.substring(0, sb.length() - 1));
        }
    }

}


// Imports
import java.util.*;
import java.io.*;

public class A {

    /**
     * @param args the command line arguments
     * @throws IOException, FileNotFoundException
     */
    public static void main(String[] args) throws IOException, FileNotFoundException {

        // TODO UNCOMMENT WHEN ALGORITHM CORRECT
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));

        // TODO code application logic here
        int T = Integer.parseInt(f.readLine());
        for(int i = 0; i < T; i++) {
            int N = Integer.parseInt(f.readLine());
            StringBuilder sb = new StringBuilder();
            for(int j = 0; j < N; j++) {
                sb.append("1 ");
            }
            System.out.println(sb.substring(0, sb.length() - 1));
        }
    }

}


import java.util.*;
import java.io.*;

public class Codeforces
{
	public static void main(String args[]) throws IOException{

		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		//BufferedWriter writer = new BufferedWriter(new OutputStreamReader(System.out));

		int t = Integer.parseInt(reader.readLine());
		while(t-- > 0){

			int n = Integer.parseInt(reader.readLine());
			// String input[] = reader.readLine().split("\\s+");
			// int[] a  = Arrays.stream(input).mapToInt(Integer::parseInt).toArray();

			for (int i = 1; i <=n ; i++){
				System.out.print(1+" ");
			}
			System.out.println();

		}
	}
}


import java.util.Scanner;

public class Andre {
	public static int lcm(int number1, int number2) {
	    if (number1 == 0 || number2 == 0) {
	        return 0;
	    }
	    int absNumber1 = Math.abs(number1);
	    int absNumber2 = Math.abs(number2);
	    int absHigherNumber = Math.max(absNumber1, absNumber2);
	    int absLowerNumber = Math.min(absNumber1, absNumber2);
	    int lcm = absHigherNumber;
	    while (lcm % absLowerNumber != 0) {
	        lcm += absHigherNumber;
	    }
	    return lcm;
	}

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		for (int l = 0; l<n; l++) {
			int num = 1;
			int max = scan.nextInt();
			for (int i = 2; i<=max; i++) {
				num = lcm(num,i);
			}
			for (int i = 0; i<max; i++) {
				System.out.print(1+" ");
			}
			System.out.println();
		}
	}

}


import java.util.Scanner;

public class Andre {
	public static int lcm(int number1, int number2) {
	    if (number1 == 0 || number2 == 0) {
	        return 0;
	    }
	    int absNumber1 = Math.abs(number1);
	    int absNumber2 = Math.abs(number2);
	    int absHigherNumber = Math.max(absNumber1, absNumber2);
	    int absLowerNumber = Math.min(absNumber1, absNumber2);
	    int lcm = absHigherNumber;
	    while (lcm % absLowerNumber != 0) {
	        lcm += absHigherNumber;
	    }
	    return lcm;
	}

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		for (int l = 0; l<n; l++) {
			int num = 1;
			int max = scan.nextInt();
			for (int i = 2; i<=max; i++) {
				num = lcm(num,i);
			}
			for (int i = 0; i<max; i++) {
				System.out.print(num+" ");
			}
			System.out.println();
		}
	}

}


import java.util.*;
import java.io.*;

public class Perfect {
	public static void main(String args[]){
	    Scanner scan = new Scanner(System.in);
	    int t=scan.nextInt();
	    while(t-->0){
	        int n=scan.nextInt();
	        int arr[]=new int[n];
	        for(int i=0;i<n;i++){
	            arr[i]=1;
	        }
	        for(int i=0;i<n;i++){
	          System.out.print(arr[i]+" ");
	        }
	        System.out.println();
	    }
	}
}


import java.io.PrintWriter;
import java.util.*;

public class A {

    static Scanner sc;
    static PrintWriter out;

    public static void main(String[] args) throws Exception {
        sc = new Scanner(System.in);
        out = new PrintWriter(System.out);
        int t = sc.nextInt();
        for(int i=0; i<t; i++) {
           solve();
        }
        out.flush();
    }

    static void solve() {
        int n = sc.nextInt();
        out.print("1");
        for(int i=1; i<n; i++) {
            out.print(" 1");
        }
        out.println();

    }

}


import java.io.PrintWriter;
import java.util.*;

public class B {

    static Scanner sc;
    static PrintWriter out;

    public static void main(String[] args) throws Exception {
        sc = new Scanner(System.in);
        out = new PrintWriter(System.out);
        int t = sc.nextInt();
        for(int i=0; i<t; i++) {
            solve();
        }
        out.flush();
    }

    static void solve() {
        int n = sc.nextInt();
        Set<Integer> set = new HashSet<>();
        int[] a = new int[n];
        for(int i=0; i<n; i++) {
            a[i] = sc.nextInt();
        }
        for(int i=0; i<n; i++) {
            if(set.contains(a[i])) {
                out.println("YES");
                return;
            }
            set.add(a[i]);
        }

        out.println("NO");

    }

}


import java.util.*;
import java.io.*;
import java.lang.*;
public class F{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 0;i<n;i++){
			int t = sc.nextInt();
				find(t);
				System.out.println();
		}
		}
		public static void find(int t){
			int[] arr = new int[t];
			for(int i = 0;i<t;i++){
				arr[i] = 1;
			}
			for(int k: arr){
				System.out.print(k+" ");
			}
		}

}


/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
    public static void main(String[] args)
	{
		FastReader sc=new FastReader();
		PrintWriter out=new PrintWriter(System.out);
                int t=sc.nextInt();
                while(t-->0){
                      int n=sc.nextInt();
                      for(int i=0;i<n;i++){
                            out.print("1 ");
                      }out.println();
                }out.flush();
	}
	static class FastReader
	{
		BufferedReader br;
		StringTokenizer st;

		public FastReader()
		{
			br = new BufferedReader(new
					InputStreamReader(System.in));
		}

		String next()
		{
			while (st == null || !st.hasMoreElements())
			{
				try
				{
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e)
				{
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt()
		{
			return Integer.parseInt(next());
		}

		long nextLong()
		{
			return Long.parseLong(next());
		}

		double nextDouble()
		{
			return Double.parseDouble(next());
		}

		String nextLine()
		{
			String str = "";
			try
			{
				str = br.readLine();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
			return str;
		}
	}

}


#include <bits/stdc++.h>
#define SPEED ios::sync_with_stdio(false); cin.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define pll pair<long long int,long long int>
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define mod 998244353
#define INF 1e18
#define eps 0.00001
#define stp setprecision(20)
#define endl '\n'
using namespace std;
ll s=0;
void merge(int arr[], int l, int m, int r)
{
    int i, j, k,c=0;
    int n1 = m - l + 1;
    int n2 =  r - m;

    int L[n1], R[n2];

    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1+ j];

    i = 0;
    j = 0;
    k = l;
    while (i < n1 && j < n2)
    {
        if (L[i] <= R[j])
        { c=0;
            arr[k] = L[i];
            i++;
        }
        else
        {c=1; s+=(n1-i)*(c);
            arr[k] = R[j];
            j++;
        }
        k++;
    }

    while (i < n1)
    {
        arr[k] = L[i];
        i++;
        k++;
    }

    while (j < n2)
    {
        arr[k] = R[j];
        j++;
        k++;
    }
}

void mergeSort(int  arr[], int l, int r)
{
    if (l < r)
    {
        int m = (l+r)/2;

        mergeSort(arr, l, m);
        mergeSort(arr, m+1, r);

        merge(arr, l, m, r);
    }
}
ll modulo (ll a , long long b, int n)
 {  long long x=1 ,y=a;
 while (b>0){
 	if(b%2==1)  x=(x*y)%n ;
 	y=(y*y)%n ;
 	b/=2;
} return(x%n) ;
 }
int main()
{    SPEED;

      ll n;cin>>n;vi v;
      int a[n];ll calcn=0;ll neg[n+1]={0};int a1[n+1]={0} ;int pref[n+1]={0};a1[0]=-1; int b[n+1],j=0;
      loop(i,0,n)
       {
       	  cin>>a[i];
       	  if(a[i]>0)
			 { a1[a[i]] ++;
			 	b[j++]=a[i];neg[i+1]=neg[i];
			 }
			 else calcn++,neg[i+1]=neg[i]+1;
	   }
	   loop(i,1,n+1)
	   {
	   	  if(a1[i-1]==0)

	   	  {
	   	  	pref[i]=pref[i-1]+1;
			 }
			 else
			 pref[i]=pref[i-1];
			// cout<<pref[i]<<" ";
	   }

       mergeSort(b,0,j-1);
       if(!calcn)
       {cout<<s;return 0;
	   }

       ll num=0,den=0;
        num+= (calcn*(calcn-1));num/=2;den=2;
        num+=s*2;
        ll num1=0;
        loop(i,0,n)
        {
        	if(a[i]>0)
        	{ //cout<<pref[a[i]]<<endl;
        		num1+= (neg[i+1] *(calcn-pref[a[i]])+(calcn-neg[i+1])*(pref[a[i]]));
			}
		}

		num = num *calcn + num1*den;
		den = den*calcn;

		ll ans=  ((num%mod)*modulo(den,mod-2,mod))%mod;
        cout<<ans<<endl;

}


#include <bits/stdc++.h>
#define SPEED ios::sync_with_stdio(false); cin.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define pll pair<long long int,long long int>
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define mod 998244353
#define INF 1e18
#define eps 0.00001
#define stp setprecision(20)
#define endl '\n'
using namespace std;
ll s=0;
void merge(int arr[], int l, int m, int r)
{
    int i, j, k,c=0;
    int n1 = m - l + 1;
    int n2 =  r - m;

    int L[n1], R[n2];

    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1+ j];

    i = 0;
    j = 0;
    k = l;
    while (i < n1 && j < n2)
    {
        if (L[i] <= R[j])
        { c=0;
            arr[k] = L[i];
            i++;
        }
        else
        {c=1; s+=(n1-i)*(c);
            arr[k] = R[j];
            j++;
        }
        k++;
    }

    while (i < n1)
    {
        arr[k] = L[i];
        i++;
        k++;
    }

    while (j < n2)
    {
        arr[k] = R[j];
        j++;
        k++;
    }
}

void mergeSort(int  arr[], int l, int r)
{
    if (l < r)
    {
        int m = (l+r)/2;

        mergeSort(arr, l, m);
        mergeSort(arr, m+1, r);

        merge(arr, l, m, r);
    }
}
ll modulo (ll a , long long b, int n)
 {  long long x=1 ,y=a;
 while (b>0){
 	if(b%2==1)  x=(x*y)%n ;
 	y=(y*y)%n ;
 	b/=2;
} return(x%n) ;
 }
int main()
{    SPEED;

      ll n;cin>>n;vi v;
      int a[n];ll calcn=0;ll neg[n+1]={0};int a1[n+1]={0} ;int pref[n+1]={0};a1[0]=-1; int b[n+1],j=0;
      loop(i,0,n)
       {
       	  cin>>a[i];
       	  if(a[i]>0)
			 { a1[a[i]] ++;
			 	b[j++]=a[i];neg[i+1]=neg[i];
			 }
			 else calcn++,neg[i+1]=neg[i]+1;
	   }
	   loop(i,1,n+1)
	   {
	   	  if(a1[i-1]==0)

	   	  {
	   	  	pref[i]=pref[i-1]+1;
			 }
			 else
			 pref[i]=pref[i-1];
			// cout<<pref[i]<<" ";
	   }

       mergeSort(b,0,j-1);
       if(!calcn)
       {cout<<s;return 0;
	   }

       ll num=0,den=0;
        num+= (calcn*(calcn-1));num/=2;den=2;
        num+=s*2;
        ll num1=0;
        loop(i,0,n)
        {
        	if(a[i]>0)
        	{ //cout<<pref[a[i]]<<endl;
        		num1+= (neg[i+1] *(calcn-pref[a[i]])+(calcn-neg[i+1])*(pref[a[i]]));
			}
		}

		num = num *calcn + num1*den;
		den = den*calcn;
		ll g = __gcd(num,den);
		num/=g;den/=g;

		ll ans=  ((num%mod)*modulo(den,mod-2,mod))%mod;
        cout<<ans<<endl;

}


#include <bits/stdc++.h>
#define SPEED ios::sync_with_stdio(false); cin.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define ll unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define pll pair<long long int,long long int>
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define mod 998244353
#define INF 1e18
#define eps 0.00001
#define stp setprecision(20)
#define endl '\n'
using namespace std;
ll s=0;
void merge(int arr[], int l, int m, int r)
{
    int i, j, k,c=0;
    int n1 = m - l + 1;
    int n2 =  r - m;

    int L[n1], R[n2];

    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1+ j];

    i = 0;
    j = 0;
    k = l;
    while (i < n1 && j < n2)
    {
        if (L[i] <= R[j])
        { c=0;
            arr[k] = L[i];
            i++;
        }
        else
        {c=1; s+=(n1-i)*(c);
            arr[k] = R[j];
            j++;
        }
        k++;
    }

    while (i < n1)
    {
        arr[k] = L[i];
        i++;
        k++;
    }

    while (j < n2)
    {
        arr[k] = R[j];
        j++;
        k++;
    }
}

void mergeSort(int  arr[], int l, int r)
{
    if (l < r)
    {
        int m = (l+r)/2;

        mergeSort(arr, l, m);
        mergeSort(arr, m+1, r);

        merge(arr, l, m, r);
    }
}
ll modulo (ll a , long long b, int n)
 {  long long x=1 ,y=a;
 while (b>0){
 	if(b%2==1)  x=(x*y)%n ;
 	y=(y*y)%n ;
 	b/=2;
} return(x%n) ;
 }
int main()
{    SPEED;

      ll n;cin>>n;vi v;
      int a[n];ll calcn=0;ll neg[n+1]={0};int a1[n+1]={0} ;int pref[n+1]={0};a1[0]=-1; int b[n+1],j=0;
      loop(i,0,n)
       {
       	  cin>>a[i];
       	  if(a[i]>0)
			 { a1[a[i]] ++;
			 	b[j++]=a[i];neg[i+1]=neg[i];
			 }
			 else calcn++,neg[i+1]=neg[i]+1;
	   }
	   loop(i,1,n+1)
	   {
	   	  if(a1[i-1]==0)

	   	  {
	   	  	pref[i]=pref[i-1]+1;
			 }
			 else
			 pref[i]=pref[i-1];
			// cout<<pref[i]<<" ";
	   }

       mergeSort(b,0,j-1);
       if(!calcn)
       {cout<<s;return 0;
	   }

       ll num=0,den=0;
        num= (calcn*(calcn-1));num/=2;den=2;
        num=(num+s*2)%mod;
        ll num1=0;
        loop(i,0,n)
        {
        	if(a[i]>0)
        	{ //cout<<pref[a[i]]<<endl;
        		num1= (num1+(neg[i+1]%mod *(calcn-pref[a[i]])%mod)%mod+(calcn-neg[i+1])%mod*(pref[a[i]])%mod)%mod;
			}
		}

		num = (num *calcn)%mod + (num1*den)%mod;
		den = den*calcn;

		ll ans=  (num%mod)*modulo(den,mod-2,mod);
        cout<<ans%mod<<endl;

}


#include <bits/stdc++.h>
#define SPEED ios::sync_with_stdio(false); cin.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define pll pair<long long int,long long int>
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define mod 998244353
#define INF 1e18
#define eps 0.00001
#define stp setprecision(20)
#define endl '\n'
using namespace std;
ll s=0;
void merge(vi arr, int l, int m, int r)
{
    int i, j, k,c=0;
    int n1 = m - l + 1;
    int n2 =  r - m;

    int L[n1], R[n2];

    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1+ j];

    i = 0;
    j = 0;
    k = l;
    while (i < n1 && j < n2)
    {
        if (L[i] <= R[j])
        { c=0;
            arr[k] = L[i];
            i++;
        }
        else
        {c=1; s+=(n1-i)*(c);
            arr[k] = R[j];
            j++;
        }
        k++;
    }

    while (i < n1)
    {
        arr[k] = L[i];
        i++;
        k++;
    }

    while (j < n2)
    {
        arr[k] = R[j];
        j++;
        k++;
    }
}

void mergeSort(vi arr, int l, int r)
{
    if (l < r)
    {
        int m = (l+r)/2;

        mergeSort(arr, l, m);
        mergeSort(arr, m+1, r);

        merge(arr, l, m, r);
    }
}
ll modulo (ll a , long long b, int n)
 {  long long x=1 ,y=a;
 while (b>0){
 	if(b%2==1)  x=(x*y)%n ;
 	y=(y*y)%n ;
 	b/=2;
} return(x%n) ;
 }
int main()
{    SPEED;

      ll n;cin>>n;vi v;
      int a[n];ll calcn=0;ll neg[n+1]={0};int a1[n+1]={0} ;int pref[n+1]={0};a1[0]=-1;
      loop(i,0,n)
       {
       	  cin>>a[i];
       	  if(a[i]>0)
			 { a1[a[i]] ++;
			 	v.pb(a[i]),neg[i+1]=neg[i];
			 }
			 else calcn++,neg[i+1]=neg[i]+1;
	   }
	   loop(i,1,n+1)
	   {
	   	  if(a1[i-1]==0)

	   	  {
	   	  	pref[i]=pref[i-1]+1;
			 }
			 else
			 pref[i]=pref[i-1];
			// cout<<pref[i]<<" ";
	   }

       mergeSort(v,0,v.size()-1);
       if(!calcn)
       {cout<<s;return 0;
	   }

       ll num=0,den=0;
        num+= (calcn*(calcn-1));num/=2;den=2;
        num+=s*2;
        ll num1=0;
        loop(i,0,n)
        {
        	if(a[i]>0)
        	{ //cout<<pref[a[i]]<<endl;
        		num1+= (neg[i+1] *(calcn-pref[a[i]])+(calcn-neg[i+1])*(pref[a[i]]));
			}
		}

		num = num *calcn + num1*den;
		den = den*calcn;
		ll g = __gcd(num,den);
		num/=g;den/=g;

		ll ans=  ((num%mod)*modulo(den,mod-2,mod))%mod;
        cout<<ans<<endl;

}


#include <bits/stdc++.h>
#define SPEED ios::sync_with_stdio(false); cin.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define pll pair<long long int,long long int>
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define mod 998244353
#define INF 1e18
#define eps 0.00001
#define stp setprecision(20)
#define endl '\n'
using namespace std;
ll s=0;
void merge(int arr[], int l, int m, int r)
{
    int i, j, k,c=0;
    int n1 = m - l + 1;
    int n2 =  r - m;

    int L[n1], R[n2];

    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1+ j];

    i = 0;
    j = 0;
    k = l;
    while (i < n1 && j < n2)
    {
        if (L[i] <= R[j])
        { c=0;
            arr[k] = L[i];
            i++;
        }
        else
        {c=1; s+=(n1-i)*(c);
            arr[k] = R[j];
            j++;
        }
        k++;
    }

    while (i < n1)
    {
        arr[k] = L[i];
        i++;
        k++;
    }

    while (j < n2)
    {
        arr[k] = R[j];
        j++;
        k++;
    }
}

void mergeSort(int  arr[], int l, int r)
{
    if (l < r)
    {
        int m = (l+r)/2;

        mergeSort(arr, l, m);
        mergeSort(arr, m+1, r);

        merge(arr, l, m, r);
    }
}
ll modulo (ll a , long long b, int n)
 {  long long x=1 ,y=a;
 while (b>0){
 	if(b%2==1)  x=(x*y)%n ;
 	y=(y*y)%n ;
 	b/=2;
} return(x%n) ;
 }
int main()
{    SPEED;

      ll n;cin>>n;vi v;
      int a[n];ll calcn=0;ll neg[n+1]={0};int a1[n+1]={0} ;int pref[n+1]={0};a1[0]=-1; int b[n+1],j=0;
      loop(i,0,n)
       {
       	  cin>>a[i];
       	  if(a[i]>0)
			 { a1[a[i]] ++;
			 	b[j++]=a[i];neg[i+1]=neg[i];
			 }
			 else calcn++,neg[i+1]=neg[i]+1;
	   }
	   loop(i,1,n+1)
	   {
	   	  if(a1[i-1]==0)

	   	  {
	   	  	pref[i]=pref[i-1]+1;
			 }
			 else
			 pref[i]=pref[i-1];
			// cout<<pref[i]<<" ";
	   }

       mergeSort(b,0,j-1);
       if(!calcn)
       {cout<<s;return 0;
	   }

       ll num=0,den=0;
        num= (calcn*(calcn-1));num/=2;den=2;
        num=(num+s*2)%mod;
        ll num1=0;
        loop(i,0,n)
        {
        	if(a[i]>0)
        	{ //cout<<pref[a[i]]<<endl;
        		num1+= ((neg[i+1]%mod *(calcn-pref[a[i]])%mod)%mod+(calcn-neg[i+1])%mod*(pref[a[i]])%mod)%mod;
			}
		}

		num = (num *calcn)%mod + (num1*den)%mod;
		den = den*calcn;

		ll ans=  ((num%mod)*modulo(den,mod-2,mod))%mod;
        cout<<ans<<endl;

}


#include <bits/stdc++.h>
#define pii pair<int, int>
#define F first
#define S second
using namespace std;
/// (0, 0), (1, 0), (0, 1), (1, 1) <--> (upper, lower)
const int N = 2e5 + 5;
const int mod = 998244353;
int t[N], f[N], grt[N], n, a[N], tt[N];
long long sum; // cac cap
bool existed[N];

void update(int id) {
    while(id <= 2e5) {
        ++t[id];
        id += id & (-id);
    }
}

int get(int id) {
    int ret = 0;
    while(id > 0) {
        ret += t[id];
        id -= id & (-id);
    }
    return ret;
}

void add(int &a, int b) {
    a += b;
    if(a >= mod) a -= mod;
}

int pw(int a, int b) {
    int c = 1;
    for(; b; b/=2, a=1ll*a*a%mod) {
        if(b & 1) c = 1ll*c*a % mod;
    }
    return c;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie();
    if(fopen("inp.txt", "r")) freopen("inp.txt", "r", stdin);
    cin >> n;
    for(int i=1 ; i<=n ; ++i) {
        cin >> a[i];
        tt[i] = tt[i-1] + (a[i] == -1);
        if(a[i] == -1) sum += tt[i-1];
        else grt[a[i]] = 1, existed[a[i]] = 1;
    }

    /// calc factorial
    f[0] = 1;
    for(int i=1 ; i<=2e5 ; ++i) {
        f[i] = 1ll*f[i-1]*i % mod;
    }

    for(int i=2e5-1 ; i ; --i) {
        grt[i] += grt[i+1];
    }

    if(tt[n] == 1) {
        int val = 0;
        for(int i=1 ; i<=n ; ++i) {
            if(existed[i] == 0) {
                val = i;
                break;
            }
        }
        for(int i=1 ; i<=n ; ++i) {
            if(a[i] == -1) {
                a[i] = val; break;
            }
        }
    }

    int ans = 0, cnt = tt[n];
    /// case1
    if(cnt > 1) {
        for(int val=1; val<=n ; ++val) {
            if(existed[val]) continue;
            int upp = n - val - grt[val+1];
            int res = 1ll*(1ll*sum*upp%mod)*f[cnt-2] % mod;
            add(ans, res);
        }
    }

    /// case3, case4
    for(int i=1 ; i<=n ; ++i) {
        if(a[i] == -1) continue;
        int res = 1ll*(get(2e5) - get(a[i]))*f[cnt] % mod;
        add(ans, res);

        int upp = n - a[i] - grt[a[i]+1];
        res = 1ll*(1ll*tt[i]*upp % mod)*f[cnt-1] % mod;
        add(ans, res);

        update(a[i]);
    }

    ///case2
    memset(t, 0, sizeof t);
    for(int i=n ; i ; --i) {
        if(a[i] == -1) continue;
        int ht = cnt - tt[i];
        int lw = a[i] - (grt[1] - grt[a[i]+1]); /// nho hon a[i] va chua xuat hien
        int res = 1ll*(1ll*lw*ht%mod)*f[cnt-1] % mod;
        add(ans, res);
    }

    ans = 1ll*ans*pw(f[cnt], mod-2) % mod;
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
#define pii pair<int, int>
#define F first
#define S second
using namespace std;
/// (0, 0), (1, 0), (0, 1), (1, 1) <--> (upper, lower)
const int N = 2e5 + 5;
const int mod = 998244353;
int t[N], f[N], grt[N], n, a[N], tt[N];
long long sum; // cac cap
bool existed[N];

void update(int id) {
    while(id <= 2e5) {
        ++t[id];
        id += id & (-id);
    }
}

int get(int id) {
    int ret = 0;
    while(id > 0) {
        ret += t[id];
        id -= id & (-id);
    }
    return ret;
}

void add(int &a, int b) {
    a += b;
    if(a >= mod) a -= mod;
}

int pw(int a, int b) {
    int c = 1;
    for(; b; b/=2, a=1ll*a*a%mod) {
        if(b & 1) c = 1ll*c*a % mod;
    }
    return c;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie();
    if(fopen("inp.txt", "r")) freopen("inp.txt", "r", stdin);
    cin >> n;
    for(int i=1 ; i<=n ; ++i) {
        cin >> a[i];
        tt[i] = tt[i-1] + (a[i] == -1);
        if(a[i] == -1) sum += tt[i-1];
        else grt[a[i]] = 1, existed[a[i]] = 1;
    }

    if(tt[n] == 1) {
        int val = 0;
        for(int i=1 ; i<=n ; ++i) {
            if(existed[i] == 0) {
                val = i;
                break;
            }
        }
        for(int i=1 ; i<=n ; ++i) {
            if(a[i] == -1) {
                a[i] = val; break;
            }
        }

        sum = 0;
        memset(grt, 0, sizeof grt);

        for(int i=1 ; i<=n ; ++i) {
            tt[i] = tt[i-1] + (a[i] == -1);
            if(a[i] == -1) sum += tt[i-1];
            else grt[a[i]] = 1, existed[a[i]] = 1;
        }

    }

    /// calc factorial
    f[0] = 1;
    for(int i=1 ; i<=2e5 ; ++i) {
        f[i] = 1ll*f[i-1]*i % mod;
    }

    for(int i=2e5-1 ; i ; --i) {
        grt[i] += grt[i+1];
    }

    int ans = 0, cnt = tt[n];
    /// case1
    if(cnt > 1) {
        for(int val=1; val<=n ; ++val) {
            if(existed[val]) continue;
            int upp = n - val - grt[val+1];
            int res = 1ll*(1ll*sum*upp%mod)*f[cnt-2] % mod;
            add(ans, res);
        }
    }

    /// case3, case4
    for(int i=1 ; i<=n ; ++i) {
        if(a[i] == -1) continue;
        int res = 1ll*(get(2e5) - get(a[i]))*f[cnt] % mod;
        add(ans, res);

        int upp = n - a[i] - grt[a[i]+1];
        res = 1ll*(1ll*tt[i]*upp % mod)*f[cnt-1] % mod;
        add(ans, res);

        update(a[i]);
    }

    ///case2
    memset(t, 0, sizeof t);
    for(int i=n ; i ; --i) {
        if(a[i] == -1) continue;
        int ht = cnt - tt[i];
        int lw = a[i] - (grt[1] - grt[a[i]+1]); /// nho hon a[i] va chua xuat hien
        int res = 1ll*(1ll*lw*ht%mod)*f[cnt-1] % mod;
        add(ans, res);
    }

    ans = 1ll*ans*pw(f[cnt], mod-2) % mod;
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
#define pii pair<int, int>
#define F first
#define S second
using namespace std;
/// (0, 0), (1, 0), (0, 1), (1, 1) <--> (upper, lower)
const int N = 2e5 + 5;
const int mod = 998244353;
int t[N], f[N], grt[N], n, a[N], tt[N];
long long sum; // cac cap
bool existed[N];

void update(int id) {
    while(id <= 2e5) {
        ++t[id];
        id += id & (-id);
    }
}

int get(int id) {
    int ret = 0;
    while(id > 0) {
        ret += t[id];
        id -= id & (-id);
    }
    return ret;
}

int add(int &a, int b) {
    a += b;
    if(a >= mod) a -= mod;
}

int pw(int a, int b) {
    int c = 1;
    for(; b; b/=2, a=1ll*a*a%mod) {
        if(b & 1) c = 1ll*c*a % mod;
    }
    return c;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie();
    if(fopen("inp.txt", "r")) freopen("inp.txt", "r", stdin);
    cin >> n;
    for(int i=1 ; i<=n ; ++i) {
        cin >> a[i];
        tt[i] = tt[i-1] + (a[i] == -1);
        if(a[i] == -1) sum += tt[i-1];
        else grt[a[i]] = 1, existed[a[i]] = 1;
    }

    /// calc factorial
    f[0] = 1;
    for(int i=1 ; i<=2e5 ; ++i) {
        f[i] = 1ll*f[i-1]*i % mod;
    }

    for(int i=2e5-1 ; i ; --i) {
        grt[i] += grt[i+1];
    }

    if(tt[n] == 1) {
        int val = 0;
        for(int i=1 ; i<=n ; ++i) {
            if(existed[i] == 0) {
                val = i;
                break;
            }
        }
        for(int i=1 ; i<=n ; ++i) {
            if(a[i] == -1) {
                a[i] = val; break;
            }
        }
    }

    int ans = 0, cnt = tt[n];
    /// case1
    if(cnt > 1) {
        for(int val=1; val<=n ; ++val) {
            if(existed[val]) continue;
            int upp = n - val - grt[val+1];
            int res = 1ll*(1ll*sum*upp%mod)*f[cnt-2] % mod;
            add(ans, res);
        }
    }

    /// case3, case4
    for(int i=1 ; i<=n ; ++i) {
        if(a[i] == -1) continue;
        int res = 1ll*(get(2e5) - get(a[i]))*f[cnt] % mod;
        add(ans, res);

        int upp = n - a[i] - grt[a[i]+1];
        res = 1ll*(1ll*tt[i]*upp % mod)*f[cnt-1] % mod;
        add(ans, res);

        update(a[i]);
    }

    ///case2
    memset(t, 0, sizeof t);
    for(int i=n ; i ; --i) {
        if(a[i] == -1) continue;
        int ht = cnt - tt[i];
        int lw = a[i] - (grt[1] - grt[a[i]+1]); /// nho hon a[i] va chua xuat hien
        int res = 1ll*(1ll*lw*ht%mod)*f[cnt-1] % mod;
        add(ans, res);
    }

    ans = 1ll*ans*pw(f[cnt], mod-2) % mod;
    cout << ans;

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MAXN = 2e5 + 9;
const ll MOD = 998244353;

int n, a[MAXN], vis[MAXN];
ll m, ans, B[MAXN], tot[MAXN], cnt[MAXN];

void Add(int p) {
	for(; p <= n; p += p & -p) B[p]++;
}

ll Que(int p) {
	ll ret = 0;
	for(; p; p -= p & -p) ret += B[p];
	return ret;
}

void upd(ll &x) {
	if(x >= MOD) x -= MOD;
	if(x < 0) x += MOD;
}

ll Pow(ll x, ll t) {
	ll ret = 1;
	for(; t; t >>= 1, x = x * x % MOD)
		if(t & 1) ret = ret * x % MOD;
	return ret;
}

ll inv(ll x) {
	return Pow(x, MOD - 2);
}

int main() {

	cin >> n;
	for(int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		cnt[i] = cnt[i - 1];
		if(a[i] == -1) {
			m++;
			continue;
		}
		cnt[i]++;
		vis[a[i]] = 1;
		Add(a[i]);
		upd(ans += cnt[i] - Que(a[i]));
	}
	for(int i = n; i >= 1; i--) {
		B[i] = 0;
		tot[i] = tot[i + 1] + (a[i] == -1);
	}
	for(int i = 1; i <= n; i++)
		if(!vis[i]) Add(i);
	upd(ans += m * (m - 1) % MOD * inv(4) % MOD);
	ll temp = 0;
	for(int i = 1; i <= n; i++) if(a[i] != -1) {
		ll delta = 0;
		upd(delta += m * cnt[i] % MOD);
		upd(delta += Que(a[i]) - m);
		temp = (temp + delta * tot[i]) % MOD;
	}
	for(int i = 2; i <= m; i++)
		temp = temp * inv(i) % MOD;
	cout << (ans + temp) % MOD << endl;

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MAXN = 1e5 + 9;
const ll MOD = 998244353;

int n, a[MAXN], vis[MAXN];
ll m, ans, B[MAXN], tot[MAXN], cnt[MAXN];

void Add(int p) {
	for(; p <= n; p += p & -p) B[p]++;
}

ll Que(int p) {
	ll ret = 0;
	for(; p; p -= p & -p) ret += B[p];
	return ret;
}

void upd(ll &x) {
	if(x >= MOD) x -= MOD;
	if(x < 0) x += MOD;
}

ll Pow(ll x, ll t) {
	ll ret = 1;
	for(; t; t >>= 1, x = x * x % MOD)
		if(t & 1) ret = ret * x % MOD;
	return ret;
}

ll inv(ll x) {
	return Pow(x, MOD - 2);
}

int main() {

	cin >> n;
	for(int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		cnt[i] = cnt[i - 1];
		if(a[i] == -1) {
			m++;
			continue;
		}
		cnt[i]++;
		vis[a[i]] = 1;
		Add(a[i]);
		upd(ans += i - Que(a[i]));
	}
	for(int i = n; i >= 1; i--) {
		B[i] = 0;
		tot[i] = tot[i + 1] + (a[i] == -1);
	}
	for(int i = 1; i <= n; i++)
		if(!vis[i]) Add(i);
	upd(ans += m * (m - 1) % MOD * inv(4) % MOD);
	ll temp = 0;
	for(int i = 1; i <= n; i++) if(a[i] != -1) {
		ll delta = 0;
		upd(delta += m * cnt[i] % MOD);
		upd(delta += Que(a[i]) - m);
		temp = (temp + delta * tot[i]) % MOD;
	}
	for(int i = 2; i <= m; i++)
		temp = temp * inv(i) % MOD;
	cout << (ans + temp) % MOD << endl;

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MAXN = 2e5 + 9;
const ll MOD = 998244353;

int n, a[MAXN], vis[MAXN];
ll m, ans, B[MAXN], lef[MAXN], rig[MAXN], cnt[MAXN];

void Add(int p) {
	for(; p <= n; p += p & -p) B[p]++;
}

ll Que(int p) {
	ll ret = 0;
	for(; p; p -= p & -p) ret += B[p];
	return ret;
}

void upd(ll &x) {
	if(x >= MOD) x -= MOD;
	if(x < 0) x += MOD;
}

ll Pow(ll x, ll t) {
	ll ret = 1;
	for(; t; t >>= 1, x = x * x % MOD)
		if(t & 1) ret = ret * x % MOD;
	return ret;
}

ll inv(ll x) {
	return Pow(x, MOD - 2);
}

int main() {

	cin >> n;
	for(int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		cnt[i] = cnt[i - 1] + (a[i] != -1);
		lef[i] = lef[i - 1] + (a[i] == -1);
		if(a[i] == -1) {
			m++;
			continue;
		}
		vis[a[i]] = 1;
		Add(a[i]);
		upd(ans += cnt[i] - Que(a[i]));
	}
	for(int i = n; i >= 1; i--) {
		B[i] = 0;
		rig[i] = rig[i + 1] + (a[i] == -1);
	}
	for(int i = 1; i <= n; i++)
		if(!vis[i]) Add(i);
	upd(ans += m * (m - 1) % MOD * inv(4) % MOD);
	ll temp = 0;
	for(int i = 1; i <= n; i++) if(a[i] != -1) {
		upd(temp += rig[i] * Que(a[i]) % MOD);
		upd(temp += lef[i] * (m - Que(a[i]) + MOD) % MOD);
	}
	for(int i = 2; i <= m; i++)
		temp = temp * inv(i) % MOD;
	cout << (ans + temp) % MOD << endl;

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MAXN = 2e5 + 9;
const ll MOD = 998244353;

int n, a[MAXN], vis[MAXN];
ll m, ans, B[MAXN], lef[MAXN], rig[MAXN], cnt[MAXN];

void Add(int p) {
	for(; p <= n; p += p & -p) B[p]++;
}

ll Que(int p) {
	ll ret = 0;
	for(; p; p -= p & -p) ret += B[p];
	return ret;
}

void upd(ll &x) {
	if(x >= MOD) x -= MOD;
	if(x < 0) x += MOD;
}

ll Pow(ll x, ll t) {
	ll ret = 1;
	for(; t; t >>= 1, x = x * x % MOD)
		if(t & 1) ret = ret * x % MOD;
	return ret;
}

ll inv(ll x) {
	return Pow(x, MOD - 2);
}

int main() {

	cin >> n;
	for(int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		cnt[i] = cnt[i - 1] + (a[i] != -1);
		lef[i] = lef[i - 1] + (a[i] == -1);
		if(a[i] == -1) {
			m++;
			continue;
		}
		vis[a[i]] = 1;
		Add(a[i]);
		upd(ans += cnt[i] - Que(a[i]));
	}
	for(int i = n; i >= 1; i--) {
		B[i] = 0;
		rig[i] = rig[i + 1] + (a[i] == -1);
	}
	assert(rig[1] == m);
	assert(lef[n] == m);
	for(int i = 1; i <= n; i++)
		if(!vis[i]) Add(i);
	cerr << ans << endl;
	upd(ans += m * (m - 1) % MOD * inv(4) % MOD);
	ll temp = 0;
	for(int i = 1; i <= n; i++) if(a[i] != -1) {
		upd(temp += rig[i] * Que(a[i]) % MOD);
		upd(temp += lef[i] * (m - Que(a[i])) % MOD);
	}
	for(int i = 2; i <= m; i++)
		temp = temp * inv(i) % MOD;
	cout << (ans + temp) % MOD << endl;

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MAXN = 3e5 + 9;
const ll MOD = 998244353;

int n, a[MAXN], vis[MAXN];
ll m, ans, B[MAXN], lef[MAXN], rig[MAXN], cnt[MAXN];

void Add(int p) {
	for(; p <= n; p += p & -p) B[p]++;
}

ll Que(int p) {
	ll ret = 0;
	for(; p; p -= p & -p) ret += B[p];
	return ret;
}

void upd(ll &x) {
	x %= MOD;
	if(x < 0) x += MOD;
}

ll Pow(ll x, ll t) {
	ll ret = 1;
	for(; t; t >>= 1, x = x * x % MOD)
		if(t & 1) ret = ret * x % MOD;
	return ret;
}

ll inv(ll x) {
	return Pow(x, MOD - 2);
}

int main() {

	cin >> n;
	for(int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		cnt[i] = cnt[i - 1] + (a[i] != -1);
		lef[i] = lef[i - 1] + (a[i] == -1);
		if(a[i] == -1) {
			m++;
			continue;
		}
		vis[a[i]] = 1;
		Add(a[i]);
		upd(ans += cnt[i] - Que(a[i]));
	}
	for(int i = n; i >= 1; i--) {
		B[i] = 0;
		rig[i] = rig[i + 1] + (a[i] == -1);
	}
	assert(rig[1] == m);
	assert(lef[n] == m);
	for(int i = 1; i <= n; i++)
		if(!vis[i]) Add(i);
	upd(ans += m * (m - 1) % MOD * inv(4) % MOD);
	ll temp = 0;
	for(int i = 1; i <= n; i++) if(a[i] != -1) {
		upd(temp += rig[i] * Que(a[i]) % MOD);
		upd(temp += lef[i] * (m - Que(a[i])) % MOD);
	}
	cout << (ans + temp * inv(m)) % MOD << endl;

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int MAXN = 3e5 + 9;
const ll MOD = 998244353;

int n, a[MAXN], vis[MAXN];
ll m, ans, B[MAXN], lef[MAXN], rig[MAXN], cnt[MAXN];

void Add(int p) {
	for(; p <= n; p += p & -p) B[p]++;
}

ll Que(int p) {
	ll ret = 0;
	for(; p; p -= p & -p) ret += B[p];
	return ret;
}

void upd(ll &x) {
	x %= MOD;
	if(x < 0) x += MOD;
}

ll Pow(ll x, ll t) {
	ll ret = 1;
	for(; t; t >>= 1, x = x * x % MOD)
		if(t & 1) ret = ret * x % MOD;
	return ret;
}

ll inv(ll x) {
	return Pow(x, MOD - 2);
}

int main() {

	cin >> n;
	for(int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		cnt[i] = cnt[i - 1] + (a[i] != -1);
		lef[i] = lef[i - 1] + (a[i] == -1);
		if(a[i] == -1) {
			m++;
			continue;
		}
		vis[a[i]] = 1;
		Add(a[i]);
		upd(ans += cnt[i] - Que(a[i]));
	}
	for(int i = n; i >= 1; i--) {
		B[i] = 0;
		rig[i] = rig[i + 1] + (a[i] == -1);
	}
	assert(rig[1] == m);
	assert(lef[n] == m);
	for(int i = 1; i <= n; i++)
		if(!vis[i]) Add(i);
	upd(ans += m * (m - 1) % MOD * inv(4) % MOD);
	ll temp = 0;
	for(int i = 1; i <= n; i++) if(a[i] != -1) {
		upd(temp += rig[i] * Que(a[i]) % MOD);
		upd(temp += lef[i] * (m - Que(a[i])) % MOD);
	}
	for(int i = 2; i <= m; i++)
		temp = temp * inv(i) % MOD;
	cout << (ans + temp) % MOD << endl;

	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string.h>
#include<climits>
#include<vector>
#include<stack>
#include<set>
#include<queue>
#include<map>
#include<math.h>

using namespace std ;

typedef long long ll ;
typedef pair < int , int > pii ;

// #define TRACE 1
#ifdef TRACE
#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#endif

#define FOR(i,a,b) for(i=a;i<=b;i++)
#define MOD 998244353
#define vi vector<int>
#define vvi vector < vi >
#define vll vector<ll>
#define pb push_back
#define mp make_pair
#define PI acos(-1.0)

const ll INF = 1e15 + 10 ;

ll fun_gcd(ll a, ll b)
{
    // Everything divides 0
    if (a == 0)
       return b;
    if (b == 0)
       return a;

    // base case
    if (a == b)
        return a;

    // a is greater
    if (a > b)
        return fun_gcd(a-b, b);
    return fun_gcd(a, b-a);
}

int n;
std::vector<int> bit;
std::vector<int> a;
std::vector<ll> numerator;
std::vector<ll> denominator;

void update(int idx_onebased, int value){
	int diff = value - a[idx_onebased];
	a[idx_onebased] = value;
	while(idx_onebased <= n){
		bit[idx_onebased] += diff;
		idx_onebased += (idx_onebased & -idx_onebased);
	}
}

long long get_sum(int idx_onebased){
	long long sum = 0;
	while(idx_onebased){
		sum += bit[idx_onebased];
		idx_onebased -= (idx_onebased & -idx_onebased);
	}
	return sum;
}

long long get_rank(int number){
	return get_sum(number);
}

bool predicate( int i , int k){
	return get_rank(i) >= k;
}

long long get_kth_numbet(int k){
	int f=0, l=n, mid=(f+l)/2;
	while((l-f)>1){
		if(predicate(mid, k))
			l = mid;
		else
			f = mid;
		mid=(f+l)/2;
	}
	return l;
}

void insertElement(int x){
	update(x, a[x] + 1);
}

void deleteElement(int x){
	update(x, a[x] - 1);
}

void add_fraction(ll a, ll b){
	ll gcd = fun_gcd(a,b);
	numerator.push_back(a/gcd);
	denominator.push_back(b/gcd);
}

ll power(ll x, ll y)
{
    ll res = 1;     // Initialize result

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x)%MOD;

        // n must be even now
        y = y>>1; // y = y/2
        x = (x*x)%MOD;  // Change x to x^2
    }
    return res;
}

ll inverse_mod(ll x){
	return power(x,MOD-2);
}

ll get_fractions_sum_mod(){
	ll ans = 0;
	for(int i=0; i<numerator.size(); i++){
		// cout << numerator[i] << " " << denominator[i] << endl;
		ans += ((numerator[i]%MOD)*(inverse_mod(denominator[i])))%MOD;
		ans %= MOD;
	}
	return ans;
}

int main(){
   	bit = std::vector<int>(200001, 0);
   	a = std::vector<int>(200001, 0);
   	std::vector<int> v;

   	cin >> n;

   	int x;
   	ll total_blanks = 0;
   	ll static_inversions = 0;
   	for(int i=0; i<n; i++){
   		cin >> x;
   		v.push_back(x);
   		if(x==-1){
   			total_blanks++;
   			continue;
   		}
   		insertElement(x);
   		static_inversions += (i+1) - total_blanks - get_rank(x);
   	}

   	add_fraction(static_inversions,1);
   	if(!total_blanks){
   		cout << static_inversions;
   		return 0;
   	}

   	add_fraction((total_blanks)*(total_blanks-1), 4);

   	ll blanks_till_now=0;
   	for(int i=0; i<n; i++){
   		x = v[i];
   		if(x==-1){
   			blanks_till_now++;
   			continue;
   		}
   		int current_greater_numbers = n - total_blanks - get_rank(x);
   		int total_greater_numbers = n - x;
   		ll greater_numbers_left = total_greater_numbers - current_greater_numbers;
   		add_fraction(blanks_till_now*greater_numbers_left*greater_numbers_left + (total_blanks-blanks_till_now)*(total_blanks-greater_numbers_left)*(total_blanks-greater_numbers_left), total_blanks*total_blanks);

   	}

   	cout << get_fractions_sum_mod();

   	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string.h>
#include<climits>
#include<vector>
#include<stack>
#include<set>
#include<queue>
#include<map>
#include<math.h>

using namespace std ;

typedef long long ll ;
typedef pair < int , int > pii ;

// #define TRACE 1
#ifdef TRACE
#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#endif

#define FOR(i,a,b) for(i=a;i<=b;i++)
#define MOD 998244353
#define vi vector<int>
#define vvi vector < vi >
#define vll vector<ll>
#define pb push_back
#define mp make_pair
#define PI acos(-1.0)

const ll INF = 1e15 + 10 ;

ll fun_gcd(ll a, ll b)
{
    // Everything divides 0
    if (a == 0)
       return b;
    if (b == 0)
       return a;

    // base case
    if (a == b)
        return a;

    // a is greater
    if (a > b)
        return fun_gcd(a-b, b);
    return fun_gcd(a, b-a);
}

int n;
std::vector<int> bit;
std::vector<int> a;
std::vector<ll> numerator;
std::vector<ll> denominator;

void update(int idx_onebased, int value){
	int diff = value - a[idx_onebased];
	a[idx_onebased] = value;
	while(idx_onebased <= n){
		bit[idx_onebased] += diff;
		idx_onebased += (idx_onebased & -idx_onebased);
	}
}

long long get_sum(int idx_onebased){
	long long sum = 0;
	while(idx_onebased){
		sum += bit[idx_onebased];
		idx_onebased -= (idx_onebased & -idx_onebased);
	}
	return sum;
}

long long get_rank(int number){
	return get_sum(number);
}

bool predicate( int i , int k){
	return get_rank(i) >= k;
}

long long get_kth_numbet(int k){
	int f=0, l=n, mid=(f+l)/2;
	while((l-f)>1){
		if(predicate(mid, k))
			l = mid;
		else
			f = mid;
		mid=(f+l)/2;
	}
	return l;
}

void insertElement(int x){
	update(x, a[x] + 1);
}

void deleteElement(int x){
	update(x, a[x] - 1);
}

void add_fraction(ll a, ll b){
	// ll gcd = fun_gcd(a,b);
	ll gcd = 1;
	numerator.push_back(a/gcd);
	denominator.push_back(b/gcd);
}

ll power(ll x, ll y)
{
    ll res = 1;     // Initialize result

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x)%MOD;

        // n must be even now
        y = y>>1; // y = y/2
        x = (x*x)%MOD;  // Change x to x^2
    }
    return res;
}

ll inverse_mod(ll x){
	return power(x,MOD-2);
}

ll get_fractions_sum_mod(){
	ll ans = 0;
	for(int i=0; i<numerator.size(); i++){
		// cout << numerator[i] << " " << denominator[i] << endl;
		ans += ((numerator[i]%MOD)*(inverse_mod(denominator[i])))%MOD;
		ans %= MOD;
	}
	return ans;
}

int main(){
   	bit = std::vector<int>(200001, 0);
   	a = std::vector<int>(200001, 0);
   	std::vector<int> v;

   	cin >> n;

   	int x;
   	ll total_blanks = 0;
   	ll static_inversions = 0;
   	for(int i=0; i<n; i++){
   		cin >> x;
   		v.push_back(x);
   		if(x==-1){
   			total_blanks++;
   			continue;
   		}
   		insertElement(x);
   		static_inversions += (i+1) - total_blanks - get_rank(x);
   	}

   	add_fraction(static_inversions,1);
   	if(!total_blanks){
   		cout << static_inversions;
   		return 0;
   	}

   	add_fraction((total_blanks)*(total_blanks-1), 4);

   	ll blanks_till_now=0;
   	for(int i=0; i<n; i++){
   		x = v[i];
   		if(x==-1){
   			blanks_till_now++;
   			continue;
   		}
   		int current_greater_numbers = n - total_blanks - get_rank(x);
   		int total_greater_numbers = n - x;
   		ll greater_numbers_left = total_greater_numbers - current_greater_numbers;
   		add_fraction(blanks_till_now*greater_numbers_left*greater_numbers_left + (total_blanks-blanks_till_now)*(total_blanks-greater_numbers_left)*(total_blanks-greater_numbers_left), total_blanks*total_blanks);

   	}

   	cout << get_fractions_sum_mod();

   	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string.h>
#include<climits>
#include<vector>
#include<stack>
#include<set>
#include<queue>
#include<map>
#include<math.h>

using namespace std ;

typedef long long ll ;
typedef pair < int , int > pii ;

// #define TRACE 1
#ifdef TRACE
#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#endif

#define FOR(i,a,b) for(i=a;i<=b;i++)
#define MOD 998244353
#define vi vector<int>
#define vvi vector < vi >
#define vll vector<ll>
#define pb push_back
#define mp make_pair
#define PI acos(-1.0)

const ll INF = 1e15 + 10 ;

ll fun_gcd(ll a, ll b)
{
    // Everything divides 0
    if (a == 0)
       return b;
    if (b == 0)
       return a;

    // base case
    if (a == b)
        return a;

    // a is greater
    if (a > b)
        return fun_gcd(a-b, b);
    return fun_gcd(a, b-a);
}

int n;
std::vector<int> bit;
std::vector<int> a;
std::vector<ll> numerator;
std::vector<ll> denominator;

void update(int idx_onebased, int value){
	int diff = value - a[idx_onebased];
	a[idx_onebased] = value;
	while(idx_onebased <= n){
		bit[idx_onebased] += diff;
		idx_onebased += (idx_onebased & -idx_onebased);
	}
}

long long get_sum(int idx_onebased){
	long long sum = 0;
	while(idx_onebased){
		sum += bit[idx_onebased];
		idx_onebased -= (idx_onebased & -idx_onebased);
	}
	return sum;
}

long long get_rank(int number){
	return get_sum(number);
}

bool predicate( int i , int k){
	return get_rank(i) >= k;
}

long long get_kth_numbet(int k){
	int f=0, l=n, mid=(f+l)/2;
	while((l-f)>1){
		if(predicate(mid, k))
			l = mid;
		else
			f = mid;
		mid=(f+l)/2;
	}
	return l;
}

void insertElement(int x){
	update(x, a[x] + 1);
}

void deleteElement(int x){
	update(x, a[x] - 1);
}

void add_fraction(ll a, ll b){
	// ll gcd = fun_gcd(a,b);
	ll gcd = 1;
	numerator.push_back(a/gcd);
	denominator.push_back(b/gcd);
}

ll power(ll x, ll y)
{
    ll res = 1;     // Initialize result

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x)%MOD;

        // n must be even now
        y = y>>1; // y = y/2
        x = (x*x)%MOD;  // Change x to x^2
    }
    return res;
}

ll inverse_mod(ll x){
	return power(x,MOD-2);
}

ll get_fractions_sum_mod(){
	ll ans = 0;
	for(int i=0; i<numerator.size(); i++){
		// cout << numerator[i] << " " << denominator[i] << endl;
		ans += ((numerator[i]%MOD)*(inverse_mod(denominator[i])))%MOD;
		ans %= MOD;
	}
	return ans;
}

int main(){
   	bit = std::vector<int>(200001, 0);
   	a = std::vector<int>(200001, 0);
   	std::vector<int> v;

   	cin >> n;

   	int x;
   	ll total_blanks = 0;
   	ll static_inversions = 0;
   	for(int i=0; i<n; i++){
   		cin >> x;
   		v.push_back(x);
   		if(x==-1){
   			total_blanks++;
   			continue;
   		}
   		insertElement(x);
   		static_inversions += (i+1) - total_blanks - get_rank(x);
   	}

   	add_fraction(static_inversions,1);
   	if(!total_blanks){
   		cout << static_inversions % MOD;
   		return 0;
   	}

   	add_fraction((total_blanks)*(total_blanks-1), 4);

   	ll blanks_till_now=0;
   	for(int i=0; i<n; i++){
   		x = v[i];
   		if(x==-1){
   			blanks_till_now++;
   			continue;
   		}
   		int current_greater_numbers = n - total_blanks - get_rank(x);
   		int total_greater_numbers = n - x;
   		ll greater_numbers_left = total_greater_numbers - current_greater_numbers;
   		add_fraction(blanks_till_now*greater_numbers_left*greater_numbers_left + (total_blanks-blanks_till_now)*(total_blanks-greater_numbers_left)*(total_blanks-greater_numbers_left), total_blanks*total_blanks);

   	}

   	cout << get_fractions_sum_mod();

   	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string.h>
#include<climits>
#include<vector>
#include<stack>
#include<set>
#include<queue>
#include<map>
#include<math.h>

using namespace std ;

typedef long long ll ;
typedef pair < int , int > pii ;

// #define TRACE 1
#ifdef TRACE
#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#endif

#define FOR(i,a,b) for(i=a;i<=b;i++)
#define MOD 998244353
#define vi vector<int>
#define vvi vector < vi >
#define vll vector<ll>
#define pb push_back
#define mp make_pair
#define PI acos(-1.0)

const ll INF = 1e15 + 10 ;

ll gcd( ll u, ll v)
{
    // simple cases (termination)
    if (u == v)
        return u;

    if (u == 0)
        return v;

    if (v == 0)
        return u;

    // look for factors of 2
    if (~u & 1) // u is even
    {
        if (v & 1) // v is odd
            return gcd(u >> 1, v);
        else // both u and v are even
            return gcd(u >> 1, v >> 1) << 1;
    }

    if (~v & 1) // u is odd, v is even
        return gcd(u, v >> 1);

    // reduce larger argument
    if (u > v)
        return gcd((u - v) >> 1, v);

    return gcd((v - u) >> 1, u);
}

int n;
std::vector<int> bit;
std::vector<int> a;
std::vector<ll> numerator;
std::vector<ll> denominator;

void update(int idx_onebased, int value){
	int diff = value - a[idx_onebased];
	a[idx_onebased] = value;
	while(idx_onebased <= n){
		bit[idx_onebased] += diff;
		idx_onebased += (idx_onebased & -idx_onebased);
	}
}

long long get_sum(int idx_onebased){
	long long sum = 0;
	while(idx_onebased){
		sum += bit[idx_onebased];
		idx_onebased -= (idx_onebased & -idx_onebased);
	}
	return sum;
}

long long get_rank(int number){
	return get_sum(number);
}

bool predicate( int i , int k){
	return get_rank(i) >= k;
}

long long get_kth_numbet(int k){
	int f=0, l=n, mid=(f+l)/2;
	while((l-f)>1){
		if(predicate(mid, k))
			l = mid;
		else
			f = mid;
		mid=(f+l)/2;
	}
	return l;
}

void insertElement(int x){
	update(x, a[x] + 1);
}

void deleteElement(int x){
	update(x, a[x] - 1);
}

void add_fraction(ll a, ll b){

	a %= MOD;
	b %= MOD;
	ll gcd_cur = gcd(a,b);
	// ll gcd_cur = 1;
	numerator.push_back(a/gcd_cur);
	denominator.push_back(b/gcd_cur);
}

ll power(ll x, ll y)
{
    ll res = 1;     // Initialize result

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x)%MOD;

        // n must be even now
        y = y>>1; // y = y/2
        x = (x*x)%MOD;  // Change x to x^2
    }
    return res;
}

ll inverse_mod(ll x){
	return power(x,MOD-2);
}

ll get_fractions_sum_mod(){
	ll ans = 0;
	for(int i=0; i<numerator.size(); i++){
		// cout << numerator[i] << " " << denominator[i] << endl;
		ans += ((numerator[i]%MOD)*(inverse_mod(denominator[i])))%MOD;
		ans %= MOD;
	}
	return ans;
}

int main(){
   	bit = std::vector<int>(200001, 0);
   	a = std::vector<int>(200001, 0);
   	std::vector<int> v;

   	cin >> n;

   	int x;
   	ll total_blanks = 0;
   	ll static_inversions = 0;
   	for(int i=0; i<n; i++){
   		cin >> x;
   		v.push_back(x);
   		if(x==-1){
   			total_blanks++;
   			continue;
   		}
   		insertElement(x);
   		static_inversions += (i+1) - total_blanks - get_rank(x);
   	}

   	add_fraction(static_inversions,1);
   	if(!total_blanks){
   		cout << static_inversions % MOD;
   		return 0;
   	}

   	add_fraction((total_blanks)*(total_blanks-1), 4);

   	ll blanks_till_now=0;
   	for(int i=0; i<n; i++){
   		x = v[i];
   		if(x==-1){
   			blanks_till_now++;
   			continue;
   		}
   		int current_greater_numbers = n - total_blanks - get_rank(x);
   		int total_greater_numbers = n - x;
   		ll greater_numbers_left = total_greater_numbers - current_greater_numbers;
   		add_fraction(blanks_till_now*greater_numbers_left*greater_numbers_left + (total_blanks-blanks_till_now)*(total_blanks-greater_numbers_left)*(total_blanks-greater_numbers_left), total_blanks*total_blanks);

   	}

   	cout << get_fractions_sum_mod();

   	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string.h>
#include<climits>
#include<vector>
#include<stack>
#include<set>
#include<queue>
#include<map>
#include<math.h>

using namespace std ;

typedef long long ll ;
typedef pair < int , int > pii ;

// #define TRACE 1
#ifdef TRACE
#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#endif

#define FOR(i,a,b) for(i=a;i<=b;i++)
#define MOD 998244353
#define vi vector<int>
#define vvi vector < vi >
#define vll vector<ll>
#define pb push_back
#define mp make_pair
#define PI acos(-1.0)

const ll INF = 1e15 + 10 ;

ll gcd( ll u, ll v)
{
    // simple cases (termination)
    if (u == v)
        return u;

    if (u == 0)
        return v;

    if (v == 0)
        return u;

    // look for factors of 2
    if (~u & 1) // u is even
    {
        if (v & 1) // v is odd
            return gcd(u >> 1, v);
        else // both u and v are even
            return gcd(u >> 1, v >> 1) << 1;
    }

    if (~v & 1) // u is odd, v is even
        return gcd(u, v >> 1);

    // reduce larger argument
    if (u > v)
        return gcd((u - v) >> 1, v);

    return gcd((v - u) >> 1, u);
}

int n;
std::vector<int> bit;
std::vector<int> a;
std::vector<ll> numerator;
std::vector<ll> denominator;

void update(int idx_onebased, int value){
	int diff = value - a[idx_onebased];
	a[idx_onebased] = value;
	while(idx_onebased <= n){
		bit[idx_onebased] += diff;
		idx_onebased += (idx_onebased & -idx_onebased);
	}
}

long long get_sum(int idx_onebased){
	long long sum = 0;
	while(idx_onebased){
		sum += bit[idx_onebased];
		idx_onebased -= (idx_onebased & -idx_onebased);
	}
	return sum;
}

long long get_rank(int number){
	return get_sum(number);
}

bool predicate( int i , int k){
	return get_rank(i) >= k;
}

long long get_kth_numbet(int k){
	int f=0, l=n, mid=(f+l)/2;
	while((l-f)>1){
		if(predicate(mid, k))
			l = mid;
		else
			f = mid;
		mid=(f+l)/2;
	}
	return l;
}

void insertElement(int x){
	update(x, a[x] + 1);
}

void deleteElement(int x){
	update(x, a[x] - 1);
}

void add_fraction(ll a, ll b){

	a %= MOD;
	b %= MOD;
	ll gcd_cur = gcd(a,b);
	// ll gcd_cur = 1;
	numerator.push_back(a/gcd_cur);
	denominator.push_back(b/gcd_cur);
}

ll power(ll x, ll y)
{
    ll res = 1;     // Initialize result

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x)%MOD;

        // n must be even now
        y = y>>1; // y = y/2
        x = (x*x)%MOD;  // Change x to x^2
    }
    return res;
}

ll inverse_mod(ll x){
	return power(x,MOD-2);
}

ll get_fractions_sum_mod(){
	ll ans = 0;
	for(int i=0; i<numerator.size(); i++){
		// cout << numerator[i] << " " << denominator[i] << endl;
		ans += ((numerator[i]%MOD)*(inverse_mod(denominator[i])))%MOD;
		ans %= MOD;
	}
	return ans;
}

int main(){
   	bit = std::vector<int>(200001, 0);
   	a = std::vector<int>(200001, 0);
   	std::vector<int> v;

   	cin >> n;

   	int x;
   	ll total_blanks = 0;
   	ll static_inversions = 0;
   	for(int i=0; i<n; i++){
   		cin >> x;
   		v.push_back(x);
   		if(x==-1){
   			total_blanks++;
   			continue;
   		}
   		insertElement(x);
   		static_inversions += (i+1) - total_blanks - get_rank(x);
   	}

   	add_fraction(static_inversions,1);
   	if(!total_blanks){
   		cout << static_inversions % MOD;
   		return 0;
   	}

   	add_fraction((total_blanks)*(total_blanks-1), 4);

   	ll blanks_till_now=0;
   	for(int i=0; i<n; i++){
   		x = v[i];
   		if(x==-1){
   			blanks_till_now++;
   			continue;
   		}
   		int current_greater_numbers = n - total_blanks - get_rank(x);
   		int total_greater_numbers = n - x;
   		ll greater_numbers_left = total_greater_numbers - current_greater_numbers;
   		add_fraction(blanks_till_now*greater_numbers_left + (total_blanks-blanks_till_now)*(total_blanks-greater_numbers_left), total_blanks);

   	}

   	cout << get_fractions_sum_mod();

   	return 0;
}


#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define MOD 998244353
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

class Bit{
public:
	vector<int>bit;
	Bit(){}
	Bit(int n){
		bit=vector<int>(n+10);
	}
	void add(int k,int x){
		k++;
		while(k<(int)bit.size()){
			bit[k]+=x;
			k+=k&-k;
		}
	}
	int sum(int k){
		k++;
		int res=0;
		while(k){
			res+=bit[k];
			k-=k&-k;
		}
		return res;
	}
};
ll ppow(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}
int p[300000];
int b[300000];
bool flag[300000];

int main(){
	int n;scanf("%d",&n);
	Bit bit(n),bit2(n);
	int all=0;
	rep(i,n){
		scanf("%d",&p[i]);
		if(p[i]!=-1)flag[p[i]]=true;
		if(p[i]==-1)all++;
	}
	int cnt=0;
	vector<int>v;
	for(int i=n;i>=1;i--){
		if(!flag[i]){
			cnt++;
			v.push_back(i);
			bit2.add(i,1);
		}
		b[i]=cnt;
	}
	sort(v.begin(),v.end());
	ll asum=0;
	if(v.size()>=2){
		for(int i=0;i+1<v.size();i++){
			(asum+=(v.size()-i-1)*ppow(all-1,MOD-2)*ppow(all,MOD-2))%=MOD;
		}
	}
	ll ans=0;
	cnt=0;
	int cnt2=0;
	ll psum=0;
	rep(i,n){
		if(p[i]!=-1){
			ll sum1=cnt2-bit.sum(p[i]);
			ll sum2=b[p[i]]*ppow(all,MOD-2)%MOD*cnt%MOD;
			(ans+=sum1+sum2)%=MOD;
			bit.add(p[i],1);
			(psum+=bit2.sum(p[i])*ppow(all,MOD-2)%MOD)%=MOD;
			cnt2++;
		}
		else{
			(ans+=psum)%=MOD;
			if(cnt)(ans+=asum*cnt)%=MOD;
			cnt++;
		}
	}
	cout<<ans%MOD<<endl;
}


#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define MOD 998244353
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

class Bit{
public:
	vector<int>bit;
	Bit(){}
	Bit(int n){
		bit=vector<int>(n+10);
	}
	void add(int k,int x){
		k++;
		while(k<(int)bit.size()){
			bit[k]+=x;
			k+=k&-k;
		}
	}
	int sum(int k){
		k++;
		int res=0;
		while(k){
			res+=bit[k];
			k-=k&-k;
		}
		return res;
	}
};
ll ppow(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}
int p[300000];
int b[300000];
bool flag[300000];

int main(){
	int n;scanf("%d",&n);
	Bit bit(n),bit2(n);
	int all=0;
	rep(i,n){
		scanf("%d",&p[i]);
		flag[p[i]]=true;
		if(p[i]==-1)all++;
	}
	int cnt=0;
	vector<int>v;
	for(int i=n;i>=1;i--){
		if(!flag[i]){
			cnt++;
			v.push_back(i);
			bit2.add(i,1);
		}
		b[i]=cnt;
	}
	ll asum=0;
	reverse(v.begin(),v.end());
	if(v.size()>=2){
		for(int i=v.size()-2;i>=0;i--){
			(asum+=(v.size()-i-1)*ppow(all-1,MOD-2)*ppow(all,MOD-2))%=MOD;
		}
	}
	ll ans=0;
	cnt=0;
	ll psum=0;
	rep(i,n){
		if(p[i]!=-1){
			ll sum1=i-bit.sum(p[i]);
			ll sum2=b[p[i]]*ppow(all,MOD-2)%MOD*cnt%MOD;
			(ans+=sum1+sum2)%=MOD;
			bit.add(p[i],1);
			(psum+=bit2.sum(p[i])*ppow(all,MOD-2)%MOD)%=MOD;
		}
		else{
			(ans+=psum)%=MOD;
			if(cnt)(ans+=asum*cnt)%=MOD;
			cnt++;
		}
	}
	cout<<ans%MOD<<endl;
}


#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define MOD 998244353
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

ll ppow(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}

class Bit{
public:
	vector<int>bit;
	Bit(){}
	Bit(int n){
		bit=vector<int>(n+10);
	}
	void add(int k,int x){
		k++;
		while(k<(int)bit.size()){
			bit[k]+=x;
			k+=k&-k;
		}
	}
	int sum(int k){
		k++;
		int res=0;
		while(k){
			res+=bit[k];
			k-=k&-k;
		}
		return res;
	}
};
int p[300000];
int b[300000];
bool flag[300000];

int main(){
	int n;scanf("%d",&n);
	Bit bit(n),bit2(n);
	ll all=0;
	rep(i,n){
		scanf("%d",&p[i]);
		if(p[i]!=-1)flag[p[i]]=true;
		else all++;
	}
	int cnt=0;;
	for(int i=n;i>=1;i--){
		if(!flag[i]){
			cnt++;
			bit2.add(i,1);
		}
		b[i]=cnt;
	}
	ll ans=0;
	cnt=0;
	int cnt2=0;
	ll psum=0;
	rep(i,n){
		if(p[i]!=-1){
			ll sum1=cnt2-bit.sum(p[i]);
			ll sum2=b[p[i]]*ppow(all,MOD-2)%MOD*cnt%MOD;
			(ans+=sum1+sum2)%=MOD;
			bit.add(p[i],1);
			(psum+=bit2.sum(p[i])*ppow(all,MOD-2)%MOD)%=MOD;
			cnt2++;
		}
		else{
			(ans+=psum)%=MOD;
			cnt++;
		}
	}
	if(all>=2)(ans+=all*(all-1)/2*ppow(2,MOD-2))%=MOD;
	cout<<ans%MOD<<endl;
}


#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define MOD 998244353
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

class Bit{
public:
	vector<int>bit;
	Bit(){}
	Bit(int n){
		bit=vector<int>(n+10);
	}
	void add(int k,int x){
		k++;
		while(k<(int)bit.size()){
			bit[k]+=x;
			k+=k&-k;
		}
	}
	int sum(int k){
		k++;
		int res=0;
		while(k){
			res+=bit[k];
			k-=k&-k;
		}
		return res;
	}
};
ll ppow(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}
int p[300000];
int b[300000];
bool flag[300000];

int main(){
	int n;scanf("%d",&n);
	Bit bit(n),bit2(n);
	int all=0;
	rep(i,n){
		scanf("%d",&p[i]);
		if(p[i]!=-1)flag[p[i]]=true;
		if(p[i]==-1)all++;
	}
	int cnt=0;
	vector<int>v;
	for(int i=n;i>=1;i--){
		if(!flag[i]){
			cnt++;
			v.push_back(i);
			bit2.add(i,1);
		}
		b[i]=cnt;
	}
	sort(v.begin(),v.end());
	ll asum=0;
	if(v.size()>=2){
		for(int i=0;i+1<v.size();i++){
			(asum+=(v.size()-i-1)*ppow(all-1,MOD-2)%MOD*ppow(all,MOD-2))%=MOD;
		}
	}
	ll ans=0;
	cnt=0;
	int cnt2=0;
	ll psum=0;
	rep(i,n){
		if(p[i]!=-1){
			ll sum1=cnt2-bit.sum(p[i]);
			ll sum2=b[p[i]]*ppow(all,MOD-2)%MOD*cnt%MOD;
			(ans+=sum1+sum2)%=MOD;
			bit.add(p[i],1);
			(psum+=bit2.sum(p[i])*ppow(all,MOD-2)%MOD)%=MOD;
			cnt2++;
		}
		else{
			(ans+=psum)%=MOD;
			if(cnt)(ans+=asum*cnt)%=MOD;
			cnt++;
		}
	}
	cout<<ans%MOD<<endl;
}


#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define MOD 998244353
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

ll ppow(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}

class Bit{
public:
	vector<int>bit;
	Bit(){}
	Bit(int n){
		bit=vector<int>(n+10);
	}
	void add(int k,int x){
		k++;
		while(k<(int)bit.size()){
			bit[k]+=x;
			k+=k&-k;
		}
	}
	int sum(int k){
		k++;
		int res=0;
		while(k){
			res+=bit[k];
			k-=k&-k;
		}
		return res;
	}
};
int p[300000];
int b[300000];
bool flag[300000];

int main(){
	int n;scanf("%d",&n);
	Bit bit(n),bit2(n);
	ll all=0;
	rep(i,n){
		scanf("%d",&p[i]);
		if(p[i]!=-1)flag[p[i]]=true;
		else all++;
	}
	int cnt=0;;
	for(int i=n;i>=1;i--){
		if(!flag[i]){
			cnt++;
			bit2.add(i,1);
		}
		b[i]=cnt;
	}
	ll ans=0;
	cnt=0;
	int cnt2=0;
	ll psum=0;
	rep(i,n){
		if(p[i]!=-1){
			ll sum1=cnt2-bit.sum(p[i]);
			ll sum2=b[p[i]]*ppow(all,MOD-2)%MOD*cnt%MOD;
			(ans+=sum1+sum2)%=MOD;
			bit.add(p[i],1);
			(psum+=bit2.sum(p[i])*ppow(all,MOD-2)%MOD)%=MOD;
			cnt2++;
		}
		else{
			(ans+=psum)%=MOD;
			cnt++;
		}
	}
	if(all>=2)(ans+=all*(all-1)/2%MOD*ppow(2,MOD-2))%=MOD;
	cout<<ans%MOD<<endl;
}


#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define MOD 998244353
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

class Bit{
public:
	vector<int>bit;
	Bit(){}
	Bit(int n){
		bit=vector<int>(n+10);
	}
	void add(int k,int x){
		k++;
		while(k<(int)bit.size()){
			bit[k]+=x;
			k+=k&-k;
		}
	}
	int sum(int k){
		k++;
		int res=0;
		while(k){
			res+=bit[k];
			k-=k&-k;
		}
		return res;
	}
};
ll ppow(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}
int p[300000];
int b[300000];
bool flag[300000];

int main(){
	int n;scanf("%d",&n);
	Bit bit(n),bit2(n);
	ll all=0;
	rep(i,n){
		scanf("%d",&p[i]);
		if(p[i]!=-1)flag[p[i]]=true;
		if(p[i]==-1)all++;
	}
	int cnt=0;;
	for(int i=n;i>=1;i--){
		if(!flag[i]){
			cnt++;
			bit2.add(i,1);
		}
		b[i]=cnt;
	}
	ll ans=0;
	cnt=0;
	ll psum=0;
	rep(i,n){
		if(p[i]!=-1){
			ll sum1=i-bit.sum(p[i]);
			ll sum2=b[p[i]]*ppow(all,MOD-2)%MOD*cnt%MOD;
			(ans+=sum1+sum2)%=MOD;
			bit.add(p[i],1);
			(psum+=bit2.sum(p[i])*ppow(all,MOD-2)%MOD)%=MOD;
		}
		else{
			(ans+=psum)%=MOD;
			cnt++;
		}
	}
	if(all>=2)(ans+=all*(all-1)/2*ppow(2,MOD-2))%=MOD;
	cout<<ans%MOD<<endl;
}


#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define MOD 998244353
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

class Bit{
public:
	vector<int>bit;
	Bit(){}
	Bit(int n){
		bit=vector<int>(n+10);
	}
	void add(int k,int x){
		k++;
		while(k<(int)bit.size()){
			bit[k]+=x;
			k+=k&-k;
		}
	}
	int sum(int k){
		k++;
		int res=0;
		while(k){
			res+=bit[k];
			k-=k&-k;
		}
		return res;
	}
};
ll ppow(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}
int p[300000];
int b[300000];
bool flag[300000];

int main(){
	int n;scanf("%d",&n);
	Bit bit(n),bit2(n);
	int all=0;
	rep(i,n){
		scanf("%d",&p[i]);
		flag[p[i]]=true;
		if(p[i]==-1)all++;
	}
	int cnt=0;
	vector<int>v;
	for(int i=n;i>=1;i--){
		if(!flag[i]){
			cnt++;
			v.push_back(i);
			bit2.add(i,1);
		}
		b[i]=cnt;
	}
	ll asum=0;
	reverse(v.begin(),v.end());
	if(v.size()>=2){
		for(int i=v.size()-2;i>=0;i--){
			(asum+=(all-1)*ppow(v.size()-i-1,MOD-2)*ppow(all,MOD-2))%=MOD;
		}
	}
	ll ans=0;
	cnt=0;
	ll psum=0;
	rep(i,n){
		if(p[i]!=-1){
			ll sum1=i-bit.sum(p[i]);
			ll sum2=b[p[i]]*ppow(all,MOD-2)%MOD*cnt%MOD;
			(ans+=sum1+sum2)%=MOD;
			bit.add(p[i],1);
			(psum+=bit2.sum(p[i])*ppow(all,MOD-2)%MOD)%=MOD;
		}
		else{
			(ans+=psum)%=MOD;
			if(cnt)(ans+=asum*cnt)%=MOD;
			cnt++;
		}
	}
	cout<<ans%MOD<<endl;
}


#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define MOD 998244353
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

class Bit{
public:
	vector<int>bit;
	Bit(){}
	Bit(int n){
		bit=vector<int>(n+10);
	}
	void add(int k,int x){
		k++;
		while(k<(int)bit.size()){
			bit[k]+=x;
			k+=k&-k;
		}
	}
	int sum(int k){
		k++;
		int res=0;
		while(k){
			res+=bit[k];
			k-=k&-k;
		}
		return res;
	}
};
ll ppow(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}
int p[300000];
int b[300000];
bool flag[300000];

int main(){
	int n;scanf("%d",&n);
	Bit bit(n),bit2(n);
	int all=0;
	rep(i,n){
		scanf("%d",&p[i]);
		if(p[i]!=-1)flag[p[i]]=true;
		if(p[i]==-1)all++;
	}
	int cnt=0;
	vector<int>v;
	for(int i=n;i>=1;i--){
		if(!flag[i]){
			cnt++;
			v.push_back(i);
			bit2.add(i,1);
		}
		b[i]=cnt;
	}
	sort(v.begin(),v.end());
	ll asum=0;
	if(v.size()>=2){
		for(int i=0;i+1<v.size();i++){
			(asum+=(v.size()-i-1)*ppow(all-1,MOD-2)*ppow(all,MOD-2))%=MOD;
		}
	}
	ll ans=0;
	cnt=0;
	ll psum=0;
	rep(i,n){
		if(p[i]!=-1){
			ll sum1=i-bit.sum(p[i]);
			ll sum2=b[p[i]]*ppow(all,MOD-2)%MOD*cnt%MOD;
			(ans+=sum1+sum2)%=MOD;
			bit.add(p[i],1);
			(psum+=bit2.sum(p[i])*ppow(all,MOD-2)%MOD)%=MOD;
		}
		else{
			(ans+=psum)%=MOD;
			if(cnt)(ans+=asum*cnt)%=MOD;
			cnt++;
		}
	}
	cout<<ans%MOD<<endl;
}